AIs available gold: how does that work?

Knew that couldn't be all of it.... while it seems to work for all AIs in this game it isn't universal. I plucked a few games from the forum to make sure and ran into a fair few that didn't cooperate, with AIs offering far less than this game suggests they should.
Looks like population and AI personality have a role here that often doesn't amount to anything, but its too late to do anymore tonight :sad:
 
Example of a game where it doesn't work for every AI, hijacked from JSBossch's Deity game. In that game it applies to all AIs bar Izzie and Roosevelt, Roo giving 10 when it 'should' be 60 and Izzie just 80 when it 'should' be 1410....

In case anyone else can decipher its meaning to find why it doesn't always work like it does in this game, the code from CvPlayerAI.cpp;
Spoiler :
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);
 
It looks like its suggesting a buffer for 12 turns of research.
Thanks, this is exactly the kind of info I was hoping for. Very useful in a tech race.

Example of a game where it doesn't work for every AI, hijacked from JSBossch's Deity game. In that game it applies to all AIs bar Izzie and Roosevelt

Maybe Izzie and Roosevelt didn't research at 100% slider?
Although I don't understand the meaning, ResearchPercent is written in this 2nd line and seems to act like a multiplier before division by 100:
iResearchBuffer = -calculateGoldRate() * 12;
iResearchBuffer *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getResearchPercent();
iResearchBuffer /= 100;
 
Thanks, this is exactly the kind of info I was hoping for. Very useful in a tech race.
It would be a lot more useful if the unknowns could be nailed down though!
Maybe Izzie and Roosevelt didn't research at 100% slider?
Although I don't understand the meaning, ResearchPercent is written in this 2nd line and seems to act like a multiplier before division by 100:
This I have been wondering about, especially as when getresearchpercent = 100 it would cancel out and leave you with just the -calculategoldrate*12 I used to find calculate the Sury problem. The question then will be whether -icalculategoldrate will be the defecit at 100% or defecit at current setting, it'd make a difference to how useful this could be....
iMaxGold = std::min(iMaxGold, getGold() - iResearchBuffer);
Tradeable gold is the minimum of the actual gold and iMaxGold. iMaxGold must be routinely pretty big (at least 910 for Sury in the OP) as quite a lot of AIs are willing to trade on gold-iResearchBuffer, but what its made up of isn't entirely clear yet,
iMaxGold = getTotalPopulation();

iMaxGold *= (GET_TEAM(getTeam()).AI_getHasMetCounter(GET_PLAYE R(ePlayer).getTeam()) + 10);

iMaxGold *= GC.getLeaderHeadInfo(getPersonalityType()).getMaxG oldTradePercent();
iMaxGold /= 100;
Population should just be the total pop points, maxgoldtradepercentage in the XML are all either 5 or 10 depending on leader. What the heck the middle line is referring to however I don't have a clue :confused:
iMaxGold -= (iMaxGold % GC.getDefineINT("DIPLOMACY_VALUE_REMAINDER"));
This last bit i'm pretty sure just accounts for the rounding down to the nearest 10

I suppose i'll try out debug mode tomorrow to test, does it allow you to control AI empires directly so that I can change the slider settings?

EDIT - Decided to force feed Sury gold to get a close figure for iMaxGold that I could use to get a value for
(GET_TEAM(getTeam()).AI_getHasMetCounter(GET_PLAYE R(ePlayer).getTeam()) + 10);
at around 140. I supect the AI_GetHasMetCounter maybe smething like a turn counter for when the AI met BIC, though this would put it at around turn 15
 
After much facepalmery I finally decided to read the rest of this line
iResearchBuffer *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpee dType()).getResearchPercent();
..... and realised that its the game speed tech cost multiplier, as in 67 for quick, 100 for normal speed, 150 for Epic, and 300 for marathon, explains where the /100 vanished to :wallbash:

Pretty sure i've got this figured out now.

The amount of gold they are willing to trade is the lowest value of either the iMaxGold in the spoilered code below
Spoiler :
iMaxGold = getTotalPopulation();

iMaxGold *= (GET_TEAM(getTeam()).AI_getHasMetCounter(GET_PLAYE R(ePlayer).getTeam()) + 10);

iMaxGold *= GC.getLeaderHeadInfo(getPersonalityType()).getMaxG oldTradePercent();
iMaxGold /= 100;

iMaxGold -= AI_getGoldTradedTo(ePlayer);
Or this
Spoiler :
iResearchBuffer = -calculateGoldRate() * 12;
iResearchBuffer *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpee dType()).getResearchPercent();
iResearchBuffer /= 100;

....getGold() - iResearchBuffer);
which is
AIs total gold - (12*defecit * Speed modifier)/100.
The actual slider percentage is irrelevant


The iMaxGold I mentioned earlier acts as a cap defining the absolute max the AI is willing to trade away in a turn, even if they had more. Its calculated by
((AI Total Population * (Turns since you met the AI + 10) * iMaxGoldTradePercent)/100) - the gold the AI has traded to the player

Turns since meeting is found by (current turn number - number of turn you met), so on the turn you actually meet them this is zero.
iMaxGoldTradePercent is an AI personality number found in the XML, each AI has either a 5 or 10 value for it and if theres any interest i'll table them up and post it.

The final max gold the AI is willing to trade is the lowest result of these two formulae rounded down to the nearest 10.


Unfortunately screenshotting isn't working for some reason so heres an example thats easy to calculate, and easy to test in WB.

If at turn 0 you have met an AI with a iMaxGoldTradePercent of 10 (Churchill is one example) and 2000 gold with a 1 pop city then we get
Gold available to trade = (Pop (1) * (turns known (0) + 10) * MaxGoldTradePercent (10))/100 - 0 gold traded to us

Simplified 1*10*10/100 = 1
Which when rounded down leaves 0....

We can also find the population required to allow him to trade 50 gold on turn 1
50 = Pop * 10 * 10/100
Pop = 50/1 = 50
 
Top Bottom