Do different AI players have different army builds and preferences?

user330977

Prince
Joined
Dec 8, 2020
Messages
348
Hello folks

I'm wondering if different AI leader flavours also extend to which units they like to build. Are they based on historical background? For example, are the Mongolian leaders more likely to build Horse units than, for example, the English leaders? Or are AI armies completely dependant on the game's conditions?

Kind regards,
Ita Bear
 
I assume so. In the file CIV4LeaderHeadInfos.xml there is a tag <UnitAIWeightModifier> which will presumably change the preference towards certain UnitAI types.

For instance: Alexander has a <UnitAIWeightModifier> of 100 for <UnitAIType> UNITAI_ATTACK. Looking in the file CIV4UnitInfos.xml you will find that a Swordsman has a <DefaultUnitAI> UNITAI_ATTACK while an Axeman's default is UNITAI_COUNTER.

The units also have a list of other UnitAIs they can be used as. The Axeman has the <UnitAIs> of UNITAI_ATTACK, UNITAI_RESERVE, UNITAI_COUNTER and UNITAI_CITY_DEFENSE, while the Swordsman has UNITAI_ATTACK, UNITAI_ATTACK_CITY, UNITAI_RESERVE and UNITAI_CITY_DEFENSE.

Both Axemen and Swordsmen can be used as UNITAI_ATTACK, even though they have different defaults. But if you look at a Machine Gun it has <DefaultUnitAI> UNITAI_CITY_SPECIAL and <UnitAIs> UNITAI_CITY_COUNTER and UNITAI_CITY_SPECIAL.

I assume this means Alexander will build more Swordsmen than Machine Guns. You'll have to go through both files and compare the <UnitAIWeightModifier> for each leader to the <DefaultUnitAI> and <UnitAIs> that are assigned to each unit if you want to find out what units each leader is more likely to train.

What I don't know is how much of a difference a <UnitAIWeightModifier> of 100 makes. That is for experimentation (or code-divers) to give an answer to.

Happy Civving!
 
Looks like it's used as a % modifier multiplier for the frequency of choosing that unit type:

The game creates a big array of unit types, applies a bunch of logic to tweak those numbers, then applies a random number, and picks the one that had the best result.

Code:
for (iI = 0; iI < NUM_UNITAI_TYPES; iI++)
    {
        aiUnitAIVal[iI] *= std::max(0, (GC.getLeaderHeadInfo(getPersonalityType()).getUnitAIWeightModifier(iI) + 100));
        aiUnitAIVal[iI] /= 100;
    }

So if I'm reading that right - 100 would make them 2x more likely to pick that than they otherwise would.
 
For example, are the Mongolian leaders more likely to build Horse units than, for example, the English leaders? Or are AI armies completely dependant on the game's conditions?

The game doesn't differentiate between mounted and non-mounted units for choosing units, and doesn't seem capable of doing so without modding the core game. (AKA, not just changing XML).
 
I have not code-dived into this subject, but it sure appears from playing that the AI likes to spam its UU. Especially ones like Genghis, Monty, Shaka, Cyrus, Mansa and Alex. But really all of them appear to follow that behavior.
 
I have not code-dived into this subject, but it sure appears from playing that the AI likes to spam its UU. Especially ones like Genghis, Monty, Shaka, Cyrus, Mansa and Alex. But really all of them appear to follow that behavior.

Any idea of that applies across unrestricted leaders? And by civ or leader? Like would Mansa of Civ X spam it’s UUs, or would Leader X of Mali spam Skirmishers, do you think?
 
There was a really good old thread that explained all the AI modifiers like this, but I can't find it now.
 
Back
Top Bottom