Bazaar developer reference

CvPlayer::GetUnhappinessFromCityCount(CvCity *, CvCity *) const

Defined in
CvPlayer.cpp, line 12525
Class
CvPlayer
Hook name
CivHooks::CvPlayer_GetUnhappinessFromCityCount

Hooks

static bool BeforeCvPlayer_GetUnhappinessFromCityCount(const CvPlayer* self, CvCity* pAssumeCityAnnexed, CvCity* pAssumeCityPuppeted, int& result);static void AfterCvPlayer_GetUnhappinessFromCityCount(const CvPlayer* self, CvCity* pAssumeCityAnnexed, CvCity* pAssumeCityPuppeted, int& result);static int ReplaceCvPlayer_GetUnhappinessFromCityCount(int (*original)(const CvPlayer*, CvCity*, CvCity*), const CvPlayer* self, CvCity* pAssumeCityAnnexed, CvCity* pAssumeCityPuppeted);CivRegisterBefore<CivHooks::CvPlayer_GetUnhappinessFromCityCount>(host, &BeforeCvPlayer_GetUnhappinessFromCityCount);CivRegisterAfter<CivHooks::CvPlayer_GetUnhappinessFromCityCount>(host, &AfterCvPlayer_GetUnhappinessFromCityCount);CivRegisterReplace<CivHooks::CvPlayer_GetUnhappinessFromCityCount>(host, &ReplaceCvPlayer_GetUnhappinessFromCityCount);

Code

12524/// Unhappiness from number of Cities12525int CvPlayer::GetUnhappinessFromCityCount(CvCity* pAssumeCityAnnexed, CvCity* pAssumeCityPuppeted) const12526{12527	int iUnhappiness = 0;12528	int iUnhappinessPerCity = /*2*/ GC.getUNHAPPINESS_PER_CITY() * 100;1252912530	bool bCityValid;1253112532	int iLoop;12533	for(const CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))12534	{12535		bCityValid = false;1253612537		// Assume city is puppeted, and counts12538		if(pLoopCity == pAssumeCityPuppeted)12539			bCityValid = true;12540		// Assume city is annexed, and does NOT count12541		else if(pLoopCity == pAssumeCityAnnexed)12542			bCityValid = false;12543		// Assume city doesn't exist, and does NOT count12544		else if(pLoopCity->IsIgnoreCityForHappiness())12545			bCityValid = false;12546		// Normal city12547		else if(!pLoopCity->IsOccupied() || pLoopCity->IsNoOccupiedUnhappiness())12548			bCityValid = true;1254912550		if(bCityValid)12551			iUnhappiness += iUnhappinessPerCity;12552	}1255312554	// Player count mod12555	int iMod = 0;12556	iMod += GetCityCountUnhappinessMod();12557	iMod += GetPlayerTraits()->GetCityUnhappinessModifier();1255812559	iUnhappiness *= (100 + iMod);12560	iUnhappiness /= 100;1256112562	// Handicap mod12563	iUnhappiness *= getHandicapInfo().getNumCitiesUnhappinessMod();12564	iUnhappiness /= 100;1256512566	// Map size mod12567	iUnhappiness *= GC.getMap().getWorldInfo().getNumCitiesUnhappinessPercent();12568	iUnhappiness /= 100;1256912570	return iUnhappiness;12571}

Calls

Called by