CvEconomicAI::AmountAvailableForPurchase(PurchaseType)
- Defined in
- CvEconomicAI.cpp, line 1208
- Class
- CvEconomicAI
- Hook name
CivHooks::CvEconomicAI_AmountAvailableForPurchase
Hooks
static bool BeforeCvEconomicAI_AmountAvailableForPurchase(CvEconomicAI* self, PurchaseType ePurchase, int& result);static void AfterCvEconomicAI_AmountAvailableForPurchase(CvEconomicAI* self, PurchaseType ePurchase, int& result);static int ReplaceCvEconomicAI_AmountAvailableForPurchase(int (*original)(CvEconomicAI*, PurchaseType), CvEconomicAI* self, PurchaseType ePurchase);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_AmountAvailableForPurchase::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvEconomicAI_AmountAvailableForPurchase);host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_AmountAvailableForPurchase::ID, CIV_HOOK_AFTER, (void*)&AfterCvEconomicAI_AmountAvailableForPurchase);host->RegisterHook(host->pluginIndex, CivHooks::CvEconomicAI_AmountAvailableForPurchase::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvEconomicAI_AmountAvailableForPurchase);
Code
1207/// Returns amount of gold economic AI is willing to release for this type of purchase. May not be full gold balance if higher priority requests are in. Does not actually spend the gold.1208int CvEconomicAI::AmountAvailableForPurchase(PurchaseType ePurchase)1209{1210 int iBalance = m_pPlayer->GetTreasury()->GetGold();12111212 // Copy into temp array and sort by priority1213 m_TempRequestedSavings = m_RequestedSavings;1214 std::stable_sort(m_TempRequestedSavings.begin(), m_TempRequestedSavings.end());12151216 for(int iI = 0; iI < (int)m_TempRequestedSavings.size(); iI++)1217 {1218 CvPurchaseRequest request = m_TempRequestedSavings[iI];12191220 // Is this higher priority than the request we care about?1221 if(request.m_eType != ePurchase)1222 {1223 iBalance -= request.m_iAmount;12241225 // No money left?1226 if(iBalance <= 0)1227 {1228 return 0;1229 }1230 }12311232 // Is this the one, if so, check balance remaining1233 else if(request.m_eType == ePurchase)1234 {1235 return (iBalance);1236 }1237 }12381239 CvAssert(false);1240 return false; // Should never reach here1241}
Calls
BaseVector::beginBaseVector::endBaseVector::operator[]BaseVector::size- CvPlayer::GetTreasury() const
CvPurchaseRequest::CvPurchaseRequest- CvTreasury::GetGold() const
FStaticVector::operator=std::stable_sort