Bazaar developer reference

CvPlayer::GetUnhappinessFromUnits() const

Defined in
CvPlayer.cpp, line 12372
Class
CvPlayer
Hook name
CivHooks::CvPlayer_GetUnhappinessFromUnits

Hooks

static bool BeforeCvPlayer_GetUnhappinessFromUnits(const CvPlayer* self, int& result);static void AfterCvPlayer_GetUnhappinessFromUnits(const CvPlayer* self, int& result);static int ReplaceCvPlayer_GetUnhappinessFromUnits(int (*original)(const CvPlayer*), const CvPlayer* self);CivRegisterBefore<CivHooks::CvPlayer_GetUnhappinessFromUnits>(host, &BeforeCvPlayer_GetUnhappinessFromUnits);CivRegisterAfter<CivHooks::CvPlayer_GetUnhappinessFromUnits>(host, &AfterCvPlayer_GetUnhappinessFromUnits);CivRegisterReplace<CivHooks::CvPlayer_GetUnhappinessFromUnits>(host, &ReplaceCvPlayer_GetUnhappinessFromUnits);

Code

12371/// How much Unhappiness are Units producing?12372int CvPlayer::GetUnhappinessFromUnits() const12373{12374	int iUnhappinessFromUnits = m_iUnhappinessFromUnits;1237512376	int iFreeUnitUnhappiness = /*0*/ GC.getFREE_UNIT_HAPPINESS();12377	if(iFreeUnitUnhappiness != 0)12378	{12379#if defined(MOD_API_EXTENSIONS)12380		// If unhappy is 2 and free happy is 4, we need to subtract 212381		// If unhappy is 5 and free happy is 4, we need to subtract 4 --> these two make "the min of unhappy and free happy"12382		// If unhappy is -2 and free happy is 4, we need to subtract 0 --> this one adds "the previous figure not to be negative"12383		iUnhappinessFromUnits -= std::max(0, std::min(iUnhappinessFromUnits, iFreeUnitUnhappiness));12384#else12385		iUnhappinessFromUnits -= iFreeUnitUnhappiness;12386#endif12387	}1238812389#if !defined(MOD_API_EXTENSIONS)12390	// Can't be less than 012391	if(iUnhappinessFromUnits < 0)12392	{12393		iUnhappinessFromUnits = 0;12394	}12395#endif1239612397#if defined(MOD_API_EXTENSIONS)12398	if(iUnhappinessFromUnits > 0 && GetUnhappinessFromUnitsMod() != 0)12399#else12400	if(GetUnhappinessFromUnitsMod() != 0)12401#endif12402	{12403		iUnhappinessFromUnits *= (100 + GetUnhappinessFromUnitsMod());12404		iUnhappinessFromUnits /= 100;12405	}1240612407	return iUnhappinessFromUnits;12408}

Calls

Called by