Bazaar developer reference

CvDiplomacyAI::IsGoldRequest(PlayerTypes, CvDeal *, int &)

Defined in
CvDiplomacyAI.cpp, line 4977
Class
CvDiplomacyAI
Hook name
CivHooks::CvDiplomacyAI_IsGoldRequest

Hooks

static bool BeforeCvDiplomacyAI_IsGoldRequest(CvDiplomacyAI* self, PlayerTypes ePlayer, CvDeal* pDeal, int& iWeightBias, bool& result);static void AfterCvDiplomacyAI_IsGoldRequest(CvDiplomacyAI* self, PlayerTypes ePlayer, CvDeal* pDeal, int& iWeightBias, bool& result);static bool ReplaceCvDiplomacyAI_IsGoldRequest(bool (*original)(CvDiplomacyAI*, PlayerTypes, CvDeal*, int&), CvDiplomacyAI* self, PlayerTypes ePlayer, CvDeal* pDeal, int& iWeightBias);CivRegisterBefore<CivHooks::CvDiplomacyAI_IsGoldRequest>(host, &BeforeCvDiplomacyAI_IsGoldRequest);CivRegisterAfter<CivHooks::CvDiplomacyAI_IsGoldRequest>(host, &AfterCvDiplomacyAI_IsGoldRequest);CivRegisterReplace<CivHooks::CvDiplomacyAI_IsGoldRequest>(host, &ReplaceCvDiplomacyAI_IsGoldRequest);

Code

4976/// Does this AI want something?4977bool CvDiplomacyAI::IsGoldRequest(PlayerTypes ePlayer, CvDeal* pDeal, int& iWeightBias)4978{4979	iWeightBias = 0;49804981	int iOurGold = GetPlayer()->GetTreasury()->GetGold();4982	int iOurGPT = GetPlayer()->calculateGoldRate();4983	int iOurExpenses = GetPlayer()->GetTreasury()->CalculateInflatedCosts();4984	int iOurGrossIncome = iOurGPT + iOurExpenses;49854986	// If we have no expenses, don't ask (and also don't crash)4987	if(iOurExpenses == 0)4988		return false;49894990	// If we already have some gold saved up then don't bother4991	if(iOurGold > 100)4992		return false;49934994	// If we're making 35% more than we're spending then don't ask, we're doing alright4995	if(iOurGrossIncome * 100 / iOurExpenses > 135)4996		return false;49974998	int iTheirGold = GET_PLAYER(ePlayer).GetTreasury()->GetGold();4999	int iTheirGPT = GET_PLAYER(ePlayer).calculateGoldRate();5000	int iTheirExpenses = GET_PLAYER(ePlayer).GetTreasury()->CalculateInflatedCosts();5001	int iTheirGrossIncome = iTheirGPT + iTheirExpenses;50025003	// Don't divide by zero please5004	if(iTheirExpenses != 0)5005	{5006		// If they're making less than 35% more than they're spending then don't ask, they're not in great shape5007		if(iTheirGrossIncome * 100 / iTheirExpenses < 135)5008			return false;5009	}5010	else if(iTheirGPT <= iOurGPT)5011	{5012		return false;5013	}50145015	// Add a little something extra since we're in dire straights5016	if(iOurGPT < 0)5017		iWeightBias += 25;50185019	// If we've made it this far we'd like to ask, so figure out how much we want to ask for5020	int iGoldToAskFor = iTheirGPT * GC.getGame().GetDealDuration() / 5;5021	int iGPTToAskFor = 0;50225023	if(iGoldToAskFor > iTheirGold)5024	{5025		iGoldToAskFor = 0;5026		iGPTToAskFor = max(1, iTheirGPT / 6);5027	}50285029	// Now seed the deal5030	if(iGoldToAskFor > 0)5031		pDeal->AddGoldTrade(ePlayer, iGoldToAskFor);5032	else if(iGPTToAskFor > 0)5033		pDeal->AddGoldPerTurnTrade(ePlayer, iGPTToAskFor, GC.getGame().GetDealDuration());50345035	return true;5036}

Calls

Called by