Hearts of Iron IV

Hearts of Iron IV

Expert AI 5.0
This topic has been locked
Kondi  [developer] Oct 10, 2023 @ 9:11am
Patch notes (EAI 5.0 - HOI 1.13)
IMPORTANT: see the github page for details of all changes made. Small fixes won't be mentioned elsewhere.

https://github.com/Kondikka/expertai

If you are looking for EAI for older HOI versions, download it from the github site. You'll find them under tags.

-------------------------------------------------

Expert AI 5.0

Overhauled AI research
* New priority research AI system that works in parallel with the regular research AI.
* Making the AI research techs in very specific orders and under various conditions is very hard with the regular research AI in the game. This system solves that by having the AI select techs from a priority research queue that overrides any other ideas the AI has.
* In practice, it means I can implement more optimal research strategies for the AI, such as:
** At the start of the game, pick up these specific techs in this exact order to optimize industry build-up.
** If it's 1940 and you are still not researching fighter tech 2 and you care about building fighters, I don't care what you are doing, just pick up that damn tech and all the design requirements as your next techs.
** The AI needs to make a design that requires X Y and Z techs? Bit of a nightmare to script that into the old system but now I can just put the required research path into a script and give it a high priority.
** The AI unlocked a national focus that gives research bonuses that should be used immediately to rush certain techs while avoiding techs that would waste that research bonus? Easy-ish now, nearly impossible before.

I've added more general priority research strategies for basically all research paths in the game. They make sure that if there is a tech that the AI actually needs (it's just a generally important tech or the AI needs it for a specific design or template it wants to make), it will want to prioritize that tech.
Along with these, there are more specific strategies, such as:
* UK rushes fighter or heavy fighter research after unlocking Fighter Command.
* USA prioritizes getting good strategic bomber designs earlier.
* Germany prioritizes getting good submarine designs earlier.
* Germany rushes 3 construction techs at the start using the national focus bonus AND does not waste the bonuses on other industrial techs .
* Germany/USSR properly rushes tank techs for whatever armor type it wants if USSR accepts the tech treaty AND they don’t waste the bonuses on armor/engine techs.

Overhauled priority construction AI
For anyone interested in the details, in this mod there are 3 types of construction AI:
* The regular HOI AI that manages and queues regular buildings. This is not great for this mod because there is not a ton of moddable control over why the AI wants certain buildings and where it places them in the queue.
* The EAI building AI system that suppresses the HOI building AI logic and determines from the mod side how many of each type of shared slot building the AI wants to queue.
* The EAI priority construction system which is a separate building queue that works along with the regular game queue. This works by diverting civilian factories the AI normally uses for constructions into "Special Projects". Priority constructions function the same as regular constructions when it comes to modifiers, costs, speeds and such. They are used by the mod to create strategies for the AI to build in highly specific ways that are otherwise impossible to script dynamically or otherwise. They make the AI build specific buildings in specific states and provinces, with a queue managed and manipulated by the mod AI alone. This is what enables creating an industrial strategy for AI USSR that more closely matches the meta strategies players come up with, or having the AI in general build radar, air bases, anti-air, forts with the appropriate urgency depending on the situation.

Changes from the old priority construction system:
* The old version was a copy-paste of a system from another mod of mine, so it was just barely enough to get the job done. The new system allows the AI an unlimited amount of queued projects for example, and doesn’t work by using timed decisions.
* It recalculates daily the building speed of every project, accounting for changes in modifiers, infrastructure etc., so it should mechanically match the regular constructions in the game aside from benefiting from the new market bonus.
* It has the ability to clear the regular construction queue for the AI, as well as force the AI not to queue any shared slot buildings in order to have complete control over construction. This is for cases where every factory has to be carefully managed and the construction queue juggled for efficiency.
* Support for provincial type buildings, assigning a priority to certain projects, sorting the priority construction queue in various ways, other stuff.
* Whichever type of construction logic the AI uses depends on the situation and country. The AI is not railroaded to do a certain thing every game, the scripts are designed to be dynamic and to adapt to changes. Only the USSR currently has a more minmax type construction strategy for example, but the scripting is still dynamic to some extent. If the USSR is left alone till '41, it's going to try to maximize its industry for late game. If it gets into a bigger war before then, it will abandon the strategy and so on.

Reworked air base construction
* The AI uses the priority construction system to build air bases with a much more expanded logic for determining locations. It will account for things such as distance (closer to enemy but not too close), try to match the enemy's ability to deploy planes around each border state, avoids building one giant airbase but prefers upgrading existing ones, and so on. It generally looks for locations to help its frontlines as well as naval control by building on isolated states (islands, larger multi-state islands, enclaves like Gibraltar etc.).

Reworked anti-air construction
* To counter heavy strategic bombing, the AI tracks the frequency of bombing activity and damage levels per region. If it considers them too high, the AI will start priority constructing state anti-air around those regions.

Fort building
* Added a number of fort priority construction strategies for majors.
** Extensive strategies for USSR, reactively creating fortification lines in backline areas where the enemies are pushing near. It will build a ton of forts, but should minimize impact on industrial expansion as it only fortifies as needed.
** Also added many fortification strategies for majors for reactively fortifying islands, cities, creating fort lines when being invaded, when enemies pushing near etc.
* A generic strategy for AI to fortify victory points near enemies when it determines it is losing a war, with more importance on the capital state, as well as creating perimeter fortifications around its capital state city provinces, with increasing amounts of factories allocated to priority constructions depending on how fast the enemy progresses through its territory.
* If it looks like the war is stagnant or its frontlines aren’t changing too fast, the AI starts fortifying its front lines in places where the front doesn't move too much.
* There should be a ton more forts than you usually see from the AI, but I don’t want it to build massive forts on every border in a way that is *too* immersion breaking. So, it’s somewhere in-between the AI never building useful forts at all and AI abusing forts. It would be interesting to hear good feedback on this.

Overhauled naval designs, production and research
* Old bugs fixed that may have prevented the AI from building newer designs.
* Complete rework of all designs the AI wants to make. More effective, less ridiculously expensive designs.
* Destroyer production: it will try to maintain screening efficiency for its number of capital ships by switching screen production to a very cheap destroyer design as needed.
* The AI avoids doing a lot of incremental ship design upgrades and instead creates complete designs once it has all the requirements for it. For some ship designs there are a couple intermediary upgrade steps (for example, adding a radar module once it is researched). For various reasons, this is the best way to handle it in this mod.

Divisions and land equipment designs
* Complete rework of armor templates and equipment designs.
* Most notable armor template/design changes:
** No SP-AA or SP-ART types in these divisions.
** 50/50 ratio of motorized/armor brigades
** Added flame tank support (basic hull, fuel drums etc.), light tank recon (not sure this is useful) to all designs.
* Medium/heavy/modern tank destroyers brigades used in every division.
* Before the AI unlocks full size divisions, it will make 26w type templates even if it wants 40w templates.
* AI will upgrade to mechanized infantry and modern armor versions of the medium/heavy armor templates it has.
* The new design restrictions (template size, support columns) have made it harder to get the AI to create complex templates. I had to create more complicated scripted systems to guide the AI’s armor template upgrades because I wanted to 100% guarantee that the AI creates complex late-game designs.
* The mod’s AI military focus types for armor designs no longer change templates the AI makes and instead changes how it designs its tanks, mostly armor levels but in some cases module changes.
* The light, heavy armor templates and designs generally mirror the medium armor types, so they are probably far less optimal. I don’t have a good, detailed source for effective light, heavy armor templates/designs.
* AI can now research, design and build amphibious divisions that replace its marine divisions.
** For countries with a large industry and interest in building marine divisions (so usually USA in the late game, perhaps Japan, UK).
** Uses a template based on the regular armor division template it uses, with infantry substituted with amtrac and armor substituted with amphibious armor of the same type.
** Amphibious tank designs are similar to the regular tank designs it wants to build but with an amphibious drive.
Last edited by Kondi; Oct 10, 2023 @ 9:50am
< >
Showing 1-13 of 13 comments
Kondi  [developer] Oct 10, 2023 @ 9:12am 
Continued:

Adjusted air designs
* Adapted to patch changes to account for changes in patch.
* Replaced some ridiculously expensive designs such as heavy fighter and strategic bomber designs with more reasonable designs.
* Other minor tweaks across all designs.

Reworked USSR industrial plan
* Now that I can make AI to research techs and build factories (pre-war at least) in a much more precise manner, I’ve made the USSR optimize its industry significantly more.
* Improved early game country management critical for industry: sending attache, war economy, free trade, industry advisor, stability advisor, construction company (+ upgrades), using paranoia decisions, etc.
* It will rush factory/construction techs (taking advantage of the industrial tech bonus national focuses) to maximize industry.
* It should hit the 100 factories target for the Five Year Plan focus at the optimal, fastest possible timing (mid ‘37 or so).
* Construction strategy for the USSR works in stages from which it transitions to other stages based on various conditions:
** 1 - early game: if the AI is left undisturbed, it follows a EAI priority construction strategy that goes to extreme lengths to minmax for the best civilian factory base as it enters mid game. It constantly reorganizes its queue to maximize CIC completion (including from conversions). It queues infrastructure first to reach lvl 4 in states where it wants CIC. As it unlocks building slot techs, it immediately starts building in the most efficient slots where they became available. The usual stuff needed for this strategy.
** 2 - Around mid '39 it starts phasing into a mixed CIC/MIC build ratio, ideally reaching 180-200 civilian factories by '40.
** 3 - Expand MIC until the war begins.
** 4 - Construction is handed off to the regular EAI building AI in the event of a major war.

Reworked the mod’s naval invasion, lend-lease, volunteer scripted AI systems
* AI no longer selects a single target country to invade against, rather the AI’s willingness to invade in general is increased when the modded invasion system determines the AI should be invading somewhere. Making the AI invade specific targets does not work as it did when I made this system, so this way is safer. There are still specific strategies for historical invasions as well as for targets the AI should not invade. The diplomatic action for giving allies invasion targets has not changed but I’m not very confident it works that well.
* The mod controls the AI’s lend-lease exclusively now to prevent some strange lend-lease scenarios. Added some logic for specific situations.
* Japan shouldn't send volunteers to countries outside asia.
* General cleanup of these scripts.

Ethiopia
* Adjusted AI ETH to play dumber vs the AI ITA. No point in having ITA getting disastrous consequences from random outcomes at the start that forces restarting the campaign.
* AI Italy creates Italian East Africa as a reichsprotectorate so that AI ITA doesn't steal its divisions which AOI needs to defend itself later.
* Tuned AI for AOI to make sure it can put up a decent fight.
* The mod pathfinds for an allied land connection between East Africa and North Africa to determine whether Italy should be sending any troops on a suicidal boat mission to reinforce East Africa.

Japan
* Japan runs several collaboration ops vs China.
* Improved factory assignments, advisor picks, PP usage, research, construction, national focus order to improve its performance against China and be better prepared against USA.
* Builds up a significantly bigger fuel reserve to help it in the Pacific later.
* Japan should be developing all the aluminum and oil deposits it can for air production, and should be better at building naval bombers.
* Improvements in front strategies to handle fighting the Allies at the same time as fighting China better.

Finland
* Tweaked advisor and decision picks.
* Plays better when playing against a player USSR.

USSR
* Improved front behavior vs FIN while fighting against a bigger threat
* Improved defensive front behavior when being invaded by Germany

Germany
* Improved front strategies and timing when doing historical invasions in Europe.

Allies
* Improved front strategies for historicity while Axis is doing early invasions in Europe.
* Improved ENG/FRA front strategies for guarding their borders against ITA during the Phoney war

Italy
* The AI tended to get its navy annihilated as soon as the war began, so now in a case where it has naval disadvantage and it’s not being invaded, it will stop using its navy until it has a decent amount of naval bombers to provide some cover for its fleets.

Misc
* Removed the remaining gameplay changes from this mod: experience bonus nerf and entrenchment nerf. The gameplay mechanics of this mod should match vanilla 100%.
* Added required DLCs: BBA, NSB, MTG. All parts of the mod AI that deal with the non-designer DLC systems are hopelessly outdated and there is little point to using this mod without them.
* AAT is not required at the moment but the MIO/Market systems put this DLC above the rest of the non-required DLCs when it comes to the AI in the mod working to its full potential.
* Almost no changes to MIO/Market related things for the AI currently. The AI seems to be utilizing MIO’s pretty well at least. If it turns out that there are choices related to MIOs upgrade paths that are very important, I’ll adjust them for the AI later.
* Restructured and renamed files, strategies, scripts. Removed many outdated scripts. Many adjustments to old AI strategies or mod systems.
* Fixed Desperate Defense and Difficulty Bonus dynamic equipment production bonus to work with the plane and tank hulls that are used with the designer DLCs. Added all tank and plane types to the possible boosted production types. Fixed a bug where the bonus was not removed after the AI’s stockpiles for a type had recovered. Dynamic equipment production bonus meaning the aspect of the difficulty settings that dynamically reduces production costs for specific equipment types that the AI a shortage in.
* AI wants to build more armor if it has a static difficulty bonus applied.
* Fixed allies not declaring war on Vichy France.
* Instead of always protecting its capital with a separate garrison army, the AI will only do it if an enemy controls a state within a certain distance of it.
* Increased armor production for Germany, USSR, tweaked armor production in general.
* Reworked a lot of equipment production factory assignment scripts.
* UK, Italy and Japan build more dockyards and naval bombers.
* Added a scripted improve relations system because it is critically important for attaches and certain other things.
* DLC focus trees for Baltic states that are not disabled for the AI anymore.
* Improved the strategy that halts AI air missions when overwhelmed by enemy air force to give it time to recover before resuming. Intended behavior is that for example, if USSR gets its air force wiped out by Germany, it should stop air missions until it has rebuilt a significant force that may have a chance at contesting air superiority.
* AI Iraq/Iran play dumber when facing AI UK in order to achieve historical take over of these countries.
* Improved AI’s resource extraction decision taking in general.
* AI rushes rubber techs via priority research if it has a major shortage and has a bunch of refineries.
* Reworked advisor picks for most majors, a more strict logic for the AI to follow on historical AI and with typical priority being political advisors (PP gain, industrial advisors when appropriate) > chiefs (as the AI doesn’t always handle XP gain from other sources well) > others. Should be a major improvement.
* Cleaned up ENG, USA, GER, FRA, ♥♥♥ political power use in random decisions that prevented them from getting important advisors.
* Improved war support, stability decision taking logic for things like economy law, women in the workforce, avoiding crisis events. Especially, if the AI has a need for manpower and some action is otherwise available to it but it doesn’t have the war support for it, it should quickly take all the propaganda decisions that it can in order to unlock whatever it wants. Added some failsafes to manpower related action scripting so that if it has been out of manpower too long, it will try taking any action it can instead of optimal actions.
* Dumbed down Norway when playing against AI Germany to make a historical conclusion more likely. National focus given division and such can make Norway a quagmire for Germany at least in this mod since it has to push all the way to Narvik.
* Support for scripted provincial pathfinding, distance calculation between provinces, province terrain type, state region id var, state province ids arrays, province state id var, province neighbor connection arrays.
* To determine if the AI really is losing or winning in a quick and dirty way, it tracks the trend of the war by looking at short and long term averages of controlled provinces (just because USSR has surrender progress does not mean it is losing, or that Germany is winning because it holds most of Europe). The AI in the mod uses this info as a better metric for decision making in fort building strategies and other cases where the AI should act defensively or offensively, like using defensive leader abilities, get various decisions, certain front behavior, lend-lease, national laws etc.
Last edited by Kondi; Oct 10, 2023 @ 9:14am
Kondi  [developer] Oct 11, 2023 @ 1:01pm 
5.001

*If the AI has a ton of fighters, it shifts its air production towards other types it wants.
*USSR should further shift air production towards other things if it has more fighters than it can use.
*Air and division related focuses have more priority for USSR.
*Stopped majors from getting scammed out of their civilian factories by Denmark.
*USSR avoids naval invasions during initial Barbarossa
Last edited by Kondi; Oct 11, 2023 @ 1:02pm
Kondi  [developer] Oct 12, 2023 @ 10:17am 
5.002

* Fixed USSR not sending air wings to Spain
* Fixed USSR randomly not getting an air chief
* Added priorities for the AI's naval doctrine paths. It will prioritize paths for ships it wants to build (likely only caused issues for Germany).
Kondi  [developer] Oct 15, 2023 @ 1:17am 
5.003

* Added artillery support to the cheaper infantry templates the AI sometimes uses.
* AI should not use a cheap template variant if it has an EAI difficulty bonus.
* AI converting too many divisions to modern armor should be fixed.
* AI might be more willing to invade in certain scenarios. Or not.

5.004

* To try to reduce the late game resource shortages the AI has, it will start slowly converting MIC to CIC when it has extreme and persistent resource shortages.
Kondi  [developer] Oct 16, 2023 @ 9:35am 
5.005

* Reduced all dynamic equipment cost reduction modifier amounts. Cost reduction setting: Air: 5%, 10%, 15%. Other: 15%, 30%, 45%. Desperate Defense: Air: 1%-20%, Other: 2.5%-50%. Some tweaks to how the mod updates and applies these modifiers. Hopefully there are no cases where the AI's equipment cost goes negative due to too many stacking cost reduction modifiers, whether it's due to the mod somehow managing to apply two modifiers to the same equipment or due to cost reduction modifier creep into the base game from various DLCs and MIOs.
* Cost reduction setting trigger for aircraft types capped. E.g. fighter bonus will only be active as long as the AI has fighters < 1000 and fighters < MIC*15.
* Adjusted general industrial build strategy so that the AI transitions from building CIC to MIC more sensibly based on various conditions. Generally speaking all countries start building MIC earlier but also build some additional CIC if it doesn't have enough available later.
* USSR uses superior firepower + more artillery. Seems to work a little better for it.
* Improved random issues AI had with France guarding against GER and AI invading Iran
Last edited by Kondi; Oct 18, 2023 @ 1:41am
Kondi  [developer] Oct 21, 2023 @ 6:55am 
5.006

* Adjusted AI template widths for AAT changes (inf, mar, mnt, arm).
10 -> ~15
~20 -> ~18
~26 -> ~25
~42 -> ~35

* Less motorized in armor templates

* Slightly more artillery in some infantry templates
Kondi  [developer] Oct 27, 2023 @ 9:54am 
v5.007

* Adjustments to ENG/SOV invasion of iran focuses to stop WW3, SOV invasion of ♥♥♥ to make it more likely when it makes sense and to stop it from causing WW3
* Majors prioritize anti-tank tech upgrades if they are building medium/heavy armor.
* Fixed template design related issues related to modern armor upgrades. Cleaned up parts of the template upgrade process
* Germany should not restart doing fascist things after losing the war.
* China should not do One China Policy while at war with a major
Kondi  [developer] Nov 1, 2023 @ 9:35am 
5.008

* Slight adjustment to how the event that makes SIK leave Comintern fires. Requires lower surrender threshold than before but it factors in the war trend to make it more historically likely. Peaces out the wars with Axis.
* 1.13.5 AI changes caused some issues for certain nations with what division template they produce (Japan choosing the armor template for its infantry). Applied some workarounds but there may be more issues depending on what type of divisions the AI configured to make.
* Japan should use the border incident decision at the start.
* Another adjustment that might stop West Germany from doing fascist focuses
* More adjustments to countries avoiding declaring war on Iran if its in a faction or a puppet. Same with Iraq.
* Air designs for AI required changes to make them work with 1.13.5 changes
Last edited by Kondi; Nov 1, 2023 @ 9:37am
Kondi  [developer] Nov 8, 2023 @ 7:41am 
5.009

* Adjusted naval invasion scripting to avoid some scenarios that inexplicably stop AI invasions. Disabled a vanilla invasion strategy for UK that was conflicting with the mod.
* Improved Axis minor unit strategy. Shouldn't send units to Africa in typical scenarios. Defends their own territory if it borders an enemy. Assists ITA/GER otherwise.
Last edited by Kondi; Nov 8, 2023 @ 7:42am
Kondi  [developer] Nov 17, 2023 @ 5:49am 
5.010

* Added field hospitals to most infantry templates
* Japan should not go to war with USA earlier than historically
* Romania should try to join USSR after the coup
* Bulgaria shouldn't join Allies during its civil war
* USA should guard some of its cities better
* Other minor adjustments historical AI progression
Kondi  [developer] Apr 5 @ 7:49am 
5.014

* Fixed an issue that might have caused the AI switch to industry tech branches later
* Fixed an issue with AI's process of choosing which espionage operation to run
Last edited by Kondi; Apr 5 @ 7:50am
Kondi  [developer] Jun 11 @ 10:14am 
5.02

* Reworked naval production ratios. There were problems in the current version leading to too many subs and such.
* Improved/fixed research priorities.
* Reworked air production ratios. Probably somewhat less focus on fighters. Better at producing CV fighters/bombers for carriers.
* Removed from AI templates: scout recon tanks, flame tanks. They create more problems than benefits for the AI with xp use, recruitment, factory assignments and I doubt I can mod the issues away. This way they deploy more armor divisions reliably.
* AI will not upgrade tanks to mech and modern types until extreme late game. Causes too many issues for the AI, it is unable to manage the resource needs for mech production.
* AI will not upgrade aircraft to jet types until extreme late game. Jets are not very effective and the AI has a seizure trying to make it work same as above.
* Tried to address the lack of allied naval invasions against Axis. They do it but they're not very effective.
* Adjusted Japan vs China AI balance to make it a little easier for Japan.
Kondi  [developer] Jul 24 @ 11:31am 
5.021

* Reworked occupation law logic - in general, avoid going over 50% resistance but prefer lower laws, prefer growing compliance if compliance is high already, democracies use autonomy, forced labor/harsh quotas in beneficial states if it can handle the resistance, brutal oppression if resistance is going over 75% due to resistance ops for example
* AI's occupation template goes from 1xCAV > 20xCAV+MP > 25xCAV+MP instead of waiting forever to unlock/get xp for the 25xCAV template
< >
Showing 1-13 of 13 comments
Per page: 1530 50