Bazaar developer reference

CvPlayer::setNavalCombatExperienceTimes100(int, CvUnit *)

Defined in
CvPlayer.cpp, line 17305
Class
CvPlayer
Hook name
CivHooks::CvPlayer_setNavalCombatExperienceTimes100

Hooks

static bool BeforeCvPlayer_setNavalCombatExperienceTimes100(CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);static void AfterCvPlayer_setNavalCombatExperienceTimes100(CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);static void ReplaceCvPlayer_setNavalCombatExperienceTimes100(void (*original)(CvPlayer*, int, CvUnit*), CvPlayer* self, int iExperienceTimes100, CvUnit* pFromUnit);CivRegisterBefore<CivHooks::CvPlayer_setNavalCombatExperienceTimes100>(host, &BeforeCvPlayer_setNavalCombatExperienceTimes100);CivRegisterAfter<CivHooks::CvPlayer_setNavalCombatExperienceTimes100>(host, &AfterCvPlayer_setNavalCombatExperienceTimes100);CivRegisterReplace<CivHooks::CvPlayer_setNavalCombatExperienceTimes100>(host, &ReplaceCvPlayer_setNavalCombatExperienceTimes100);

Code

17303#if defined(MOD_GLOBAL_LOCAL_GENERALS)17304#if defined(MOD_UNITS_XP_TIMES_100)17305void CvPlayer::setNavalCombatExperienceTimes100(int iExperienceTimes100, CvUnit* pFromUnit)17306#else17307void CvPlayer::setNavalCombatExperience(int iExperience, CvUnit* pFromUnit)17308#endif17309#else17310#if defined(MOD_UNITS_XP_TIMES_100)17311void CvPlayer::setNavalCombatExperienceTimes100(int iExperienceTimes100)17312#else17313void CvPlayer::setNavalCombatExperience(int iExperience)17314#endif17315#endif17316{17317#if defined(MOD_UNITS_XP_TIMES_100)17318	CvAssert(iExperienceTimes100 >= 0);1731917320	if (iExperienceTimes100 != getNavalCombatExperienceTimes100())17321#else17322	CvAssert(iExperience >= 0);1732317324	if (iExperience != getNavalCombatExperience())17325#endif17326	{17327#if defined(MOD_UNITS_XP_TIMES_100)17328		m_iNavalCombatExperienceTimes100 = iExperienceTimes100;17329#else17330		m_iNavalCombatExperience = iExperience;17331#endif1733217333		// Enough XP for a Great Admiral to appear?17334		if(!isBarbarian())17335		{17336#if defined(MOD_UNITS_XP_TIMES_100)17337			int iExperienceThresholdTimes100 = greatAdmiralThreshold() * 100;17338			if (m_iNavalCombatExperienceTimes100 >= iExperienceThresholdTimes100 && iExperienceThresholdTimes100 > 0)17339#else17340			int iExperienceThreshold = greatAdmiralThreshold();17341			if (m_iNavalCombatExperience >= iExperienceThreshold && iExperienceThreshold > 0)17342#endif17343			{17344				// create great person17345				CvCity* pBestCity = NULL;17346#if defined(MOD_GLOBAL_LOCAL_GENERALS)17347				if(pFromUnit == NULL)17348				{17349#endif17350					int iBestValue = INT_MAX;17351					int iLoop;17352					for(CvCity* pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))17353					{17354						if(!pLoopCity->isCoastal())17355						{17356							continue;17357						}1735817359						int iValue = 4 * GC.getGame().getJonRandNum(getNumCities(), "Great Admiral City Selection");1736017361						for(int i = 0; i < NUM_YIELD_TYPES; i++)17362						{17363							iValue += pLoopCity->findYieldRateRank((YieldTypes)i);17364						}17365						iValue += pLoopCity->findPopulationRank();1736617367						if(iValue < iBestValue)17368						{17369							pBestCity = pLoopCity;17370							iBestValue = iValue;17371						}17372					}17373#if defined(MOD_GLOBAL_LOCAL_GENERALS)17374				}17375#endif1737617377#if defined(MOD_GLOBAL_LOCAL_GENERALS)17378				if(pBestCity || pFromUnit)17379#else17380				if(pBestCity)17381#endif17382				{17383					// Figure out which Promotion is the one which makes a unit a Great Admiral17384					PromotionTypes eGreatAdmiralPromotion = NO_PROMOTION;17385					for(int iI = 0; iI < GC.getNumPromotionInfos(); iI++)17386					{17387						const PromotionTypes eLoopPromotion = static_cast<PromotionTypes>(iI);17388						CvPromotionEntry* pkPromotionInfo = GC.getPromotionInfo(eLoopPromotion);17389						if(pkPromotionInfo)17390						{17391							if(pkPromotionInfo->IsGreatAdmiral())17392							{17393								eGreatAdmiralPromotion = eLoopPromotion;17394							}17395						}17396					}1739717398					// If GA promotion exists, find a unit which gets it for free (i.e. the Great Admiral unit itself)17399					if(eGreatAdmiralPromotion != NO_PROMOTION)17400					{17401						for(int iI = 0; iI < GC.getNumUnitInfos(); iI++)17402						{17403							const UnitTypes eLoopUnit = static_cast<UnitTypes>(iI);17404							CvUnitEntry* pkUnitInfo = GC.getUnitInfo(eLoopUnit);17405							if(pkUnitInfo)17406							{17407								if(pkUnitInfo->GetFreePromotions(eGreatAdmiralPromotion))17408								{17409									// Is this the right unit of this class for this civ?17410									const UnitTypes eUnit = (UnitTypes) getCivilizationInfo().getCivilizationUnits((UnitClassTypes)pkUnitInfo->GetUnitClassType());1741117412									if(eUnit == eLoopUnit)17413									{17414#if defined(MOD_GLOBAL_LOCAL_GENERALS)17415										if(pFromUnit)17416										{17417											CUSTOMLOG("Create Great Admiral at (%d, %d) from unit %s", pFromUnit->plot()->getX(), pFromUnit->plot()->getY(), pFromUnit->getName().GetCString());17418#if defined(MOD_GLOBAL_TRULY_FREE_GP)17419											createGreatAdmiral(eUnit, pFromUnit->plot()->getX(), pFromUnit->plot()->getY(), false);17420#else17421											createGreatAdmiral(eUnit, pFromUnit->plot()->getX(), pFromUnit->plot()->getY());17422#endif1742317424#if defined(MOD_PROMOTIONS_FLAGSHIP)17425											if (MOD_PROMOTIONS_FLAGSHIP) {17426												pFromUnit->setHasPromotion((PromotionTypes)GC.getPROMOTION_FLAGSHIP(), true);17427											}17428#endif17429										}17430										else17431										{17432#endif17433#if defined(MOD_GLOBAL_TRULY_FREE_GP)17434											pBestCity->createGreatAdmiral(eUnit, false);17435#else17436											pBestCity->createGreatAdmiral(eUnit);17437#endif17438#if defined(MOD_GLOBAL_LOCAL_GENERALS)17439										}17440#endif17441#if defined(MOD_UNITS_XP_TIMES_100)17442										setNavalCombatExperienceTimes100(getNavalCombatExperienceTimes100() - iExperienceThresholdTimes100);17443#else17444										setNavalCombatExperience(getNavalCombatExperience() - iExperienceThreshold);17445#endif17446										break;17447									}17448								}17449							}17450						}17451					}17452				}17453			}17454		}17455	}17456}

Calls

Called by