Bazaar developer reference

CvPlayer::DoDeficit()

Defined in
CvPlayer.cpp, line 18964
Class
CvPlayer
Hook name
CivHooks::CvPlayer_DoDeficit

Hooks

static bool BeforeCvPlayer_DoDeficit(CvPlayer* self);static void AfterCvPlayer_DoDeficit(CvPlayer* self);static void ReplaceCvPlayer_DoDeficit(void (*original)(CvPlayer*), CvPlayer* self);CivRegisterBefore<CivHooks::CvPlayer_DoDeficit>(host, &BeforeCvPlayer_DoDeficit);CivRegisterAfter<CivHooks::CvPlayer_DoDeficit>(host, &AfterCvPlayer_DoDeficit);CivRegisterReplace<CivHooks::CvPlayer_DoDeficit>(host, &ReplaceCvPlayer_DoDeficit);

Code

18963/// Player spending too much cash?18964void CvPlayer::DoDeficit()18965{18966	int iNumMilitaryUnits = 0;1896718968	CvUnit* pLoopUnit;18969	int iLoop;18970	for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))18971	{18972		if(pLoopUnit->IsCombatUnit())18973			iNumMilitaryUnits++;18974	}1897518976	// If the player has more units than cities, start disbanding things18977	if(iNumMilitaryUnits > getNumCities())18978	{18979		if(GC.getGame().getJonRandNum(100, "Disband rand") < 50)18980		{18981			UnitHandle pLandUnit;18982			UnitHandle pNavalUnit;18983			int iLandScore = MAX_INT;18984			int iNavalScore = MAX_INT;1898518986			// Look for obsolete land units if in deficit or have sufficient units18987			if(GetMilitaryAI()->GetLandDefenseState() <= DEFENSE_STATE_NEUTRAL)18988			{18989				pLandUnit = GetMilitaryAI()->FindBestUnitToScrap(true /*bLand*/, true /*bDeficitForcedDisband*/, iLandScore);18990			}1899118992			// Look for obsolete naval units if in deficit or have sufficient units18993			if(GetMilitaryAI()->GetNavalDefenseState() <= DEFENSE_STATE_NEUTRAL)18994			{18995				pNavalUnit = GetMilitaryAI()->FindBestUnitToScrap(false/*bNaval*/, true /*bDeficitForcedDisband*/, iNavalScore);18996			}1899718998			if(iLandScore < MAX_INT && (GetMilitaryAI()->GetLandDefenseState() <= GetMilitaryAI()->GetNavalDefenseState() || iLandScore <= iNavalScore))18999			{19000				if(pLandUnit)19001				{19002					CvNotifications* pNotifications = GetNotifications();19003					if(pNotifications)19004					{19005						Localization::String locString = Localization::Lookup("TXT_KEY_NTFN_UNIT_DISBANDED");19006						Localization::String locSummary = Localization::Lookup("TXT_KEY_NTFN_UNIT_DISBANDED_S");19007						pNotifications->Add(NOTIFICATION_UNIT_DIED, locString.toUTF8(), locSummary.toUTF8(), pLandUnit->getX(), pLandUnit->getY(), pLandUnit->getUnitType(), GetID());19008					}1900919010					pLandUnit->scrap();19011					GetMilitaryAI()->LogDeficitScrapUnit(pLandUnit);19012				}19013			}19014			else if(iNavalScore < MAX_INT)19015			{19016				if(pNavalUnit)19017				{19018					CvNotifications* pNotifications = GetNotifications();19019					if(pNotifications)19020					{19021						Localization::String locString = Localization::Lookup("TXT_KEY_NTFN_UNIT_DISBANDED");19022						Localization::String locSummary = Localization::Lookup("TXT_KEY_NTFN_UNIT_DISBANDED_S");19023						pNotifications->Add(NOTIFICATION_UNIT_DIED, locString.toUTF8(), locSummary.toUTF8(), pNavalUnit->getX(), pNavalUnit->getY(), pNavalUnit->getUnitType(), GetID());19024					}1902519026					pNavalUnit->scrap();19027					GetMilitaryAI()->LogDeficitScrapUnit(pNavalUnit);19028				}19029			}19030		}19031	}19032}

Calls

Called by