Patch Request: Allow more total units and units per AI.

Skybuck

Prince
Joined
Apr 23, 2005
Messages
301
This is probably the most important patch request, especially for playing on earth map. The AI seems severly limited in the number of units it can produce. It seems once the game reaches a total maximum units, nothing else can be produced. By increasing the total unit limit, civilization can be "set free" and it's true potential will be known ! ;) =D

I noticed this many times, it seems like some civilizations are "hampered", knocked out, sometimes it's simply china because it doesn't grow, but sometimes it can also be the unit limitation, especially later in the game...

(Maybe use ChatGPT to reverse engineer the assembler to C/C++ source code =D)

(In this video you can see how the AI seems to "drop dead" mostly, at least once inspecting with jcived the americans seem unable to produce any more units in their homeland...)

The statistics are also messed up (or they did not attack each other, but I think they did =D, it probably just shows my stats, but little bit inverted or something...), as well as palace building once switching to another civid, neat feature of the editor though !So I switched from India to Americans and it just inverts the stats in F2 or F3 screen or something)

By keeping my unit count low, perhaps it allowed 3 AIs to actually play the game ! =D
 
Last edited:
All loops and memory storage related to civs, units and cities are hard-coded in CIV.EXE:
- 8 Civs max (incl. Barbarians), and much data about Civs is stored in single bytes, as bit flags (8 bits = 8 Civs), best example is the contents of MAP files... Wouldn't even know where to start to patch this
- 128 total Cities max: this is the maximum value of a signed byte, and also CIV.EXE has only city names for that many Cities... Even thinking of using unsigned bytes to push the limit to 256 would be tricky, since value 0xFF is often used to indicate "NONE", such as a Unit's home city...
- 128 units per Civ maximum (+ 2 per city): arguably this *could be* the least hard to patch, because there are no adherence to other data (such as byte flags for Civs or Names for cities) but still you'd need to make room for the extra Unit data in memory, in SVE, and locate and patch ALL loops in CIV.EXE hard-coded to 128 units...

Making sufficiently extra room in CIV.EXE for any of this is not something I deem feasible, but I'm just an amateur hacker :)

Best shot at breaking this limit is to re-write the game IMHO, which several have started doing around the forums in the past years.

Cheers
 
  • Like
Reactions: GPR
1. Either insert jmps to need code sections where the code is updated to 16 bit.

2. Or reverse engineer with ghydra to c and then change it in c to16 bit...
 
1. Either insert jmps to need code sections where the code is updated to 16 bit.

Yes that's the basic idea but inserting code in CIV.EXE, which is a MS-DOS executable, is not so easy.

The main reason is that apparently CIV.EXE has been tailored by MPS Labs at the time, to fit in a regular MS-DOS system memory (640kb), and this makes it nearly impossible to add new code that would inflate CIV.EXE beyond this size.

Adding more units is typically something that would significantly take more memory, and possibly make it impossible to execute in MS-DOS.

Beyond this already huge obstacle, there are many technical difficulties to alter CIV.EXE code or add more code :
- all relocation tables and relocated values must be updated,
- possible some calls to new code would need more space than is avialable in existing code snippets, especially when doing loops on units, which happens everywhere in CIV.EXE
- not all of CIV.EXE has been reversed so far, so there is definitely unvertainty about side effects of doing such large changes to CIV.EXE

2. Or reverse engineer with ghydra to c and then change it in c to16 bit...

Like you say, the amount of work to "patch" something like that would push most sane minds to, instead, reverse CIV.EXE completely to more free to modify and recompile.

Such efforts are underway, I am myself in the moddle of reversing, but rather to port it to Java, only in my free time.

As you know, there is another effort underway here, to completely reverse and make a perfect high-language CIV for further modding, see here: https://forums.civfanatics.com/threads/reverse-engineering-group-excercise.644077/#post-16310086

There are probably other reversing efforts under way, but this is definitely neither an easy task nor a quick task.

From my experience, the biggest challenge in reversing is to understand the code: there are hundreds of functions everywhere, plus a handful of enormous large functions where everything happens: typically, a function I called "cityProcess" contains to code performing everything related to cities in the same place, depending on some input parameters: rendering city on map, rendering the city main screen, calculating city resources, city pollution, city contribution to science/treasure, city maintenance cost, all random events related to cities, AI automatic selection of next unit/building, etc.:

cityProcess.outline.png

This function alone is over 26,000 bytes in assembly, with corss-references and calls throughout CIV.EXE, so very complicated effort to split up.
 
Top Bottom