Resource icon

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

The challenge is that the AI doesn't move its units into a city with the required improvement (barracks, harbor, airport) to be upgraded like the human would. The units would just be upgraded in whatever city they're stationed in if they're lucky to have the needed improvement. To remedy this, perfume the 3 above mentioned improvements so that they get built in every city.
A better solution could be to set the palace a SW (as it is in CCM) that provides barracks (set to no maintenance costs) to every city of a civ.
 
The AI will upgrade units as long as they have an AI strategy in the editor and as long as they have the cash for it. I'm not sure if the AI will upgrade if it has 0 cash but the upgrades themselves too require no cash.

The first sentence sounds like the AI spends gold on upgrades, but the second sentence sounds like they don't spend gold on upgrades.

From what I've seen with MapStat in the classic game, I think that they do spend gold when upgrading.

The AIs upgrading more might sound like it will make them more difficult. Of course, surely, it will result in them having higher value units. However, in the classic game AIs use that gold to trade. So, for players who don't seek to conquer the AIs, that could make them easier. It could also mean that they end up easier to conquer, for example, they could get the draft later if they upgraded their spearmen to musketmen and thus ended up getting to Nationalism later.

The AIs moving units out from the battlefield to go upgrade also doesn't seem like it would work out well. Imagine their stack of trebuchets and pikemen all of a sudden turning around to go upgrade. Or they have a stack of knights charging at your border city which all of a sudden turn around to go to the other side of their empire to upgrade.
 
The first sentence sounds like the AI spends gold on upgrades, but the second sentence sounds like they don't spend gold on upgrades.

In the second sentence he's saying he's not sure if the AI will upgrade if it actually has no money, even if the upgrade itself is free - it will sometimes upgrade if it does have money, but seemingly not all the time.
 
Did you find out if the "defense" of terrain improvements/overlays vs bombardment uses the same value as citizens or buildings, and if not can you make it configurable?
It doesn't. Looking through the logic for bombard-damaging terrain, I don't see any references to the building or citizen defense bonuses. The chance to do damage depends only on the tile's terrain, whether it has a fortress or barricade, and of course the stats of the attacking unit. Making it configurable would be easy since it calls out to a couple of functions to get the tile's defense bonus so I could intercept those calls and add some extra.

City base maintenance. I think you said it would be doable to add a cost but you didn't know how to show it in the UI. How difficult would it be to vary the cost by size level and/or government? Visually, I think it would make sense to show the cost as red coins either to the right of "IMPROVEMENTS", or in place of the treasury gold at the top (why is that even relevant here?)
Once it's working at all, making city maintenance vary by city size or government would be easy. The hard part would be reading in those rules from the config file. This is a case where the ideal thing would be to allow a little Lua script to compute the maintenance amount but setting that up would be a huge amount of work.

Did you ever find the problem with culturally linked starting locations?
Unfortunately not. I spent a week or two looking into it a while back but gave up in the end. This bug is hard because there's a lot of code that goes into determining starting locations and it's spread out over several different large methods that the decompiler doesn't handle well. I wasn't even able to get a clear picture of how starting locations are placed, never mind figure out what was wrong with it.

And a new request: Both thematically and for gameplay, it's unfortunate that you can only see 1 tile away from your starting location. For random maps, would it be practical to either expose a larger radius, or automatically trigger the "maps of their region" goody hut effect?
It would be simple to reveal some more tiles around the starting settler. I've already found the method to reveal a tile and the method that gets called when a unit starts its turn, so I could insert a bit of code to reveal two rings of tiles around settlers when they begin on turn 0. Again it would be nice to be able to do this sort of thing with a little Lua script. Also as Civinator pointed out, you can do almost the same thing using the scenario editor.

1. AI sends his defense unit to pillage strategic resource. When defense unit is staying on tile with strategic resource I bombard him. Wounded AI's unit run away to heal but he can to pillage tile with strategic resource. He heal and then to attempt pillage again. Again and again. I think will be better if wounded AI's unit is so far from healing zone he must pillage.
2. Can AI upgrade obsolete unit? I often see AI's units different eras together. It is the big problem for him because his army is weak.
I don't know the inner workings of the AI well enough to be able to make these sort of changes easily. For example, I don't even know how the AI tracks which defenders have been assigned to pillage duty. Presumably that's the use of one of the 3 unit states I haven't figured out yet. Even knowing that, the modification might be difficult since the unit AI is not very flexible in general. About AI upgrading, as far as I know it's like Predator145 said, the issue is the AI isn't smart enough to move its obsolete units to the cities where it has barracks. The difficult part about adding that behavior to the unit AI would be somehow integrating it with all the other things the unit could potentially do.
 
I've been away for a little bit but I see that someone picked up where Antal left off. This is an amazing patch. I have a question I don't know if it has been asked before. I'm interested in limits. What are the limits? Would it be possible to:

1- Limit building auto-production of "Army" units after the "Army" city requirement threshold is met? Just how you cant build any more armies because you dont have enough cities. Oddly it doesnt apply with auto-production.
2- Limit the game from from graying out A/D and air defense values when the "Army" ability is chosen in the editor? We should have the option to adjust values there or leave as zero for default settings.
3- Limit the AI from prioritizing the "Army" strategy if any other strategy has been selected? Example: attack, defense, artillery, cruise missile, tactical nuke...

The point of this is to allow the use of the "Army" flag under "Abilities" for custom uses without sacrificing the intended AI strategy and retaining the unit's intended/original function. Example: A tank with the "Army" ability still behaves like a tank, and the AI uses it as a tank. It'll just allow me for example to make use of the "Army" ability city count limit to limit the amount of tanks I can have at a time.

I hope I didnt get carried away I'm just curious about whats possible. These things are built in the game already but it'd be nice to have some form of control to customize things a little.
 
Last edited:
Unit limits were already discussed, and without needing to tag them as armies:

That is possible and should be relatively easy. I recently discovered that the game already maintains a count of how many units of each type each player has in production, so that simplifies things. I'd probably have the limits defined by a list of pairs of unit types and numbers, for example [Missionary: 3, Spy: 3, "Corporate Executive": 5]. That should be the easiest way unless you want many unit types to have the same limit.
 
1. Diplomacy. I play random map. I have one city. I have 30 000 coins. Any AI civilization asks 100-120 coins or will declare war. They ask always too little gold when I have thousands coins. I pay 100 gold and they not declare war. It is so easy to pay 100 gold. Will be better if AI asks not 100 coins, and 80-90% of my treasury.
2. AI declares war if I not pay gold. AI declares war if I not permit to move its units across my territory. It is all. It is so easy. I feel safe playing with AI. Will be better if AI will declare war when it is stronger and bigger than I am. Just declares war without asking gold.
 
It doesn't. Looking through the logic for bombard-damaging terrain, I don't see any references to the building or citizen defense bonuses. The chance to do damage depends only on the tile's terrain, whether it has a fortress or barricade, and of course the stats of the attacking unit. Making it configurable would be easy since it calls out to a couple of functions to get the tile's defense bonus so I could intercept those calls and add some extra.
So it takes the tile's defense modifiers into account. That makes sense. But those are all multiplicative, so there must be a base value somewhere. I'd like to be able to set a higher base, as I plan to increase unit stats across the board which will make mid-late game bombardment strength substantially higher.
Once it's working at all, making city maintenance vary by city size or government would be easy. The hard part would be reading in those rules from the config file. This is a case where the ideal thing would be to allow a little Lua script to compute the maintenance amount but setting that up would be a huge amount of work.
I wouldn't say to no Lua :D but understandably that's unreasonable for now. How about a single flat rate though?
Unfortunately not. I spent a week or two looking into it a while back but gave up in the end. This bug is hard because there's a lot of code that goes into determining starting locations and it's spread out over several different large methods that the decompiler doesn't handle well. I wasn't even able to get a clear picture of how starting locations are placed, never mind figure out what was wrong with it.
Darn. If you ever sort it out I'm sure it would be a popular feature.
It would be simple to reveal some more tiles around the starting settler. I've already found the method to reveal a tile and the method that gets called when a unit starts its turn, so I could insert a bit of code to reveal two rings of tiles around settlers when they begin on turn 0. Again it would be nice to be able to do this sort of thing with a little Lua script. Also as Civinator pointed out, you can do almost the same thing using the scenario editor.
Good to know. I think I'll try radar for now. I do like the idea of having a semi-random region explored though.
 
This is an amazing patch.
Thank you!

Would it be possible to:
1- Limit building auto-production of "Army" units after the "Army" city requirement threshold is met? Just how you cant build any more armies because you dont have enough cities. Oddly it doesnt apply with auto-production.
2- Limit the game from from graying out A/D and air defense values when the "Army" ability is chosen in the editor? We should have the option to adjust values there or leave as zero for default settings.
3- Limit the AI from prioritizing the "Army" strategy if any other strategy has been selected? Example: attack, defense, artillery, cruise missile, tactical nuke...
  1. I'm certain it would be possible to stop auto-production of armies once the per-city limit has been reached. I'll try to get that done for R18 since it should be easy.
  2. I don't want to modify the editor for two reasons. First, it would be a lot of work. When modifying the game itself, I can build on top of all the work Antal and I have done reverse engineering it, whereas for the editor I'd be starting from zero. Second, there are already third party editors that allow you to set up all sorts of rules that the official editor doesn't. If those rules don't work in the game then I'd consider modifying it to make them work. I'm not sure what exactly you're asking for here, what should armies do that they currently don't?
  3. If the only point is to cap unit production by type, I could do that directly. If you want AI armies to run a different strategy, for example the offensive unit strat, that's also possible. I'm not sure if that would work well in practice, but it's possible to redirect the AI's processing like that.

1. Diplomacy. I play random map. I have one city. I have 30 000 coins. Any AI civilization asks 100-120 coins or will declare war. They ask always too little gold when I have thousands coins. I pay 100 gold and they not declare war. It is so easy to pay 100 gold. Will be better if AI asks not 100 coins, and 80-90% of my treasury.
2. AI declares war if I not pay gold. AI declares war if I not permit to move its units across my territory. It is all. It is so easy. I feel safe playing with AI. Will be better if AI will declare war when it is stronger and bigger than I am. Just declares war without asking gold.
Noted. I'd have to look into these to say anything about how easy they would be to do since so far I have barely looked at the AI diplo code.

So it takes the tile's defense modifiers into account. That makes sense. But those are all multiplicative, so there must be a base value somewhere. I'd like to be able to set a higher base, as I plan to increase unit stats across the board which will make mid-late game bombardment strength substantially higher.
I guess you could say the base value is 100. The specific rule is that the chance to do damage on each roll equals 1 - X/(S + X) where S is the attacker's bombard strength and X = floor((100 + D) * 16 / 100) where D is the total tile defense in percent. The attacker gets to roll multiple times up to its rate of fire and if it succeeds on any roll then the tile is damaged.

It's because of rate of fire that late game units are so effective at bombarding tiles. Based on some quick math in Excel, a bomber (S=12, RoF 3) has an 80% chance to destroy an improvement on plain grassland (D=10). If it had a RoF of 1 instead, it would need a strength of 66 to have that same 80% chance.

Also, if you were to double the bomber's strength (so S=24, RoF 3), it has a 93% chance to damage the tile. To bring that back down to 80%, you'd need to increase the tile defense bonus to D=113.

Good to know. I think I'll try radar for now. I do like the idea of having a semi-random region explored though.
It's an interesting idea to give the player a random map reveal at the start of the game. Unfortunately it would be awkward to implement since the goody hut effects are all integrated into the same method. There's one method that's called whenever the player pops a hut and it's responsible for both rolling which bonus the player gets and awarding the bonus. So to give a particular bonus, I'd either have to modify that method to force the outcome of the random roll or duplicate the code to award the bonus.
 
I don't want to modify the editor for two reasons. First, it would be a lot of work. When modifying the game itself, I can build on top of all the work Antal and I have done reverse engineering it, whereas for the editor I'd be starting from zero. Second, there are already third party editors that allow you to set up all sorts of rules that the official editor doesn't. If those rules don't work in the game then I'd consider modifying it to make them work. I'm not sure what exactly you're asking for here, what should armies do that they currently don't?
The problem:
Ok so imagine you want to limit tank production and you came up for a way to limit units based on unit count as proposed in previous posts. We have 2 civs for this example. Civ1 has 50 cities and Civ2 has 10 cities. If you limit tank production by unit count alone then both Civ1 and Civ2 will build the same amount of tanks, even though Civ1 is much bigger than Civ2.

My solution:
This is why I thought using the "Army" ability would come in handy. By going into the editor and selecting the "Army" ability for the vanilla tank unit they will be counted as an "Army" and will then require you to have 3 cities to support each tank until capped. Civ1 (50 cities) could support 16 tanks while Civ2 (10 cities) could only support 3, assuming no actual army units are around.

The flaw:
Selecting the "Army" ability has unintended consequences. The graying out of the attack and defense attributes is the equivalent of turning those values down to zero. What other unit has zero attack or defense values? That would be workers, settlers and armies, thus turning our vanilla tank unit into a useless unit that cannot attack and will be destroyed if another unit walks into its tile. Also by having zero A/D values the AI strategy for A/D will also become grayed out and the AI will not know what to do with it. This makes my "solution" not viable for gameplay.

The workaround:
Yes by "stopping auto-production of armies once the per-city limit has been reached" can be used to bypass "The problem" and "The flaw" by relying on auto-production rather than manual production and using something like Quintillus editor to do the rest is absolutely acceptable to me. It will also keep things simple.

The conclusion:
It would be nice if you did make it so that we could limit any units based on unit count as you suggested in previous posts. I'd suggest you also add auto-production limits to that as well. I think that idea plus army auto-production limit would satisfy most limiting needs.
 
The AI will upgrade units as long as they have an AI strategy in the editor and as long as they have the cash for it. I'm not sure if the AI will upgrade if it has 0 cash but the upgrades themselves too require no cash.
I don't think that the AI will upgrade Settlers, Workers, or Units flagged as Kings.
 
I don't think that the AI will upgrade Settlers, Workers, or Units flagged as Kings.
The AI will definitely upgrade King-flagged units if it can afford to: anyone who's played the Sengoku conquest (or CCM) can attest to that.
 
The AI will definitely upgrade King-flagged units if it can afford to: anyone who's played the Sengoku conquest (or CCM) can attest to that.
Sorry: "brain blip:" I meant Armies, not Kings.
 
Sorry: "brain blip:" I meant Armies, not Kings.
Armies can also be set to upgrade.

The problem in unpatched Civ3, is that an Army can only be upgraded in a town with both a Military Academy-type SW ("Build Army" Wonder-attribute) and a Barracks-type Improvement ("Allows veteran units" Improvement-attribute) -- or an SW with both those attributes -- which is too complicated for the AI to take advantage of routinely. So they'll only do it "by accident", if/when an Army happens to pass through such a town.

That said, I recently (re?)discovered that if an Army upgrade-chain is built into the .biq (based on improved tech-level), then when a newly generated MGL is used to build an Army, the most recent upgrade-version available will be created. So the AI can already get the newest Army-version(s), they just won't voluntarily upgrade or disband their older ones -- they can only lose them in combat.

For the patch to fix that, one possibility might be to get the game to ignore the "Build Army" attribute-requirement, allowing Armies to be upgraded in any town with just a Barracks-type improvement, like any other unit.
 
Last edited:
Armies can also be set to upgrade.

The problem in unpatched Civ3, is that an Army can only be upgraded in a town with both a Military Academy-type SW ("Build Army" Wonder-attribute) and a Barracks-type Improvement ("Allows veteran units" Improvement-attribute) -- or an SW with both those attributes -- which is too complicated for the AI to take advantage of routinely. So they'll only do it "by accident", if/when an Army happens to pass through such a town.

That said, I recently (re?)discovered that if an Army upgrade-chain is built into the .biq (based on improved tech-level), then when a newly generated MGL is used to build an Army, the most recent upgrade-version available will be created. So the AI can already get the newest Army-version(s), they just won't voluntarily upgrade or disband their older ones -- they can only lose them in combat.

For the patch to fix that, one possibility might be to get the game to ignore the "Build Army" attribute-requirement, allowing Armies to be upgraded in any town with just a Barracks-type improvement, like any other unit.

Does the "Build Army" flag only work on an SW and Wonder? Does it work on regular improvements? If yes then you could give all barracks that flag as well and then use the C3X config sheet to limit production of armies to the Military Academy.
 
Does the "Build Army" flag only work on an SW and Wonder? Does it work on regular improvements?
Yes to the first question, and No to the second -- at least, if using the Firaxis Editor. That flag's in the "Small Wonder attributes" section of the "Improvements + Wonders" tab -- which means it can only be activated if the building one intends to give that attribute to has already been set as a GW/SW.

IIRC, @Quintillus' Editor allows GW-attributes to also be assigned to SWs -- but I'm not sure whether it also allows a Wonder-attribute to be attached to a generic Improvement(?).
 
Last edited:
About the adjustable AI worker requirement: The way this works is it adjusts the city count that the AI uses to evaluate how many workers it needs. So if it's set to 150, the AI builds workers as if it had 50% more cities than it actually does. The reason I added this was that I've thought for a long time that the AI could benefit by building more workers. Perfuming doesn't work well to make it build more since the AI assigns a point value of zero to the worker build option when it feels it has enough of them. The proper approach is to modify how many the AI thinks is enough.

The cool thing about the adjustable worker requirement is that it works nicely alongside the AI's existing logic for building workers. The AI can still reduce its requirement as its cities become fully developed and it can still join workers back into its cities when it feels that's appropriate. If you crank the requirement up way high, say to 300%, the AI will build workers like crazy in the early game until it has improved all its tiles, then it will join its workers back into its cities and stop building more until it reaches railroad tech.

Here are the results from a test I ran (pretty sure this was on deity):

At turn 100, the AI with the standard 100% requirement had 20 workers. With the requirement set to 300%, it built up to 56 instead. As you'd expect, it made a lot more progress improving its tiles but its cities were smaller since their population had been turned into workers.
worker-req-cmp-turn-100.jpg


At turn 150, the standard AI had 19 workers. At 300% requirement, it had only 3! That's because it had almost finished improving its tiles at that point and so had joined almost all of its workers back into its cities.
worker-req-cmp-turn-150.jpg


I'm not sure if a 300% worker requirement would make the AI more competitive overall. I expect it would for AIs isolated on islands but with hostile neighbors it could backfire by leaving the AI open to getting rushed in the early game when it's depleted its city population by building workers. The default worker requirement in R17 is set to 150% so it should help the AI but not burden it too much. Eventually I'd like to make the worker requirement vary depending on circumstances, for example increase it based on how many jungle/marsh tiles there are to be cleared, how many hills/mountains there are to be improved, and increase it if accelerated production is turned on.

The problem:
Ok so imagine you want to limit tank production and you came up for a way to limit units based on unit count as proposed in previous posts. We have 2 civs for this example. Civ1 has 50 cities and Civ2 has 10 cities. If you limit tank production by unit count alone then both Civ1 and Civ2 will build the same amount of tanks, even though Civ1 is much bigger than Civ2.
...
The conclusion:
It would be nice if you did make it so that we could limit any units based on unit count as you suggested in previous posts. I'd suggest you also add auto-production limits to that as well. I think that idea plus army auto-production limit would satisfy most limiting needs.
Another problem with using the army ability to limit production is that you can only have a single limit shared across all unit types. There's no easy way to fix that since the game only stores a single army count per player. If I were to expand that to multiple counts for multiple unit types, might as well use those counts to limit production and forget about the army flag workaround. I think that's the easiest solution, actually. Just track how many units of each type each player has. I could modify Leader::spawn_unit and Unit::despawn to update the count as it changes. After that it wouldn't be difficult to limit production, even limiting based on city count would be simple.
 
About the adjustable AI worker requirement: The way this works is it adjusts the city count that the AI uses to evaluate how many workers it needs. So if it's set to 150, the AI builds workers as if it had 50% more cities than it actually does. The reason I added this was that I've thought for a long time that the AI could benefit by building more workers. Perfuming doesn't work well to make it build more since the AI assigns a point value of zero to the worker build option when it feels it has enough of them. The proper approach is to modify how many the AI thinks is enough.
Cool thing that you are looking into this, Flintlock. Building enough Workers is one of the areas where the human player can gain a major advantage over the AI, even at higher difficulty settings. I think your method of approach sounds just about right. This is why:

I ran some experiments about 2-3 years ago, to see if I could coerce the AI into building more Workers with the tools at my disposal at the time. More specifically, I tested whether setting the "Workers" flag under "Build often" in the vanilla Editor would have a measurable effect or not. And, whether it actually mattered how many "Build often" flags were set simultaneously, like 3, 4 or 5. I set up an experiment with a premade pangaea map, with only myself isolated on an unreachable island, and the Romans starting at a predetermined location on the main continent, without competition. Then I changed all the various parameters and let the Romans develop the continent fully multiple times (in Debug mode, so I could watch everything that was going on). My conclusions were:

Setting the "Build often" flag for Workers makes absolutely no difference. Because: The AI would always build a number of Workers equivalent to 80-90% of its number of cities at the peak of its development (49-57 Workers compared to 63 cities). It would never build more than that, no matter what. Then, as tile development progressed and the AI felt like it had redundant Workers, it would start killing them off. It did not bother moving them into cities to either add to the population, or disband them there to gain some resources back. It simply disbanded them on the spot, as soon as they had finished clearing one of the last jungle tiles, for example. Have you ever noticed during gameplay, that sometimes you suddenly hear a loud "UHHH!" sound, and wonder what it was, because you can't see any combat going on? Well, that's the AI killing off its own Workers! The AI would always finish developing the last tile very close to the year 1945, no matter how I changed the parameters (turn 445 in my mod, which is quite late). In the end, after all tiles had been developed, the AI would keep a token force of 8-10 Workers around.

After the experiment, as the ability to perfume units became available with the C3X mod, that didn't do the trick either. Because the AI kills off Workers it doesn't want. So it doesn't matter if you force it to build more. This is why I think fooling the AI into thinking it actually needs more Workers is the right way to do this. With that approach, it is just a matter of finding the magic number, the sweet spot that works best with the AI. I'm looking forward to this improvement.
 
Last edited:
Then, as tile development progressed and the AI felt like it had redundant Workers, it would start killing them off. It did not bother moving them into cities to either add to the population, or disband them there to gain some resources back.
I would see worker suicide during an invasion and thought it was some act of spite if the AI felt it couldn't get them to safety fast enough; I never knew it was a general behaviour. :eek:
 
Then, as tile development progressed and the AI felt like it had redundant Workers, it would start killing them off. It did not bother moving them into cities to either add to the population, or disband them there to gain some resources back. It simply disbanded them on the spot, as soon as they had finished clearing one of the last jungle tiles, for example
I wonder how often the AI joins its excess workers compared to disbanding them. In my own test I didn't look closely to see what was happening to the workers. I just assumed the AI was joining all of them since that would be the sane thing to do. (I should know better than to trust the Civ 3 AI to do anything smart.) I'll have to investigate what it usually does. I know the AI will join its workers in at least some circumstances. I've seen it do it.

Another thing I'll need to investigate is how the AI determines how many workers to keep around in reserve. I don't believe it keeps any around except for pollution cleanup. But I've also seen the AI get overwhelmed with pollution so whatever logic it's running there is not sufficient.
 
Top Bottom