Hooks
static bool BeforeCvPlayer_setCombatExperienceTimes100(CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);static void AfterCvPlayer_setCombatExperienceTimes100(CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);static void ReplaceCvPlayer_setCombatExperienceTimes100(void (*original)(CvPlayer*, int, CvUnit*), CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);CivRegisterBefore<CivHooks::CvPlayer_setCombatExperienceTimes100>(host, &BeforeCvPlayer_setCombatExperienceTimes100);CivRegisterAfter<CivHooks::CvPlayer_setCombatExperienceTimes100>(host, &AfterCvPlayer_setCombatExperienceTimes100);CivRegisterReplace<CivHooks::CvPlayer_setCombatExperienceTimes100>(host, &ReplaceCvPlayer_setCombatExperienceTimes100);
Code
17089#if defined(MOD_GLOBAL_LOCAL_GENERALS)17090#if defined(MOD_UNITS_XP_TIMES_100)17091void CvPlayer::setCombatExperienceTimes100(int iExperienceTimes100, CvUnit* pFromUnit)17092#else17093void CvPlayer::setCombatExperience(int iExperience, CvUnit* pFromUnit)17094#endif17095#else17096#if defined(MOD_UNITS_XP_TIMES_100)17097void CvPlayer::setCombatExperienceTimes100(int iExperienceTimes100)17098#else17099void CvPlayer::setCombatExperience(int iExperience)17100#endif17101#endif17102{17103 CvAssert(iExperience >= 0);1710417105#if defined(MOD_UNITS_XP_TIMES_100)17106 if (iExperienceTimes100 != getCombatExperienceTimes100())17107#else17108 if (iExperience != getCombatExperience())17109#endif17110 {17111#if defined(MOD_UNITS_XP_TIMES_100)17112 m_iCombatExperienceTimes100 = iExperienceTimes100;17113#else17114 m_iCombatExperience = iExperience;17115#endif1711617117 // Enough XP for a Great General to appear?17118 if(!isBarbarian())17119 {17120#if defined(MOD_UNITS_XP_TIMES_100)17121 int iExperienceThresholdTimes100 = greatGeneralThreshold() * 100;17122 if (m_iCombatExperienceTimes100 >= iExperienceThresholdTimes100 && iExperienceThresholdTimes100 > 0)17123#else17124 int iExperienceThreshold = greatGeneralThreshold();17125 if (m_iCombatExperience >= iExperienceThreshold && iExperienceThreshold > 0)17126#endif17127 {17128 // create great person17129 CvCity* pBestCity = NULL;17130#if defined(MOD_GLOBAL_LOCAL_GENERALS)17131 if(pFromUnit == NULL)17132 {17133#endif17134 int iBestValue = INT_MAX;17135 int iLoop;17136 for(CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))17137 {17138 int iValue = 4 * GC.getGame().getJonRandNum(getNumCities(), "Great General City Selection");1713917140 for(int i = 0; i < NUM_YIELD_TYPES; i++)17141 {17142 iValue += pLoopCity->findYieldRateRank((YieldTypes)i);17143 }17144 iValue += pLoopCity->findPopulationRank();1714517146 if(iValue < iBestValue)17147 {17148 pBestCity = pLoopCity;17149 iBestValue = iValue;17150 }17151 }17152#if defined(MOD_GLOBAL_LOCAL_GENERALS)17153 }17154#endif1715517156#if defined(MOD_GLOBAL_LOCAL_GENERALS)17157 if(pBestCity || pFromUnit)17158#else17159 if(pBestCity)17160#endif17161 {17162 // Figure out which Promotion is the one which makes a unit a Great General17163 PromotionTypes eGreatGeneralPromotion = NO_PROMOTION;17164 for(int iI = 0; iI < GC.getNumPromotionInfos(); iI++)17165 {17166 const PromotionTypes eLoopPromotion = static_cast<PromotionTypes>(iI);17167 CvPromotionEntry* pkPromotionInfo = GC.getPromotionInfo(eLoopPromotion);17168 if(pkPromotionInfo)17169 {17170 if(pkPromotionInfo->IsGreatGeneral())17171 {17172 eGreatGeneralPromotion = eLoopPromotion;17173 break;17174 }17175 }17176 }1717717178 // If GG promotion exists, find a unit which gets it for free (i.e. the Great General unit itself)17179 if(eGreatGeneralPromotion != NO_PROMOTION)17180 {17181 for(int iI = 0; iI < GC.getNumUnitInfos(); iI++)17182 {17183 const UnitTypes eLoopUnit = static_cast<UnitTypes>(iI);17184 CvUnitEntry* pkUnitInfo = GC.getUnitInfo(eLoopUnit);17185 if(pkUnitInfo)17186 {17187 if(pkUnitInfo->GetFreePromotions(eGreatGeneralPromotion))17188 {17189 // Is this the right unit of this class for this civ?17190 const UnitTypes eUnit = (UnitTypes) getCivilizationInfo().getCivilizationUnits((UnitClassTypes)pkUnitInfo->GetUnitClassType());1719117192 if(eUnit == eLoopUnit)17193 {17194#if defined(MOD_GLOBAL_LOCAL_GENERALS)17195 if(pFromUnit)17196 {17197 CUSTOMLOG("Create Great General at (%d, %d) from unit %s", pFromUnit->plot()->getX(), pFromUnit->plot()->getY(), pFromUnit->getName().GetCString());17198#if defined(MOD_GLOBAL_TRULY_FREE_GP)17199 createGreatGeneral(eUnit, pFromUnit->plot()->getX(), pFromUnit->plot()->getY(), false);17200#else17201 createGreatGeneral(eUnit, pFromUnit->plot()->getX(), pFromUnit->plot()->getY());17202#endif17203 }17204 else17205 {17206#endif17207#if defined(MOD_GLOBAL_TRULY_FREE_GP)17208 pBestCity->createGreatGeneral(eUnit, false);17209#else17210 pBestCity->createGreatGeneral(eUnit);17211#endif17212#if defined(MOD_GLOBAL_LOCAL_GENERALS)17213 }17214#endif17215#if defined(MOD_UNITS_XP_TIMES_100)17216 setCombatExperienceTimes100(getCombatExperienceTimes100() - iExperienceThresholdTimes100);17217#else17218 setCombatExperience(getCombatExperience() - iExperienceThreshold);17219#endif17220 break;17221 }17222 }17223 }17224 }17225 }17226 }17227 }17228 }17229 }17230}