Bazaar developer reference

CvTreasury::CalculateUnitSupply(int &, int &)

Defined in
CvTreasury.cpp, line 614
Class
CvTreasury
Hook name
CivHooks::CvTreasury_CalculateUnitSupply

Hooks

static bool BeforeCvTreasury_CalculateUnitSupply(CvTreasury* self, int& iPaidUnits, int& iBaseSupplyCost, int& result);static void AfterCvTreasury_CalculateUnitSupply(CvTreasury* self, int& iPaidUnits, int& iBaseSupplyCost, int& result);static int ReplaceCvTreasury_CalculateUnitSupply(int (*original)(CvTreasury*, int&, int&), CvTreasury* self, int& iPaidUnits, int& iBaseSupplyCost);CivRegisterBefore<CivHooks::CvTreasury_CalculateUnitSupply>(host, &BeforeCvTreasury_CalculateUnitSupply);CivRegisterAfter<CivHooks::CvTreasury_CalculateUnitSupply>(host, &AfterCvTreasury_CalculateUnitSupply);CivRegisterReplace<CivHooks::CvTreasury_CalculateUnitSupply>(host, &ReplaceCvTreasury_CalculateUnitSupply);

Code

613/// Compute unit supply for the turn (returns component info)614int CvTreasury::CalculateUnitSupply(int& iPaidUnits, int& iBaseSupplyCost)615{616	int iSupply;617618	iPaidUnits = std::max(0, (m_pPlayer->getNumOutsideUnits() - /*3*/ GC.getINITIAL_FREE_OUTSIDE_UNITS()));619620	// JON: This is set to 0 right now, which pretty much means it's disabled621	iBaseSupplyCost = iPaidUnits* /*0*/ GC.getINITIAL_OUTSIDE_UNIT_GOLD_PERCENT();622	iBaseSupplyCost /= 100;623624	iSupply = iBaseSupplyCost;625626	CvHandicapInfo& playerHandicap = m_pPlayer->getHandicapInfo();627	iSupply *= playerHandicap.getUnitCostPercent();628	iSupply /= 100;629630	if(!m_pPlayer->isHuman() && !m_pPlayer->IsAITeammateOfHuman() && !m_pPlayer->isBarbarian())631	{632		//iSupply *= gameHandicap->getAIUnitSupplyPercent();	// This is no longer valid633		//iSupply /= 100;634635		iSupply *= std::max(0, ((GC.getGame().getHandicapInfo().getAIPerEraModifier() * m_pPlayer->GetCurrentEra()) + 100));636		iSupply /= 100;637	}638639	// Game progress factor ranges from 0.0 to 1.0 based on how far into the game we are640	double fGameProgressFactor = float(GC.getGame().getElapsedGameTurns()) / GC.getGame().getEstimateEndTurn();641642	// Multiplicative increase - helps scale costs as game goes on - the HIGHER this number the more is paid643	double fMultiplyFactor = 1.0 + (fGameProgressFactor* /*8*/ GC.getUNIT_MAINTENANCE_GAME_MULTIPLIER());644	// Exponential increase - this one really punishes those with a HUGE military - the LOWER this number the more is paid645	double fExponentialFactor = 1.0 + (fGameProgressFactor / /*7*/ GC.getUNIT_MAINTENANCE_GAME_EXPONENT_DIVISOR());646647	double fTempCost = fMultiplyFactor * iSupply;648	int iFinalCost = (int) pow(fTempCost, fExponentialFactor);649650	// A mod at the player level? (Policies, etc.)651	if(m_pPlayer->GetUnitSupplyMod() != 0)652	{653		iFinalCost *= (100 + m_pPlayer->GetUnitSupplyMod());654		iFinalCost /= 100;655	}656657	CvAssert(iFinalCost >= 0);658659	return iFinalCost;660}

Calls

Called by