I am currently looking into the following request from
hannurabi:
Darkpanda, can I request you something to research in exe? I would be interest to edit the procedure that determines how many bulbs is required for the next advance.
While reverse-engineering CIV.EXE, I stumbled upon the logic that is also presented in
this chart, showing how many
more bulbs (the
increment)[/B]are required for the player or for the AI, depending on the difficulty level.
1. What we know
With difficulty valued from 0 (Chieftain) to 4 (Emperor), the
increment is computed as follows:
- for the AI: increment = 14 - difficultyLevel
- for the Player: increment = 6 + 2*difficultyLevel
Later in the code, we find more logic that deals with the
2x factor after 0 AD:
Code:
...
factor2x = 1;
if( currentYear >= 0 ) factor2x = 2;
if( bulbs[civID]/factor2x >= increment*techCount[civID] ) {
// ... discover advance, reset bulbs[civID] to 0
}
Note that this condition could as well be written:
bulbs[civID] >= factor2x*increment*techCount[civID], which effectively means that the
increment is twice higher after 0 AD.
Thus we can list expected increment values based on difficulty level and year:
|Chieftain (0)|Warlord (1)|Prince (2)|King (3)|Emperor (4)
AI increment (BC)|14|13|12|11|10
Player increment (BC)|6|8|10|12|14
AI increment (AD)|28|26|24|22|20
Player increment (AD)|12|16|20|24|28
But wait a second... between these 2 pieces of code, there is some more logic that is actually affecting the computation of bulbs!
2. First discovery
After initial calculation of the
increment following the first formula above, and evaluating the condition, a mysterious value is added to the increment, which I have called
additionalRequiredBulbs.
This value, additionalRequiredBulbs, is
re-computed every 50 turns after 0 AD, as part of the main game loop, with the following formula:
Code:
additionalRequiredBulbs = maxTechCounter - gameTurn/9;
if(additionalRequiredBulbs<0) additionalRequiredBulbs=0;
if(additionalRequiredBulbs>6) additionalRequiredBulbs=6;
In the code above,
maxTechCounter is the maximum number of techs discovered by any Civ so far.
Let's recall the equivalent between
turns and
years:
- Turns 0 to 250 (4000 BC to 1000 AD): 1 turn = 20 years
- Turns 250 to 300 (1000 AD to 1500 AD): 1 turn = 10 years
- Turns 300 to 350 (1500 AD to 1750 AD): 1 turn = 5 years
- Turns 350 to 400 (1750 BC to 1850 AD): 1 turn = 2 years
- Turns 400 onwards (after 1850 AD): 1 turn = 1 year
We can ignore everything before
0 AD, which corresponds to
turn 200.
At 0 AD, it is the first time that
additionalRequiredBulbs is computed. At that time,
turn/9 = 200/9 = 22. That means if any Civ has discovered 23 or more techs, then the
increment will be modified, and will keep its value for the next 50 years.
If we imagine that the player knows the most, with 23 techs, the increment will increase by 1, but since we're at 0 AD (or after), it really means an additional 2 bulbs required per known techs. Since the player knows 23 techs already, that means
at least 2*23 = 46 more bulbs will be necessary to discover the 24th tech !
And if any Civ knows 28 techs, the increment will increase by 12 (2*6), leading to an incredible 336 additional bulbs required for that Civ to discover its 29th tech !
Honestly, I never cared to hold a detail accounting on bulbs and techs when playing Civ, but these numbers look quite astonishing to me, and I wonder if anyone would care to put them to the test... I'd like to highlight I discovered this in version 474.01, and this may have been altered in subsequent versions.
Similar logic applies every 50 years after this:
- After 1000 AD, turn 250, the base increment will be increased if any Civ has more than 250/9 = 27 techs
- After 1500 AD, turn 300, the base increment will be increased if any Civ has more than 300/9 = 33 techs
- After 1750 AD, turn 350, the base increment will be increased if any Civ has more than 350/9 = 38 techs
- After 1850 AD, turn 400, the base increment will be increased if any Civ has more than 400/9 = 44 techs
3. Second discovery
After adding
additionalRequiredBulbs to the increment, CIV makes an extra step just for the player, that
may completely override the increment:
Code:
if( 11 - techCount[playerCivID] > increment ) {
increment = 11 - techCount[playerCivID];
}
This one is summed up as follows: the fewer techs the player has (below 11 techs), the more bulbs he will require for the next tech. Somehow this seeks to mitigate the conditions at game start, I suppose, but I really don't find it straightforward.
That's it for now, I'll come with more details, if any come up.