bool isPromotionValid(PromotionTypes ePromotion, UnitTypes eUnit, bool bLeader, bool bTestingPrereq) { CvUnitEntry* unitInfo = GC.getUnitInfo(eUnit); CvPromotionEntry* promotionInfo = GC.getPromotionInfo(ePromotion); if(unitInfo == NULL || promotionInfo == NULL) return false; // Can this Promotion not be chosen through normal leveling? if(!bTestingPrereq && promotionInfo->IsCannotBeChosen()) { return false; } // If a Unit gets a Promotion for free then hand it out, no questions asked if(unitInfo->GetFreePromotions(ePromotion)) { return true; } // If this isn't a combat Unit, no Promotion if(unitInfo->GetUnitCombatType() == NO_UNITCOMBAT) { return false; } // Is this a valid Promotion for the UnitCombatType? if(!::IsPromotionValidForUnitCombatType(ePromotion, eUnit)) { return false; } if(!bLeader && promotionInfo->IsLeader()) { return false; } // If the Unit only has one move then Blitz is not useful if(unitInfo->GetMoves() == 1) { if(promotionInfo->IsBlitz()) { return false; } } // Promotion Prereqs if(NO_PROMOTION != promotionInfo->GetPrereqPromotion()) { if(!isPromotionValid((PromotionTypes)promotionInfo->GetPrereqPromotion(), eUnit, bLeader, true)) { return false; } } PromotionTypes ePrereq1 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion1(); PromotionTypes ePrereq2 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion2(); PromotionTypes ePrereq3 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion3(); PromotionTypes ePrereq4 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion4(); PromotionTypes ePrereq5 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion5(); PromotionTypes ePrereq6 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion6(); PromotionTypes ePrereq7 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion7(); PromotionTypes ePrereq8 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion8(); PromotionTypes ePrereq9 = (PromotionTypes)promotionInfo->GetPrereqOrPromotion9(); if(ePrereq1 != NO_PROMOTION || ePrereq2 != NO_PROMOTION || ePrereq3 != NO_PROMOTION || ePrereq4 != NO_PROMOTION || ePrereq5 != NO_PROMOTION || ePrereq6 != NO_PROMOTION || ePrereq7 != NO_PROMOTION || ePrereq8 != NO_PROMOTION || ePrereq9 != NO_PROMOTION) { bool bValid = false; if(!bValid) { if(NO_PROMOTION != ePrereq1 && isPromotionValid(ePrereq1, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq2 && isPromotionValid(ePrereq2, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq3 && isPromotionValid(ePrereq3, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq4 && isPromotionValid(ePrereq4, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq5 && isPromotionValid(ePrereq5, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq6 && isPromotionValid(ePrereq6, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq7 && isPromotionValid(ePrereq7, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq8 && isPromotionValid(ePrereq8, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { if(NO_PROMOTION != ePrereq9 && isPromotionValid(ePrereq9, eUnit, bLeader, true)) { bValid = true; } } if(!bValid) { return false; } } return true; }
bool cyIsPromotionValid(int /*PromotionTypes*/ ePromotion, int /*UnitTypes*/ eUnit, bool bLeader) { return isPromotionValid((PromotionTypes) ePromotion, (UnitTypes) eUnit, bLeader); }