Bazaar developer reference

CvUnit::setExperienceTimes100(int, int)

Defined in
CvUnit.cpp, line 17057
Class
CvUnit
Hook name
CivHooks::CvUnit_setExperienceTimes100

Hooks

static bool BeforeCvUnit_setExperienceTimes100(CvUnit* self, int iNewValueTimes100, int iMax);static void AfterCvUnit_setExperienceTimes100(CvUnit* self, int iNewValueTimes100, int iMax);static void ReplaceCvUnit_setExperienceTimes100(void (*original)(CvUnit*, int, int), CvUnit* self, int iNewValueTimes100, int iMax);CivRegisterBefore<CivHooks::CvUnit_setExperienceTimes100>(host, &BeforeCvUnit_setExperienceTimes100);CivRegisterAfter<CivHooks::CvUnit_setExperienceTimes100>(host, &AfterCvUnit_setExperienceTimes100);CivRegisterReplace<CivHooks::CvUnit_setExperienceTimes100>(host, &ReplaceCvUnit_setExperienceTimes100);

Code

17056#if defined(MOD_UNITS_XP_TIMES_100)17057void CvUnit::setExperienceTimes100(int iNewValueTimes100, int iMax)17058#else17059void CvUnit::setExperience(int iNewValue, int iMax)17060#endif17061{17062	VALIDATE_OBJECT17063#if defined(MOD_UNITS_XP_TIMES_100)17064	// Checking limits.h for the values of MAX_INT and MAX_LONG they are the same, so we need to use "long long" and hence MAX_LLONG17065	long long lMaxTimes100 = (iMax == -1) ? INT_MAX : (iMax * 100LL);17066	int iMaxTimes100 = (lMaxTimes100 > ((long long) INT_MAX)) ? INT_MAX : (int) lMaxTimes100;17067	17068	if ((getExperienceTimes100() != iNewValueTimes100) && (getExperienceTimes100() < iMaxTimes100))17069#else17070	if ((getExperience() != iNewValue) && (getExperience() < ((iMax == -1) ? INT_MAX : iMax)))17071#endif17072	{17073#if defined(MOD_UNITS_XP_TIMES_100)17074		int iExperienceChangeTimes100 = iNewValueTimes100 - getExperienceTimes100();17075#else17076		int iExperienceChange = iNewValue - getExperience();17077#endif1707817079#if defined(MOD_UNITS_XP_TIMES_100)17080		if (!MOD_UNITS_XP_TIMES_100) {17081			// If NOT using XP times 100, remove any fractional part17082			iNewValueTimes100 -= (iNewValueTimes100 % 100);17083		}17084		17085		m_iExperienceTimes100 = std::min(iMaxTimes100, iNewValueTimes100);17086		CvAssert(getExperienceTimes100() >= 0);17087#else17088		m_iExperience = std::min(((iMax == -1) ? INT_MAX : iMax), iNewValue);17089		CvAssert(getExperience() >= 0);17090#endif1709117092		if(getOwner() == GC.getGame().getActivePlayer())17093		{17094			// Don't show XP for unit that's about to bite the dust17095			if(!IsDead())17096			{17097				Localization::String localizedText = Localization::Lookup("TXT_KEY_EXPERIENCE_POPUP");17098#if defined(MOD_UNITS_XP_TIMES_100)17099				localizedText << iExperienceChangeTimes100 / 100;17100#else17101				localizedText << iExperienceChange;17102#endif17103#if !defined(SHOW_PLOT_POPUP)17104				float fDelay = GC.getPOST_COMBAT_TEXT_DELAY();17105#endif1710617107				int iX = m_iX;17108				int iY = m_iY;1710917110				// Where do we display this text?17111				const MissionData* pkMissionData = GetHeadMissionData();17112				if(pkMissionData != NULL)17113				{17114					if(pkMissionData->eMissionType == CvTypes::getMISSION_MOVE_TO())17115					{17116						int iTempX = pkMissionData->iData1;17117						int iTempY = pkMissionData->iData2;1711817119						if(GC.getMap().plot(iTempX, iTempY)->getNumVisibleEnemyDefenders(this) == 0)17120						{17121							iX = iTempX;17122							iY = iTempY;17123						}17124					}17125				}1712617127#if defined(SHOW_PLOT_POPUP)17128				SHOW_PLOT_POPUP(GC.getMap().plot(iX, iY), getOwner(), localizedText.toUTF8(), 0.0f);17129#else17130				DLLUI->AddPopupText(iX, iY, localizedText.toUTF8(), fDelay);17131#endif1713217133				if(IsSelected())17134				{17135					DLLUI->setDirty(UnitInfo_DIRTY_BIT, true);17136				}17137			}17138		}17139	}17140}

Calls

Called by