Bazaar developer reference

CvMilitaryAI::UpdateThreats()

Defined in
CvMilitaryAI.cpp, line 2380
Class
CvMilitaryAI
Hook name
CivHooks::CvMilitaryAI_UpdateThreats

Hooks

static bool BeforeCvMilitaryAI_UpdateThreats(CvMilitaryAI* self);static void AfterCvMilitaryAI_UpdateThreats(CvMilitaryAI* self);static void ReplaceCvMilitaryAI_UpdateThreats(void (*original)(CvMilitaryAI*), CvMilitaryAI* self);CivRegisterBefore<CivHooks::CvMilitaryAI_UpdateThreats>(host, &BeforeCvMilitaryAI_UpdateThreats);CivRegisterAfter<CivHooks::CvMilitaryAI_UpdateThreats>(host, &AfterCvMilitaryAI_UpdateThreats);CivRegisterReplace<CivHooks::CvMilitaryAI_UpdateThreats>(host, &ReplaceCvMilitaryAI_UpdateThreats);

Code

2379/// See if the threats we are facing have changed2380void CvMilitaryAI::UpdateThreats()2381{2382	AI_PERF_FORMAT("Military-AI-perf.csv", ("UpdateThreats, Turn %03d, %s", GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );23832384	ThreatTypes eMilitaryThreatType;23852386	PlayerTypes eLoopPlayer;2387	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)2388	{2389		eLoopPlayer = (PlayerTypes) iPlayerLoop;23902391		// Is this a player we have relations with?2392		if(eLoopPlayer != m_pPlayer->GetID() && m_pDiplomacyAI->IsPlayerValid(eLoopPlayer))2393		{2394			eMilitaryThreatType = m_pDiplomacyAI->GetMilitaryThreat(eLoopPlayer);2395			if(eMilitaryThreatType != m_paeLastTurnMilitaryThreat[eLoopPlayer])2396			{2397				// Change in threat level2398				if(eMilitaryThreatType > m_paeLastTurnMilitaryThreat[eLoopPlayer])2399				{2400					ThreatIncrease(eMilitaryThreatType, (ThreatTypes)m_paeLastTurnMilitaryThreat[eLoopPlayer]);2401				}2402				else2403				{2404					ThreatDecrease(eMilitaryThreatType, (ThreatTypes)m_paeLastTurnMilitaryThreat[eLoopPlayer]);2405				}24062407				// Save off new value2408				m_paeLastTurnMilitaryThreat[eLoopPlayer] = eMilitaryThreatType;2409			}2410		}2411	}2412}

Calls

Called by