//------------------------------------------------------------------------------ //int CalculateStartingVotesForMember(PlayerTypes ePlayer); int CvLuaLeague::lCalculateStartingVotesForMember(lua_State* L) { CvLeague* pLeague = GetInstance(L); const PlayerTypes ePlayer = (PlayerTypes) lua_tointeger(L, 2); const int iValue = pLeague->CalculateStartingVotesForMember(ePlayer); lua_pushinteger(L, iValue); return 1; }
/// Returns Priority for United Nations Grand Strategy int CvGrandStrategyAI::GetUnitedNationsPriority() { int iPriority = 0; PlayerTypes ePlayer = m_pPlayer->GetID(); // If UN Victory isn't even available then don't bother with anything VictoryTypes eVictory = (VictoryTypes) GC.getInfoTypeForString("VICTORY_DIPLOMATIC", true); if(eVictory == NO_VICTORY || !GC.getGame().isVictoryValid(eVictory)) { return -100; } int iNumMinorsAttacked = GET_TEAM(GetPlayer()->getTeam()).GetNumMinorCivsAttacked(); iPriority += (iNumMinorsAttacked* /*-30*/ GC.getAI_GRAND_STRATEGY_UN_EACH_MINOR_ATTACKED_WEIGHT()); int iVotesNeededToWin = GC.getGame().GetVotesNeededForDiploVictory(); int iVotesControlled = 0; int iVotesControlledDelta = 0; int iUnalliedCityStates = 0; if (GC.getGame().GetGameLeagues()->GetNumActiveLeagues() == 0) { // Before leagues kick in, add weight based on flavor int iFlavorDiplo = m_pPlayer->GetFlavorManager()->GetPersonalityIndividualFlavor((FlavorTypes)GC.getInfoTypeForString("FLAVOR_DIPLOMACY")); iPriority += (10 - m_pPlayer->GetCurrentEra()) * iFlavorDiplo * 150 / 100; } else { CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague(); CvAssert(pLeague != NULL); if (pLeague != NULL) { // Votes we control iVotesControlled += pLeague->CalculateStartingVotesForMember(ePlayer); // Votes other players control int iHighestOtherPlayerVotes = 0; for (int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++) { PlayerTypes eLoopPlayer = (PlayerTypes) iPlayerLoop; if(eLoopPlayer != ePlayer && GET_PLAYER(eLoopPlayer).isAlive()) { if (GET_PLAYER(eLoopPlayer).isMinorCiv()) { if (GET_PLAYER(eLoopPlayer).GetMinorCivAI()->GetAlly() == NO_PLAYER) { iUnalliedCityStates++; } } else { int iOtherPlayerVotes = pLeague->CalculateStartingVotesForMember(eLoopPlayer); if (iOtherPlayerVotes > iHighestOtherPlayerVotes) { iHighestOtherPlayerVotes = iOtherPlayerVotes; } } } } // How we compare iVotesControlledDelta = iVotesControlled - iHighestOtherPlayerVotes; } } // Are we close to winning? if (iVotesControlled >= iVotesNeededToWin) { return 1000; } else if (iVotesControlled >= ((iVotesNeededToWin * 3) / 4)) { iPriority += 40; } // We have the most votes if (iVotesControlledDelta > 0) { iPriority += MAX(40, iVotesControlledDelta * 5); } // We are equal or behind in votes else { // Could we make up the difference with currently unallied city-states? int iPotentialCityStateVotes = iUnalliedCityStates * 2; int iPotentialVotesDelta = iPotentialCityStateVotes + iVotesControlledDelta; if (iPotentialVotesDelta > 0) { iPriority += MAX(20, iPotentialVotesDelta * 5); } else if (iPotentialVotesDelta < 0) { iPriority += MIN(-40, iPotentialVotesDelta * -5); } } // factor in some traits that could be useful (or harmful) iPriority += m_pPlayer->GetPlayerTraits()->GetCityStateFriendshipModifier(); iPriority += m_pPlayer->GetPlayerTraits()->GetCityStateBonusModifier(); iPriority -= m_pPlayer->GetPlayerTraits()->GetCityStateCombatModifier(); return iPriority; }