Checking unit XP needed to next promotion

Zimdictive

Chieftain
Joined
Mar 18, 2013
Messages
47
Location
Cambridge, UK
I'd like to implement a small health bonus upon receiving the required XP for the next promotion (i.e. if unit:ExperienceNeeded() == 0) to help units (and hopefully the AI on those occasions they through throw their nearly-promoted unit away on a dumb low-HP attack) survive through to the next turn when they can choose their promotion. But I'm not sure how to monitor units for this information (especially units who are defending rather than attacking) - I thought about subscribing to Events.EndCombatSim to grab the attacking and defending units' IDs - but I'm pretty sure this will only work for combat the player is engaged in, or at least can see, because it's intended to update the UI. Does anyone have any suggestions?

Thanks.
 
It's a variation on the "has the unit been upgraded" problem and if so, do I need to swap promotions from ranged to melee ... and I happen to know there's no simple answer to that one other than looping every unit at the start of the players turn and checking.

Edit: And you're right about EndCombatSim only being of use if you can see the combat, and it's been further "broken" in that it doesn't fire if one of the units dies in the combat IIRC (that single change is what killed all of Spatz's work in his Alpha Centuri mods :( )
 
Does that noticeably harm performance?
Depends how much work you do for each unit in the loop. Working out if they have been promoted is quite time consuming so you wouldn't want to do it every turn for every unit, which is why when I've checked a unit I give them the "Mustered" promotion (which is lost on upgrade) so the next turn if they have that promotion I know not to spend any time on them - checking for a promotion is very quick.

...You wouldn't happen to be planning to implement something additional to the currently existing promotions API in your DLL, would you? ;)
Presumably you mean events sent on upgrade/promotion - I wasn't but can. I've already added most of the obvious "missing ones" - http://forums.civfanatics.com/showpost.php?p=12344467&postcount=134 - to pair up tests with notifies
 
Back
Top Bottom