Bazaar developer reference

CvMinorCivAI::DoElection()

Defined in
CvMinorCivAI.cpp, line 9678
Class
CvMinorCivAI
Hook name
CivHooks::CvMinorCivAI_DoElection

Hooks

static bool BeforeCvMinorCivAI_DoElection(CvMinorCivAI* self);static void AfterCvMinorCivAI_DoElection(CvMinorCivAI* self);static void ReplaceCvMinorCivAI_DoElection(void (*original)(CvMinorCivAI*), CvMinorCivAI* self);CivRegisterBefore<CivHooks::CvMinorCivAI_DoElection>(host, &BeforeCvMinorCivAI_DoElection);CivRegisterAfter<CivHooks::CvMinorCivAI_DoElection>(host, &AfterCvMinorCivAI_DoElection);CivRegisterReplace<CivHooks::CvMinorCivAI_DoElection>(host, &ReplaceCvMinorCivAI_DoElection);

Code

9678void CvMinorCivAI::DoElection()9679{9680	// if it is not an election turn, don't process!9681	if(GC.getGame().GetTurnsUntilMinorCivElection() != 0)9682	{9683		return;9684	}96859686	CvWeightedVector<PlayerTypes, MAX_MAJOR_CIVS, true> wvVotes;9687	Firaxis::Array<CvEspionageSpy*, MAX_MAJOR_CIVS> apSpy;9688	CvCity* pCapital = GetPlayer()->getCapitalCity();9689	if(!pCapital)9690	{9691		return;9692	}96939694	for(uint ui = 0; ui < MAX_MAJOR_CIVS; ui++)9695	{9696		PlayerTypes eEspionagePlayer = (PlayerTypes)ui;9697		CvPlayerEspionage* pPlayerEspionage = GET_PLAYER(eEspionagePlayer).GetEspionage();9698		int iVotes = 0;9699		int iLoop;9700		apSpy[ui] = NULL;97019702		if (!GET_PLAYER(eEspionagePlayer).isAlive())9703		{9704			continue;9705		}97069707		for(CvCity* pCity = m_pPlayer->firstCity(&iLoop); pCity != NULL; pCity = m_pPlayer->nextCity(&iLoop))9708		{9709			CvCityEspionage* pCityEspionage = pCity->GetCityEspionage();9710			int iSpyID = pCityEspionage->m_aiSpyAssignment[eEspionagePlayer];9711			// if no spies are assigned here, continue9712			if(iSpyID == -1)9713			{9714				continue;9715			}97169717			// on election day, evaluate spy to be reassigned9718			pPlayerEspionage->m_aSpyList[iSpyID].m_bEvaluateReassignment = true;97199720			// if the spy assigned here is not rigging the election yet, continue9721			if(pPlayerEspionage->m_aSpyList[iSpyID].m_eSpyState != SPY_STATE_RIG_ELECTION)9722			{9723				continue;9724			}97259726			apSpy[ui] = &(pPlayerEspionage->m_aSpyList[iSpyID]);97279728			iVotes += (pCityEspionage->m_aiAmount[eEspionagePlayer] * (100 + m_pPlayer->GetPlayerPolicies()->GetNumericModifier(POLICYMOD_RIGGING_ELECTION_MODIFIER))) / 100;97299730			// now that votes are counted, remove the progress from the spy9731			pCityEspionage->ResetProgress(eEspionagePlayer);97329733			int iRate = pPlayerEspionage->CalcPerTurn(SPY_STATE_RIG_ELECTION, pCity, iSpyID);9734			int iGoal = pPlayerEspionage->CalcRequired(SPY_STATE_RIG_ELECTION, pCity, iSpyID);9735			pCityEspionage->SetActivity(eEspionagePlayer, 0, iRate, iGoal);9736			pCityEspionage->SetLastProgress(eEspionagePlayer, iRate);9737		}97389739		if(iVotes > 0)9740		{9741			wvVotes.push_back(eEspionagePlayer, iVotes);9742		}9743	}97449745	if(wvVotes.size() > 0)9746	{9747		RandomNumberDelegate fcn;9748		fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);9749		PlayerTypes eElectionWinner = wvVotes.ChooseByWeight(&fcn, "Choosing CS election winner by weight");97509751		for(uint ui = 0; ui < MAX_MAJOR_CIVS; ui++)9752		{9753			PlayerTypes ePlayer = (PlayerTypes)ui;97549755			if(ePlayer == eElectionWinner)9756			{9757				CvNotifications* pNotifications = GET_PLAYER(ePlayer).GetNotifications();9758				if(pNotifications)9759				{9760					Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_SUCCESS_S");9761					strSummary << pCapital->getNameKey();9762					Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_SUCCESS");9763					strNotification << GET_PLAYER(ePlayer).GetEspionage()->GetSpyRankName(apSpy[ui]->m_eRank);9764#if defined(MOD_BUGFIX_SPY_NAMES)9765					strNotification << apSpy[ui]->GetSpyName(&GET_PLAYER(ePlayer));9766#else9767					strNotification << GET_PLAYER(ePlayer).getCivilizationInfo().getSpyNames(apSpy[ui]->m_iName);9768#endif9769					strNotification << pCapital->getNameKey();9770					pNotifications->Add(NOTIFICATION_SPY_RIG_ELECTION_SUCCESS, strNotification.toUTF8(), strSummary.toUTF8(), pCapital->getX(), pCapital->getY(), -1);9771				}97729773				ChangeFriendshipWithMajor(ePlayer, GC.getESPIONAGE_INFLUENCE_GAINED_FOR_RIGGED_ELECTION(), false);97749775#if !defined(NO_ACHIEVEMENTS)9776				//Achievements!9777				if(ePlayer == GC.getGame().getActivePlayer())9778				{9779					gDLL->UnlockAchievement(ACHIEVEMENT_XP1_14);9780				}9781#endif9782			}9783			else9784			{9785				int iFriendship = GetEffectiveFriendshipWithMajor(ePlayer);9786				int iRelationshipAnchor = GetFriendshipAnchorWithMajor(ePlayer);9787				bool bFriends = IsFriends(ePlayer);9788				bool bMet = GET_TEAM(GET_PLAYER(ePlayer).getTeam()).isHasMet(m_pPlayer->getTeam());97899790				// if they have a spy in the city9791				if(apSpy[ui] != NULL)9792				{9793					CvNotifications* pNotifications = GET_PLAYER(ePlayer).GetNotifications();9794					if(pNotifications)9795					{9796						Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_FAILURE_S");9797						strSummary << pCapital->getNameKey();9798						Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_FAILURE");9799						strNotification << GET_PLAYER(ePlayer).GetEspionage()->GetSpyRankName(apSpy[ui]->m_eRank);9800#if defined(MOD_BUGFIX_SPY_NAMES)9801						strNotification << apSpy[ui]->GetSpyName(&GET_PLAYER(ePlayer));9802#else9803						strNotification << GET_PLAYER(ePlayer).getCivilizationInfo().getSpyNames(apSpy[ui]->m_iName);9804#endif9805						strNotification << pCapital->getNameKey();9806						strNotification << GET_PLAYER(eElectionWinner).getCivilizationShortDescriptionKey();9807						pNotifications->Add(NOTIFICATION_SPY_RIG_ELECTION_FAILURE, strNotification.toUTF8(), strSummary.toUTF8(), pCapital->getX(), pCapital->getY(), -1);9808					}9809				}9810				else if (bMet && (bFriends || iFriendship > iRelationshipAnchor))9811				{9812					// no spy in the city, so just give them an alert that scenanigans are going on9813					CvNotifications* pNotifications = GET_PLAYER(ePlayer).GetNotifications();9814					if(pNotifications)9815					{9816						Localization::String strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_ALERT_S");9817						strSummary << pCapital->getNameKey();9818						Localization::String strNotification = Localization::Lookup("TXT_KEY_NOTIFICATION_SPY_RIG_ELECTION_ALERT");9819						strNotification << pCapital->getNameKey();9820						pNotifications->Add(NOTIFICATION_SPY_RIG_ELECTION_ALERT, strNotification.toUTF8(), strSummary.toUTF8(), pCapital->getX(), pCapital->getY(), -1);9821					}9822				}98239824				if (GetEffectiveFriendshipWithMajorTimes100(ePlayer) > 0)9825				{9826					int iDiminishAmount = min(GC.getESPIONAGE_INFLUENCE_LOST_FOR_RIGGED_ELECTION() * 100, GetEffectiveFriendshipWithMajorTimes100(ePlayer));9827					ChangeFriendshipWithMajorTimes100(ePlayer, -iDiminishAmount, false);9828				}9829			}9830		}9831	}98329833	GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);9834	GC.GetEngineUserInterface()->setDirty(CityInfo_DIRTY_BIT, true);9835}

Calls

Called by