CvPlayer::GetMostUnhappyCity()
- Defined in
- CvPlayer.cpp, line 11924
- Class
- CvPlayer
- Hook name
CivHooks::CvPlayer_GetMostUnhappyCity
Hooks
static bool BeforeCvPlayer_GetMostUnhappyCity(CvPlayer* self, CvCity *& result);static void AfterCvPlayer_GetMostUnhappyCity(CvPlayer* self, CvCity *& result);static CvCity * ReplaceCvPlayer_GetMostUnhappyCity(CvCity * (*original)(CvPlayer*), CvPlayer* self);CivRegisterBefore<CivHooks::CvPlayer_GetMostUnhappyCity>(host, &BeforeCvPlayer_GetMostUnhappyCity);CivRegisterAfter<CivHooks::CvPlayer_GetMostUnhappyCity>(host, &AfterCvPlayer_GetMostUnhappyCity);CivRegisterReplace<CivHooks::CvPlayer_GetMostUnhappyCity>(host, &ReplaceCvPlayer_GetMostUnhappyCity);
Code
11923// Calculate city that will want to revolt11924CvCity *CvPlayer::GetMostUnhappyCity()11925{11926 CvCity *pRtnValue = NULL;11927 int iHighestUnhappiness = -1;1192811929 if (getNumCities() > 1)11930 {11931 PolicyBranchTypes ePreferredIdeology = GetCulture()->GetPublicOpinionPreferredIdeology();1193211933 int iLoop;11934 CvCity* pLoopCity;11935 for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))11936 {11937 if (pLoopCity->isCapital())11938 {11939 continue;11940 }1194111942 // Start with population11943 int iUnhappiness = pLoopCity->getPopulation();1194411945 // Subtract off local unhappiness11946 iUnhappiness -= pLoopCity->GetLocalHappiness(); 1194711948 // Look at each civ11949 for (int iLoopPlayer = 0; iLoopPlayer < MAX_MAJOR_CIVS; iLoopPlayer++)11950 {11951 CvPlayer &kPlayer = GET_PLAYER((PlayerTypes)iLoopPlayer);11952 if (iLoopPlayer != GetID() && kPlayer.isAlive() && !kPlayer.isMinorCiv())11953 {11954 PolicyBranchTypes eOtherCivIdeology = kPlayer.GetPlayerPolicies()->GetLateGamePolicyTree();11955 if (eOtherCivIdeology == ePreferredIdeology)11956 {11957 int iCulturalDominanceOverUs = kPlayer.GetCulture()->GetInfluenceLevel(GetID()) - GetCulture()->GetInfluenceLevel((PlayerTypes)iLoopPlayer);11958 if (iCulturalDominanceOverUs > 0 && kPlayer.getCapitalCity() != NULL)11959 {11960 // Find how far their capital is from this city11961 int iCapitalDistance = plotDistance(pLoopCity->getX(), pLoopCity->getY(), kPlayer.getCapitalCity()->getX(), kPlayer.getCapitalCity()->getY());11962 if (iCapitalDistance < 100)11963 {11964 int iDistanceFactor = 100 - iCapitalDistance;11965 iDistanceFactor = (int)sqrt((float)iDistanceFactor);11966 iUnhappiness += (iDistanceFactor * iCulturalDominanceOverUs);11967 }11968 }11969 }11970 }11971 }1197211973 if (iUnhappiness > iHighestUnhappiness)11974 {11975 iHighestUnhappiness = iUnhappiness;11976 pRtnValue = pLoopCity;11977 }11978 }11979 }1198011981 return pRtnValue;11982}
Calls
- CvCity::GetLocalHappiness() const
- CvCity::getPopulation(bool) const
- CvCity::getX() const
- CvCity::getY() const
- CvCity::isCapital() const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::getCapitalCity()
- CvPlayer::GetCulture() const
- CvPlayer::GetID() const
- CvPlayer::getNumCities() const
- CvPlayer::GetPlayerPolicies() const
- CvPlayer::isAlive() const
- CvPlayer::isMinorCiv() const
- CvPlayer::nextCity(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlayerCulture::GetInfluenceLevel(PlayerTypes) const
- CvPlayerCulture::GetPublicOpinionPreferredIdeology() const
- CvPlayerPolicies::GetLateGamePolicyTree() const
- plotDistance(int, int, int, int)
sqrt