Class: Zyps::PopulationLimit

Inherits:
EnvironmentalFactor show all
Defined in:
lib/zyps/environmental_factors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count) ⇒ PopulationLimit

Returns a new instance of PopulationLimit.



172
173
174
# File 'lib/zyps/environmental_factors.rb', line 172

def initialize(count)
	self.count = count
end

Instance Attribute Details

#countObject

Maximum allowed population.



170
171
172
# File 'lib/zyps/environmental_factors.rb', line 170

def count
  @count
end

Instance Method Details

#act(environment) ⇒ Object

Remove target if there are too many objects in environment.



177
178
179
180
# File 'lib/zyps/environmental_factors.rb', line 177

def act(environment)
	excess = environment.objects.length - @count
	environment.objects.slice!(0, excess) if excess > 0
end