• 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:
Sounds cool, looks like something fun to play with for modders! One thing I have noticed with the AI as it is currently is that when I have allies in a war, the allies will often suicide themselves attacking the enemy's strong stacks, even when my troops are stationed too far away to help them. It is almost as if the AI thinks I am also an AI and it can control my armies to coordinate attacks, only it can't and doesn't realise my armies aren't moving into position.
 
The single largest problem i've found with AI repeatedly is colonial superpowers (France, Britain, Portugal etc) declaring war on tribes in Africa/Latin America (i.e Mutapa, Cusco) without preparing any troops even on the same continent before the decleration of war. The small African/Latin American tribes then occupy all nearby colonies land, the colonial superpowers seem to be frazzled and end up paralysed for the entirety of the war untill they eventually peace out giving away a bunch of their colonial provinces.

I can't tell you how many times i've seen Carib do this to Portugal and end up as a huge Catholic powerhouse in Brazil. It would be cool to see this happen for legit reasons (Carib delcaring war during a moment of Portugal's weakness fighitng in Europe or something) but it never is, it's just the dumb Portugese AI declaring war with no troops nearby and then being paralysed for 10 years and peacing out with a negative warscore.
 
- 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.


This is my favorite part of this. Thank you x10. I do hope that the AI will account for being in coalitions in the HRE; as each individual army will be miniscule to the overall effort but them blobbing together is an important part of the wars that take place. Hopefully this specific AI component gets a lot of testing in such cases; as India now has a lot of those minors as well.
 
Eh no, the AI needs to be made stronger not weaker.
It should be stronger by addressing silly/unrealistic/buggy behaviour (which their is an abundance of, a lot that would be seemingly quite simple to fix - see this thread), not by making it clairvoyant and rendering player strategy/preperation/tactics useless.
 
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.
 
Are changes to the AI military-related only, or have you considered improving the way AI handles economy and research? I'm not sure what part is it, buy AI always seems to struggle to keep up with the player in the long term. I suspect it has to do with AI being bad at managing and milking estates.
 
I like this partly because AI improvements to the base game are always gratefully received, and partly because I really want to create a completely broken AI script that makes every single AI army irresistibly drawn to the Isle of Man or Bornholm or somewhere equally as ridiculous.
 
First thankyou for AI improvements, this really is the most important aspect to work on in the game at this point.

one has to wonder how even more useless England will be now

AI being able to understand when its island/strait provinces are protected would be a HUGE improvement. Its so common to see a 30k Ottoman stack stuck on Corfu, after it sank its navy by sending 5 separate fleets to lose against a force half its size.

Teach the AI to use overwhelming naval superiority properly. Blockade everything. Spam pirates. Focus on straits. Attack islands. Support offshore rebels. Ignore enemy strength if they can’t land. ect.

In other words... just make English AI replicate the utter scumbag troll it is in multiplayer hands. Or hell, just make Venetian not have Down syndrome.
 
Great news! Or should i say finally?

I have two questions though:

-I am wondering if all of these will cripple the performance. But just wondering, otherwise these improvements should be made nearly at all costs.
-Estate management. Especially with Dharma, estates became an enormous power base. They provide all kinds of monarch powers, money, loan, speacial unit, missionary strength etc. can't even count all of'em rn. When will AI use these properly for God's sake?
 
The obvious immediate solution is too just nerf estates back to 1.24 levels (which were still OP then, lol).
 
Yeah, and a quarter of the comments are people still arguing over Spanish provinces.

-_-
Yes and we are doing so in the appropriate dev diary. In no way does that diminish the merits of an AI update, as I have already posted here. This is the Iberia Immersion Pack so if we feel like a region needs further work of course we are going to be more vocal now. Don't like it, don't read it. You simply don't have to click on the dev diary which is specifically about map changes.
 
Reminder : this dev diary is about the AI, not the map. Stay on topic.

You still have the previous dev diary to talk about the map.
 
That isn't a bug; the AI thinks you're weak [Especially with inferior tech; and Smallpox event] and wants your gold.

Balance of power gets even worse if they see you're at war with a major already. They'll dogpile.

If you look at most colonizer AI's; they'll mark all gold provinces as Vital Interest.

I realise this is not a bug, but working as the AI is taught, however, I find it a bit irritating/annoying to constantly endure their wars.
Consider that they basically hate me more than their historical rivals, and even with close to equal tech, any arbitrary dutch coloniser will have -200 opinion due to want your territory and eager to join the French or other in a war against me.

I posted this in the AI dev diary, hoping this behivour might be tweaked a bit.