Changing AI randomization?

Tecumseh1

Warlord
Joined
Feb 8, 2024
Messages
224
Location
California
As I understand the AI opponents are randomly distributed by country/empire. This means I rarely get to face AI like Lincoln and Louis, while the idiot Montezuma is in every game I play. Is there a way to randomize so each leader has the same probability of appearing?
 
The algorithm for civ/leader randomization is implemented in the EXE, and, yes, apparently it first selects a civ uniformly at random. If you're comfortable with modifying and recompiling the DLL source, then you could overwrite the choices made by the EXE by implementing your own algorithm (first selecting a leader uniformly at random and then choosing the matching civ) in the DLL. For details: a similar question was asked in the Quick Questions thread this spring; link. Alternatively, you could probably create e.g. multiple France civs just through Civ4CivilizationInfos.xml, each with exactly one leader. Maybe the side-effects of this wouldn't be too bad. They could still all have the same display text ("France"). There will be redundant Civilopedia entries. Oh, and some civs have specific random events that are defined in CvRandomInterface.py; that code will also need to be amended. Searching that file for all occurrences of CIVILIZATION_ should show the relevant spots.
 
Thanks for the info. Yeah I was also thinking about duplicating civs. I'm not sure exactly which files need copying but worth a try. Might run into issues regarding unique ids if same civ is chosen twice in a game. I guess that probably is pretty low and can always re-roll :))
 
Oh, right, I thought of that too, then somehow forgot again. :blush: My intuition is that collisions will be quite frequent; brings to mind the birthday "paradox". One could try to turn that into a feature by naming e.g. De Gaulle's France "French Republic" and Louis' "Bourbon France", i.e. letting them coexist in the same game. Technically, to clone a civ, it should suffice to copy and paste its whole CivilizationInfo element in Civ4CivilizationInfos.xml, and to change only the Type subelements to make them unique. Since the original Type strings are referenced by CvRandomInterface.py, that file will need a little bit of work too – if one cares about Random Events at all. Plus, again under CivilizationInfo, possibly the various TXT_KEY elements for distinct display strings. And the Leaders lists to have only one leader per civ. Ah, DefaultPlayerColor will get tricky - 52 distinguishable colors instead of just 34. (Colors get defined in Interface\Civ4ColorVals.xml, Civ4PlayerColorInfos.xml.)
 
I think I remember from years ago a game I started and it had two Koreas. It wasn't modded, just set up the game with two Koreas at the start. The second one had brown color as I remember.
 
Yes, apparently the EXE will pick - supposedly unused - colors from the end of Civ4PlayerColorInfos.xml; or rather color schemes consisting of a primary, secondary and text color. The individual colors can clash with colors of other civs in the game, e.g. the unused scheme PLAYERCOLOR_CYAN_AND_GRAY and PLAYERCOLOR_CYAN (Persia) both have COLOR_PLAYER_CYAN as their primary color. I think that's what goes wrong in this screenshot. I have this info at hand because I've reimplemented the color reassignment in my own mod.

I've been assuming that color reassignment by the EXE is triggered by multiple players having the same civ type, but it might actually check for clashing player colors; that would make more sense. So, even if the reassignment is flawed, it could indeed help when the same DefaultPlayerColor is set for e.g. all copies of France. I think there are only 5 truly unused player colors in Civ4ColorInfos.xml, so at least 13 more would have to be defined in terms of RGB values if each leader is supposed to have unique colors. Some mod with a lot of extra civs could be inspected for this. Edit:There are also tools for this: btsColorEditor, script for displaying all player colors.

All hypothetical - for whoever wants to go down a road of unique civs per leader.
 
Last edited:
Top Bottom