• 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.

HOI4 Dev Diary - Performance and AI

Hello! I’ve been drafted from EU4 to fight in the trenches together with the HOI4 team for a month and give some support on AI and performance. So I’m here to talk about those.

AI

I’ve been mostly devoting my time into improving garrison orders to solve some really wonky cases that could happen. Like it placing two units on Magdeburg instead of Berlin letting the capital be completely exposed. But also focused on making the garrison work a lot better when you don’t have enough troops to cover every point in the order that needs it.

First I implemented a new tool for HOI4 to let us programmers visually inspect what the unit controller is up to.

capture(95).png

Province Weights

capture(96).png

State Weights


After that came the big task, rewriting garrison order and how it assigns units. There’s been a lot of issues here and you’ve probably experienced them from time to time. Shuffling, units prioritizing the wrong states or provinces, the list goes on.

So what did I do that is new. Instead of having the old logic setting up rules for where units should go I went with a thing I hate. Mathematics. The main difference is that each state will sort of calculate how “painful” it is to remove a unit from it now. This means as each state goes through this, they will be trying to find the least painful way to perform the garrison order and will eventually settle on a sort of equilibrium.

It’s given us a lot easier way to control where units should go in a garrison and where they end up will match a lot more in style of the weights you can see on the pictures above.


A thing that we have been planning to do for a long time and finally got around to is to allow a more flexible way to control how the AI plays. We use a system we call “Ai Strategic Plans” for this. Its essentially telling Ai to act a certain way when it comes to national focuses and priorities based on scripted conditions. To put that in english I am going to hand over to @Bratyn for some examples:

Some situations in which the new Strategy Plans have been useful is to ensure ‘compatible’ AI behaviour in the case of an ahistorical Germany. A lot of the AI behaviours for the major European powers has been based on the assumption that Germany remains fascist and causes mayhem in Europe. This means that AI Italy would usually see Germany as an ally, and that AI France would either always go with the United Kingdom (if historic mode was turned on), or be so unpredictable that it was problematic for planning out and predicting alternate history scenarios.

Using strategy plans, we have made these AI nations partly behave more logical to the changing world scene, and partly ensure that the player will always have a challenging playthrough. Going democratic Germany, only to get your only enemy (Soviet Union) end up at war with both the Allies and yourself, is not a very fulfilling playthrough. Instead, a new strategy plan will now load for France upon German completion of the “Oppose Hitler” focus. This delays their pick of which political direction to head into until we have more information from the German player, essentially a ‘holding pattern’.

  • If Germany revives the Kaiserreich and chooses “Focus on the True Enemy”, France is released from the holding pattern and will go with Britain, forming a counter-reaction to rising German colonialism. Essentially, in this playthrough not much will change other than Germany being unaligned rather than fascist. The war will likely develop in a similar matter (though not on a similar timeline), with one war with the Allies, and one war with the Soviet Union.

  • If Germany revives the Kaiserreich and chooses “Expatriate the Communists”, these communists will head to France and give them a communist drift national spirit. France is released from the holding pattern and will go communist, choosing to side closer with the USSR so that both powers can stand against the new Anglo-German alliance.
  • If Germany goes democratic, France is released from this holding pattern and will choose to Revise Versailles. Which direction they pick next is up to the AI, ensuring some unpredictability. France may go Communist and start their own faction, or join the Soviet Union, ensuring a two-front war if Germany goes to war with the USSR. Alternatively, the French may go fascist. They then will go for “Woo Italy”, creating a new semi-powerful Fascist faction in south-west Europe. Similar strategy plans for Italy (and liberal application of AI strategy values…) ensure this alliance is stable. A new focus for france “Dismantle the Democracies” becomes available if Germany is democratic, and the AI has a high likelihood of taking this when the Germans are already at war with the USSR. This makes gameplay more dynamic, and ensures Germany will have ample enemies to fight against even if they elected to go democratic.
We also used AI strategy plans to teach the Chinese AI how to handle the Inflation mechanic and do things like making the PRC AI keep the peace in China when they are going for the peaceful takeover through the political struggle. All in all, to myself and @Archangel85, this has been (and will continue to be) an invaluable tool for ensuring believable and, most importantly, fun playthroughs for each ahistorical path that one can take. We hope to continue building upon this basis and make nations ‘smarter’ in dealing with alternate history situations, or just general oddities that arise in the state of the world over the course of a playthrough.

Modders I am sure are going to like this a lot, so for you guys check out the example below for how it can be set up (regular humans without modding superpowers can safely ignore ;) ).

upload_2018-2-21_16-49-6.png


upload_2018-2-21_16-49-24.png

PERFORMANCE

Late game performance have always been a tough nut to crack for us on our games. For Cornflakes we rolled up our sleeves and got elbow deep into the code to improve it the best we could.

In order to measure performance and see where it goes bad to better pinpoint what causes the slowdown I write a little script that generates this super sexy graph for us.

capture(93).png


We did tons of neat little tricks to improve our performance. AI when it micromanages does a lot less pathfinding now. The game will automatically balance workload between cores depending on how long the hourly update took for a country, The fronts system has been a lot more streamlined to make it not hog performance

And we’ve done quite A good job at it as well. Here’s the result of our hard work just this week

capture(94).png


Between finding ways to make things more efficient and utilizing the cores on the CPU better we’ve gotten an overall improvement late game. We won’t rest there though, there’s tons more that we can do to make late game an even more enjoyable experience!



To conclude this Dev Diary, we have a reminder for you. Tune in for the first day of the Three Day War later tonight, 20:00 until 22:00 CET. Since the release of Waking the Tiger is approaching we have invited some of the grandest streamers to battle it out in multiplayer and show off the expansion as well as put the build to the test.


Quill18, Alex the Rambler, Marbozir, Enter Elysium, Solar Gamer, Spiffing Brit, Drew Durnil, The Prussian Prince, Bratyn, Da9L, Shen Plays and Jay’s Gaming will all be streaming their point of view in their own channels, and we’ll be hosting a main observer stream at the Paradox Twitch channel: https://www.twitch.tv/paradoxinteractive

Next week we are going to try and do a big recap of all the features and changes and also talked about a bunch of small stuff that hasn't fit into diaries so far. See you then!


Rejected Titles:
Droogies Quest For The Missing Core
Hoi4 Dev diary: Reverse the polarity of the deflector dish
Graphs are hot!
 
Last edited by a moderator:
Yes I think so. The changes I did was about where it places them and trying to prevent shuffling.

Do your tweaks also factor in the need for suppression and rising resistance in occupied countries?
 
I should note that I don't think it's at all likely for the AI Ethiopia to kick AI Italy out, one way or another, it would be due to player interference

Wasn't it a strategy back in the day in MP for the Soviet Union to send tanks into Ethiopia and fuck over Italy? Ooh... The good days in the summer of 2016 :rolleyes:, before Together for Victory got released and the tactics were plain and simple.. UK sends 90% of their equipment to India, Japan sends half of their army on Naval invasions, Axis keeps the world tension low, the Soviet Union conjures whatever they can to up the world tension so they can have the US join against the Axis, the Soviets boosting the low countries and Scandinavia on purpose so the UK can invade them... Oh the good times...

It seems nowadays people are playing MP on an Esports competitive scale, with rulebooks/Google docs the size of encyclopedia's.. I may misunderstand this, but this is how I experience it at leasto_O. I didn't dabble in the MP scene as I used to, but my last MP games were just Germany and other powers ordering me around to delete my army and focus on 1 kind of research, production and focus..
 
I should note that I don't think it's at all likely for the AI Ethiopia to kick AI Italy out, one way or another, it would be due to player interference

I have seen AI Italy come pretty close to losing that war. Besides, it would be very nice as a player if after you pushed Italy out of the horn the war ended instead what happens now, which is a long, long uphill slog until the Axis capitulates.
 
I would personally like that to be a possibility, still. While HOI4 is first and foremost a war game, I think a scenario in which all of the West fights against the Soviets shpld be on the table, still. Even if it is basically ‘easy mode.’

I don’t play these games solely for the challenge and balance - if I did, I’d play chess. I play to explore these various scenarios, and challenge is merely subordinate to that exploration.
They could solve it by giving the USSR some insane buffs in that scenario, so it would fight pretty much everybody like Germany did historically.
 
@podcat - I'm really impressed with everything we have seen regarding the upcoming DLC and update. It leads me to a question, though.

Is Paradox committed to getting HOI4 to the closest approximation of the ideal game for its genre or are/will you be working on an HOI5?
 
Because East Prussia has a port and Königsberg that is worth... 30 points I think? However the amount of units it needs to cover all of those is only one, so there is a super low pain to steal units from Prussia to another State. Why the coastal states have more weight is because of the Ports and the settings that was set on the garrison order. Since it was told to guard the ports with too few units it will try and focus on that first.

Thx for this one. Q: does the new garrison algoritm also fix the right focus for germany to be sure to suppress revolts in the qonquered states? Now a lot of industry is lost for the ai after attacking Russia.
 
My biggest issue with the AI, is that if you ally with them, they will notoriously overcrowd my airfields and most likely do nothing with their planes.

Also fighting on allied territory will make them flood the frontline and cause huge supply issues for me. And they don't even do anything there, even if I attack.

So this leaves me to constantly find a way to attack alone.
 
Question , have you fixed that bug that occured when Roamnia ceded Bessarabia and could give away Bukowina even if it owned by another state? This has alaways bugged in my A-H runs
 
Is Paradox committed to getting HOI4 to the closest approximation of the ideal game for its genre or are/will you be working on an HOI5?

This is a very interesting question. There are already ideas i would want to try in a HOI5 that are so different that it wouldnt be doable in a dlc so a HOI5 i can imagine one day for sure. It would be a different game just in the same way hoi2, hoi3 and hoi4 are all different (they also all had different lead designers so may not even be me doing hoi 5 once the time comes. who knows!)

As for hoi4 there are a ton of more ideas and ways i want to grow and improve it. At some point i will do a diary on some of that like we did after DoD
 
Does this mean I can finally get past 1942 and also run the game at 5 speed without it slowing down? THANKS FOR THE OPTIMIZATION!

As best I understand it, Speed 5 is "unrestricted" - so it's as fast as your system will allow, rather than a set speed (like speeds 1 through 4). In that context, given there's always less going on at the start than there is at the end, Speed 5 will always be slower later in the game when the engine has more to do (but more optimisation/better performance will make it run faster at a particular point in time, all else being equal).
 
Glad you were able to get this diary out.
 
a new strategy plan will now load for France upon German completion of the “Oppose Hitler” focus.

What about when Germany goes democratic via advisor rather than WtT events? Will it work the same way?
 
This is a very interesting question. There are already ideas i would want to try in a HOI5 that are so different that it wouldnt be doable in a dlc so a HOI5 i can imagine one day for sure. It would be a different game just in the same way hoi2, hoi3 and hoi4 are all different (they also all had different lead designers so may not even be me doing hoi 5 once the time comes. who knows!)

As for hoi4 there are a ton of more ideas and ways i want to grow and improve it. At some point i will do a diary on some of that like we did after DoD

You say its so different it couldn't be a DLC, but would you ever consider making a patch with the kind of game-altering mechanical changes we're seeing with Stellaris 2.0 in HoI4 if you believed it would lead to a far better game, even if it means alienating some players?
 
i hope the changed also the land routes or how AI handles them. or get extra option save travel ;-) . for example instead of unit go to bulgarie from turkey it ships them and wil go arround south afrika and follow spain english canal route. Germany i do not control the sea very good. insteat of using a land route. may be slower but a lot saver then losing all your high expensive build units in ships which are sinked.