Unit Production AI Tweaks (experimental)

balparmak

Prince
Joined
Sep 20, 2015
Messages
545
In short, this modmod introduces soft checks to AI army composition to help it create more balanced armies. This is done by introducing new AIMilitaryStrategies, Flavors and UNITAIs for each unit type*. When an AI player has too few of a certain unit type, it gets a bonus to prioritize the production of that type, and vice versa when it has too much. For a long description on what it does and why, please refer to: https://github.com/LoneGazebo/Community-Patch-DLL/pull/8783

Spoiler Current formula :

NeedArcher: NumArcher / NumMelee <= 1/4 * AIFlavor / 5, EnoughArcher: NumArcher / NumMelee >= 1/2 * AIFlavor / 5
NeedMobile: NumMobile / NumMelee <= 1/4 * AIFlavor / 5, EnoughMobile: NumMobile / NumMelee >= 1/2 * AIFlavor / 5
NeedSiege: NumSiege / NumMelee <= 1/8 * AIFlavor / 5, EnoughSiege: NumSiege / NumMelee >= 1/2 * AIFlavor / 5
NeedSkirmisher: NumSkirmisher / NumMelee <= 1/8 * AIFlavor / 5, EnoughSkirmisher: NumSkirmisher / NumMelee >= 1/2 * AIFlavor / 5
NeedNavalMelee: NumNavalMelee / NumNavy <= 3/10 * AIFlavor / 5, EnoughNavalMelee: NumNavalMelee / NumNavy >= 7/10 * AIFlavor / 5
NeedNavalRanged: NumNavalRanged / NumNavy <= 3/10 * AIFlavor / 5, EnoughNavalRanged: NumNavalRanged / NumNavy >= 7/10 * AIFlavor / 5
NeedSubmarine: NumSubmarine / NumNavy <= 1/10 * AIFlavor / 5, EnoughSubmarine: NumSubmarine / NumNavy >= 3/10 * AIFlavor / 5
NeedBomber: NumBomber / NumAir <= 3/10 * AIFlavor / 5, EnoughBomber: NumBomber / NumAir >= 7/10 * AIFlavor / 5
NeedFighter: NumFighter / NumAir <= 3/10 * AIFlavor / 5, EnoughFighter: NumFighter / NumAir >= 7/10 * AIFlavor / 5


I welcome any feedback on the ratios above or suggestions where we can further employ these additions. Just to give an example, I modified AIGrandStrategy_FlavorMods so that civs going for domination get a bonus to bombers and siege units, while the culture, diplomacy and science get it for fighters.
If the results are good this may get integrated into the base VP, so any testing is much appreciated.

You can check the AI army composition through Logs/MilitarySummary.csv
Spoiler The header gets removed from the log file after reload, you can copy/paste the line below and open with Excel etc. to get a readable view :

Turn, Player, Era, Cities, Settlers, LandUnits, LandArmySize, RecLandOffensive, RecLandDefensive, NavalUnits, NavalArmySize, RecNavyOffensive, MeleeUnits, MobileUnits, ReconUnits, ArcherUnits, SiegeUnits, SkirmisherUnits, AllLandRanged, AntiAirUnits, MeleeNavalUnits, RangedNavalUnits, Submarines, Carriers, TotalAirUnits, BomberUnits, FighterUnits, Nukes, Missiles, RecTotal, TotalMilitaryUnits, SupplyLimit, OutOfSupply, WarWearinessSupplyReduction, NoSupplyUnits, WarCount, MostEndangeredCity, Danger


Works with new units/civs/leaders.
I specifically tested with 4UC, ENW, Macedon/Greece Split and Kushan Empire, highly unlikely that other custom civs will have any issues. Units will get assigned the correct UNITAI but may miss specific flavors and the new leaders will get the default flavor value of 5 for new flavors. To be honest this shouldn't matter much, UUs get spammed by another function anyway. You can make your custom leader optimized for UPAI by referencing new flavors/unitais with a IF EXISTS check.

Many thanks to Recursive, ilteroi and the discord community for their help.
Requires VP 2.1 or later.

To-Do:
- Rewrite need/have enough recon code (UPAI doesn't modify this as it's handled by another part of the code)
- Better integration between new flavors and technologies&policies
- A trigger to auto-detect UUs and give boost to related flavor of custom leaders

*unit type in this context refers to the broader types such as melee, ranged, bomber, fighter, not the specific unit types used in database like "unit_mongolian_keshik"

Moderator Action: Moving this to the main forum for visibility because AI improvements good. - Recursive

23.04 : Very small update, doesn't warrant a bump. You can find options to reduce Leader Flavor randomization in NewLeaderFlavors.sql . The same file also includes and option to remove randomization from city production decisions (includes both buildings and units). Both are commented out/disabled by default to make comparisons with the base VP more reliable. No need to download v2 if you won't enable them.
 

Attachments

  • Unit Production AI (v 1).zip
    9.5 KB · Views: 32
  • Unit Production AI (v 2).zip
    9.8 KB · Views: 65
Last edited:
@Jdoug312 Thanks! To be perfectly honest, this sounds better on paper but its in-game effect is not very pronounced. You can increase the bonus/malus from need/hasenough in NewStrategies.sql, but the more important modifier is currently set in the DLL, I plan to expose that for db modding.
 
@Recursive Why is this thread archived? This is a brilliant addition to AI improvements I would say.
Move it to the main forum, and let people play with it so then we can probably implement it
 
@Recursive Why is this thread archived? This is a brilliant addition to AI improvements I would say.
Move it to the main forum, and let people play with it so then we can probably implement it
I archived all threads except those which contained a message within 30-60 days.

Bal has a gameplay/balance mod thread which includes this mod. But sure, if you want...

Moderator Action: Moved to main forum as requested.
 
Any feedback from people who use it? Do they see the difference?
 
Top Bottom