Resource icon

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

I have now found a document in my archives with posts that were written 10 years ago or earlier, offering an interesting solution for that problem. Unfortunately I have no link to that post and have not noted the author of that post, offering the following solution for that problem:
This definitely helps, it would be easy to do something equivalent to this through C3X. Do you know if this edit completely fixes the bug, including stopping the game from crashing? Or does it only hide the message boxes?
 
This definitely helps, it would be easy to do something equivalent to this through C3X. Do you know if this edit completely fixes the bug, including stopping the game from crashing? Or does it only hide the message boxes?

Flintlock, I was not able to create a working test-exe with this fix and therefore unfortunately I have no further details if this fix is working and if it only hides the message box or if it also fixes the CTD. The original post didn´t speak about fixing crashes, but may be, when this was posted long time ago, the author was not aware of the possibility of crashes. If I would have a working exe with that fix in the next step I would look what happens when starting the AOI scenario (Age of Imperialism) and click in one of the civilopedia unit entries on the resource iron (marked with a "Don´t click" icon).
 
Last edited:
#1 will be easy but #2 will be difficult, maybe not possible, but I'll have to give it some thought first. The issue with #2 is that the game adds resources to each trade network on a per-tile basis. In other words, it processes all tiles on the map and for each one with a resource, it marks every city on the same trade network as that tile as having access to the tile's resource. A city could add a resource to its tile but the assumption that each tile only has one resource is baked in. So enabling cities to add resources to their trade networks will either require extensive machine code edits, or I'll have to think of something clever.
(Quoting myself here for an update) I've since figured out a way to enable buildings to generate resources and add them to the trade network. It didn't require anything super clever. First, for some context, the game begins by calculating trade networks, i.e. what tiles & cities connect to what others, then it calls a function I've called "recompute_resources" that fills in the available resources on each trade network. recompute_resources begins by looping over every tile on the map and for every tile that's owned by a player and has a resource, propagates that resource throughout whatever trade network that tile is part of, including recording access for all cities on the network. After the loop, recompute_resources runs some logic that I don't fully understand but can see includes something about player trade agreements, recomputing city happiness, and displaying those advisor popups that go like "we've connected [luxury], this will make our people happy."

The ideal way to enable buildings to generate tradeable resources, i.e. what I would do if I had the source code, is to modify that loop over tiles to include additional logic for the case where a tile has a city with buildings that are generating resources. In that case, it would simply process those resources in addition to any on the tile itself. But it would not be practical to patch that in to the compiled code because it was written assuming that each tile had only one resource, if any at all. I realized I could work around this problem by extending the loop. In other words, I wanted multiple resources per tile, so instead of changing how each tile is processed, I could make it process the same tile multiple times with different resources.

The loop works over tile indices, 0 1 2 ... up to the tile count, and calls a method I called "get_tile" to get the tile object for each index. I was able to make the loop visit the same tile multiple times by temporarily increasing the tile count just for the recompute_resources function and intercepting its calls to get_tile so that, once it runs past the tile count, it starts getting the tiles that I want to be processed again. Making it so that those tiles have different resources on their multiple passes was similarly easy, as recompute_resources calls a function to get the resource on any tile and I intercepted that too. The last piece of the puzzle is that I injected some code that runs before recompute_resources to check every city on the map for buildings that are generating resources. For each one it finds, it records the tile the city is on and the resource generated so that info can be used by the mechanism I described.

So buildings generating resources now works. There are only a couple of small things left to do, for example I need to add a check for the case where a building is generating a resource that its owning player doesn't have the tech for. Right now the resource is provided, but it shouldn't be. Also if a building generating a resource is sold or destroyed, the resource is still provided until the end of the turn. That's because the game doesn't recompute resource access when a building is lost unless the building was enabling air or sea trade. I need to make it do that too for buildings that are generating a resource.

I also made it so buildings can generate resources not for the trade network, just for their city alone. That was much easier. I only had to modify the single function that checks if a given city has access to a given resource to include a check for if that resource is being generated by a building. The other thing I wanted to do before R11 (the first thing was resource generation by buildings) was allowing buildings as prerequisites for unit construction. That's done too. It took a while but doesn't make for an interesting story. The gameplay code modifications were simple, I just had to modify the single function that determines if a given city can produce a given unit. The hard part was reading in the rules from the text config. The mod is written in C and doing text processing in C is always a pain. Here's an example of what it looks like in the config:
Code:
building_prereqs_for_units = [Factory: Tank "Modern Armor",
                              Barracks: Swordsman Cavalry Tank "Modern Armor",
                              Airport: Bomber]
That's it for R11. Like I mentioned before, I don't want to keep adding things because then it will never be done. I'll look into that maximum hypertext links thing for R12. R11 still needs some finishing touches then I'll post it. That'll be soon... ish, like not this week but for sure by the end of June.
 
Flintlock, this is great news!

for example I need to add a check for the case where a building is generating a resource that its owning player doesn't have the tech for. Right now the resource is provided, but it shouldn't be

If that building (mill) is only available at least with the tech that makes the resource available, such a check seems to be not necessary.

The great advantage of these resource producing buildings would be to produce strategic (or luxury) resources, that are not available by normal techs, per example transforming coal or oil into petrol or the sythetic production of rubber (very useful, especially in WW 2 scenarios). So generating a resource, that no player owning such a building has the tech for (era none tech), would just be the constellation I think it would be the most useful for modders. Therefore I think, the current situation without such a check, is much better. :)
 
Last edited:
Unless the city is captured by a less advanced player or traded away to a less advanced player.

For capturing that city this is no problem when the "mill" holds culture or is a SW. If the city is traded away (what happens much less frequently than capturing), this is part of the deal. In most of these cases a civ that hasn´t the relevant tech will have not much profit, as the units that can been built with that "artificial" resource will not be available without that tech, too.

And to say it directly: These "artifical resources", that can not be gained normally, can be the base for complete new chains of industry in Civ 3, especially in combination with the fix of the ghost resources bug in the Flintlock patch. :)
 
Last edited:
Quick question on resource production, if I had a building, say a Steel Plant, which required Iron and Coal, and produced Steel, would it cease producing the resource if the city lost access to either Iron or Coal?

The great advantage of these resource producing buildings would be to produce strategic (or luxury) resources, that are not available by normal techs, per example transforming coal or oil into petrol or the sythetic production of rubber (very useful, especially in WW 2 scenarios). So generating a resource, that no player owning such a building has the tech for (era none tech), would just be the constellation I think it would be the most useful for modders. Therefore I think, the current situation without such a check, is much better. :)

Instead of making these resources require an era:none tech, surely they can just not be selected to appear on any terrain, which is a much simpler option?

It could also be used with regular resources, e.g. if I had a Latex resource (available only to American civs from early in the game and necessary to build a Ball Court improvement) and a seperate Rubber resource available in the Industrial era, I could make the Ball Court (again, requiring latex) produce a Rubber resource thereby removing the separation when the Industrial Era hits.
 
If that building (mill) is only available at least with the tech that makes the resource available, such a check seems to be not necessary.

The great advantage of these resource producing buildings would be to produce strategic (or luxury) resources, that are not available by normal techs, per example transforming coal or oil into petrol or the sythetic production of rubber (very useful, especially in WW 2 scenarios). So generating a resource, that no player owning such a building has the tech for (era none tech), would just be the constellation I think it would be the most useful for modders. Therefore I think, the current situation without such a check, is much better. :)
If you want a resource to be available only through a building, the natural way to do that would be to set it so the resource doesn't appear anywhere on the map. I expect the check won't be necessary in most cases as typically the resource and building will be enabled by the same tech but I can also imagine cases where you'd want to separate them. For example a forge building could give a production bonus and produce jewelry from gold, with the jewelry only enabled by a later tech than the forge itself. Or maybe oil refineries could be unlocked in the industrial era and only start producing plastic in the modern era.
Quick question on resource production, if I had a building, say a Steel Plant, which required Iron and Coal, and produced Steel, would it cease producing the resource if the city lost access to either Iron or Coal?
I haven't implemented that yet but I plan to. Though this does raise a problem: if production of some resource B requires some resource A which is also produced by a building, that might not work since there's no guarantee that the game will compute access for resource A first. It will work when resource A comes from the map since resources on tiles are all processed before the buildings. Buildings are processed city by city and cities, as far as I know, are usually but not necessarily listed in the order they were founded. I'll have to think of something.
 
Quick question on resource production, if I had a building, say a Steel Plant, which required Iron and Coal, and produced Steel, would it cease producing the resource if the city lost access to either Iron or Coal?

Such a function, as it is in C3C for the autoproduction of units would be nice, but when reading the following part at present I guess, that this is not implemented, as the check is on the building and not additionally on the resources that are needed by the building:

check every city on the map for buildings that are generating resources. For each one it finds, it records the tile the city is on and the resource generated so that info can be used by the mechanism I described.

I am interested in the answer of Flintlock, too. :)

Instead of making these resources require an era:none tech, surely they can just not be selected to appear on any terrain, which is a much simpler option?

I posted the solution with the era-none tech, as an argument, that the tech check for the case where a building is generating a resource that its owning player doesn't have the tech for, is not necessary. It was a quick argument, that such a check is not necessary and the current situation without such a check is much better.

It could also be used with regular resources, e.g. if I had a Latex resource (available only to American civs from early in the game and necessary to build a Ball Court improvement) and a seperate Rubber resource available in the Industrial era, I could make the Ball Court (again, requiring latex) produce a Rubber resource thereby removing the separation when the Industrial Era hits.

:yup: Yes, this new function opens a cornucopia of new modding options. :)

Edit: Crosspost with Flintlock´s post.
 
I posted the solution with the era-none tech, as an argument, that the tech check for the case where a building is generating a resource that its owning player doesn't have the tech for, is not necessary. It was a quick argument, that such a check is not necessary and the current situation without such a check is much better.
It's still not clear to me why you'd rather not have the check. As far as I can see, the check makes the difference between:
  1. (With the check in place) You could create buildings that are built and then later generate a resource once a tech is unlocked to reveal it.
  2. (Without the check) You could create buildings that grant early access to resources that haven't yet appeared on the map, that will only appear later with a tech.
I can think of some cases where #1 would be useful but none for #2. The specific things you mentioned are a building to convert oil into petrol, that shouldn't be problem since petrol wouldn't appear on the map, and a synthetic rubber producer, but that would only come after the tech to unlock natural rubber, no?
:yup: Yes, this new function opens a cornucopia of new modding options. :)
:thumbsup:
 
It's still not clear to me why you'd rather not have the check. As far as I can see, the check makes the difference between:
  1. (With the check in place) You could create buildings that are built and then later generate a resource once a tech is unlocked to reveal it.
  2. (Without the check) You could create buildings that grant early access to resources that haven't yet appeared on the map, that will only appear later with a tech.
The problem could be in the appearance ratio of strat./lux. resources. A limited appearance ratio must be at least 1. According to the Civ3ConquestsEdit an appearance ratio of 0 means only a random distribution of that resource.

Appearance Ratio.jpg


CCM holds a resource, that is unavailable for any terrain with an appearance ratio of 1.

Gamemechanics.jpg


In the past there were some situations when one Gamemechanics resource could be seen on the map in games played in Debug mode. I tried to do a screenshot showing such a situation, but I haven´t detected such a resource in my current Debug testgame. It can also be the case, that in those Debug testgames, longer time ago, one of those terrains was accidentally enabled for that resource.

The second reason is, that I want to have this fantastic option as quick as possible without hurrying you. :)
 
Last edited:
So I'm finally playing through a real game with C3X and the AI is besieging my outlying cities with catapults and AHHH THIS CHANGES EVERYTHING :run::bounce:

It's a bit different. But, on the other hand when you take out such a stack, you get their artillery type units.
 
It can also be the case, that in those Debug testgames, longer time ago, one of those terrains was accidentally enabled for that resource.

100% sure that would be it, because if no terrains are enabled for the resource, it physically cannot be found on the map; the game absolutely will not put it on a tile that isn't selected.
 
Flintlock, I was not able to create a working test-exe with this fix and therefore unfortunately I have no further details if this fix is working and if it only hides the message box or if it also fixes the CTD. The original post didn´t speak about fixing crashes, but may be, when this was posted long time ago, the author was not aware of the possibility of crashes. If I would have a working exe with that fix in the next step I would look what happens when starting the AOI scenario (Age of Imperialism) and click in one of the civilopedia unit entries on the resource iron (marked with a "Don´t click" icon).
This is the source: https://forums.civfanatics.com/threads/hyperlink-limit-exceeded-bug-fix.307663/
I did try it once. It does not work with the steam executable. Instead, I had to use a file from Antal (p4) but the GOG version would probably work as well.
While this modification does indeed remove the pop-up, it does not remove the crash. It may increase the effective number of links possible, but not by much. The test subject was AOI: normally lumber gives many warnings while industrialization CTD. With this modification, lumber(and oil) gives no warnings but the crash with industrialization persist.

EDIT: Fun fact, the first post I wrote here mentions this exact method. To be fair, I had not created a working exe back then.
 
Last edited:
The second reason is, that I want to have this fantastic option as quick as possible without hurrying you. :)
Don't worry about that for the technology checks, those would be easy to implement. The only significant roadblock now is the resource ordering issue, so resource generation chains can work reliably. I think what I'll do there is make it so that resource generation from buildings is processed in the order that the resources appear in the scenario data. That's easy to implement. Remember when I said I injected some code to record a list of resources generated and their city locations? It's just a matter of sorting that list by resource ID. The thing I don't like about that approach is that it's only a half solution, the other half being up to mod authors to put resources in the correct order. Another option would be to identify the resource tiers automatically, but that's not simple and foolproof either since a simple algorithm to do that will fail if there's a cycle in resource dependencies.
While this modification does indeed remove the pop-up, it does not remove the crash.
That's too bad. It's still probably worth it to hide the message boxes. I'll look into the code that triggers them to see if I can figure out why it's crashing & maybe I can prevent the crash too.
 
It's a bit different. But, on the other hand when you take out such a stack, you get their artillery type units.

I think modding artillery to very low defense stat and -4 HP is needed for more balanced gameplay. By the time you take out the 1st civ you'd be swimming in free artillery with stock game settings. Also, the AI fails to follow up their bombardment with offensive units most of the time if they lack fast movers.
 
So I'm finally playing through a real game with C3X and the AI is besieging my outlying cities with catapults and AHHH THIS CHANGES EVERYTHING :run::bounce:

The AI can also properly use armies now. And they're just as busted in AI hands as in humans'. Usually the AI lucky enough to create leaders end up steamrolling the others and become the dreaded run away. Except now with armies not even coalitions can stop them. The AI doesn't know how to deal with armies at all pre-bombers. They're basically immortal.
 
I think modding artillery to very low defense stat and -4 HP is needed for more balanced gameplay. By the time you take out the 1st civ you'd be swimming in free artillery with stock game settings. Also, the AI fails to follow up their bombardment with offensive units most of the time if they lack fast movers.

I played an always war monarch game (except I can trade with a civ and then declare on the same turn). I would see a defender and an artillery unit. I got a stack of 3-5 one time with defenders. I've also seen them drop off artillery type units via boats in 20k games on emperor. Sometimes, they would only drop off say a trebuchet with no defender or attacker. It was quite silly, and could have happened since the defender in the boat might have gotten disbanded due to a unit support issue.

I played some on deity, BUT, I was using a modified version of the Quick Civ mod, so that might have thrown things off.

What I can say is how their stacks perform on high levels against the human player. At mid and lower levels they seem to be cheap captures, I agree. I thought I remember seeing earlier in this thread a mega stack of AI units with artillery type units that wouldn't be a cheap capture.

Also, I've had a few trebuchets bombard my armies before (the AIs won't attack a 7 hp fortified 3 unit, 3 defense army before tanks and maybe not a 6 hp fortified 3 unit, 3 defense army), which if they had enough trebuchets, could mean that they would attack it that turn. And I have a habit of using armies to cover workers who have made rails, so that could be bad. Though, likely the AIs probably need artillery proper and rails before they could pose a serious threat to my armies, and then they would have to use them in the right way, which they probably wouldn't.
 
Back
Top Bottom