Bazaar developer reference

CvEconomicAI::CanWithdrawMoneyForPurchase(PurchaseType, int, int)

Defined in
CvEconomicAI.cpp, line 1165
Class
CvEconomicAI
Hook name
CivHooks::CvEconomicAI_CanWithdrawMoneyForPurchase

Hooks

static bool BeforeCvEconomicAI_CanWithdrawMoneyForPurchase(CvEconomicAI* self, PurchaseType ePurchase, int iAmount, int iPriority, bool& result);static void AfterCvEconomicAI_CanWithdrawMoneyForPurchase(CvEconomicAI* self, PurchaseType ePurchase, int iAmount, int iPriority, bool& result);static bool ReplaceCvEconomicAI_CanWithdrawMoneyForPurchase(bool (*original)(CvEconomicAI*, PurchaseType, int, int), CvEconomicAI* self, PurchaseType ePurchase, int iAmount, int iPriority);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_CanWithdrawMoneyForPurchase::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvEconomicAI_CanWithdrawMoneyForPurchase);host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_CanWithdrawMoneyForPurchase::ID, CIV_HOOK_AFTER, (void*)&AfterCvEconomicAI_CanWithdrawMoneyForPurchase);host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_CanWithdrawMoneyForPurchase::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvEconomicAI_CanWithdrawMoneyForPurchase);

Code

1163/// Returns true if have enough saved up for this purchase. May return false if have enough but higher priority requests have dibs on the gold.1164//  (Priority of -1 (default parameter) means use existing priority1165bool CvEconomicAI::CanWithdrawMoneyForPurchase(PurchaseType ePurchase, int iAmount, int iPriority)1166{1167	int iBalance = m_pPlayer->GetTreasury()->GetGold();11681169	// Update this item's priority1170	if(iPriority != -1)1171	{1172		int iIndex = (int)ePurchase;1173		m_RequestedSavings[iIndex].m_iPriority = iPriority;1174	}11751176	// Copy into temp array and sort by priority1177	m_TempRequestedSavings = m_RequestedSavings;1178	std::stable_sort(m_TempRequestedSavings.begin(), m_TempRequestedSavings.end());11791180	for(int iI = 0; iI < (int)m_TempRequestedSavings.size(); iI++)1181	{1182		CvPurchaseRequest request = m_TempRequestedSavings[iI];11831184		// Is this higher priority than the request we care about?1185		if(request.m_eType != ePurchase)1186		{1187			iBalance -= request.m_iAmount;11881189			// No money left?1190			if(iBalance <= 0)1191			{1192				return false;1193			}1194		}11951196		// Is this the one, if so, check balance remaining1197		else if(request.m_eType == ePurchase)1198		{1199			return (iBalance >=iAmount);1200		}1201	}12021203	CvAssert(false);1204	return false;  // Should never reach here1205}

Calls

Called by