Bazaar developer reference

CvDiplomacyAI::DoUpdateOnePlayerTargetValue(PlayerTypes)

Defined in
CvDiplomacyAI.cpp, line 6762
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_DoUpdateOnePlayerTargetValue

Hooks

static bool BeforeCvDiplomacyAI_DoUpdateOnePlayerTargetValue(CvDiplomacyAI* self, PlayerTypes ePlayer);static void AfterCvDiplomacyAI_DoUpdateOnePlayerTargetValue(CvDiplomacyAI* self, PlayerTypes ePlayer);static void ReplaceCvDiplomacyAI_DoUpdateOnePlayerTargetValue(void (*original)(CvDiplomacyAI*, PlayerTypes), CvDiplomacyAI* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerTargetValue>(host, &BeforeCvDiplomacyAI_DoUpdateOnePlayerTargetValue);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerTargetValue>(host, &AfterCvDiplomacyAI_DoUpdateOnePlayerTargetValue);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoUpdateOnePlayerTargetValue>(host, &ReplaceCvDiplomacyAI_DoUpdateOnePlayerTargetValue);

Code

6761/// Updates what our assessment is of all players' value as a military target6762void CvDiplomacyAI::DoUpdateOnePlayerTargetValue(PlayerTypes ePlayer)6763{6764	CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index.  Please send Jon this with your last 5 autosaves and what changelist # you're playing.");6765	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.");67666767	if(!IsPlayerValid(ePlayer))6768		return;67696770	int iTargetValue;6771	TargetValueTypes eTargetValue;67726773	int iWarCount;67746775	CvCity* pLoopCity;6776	int iCityLoop;67776778	int iOtherPlayerMilitaryStrength;6779	int iCityStrengthMod;6780	int iMilitaryRatio;67816782	int iMyMilitaryStrength = GetPlayer()->getPower();6783	// Prevent divide by 06784	if(iMyMilitaryStrength == 0)6785	{6786		iMyMilitaryStrength = 1;6787	}67886789	int iCityDamage;6790	int iNumCities;67916792	int iThirdPartyLoop;6793	PlayerTypes eThirdPartyPlayer;6794	int iThirdPartyValue;6795	StrengthTypes eThirdPartyStrength;6796	PlayerProximityTypes eThirdPartyProximity;6797	iTargetValue = 0;67986799	iCityDamage = 0;6800	iNumCities = 0;68016802	iOtherPlayerMilitaryStrength = GET_PLAYER(ePlayer).getPower();68036804	// City Defensive Strength6805	for(pLoopCity = GET_PLAYER(ePlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(ePlayer).nextCity(&iCityLoop))6806	{6807		iCityStrengthMod = pLoopCity->GetPower();68086809		iCityStrengthMod *= /*33*/ GC.getMILITARY_STRENGTH_CITY_MOD();6810		iCityStrengthMod /= 100;68116812		iOtherPlayerMilitaryStrength += iCityStrengthMod;68136814		// Keep track of damage because we'll use it later as a global modifier for the player's strength6815		iCityDamage += pLoopCity->getDamage();6816		iNumCities++;6817	}68186819	// Depending on how damaged a player's Cities are, he can become a much more attractive target6820	if(iNumCities > 0)6821	{6822		iCityDamage /= iNumCities;6823		iCityDamage *= 100;6824		iCityDamage /= GC.getMAX_CITY_HIT_POINTS();6825		// iCityDamage is now a percentage of global City damage6826		iCityDamage *= iOtherPlayerMilitaryStrength;6827		iCityDamage /= 200;	// divide by 200 instead of 100 so that if all Cities have no health it only HALVES our strength instead of taking it all the way to 068286829		iOtherPlayerMilitaryStrength -= iCityDamage;6830	}68316832	iMilitaryRatio = iOtherPlayerMilitaryStrength* /*100*/ GC.getMILITARY_STRENGTH_RATIO_MULTIPLIER() / iMyMilitaryStrength;6833	// Example: If another player has double the Military strength of us, the Ratio will be 20068346835	iTargetValue += iMilitaryRatio;68366837	// Increase target value if the player is already at war with other players6838	iWarCount = GET_TEAM(GET_PLAYER(ePlayer).getTeam()).getAtWarCount(true);6839	// Reduce by 1 if WE'RE already at war with him6840	if(GET_TEAM(GetTeam()).isAtWar(GET_PLAYER(ePlayer).getTeam()))6841	{6842		iWarCount--;6843	}68446845	iTargetValue += (iWarCount* /*30*/ GC.getTARGET_ALREADY_WAR_EACH_PLAYER());68466847	// Factor in distance6848	switch(GetPlayer()->GetProximityToPlayer(ePlayer))6849	{6850	case PLAYER_PROXIMITY_NEIGHBORS:6851		iTargetValue += /*-10*/ GC.getTARGET_NEIGHBORS();6852		break;6853	case PLAYER_PROXIMITY_CLOSE:6854		iTargetValue += /*0*/ GC.getTARGET_CLOSE();6855		break;6856	case PLAYER_PROXIMITY_FAR:6857		iTargetValue += /*30*/ GC.getTARGET_FAR();6858		break;6859	case PLAYER_PROXIMITY_DISTANT:6860		iTargetValue += /*80*/ GC.getTARGET_DISTANT();6861		break;6862	}68636864	// Factor in Friends this player has, if it's a minor6865	if(GET_PLAYER(ePlayer).isMinorCiv())6866	{6867		for(iThirdPartyLoop = 0; iThirdPartyLoop < MAX_MAJOR_CIVS; iThirdPartyLoop++)6868		{6869			eThirdPartyPlayer = (PlayerTypes) iThirdPartyLoop;68706871			if(IsPlayerValid(eThirdPartyPlayer))6872			{6873				// This works for human players as well (NetPledgeMinorProtection in Civ5NetMessage.cpp)6874				if(GET_PLAYER(ePlayer).GetMinorCivAI()->GetAlly() == eThirdPartyPlayer ||6875				        GET_PLAYER(ePlayer).GetMinorCivAI()->IsProtectedByMajor(eThirdPartyPlayer))6876				{6877					iThirdPartyValue = 0;6878					eThirdPartyStrength = GetPlayerMilitaryStrengthComparedToUs(eThirdPartyPlayer);6879					eThirdPartyProximity	= GetPlayer()->GetProximityToPlayer(eThirdPartyPlayer);68806881					// How strong is this friend?6882					if(eThirdPartyStrength == STRENGTH_PATHETIC)6883						iThirdPartyValue += /* 0*/ GC.getTARGET_MINOR_BACKUP_PATHETIC();6884					else if(eThirdPartyStrength == STRENGTH_WEAK)6885						iThirdPartyValue += /* 0*/ GC.getTARGET_MINOR_BACKUP_WEAK();6886					else if(eThirdPartyStrength == STRENGTH_POOR)6887						iThirdPartyValue += /* 5*/ GC.getTARGET_MINOR_BACKUP_POOR();6888					else if(eThirdPartyStrength == STRENGTH_AVERAGE)6889						iThirdPartyValue += /* 15*/ GC.getTARGET_MINOR_BACKUP_AVERAGE();6890					else if(eThirdPartyStrength == STRENGTH_STRONG)6891						iThirdPartyValue += /* 25*/ GC.getTARGET_MINOR_BACKUP_STRONG();6892					else if(eThirdPartyStrength == STRENGTH_POWERFUL)6893						iThirdPartyValue += /* 35*/ GC.getTARGET_MINOR_BACKUP_POWERFUL();6894					else if(eThirdPartyStrength == STRENGTH_IMMENSE)6895						iThirdPartyValue += /* 50*/ GC.getTARGET_MINOR_BACKUP_IMMENSE();68966897					// How close is this guy to us?6898					if(eThirdPartyProximity == PLAYER_PROXIMITY_DISTANT)6899						iThirdPartyValue *= /* 100*/ GC.getTARGET_MINOR_BACKUP_DISTANT();6900					else if(eThirdPartyProximity == PLAYER_PROXIMITY_FAR)6901						iThirdPartyValue *= /* 115*/ GC.getTARGET_MINOR_BACKUP_FAR();6902					else if(eThirdPartyProximity == PLAYER_PROXIMITY_CLOSE)6903						iThirdPartyValue *= /* 150*/ GC.getTARGET_MINOR_BACKUP_CLOSE();6904					else if(eThirdPartyProximity == PLAYER_PROXIMITY_NEIGHBORS)6905						iThirdPartyValue *= /* 200*/ GC.getTARGET_MINOR_BACKUP_NEIGHBORS();69066907					iThirdPartyValue /= 100;69086909					// Add the strength of this friend in to the overall eval6910					iTargetValue += iThirdPartyValue;6911				}6912			}6913		}6914	}69156916	// Now do the final assessment6917	if(iTargetValue >= /*200*/ GC.getTARGET_IMPOSSIBLE_THRESHOLD())6918		eTargetValue = TARGET_VALUE_IMPOSSIBLE;6919	else if(iTargetValue >= /*125*/ GC.getTARGET_BAD_THRESHOLD())6920		eTargetValue = TARGET_VALUE_BAD;6921	else if(iTargetValue >= /*80*/ GC.getTARGET_AVERAGE_THRESHOLD())6922		eTargetValue = TARGET_VALUE_AVERAGE;6923	else if(iTargetValue >= /*50*/ GC.getTARGET_FAVORABLE_THRESHOLD())6924		eTargetValue = TARGET_VALUE_FAVORABLE;6925	else6926		eTargetValue = TARGET_VALUE_SOFT;69276928	// If the player is expanding aggressively, bump things down a level6929	if(eTargetValue < TARGET_VALUE_SOFT && IsPlayerRecklessExpander(ePlayer))6930		eTargetValue = TargetValueTypes(eTargetValue + 1);69316932	// If it's a city-state and we've been at war for a LONG time, bump things up6933	if(eTargetValue > TARGET_VALUE_IMPOSSIBLE && GetPlayerNumTurnsAtWar(ePlayer) > /*50*/ GC.getTARGET_INCREASE_WAR_TURNS())6934		eTargetValue = TargetValueTypes(eTargetValue - 1);69356936	// If the player is too far from us then we can't consider them Soft6937	if(eTargetValue == TARGET_VALUE_SOFT)6938	{6939		if(GetPlayer()->GetProximityToPlayer(ePlayer) <= PLAYER_PROXIMITY_FAR)6940		{6941			eTargetValue = TARGET_VALUE_FAVORABLE;6942		}6943	}69446945	// Set the value6946	SetPlayerTargetValue(ePlayer, eTargetValue);6947}

Calls

Called by