EU4 - Development Diary - 16th of October 2018

EU4 - Development Diary - 16th of October 2018

  • Pre order now!

    Paradox Development Studio brings you the sequel to one of the most popular strategy games ever made! Crusader Kings III is soon upon us and you can pre order it today!


    Releasing September 1st 2020

mikesc

Programmer - EU4
3 Badges
Aug 4, 2013
32
0
  • Stellaris
  • Hearts of Iron IV Sign-up
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:

XavierDarius

Private
2 Badges
Jun 15, 2018
22
0
  • Age of Wonders III
  • Crusader Kings II
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.
 

Arbus

Lt. General
109 Badges
Jun 3, 2009
1.340
316
  • Crusader Kings II: Jade Dragon
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Pre-order
  • Age of Wonders: Planetfall Deluxe edition
  • The Showdown Effect
  • Stellaris: Lithoids
  • Rome: Vae Victis
  • 500k Club
  • Hearts of Iron IV: Field Marshal
  • Crusader Kings II: Holy Knight (pre-order)
  • Europa Universalis IV: El Dorado
  • Pride of Nations
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Conclave
  • Imperator: Rome Sign Up
  • Prison Architect
  • Stellaris: Galaxy Edition
  • Imperator: Rome Deluxe Edition
  • Hearts of Iron IV Sign-up
  • Stellaris Sign-up
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Stellaris: Humanoids Species Pack
  • Tyranny: Archon Edition
  • Stellaris: Digital Anniversary Edition
  • Stellaris: Leviathans Story Pack
  • Europa Universalis IV: Dharma Pre-order
  • Europa Universalis IV: Dharma
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Europa Universalis IV: Golden Century
  • BATTLETECH
  • Hearts of Iron IV: Death or Dishonor
  • Cities: Skylines - Green Cities
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Apocalypse
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Holy Fury Pre-order
  • Europa Universalis III Complete
  • Europa Universalis III Complete
  • Europa Universalis IV: Rule Britannia
  • Cities: Skylines - Parklife
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Ancient Relics
  • Age of Wonders: Planetfall
Can we have a summary of all the province changes after the last diary?
I admire your optimism.

On topic, AI improvements and modability are always welcomed :)
 

Kane_hun

Dreamy Mistknight of Tomorrow
32 Badges
Nov 29, 2016
324
18
steamcommunity.com
  • Europa Universalis IV: Pre-order
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Crusader Kings II: Reapers Due
  • Crusader Kings II: Horse Lords
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Monks and Mystics
  • Europa Universalis IV: Mandate of Heaven
  • Age of Wonders III
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis IV: Rule Britannia
  • Europa Universalis IV: Dharma
  • Crusader Kings II: Holy Fury
  • Europa Universalis IV: Golden Century
  • Crusader Kings III Referal
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Cossacks
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: El Dorado
  • Europa Universalis IV: Mare Nostrum
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Republic
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Charlemagne
  • Crusader Kings II
Perhaps this is a bit out of scope, but are there any changes coming to the endless waves of European coloniser dows against NW nations (even as big a a reformed Inca, for example)
 

claivin

Private
44 Badges
Jun 1, 2015
20
3
  • Crusader Kings II
  • Stellaris: Leviathans Story Pack
  • Stellaris - Path to Destruction bundle
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: Pre-order
  • Victoria 2
  • The Showdown Effect
  • Ship Simulator Extremes
  • Sengoku
  • Europa Universalis IV: Res Publica
  • Knights of Pen and Paper +1 Edition
  • Impire
  • Magicka
  • Hearts of Iron III
  • Crusader Kings II: Sons of Abraham
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Cossacks
  • Europa Universalis IV: Mandate of Heaven
  • Europa Universalis IV: Cradle of Civilization
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Europa Universalis IV: Rule Britannia
  • Europa Universalis IV: Dharma
  • Shadowrun Returns
  • Imperator: Rome Deluxe Edition
  • Europa Universalis IV: Golden Century
  • Stellaris: Digital Anniversary Edition
  • Europa Universalis IV: Rights of Man
  • Hearts of Iron IV: Cadet
  • Stellaris Sign-up
  • Hearts of Iron IV Sign-up
  • Stellaris
  • Europa Universalis IV: Mare Nostrum
  • Humble Paradox Bundle
  • Europa Universalis IV: El Dorado
  • War of the Roses
  • Teleglitch: Die More Edition
  • Stellaris: Synthetic Dawn
  • Europa Universalis IV: Call to arms event
  • Imperator: Rome
Scriptable AI sounds really cool! Is there any functionality on how AI will divvy up/organize its forces, or is it mainly a siege/movement/positioning thing?
 

Blobhemian

First Lieutenant
52 Badges
Dec 3, 2015
219
180
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Pre-order
  • Europa Universalis IV: Cossacks
  • Crusader Kings II: Way of Life
  • Crusader Kings II: Conclave
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Monks and Mystics
  • Europa Universalis IV: Mandate of Heaven
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis IV: Rule Britannia
  • Europa Universalis IV: Dharma
  • Crusader Kings II: Holy Fury
  • Europa Universalis IV: Golden Century
  • Imperator: Rome Deluxe Edition
  • Imperator: Rome
  • Prison Architect
  • Imperator: Rome Sign Up
  • Imperator: Rome - Magna Graecia
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Magicka: Wizard Wars Founder Wizard
  • Europa Universalis IV: El Dorado
  • War of the Roses
  • Victoria 2
  • Teleglitch: Die More Edition
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV: Call to arms event
  • Crusader Kings II
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: The Republic
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Mare Nostrum
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?
 

Mingmung

General
34 Badges
Aug 23, 2014
1.719
488
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Mare Nostrum
  • Europa Universalis IV: Third Rome
  • Crusader Kings II
  • Europa Universalis IV: Res Publica
  • Europa Universalis IV: Call to arms event
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Europa Universalis IV: Dharma
  • Europa Universalis IV: Rule Britannia
  • Europa Universalis IV: Cradle of Civilization
  • Hearts of Iron IV: Death or Dishonor
  • Europa Universalis IV: Mandate of Heaven
  • Crusader Kings II: Monks and Mystics
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Holy Fury
  • Crusader Kings II: Reapers Due
  • Hearts of Iron IV: Cadet
  • Crusader Kings II: Conclave
  • Europa Universalis IV: Cossacks
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: El Dorado
  • Cities: Skylines
  • Victoria 2
  • Europa Universalis IV: Pre-order
  • Cities: Skylines Deluxe Edition
Can we have a summary of all the province changes after the last diary?
I agree with @navaluiki , this isn't neondt's dev diary, so I think we should wait until next week when Spain is in the focus again.

Unless @neondt doesn't mind it?
 

Hermaan

Private
74 Badges
Apr 6, 2016
10
0
  • Crusader Kings II
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Crusader Kings II: The Republic
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Europa Universalis IV: Mare Nostrum
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Mandate of Heaven
  • Cities: Skylines - Mass Transit
  • Crusader Kings II: Monks and Mystics
  • Hearts of Iron IV: Together for Victory
  • Cities: Skylines - Natural Disasters
  • Stellaris: Leviathans Story Pack
  • Stellaris: Digital Anniversary Edition
  • Crusader Kings II: Holy Fury
  • Cities: Skylines - Parklife Pre-Order
  • Surviving Mars: First Colony Edition
  • Surviving Mars
  • Hearts of Iron IV: Death or Dishonor
  • Crusader Kings II: Holy Fury Pre-order
  • Cities: Skylines - Green Cities
  • Cities: Skylines - Parklife
  • Europa Universalis IV: Golden Century
  • Hearts of Iron IV: Expansion Pass
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Europa Universalis IV: Rule Britannia
  • Hearts of Iron IV: Cadet
  • Europa Universalis IV: Dharma
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Stellaris: Lithoids
  • Stellaris: Distant Stars
  • Crusader Kings II: Conclave
  • Cities: Skylines - Campus
  • Stellaris: Galaxy Edition
  • Imperator: Rome Sign Up
  • Stellaris Sign-up
  • Hearts of Iron IV: Colonel
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
Would this make scripting something like "rebel" armies going out into neighboring countries from their home province possible? I am thinking of something like robber barons.
 

hdhhshdsh<s

Second Lieutenant
22 Badges
Mar 1, 2016
166
0
  • Europa Universalis IV: Art of War
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Res Publica
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Mare Nostrum
  • Imperator: Rome
  • Europa Universalis IV: Dharma
  • Europa Universalis IV: Rule Britannia
  • Surviving Mars
  • Europa Universalis IV: Mandate of Heaven
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Rights of Man
  • Hearts of Iron IV: Cadet
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: El Dorado
  • Cities: Skylines
  • Europa Universalis IV: Cossacks
  • Europa Universalis IV: Cradle of Civilization
  • Crusader Kings II
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?
Most likely related to this -
ACCEPTABLE_BALANCE_DEFAULT = 1.7, --AI wants this advantage to enter battles typically. (There are some exceptions, e.g. offensives.)

Though if I understand the changes correct, it should be easy to circumvent such behaviour (Ie could make AI take into account things such as defensive bonus of fort/province, military boni etc, so its not just limited to a flat 1.7 times larger force decider)
 

Warthull

Corporal
72 Badges
Oct 24, 2015
44
40
  • Europa Universalis IV: Third Rome
  • Victoria 2: A House Divided
  • Victoria 2: Heart of Darkness
  • Europa Universalis IV: Pre-order
  • Cities: Skylines - After Dark
  • Stellaris: Galaxy Edition
  • Stellaris: Leviathans Story Pack
  • Europa Universalis IV: Mare Nostrum
  • Stellaris
  • Stellaris: Galaxy Edition
  • Hearts of Iron IV: Cadet
  • Hearts of Iron IV: Colonel
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Stellaris: Digital Anniversary Edition
  • Crusader Kings II: Way of Life
  • Hearts of Iron IV: Together for Victory
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Surviving Mars
  • Hearts of Iron IV: Death or Dishonor
  • Europa Universalis IV: Rule Britannia
  • Age of Wonders III
  • PDXCON 2018 "The King"
  • Stellaris: Apocalypse
  • Stellaris: Humanoids Species Pack
  • Stellaris: Distant Stars
  • Imperator: Rome Deluxe Edition
  • Prison Architect
  • Imperator: Rome Sign Up
  • Stellaris: Ancient Relics
  • Stellaris: Lithoids
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Parklife
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: Dharma
  • Stellaris: Megacorp
  • Crusader Kings II: Holy Fury
  • Europa Universalis IV: Golden Century
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Stellaris - Path to Destruction bundle
  • Victoria: Revolutions
  • Europa Universalis IV: Res Publica
  • Hearts of Iron III Collection
  • Darkest Hour
  • Crusader Kings II: Sword of Islam
Thanks! Always love to see dev diaries on the A.I.

A couple questions:
- How do these changes (and others being made) affect the overall A.I's decisiveness? I may be wrong but it feels like these last patches at least the friendly A.I. has been, in analogous scenarios, noticeably less willing to commit to an action than before (e.g. whether to siege province A or chase army B, or be in region A or B), resulting in much walking around but not much getting accomplished (e.g. ottomans at war with mamluks and doing multiple laps of the arabian peninsula). Im curious about the results of the changes to region assignment of armies and how it relates to this.
- How does the focus on homeland defense affect the willingness of friendly A.I. to invade relatively distant foreign lands in a big war (e.g. france going after bohemia or poland in a protestant league war)? Will it be far less common now?

Thanks for all the great work, keep up! :)