Resource icon

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

Hehe, all hail lord lady Lua! :P Btw, what is it that makes this language so suitable for these applications compared to say python?
Lua was originally designed as an extension language and that's mostly what it's used for, for example Civ 5 used it for its interface. It's supposed to be very easy to call C/C++ to/from Lua. I don't know how it compares to Python, though, as I've never tried to use Python in that manner. I have already done a little proof of concept with Lua, calling Lua functions from the mod's inserted C code, and that all works nicely. It's pretty easy with LuaJIT's cffi module to interface with the C side of things from Lua.

What I like the most about Lua is that it's small and fast. Last I checked a full Python system requires about 20 MB, and I checked years ago so it's probably larger now. The rest of C3X is only about 3.5 MB uncompressed so adding Python would bloat it a lot. For comparison, LuaJIT is only a few hundred kB. LuaJIT is also among the fastest implementations of any dynamic language, partly because Lua is such a small language so it's easier to optimize while compiling without breaking things.

1) It is impossible to disable it later. It just need to uncheck this box when researching a technology (like a monotheism for example), but the editor lets only to turn it on.
This is easy to change. The game calls a function to check if a player has the tech allowing sacrifices, and I can intercept its calls and modify them to return whether the player has the allowing tech but not a disallowing one.

2) For some reason, if a unit (for example, a worker) does not have the sacrifice option enabled, the AI can still sacrifice it when researching the necessary technology, but you cannot.
I'll look into this. I can see in the AI's logic that there's a function gating sacrifices that doesn't check whether the unit type has the sacrifice ability. However, in the equivalent logic for the human player, I don't see that check either. Maybe I'm missing something.

3) I still do not understand the principle of culture points adding after the sacrifice. It would be logical if it depended on the religious type of civilization, but tests showed that there is no such connection.
Looking at the code for this, the formula is very simple. The value of a sacrifice is twice the unit's shield cost, times two for each doubling improvement in the city. Also, the value for xenophobic governments is zero unless the city has at least 51% native population.
 
I use it in the Modern period for Guerrilla units who spawn from victories against enemies by Militia units.

As a workaround for disabling sacrifice later in the game, try making two separate units: Forced Laborer (unit produced by capturing pop), which upgrades to Gladiator. Forced Laborer can't be sacrificed, but Gladiator can. If you tag Gladiator as a King unit, you won't be able to build it, only upgrade to it.
Thank you for help, I thought about something like this, but I didn't like this way because it would be able to break the AI's ability to manage these things.

I'll look into this. I can see in the AI's logic that there's a function gating sacrifices that doesn't check whether the unit type has the sacrifice ability. However, in the equivalent logic for the human player, I don't see that check either. Maybe I'm missing something.
Maybe disabling a unit's sacrifice ability simply disables the button in the interface that allows it? And the AI continues to use this function because it doesn't need the button?
 
@Flintlock
I have played with specialists for a while in the editor and I wish there were MORE options. I really liked civ4's concept of unique people specialists that joined the city as a super specialist. I'm not trying to copy civ4 but as a ruler it would feel more engaging if your servants could do more that just be there and could enforce your will in a more meaningful way.

Could anything be done to specialists to give them more depth such as:

Requirements:
-Require a resource available to the city to become available for hire.
-Require a building built in the city to become available for hire.
-Require a certain government to become available for hire.
-Require a certain unit to join the city to become available for hire.
-Require a certain specialist to be hired in the city to allow a unique unobtainable specialist.

Enhancements:
-Ability for specialist to provide food (1-?).
-Ability for specialist to provide or remove pollution (1-?).
-Ability for specialist to provide culture (1-?).
-Ability for specialist to provide a resource (1-?).
-Ability for specialist to upgrade to another specialist via research (Disabling the old one).
-Ability for a certain specialist to be consumed when a certain unit or building is built.
-Ability for AI to use vanilla specialists and modded ones as a result.


Limits:
-Limit how many of each kind can be hired per city (1-?).
-Limit how many of each kind can be hired per city based on resource amount (1 resource per specialist).
-Make specialists locked to their specialty.

With even a fraction of these options available one can accomplish so much through configuration!
Updated my post for "Enchancements" with:
-Ability for specialist to provide or remove pollution (1-?).

Even if you cant tell or teach the AI how to use the specialists at the very least I would like to add a trade off stat that the human player would receive in order to balance things out. Sure we can use specialists but that shouldnt come free specially if only humans can use it. We should be able to add negative tax, corruption, production, food, And/or pollution as a trade off unwanted stat for getting the extra benefits the AI cant use.
 
I know you can add negative gold to Specialists even in the Firaxis Editor, because I've done that (-1g) for all of them except the Taxman (but I doubled the Happies from Clowns, and the decorruption from Cops).

So you might also be able to add negative shields (for Geeks?) -- and possibly even negative happies (for Cops)? ;)
 
Last edited:
So you might also be able to add negative shields (for Geeks?) -- and possibly even negative happies (for Cops)? ;)
Steph tried negative shields from city specialists in his extended mod, but this caused a crash when the city were building improvements (but not when building units). I suspect it was a division by zero crash, since it only occured when the city produced only one shield and had employed this specialist with minus one shield. This was back in the days with Vanilla Conquest. It might be possible to squash this bug with C3X?

Link to thread where this crash was discussed (the Shaman is the culprit with minus one shield): Steph's mod 5: early testing.
 
I assume people have already asked for this, but is it possible to create a feature to form new civs in the middle of the game? Like secessionist revolts from existing civs, or emergent new civs from clusters of barbarian-held cities?
 
Negative happy faces from specialists work, you can see it for example in mods like "the desert and the mountain".
 
Maybe disabling a unit's sacrifice ability simply disables the button in the interface that allows it? And the AI continues to use this function because it doesn't need the button?
It's nothing so strange. As it turns out, the check for unit type's sacrifice ability is in the expected place, the main function that checks whether a given unit can perform a given command. I just didn't notice it initially because the code I'm looking at has been passed through an optimizer then a decompiler, and as a result is often counterintuitive. The check for the unit type's ability is at the beginning of the function separate from the rest of the criteria for sacrificing, which is later in the function in a branch for sacrificing specifically. That may be how this bug came about in the first place, maybe some programmer copied the criteria into its own function for the AI but forgot to copy over the ability check at the beginning too. In any case, it's easy to fix.

Steph tried negative shields from city specialists in his extended mod, but this caused a crash when the city were building improvements (but not when building units). I suspect it was a division by zero crash, since it only occured when the city produced only one shield and had employed this specialist with minus one shield.
I'll look into this before R24 is done. If it's a division by zero as you suspect, it ought to be an easy fix.

I assume people have already asked for this, but is it possible to create a feature to form new civs in the middle of the game? Like secessionist revolts from existing civs, or emergent new civs from clusters of barbarian-held cities?
I'm sure it's possible with enough effort but I don't have a good idea of how much effort it would take. For example, the game has a method I've named Leader::initialize_at_game_start which sets up a player object. Of course, in the base game that's only called when setting up a new game, so calling it in the middle of an ongoing game might cause various problems that must be hunted down and fixed. Or maybe not, maybe it will just work. That's happened before. I'd have to try it and see what happens in this case.
 
Thanks again for all your work and for this big laboratory

I would like to implement two mechanics:

1) Stack unit for town and cities, different from stack unit on terrains, so that for example Towns can handle max 7 units and citis 15.
Do you think that the following strings will work?

limit_units_per_town = 7
limit_units_per_city = 15

2) A bit more complex, but I would like to create a city siege effect, so that if the town/city is surrounded in all 8 tiles by units (land or naval) the units in the city will lose 1HP every 3 turn.
How could I write it in code? 😁

Thanks in advance

------------
EDIT

limit_units_per_town = 7 gives error message
The "limit_units_per_city" does not work:
if "exclude_cities_from_units_per_tile_limit" is true, there is no unit limit, if it's false the "limit_units_per_tile" entry wins. If I cancel it, it works like false
 
Last edited:
2) A bit more complex, but I would like to create a city siege effect, so that if the town/city is surrounded in all 8 tiles by units (land or naval) the units in the city will lose 1HP every 3 turn.
...and so that the city loses access to resources from outside.
 
I know you can add negative gold to Specialists even in the Firaxis Editor, because I've done that (-1g) for all of them except the Taxman (but I doubled the Happies from Clowns, and the decorruption from Cops).

So you might also be able to add negative shields (for Geeks?) -- and possibly even negative happies (for Cops)? ;)
Yes sorry i should rephrase my post. I am aware of negative stats that can be done in vanilla but in addition to that add pollution/-pollution to specialists. The main purpose of pollution to specialists would really be to punish human players in a way for using specialists since the AI can't use them. The benefits would outweigh the punishment anyways but since you can already do happiness, corruption, and gold why not do pollution (and food/-food by amounts larger than specified in the editor while at that). It would make for very unique specialists.
 
Last edited:
AI can't use them
Have you tested this? Just wondering how helpless the AI is in this regard - completely (uses only clowns when all city's tiles are already being processed) or only partially.

why not do pollution ... It would make for very unique specialists.
And CULTURE! Furthermore, it would be interesting to tie the ability to hire specialists to improvements and modify their usefulness as technologies are learned, like in Civ IV. But I let my dreams fly away too far.

P.S. I use (-1) corruption as a fine for tax collectors (part of the collected money logically ends up "in its nasty little pocketses"), and (-1) money for policemen and scientists (payment for maintenance and research, respectively).
 
Last edited:
Have you tested this? Just wondering how helpless the AI is in this regard - completely (uses only clowns when all city's tiles are already being processed) or only partially
You can see how (ineptly) the AI uses Specialists by setting your own city governors to "Manage Moods".

You'll see that in the early game, they'll tend to assign Clowns for happiness. Once a town(s) has happy-buildings, Markets and/or a few Luxes (so unhappiness is no longer a problem), they'll tend to assign 'excess' citizens as Specialists in opposition to your slider-settings (i.e. running Taxmen when the TAX%-setting is low, or Geeks when the SCI%-setting is low).

And as noted above, I have never seen a Governator assign Cops or Engineers. These Specialist-functions (reduced corruption, and building-shields) were added in Conquests, but even if they were also added to the AI's "How to use Specialists" instructions at the same time, they don't appear to have been properly bug-tested (as was the case with other new features in Conquests -- such as the Science Age), making these Specialists essentially a human-use-only mechanic.
 
1) Stack unit for town and cities, different from stack unit on terrains, so that for example Towns can handle max 7 units and citis 15.
Do you think that the following strings will work?
limit_units_per_town = 7
limit_units_per_city = 15
Stack limits are already broken down by class (land, sea, or air), and if I were to break them down further by town, city, metro, or none, the limits would have to set as a table of 12 entries. I'm reluctant to make the config that complicated. It also wouldn't even please everyone, I've gotten requests before to break the limits down by terrain type and by unit kind (like separate limits for non-combat, artillery, etc.), and to have a separate supply weight for each unit type, and probably some other things I'm forgetting. The ultimate solution here is to call out to a Lua function to determine the stack limit for a given unit on a given tile, because that could accommodate any rule you'd like without requiring the config to be crazy complicated.

2) A bit more complex, but I would like to create a city siege effect, so that if the town/city is surrounded in all 8 tiles by units (land or naval) the units in the city will lose 1HP every 3 turn.
How could I write it in code? 😁
I'm not sure what you mean by "write it in code." To program this, I would patch the game's method Unit::begin_turn to include some additional logic at the end to check if the unit is in a city under siege, and if so, undo any healing it got and apply the damage. To do damage every three turns, I'd also need to keep a record of how long each unit has been in a sieged city and include that record in the save file.

Since we're talking about specialists, is it possible to make them obsolete?
Sure, I don't see any reason why not. It might be hard to know what to do with assigned specialists when their type becomes obsolete but I'm sure I could figure something out.

...and so that the city loses access to resources from outside.
Hostile naval units already block trade connections, so all you'd have to do to cut a surrounded city off is pillage the roads with your land units. I could try to make it so that land units cut connections simply by occupying a tile, but the hard part would be knowing when to recompute trade networks. You can't do that all the time since it's an expensive operation, so it would be necessary to detect when a city has become surrounded and recalculate only then.
 
Hi !
First time I post here. I noticed (it is quite obvious actually) that the AI never builds a city within its own cultural borders.
In some situations (razed city, or the capital city radius grew too fast like in the attached picture), some juicy zones are not exploited by it, which is a huge disavadvantage compared to the human player, as these cities would be almost free of corruption + exploit resources.
Do you think there could be a way to allow the AI to found cities within its borders, provided its not on another city's radius ?

Thanks for your work !

1752054466071.png
 
Sure, I don't see any reason why not. It might be hard to know what to do with assigned specialists when their type becomes obsolete but I'm sure I could figure something out.
From the message above I learned that AI is very bad to use with specialists, so i think it is not worth spending time on it. Unless you fix the AI logic, but that is too much time and effort, it is definitely not a matter of first importance.

Hostile naval units already block trade connections
I did not know about that, It's awesome!
 
From the message above I learned that AI is very bad to use with specialists, so i think it is not worth spending time on it. Unless you fix the AI logic, but that is too much time and effort, it is definitely not a matter of first importance.
Even so most of us are playing on a modified version of the game and each person can choose to play the game as they wish. Working on specialists and adding some of the things mentioned could still be an option that would enrich players experience, while still being an option that people who worry about the AI can still leave turned off.

Take me for example. I've created AI only techs, bldgs, and units in the past. In my personal mod. It allowed me to offset the imbalances due to human bonuses in a way the AI knows how to use. That was my way of leveling the playing field, while still being able to use custom specialists or any other feature they AI couldn't take advantage of.

I think the number of people that would benefit from these changes would be something to consider. How about starting a poll and asking players themselves if they think they would benefit from a feature? This way we can be sure it's not time and effort being "wasted".

And besides doesn't the AI cheat at higher difficulty levels? It's not smarter it's just a cheat, so this isn't something the game doesn't already do. The AI cheats and we get to use human only concepts such as specialized specialists.
 
And besides doesn't the AI cheat at higher difficulty levels?
Not any more than it "cheats" at lower levels.

Leaving aside the extra starting units, the improvements in AI performance at higher levels are mainly down to the lower cost-factors (= faster growth + builds for the AICivs, slower research for the human), and the preferential inter-AI trade-rates.
 
Last edited:
Nitpicking, but I don't see it as AI cheats. If you play someone at a game and you give them a spot, they are not cheating. You agreed to have the AI use those advantages. Same as you are not cheating, when you play on Chieftain and have some of those bonus settings. It would be cheating, if we did not know they had them.
 
Back
Top Bottom