Bazaar developer reference

CvPlayer::ChangeFreePromotionCount(PromotionTypes, int)

Defined in
CvPlayer.cpp, line 20361
Class
CvPlayer
Hook name
CivHooks::CvPlayer_ChangeFreePromotionCount

Hooks

static bool BeforeCvPlayer_ChangeFreePromotionCount(CvPlayer* self, PromotionTypes ePromotion, int iChange);static void AfterCvPlayer_ChangeFreePromotionCount(CvPlayer* self, PromotionTypes ePromotion, int iChange);static void ReplaceCvPlayer_ChangeFreePromotionCount(void (*original)(CvPlayer*, PromotionTypes, int), CvPlayer* self, PromotionTypes ePromotion, int iChange);CivRegisterBefore<CivHooks::CvPlayer_ChangeFreePromotionCount>(host, &BeforeCvPlayer_ChangeFreePromotionCount);CivRegisterAfter<CivHooks::CvPlayer_ChangeFreePromotionCount>(host, &AfterCvPlayer_ChangeFreePromotionCount);CivRegisterReplace<CivHooks::CvPlayer_ChangeFreePromotionCount>(host, &ReplaceCvPlayer_ChangeFreePromotionCount);

Code

20360/// Is ePromotion a free promotion?20361void CvPlayer::ChangeFreePromotionCount(PromotionTypes ePromotion, int iChange)20362{20363	CvAssertMsg(ePromotion >= 0, "ePromotion is expected to be non-negative (invalid Index)");20364	CvAssertMsg(ePromotion < GC.getNumPromotionInfos(), "ePromotion is expected to be within maximum bounds (invalid Index)");2036520366	if(iChange != 0)20367	{20368		bool bWasFree = IsFreePromotion(ePromotion);2036920370		m_paiFreePromotionCount.setAt(ePromotion, m_paiFreePromotionCount[ePromotion] + iChange);2037120372		CvAssert(GetFreePromotionCount(ePromotion) >= 0);2037320374		// This promotion is now set to be free, but wasn't before we called this function20375		if(IsFreePromotion(ePromotion) && !bWasFree)20376		{20377			// Loop through Units20378			CvUnit* pLoopUnit;2037920380			int iLoop;20381			for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))20382			{20383				// Valid Promotion for this Unit?20384				if(::IsPromotionValidForUnitCombatType(ePromotion, pLoopUnit->getUnitType()))20385				{20386					pLoopUnit->setHasPromotion(ePromotion, true);20387				}2038820389				else if(::IsPromotionValidForCivilianUnitType(ePromotion, pLoopUnit->getUnitType()))20390				{20391					pLoopUnit->setHasPromotion(ePromotion, true);20392				}20393			}20394		}20395	}20396}

Calls

Called by