Bazaar developer reference

CvDiplomacyAI::DoUpdateOnePlayerMilitaryAggressivePosture(PlayerTypes)

Defined in
CvDiplomacyAI.cpp, line 9417
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture(CvDiplomacyAI* self, PlayerTypes ePlayer);static void AfterCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture(CvDiplomacyAI* self, PlayerTypes ePlayer);static void ReplaceCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture(void (*original)(CvDiplomacyAI*, PlayerTypes), CvDiplomacyAI* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture>(host, &BeforeCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture>(host, &AfterCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture>(host, &ReplaceCvDiplomacyAI_DoUpdateOnePlayerMilitaryAggressivePosture);

Code

9416/// Updates how aggressively this player's Units are positioned in relation to us9417void CvDiplomacyAI::DoUpdateOnePlayerMilitaryAggressivePosture(PlayerTypes ePlayer)9418{9419	CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");9420	CvAssertMsg(ePlayer < MAX_CIV_PLAYERS, "DIPLOMACY_AI: Invalid Player Index.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");94219422	if(!IsPlayerValid(ePlayer))9423		return;94249425	AggressivePostureTypes eAggressivePosture;9426	AggressivePostureTypes eLastTurnAggressivePosture;94279428	int iUnitValueOnMyHomeFront;9429	int iValueToAdd;9430	bool bIsAtWarWithSomeone;94319432	CvUnit* pLoopUnit;9433	int iUnitLoop;94349435	int iOtherPlayerLoop;9436	PlayerTypes eLoopOtherPlayer;94379438	// Keep a record of last turn9439	eLastTurnAggressivePosture = GetMilitaryAggressivePosture(ePlayer);9440	if(eLastTurnAggressivePosture != NO_AGGRESSIVE_POSTURE_TYPE)9441		SetLastTurnMilitaryAggressivePosture(ePlayer, eLastTurnAggressivePosture);94429443	iUnitValueOnMyHomeFront = 0;9444	CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);9445	CvTeam& kTeam = GET_TEAM(kPlayer.getTeam());9446	bIsAtWarWithSomeone = (kTeam.getAtWarCount(false) > 0);94479448	TeamTypes eOurTeam = GetTeam();9449	PlayerTypes eOurPlayerID = GetPlayer()->GetID();94509451	// Loop through the other guy's units9452	for(pLoopUnit = kPlayer.firstUnit(&iUnitLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iUnitLoop))9453	{9454		// Don't be scared of noncombat Units!9455		if(pLoopUnit->IsCombatUnit())9456		{9457			CvPlot* pUnitPlot = pLoopUnit->plot();9458			// Can we actually see this Unit's Plot?  No cheating!9459			if(pUnitPlot->isVisible(eOurTeam))9460			{9461				// On our home front9462				if(pUnitPlot->IsHomeFrontForPlayer(eOurPlayerID))9463				{9464					// At war with someone?  Because if this is Unit in the vicinity of another player he's already at war with, don't count this Unit as aggressive9465					if(bIsAtWarWithSomeone)9466					{9467						// Loop through all players...9468						for(iOtherPlayerLoop = 0; iOtherPlayerLoop < MAX_CIV_PLAYERS; iOtherPlayerLoop++)9469						{9470							eLoopOtherPlayer = (PlayerTypes) iOtherPlayerLoop;94719472							// Don't look at us or see if this player is at war with himself9473							if(eLoopOtherPlayer != ePlayer && eLoopOtherPlayer != eOurPlayerID)9474							{9475								// At war with this player?9476								if(kTeam.isAtWar(GET_PLAYER(eLoopOtherPlayer).getTeam()))9477								{9478									if(GET_PLAYER(eLoopOtherPlayer).isAlive())9479									{9480										if(pUnitPlot->IsHomeFrontForPlayer(eLoopOtherPlayer))9481										{9482											continue;9483										}9484									}9485								}9486							}9487						}9488					}94899490					iValueToAdd = 10;94919492					// If the Unit is in the other player's territory, halve it's "aggression value," since he may just be defending himself9493					if(pLoopUnit->plot()->isOwned())9494					{9495						if(pLoopUnit->plot()->getOwner() == ePlayer)9496							iValueToAdd /= 2;9497					}94989499					// Maybe look at Unit Power here instead?9500					iUnitValueOnMyHomeFront += iValueToAdd;9501				}9502			}9503		}9504	}95059506	// So how threatening is he being?9507	if(iUnitValueOnMyHomeFront >= /*80*/ GC.getMILITARY_AGGRESSIVE_POSTURE_THRESHOLD_INCREDIBLE())9508		eAggressivePosture = AGGRESSIVE_POSTURE_INCREDIBLE;9509	else if(iUnitValueOnMyHomeFront >= /*50*/ GC.getMILITARY_AGGRESSIVE_POSTURE_THRESHOLD_HIGH())9510		eAggressivePosture = AGGRESSIVE_POSTURE_HIGH;9511	else if(iUnitValueOnMyHomeFront >= /*30*/ GC.getMILITARY_AGGRESSIVE_POSTURE_THRESHOLD_MEDIUM())9512		eAggressivePosture = AGGRESSIVE_POSTURE_MEDIUM;9513	else if(iUnitValueOnMyHomeFront >= /*10*/ GC.getMILITARY_AGGRESSIVE_POSTURE_THRESHOLD_LOW())9514		eAggressivePosture = AGGRESSIVE_POSTURE_LOW;9515	else9516		eAggressivePosture = AGGRESSIVE_POSTURE_NONE;95179518	SetMilitaryAggressivePosture(ePlayer, eAggressivePosture);9519}

Calls

Called by