Bazaar developer reference

CvDiplomacyAI::DoUpdateOtherPlayerWarDamageLevel()

Defined in
CvDiplomacyAI.cpp, line 9215
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel>(host, &BeforeCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel>(host, &AfterCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel>(host, &ReplaceCvDiplomacyAI_DoUpdateOtherPlayerWarDamageLevel);

Code

9214/// Updates what is our guess as to amount of war damage a player has suffered to another player9215void CvDiplomacyAI::DoUpdateOtherPlayerWarDamageLevel()9216{9217	PlayerTypes eLoopOtherPlayer;9218	int iOtherPlayerLoop;92199220	int iValueLost;9221	int iCurrentValue;9222	int iValueLostRatio;92239224	CvCity* pLoopCity;9225	int iValueLoop;92269227	WarDamageLevelTypes eWarDamageLevel;92289229	// Loop through all (known) Majors9230	PlayerTypes eLoopPlayer;9231	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)9232	{9233		eLoopPlayer = (PlayerTypes) iPlayerLoop;92349235		if(IsPlayerValid(eLoopPlayer))9236		{9237			// Now loop through every player HE knows9238			for(iOtherPlayerLoop = 0; iOtherPlayerLoop < MAX_MAJOR_CIVS; iOtherPlayerLoop++)9239			{9240				eLoopOtherPlayer = (PlayerTypes) iOtherPlayerLoop;92419242				// Don't compare a player to himself9243				if(eLoopPlayer != eLoopOtherPlayer)9244				{9245					// Do both we and the guy we're looking about know the third guy?9246					if(IsPlayerValid(eLoopOtherPlayer) && GET_PLAYER(eLoopPlayer).GetDiplomacyAI()->IsPlayerValid(eLoopOtherPlayer))9247					{9248						// At War?9249						if(GET_TEAM(GET_PLAYER(eLoopPlayer).getTeam()).isAtWar(GET_PLAYER(eLoopOtherPlayer).getTeam()))9250						{9251							iValueLost = GetOtherPlayerWarValueLost(eLoopPlayer, eLoopOtherPlayer);92529253							// Calculate the value of what we have currently9254							iCurrentValue = 0;92559256							// City value9257							if(GET_PLAYER(eLoopPlayer).getNumCities() > 0)9258							{9259								for(pLoopCity = GET_PLAYER(eLoopPlayer).firstCity(&iValueLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(eLoopPlayer).nextCity(&iValueLoop))9260								{9261									iCurrentValue += (pLoopCity->getPopulation() * /*150*/ GC.getWAR_DAMAGE_LEVEL_INVOLVED_CITY_POP_MULTIPLIER());9262									if (pLoopCity->IsOriginalCapital()) // anybody's9263									{9264										iCurrentValue *= 3;9265										iCurrentValue /= 2;9266									}9267								}9268							}92699270							// Prevents divide by 09271							iCurrentValue = max(1,iCurrentValue);92729273							iValueLostRatio = iValueLost * 100 / iCurrentValue;92749275							if(iValueLostRatio >= /*50*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_CRIPPLED())9276								eWarDamageLevel = WAR_DAMAGE_LEVEL_CRIPPLED;9277							else if(iValueLostRatio >= /*35*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_SERIOUS())9278								eWarDamageLevel = WAR_DAMAGE_LEVEL_SERIOUS;9279							else if(iValueLostRatio >= /*20*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_MAJOR())9280								eWarDamageLevel = WAR_DAMAGE_LEVEL_MAJOR;9281							else if(iValueLostRatio >= /*10*/ GC.getWAR_DAMAGE_LEVEL_THRESHOLD_MINOR())9282								eWarDamageLevel = WAR_DAMAGE_LEVEL_MINOR;9283							else9284								eWarDamageLevel = WAR_DAMAGE_LEVEL_NONE;9285						}92869287						else9288							eWarDamageLevel = WAR_DAMAGE_LEVEL_NONE;92899290						SetOtherPlayerWarDamageLevel(eLoopPlayer, eLoopOtherPlayer, eWarDamageLevel);9291					}9292				}9293			}9294		}9295	}9296}

Calls

Called by