Auto-destruction of units

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
I start working on the code that spawns animals and monsters randomly. The idea is to pick several random map tiles each turn (the number of these tiles depending on the map size and game speed) and put animal/monster units there, their type depending on terrain and feature type, as well as the techs available to the barbarian civ (which, as far as I remember, depend on the techs researched by the civs). But there is one thing that I need to do, and I don't know how: to prevent the situation where uninhabited islands have lots of low-tech units hanging around, I need to make the units that are too old disappear. So, I need code that does the following:

1. Iterate through all barbarian units
2. Check their age
3. Destroy units that reach certain age (depending on game speed)

Would it be possible using Lua, and if so, how?
 
Certainly possibly, if no one else offers a solution before I get home tonight, the following will be needed

Code:
for pUnit in pBarbPlayer:Units() do
end


Code:
local iUnitAge = Game.GetGameTurn() - pUnit:GetGameTurnCreated()

Code:
pUnit:Kill(true, -1)
 
Thanks, I think I can complete the code myself using the fragments you provided (will post again if I have any more problems).
 
Back
Top Bottom