Actual build cost (for AI tribes)

Knighttime

Prince
Joined
Sep 20, 2002
Messages
380
I'm trying to track down the details of how the game determines the actual shields required for tribes to build units, improvements, and wonders at any point in the game. The numbers listed for each item in Rules.txt are always multiplied by another number to determine the true cost, and it's the way that other number is determined that interests me.

I'm running Test of Time, with TOTPP, in case that matters. But it seems likely that the formula is the same as in earlier versions.

I know that (a) the base number of shield columns is established by the fifth number in @Cosmic (labeled "# of rows in shield box" although that's misleading since it's really columns, not rows). In Lua this is accessible as civ.cosmic.shieldRows. This is the sole number used to calculate the true cost for you as the human player.

But for AI tribes, (b) this is modified by the difficulty level. I think the following numbers are correct?
Chieftain: 150% of base
Warlord: 130% of base
Prince: 120% of base
King: 100% of base
Emperor: 90% of base
Deity: 80% of base
I don't recall exactly where I found these documented -- and please let me know if these numbers are off.

Side question: does anyone know if it is possible to access a game's current difficulty level programmatically, from within a Lua script? That would be very helpful...

However, I think there is one more factor that is almost never mentioned. (c) In some of my saved games, I noticed that AI cities had 2 fewer columns than they should according to the difficulty level. After a lot of searching online, I came across a comment saying that this additional "-2 column" bonus is given to all AI tribes when your power rating (as the human player) is Supreme. I wish I had noted where I found this information -- I didn't do so and now I can't find it again, unfortunately.

It does seem to be true that in all the cases where I noted this additional AI bonus, I was indeed Supreme. The problem is that I can find other saved games where I am also Supreme, and yet the AI is not receiving the bonus.

So I'm left wondering... what else is required to trigger this? Do you have to be Supreme for X consecutive turns? Does it only apply after turn X in the game? Does it only apply after you've discovered tech X? (or after any tribe has discovered tech X?) Is it looking deeper than simply "are you Supreme" and referencing the actual numeric power rating, perhaps to say your score must be X% higher than anyone else's?

If anyone is aware of existing documentation about this topic, or has information related to any of the above, I'd love to hear about it. Thanks!
 
I suspect that it is +1 or +2 shields rather than a percentage. My guess is that there is a post 1750 bonus, rather than a supreme bonus. The reason is that in Deity+2 and above difficulty levels, after 1750, a city with a granary will grow by 1 citizen every turn, regardless of any food deficit. The idea being that the city's food box is now "smaller" than the granary box.

I think you are just going to have to do some testing with regard to some of these things. My advice is to save a scenario so you can easily change difficulty levels while otherwise reusing your test setup.
 
Side question: does anyone know if it is possible to access a game's current difficulty level programmatically, from within a Lua script? That would be very helpful...

difficulty (get/set)
civ.game.difficulty -> integer

Returns the difficulty level.
 
difficulty (get/set)
civ.game.difficulty -> integer

Returns the difficulty level.
Y'know, I've been working off of my own local copy of the Lua function reference for a long time, which I created so that I could add personal notes/links/tips/thoughts as I tried things out. For some reason the entire civ.game object is missing from it though! :eek: and I didn't even realize those fields existed! So I really appreciate you pointing out something that you probably felt was obvious. (Now I'm going to do a thorough comparison and see what else I might I have overlooked!)
(EDIT: Whew, that appears to be the only section I had missed. Sure don't know how that happened though.)

I'll come back to the original topic of build cost in a bit.
 
Last edited:
I suspect that it is +1 or +2 shields rather than a percentage.
Are you talking about the difficulty level bonus I described in (b), or about the additional AI bonus I'm trying to understand in (c)? For (b) I'm pretty sure the bonus is a percentage, not a fixed quantity, based on my testing results below. For (c), I'm talking about a bonus that is always equal to exactly 2 shield columns, which I refer to as "-2" because there are two fewer columns in every AI city. So "+1 or +2 shields" is a little unclear to me.

I think you are just going to have to do some testing with regard to some of these things. My advice is to save a scenario so you can easily change difficulty levels while otherwise reusing your test setup.
Thanks to your tip about civ.game.difficulty, I realized that civ.cosmic.shieldRows and civ.game.difficulty are both (get/set) so it's possible to adjust them within a single game and immediately check out the impact -- without exiting and reloading. That made testing a whole lot easier.

First, regarding (b):
The bonus does seem to be a percentage, as I described, and the percent values I listed are correct for civ.cosmic.shieldRows = 10. For any other value of that cosmic variable, the percentage formula still works, except that the quantity of columns is apparently rounded to the nearest even number. I have no idea why an odd number of columns is permitted for the base cosmic value of 10, but not for any other value that I tested. To be clear, the human player always sees exactly the number of columns (odd or even) specified by civ.cosmic.shieldRows -- but the AI players always see an even number, except when the base is 10.

Here are the results of my testing (b):
AI city shield box columns.png

(EDIT: "AI Percent Bonus" isn't the best label for that column, since numbers above 100% are actually a penalty to the AI, causing them to build/grow more slowly.)

Then regarding (c):
My guess is that there is a post 1750 bonus, rather than a supreme bonus.
I finally found the obscure post that led me to believe the human's power rating was the key factor:
https://apolyton.net/forum/miscella...ategy-archive/4269-cruise-missile-cheat/page2
The final post on that page, bolding added by me for emphasis:
Personally, I think the production rules for the AI are largely the same as ours, except as already noted here and in the "AI cheats" thread: starting at 80% production cost at deity and dropping to 60% when the human is Supreme (90% at emperor, dropping to 70%), and being able to switch freely between types of production, and being able to build a new type of unit on the very turn when it learns the tech. Does anybody have any clear reason to think there are other production advantages for the AI?
I will freely admit that a single post from 19 years ago is not a very substantial basis for my theory! But based on my testing, I believe it is correct -- and, you are also correct! So thank you very much for providing the missing piece of the puzzle.

In my first test, my power rating was Moderate. I tested changing the game year via Cheat -> Set Game Year to various values, but no matter what I entered, AI cities did not receive the -2 shield column bonus. I tested this at different difficulty levels and the result was unchanged.

In my second test, my power rating was Supreme. When I changed the game year via Cheat -> Set Game Year, I discovered that any value greater than or equal to 200 would immediately provide the -2 shield column bonus to the AI. There was no change for values less than 200. Again, this was true at all difficulty levels.

1750 AD is turn 201 on Deity level. Several things to note in this regard:

(1) The actual bonus begins on turn 200, not 201, which is actually the year 1740 at Deity level.
(2) The critical factor is the turn number, not the year. At lower difficulty levels, turn 200 occurs at a different year -- for example, on a medium-sized map at King level, turn 200 is 1490. The AI bonus kicks in at that year, on the 200th turn.
(3) I'm almost certain that this AI bonus applies in just the same way to scenarios that use custom values for start year, end year, and/or years per turn: at turn 200 if your power rating is Supreme.

I should admit right away that I didn't test other power ratings, i.e., I didn't confirm behavior if you were Mighty (one notch below Supreme). That's probably necessary in order to wrap this up.

The reason is that in Deity+2 and above difficulty levels, after 1750, a city with a granary will grow by 1 citizen every turn, regardless of any food deficit. The idea being that the city's food box is now "smaller" than the granary box.
Yes, the "-2 shield box columns" bonus I'm talking about is also a "-2 food box rows" bonus. A Granary allows the food box to stay 50% full when a city grows, but I never realized exactly how that worked for the AI.

After testing this out, I see that their food box actually retains the quantity of food that would be required to fill the food box to 50% if it was a human player's city -- in other words, the quantity of food is calculated without (or prior to) accounting for the AI difficulty level bonus in (b), or the potential AI bonus in (c). So before turn 200, at Deity +3 when the AI box is 50% as large as the human player's, the quantity of food retained would be exactly enough to fill the entire box, and growth could occur immediately -- as long as there is no food deficit. At Deity+4, the quantity of food retained would be enough to fill the entire box with some left over -- so as long as the deficit does not exceed that carryover, growth can again occur immediately.

With the post-turn 200 bonus in effect, Deity +2 essentially acts like Deity +4 (at least for many values of civ.cosmic.foodRows), so the behavior you described makes sense to me. I do think that if there was a large enough food deficit, though, growth would stop. Have you ever seen AI cities grow indefinitely like this to size 100+? I really haven't done much (until now) with difficulty levels above Deity.

I'd welcome you or anyone else to test this on your own and confirm my conclusions -- or contradict them if necessary! Thanks again for your response.
 
Last edited:
Are you talking about the difficulty level bonus I described in (b), or about the additional AI bonus I'm trying to understand in (c)? For (b) I'm pretty sure the bonus is a percentage, not a fixed quantity, based on my testing results below. For (c), I'm talking about a bonus that is always equal to exactly 2 shield columns, which I refer to as "-2" because there are two fewer columns in every AI city. So "+1 or +2 shields" is a little unclear to me.

I meant part (b). EDIT: But your tests would contradict that assumption.

In my second test, my power rating was Supreme. When I changed the game year via Cheat -> Set Game Year, I discovered that any value greater than or equal to 200 would immediately provide the -2 shield column bonus to the AI. There was no change for values less than 200. Again, this was true at all difficulty levels.

1750 AD is turn 201 on Deity level. Several things to note in this regard:

(1) The actual bonus begins on turn 200, not 201, which is actually the year 1740 at Deity level.
(2) The critical factor is the turn number, not the year. At lower difficulty levels, turn 200 occurs at a different year -- for example, on a medium-sized map at King level, turn 200 is 1490. The AI bonus kicks in at that year, on the 200th turn.
(3) I'm almost certain that this AI bonus applies in just the same way to scenarios that use custom values for start year, end year, and/or years per turn: at turn 200 if your power rating is Supreme.

I should admit right away that I didn't test other power ratings, i.e., I didn't confirm behavior if you were Mighty (one notch below Supreme). That's probably necessary in order to wrap this up.

Turn 200 makes sense. Trade delivery bonuses stop being doubled at that turn (they also stop being doubled when navigation or invention is researched).

There is a decent chance that it is only a "supreme" mechanic. I played a game in Civ II classic many years ago, where I fluctuated between Mighty and Supreme just after 1750, and the AI attitude fluctuated between normal civ II classic ai, and MGE style hostile AI. Still, it will be worthwhile to check.

With the post-turn 200 bonus in effect, Deity +2 essentially acts like Deity +4 (at least for many values of civ.cosmic.shieldRows), so the behavior you described makes sense to me. I do think that if there was a large enough food deficit, though, growth would stop. Have you ever seen AI cities grow indefinitely like this to size 100+? I really haven't done much (until now) with difficulty levels above Deity.

The old Deity+2 succession game has screenshots of cities size 43 and 50. That was in Classic, so there is a small chance things would be different in TOT.

https://forums.civfanatics.com/thre...-of-non-essentials.54314/page-16#post-1212004
 
Last edited:
The old Deity+2 succession game has screenshots of cities size 43 and 50. That was in Classic, so there is a small chance things would be different in TOT.
https://forums.civfanatics.com/thre...-of-non-essentials.54314/page-16#post-1212004
Thanks for this link. I think what I'm seeing there confirms my theory about growth limitation though, and also way the formula works. Looking at the second city, Dnepropetrovsk:

City size = 50
civ.cosmic.foodRows = 10 (I'm assuming this was unchanged from the base value?)
Food in full box for human player = 510 (formula is (city.size + 1) * food box rows)
Food kept due to granary, for both human and AI players, when city grows to size 50 = 255 (50% of above)
AI food rows = 4 (clearly shown in screen shot)
Food in full box for AI player = 204 (same formula as above)
Excess food when city grew from 49 to 50 = 255 - 204 = 51
Annual food surplus = -52 (shown in screen shot, i.e. hunger or food deficit)
Net surplus = -1 (i.e. deficit of 1)

So the city couldn't continue growing to size 51, and the net deficit of 1 has been deducted from the food storage box (it looks to me like the fourth row is one symbol shorter). I would expect that next turn, the full deficit of 52 would be applied, so the amount of food in the box would drop from 203 to 151.
 
Last edited:
Back
Top Bottom