Resource icon

C3X: EXE Mod including Bug Fixes, Stack Bombard, and Much More Release 23

Great work again!

Remember to back up your perfume list. I just replaced mine without thinking :(.

The next holy grail besides improved AI worker function is to have the AI build airfields and use land transports as well as the lux slider and specialists.
 
Last edited:
Flintlock... Excellent Work!
I especially like your removing the move cost for Airdrops to allow movement after an Airdrop and setting intercept will allow the Air Units to intercept on the same turn. Those adjustments alone are Great Game Changers :clap:
I do wonder how you managed to fix the Phantom Resource Bug :salute:
 
Thank you all for the accolades. :)



I do wonder how you managed to fix the Phantom Resource Bug :salute:
Ah right, I explained the other bugs and their fixes but overlooked this one. The phantom resource bug fix is unlike the others since the "bug" is not exactly a bug but more like a limitation in the game's programming. Hence the fix is more like implementing a new feature than doing a surgical change to the code, for example the submarine bug required weeks of analysis but in the end the fix only flips a single critical bit.

First an explanation of the bug: The way the game was originally programmed, each city has a 32-bit integer, treated as a set of 32 bits, that's used to record resource access info for when the city is not connected to the main trade network (the one that includes the capital). For an unconnected city, the first bit gets set to 1 to indicate that that city has access to the game's first resource, the second bit gets set to indicate access to the second, and so on. If a game has more than 32 resources the count "wraps around" and the bits are shared, so access to the 33rd resource is also recorded in the first bit, the 34th resource in the second bit, etc. That sharing of bits is what causes the phantom resource bug, as unconnected cities are marked as having access to resources that they shouldn't have.

With all that in mind, the fix is conceptually simple. It removes the limitation by creating extra space to store resource access info. The hard part is modifying the code to use the additional space. The reason I was able to remove this limitation, unlike the city limit or 31 civ limit, is that the game code only operates on those sets of 32 bits in two places (actually there are a couple more places but they're not important, see note below). So there are only two places where I needed to alter the code, one where the bits are checked and another where they are set.

The bits are checked in City::has_resource (GOG address 0x4B4E10), the function that the game logic uses to ask if a city has access to a particular resource. That function I simply replaced with one that additionally checks for a set bit in the extra space. The second place, where the bits are set, is in Trade_Net::recompute_resources (GOG addr 0x58B1A0). In that case I needed to modify the code so that, when it goes to mark access for resources beyond the first 32, it does so in the extra space instead of the original set of 32 bits. That modification required me to insert a function call into a stream of instructions, which is more difficult than replacing a function, but not so difficult since I was able to reuse some code I wrote to do that same thing for the AI production ranking & perfuming.

That's basically it, except for a couple of implementation issues like the extra space must be cleared when the game goes to recompute resource access and it must be expanded as necessary for how many cities there are on the map. This was a case where I was able to remove a limit from the game because it only required modifying a couple of places in the code. Removing the city limit would be more difficult since it would require creating extra space for the game to store city connection info and that info is accessed from many different locations (maybe not so many that I couldn't modify them all but I'd have to look into it). Removing the 31 civ limit is impossible because there are thousands of references to the 31 civ slots scattered throughout the code.


NOTE: What about the unimportant places? I did some investigating and found two additional locations where the sets of 32 bits are used. Those locations are not part of the game logic so that's why I don't consider them important. They check the resource access bits for the purpose (I'm pretty sure) of computing player score and power rankings. I didn't bother modifying those locations to check the extra space, meaning player score won't account for resources beyond the first 32. That's technically a bug but I'm not worried about it because (1) the original code was bugged anyway, with the phantom resources, and (2) if I hadn't pointed this out I doubt anyone would have ever noticed.
 
It removes the limitation by creating extra space to store resource access info. The hard part is modifying the code to use the additional space.
I'm not a coder, so have I understood correctly that this means mods can now safely include >32 Strat+Lux resources...?

If so, what is the new limit for the Strat+Lux total, i.e. how much extra space per city have you allocated to recording 'excess' resources beyond the original 32-limit? Another 32 bits, or is it potentially more flexible than that?
 
Last edited:
Flintlock... Excellent Method to solve the Phantom Resource Bug. Thank You for the concise explanation :goodjob::hatsoff:

I second this. :agree: This is truly a phantastic achievment! :hatsoff:Is the limitation of all kind of resources (strat./lux.bonus) to a total of 256 now fallen, too ?
 
Is the limitation of all kind of resources (strat./lux.bonus) to a total of 256 now fallen, too ?
I wouldn't think so, I believe this is unrelated - after all, the phantom resource bug doesn't cause the game to CTD at the start.

The same method to fix the phantom resource bug could potentially, however, be used to fix the 256 Improvement/Wonder limit since from what I remember playing around with adding more improvements than that in Steph's editor many years ago, the issues arised specifically within the city (i.e. the game could load more than 256 improvements but had no way of knowing which improvements past the first 256 were built in any given city so just threw a bunch randomly in there). But that's food for later thought!
 
I'm not a coder, so have I understood correctly that this means mods can now safely include >32 Strat+Lux resources...?
If so, what is the new limit for the Strat+Lux total, i.e. how much extra space per city have you allocated to recording 'excess' resources beyond the original 32-limit?
That's correct, having more than 32 strat and lux resources now should not cause any problems. The modded executable will allocate as much space as it needs for however many resources are included in the scenario data.
Is the limitation of all kind of resources (strat./lux.bonus) to a total of 256 now fallen, too ?
No, I haven't touched the 256 resource limit. I'm not sure if it would be plausible to remove that, I'd have to look into it. One difficulty with that limit is it might come into play in many different places throughout the code, unlike the 32 resource access bits which were a one-off thing. Same goes for the 256 building limit.
 
A parse error is like a grammatical error, for example a missing comma or quotation mark. That error message should also contain the name of a config file, I'm pretty sure the only way it can appear is when the game fails to load one. The line number is there to hopefully help you track down where in the file the problem is.
 
I honestly do not know if this has been covered already, but automated workers are annoying. At the very least, I would like to set the priority of automated worker actions. They want to clear the forests I plant!, That's ... annoying.
 
Is there a way to bring PTW artillery targeting into C3C as a "true/false" option? The PTW version is far more realistic.
Can you explain what PTW artillery targeting entails? I've never played PTW, and it's not easy to get hold of it these days.
 
Can you explain what PTW artillery targeting entails? I've never played PTW, and it's not easy to get hold of it these days.

In vanilla and PTW, artillery units target cities the same way air bombard does. You have a 1/3 chance to either hit the units, the improvements or the population. In C3C artillery is "smart" and only targets units until all of them have been redlined. IMO it's both unrealistic and overpowered and heavily favors the human player. The AI often doesn't concentrate enough artillery and offensive for an outright assault but due to its sheer numbers will manage to bombard your cities for a good number of turns. I've made artillery not capture-able otherwise they'd just be donating them without doing any damage. Had the targeting been PTW style, my defending city would have been severely damaged even if the AI couldn't storm it.

Also air bombard has been changed in C3C. Air bombard in C3C can lethally affect air units and will smartly target them first. Bombers thus combat fighters chiefly by bombing them. A fighter has 2 defense. If the bomber slips past the interception chance of 50% it would likely severely damage or even kill the fighter with its 12x3 bombard.

Cruise Missile units in C3C will always target sea units first. I'm not sure if that's the case in PTW.
 
Last edited:
Can you explain what PTW artillery targeting entails? I've never played PTW, and it's not easy to get hold of it these days.
In Vanilla and PTW, bombardment of towns would destroy improvements (Walls first, if present), population and units about equally often.

So you needed a comparatively much bigger bombard-stack to be sure of redlining all the defenders, and if you succeeded in doing so, there wouldn't be much of the town left to capture.
(Ah, ninja'd by @Predator145! :ninja: )
I've never played PTW, and it's not easy to get hold of it these days.
If one already has C3C installed, then technically all one needs is the Civilization3X.exe to put in the PTW root-folder.

And then it's just a question of knowing where to look... ;)
 
In vanilla and PTW, artillery units target cities the same way air bombard does. You have a 1/3 chance to either hit the units, the improvements or the population.
Alright, thanks for the explanation. It may be easy to restore that behavior, or may be quite difficult, it all depends on how the code is structured. I've haven't looked at the combat code much so I can't say right off hand.
The AI often doesn't concentrate enough artillery and offensive for an outright assault but due to its sheer numbers will manage to bombard your cities for a good number of turns.
That reminds me, I was planning to try to get the AI to join its offensive units up with its artillery stacks. I believe it already joins them up with each other in a very limited way to form little attack stacks. I've noticed that the AI often has stacks of artillery bombarding cities with no offensive units around to capitalize on the damage. I think it would help a lot if the offensive units felt a little push keeping them near the artillery. Ideally the AI would understand the idea of unit stacks and try to form & use them like in Civ 4 but that's probably not practical to patch into the game.
If one already has C3C installed, then technically all one needs is the Civilization3X.exe to put in the PTW root-folder.
That EXE name is kind of unfortunate given the name of this mod. If I'd known "X" was already associated with PTW, and it's not just that file name I've seen it elsewhere too, I probably would have named the mod something else.
 
Alright, thanks for the explanation. It may be easy to restore that behavior, or may be quite difficult, it all depends on how the code is structured. I've haven't looked at the combat code much so I can't say right off hand.

That reminds me, I was planning to try to get the AI to join its offensive units up with its artillery stacks. I believe it already joins them up with each other in a very limited way to form little attack stacks. I've noticed that the AI often has stacks of artillery bombarding cities with no offensive units around to capitalize on the damage. I think it would help a lot if the offensive units felt a little push keeping them near the artillery. Ideally the AI would understand the idea of unit stacks and try to form & use them like in Civ 4 but that's probably not practical to patch into the game.

That EXE name is kind of unfortunate given the name of this mod. If I'd known "X" was already associated with PTW, and it's not just that file name I've seen it elsewhere too, I probably would have named the mod something else.

Imagine being able to designate different codes of targeting for different units have both of them in the game at the same time. You'd be able to create a new class of "smart artillery" targeting units first as opposed to the conventional one. Maybe a direct fire arty line like ballistas all the way to AT guns and ATGMs as opposed to conventional catapults to howitzers.
 
Back
Top Bottom