• 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:
This is fantastic, hopefully the AI will stop carpet seiging the Steppes/other useless land while I fullsiege their homeland. It didn't help them, it was just annoying.

10/10
 
Could we have vassals and marches being unable to ask/grant for military access too? Thats a mess when we try to keep some countries out of another region and then our vassal just goes like 'sure, come through!'
 
To be honest i kind of enjoyed the predictability of the AI, just makes it very easy to sweep in with naval forces faster than they can react and drop a entire army on them by pitching up at the province under siege with a transport fleet, like moths drawn to bright light they clamour to and you zap them with a direct 5 shock general until they crumble. (as Ottomans obviously)
  • If not too damaged, pack up and launch a naval invasion somewhere else or retreat your troops out of range to spook small stacks and do it again.
England might not be as willing to lend support from the implied changes, but they might be more dedicated to send piecemeal 'waves' of troops if I understand right rather than drop everything and sail halfway around the world counter-clockwise the long way because someone in mesopotamia (lets say Haasa or a slightly fed Hormuz) left their fortress with no maintenance exposed pre-canal for easy access or sail around busy Africa which might be teeming with rival great power nation ships.
 
AI improvements are always welcome! and I remember making a suggestion for that concern -- was disappointed that most wars look like "I am besieging your country and you are besieging mine, let's see who finishes first". Now there's going to be a greater balance, and more strategic calculus, about defence & offence and how to divide one's armies. I love it. If you've done a good job, this should greatly enhance the wars' depth and diversity.

I have one question regarding the upcoming Spain patch/Immersion Pack: what about Catholicism? This sounds like a great opportunity for improving it. Although most people would disagree, I am personally satisfied with way it stands now but I feel there is room for improvements nevertheless. Especially since the old mission system is gone, the Papal State is not receiving more gifts and friendships as it used to have. And historically, Spain was a huge devotee to the Pope, so it would make sense to include more dimensions in the update. I feel like there could be at least more events where the player has to make heart-breaking choices between giving gifts to the Papal State in exchange for bonuses and privileges, or keeping these resources for itself but being punished for not being generous enough.
 
Have there been any tweaks to AI building prioritization? Like many have already said, the AI doesn't upgrade their capital fort, wastes money on forts and other buildings where they serve little to no purpose, refuses to upgrade centers of trade, wastes thousands of ducats in TC regions that they get little benefit from, and I'm sure there's more.

Maybe it's a money problem, the AI seems to have a lot of level 3 centers of trade and, while it might not instantly upgrade their forts, they almost all end up being level 8 eventually.
 
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.
This doesn't make any sense. I agree that it's weird to chase the armies across the planet, but if the goal is removing that and having less annoyance to the player, then give extra reasons to accept peace for having clearly inferior armies. Instead, this is a more immersion-breaking design choice. More likely to stand ground when weaker?

Yes I'm sure a lot of the AI's reasoning is very unrealistic if it's explained, but, it's the one negative that stood out to me from the diary among the many good things.
 
This doesn't make any sense. I agree that it's weird to chase the armies across the planet, but if the goal is removing that and having less annoyance to the player, then give extra reasons to accept peace for having clearly inferior armies. Instead, this is a more immersion-breaking design choice. More likely to stand ground when weaker?

Agreed. If enemy becomes too weak to stand against player, he must just surrender and not start whack a mole game.
This ofc will result in lots of one battle decided wars, but historically wars often were decided in one big battle, after which one side became unable to continue war.
To help with this, you may add ability to retreat from unsuccessful battle and save most of army, with chance, depending on leader's Maneuver skill, distance to friendly lands, and something like this.
 
This doesn't make any sense. I agree that it's weird to chase the armies across the planet, but if the goal is removing that and having less annoyance to the player, then give extra reasons to accept peace for having clearly inferior armies. Instead, this is a more immersion-breaking design choice. More likely to stand ground when weaker?

Yes I'm sure a lot of the AI's reasoning is very unrealistic if it's explained, but, it's the one negative that stood out to me from the diary among the many good things.
I hope that at least that if the AI decide to "stand their ground", that at least they then choose defensive terrain for the last stand. Make the enemy bleed for their victory, drive up their war exhaustion so they are more likely to peace out for less, that sort of thing.
 
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.
not me I dont experince it? I mean sure AI sometimes doing stupid things but not deadlooking
and if they do I usually give them orders wich makes them move


also am I the only one noticed this changes gonna make AI ming scary :p
 
Have there been any tweaks to AI building prioritization? Like many have already said, the AI doesn't upgrade their capital fort, wastes money on forts and other buildings where they serve little to no purpose, refuses to upgrade centers of trade, wastes thousands of ducats in TC regions that they get little benefit from, and I'm sure there's more.

building is generally bugged. for example you can see AI is not building manufactories for richest provinces. open observe mode and watch the ottomans, AI mostly ignores manufactories with more than +0.50 in return.

Excuse me, but what is a Forced March for?
https://eu4.paradoxwikis.com/Land_warfare#Forced_march said:
Forced march makes an army move 50% faster, but costs 2 military power for each province the army marches through. Forced march is available at administrative technology 15. Armies that are forced marching do not recover morale. During Age of Revolutions it is possible to enable Improved Force March ability, which reduces military power cost to 0 (requires Mandate of Heaven).
 
Thanks for the changes, they are certainly welcome.

As for questions, recently I've noticed that the AI often refuses to attack similar stacks that are sieging its forts. Eg. if a 24k stack is sieging a fort, the AI will often park its similar sized army next to it, wait for the siege to finish and only attack after it's been occupied. It seems to me that the AI is scared of even battles and doesn't factor in the newish defensive bonus when relieving fort sieges. This often makes it lose fortresses to rebels or enemies for no reason. Oddly enough, it often chooses to engage right after the fort has been captured, needlessly taking attacker penalties. Shouldn't the AI be more courageous, especially against rebels or when having strong military bonuses?
This behaviour has been there at least since the 1.25 patch, and it's not only when sieging.
 
@mikesc

- AI doesnt try to complete its missions. taking wrong provinces in peace treaty.
- AI deosnt know how to feed its vassals.
- AI uses its vassals' casus belli and claims to declare war on some country but at the end of the war AI takes provinces to itself rather than its vassals.
- AI still cant calculate which wars/battles it can win and which wars/battles not. 44k ottoman soldiers are not attacking to 22k mamluk soldiers for example. it is happening in observe mode and after that i control AI via console command and attacking mamluk army with 44k soldiers and can easily win against them, actually almost stackwipe.
- AI never builds universities at all.
 
Last edited: