Bazaar developer reference

isPromotionValid(PromotionTypes, UnitTypes, bool, bool)

Defined in
CvGameCoreUtils.cpp, line 288
Hook name
CivHooks::isPromotionValid

Hooks

static bool BeforeisPromotionValid(PromotionTypes ePromotion, UnitTypes eUnit, bool bLeader, bool bTestingPrereq, bool& result);static void AfterisPromotionValid(PromotionTypes ePromotion, UnitTypes eUnit, bool bLeader, bool bTestingPrereq, bool& result);static bool ReplaceisPromotionValid(bool (*original)(PromotionTypes, UnitTypes, bool, bool), PromotionTypes ePromotion, UnitTypes eUnit, bool bLeader, bool bTestingPrereq);CivRegisterBefore<CivHooks::isPromotionValid>(host, &BeforeisPromotionValid);CivRegisterAfter<CivHooks::isPromotionValid>(host, &AfterisPromotionValid);CivRegisterReplace<CivHooks::isPromotionValid>(host, &ReplaceisPromotionValid);

Code

288bool isPromotionValid(PromotionTypes ePromotion, UnitTypes eUnit, bool bLeader, bool bTestingPrereq)289{290	CvUnitEntry* unitInfo = GC.getUnitInfo(eUnit);291	CvPromotionEntry* promotionInfo = GC.getPromotionInfo(ePromotion);292293	if(unitInfo == NULL || promotionInfo == NULL)294		return false;295296	// Can this Promotion not be chosen through normal leveling?297	if(!bTestingPrereq && promotionInfo->IsCannotBeChosen())298	{299		return false;300	}301302	// If a Unit gets a Promotion for free then hand it out, no questions asked303	if(unitInfo->GetFreePromotions(ePromotion))304	{305		return true;306	}307308	// If this isn't a combat Unit, no Promotion309	if(unitInfo->GetUnitCombatType() == NO_UNITCOMBAT)310	{311		return false;312	}313314	// Is this a valid Promotion for the UnitCombatType?315	if(!::IsPromotionValidForUnitCombatType(ePromotion, eUnit))316	{317		return false;318	}319320	if(!bLeader && promotionInfo->IsLeader())321	{322		return false;323	}324325	// If the Unit only has one move then Blitz is not useful326	if(unitInfo->GetMoves() == 1)327	{328		if(promotionInfo->IsBlitz())329		{330			return false;331		}332	}333334	// Promotion Prereqs335	if(NO_PROMOTION != promotionInfo->GetPrereqPromotion())336	{337		if(!isPromotionValid((PromotionTypes)promotionInfo->GetPrereqPromotion(), eUnit, bLeader, true))338		{339			return false;340		}341	}342343	PromotionTypes ePrereq1 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion1();344	PromotionTypes ePrereq2 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion2();345	PromotionTypes ePrereq3 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion3();346	PromotionTypes ePrereq4 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion4();347	PromotionTypes ePrereq5 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion5();348	PromotionTypes ePrereq6 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion6();349	PromotionTypes ePrereq7 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion7();350	PromotionTypes ePrereq8 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion8();351	PromotionTypes ePrereq9 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion9();352	if(ePrereq1 != NO_PROMOTION ||353		ePrereq2 != NO_PROMOTION ||354		ePrereq3 != NO_PROMOTION ||355		ePrereq4 != NO_PROMOTION ||356		ePrereq5 != NO_PROMOTION ||357		ePrereq6 != NO_PROMOTION ||358		ePrereq7 != NO_PROMOTION ||359		ePrereq8 != NO_PROMOTION ||360		ePrereq9 != NO_PROMOTION)361	{362		bool bValid = false;363		if(!bValid)364		{365			if(NO_PROMOTION != ePrereq1 && isPromotionValid(ePrereq1, eUnit, bLeader, true))366			{367				bValid = true;368			}369		}370371		if(!bValid)372		{373			if(NO_PROMOTION != ePrereq2 && isPromotionValid(ePrereq2, eUnit, bLeader, true))374			{375				bValid = true;376			}377		}378379		if(!bValid)380		{381			if(NO_PROMOTION != ePrereq3 && isPromotionValid(ePrereq3, eUnit, bLeader, true))382			{383				bValid = true;384			}385		}386387		if(!bValid)388		{389			if(NO_PROMOTION != ePrereq4 && isPromotionValid(ePrereq4, eUnit, bLeader, true))390			{391				bValid = true;392			}393		}394395		if(!bValid)396		{397			if(NO_PROMOTION != ePrereq5 && isPromotionValid(ePrereq5, eUnit, bLeader, true))398			{399				bValid = true;400			}401		}402403		if(!bValid)404		{405			if(NO_PROMOTION != ePrereq6 && isPromotionValid(ePrereq6, eUnit, bLeader, true))406			{407				bValid = true;408			}409		}410411		if(!bValid)412		{413			if(NO_PROMOTION != ePrereq7 && isPromotionValid(ePrereq7, eUnit, bLeader, true))414			{415				bValid = true;416			}417		}418419		if(!bValid)420		{421			if(NO_PROMOTION != ePrereq8 && isPromotionValid(ePrereq8, eUnit, bLeader, true))422			{423				bValid = true;424			}425		}426427		if(!bValid)428		{429			if(NO_PROMOTION != ePrereq9 && isPromotionValid(ePrereq9, eUnit, bLeader, true))430			{431				bValid = true;432			}433		}434435		if(!bValid)436		{437			return false;438		}439	}440441	return true;442}

Calls

Called by