Possible bug with AI discounts on World Wonders

ZPV

Short for ZPVCSPLFUIFDPEF
Joined
Jan 16, 2008
Messages
3,946
Location
England
I was under the impression that the AI didn't get any bonus for World Wonders, Projects and Units. This is true in the Ancient Age.

However, I was playing with a Permanent Alliance on Deity and notice that my ally was building the Eiffel Tower at a cost of 937 hammers on Normal speed. (It costs me 1250). After digging through the code for a bit, I found the problem: the "per era" discount is still applied to World Wonders.

What I want to know is: is this intended? Is it a bug or a feature?

Edit: this was in BTS. I don't know if this is the case in Vanilla or Warlords
 
What is the "per era" discount, and can you post the relevant piece of code?

Doesn't the AI get production bonuses on deity?

Did you take the possibility of a production bonus due to access to iron into account? (Unlkely to produce the effect you described but I'm just checking all the options)

Can you post of savegame so that we can reproduce your findings?
 
CvPlayer.cpp said:
int CvPlayer::getProductionNeeded(BuildingTypes eBuilding)
{
int iProductionNeeded;

iProductionNeeded = GC.getBuildingInfo(eBuilding).getProductionCost();

iProductionNeeded *= GC.getDefineINT("BUILDING_PRODUCTION_PERCENT");
iProductionNeeded /= 100;

iProductionNeeded *= GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getConstructPercent();
iProductionNeeded /= 100;

iProductionNeeded *= GC.getEraInfo(GC.getGameINLINE().getStartEra()).getConstructPercent();
iProductionNeeded /= 100;

if (!isHuman() && !isBarbarian())
{
if (isWorldWonderClass((BuildingClassTypes)(GC.getBuildingInfo(eBuilding).getBuildingClassType())))
{
iProductionNeeded *= GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIWorldConstructPercent();
iProductionNeeded /= 100;
}
else
{
iProductionNeeded *= GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIConstructPercent();
iProductionNeeded /= 100;
}

iProductionNeeded *= max(0, ((GC.getHandicapInfo(GC.getGameINLINE().getHandicapType()).getAIPerEraModifier() * getCurrentEra()) + 100));
iProductionNeeded /= 100;

}

return max(1, iProductionNeeded);
}


I have bolded the lines that deal with the Per Era Discount, basically in the later game eras, buildings cost less for the AI. (Similar for units, projects.)

I know that the AI gets production bonuses on Deity, the issue is that I had understood that the AI got no bonuses for World Wonders, and if we look up AIWorldConstructPercent in the XML, it is 100, so no there is inherent bonus for them. I would guess that it is an oversight that AIPerEraModifier is applied to them.

The screenshot below shows two AI cities building Stonehenge. One of them (Mehmed) is in the Classical Era, and has a 5% discount on the wonder. (It costs 114 hammers instead of 120). It costs 120 hammers for Catherine, however, because she was in the Ancient Era when she started building it.



The save for that turn is attached. It was played using v3.17
 

Attachments

Thanks, that was a very thorough analysis!

So I guess the question is whether the AI should get a per-era discount on wonder building or not. I see three possible perspectives on this:

1. The perEra discount for wonders should be removed.
This is, imho, the least plausible solution, because in this case we'd be modifying the DLL because of a specific value in the XML. If we mod a difficulty level so that the AI does get a discount on wonder building, then (by your reasoning) the perEra discount should apply as well. However, it wouldn't because we'd have removed that line of code. This means that a change of AIWorldConstructPercent to anything below 100 would need a DLL modification to work consistenly to other production modifiers (i.e., with AIPerEraModifier applied), which clearly isn't a good solution.

2. Make the perEra modifier apply only if (AIWorldConstructPercent < 100)
This would solve the problem I mentioned in the paragraph above and would be consistent with your view that the AI should only get a perEra discount if it already got a discount in the first place

3. Don't change anything
However, one could also argue that AIWorldConstructPercent simply specifies the starting value of the discount, that AIPerEraModifier then modifies this discount, and that the current state of affairs (a starting discount of 0 in the first era, which then increases in subsequent eras) is entirely reasonable.

Personally, I'm leaning to (3), but (2) is just as plausible imho.
 
Thanks for your thoughts Psyringe :)

I agree option 1 is not right for exactly the reason you stated

Either option 2 or option 3 are perfectly reasonable, I was just trying to guess developers' intentions.
 
Back
Top Bottom