Hearts of Iron IV

Hearts of Iron IV

Expert AI 5.0
 This topic has been pinned, so it's probably important
Kondi  [developer] Aug 12, 2016 @ 2:18am
Details
Not updated for LaR. Contains some outdated info.

Gameplay changes:

This mod tries not to change the balance too much. What works in vanilla in terms of builds and such should work just the same in this mod. There are a couple of changes aimed at slowing down the pace of the game as well as nerfing some aspects that make the game much more difficult for the AI.

-Forts are much more expensive per upgrade (from 500 to 1500 cost per additional level).

-Division XP level gives less combat bonus (from 25% to 10% per level).

-Entrenchment combat bonus reduced by 50%


Overall mod design

The basic idea is to create a more competetive AI by scripting the AI to take advantage of the game mechanics in every way possible. That means I've had to heavily edit the game files to modify the AI behavior and create many event driven scripted AI systems that help the AI make the right choices which explains the limited compatibility with other mods.

Scripted AI does not mean railroaded (except in the sense that the AI should not make bad choices if possible) or a cheating AI. These systems simply give me far more control over what the AI should do under certain circumstances. They replace partially or completely some parts of the vanilla AI because there are nuances to the game that the vanilla AI just can't figure out on its own.

In fact a lot of the mod is designed to create a more dynamic AI but in a way that makes sense. The AI is not locked into building the same things every game as in vanilla for example, there is a huge variety of army configurations it can choose to build its army around (and of course it adjusts its research, variant, production etc. priorities accordingly). There are scripted AI systems that guide the AI's lend-lease, invasions and such which simply consider the AI's situation and try to come up with a sensible strategy.

Laws, political power use, leader recruitment, construction, variants, production, diplomacy and more... these are all heavily scripted in the mod and almost all of them are shared by every AI country in the game so they are not simple pre-determined paths that the AI follows every game. What the mod DOES "railroad" is that it makes a historical game actually progress historically(*relative* to vanilla) and even that is implemented in a way that allows the AI freedom within reason.

99% of this mod deals with improving the country management i.e. the big picture of the AI and NOT the details of how it moves its divisions, what kind of fleets it makes and where it sends them and what not. So there is rarely any point bringing up what the AI did or did not do with some unit!

Below are descriptions of what this mod does in various areas but there are too many changes to write everything down.


Game customisation/Difficulty configuration

This mod has a lot of settings for customising the AI behavior or the difficulty. This mod is not going to hold your hand and tell you what you should use. You should have a general idea of what you want and how difficult you need the game to be. If you aren't sure, you should simply start with the normal difficulty and see how it goes.

General AI settings change the AI behavior in one way or another. There is the "AI army focus" setting that influences what types of armies the AI makes. Challenging mode allows the AI to create full 40 width armies for example (but it is a bit random). Historical mode restricts the AI to only build sub-40 width divisions and limits the general randomness of their choices that other settings have. Random setting allows the AI to go wild essentially (Germany going Mass Assault, building carriers and 10w infantry etc.). Normal setting is essentially the same as Challenging but the AI will not build 40-width templates except for armor.

You have the option to directly configure every detail of the AI's army focuses for any country. You might want to do so if you think a certain strategy would be better for it for example. Keep in mind that the AI balance is delicate... making Japan build 40 width infantry just because it works for you doesn't mean it works better for the AI than 26-width infantry with artillery.

Difficulty settings are all about buffing the AI in one way or another and do not make the AI "smarter", and these settings are meant to be FAR MORE extreme than any vanilla difficulty setting (which can still be used, for milder buffs). They do not give the AI bonuses it doesn't need in this mod due to AI improvements, such as buffs to political power, research or divisions but focus on the AI weaknesses instead.

The hardest setting is literally meant to be impossible, although it may not be in practice. You should not be surprised if the game becomes unwinnable. Fortunately I've created the mod in a way that you can adjust any setting on the fly, in the middle of your campaign! You don't like how the war is going on some front between two AIs? Throw some buffs their way. You set the difficulty too high and you can't get anywhere? Simply remove it.

Note that the difficulty presets in the startup popup are not the absolute highest difficulty you can set in the mod. They are a combination of various settings and do not include any country-specific difficulty settings. For a given campaign it would be harder if you specifically boost the countries you will be fighting (USA, USSR as Germany etc.).

I'll say this much: if you choose a major country - especially one of the big three - you cannot expect an actually hard game without buffing the AI some amount. The amount of course depends on how good you are, how much you exploit the game mechanics, how much you exploit the AI weaknesses, and how much your roleplay rather than min-max.

These settings are scripted to be as "realistic" as possible when having such extreme bonuses. For example the AI gets a massive reduction to equipment production cost, but only if it is low on that specific equipment and loses the bonus after it has enough. The AI may get free divisions with the Reinforcement setting, but the amount of divisions depends on their industry and size. The desperate defense settings only apply while the AI is losing, and scale accordingly to capitulation progress. Dynamic settings are only active for countries at war with a player and depend on proximity of the player and their allies etc. None of the mod settings directly buff the combat ability of the AI's troops (only one setting buffs entrenchment/planning speed). That's it. There's no dark juju in the mod creating superhuman AI troops - only the vanilla sliders do that.


Military coordination decisions

There are several ways to influence your allies in this mod through decisions (some of which cost command power). You can tell them:

-what to build, what kind of divisions to make (and thereby changing their research priorities as well) (and check their stockpiles as well).
-which country to naval invade, and to spefically tell your allies NOT to invade.
-to stay away from fronts controlled by you.
-who to lend-lease.

Do note that they do not give you absolute control over what the AI does. You can't force it to naval invade if it thinks it is a bad idea. It may sometimes send troops to your borders even if you forbade it. Etc.


Construction

Vanilla AI's construction in this mod is essentially replaced by two scripted systems: one which periodically queues buildings for the AI and another that creates priority construction projects for the AI.

These systems allow me to control exactly how the AI constructs buildings: which locations it should prioritise, how many of specific buildings it wants, when it should build them. They allow me to create detailed strategies for specific countries, such as having USSR focus on civilian factories for the early-mid part of the game and also priorities building its industry beyond the Urals.

The purpose of the priority construction system is to allow the AI to build certain critical buildings as soon as possible instead of sitting at the bottom of the construction queue due to other queued buildings or a massive amount of damaged buildings waiting to be repaired. It calculates the time it would need to build that building and creates a decision/project that reserves the selected amount of civilian factories for the construction duration.

Some of the things these systems allow the AI to do:
-build radar stations in good locations and focus on upgrading them instead of having a lot of small and useless radar stations, and it'll try to provide coverage for its entire territory eventually
-build effective industries (they are aimed at historical campaigns, a building strategy for an early war would look very different and it obviously can't do both - it can adapt to the situation somewhat however)
-build refineries, anti-air, airbases, silos, infrastructure generally with better placement and in better circumstances than in vanilla
-exploit its resources better by prioritising infrastructure in states with tons of resources when needed


Variants

AI's variant creation is replaced with a scripted AI system that makes sure it creates good variants for the right equipment with the right priorities. Its priorities depend on the type of army the AI wants to create, so that a country focusing on medium armor divisions will upgrade medium armor first and so on. It will also avoid wasting XP on upgrading tier 1 equipment. It will pay attention to details such as saving its current XP for the equipment that it is researching instead of using it for its current equipment, and instantly upgrading the equipment that it just finished researching so as to avoid making double production line switch and losing efficiency.


Army Production

Division production is entirely rewritten. Each AI country builds an army composition for itself at the start of the game. It makes choices such as focus on heavy armor or medium armor, CAS vs TAC production, doctrine choices, which type of special forces and how much it will build and so on. Some decisions are weighed based on things like resources, other focuses it selected (Base Strike is more likely for carrier focused countries, Battlefield Support is more likely for CAS focused countries and so on).

Most countries are also restricted on default settings to focuses that make sense so that Germany doesn't go for carriers or USSR doesn't build strategic bombers from the start. There are various customisation options to change this at the start of the game however. Even on default setting, most AI countries will change their army from game to game and prioritise research and designs accordingly.

Each AI country has a dynamically calculated army manpower cap that depends primarily on the number of building slots it has. It is not a division number cap because the number of divisions you field depends on the size of your divisions. This cap limits countries to more reasonable army sizes, reduces lag and allows it to adjust its army size as its industry improves or territory grows.


Templates

There are no country specific templates in the mod (and therefore no historical divisions): there are around 400 templates that the AI will choose to design towards depending on the situation. The AI adapts its division designs to its land doctrine and the overall type of army it wants to build and also includes some random variation in designs from game to game and some ability to adapt to its situations. Template width varies between 10/20/26/40. This is different from the vanilla where the AI has predetermined designs that it will go for every game.

Some examples:

-anti-tank infantry with line AT, medium or heavy tank destroyers depending on the tech paths it chose
-armored division designs with more or less sp. artillery
-motorized designs with light, medium sp. artillery or motorized rocket artillery
-countries with superior firepower use support artillery and rocket artillery
-facing enemy divisions with high armor, it will add more piercing to its AT divisions and armor divisions
-upgrading to 40w+ armor divisions if it has tons of tanks in the stockpile
-Mass Assault countries will upgrade width to match the tech bonus.


Navy Production

The AI specializes in a number of different ship types rather than trying to build and research all of them which is inefficient. The specific types depend on the country (usually they choose the types they already have 36's techs for). It will not bother building early ship types. Although you can make the AI build submarines, they normally do not because the AI can't manage them. The AI also adapts its dockyard assignment priority according to its convoy situation and how many screen ships it has relative to its capital ships.


Air Production

Similar to navy production, the AI's priorities have been focused on producing fewer types of aircraft so that it can produce up-to-date and upgraded types rather than as in the vanilla, build every type of aircraft whether it is needed or not.

The AI will not produce interwar aircraft and it adjusts its air production according to the current situation. For example if Italy or UK have very few fighters left, rather than continuing to produce bombers it will refocus its efforts on building fighters until it has a respectable air force.

Countries other than UK and USA may also produce strategic bombers if the situation is right for it but generally most countries build fighters and either TAC or CAS. CV aircraft has a lower priority in this mod unlike in vanilla where the AI builds 1:1 ratio of ftr:cvftr etc.


Diplomacy

Major work has gone into giving the historical focuses mode an actually historical progression... to a certain extent. This mod is NOT a 100% correct simulation of WW2 and it's not meant to be. Most decisions by the AI are scripted to be flexible while keeping in mind that in a standard historical game, you can expect the major events to unfold historically in broad terms.

You will run into AI behavior when playing on historical focuses that doesn't happen in vanilla and seems inexplicable. However the reason for these (if they are not bugs) is usually historically motivated. For example Italy will not want to join Axis until Germany has "proven" itself by taking out Poland and breaking through the low countries. Nor will Hungary or Romania want to join until Germany has taken over western Europe (they will join after doing their Axis focuses). There is additional behavior scripted in case of some ahistorical outcomes.

USA and Nat. Spain AIs are restricted from joining a faction prematurely for historical reasons (they will join later depending on how the war goes). A lot of specific behavior has been scripted into the AI, such as Finland joining Axis for Barbarossa or Germany/USSR/Japan keeping up their non-aggression pacts instead of cancelling them far too soon. A ton of AI logic has been added to the most important focuses and decisisions related to war declarations and such to make the game more historical and to avoid non-sense situations even if the game is slightly derailed from history. Some concessions have been made regarding historicity for the sake of the AI and to avoid every game playing out exactly the same.

AI can react to "illegal" justifications (not backed up by a core, claim, national focus or event). Nearby countries may guarantee your target, send them volunteers and lend-lease if possible and will view you negatively. They may also join a faction if the world tension is very high and consider you a major threat. You can avoid this by making non-aggression pacts or by improving relations with the surrounding countries for example. This is to make national focuses for war declarations more useful and to make the AI more active instead of just waiting to be conquered.

German and Japanese factions will keep declaring wars if they have nothing left to do (so if Germany has taken out USSR, it will keep invading countries that it sees as targets) rather than becoming "dead" AIs. There are also a couple of optional settings that allow the AI to justify wars on its own and to focus on specific ideologies for ahistorical campaigns.


Decisions

A bunch of AI logic has been added to various decisions. AI will try to take advantage of all the obviously beneficial decisions that boost its country in some way, like improving its stability by various decisions, while avoiding the obviously bad ones (or improving stability when it is not needed for example).

As mentioned before, the bigger diplomatic decisions have been adjusted so that the AI doesn't veer too far off course in a historical game.


Lend-lease

AI's willingness to lend-lease is massively increased in this mod (possible to disable through the settings) with a ton of logic added so the AI utilizes it in the right situations. There are many factors to this but for example, "enemy of my enemy" is a valid reason for the AI to support a country such as the Allies supporting USSR against Germany. In this case the entire Allied faction helps out USSR unlike in vanilla where only USA is scripted to support USSR in a very limited/predetermined fashion.

Some other situations where in this mod the AI likes to lend-lease: wars against countries that have a different ideology, countries that have the same ideology. There are also some limits like a democracy doesn't want to support a country with another ideology in an offensive war (USSR vs Finland for example).


Naval Invasions

AI naval invasions are handled by yet another scripted AI system rather than the vanilla AI. Specifically this relates to which countries the AI targets with naval invasions. The actual execution of naval invasions is generally the same as vanilla, except the AI prefers more concentrated invasions.

The scripted AI naval invasion system considers several things when choosing an invasion target, for example:
-AI faction members will generally try to join the faction leader when it is invading. This will create faction-wide coordinated naval invasions that have a better chance of success. Else they may join the strongest faction member instead (e.g. USA in Allies).
-They will factor in things like their current manpower, army size, check that they are not being invaded at home and so on before trying to naval invade someone else.
-If it has not made progress on the invasion after a certain amount of time, it will try to target some other country if possible


Research

AI research has been heavily edited to refocus its priorities according to what type on an army it builds. For example, if the AI intends to ignore tanks and only build infantry and use line-AT against enemy armor, it will also ignore tanks and heavily prioritise AT techs. If it only plans on building CAS, it will not bother researching TAC and so on. To stay competetive, focusing its research where its needed is critical which is something the vanilla AI lacks.

The AI is also scripted to change doctrines at the start of the game depending on what kind of an army it wants to build. It will also take advantage of the manpower techs in the mobile warfare tree if it runs out of manpower. There are tons of other scripted behaviour added to make sure the AI gets certain critical techs on time and understands which tech to prioritise over another.


Laws

Law selection AI is also handled by scripted/event based AI because it is a critical part of the game. A crucial change is that the AI is now able to store away political power for critical needs whereas normally the AI would spend PP as soon as it has enough for anything. This stored PP is only used for changing laws, and these laws have specific priorities depending on the situation.

This means that it can upgrade important laws as soon as they become available; for example democratic countries must be able to immediately upgrade manpower laws once they get into a war, which they do now since they have extra PP saved for bad days.

The AI will try to avoid the higher manpower laws with heavy penalties as long as possible, preferring to switch land doctrine branch (for MW) or switching away from Total Mobilization.

Economy law upgrade is the highest priority during peacetime and most countries will try to get War Economy as soon as possible.

Trade law selection logic is calculated based on average resource needs and current resources in order to maximise efficiency. Small countries will mostly stick to Free Trade while bigger countries with a lot of resources will gradually lower it as their industry expands.


Advisors/Generals

AI will not choose useless advisors and it highly prioritises getting the useful advisors in a sensible order. Majors have a more specific order while minors tend to have a high priority on just infantry advisors and a few others.

Marshal and general recruitment is handled with scripted AI. It will compare the number of generals, marshals and divisions to figure out how many of each it should have. It is capable of promoting generals as well.

Leader ability use logic has been overhauled. The AI will save up command power so that it can use abilities for larger armies, it will try to use abilities for armies when it makes sense e.g when over half the army is attacking over a river, it should use makeshift bridges and so on. It should avoid using last stand and force attack when it is low on infantry equipment. Lastly it should almost always be using its command power for something and not let it sit at maximum.

Leader trait picking logic has been overhauled. The AI has high priority on traits like logistics wizard, ambusher, fortress buster, improv. expert and it no longer wastes trait slots on bad traits.


Combat AI

There are not many changes to the actual land combat AI (numerous issues have been fixed by patches). The AI is willing to cancel bad combats much sooner than before, and it is more conservative about executing battleplans when its units have low strength for example.

Naval AI is mostly unchanged but the AI prefers very big fleets now. You can expect fleets as big as 150 ships from the bigger countries. One important change is that the values for repair priority have been overhauled so that the AI knows when to withdraw its damaged ships from combat and to avoid fighting battles with poor odds. This also has an effect on how your fleets behave (low priority repair is much safer now, while high priority is slightly more safe than vanilla high priority).

Air AI has been tweaked to make the AI use air superiority to support its divisions, which I consider its most important role. There is unfortunately a cost in other air AI areas which can't be solved, such as the AI being reluctant to defend against strategic bombing.


Other

Many other changes/fixes like:

-National focus order on historical mode has been edited so that the AI gets the most out of it and takes advantage of the continuous focuses properly.
-Stuff I forgot to mention. It's a big mod.
Last edited by Kondi; Dec 10, 2021 @ 7:36am
< >
Showing 1-15 of 25 comments
Grandwolf Smegcock Dec 21, 2016 @ 11:27am 
nice
Condorman Feb 4, 2017 @ 9:31pm 
All those changes sounds like they should be but into the vanilla game by the developers.
[N.C]-Lusche Apr 20, 2017 @ 11:28am 
Yep, very nice! Thank you for your detailed changes! Again, great work!!! :steamhappy:
Deathwing May 23, 2018 @ 1:45pm 
"AI will react to "illegal" justifications (not backed up by a core, claim, national focus or event). Nearby countries may guarantee your target, send them volunteers and lend-lease if possible and will view you negatively. "

So with the Embargo mod (if it can be use with your mod), they would react to "illegal" justifications by an embargo on you ? (lot of AI doing that)
All the time for every player and every AI doing "illegal" wars ?
(just wondering :p)
Kondi  [developer] Jun 5, 2018 @ 6:44am 
Originally posted by Deathwing:
"AI will react to "illegal" justifications (not backed up by a core, claim, national focus or event). Nearby countries may guarantee your target, send them volunteers and lend-lease if possible and will view you negatively. "

So with the Embargo mod (if it can be use with your mod), they would react to "illegal" justifications by an embargo on you ? (lot of AI doing that)
All the time for every player and every AI doing "illegal" wars ?
(just wondering :p)
Probably not.
dzantor Jul 29, 2018 @ 1:32pm 
hi, sorry for stupid question. When you update mod, i try to see what are changes, but i never find them. Where should we look up for mod update changes, i just can't find that?
Kondi  [developer] Jul 30, 2018 @ 12:14pm 
Originally posted by Espek:
hi, sorry for stupid question. When you update mod, i try to see what are changes, but i never find them. Where should we look up for mod update changes, i just can't find that?
If I didn't write any notes in the patch notes then I considered the changes too small to be worth mentioning. :)
dzantor Jul 30, 2018 @ 3:40pm 
Originally posted by Chondrite:
Originally posted by Espek:
hi, sorry for stupid question. When you update mod, i try to see what are changes, but i never find them. Where should we look up for mod update changes, i just can't find that?
If I didn't write any notes in the patch notes then I considered the changes too small to be worth mentioning. :)
Thanks for explaining! Now i know )
Pordy Apr 4, 2019 @ 3:10am 
Hello!
I would like to apply some defines to my mod, based on your changes, but there are some thing i cannot understand. Can you explain these defines?
A:
Why makes any difference your changes in the matter of this define value.
NDefines.NAI.PRODUCTION_MAX_PROGRESS_TO_SWITCH_NAVAL = 0.01
Beside the original values, the AI could manage make new refits and change the ship production?
Or it just a safety decision to prevent the possibility of this situation?
B:
I would like to ask, why this number is NDefines.NAI.REFIT_SHIP_PERCENTAGE_OF_FORCES = 0.0?
The Ai will do any refit with this option?
The REFIT_SHIP_RELUCTANCE was increased to 500 is this enough for the AI to do refits in general?
C:
PRODUCTION_EQUIPMENT_SURPLUS_FACTOR = 0.5 This means that the AI will stockpile millions of infantry equipment instead of vanilla AI who stckpile hundrends of thousands?
D:
NDefines.NAI.PLAN_MOVE_MIN_ORG_TO_ENEMY_PROVINCE = 20.0 not appears in the vanilla defines, Is this values works or not handled the game yet?
E:
NDefines.NAI.PLAN_MIN_SIZE_FOR_FALLBACK = 5000
The AI fallback line drawing was such a big issue for this necessary? Is this increase the stability of the frontlines?
F:
NDefines.NAI.ENEMY_NAVY_STRENGTH_DONT_BOTHER = 1000
If i use this value without the scripts, this value means that for example an ITA ai who loosed all ship against england, will suicidly plan naval invasions?
G:
NDefines.NAI.MISSING_CONVOYS_BOOST_FACTOR = 0.0
NDefines.NAI.CONVOY_NEED_SAFETY_BUFFER = 0
If i use only these raw defines, the AI wont replace thier convoys once lost?
Or it just controls that missing convoy production wont priorized over ship production?

Thats all :)
Thank you for the answers!
Last edited by Pordy; Apr 4, 2019 @ 3:13am
Kondi  [developer] Apr 4, 2019 @ 7:52am 
Originally posted by RHA PordyHUN:
Hello!
I would like to apply some defines to my mod, based on your changes, but there are some thing i cannot understand. Can you explain these defines?
A: it's supposed to prevent the AI from cancelling ships with more than X progress. I think it just doesn't work in 1.6 even with the typo fixed that you noticed (the typo used to be in the base game and the defined worked in 1.5).

B: those changes prevent the AI from refitting. I just noticed that it caused some issues for the AI (at least in my mod) that just resulted in a waste of IC.

C: it means that it wants a stockpile equal to 50% of its fielded equipment before it reduces production.

D: I think it was removed from the base game in one of the 1.6 patches so it doesn't do anything anymore.

E: that's right. I think the AI using fallback lines does more harm than good.

F: yep

G: the mod controls the convoy production so these parameters disable the "game AI" from changing the convoy production
Matoro Apr 14, 2019 @ 8:54am 
"Although you can make the AI build submarines, they normally do not because the AI can't manage them. "

Is this true also for 1.6 version of EAI? I don't think it should, since now AI is quite adequate at submarine warfare.
Kondi  [developer] Apr 18, 2019 @ 7:03am 
Originally posted by Matoro:
"Although you can make the AI build submarines, they normally do not because the AI can't manage them. "

Is this true also for 1.6 version of EAI? I don't think it should, since now AI is quite adequate at submarine warfare.
Yeah this is outdated, most of them build subs.
Nate of Scooba Sep 17, 2019 @ 5:28pm 
If I play as the USSR, will the AI competently create a second front now?
STABBY5 Dec 22, 2019 @ 5:25pm 
Is there any way to either have a version without your changes or make the mods separate. I don't want balance changes, I want the AI improvements.
Riekopo Feb 24, 2020 @ 1:30am 
Is there a version without the gameplay changes? I like that you can improve Transport aircraft but I'm iffy about the rest. Also, you say there are no unique or historical country templates but doesn't the mod have a historical Division design setting?
< >
Showing 1-15 of 25 comments
Per page: 1530 50