Bazaar developer reference

CvGrandStrategyAI::GetUnitedNationsPriority()

Defined in
CvGrandStrategyAI.cpp, line 615
Class
CvGrandStrategyAI
Hook name
CivHooks::CvGrandStrategyAI_GetUnitedNationsPriority

Hooks

static bool BeforeCvGrandStrategyAI_GetUnitedNationsPriority(CvGrandStrategyAI* self, int& result);static void AfterCvGrandStrategyAI_GetUnitedNationsPriority(CvGrandStrategyAI* self, int& result);static int ReplaceCvGrandStrategyAI_GetUnitedNationsPriority(int (*original)(CvGrandStrategyAI*), CvGrandStrategyAI* self);CivRegisterBefore<CivHooks::CvGrandStrategyAI_GetUnitedNationsPriority>(host, &BeforeCvGrandStrategyAI_GetUnitedNationsPriority);CivRegisterAfter<CivHooks::CvGrandStrategyAI_GetUnitedNationsPriority>(host, &AfterCvGrandStrategyAI_GetUnitedNationsPriority);CivRegisterReplace<CivHooks::CvGrandStrategyAI_GetUnitedNationsPriority>(host, &ReplaceCvGrandStrategyAI_GetUnitedNationsPriority);

Code

614/// Returns Priority for United Nations Grand Strategy615int CvGrandStrategyAI::GetUnitedNationsPriority()616{617	int iPriority = 0;618	PlayerTypes ePlayer = m_pPlayer->GetID();619620	// If UN Victory isn't even available then don't bother with anything621	VictoryTypes eVictory = (VictoryTypes) GC.getInfoTypeForString("VICTORY_DIPLOMATIC", true);622	if(eVictory == NO_VICTORY || !GC.getGame().isVictoryValid(eVictory))623	{624		return -100;625	}626627	int iNumMinorsAttacked = GET_TEAM(GetPlayer()->getTeam()).GetNumMinorCivsAttacked();628	iPriority += (iNumMinorsAttacked* /*-30*/ GC.getAI_GRAND_STRATEGY_UN_EACH_MINOR_ATTACKED_WEIGHT());629630	int iVotesNeededToWin = GC.getGame().GetVotesNeededForDiploVictory();631632	int iVotesControlled = 0;633	int iVotesControlledDelta = 0;634	int iUnalliedCityStates = 0;635	if (GC.getGame().GetGameLeagues()->GetNumActiveLeagues() == 0)636	{637		// Before leagues kick in, add weight based on flavor638		int iFlavorDiplo =  m_pPlayer->GetFlavorManager()->GetPersonalityIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_DIPLOMACY"));639		iPriority += (10 - m_pPlayer->GetCurrentEra()) * iFlavorDiplo * 150 / 100;640	}641	else642	{643		CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague();644		CvAssert(pLeague != NULL);645		if (pLeague != NULL)646		{647			// Votes we control648			iVotesControlled += pLeague->CalculateStartingVotesForMember(ePlayer);649650			// Votes other players control651			int iHighestOtherPlayerVotes = 0;652			for (int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)653			{654				PlayerTypes eLoopPlayer = (PlayerTypes) iPlayerLoop;655656				if(eLoopPlayer != ePlayer && GET_PLAYER(eLoopPlayer).isAlive())657				{658					if (GET_PLAYER(eLoopPlayer).isMinorCiv())659					{660						if (GET_PLAYER(eLoopPlayer).GetMinorCivAI()->GetAlly() == NO_PLAYER)661						{662							iUnalliedCityStates++;663						}664					}665					else666					{667						int iOtherPlayerVotes = pLeague->CalculateStartingVotesForMember(eLoopPlayer);668						if (iOtherPlayerVotes > iHighestOtherPlayerVotes)669						{670							iHighestOtherPlayerVotes = iOtherPlayerVotes;671						}672					}673				}674			}675676			// How we compare677			iVotesControlledDelta = iVotesControlled - iHighestOtherPlayerVotes;678		}679	}680681	// Are we close to winning?682	if (iVotesControlled >= iVotesNeededToWin)683	{684		return 1000;685	}686	else if (iVotesControlled >= ((iVotesNeededToWin * 3) / 4))687	{688		iPriority += 40;689	}690691	// We have the most votes692	if (iVotesControlledDelta > 0)693	{694		iPriority += MAX(40, iVotesControlledDelta * 5);695	}696	// We are equal or behind in votes697	else698	{699		// Could we make up the difference with currently unallied city-states?700		int iPotentialCityStateVotes = iUnalliedCityStates * 2;701		int iPotentialVotesDelta = iPotentialCityStateVotes + iVotesControlledDelta;702		if (iPotentialVotesDelta > 0)703		{704			iPriority += MAX(20, iPotentialVotesDelta * 5);705		}706		else if (iPotentialVotesDelta < 0)707		{708			iPriority += MIN(-40, iPotentialVotesDelta * -5);709		}710	}711712	// factor in some traits that could be useful (or harmful)713	iPriority += m_pPlayer->GetPlayerTraits()->GetCityStateFriendshipModifier();714	iPriority += m_pPlayer->GetPlayerTraits()->GetCityStateBonusModifier();715	iPriority -= m_pPlayer->GetPlayerTraits()->GetCityStateCombatModifier();716717	return iPriority;718}

Calls

Called by