Bazaar developer reference

CvDiplomacyAI::DoUpdateEstimateOtherPlayerMilitaryThreats()

Defined in
CvDiplomacyAI.cpp, line 7129
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats>(host, &BeforeCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats>(host, &AfterCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats>(host, &ReplaceCvDiplomacyAI_DoUpdateEstimateOtherPlayerMilitaryThreats);

Code

7128/// Updates what our guess is as to the level of Military Threat one player feels from another7129void CvDiplomacyAI::DoUpdateEstimateOtherPlayerMilitaryThreats()7130{7131	int iMilitaryThreat;7132	ThreatTypes eMilitaryThreatType;71337134	int iWarCount;71357136	int iPlayerMilitaryStrength;71377138	CvCity* pLoopCity;7139	int iCityLoop;7140	int iCityStrengthMod;71417142	int iThirdPlayerMilitaryStrength;7143	int iMilitaryRatio;71447145	PlayerTypes eLoopOtherPlayer;7146	int iOtherPlayerLoop;71477148	// Loop through all (known) Majors7149	PlayerTypes eLoopPlayer;7150	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)7151	{7152		eLoopPlayer = (PlayerTypes) iPlayerLoop;71537154		if(IsPlayerValid(eLoopPlayer))7155		{7156			iPlayerMilitaryStrength = GET_PLAYER(eLoopPlayer).GetMilitaryMight();71577158			// Add in City Defensive Strength7159			for(pLoopCity = GET_PLAYER(eLoopPlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eLoopPlayer).nextCity(&iCityLoop))7160			{7161				iCityStrengthMod = pLoopCity->GetPower();7162				iCityStrengthMod *= (pLoopCity->GetMaxHitPoints() - pLoopCity->getDamage());7163				iCityStrengthMod /= pLoopCity->GetMaxHitPoints();7164				iCityStrengthMod /= 100;7165				iCityStrengthMod *= /*33*/ GC.getMILITARY_STRENGTH_CITY_MOD();7166				iCityStrengthMod /= 100;7167				iPlayerMilitaryStrength += (MAX(iCityStrengthMod, 0));7168			}71697170			// Prevent divide by 07171			if(iPlayerMilitaryStrength == 0)7172				iPlayerMilitaryStrength = 1;71737174			// Now loop through every player HE knows7175			for(iOtherPlayerLoop = 0; iOtherPlayerLoop < MAX_MAJOR_CIVS; iOtherPlayerLoop++)7176			{7177				eLoopOtherPlayer = (PlayerTypes) iOtherPlayerLoop;71787179				// Don't compare a player to himself7180				if(eLoopPlayer != eLoopOtherPlayer)7181				{7182					// Do both we and the guy we're looking about know the third guy?7183					if(IsPlayerValid(eLoopOtherPlayer) && GET_PLAYER(eLoopPlayer).GetDiplomacyAI()->IsPlayerValid(eLoopOtherPlayer))7184					{7185						eMilitaryThreatType = THREAT_NONE;7186						iMilitaryThreat = 0;71877188						iThirdPlayerMilitaryStrength = GET_PLAYER(eLoopOtherPlayer).GetMilitaryMight();71897190						// Example: If another player has double the Military strength of us, the Ratio will be 2007191						iMilitaryRatio = iThirdPlayerMilitaryStrength* /*100*/ GC.getMILITARY_STRENGTH_RATIO_MULTIPLIER() / iPlayerMilitaryStrength;71927193						iMilitaryThreat += iMilitaryRatio;71947195						//// At war: what is the current status of things?7196						//if (GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam()))7197						//{7198						//	// War State7199						//	switch (GetWarState(eLoopPlayer))7200						//	{7201						//	case WAR_STATE_CALM:7202						//		iMilitaryThreat += /*0*/ GC.getMILITARY_THREAT_WAR_STATE_CALM();7203						//		break;7204						//	case WAR_STATE_NEARLY_WON:7205						//		iMilitaryThreat += /*-100*/ GC.getMILITARY_THREAT_WAR_STATE_NEARLY_WON();7206						//		break;7207						//	case WAR_STATE_OFFENSIVE:7208						//		iMilitaryThreat += /*-40*/ GC.getMILITARY_THREAT_WAR_STATE_OFFENSIVE();7209						//		break;7210						//	case WAR_STATE_STALEMATE:7211						//		iMilitaryThreat += /*30*/ GC.getMILITARY_THREAT_WAR_STATE_STALEMATE();7212						//		break;7213						//	case WAR_STATE_DEFENSIVE:7214						//		iMilitaryThreat += /*80*/ GC.getMILITARY_THREAT_WAR_STATE_DEFENSIVE();7215						//		break;7216						//	case WAR_STATE_NEARLY_DEFEATED:7217						//		iMilitaryThreat += /*150*/ GC.getMILITARY_THREAT_WAR_STATE_NEARLY_DEFEATED();7218						//		break;7219						//	}7220						//}72217222						// Factor in Friends this player has72237224						// TBD72257226						// Factor in distance7227						switch(GET_PLAYER(eLoopPlayer).GetProximityToPlayer(eLoopOtherPlayer))7228						{7229						case PLAYER_PROXIMITY_NEIGHBORS:7230							iMilitaryThreat += /*100*/ GC.getMILITARY_THREAT_NEIGHBORS();7231							break;7232						case PLAYER_PROXIMITY_CLOSE:7233							iMilitaryThreat += /*40*/ GC.getMILITARY_THREAT_CLOSE();7234							break;7235						case PLAYER_PROXIMITY_FAR:7236							iMilitaryThreat += /*-40*/ GC.getMILITARY_THREAT_FAR();7237							break;7238						case PLAYER_PROXIMITY_DISTANT:7239							iMilitaryThreat += /*-100*/ GC.getMILITARY_THREAT_DISTANT();7240							break;7241						}72427243						// Don't factor in # of players attacked or at war with now if we ARE at war with this guy already7244//						if (!GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam()))7245						{7246							// Increase threat based on how many Player's we've already seen this guy attack and conquer7247							iMilitaryThreat += (GetOtherPlayerNumMinorsAttacked(eLoopOtherPlayer)  * /*20*/ GC.getMILITARY_THREAT_PER_MINOR_ATTACKED());7248							iMilitaryThreat += (GetOtherPlayerNumMinorsConquered(eLoopOtherPlayer) * /*10*/ GC.getMILITARY_THREAT_PER_MINOR_CONQUERED());7249							iMilitaryThreat += (GetOtherPlayerNumMajorsAttacked(eLoopOtherPlayer)  * /*40*/ GC.getMILITARY_THREAT_PER_MAJOR_ATTACKED());7250							iMilitaryThreat += (GetOtherPlayerNumMajorsConquered(eLoopOtherPlayer) * /*20*/ GC.getMILITARY_THREAT_PER_MAJOR_CONQUERED());72517252							// Reduce the Threat (dramatically) if the player is already at war with other players7253							iWarCount = GET_TEAM(GET_PLAYER(eLoopOtherPlayer).getTeam()).getAtWarCount(true);7254							if(iWarCount > 0)7255								iMilitaryThreat += (/*-30*/ GC.getMILITARY_THREAT_ALREADY_WAR_EACH_PLAYER_MULTIPLIER() * iWarCount * iMilitaryThreat / 100);7256						}72577258						// Now do the final assessment7259						if(iMilitaryThreat >= /*300*/ GC.getMILITARY_THREAT_CRITICAL_THRESHOLD())7260							eMilitaryThreatType = THREAT_CRITICAL;7261						else if(iMilitaryThreat >= /*220*/ GC.getMILITARY_THREAT_SEVERE_THRESHOLD())7262							eMilitaryThreatType = THREAT_SEVERE;7263						else if(iMilitaryThreat >= /*170*/ GC.getMILITARY_THREAT_MAJOR_THRESHOLD())7264							eMilitaryThreatType = THREAT_MAJOR;7265						else if(iMilitaryThreat >= /*100*/ GC.getMILITARY_THREAT_MINOR_THRESHOLD())7266							eMilitaryThreatType = THREAT_MINOR;72677268						// Set the Threat7269						SetEstimateOtherPlayerMilitaryThreat(eLoopPlayer, eLoopOtherPlayer, eMilitaryThreatType);7270					}7271				}7272			}7273		}7274	}7275}

Calls

Called by