Preventing A Unit From Waking

LyTning94

Dragonborn
Joined
Nov 10, 2010
Messages
397
Location
Skyrim
I added a new unit xml tag which makes a unit unable to be attacked, enables it to enter the same plot as an enemy unit, and even enter enemy cities without capturing them. I then added a unit mission which made the unit able to boost diplomacy with the owner of the capital it was in. The diplomacy boost, however, does not take effect until the next turn.

If you are at war with the owner of the capital in which the unit is boosting diplomacy, you can still enter the capital and perform the mission, but every time an enemy unit enters its visibility range, it wakes the unit. This is annoying not only because you have to repeatedly click the mission on subsequent turns, but also because, since the diplomacy boost does not take effect until the next turn, you do not get the boost if the unit is being woken every turn.

So my question is, is anyone aware of the function which wakes a unit from its mission when an enemy unit enters its visibility range? I have been thoroughly searching the SDK, but I can't seem to find the function anywhere. Any help would be greatly appreciated.

Thanks in advance!
 
Try looking at CvSelectionGroup::doTurn():

Code:
		// wake unit if skipped last turn 
		//		or healing and automated or no longer hurt (automated healing is one turn at a time)
		//		or on sentry and there is danger
		if ((eActivityType == ACTIVITY_HOLD) ||
			((eActivityType == ACTIVITY_HEAL) && (AI_isControlled() || !bHurt)) ||
			([B](eActivityType == ACTIVITY_SENTRY) && (sentryAlert()[/B])))
		{
			setActivityType(ACTIVITY_AWAKE);
		}

CvSelectionGroup::sentryAlert() checks for enemy visibility.
 
Be careful, the file that you will be working in (where Asaf showed you) is pretty touchy if you get things wrong. So when making this unit in this case not wake up, be sure you are VERY specific so you don't mess things up for other cases where you don't intend to. If at all possible (sounds like it should be) a good approach would be to make a UnitCombat type specific for this unit alone, and cause that unitcombat type to avoid this wake check. But of course that means that if the unit is doing something else which normally leads to being woke up (like healing, or actual sentry command) that it skips that as well. However, those cases don't arise if this unit is meant to never enter combat at all like a worker or spy.
 
Try looking at CvSelectionGroup::doTurn():

Code:
		// wake unit if skipped last turn 
		//		or healing and automated or no longer hurt (automated healing is one turn at a time)
		//		or on sentry and there is danger
		if ((eActivityType == ACTIVITY_HOLD) ||
			((eActivityType == ACTIVITY_HEAL) && (AI_isControlled() || !bHurt)) ||
			([B](eActivityType == ACTIVITY_SENTRY) && (sentryAlert()[/B])))
		{
			setActivityType(ACTIVITY_AWAKE);
		}

CvSelectionGroup::sentryAlert() checks for enemy visibility.

This doesn't seem to be the problem. I set a breakpoint at the beginning of CvSelectionGroup::doTurn() and the unit's activity was already set to ACTIVITY_AWAKE. I had just started the mission the turn before, so it should have been ACTIVITY_MISSION. Does this mean it's waking sometime during the AI's turn? Where?
 
If it's not there, then set a breakpoint in CvSelectionGroup::setActivityType(), and see when it changes to ACTIVITY_AWAKE.

To save going through all the selection groups, you can add a condition to the breakpoint with (for example) the value of 'this' (after you check this when you start the mission).
 
Top Bottom