Anbeeld

Projects Articles Support Contact

Imperator: Invictus AI Dev Diary 1.9.2

Added law management, tribal reform, diplomatic stances, state investment, character loyalty, and economic policy improvements.

Filling in the missing pieces of AI

Hiya! Once again, Anbeeld there, continuing AI work described in the previous dev diary. In this patch I worked on a number of systems one could call less significant, but together they lead to quite an impact: laws and tribal reform, diplomatic stances, state investment, character loyalty, economic policies, and more. Let’s dive into it!

Wild West? Wild Gaul!

I’ll start with a confession. Not only am I a tall player, but I’m a tribe player. I love to build tribal utopias. I think Rome is beautiful for tourism. So naturally, I appreciate tribal laws, with how many of them are there and how impactful some of them are.

Tribal laws in Imperator: Invictus

But as it turns out, some players are not aware of tribal law’s existence at all. And first and foremost, I’m talking about all the AI countries in your games. This terrible realization struck me when I happened to check the law panel of various AI tribes, only to find out that it’s almost empty for all of them!

The horror didn’t end there. I started to dig deeper, and found monarchies and republics completely depending on rare occasions of laws changing in random parts of the code as their main source of directing the country’s course. This is where it became obvious to me.

Wow. There’s simply no system of AI enacting laws in the game. It doesn’t exist.

Empty AI law panels

Okay. No big deal. That’s why I’m here. I’ll just create one of my own.

Being a tribe enjoyer, unsurprisingly I started with their laws, which is a joy considering how much freedom they have with changing them left and right. As I mentioned before, their law panels were almost empty – there are some events with options to change laws, which were the only source of bringing law to tribal lands, most notably the one leading to widespread disease of Adopt Human Sacrifice.

AI tribal law management

Instead of AI ignoring these events, I decided to make them part of the bigger question of choosing centralization vs decentralization. For those who don’t know, tribes can go one of these two paths with their laws, each giving completely different benefits. Centralization leads to higher civilization, more research points and eventually the ability to reform into a monarchy or republic. Decentralization is all about staying as a tribe and dragging others into the mud, thanks to levy size and morale bonuses, as well as the ability to migrate with minimal stability costs.

Centralization vs decentralization law paths

At the start of the game every tribe has a certain centralization value. To keep things simple, I designed their law management in a way that most of the tribes will double down on it, going negative or positive all the way depending on the starting value. There are exceptions, of course, like tribes that start with 0% centralization. These will have a chance to go either path, thanks to the law events that I mentioned earlier and events that give ticking (de)centralization modifier, bringing in an element of randomness.

Tribal centralization progression

As most of these laws offer quite good bonuses, on average tribes will be slightly stronger now compared to their Wild Gaul version where they had almost no laws. Good news for civilized nations is that there are barely any direct military bonuses, it’s all about internals like income, happiness, stability and so on.

Unless we are talking Steppe Horde.

Steppe Horde military bonuses

Good luck for those in a way of a large horde. Until it collapses by itself, that is.

Tour de France with training wheels

As usual, such a drastic change led to even funnier things floating to the surface. Turns out, to compensate for AI tribes inability to found cities and enact laws, they had special decisions to reform into monarchy or republic with drastically lowered requirements compared to what players go through in the tribal reform mission tree. And now that they learnt to play properly, they abused it really hard.

AI tribes mass reforming exploit

Snowlet, the lead of the Invictus team, seemed somewhat unhappy about tribes mass reforming barely 100 years into the game. I love this guy, but he’s such a cold ice and constantly stops me from turning the game into Stellaris 2! Ugh.

So I fixed the issue by forcing the AI to meet all the same requirements as players do to reform the tribe, including stuff like ruler popularity and correct law corresponding with going monarchy vs republic. Some additional requirements were added as well, for example having a rank of at least regional power, to avoid AI countries looking like they are being played by an average OPM enjoyer.

Fixed tribal reform requirements for AI

In the end there are still tribes that reform naturally without help from cultural decisions and mission trees, but it’s more of an exception, which makes more sense historically than half of Europe turning into monarchies somewhere in 200 BC.

Just download more army, bro

While laws of monarchies and republics have much less going for them in the context of the AI, they too benefit from having an actual law changing system. Previously inventions that allow to enact new laws contained special effects for AI countries, where they would be forced to change towards them, because otherwise it would have never been done. This could lead to big problems with stability – if it happened to be already low by the moment of researching the invention, now after paying the price to change a law it’s gonna be put six feet under.

Stability issues with forced law changes

But in this new system stability is a key factor, and laws are only enacted when it’s high enough to not ruin the whole country by doing so, with thresholds varying depending on the importance of the specific law we’re looking forward to.

So after dealing with some funny things, like the monarchy.101 event apparently enacting Royal Army for every single monarchy that has the required invention, I managed to provide civilized AI countries with the logic for the most important law group, which is of course military reforms.

AI military law reform system

The main elements here are levy size and the ability to raise legions, so the AI will consider all the factors and choose what fits it the best. For example, a country that has most of its levy population inside the capital region doesn’t want a law that allows to raise legions outside of it, even if the country has the required invention, because it will lose the levy size bonus and thus its army will only get weaker.

Then there are military laws that are only useful as a part of a certain strategy, such as laws with mercenary bonuses, but we can’t rely on the AI making use of them, so instead it will prefer raw army numbers.

Me monarchy, me assimilate

Monarchies also have the very important Conversion Policy law group, unlocked with Proscribed Canon invention. It has insane value for any country with subpar cultural and/or religious unity, providing best in class bonuses for assimilation or conversion, depending on what law you’ll choose. The best strategy would be going for conversion first, as it’s a faster process overall, and then switch to assimilation – which is basically what I told AI monarchies to do.

AI monarchy conversion and assimilation policy

This can lead to countries like Diadochi states becoming proper raid bosses by the very late game, granted they won’t get smashed into the ground before it, as increased percent of integrated pops means higher stability and much larger army. Beware!

Diadochi states with integrated pops

Most other monarchy law groups are locked behind inventions. Some of them are just generally useful and thus AI countries will look to enact something in them after reaching the required invention, while others have drawbacks and again require some conscious strategy to make use of them, so the AI won’t bother with it.

As for republics, they have a fair share of law changes going on through events, which is why for them the system only touches military laws. Otherwise there could be conflicts, leading to losing stability without any value gained. Besides, while effects of republic laws are nice to have, there’s nothing comparable to the mighty Conversion Policy, for example. I may look into it a bit more in the future, but for now that’s how it goes.

Wanna some trade routes?

Another borderline shocking discovery I made is that not only AI barely uses state investment mechanic, but they also play darts with what exactly they will invest in. Literally! While usually there are at least some barebones conditions, for investments the AI weights looked like 1 and 1.5, like that’s it, just some number. This is no fit for state investments, where most of them are actually highly conditional – it’s only trade routes that you can spam and always gain at least something from it.

AI state investment with minimal weights

First I was forced to move all the logic around in the files, because it was glued to GUI, and there’s no proper way to control how often and under which conditions the AI presses the buttons you want it to press, in fact usually it prefers to ignore them. Just Paradox modding things.

Then the actual fun started, where I was making the AI realize that military investments help with fort limit and don’t do much otherwise, that you need some real overcrowding going on to make use of civic investments, that religious investments are only impactful when you have multiple built up cities, and on the contrary that trade routes are just good – so when in doubt, go for oratory investments.

AI state investment type selection

Then there is another layer of limiting how eager AI countries are to invest in their states. They should do it only if they have some otherwise unused political influence on their hands or there are free investments, but also I limited how much investments they can get by a combination of country government type and state population, so we don’t end up with small German tribes having dozens of them.

And it worked, I guess? Said German tribes don’t invest into city building slots anymore, instead spending their few investments towards more useful things. Small Greek states with multiple cities, on the contrary, are likely to get some of these religious investments, allowing them to construct more nice buildings. Finally, all of them are now united in thinking that investing in the capital state is good, so they could better develop it and import more strategic goods.

AI capital state investment

Oratory investment with its trade routes really is a base option for the AI, so with the balance shifting towards it, the average AI country will have slightly higher income thanks to higher numbers of both imports and exports. Unfortunately, I’ve met a harsh limitation there, as it turns out AI trading is very heavy on performance. Because of this oratory investments are allowed only if the state has some trade routes already from other sources.

On this note, I’ve also adjusted AI logic for country commerce policy. Previously every country above city state defaulted to Free Trade for export income, but now they actually check if they have enough exports to make use of it. If not, they will use Trading Permits for 2 more capital import routes, leading to another small boost in AI trading capabilities. Again, because of performance concerns this has the same limitations as described above.

Keeping inner demons at bay

If you are tired like me of re-adjusting your trade routes because Carthage has a civil war again, you’ll love this segment. Inability of the AI to press these shiny “fix loyalty” buttons finally got me, so they received some lessons here as well.

AI countries were pretty ok at bribing people already, although it looked like they did it without a specific idea. But when more drastic measures were needed, they couldn’t do anything, falling into civil wars they could easily avoid. Turns out, they were not paying political influence for bribing and persuading! Life definitely gets easier when you cheat the system like this.

AI cheating on political influence costs

When I started to write my own AI logic for fixing loyalty, this became a big issue, as I needed to make up some random rules for them to not exploit this free bribing left and right. We decided to remove the cheating, because combined with improved decision making this could lead to overly high internal stability, and the need to pay political influence is an important factor by itself for designing the logic.

Now the AI is not only capable of making bribes just to keep loyalty at a decent level, but is also well equipped to combat civil wars. If bribes are not enough, free hands will be given – and revoked somewhere in the future, with governors having strict limits on corruption due to its impact on province loyalty. Where everything else fails, subsidies will be given to families, granted there’s enough gold in the treasury.

AI loyalty management improvements

This doesn’t mean AI countries won’t have civil wars. While they are now better at dealing with disloyalty, I haven’t touched anything regarding what causes it, like improper management of offices and power base in general. And that’s completely fine – the government is often a synonym of corruption and incompetence, no reason to make it different here.

We also added some additional limitations to avoid AI countries being too stable. For example, none of the loyalty fixing can be applied to rivals of the current ruler, unless there’s stuff like the country facing an existential threat. In some cases this will result in civil wars, but this time – as the result of an actual political struggle, instead of any light breeze and the AI just not pressing the buttons for no reason as it was before.

The school of diplomacy

Another system that saw some improvements is diplomatic stances. We’ve adjusted the balance between them and added new modifiers in this patch, so it must be important to make the AI aware of these changes, isn’t it?

In vanilla every stance has its AI weight increased or decreased by small values under many different conditions. For me it looked shaky, with potential for close or even equal weights leading to switching back and forth. I reworked it into exclusive logic with a bit more elaborate, but still simple decision making. Now at any given moment the AI may want only one specific stance, and there are buffers in action to prevent it changing way too often.

AI diplomatic stance improvements

High AE and is not attacking anyone? Appeasing until low enough.

Big war? Bellicose for lower war goal costs and AE impact.

Going really hard on subjugating other countries? Domineering.

Low on diplomatic relations or political influence? Neutral.

Old good money printing? Mercantile.

What a national idea!

For a long time there was a belief that we can’t control which nationals ideas the AI would pick, as no syntax was provided for that in the corresponding files. That is, until I semi-randomly tried to use the same syntax as we have in other systems… and it worked.

After realising this we discussed what national ideas would serve AI countries better, and implemented this in the form of AI weights. Unfortunately, it seems that the AI doesn’t update the ideas over time, instead sticking to the ones it got after initial setup, and there’s no workaround we could find. A pity, considering that late game ideas are substantially stronger.

AI national idea selection with weights

Still, countries that changed their government type can benefit from this, as this process wipes one’s national ideas. Revolts start with them being blank as well, so civil wars can bring some fresh ideas to the table. Otherwise I just hope some way to fix this issue will be found in the future.

A few more bricks in the wall

As you can see, it’s nothing mind blowing. Some better law management, some smarter investments, a few civil wars prevented. But all this and other small fixes combined should further improve internal development of AI countries, so they could pose more challenge to you, the mighty player.

That’s it for today! Thanks for reading this one, and I hope to continue bringing you good news in the future.

Back to articles