• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

EU4 - Development Diary - 16th of October 2018

Welcome all to today’s dev diary, my name is Michael, and I've been on the EU4 team as a programmer for a bit more than a year now.

Many of you have noted that the AI has been showing some undesirable behavior after recent updates, especially when it comes to defending their homeland and when choosing which forts to siege. So for the upcoming "Spain" update we spent some time on improving those aspects of the army AI. In this dev diary I will be explaining some of the changes we made. In addition to the improved hard-coded AI behavior, with the upcoming update modders will be able to influence some parts of the army AI with scripts. I'll end this dev diary with a short explanation/tutorial of this.


First I'll go over the changes and improvements made so far. Since we are still working on this update all of this is of course subject to change.

- The selection of armies to go on invasions (overseas) does now consider potential threats to the homeland and will be smaller if necessary. There still is the option that the AI will decide to invade with the full force if it thinks it cannot win otherwise. The calculation of the required strength has been overhauled and should be better in determining how many troops are actually needed.

- Region assignment of armies used to be done about once per year. There was a random factor involved so in some cases it could take even longer. In addition to the random reassignments it is now recalculated whenever the threat to the homeland changes considerably, i.e. there are sieges, large amounts of hostile troops moving towards homeland, etc..

- If there is a threat to the homeland these regions will have a much higher priority when assigning AI agents to regions. Even if not threatened, the homeland has higher priority in region assignment, if enough armies are available. On the province level (Within the assigned region) provinces close to the own country are now preferred when looking at what to siege/where to defend and what war goals to go for first.

- Armies running away from a superior force will still try to find a safe place, but provinces that require using military access or long walks will have lower priority, and if reasonably safe, the homeland receives much higher priority. AI armies are more likely to stand their ground, especially if they are clearly inferior and there is no real chance of winning the ongoing war anymore. Previously the player was often forced to chase them around the world thanks to easily available military access.


Scriptable army AI
A central part of the EU4 army AI is the evaluation of provinces, which determines where and when armies move to. There are already many defines you can change to tweak the outcome of this evaluation, but starting with the coming update you will also be able to change or even overwrite the evaluation score by using any trigger you like.
You will find new script files that have some basic functionality in commmon/ai_army, but you can add as many of your own as you like.

Let's look at a simple example:

Code:
province = {
    war = {
        active = {
            is_at_war = yes
        }
        eval_multiply = {
            modifier = {
                factor = 0.1
                is_in_capital_area = yes
            }
        }
    }
}

For now the top-level scope is always "province". We might add different options later. The second level is just a name you can choose freely and it serves to separate different modifications you want to apply. Just like event probabilities the starting value for these is 1. The interesting scopes are "active", "eval_multiply" and (not shown) "eval_add" and "eval_overwrite". With those you can control the modifications that will be applied to the evaluated province score. In this case it will be applied whenever the country is at war.
It is important to note that the evaluation of provinces happens very frequently for all armies in the game, so this "active" trigger will not be checked every time a province is evaluated (Which might happen hundreds of times per daily tick).
It will be evaluated when any of the following happens:
- Whenever you gain or lose ownership or control of a province
- Whenever a war starts or ends
There are three ways to modify the score, you can multiply it, add to it or overwrite it. The factor can be negative and < 1.0 as well so the inverse operations are also possible.
Note that armies prefer the province with the lowest score.

While you can influence armies a lot with this, there are still some hard-coded things that will always take precedence and obviously armies will still always adhere to the rules of the game (e.g. shattered retreat). It is a nice option to have however and I'm looking forward to seeing if and how it will be used in mods. Of course it is also possible to break AI behavior with this, so I'd recommend being careful, especially with "eval_overwrite".

To debug your script you can use the AI mapmode. In this mapmode you can see the evaluation scores for every province if you select an army. You can enable this mapmode by running this command in the console:

Code:
mapmode aieval

Capture.PNG


That’s all for today! Next week we will be looking at new features of the upcoming immersion pack. In the meantime, I’ll be watching this thread, so feel free to ask any questions you might have.
 
Last edited:
Hopefully with an improved AI we can also improve things that the AI otherwise would choke on. Like making Loans more expensive/less available the worse your war is going, nerfing "Emergency Mercenaries" so lategame Players/AI can't spam mercenaries on loans when they're losing, etc.
 
These are great changes and I am extremely excited for them. I just need to gripe a bit because I think they are treating symptoms of a deeper issue: the AI lacks strategy and direction.

The glaring part of this is acknowledgment of whackamole being fixed. This is awesome, but go further. If the AI is at a point that it knows its a sure loss, it needs to make peace. It needs to stop mercing.

This needs to hold true in a broader sense. As a war ally with nothing but favors to game, wiped stacks in foreign land should not be replaced by heavily loaned for mercs. Stop throwing money or men into the blender on another's war. This would work nicely with an honest rethinking of "war enthusiasm" where if you aren't in line for spoils or against a bitter rival, you aren't willing to balls to the wall fight through hardship.

AI should occasionally hit a point (that players routinely do) where they are done fighting back and just stay home. How many times have you bailed on a loss and just played defense, wishing the ally would just give up already?

Regarding regional assignment, this sounds good. I would add that you already have AI figure out opinions of enemies and provinces of interest - use it! If 2 pals get called in, don't have them stomping each other. 2 rivals? Screw the target, I want to teach my enemy a lesson. The selflessness of the AI is often its biggest weakness.

Finally, AI have a check where they want things in a peace deal to accept. Do the reverse: make them more likely to drop a losing war with concessions if the concessions include "acceptable" losses / no "unacceptable" ones. Demanding gold and annuled treaties of actual participants should get a "just peace" modifier or something.

Tl;dr have the AI prioritize its interest and opinions, make peace sooner if conditions are good, and not wreck manpower or loan+merc spam wars it shouldn't care about.
 
Can you as well upgrade AI knowledge about trade? I see a lot of times when AI is collecting trade like idiots, losing a lot of money because of it.
I've game right now where Ottomans are sending all trade from Egypt/Persia/Aleppo to collect 10% trade in Constantinople.

Also I found "feature" or bug. You are limited to 3 "trade center lvl3" per country, but you can also make 3 trade center lvl3 in wasal, then demand to send all their trade. It would be nice to limit upgrading trade centers in wasal/PU to 2.
 
Have you considered allowing the player to assign armies to AI control, like you can with fleets? With more missions than only exploration or rebel fighting that is.

In some large wars I would like to assign some of the armies to the AI and focus on just some of my larger armies myself.
 
Have you considered allowing the player to assign armies to AI control, like you can with fleets? With more missions than only exploration or rebel fighting that is.

In some large wars I would like to assign some of the armies to the AI and focus on just some of my larger armies myself.

It is not really a big command-and-control issue when you can simply pause and unpause the game while adjusting the movements and positioning of your armies but even then I can see appeal of this. It would be simply delegating some armies to AI commanders that can save some time trying to manage many armies, especially when you have a large colonial empire with many possessions dispersed all over the world. This can potentially reduce micro-management to some extent.

Even more importantly, it would be interesting to see how AI generals with leader personality can influence a theater in the war on human side against AI or even a human player. It may even provide an incentive for the devs to add more personality / trait and bring its total number up to the level comparable to that of Victoria II.

It also gives a significance to the idea of having main armies and secondary armies whereas you personally retains control over the main ones while giving the AI generals in other armies freedom of action to do things as they see fit. For example, during a great war involving Europe with additional theaters overseas, you might retain personal control over all armies deployed or stationed in European theater while delegating control of the armies in overseas territories such as those in Africa and elsewhere.

Typically, as England/Great Britain I have small "company armies" in West Africa which I'd be happy to delegate to my AI generals when I have a war to worry about in Europe. One other reason I see an appeal in this delegation is my experience with using AI vassals as the "princely states" to supplement my forces in the English/British India. They help a lot in distracting / tying down the AI enemy armies within or near the India while I focus on besieging and destroying the large armies whenever I can. Sometimes, AI vassal armies can do something you have never even thought about when strategizing where to go next during the war there.
 
Can you also fix TImeline issue, when you use Custom World and only created nation are on the map, but in Timeline, there's also a vanilla nations. This is frustrating, you know. And this could be fixed back in Mare Nostrum DLC release.
 
A couple of notes:

- Sometimes (before at least), England-United Kingdom, having naval superiority, was leaving in the middle of a war I do not know where, and France with 4 ships invaded the country. I have seen this, I do not know if it is resolved now that England and the United Kingdom are very powerful.

Of course, the first objective should be to defend your country with its naval superiority.

- In a Prussian game, I've been watching 150 years with the Polish-Lithuanian Alliance that has France as its subject.
After several wars, France has more development, more army and 100% desire for Freedom.

They have not declared war nor will they do it, they have been 70/80 years with more freedom of 50% and nothing.

I suppose that the machine compares its power, France, with that of Poland-Lithuania plus all its allies and does not dare.

There should be a mechanism of countries that offer their help and even participate in a war of liberation.

Many years ago I want to liberate France but the only way is to get 100% in a war against Poland and its Allies.
 
It would be swell if you guys fixed that bug where your vassals don't move their armies at all. I don't know if others experience it, has been happening since 1.24 to me.
There are features from Crusader kings 2 and Hearts of Iron 4 that allow you to request all or at least some of your "puppets/vassals" forces. This would make it much more simpler and easier than having 100% of your vassals troops sitting at their home capital doing nothing for the majority of wars, or simply just charging their small forces into much more superior forces for no reason. At that point I feel like scuttling them or using their territory as a speed bump for the AI. I am not a developer and this is just a request, you guys have made a great game here and I just want to see it improve.Thank you for all the work you have done so far.
 
OK I think this immersion pack is a little underwhelming compared to Third Rome but I really don't get the sheer controvosy thats going on here right now? It's a €10 dlc? Chill ?