CvUnitPromotions::ChangePromotionAfterCombat(PromotionTypes)
- Defined in
- CvPromotionClasses.cpp, line 2342
- Class
- CvUnitPromotions
- Hook name
CivHooks::CvUnitPromotions_ChangePromotionAfterCombat- Lua events
GameEvents.CanHavePromotion,GameEvents.UnitCanHavePromotion
Hooks
static bool BeforeCvUnitPromotions_ChangePromotionAfterCombat(CvUnitPromotions* self, PromotionTypes eIndex, PromotionTypes& result);static void AfterCvUnitPromotions_ChangePromotionAfterCombat(CvUnitPromotions* self, PromotionTypes eIndex, PromotionTypes& result);static PromotionTypes ReplaceCvUnitPromotions_ChangePromotionAfterCombat(PromotionTypes (*original)(CvUnitPromotions*, PromotionTypes), CvUnitPromotions* self, PromotionTypes eIndex);CivRegisterBefore<CivHooks::CvUnitPromotions_ChangePromotionAfterCombat>(host, &BeforeCvUnitPromotions_ChangePromotionAfterCombat);CivRegisterAfter<CivHooks::CvUnitPromotions_ChangePromotionAfterCombat>(host, &AfterCvUnitPromotions_ChangePromotionAfterCombat);CivRegisterReplace<CivHooks::CvUnitPromotions_ChangePromotionAfterCombat>(host, &ReplaceCvUnitPromotions_ChangePromotionAfterCombat);
Code
2341// Swap to a new promotion after a combat - returns new promotion we switched to2342PromotionTypes CvUnitPromotions::ChangePromotionAfterCombat(PromotionTypes eIndex)2343{2344 std::vector<int> aPossiblePromotions;23452346 for (int iI = 0; iI < m_pPromotions->GetNumPromotions(); iI++)2347 {2348 CvPromotionEntry *pkEntry = m_pPromotions->GetEntry(eIndex);2349 if (pkEntry && pkEntry->IsPostCombatRandomPromotion(iI))2350 {2351 if (!pkEntry->ArePostCombatPromotionsExclusive() || !IsInUseByPlayer((PromotionTypes)iI, m_pUnit->getOwner()))2352 {2353#if defined(MOD_EVENTS_UNIT_UPGRADES)2354 if (MOD_EVENTS_UNIT_UPGRADES) {2355 if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_CanHavePromotion, m_pUnit->getOwner(), m_pUnit->GetID(), iI) == GAMEEVENTRETURN_FALSE) {2356 continue;2357 }23582359 if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_UnitCanHavePromotion, m_pUnit->getOwner(), m_pUnit->GetID(), iI) == GAMEEVENTRETURN_FALSE) {2360 continue;2361 }2362 }2363#endif2364 aPossiblePromotions.push_back(iI);2365 }2366 }2367 }23682369 int iNumChoices = aPossiblePromotions.size();2370 if (iNumChoices > 0)2371 {2372 int iChoice = GC.getGame().getJonRandNum(iNumChoices, "Random Promotion Pick");2373 return (PromotionTypes)aPossiblePromotions[iChoice];2374 }23752376 return NO_PROMOTION;2377}
Calls
- CustomMods::eventTestAll(const char *, const char *, ...)
- CustomMods::isEVENTS_UNIT_UPGRADES()
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getGame()
- CvPromotionEntry::ArePostCombatPromotionsExclusive() const
- CvPromotionEntry::IsPostCombatRandomPromotion(int) const
- CvPromotionXMLEntries::GetEntry(int)
- CvPromotionXMLEntries::GetNumPromotions()
- CvUnit::GetID() const
- CvUnit::getOwner() const
- CvUnitPromotions::IsInUseByPlayer(PromotionTypes, PlayerTypes)
std::vector::operator[]std::vector::push_backstd::vector::sizestd::vector::vector