Ghpstage
Deity
Originally started in this thread, finally finished.
How much gold will an AI trade to the player?
First, the whole code block, its all from CVPlayerAI.ccp
And now how it works.
The AI calculates two values, iMaxGold and iResearch buffer, and the lower value of iMaxGold and (current gold - iReseachBuffer) gives the final gold they are willing to trade.
the this is rounded down to the nearest 10
iMaxGold is basically a cap that builds up over the game, and reduces as the AI trades gold to the player.
The calculation is ((AI Total Population * (Turns since you met the AI + 10) * iMaxGoldTradePercent)/100) - total of all gold that AI traded to player previously
The term MaxGoldTradePercent is an xml value individual to AIs (Leaderheads), as may be expected some AIs are willing to trade more of their gold than others.
iResearchBuffer comes from,
Which is basically (12*deficit * Speed modifier)/100.
So to give the short numbers. The AI will trade the minimum value out of;
Of particular note is the cause of the thread linked at the start which originally led to this codedive,
The term calculategoldrate is quite literally income - expenses.
When the AI is losing 0 gold, or a surplus (which, sensibly rounds to 0 here) the iResearchBuffer becomes 0 allowing the AI to trade all of its gold to a player provided this is less than the iMaxGold value. The notable part is that we can force an AIs expenses drop to 0 or therabouts by causing Anarchy
EDIT - I also looked into the maximum amount of gold per turn the AI is willing to trade at any point later in the thread
Omitting the code here for brevity
Of note, unlike bulk gold there isn't an absolute cap on the amount of GPt an AI can trade in a given turn, if an AI has 16 GPT and is willing to trade only 8GPT at once, doing so will reveal, ad make available the other 8GPT.
How much gold will an AI trade to the player?
First, the whole code block, its all from CVPlayerAI.ccp
Spoiler :
Code:
int CvPlayerAI::AI_maxGoldTrade(PlayerTypes ePlayer) const
{
int iMaxGold;
int iResearchBuffer;
FAssert(ePlayer != getID());
if (isHuman() || (GET_PLAYER(ePlayer).getTeam() == getTeam()))
{
iMaxGold = getGold();
}
else
{
iMaxGold = getTotalPopulation();
iMaxGold *= (GET_TEAM(getTeam()).AI_getHasMetCounter(GET_PLAYER(ePlayer).getTeam()) + 10);
iMaxGold *= GC.getLeaderHeadInfo(getPersonalityType()).getMaxGoldTradePercent();
iMaxGold /= 100;
iMaxGold -= AI_getGoldTradedTo(ePlayer);
iResearchBuffer = -calculateGoldRate() * 12;
iResearchBuffer *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getResearchPercent();
iResearchBuffer /= 100;
iMaxGold = std::min(iMaxGold, getGold() - iResearchBuffer);
iMaxGold = std::min(iMaxGold, getGold());
iMaxGold -= (iMaxGold % GC.getDefineINT("DIPLOMACY_VALUE_REMAINDER"));
}
return std::max(0, iMaxGold);
The AI calculates two values, iMaxGold and iResearch buffer, and the lower value of iMaxGold and (current gold - iReseachBuffer) gives the final gold they are willing to trade.
Code:
iMaxGold = std::min(iMaxGold, getGold() - iResearchBuffer)
Code:
iMaxGold -= (iMaxGold % GC.getDefineINT("DIPLOMACY_VALUE_REMAINDER"));
iMaxGold is basically a cap that builds up over the game, and reduces as the AI trades gold to the player.
Code:
iMaxGold = getTotalPopulation();
iMaxGold *= (GET_TEAM(getTeam()).AI_getHasMetCounter(GET_PLAYER(ePlayer).getTeam()) + 10);
iMaxGold *= GC.getLeaderHeadInfo(getPersonalityType()).getMaxGoldTradePercent();
iMaxGold /= 100;
iMaxGold -= AI_getGoldTradedTo(ePlayer);
The term MaxGoldTradePercent is an xml value individual to AIs (Leaderheads), as may be expected some AIs are willing to trade more of their gold than others.
iResearchBuffer comes from,
Code:
iResearchBuffer = -calculateGoldRate() * 12;
iResearchBuffer *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getResearchPercent();
iResearchBuffer /= 100;
So to give the short numbers. The AI will trade the minimum value out of;
- ((AI Total Population * (Turns since you met the AI + 10) * iMaxGoldTradePercent)/100) - total of all gold that AI traded to player previously
- AIs current gold - (12*deficit * Speed modifier)/100.
Of particular note is the cause of the thread linked at the start which originally led to this codedive,
Code:
iResearchBuffer = -calculateGoldRate() * 12;
When the AI is losing 0 gold, or a surplus (which, sensibly rounds to 0 here) the iResearchBuffer becomes 0 allowing the AI to trade all of its gold to a player provided this is less than the iMaxGold value. The notable part is that we can force an AIs expenses drop to 0 or therabouts by causing Anarchy
EDIT - I also looked into the maximum amount of gold per turn the AI is willing to trade at any point later in the thread
Omitting the code here for brevity
Obviously if the AI doesn't have that much GPT then its current GPT is all it can trade.iMaxGoldPerTurn = getTotalPopulation();
iMaxGoldPerTurn *= GC.getLeaderHeadInfo(getPersonalityType()).getMaxGoldPerTurnTradePercent();
iMaxGoldPerTurn /= 100;
Which is (Total pop of civ * Leader XML attribute)/100
That leader attribute is 10 for all but 3 AIs, Lincoln, Sury and Pacal who have 15.
In short its a tenth of the pop of most civs and 1.5 times that for the above 3.
Of note, unlike bulk gold there isn't an absolute cap on the amount of GPt an AI can trade in a given turn, if an AI has 16 GPT and is willing to trade only 8GPT at once, doing so will reveal, ad make available the other 8GPT.