Bazaar developer reference

CvDiplomacyAI::DoUpdateMilitaryThreats()

Defined in
CvDiplomacyAI.cpp, line 6974
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateMilitaryThreats

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateMilitaryThreats(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateMilitaryThreats(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateMilitaryThreats(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateMilitaryThreats>(host, &BeforeCvDiplomacyAI_DoUpdateMilitaryThreats);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateMilitaryThreats>(host, &AfterCvDiplomacyAI_DoUpdateMilitaryThreats);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateMilitaryThreats>(host, &ReplaceCvDiplomacyAI_DoUpdateMilitaryThreats);

Code

6973/// Updates how threatening each player is Militarily6974void CvDiplomacyAI::DoUpdateMilitaryThreats()6975{6976	int iMilitaryThreat;6977	ThreatTypes eMilitaryThreatType;69786979	int iWarCount;69806981	int iMyMilitaryStrength = GetPlayer()->getPower();6982	// Prevent divide by 06983	if(iMyMilitaryStrength == 0)6984	{6985		iMyMilitaryStrength = 1;6986	}69876988	// Add in City Defensive Strength6989	CvCity* pLoopCity;6990	int iCityLoop;6991	int iCityStrengthMod;6992	for(pLoopCity = GetPlayer()->firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GetPlayer()->nextCity(&iCityLoop))6993	{6994		iCityStrengthMod = pLoopCity->GetPower();6995		iCityStrengthMod *= (pLoopCity->GetMaxHitPoints() - pLoopCity->getDamage());6996		iCityStrengthMod /= pLoopCity->GetMaxHitPoints();6997		iCityStrengthMod /= 100;6998		iCityStrengthMod *= /*33*/ GC.getMILITARY_STRENGTH_CITY_MOD();6999		iCityStrengthMod /= 100;7000		iMyMilitaryStrength += iCityStrengthMod;7001	}70027003	int iOtherPlayerMilitaryStrength;7004	int iMilitaryRatio;70057006	// Loop through all (known) Players7007	PlayerTypes eLoopPlayer;7008	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)7009	{7010		eLoopPlayer = (PlayerTypes) iPlayerLoop;70117012		if(IsPlayerValid(eLoopPlayer))7013		{7014			iMilitaryThreat = 0;70157016			iOtherPlayerMilitaryStrength = GET_PLAYER(eLoopPlayer).getPower();70177018			// Example: If another player has double the Military strength of us, the Ratio will be 2007019			iMilitaryRatio = iOtherPlayerMilitaryStrength* /*100*/ GC.getMILITARY_STRENGTH_RATIO_MULTIPLIER() / iMyMilitaryStrength;70207021			iMilitaryThreat += iMilitaryRatio;70227023			// At war: what is the current status of things?7024			if(GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam()))7025			{7026				// War State7027				switch(GetWarState(eLoopPlayer))7028				{7029				case WAR_STATE_CALM:7030					iMilitaryThreat += /*0*/ GC.getMILITARY_THREAT_WAR_STATE_CALM();7031					break;7032				case WAR_STATE_NEARLY_WON:7033					iMilitaryThreat += /*-100*/ GC.getMILITARY_THREAT_WAR_STATE_NEARLY_WON();7034					break;7035				case WAR_STATE_OFFENSIVE:7036					iMilitaryThreat += /*-40*/ GC.getMILITARY_THREAT_WAR_STATE_OFFENSIVE();7037					break;7038				case WAR_STATE_STALEMATE:7039					iMilitaryThreat += /*30*/ GC.getMILITARY_THREAT_WAR_STATE_STALEMATE();7040					break;7041				case WAR_STATE_DEFENSIVE:7042					iMilitaryThreat += /*80*/ GC.getMILITARY_THREAT_WAR_STATE_DEFENSIVE();7043					break;7044				case WAR_STATE_NEARLY_DEFEATED:7045					iMilitaryThreat += /*150*/ GC.getMILITARY_THREAT_WAR_STATE_NEARLY_DEFEATED();7046					break;7047				}7048			}70497050			// Factor in Friends this player has70517052			// TBD70537054			// Factor in distance7055			switch(GetPlayer()->GetProximityToPlayer(eLoopPlayer))7056			{7057			case PLAYER_PROXIMITY_NEIGHBORS:7058				iMilitaryThreat += /*100*/ GC.getMILITARY_THREAT_NEIGHBORS();7059				break;7060			case PLAYER_PROXIMITY_CLOSE:7061				iMilitaryThreat += /*40*/ GC.getMILITARY_THREAT_CLOSE();7062				break;7063			case PLAYER_PROXIMITY_FAR:7064				iMilitaryThreat += /*-40*/ GC.getMILITARY_THREAT_FAR();7065				break;7066			case PLAYER_PROXIMITY_DISTANT:7067				iMilitaryThreat += /*-100*/ GC.getMILITARY_THREAT_DISTANT();7068				break;7069			}70707071			// Don't factor in # of players attacked or at war with now if we ARE at war with this guy already7072			if(!GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(eLoopPlayer).getTeam()))7073			{7074				// Increase threat based on how many Player's we've already seen this guy attack and conquer7075				iMilitaryThreat += (GetOtherPlayerNumMinorsAttacked(eLoopPlayer) * /*20*/ GC.getMILITARY_THREAT_PER_MINOR_ATTACKED());7076				iMilitaryThreat += (GetOtherPlayerNumMinorsConquered(eLoopPlayer) * /*10*/ GC.getMILITARY_THREAT_PER_MINOR_CONQUERED());7077				iMilitaryThreat += (GetOtherPlayerNumMajorsAttacked(eLoopPlayer) * /*40*/ GC.getMILITARY_THREAT_PER_MAJOR_ATTACKED());7078				iMilitaryThreat += (GetOtherPlayerNumMajorsConquered(eLoopPlayer) * /*20*/ GC.getMILITARY_THREAT_PER_MAJOR_CONQUERED());70797080				// Reduce the Threat (dramatically) if the player is already at war with other players7081				iWarCount = GET_TEAM(GET_PLAYER(eLoopPlayer).getTeam()).getAtWarCount(true);7082				if(iWarCount > 0)7083				{7084					iMilitaryThreat += (/*-30*/ GC.getMILITARY_THREAT_ALREADY_WAR_EACH_PLAYER_MULTIPLIER() * iWarCount * iMilitaryThreat / 100);7085				}7086			}70877088			// Now do the final assessment7089			if(iMilitaryThreat >= /*300*/ GC.getMILITARY_THREAT_CRITICAL_THRESHOLD())7090				eMilitaryThreatType = THREAT_CRITICAL;7091			else if(iMilitaryThreat >= /*220*/ GC.getMILITARY_THREAT_SEVERE_THRESHOLD())7092				eMilitaryThreatType = THREAT_SEVERE;7093			else if(iMilitaryThreat >= /*170*/ GC.getMILITARY_THREAT_MAJOR_THRESHOLD())7094				eMilitaryThreatType = THREAT_MAJOR;7095			else if(iMilitaryThreat >= /*100*/ GC.getMILITARY_THREAT_MINOR_THRESHOLD())7096				eMilitaryThreatType = THREAT_MINOR;7097			else7098				eMilitaryThreatType = THREAT_NONE;70997100			// Set the Threat7101			SetMilitaryThreat(eLoopPlayer, eMilitaryThreatType);7102		}7103	}7104}

Calls

Called by