[PYTHON] - Looking for a unit check that's done every turn

Tholal

Emperor
Joined
May 19, 2009
Messages
1,676
I'm looking for a way to change the UnitAI on the fly. Changing it is no problem, I'm just not sure where to place my code so that it gets checked every turn. I see that there is a function called AI_unitUpdate, but I don't know when this is called. Is this called for every unit on every turn or is there some special trigger that results in this function being used?
 
onBeginPlayerTurn in CvEventmanager is called every turn once. You can use it and place a loop over all units of the player there.
 
AI_unitUpdate might be a better place to change the UnitAI. It is called for every AI unit every turn and is the only place (that I know of) where you can push a mission to a unit from Python. I'm not sure if changing the UnitAI has the same limitations as pushing a mission. However, if it does then AI_unitUpdate is the only place that would work.
 
I am sure the python callback in CvUnit::AI_unitUpdate is only called for Headunits of selectionsgroups that have ACTIVITY_AWAKE activityType (cargo of a ship for example not)
 
My mistake, I changed the way it works in my mod, and didn't notice my comment lines when looking at the code.
 
I am sure the python callback in CvUnit::AI_unitUpdate is only called for Headunits of selectionsgroups that have ACTIVITY_AWAKE activityType (cargo of a ship for example not)

I'm not quite sure what all that means, but it sounds like it might work. Let me give an example of what I'm trying to do.

Example: When the AI gets involved in a war, I want them to think about changing their settler ships over to assault AI. Can I do that by adding a check into AI_unitUpdate?
 
in unmodded BTS, probably yes.

in FFH AI_unitUpdate in cvgameutils in only called for barbarian units.
 
Top Bottom