I need some help with a bug in my mod

XStationCube

Chieftain
Joined
May 1, 2009
Messages
6
Location
USA
For a while now, I've been working on a custom mod for BTS which adds new game speeds, world sizes and difficulties. One of the new game speeds is called Insanity and lasts 20,000 turns. I just finished a test game with this speed and noticed a few issues with it:

1. No inflation (Fixed)
2. No war weariness (Fixed)
3. Workers not being able to finish construction of certain improvements (Forts and Oil Wells)

Now, for this game speed, I have iBuildPercent in the Civ4GameSpeedInfo XML file set to 4000 and this appears to be causing the problem. With a single worker building an Oil Well, the game says it will take 267 turns to finish, and when the worker gets close to finishing (~20 turns away), the number of turns to completion jumps up to something like 399. As a further test, I used world builder to put 700+ workers onto an oil tile to build a well. The game said it would only take one turn, but after pressing the "Build" button, the number jumped to 2. On the next turn it went down to 1, only to go back up to 2 on the turn after that.

So, I played around with the value of iBuildPercent and found that if it is decreased to about 3200, the problem vanishes. And if it is increased beyond 4000, the problem starts happening to other "cheaper" improvements like plantations and pastures.

I cannot find any reason for why this is happening (Although I'm not very experienced with coding), so does anyone have any idea why this occurs? If you like I could upload my mod in its present state, if you need it.

Also, is it possible to modify the game so as to allow for weeks per turn instead of months per turn? I know that there is CALENDAR_WEEKS, but this does not allow for variable numbers of weeks per turn like CALENDAR_DEFAULT allows for variable numbers of months per turn.
 
Now, for this game speed, I have iBuildPercent in the Civ4GameSpeedInfo XML file set to 4000 and this appears to be causing the problem. With a single worker building an Oil Well, the game says it will take 267 turns to finish, and when the worker gets close to finishing (~20 turns away), the number of turns to completion jumps up to something like 399. As a further test, I used world builder to put 700+ workers onto an oil tile to build a well. The game said it would only take one turn, but after pressing the "Build" button, the number jumped to 2. On the next turn it went down to 1, only to go back up to 2 on the turn after that.

So, I played around with the value of iBuildPercent and found that if it is decreased to about 3200, the problem vanishes. And if it is increased beyond 4000, the problem starts happening to other "cheaper" improvements like plantations and pastures.
.

How many turns does it take with 3200, and how many is the minimum where it doesn't work anymore?
e.g. does it work when it displays 255 turns, and doesn't work anymore if it needs more than 256 turns?
 
I just did some more testing, and it seems that a value of 3270 is the maximum for iBuildPercent that all improvements can still be built. At that value it takes 218 turns to finish an oil well.

However, I also noticed that at slightly higher values, the improvement is completed but with significant delays. For example, I had 450 workers build a well with iBuildPercent at 3276, and despite saying it had 1 turn to completion, it did finish within 30 turns. It appears that with higher values improvements will finish eventually after a certain number of resets to the turn count, but I still have no idea what's causing this.
 
The variable that 'remembers' for each plot each build's progress is of type short. The range for this variable is (−32,768) to (32,767) (2 bytes).

When the build time cost of forts and wells is 1000, and you multiply it by 40, you get 40,000 which is beyond the limit for this variable, so you get an overflow. And weird things happen when you get an overflow.
 
Thanks! After digging around in the source code, I was able to find those variables and change their types to long. Now with a 4-byte integer, the problem has been resolved. Thank you for pointing that out, Asaf!

Now that that's resolved, is there any way to modify the game calendar to allow for variable weeks per turn instead of variable months per turn?
 
Back
Top Bottom