PDA

View Full Version : Campaign/Diplomacy AI



nikolai1962
11-19-2007, 23:20
Thought I'd start a thread on this as I'm currently messing with it.

Will post anything I come up with.

edit: removed first point until i get a chance to retest :)

~~~~

Lots of very useful info on this subject in this link posted by CavalryCmdr

http://rtw.heavengames.com/cgi-bin/forums/display.cgi?action=ct&f=9,6718,,10

(only a couple of posts down but wanted to stress the value :) )

nikolai1962
11-20-2007, 00:59
Second thing...

May be obvious to people but just in case it isn't--if you want a faction to start as a vassal of another faction then you can rig the campaign AI file to make them do it in the first turn.

Say you wanted milan to be a vassal of hre for example.

1. Make a copy of the "catholic" profile in the campaign AI file
2. Rename it "catholic_milan"
3. Assign milan the ai_label "catholic_milan" in the strat file.
4. Add this clause at the top of the "catholic_milan" profile's <defend decisions> bit.



<decision_entry>
<min_entry stance="AtWar" target_faction="hre"/>
<max_entry stance="AtWar" target_faction="hre" turn_number="4"/>
<faction_attitude want_peace="true" want_be_protect="true" defense="defend_deep"/>
</decision_entry>

4. Repeat the process for hre, copy the catholic profile, rename the copy and assign it to hre.
5. Add this clause to the top of the new "catholic_hre" profile's <attack decisions>



<decision_entry>
<min_entry stance="AtWar" target_faction="milan"/>
<max_entry stance="AtWar" target_faction="milan" turn_number="4"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" want_offer_protect="true"/>
</decision_entry>

6. Start hre and milan at war.
7. Make sure there's no milan diplomats around.
8. Start an hre diplomat next to milan
9. Job done.


edit: The order in which the two factions move may matter. The faction you want to be a vassal needs to have one turn to process their decison entries and decide they want to be a protectorate. So if the boss faction moves first their diplomat will be turned down on turn 1 (turn 0 in the code). Not sure if that would affect things. If you want it to definitely happen on the first turn then the "vassal" faction has to have their turn first.

CavalryCmdr
11-20-2007, 06:21
Finally, someone elts doing and posting proper research on this subject. I've been searching all the forums for info on this for quite some time and have made alot of progress myself. I have a sticky at TotalWar Haven that contains information you may find helpful, but this thing tells me I cant add a link until after I've made one post already, so I'll try again.

CavalryCmdr
11-20-2007, 06:29
M2TW AI Modification: An Interactive Essay (http://rtw.heavengames.com/cgi-bin/forums/display.cgi?action=ct&f=9,6718,,10)
There, now I can link it.

Anyway, all this is relevent to M2 1.2 but not been updated to Kingdoms as I dont own it yet.

If you want to see my research in action there is a link in my sig on that site to my Medimod. As I have only dial-up I am unable to download/upload large files, so Medimod is quite small.

nikolai1962
11-21-2007, 04:19
@CavalryCmdr

*Very* useful info. I'll add your link to the first post. Thanks a lot. I'll check out your mod too to see what you've done.

~~~

3rd Thing.

The conditions like "strongest_neighbour" in the campaign ai file seem to glitch when the target faction's regions are split up.

Example: I had all the catholic factions set up to want to ally to their strongest_neighbour if catholic at game start. Milan and Venice allied with HRE as expected but not Sicily and Hungary. Took me a while to realise this was because neither Sicily nor Hungary border all the HRE's region groups whereas both Milan and Venice do.

Diplomats from Sicily and Hungary did both move to an HRE city (and stayed there) but no alliance was made.

Just an odd thing that may be relevant in some situations.

~~~

4th Thing.

descr_faction_standings

The "Forgiveness" event that supposedly triggers for "each" 100 florins given to a faction seems to only trigger once per event. So giving 4000 has no more effect than giving 100.

The GiveMoney event works fine if it is a single payment but if it is part of a regular tribute then it seems to double-count in some way such that giving 4000 as a single payment has a much lower effect than a tribute of 1000 for 4 turns. There's almost an exponential efect involved which messes me up quite a bit. Most annoying.

CavalryCmdr
11-21-2007, 05:01
Another point I think I left out in my essay post, there is a bug where if the AI attempts a forced invasion (Naval at least so 'forced' is more a guess) and a standard invasion from and to the same regions all invasions are cancelled. This is why if you look at the ai_db in Medimod you will see a strange entry...


<decision_entry>
<!--
cancelation of invasions override
-->
<min_entry is_neighbour="true" borders_all_our_regions="true"/>
<max_entry is_neighbour="true" borders_all_our_regions="true" num_settlements="3"/>
<faction_attitude can_force_invade="false" continue="true"/>
</decision_entry>
I have set a max number of settlements because it almost never happens with larger factions. Strangely it also seems not to happen if they have multiple settlement blocks (borders_all_our_regions.)

This also brings up another interesting phenomenon (aka bug) wherein somehow it is posible on occasion for borders_all_our_regions to be true when the two in question are not even neighbors. Thus my use of both.

nikolai1962
11-21-2007, 05:33
This also brings up another interesting phenomenon (aka bug) wherein somehow it is posible on occasion for borders_all_our_regions to be true when the two in question are not even neighbors. Thus my use of both.

Haven't noticed your first thing but the second fits in with a theory of mine. From looking at map path-finding problems it seemed to me the game can glitch on map.rwn creation. Some regions that are adjacent don't seem to be recognized as such. A consistent (I think) clue that this has happened is when a faction mounts a naval landing against an adjacent land region e.g scotland landing in York on the vanilla map.

More relevant to your point is I don't think all naval landings are forced. I think some coast->coast, coast->island etc paths count as neighbours, but only a few. Not sure if the cases you mentioned were coastal ones or interior ones.

Up until recently i've mostly been wrestling with the AI's map problems and I had an "attack rebels only" AI profile. There were only two invade decisions:

if slave faction: is_neighbour, attack immediate, force_invade=false

and

if any other faction: invade_none, force_invade=false

Interestingly some naval landings still happened e.g Tunis->Sardinia when the moors took Tunis. Sicily went Naples->Durazzo but otherwise never did their usua naval landings. So i think where the naval paths exist they count as neighbour and don't require a forceinvade but CA added a few forced naval landings in specific places where they weren't happening but were needed e.g Sicily.

Maybe.

Maybe some other reason.

CavalryCmdr
11-21-2007, 07:09
The problem I've had with invasions being cancelled happend multiple times, if you run the LTGD log for say a 10 turn stretch it would happen say 3 times total. The only one I particularly remember nailing down the cause was Venice attacking Durazzo from Ragusa. So you could be right that it was infact two normal invasions attempted by the same army via diferent routs, which would also explain why it would cancel all invasions, the AI 'got confused.'

It would show up in the LTGD log as
LTGD: invasions cancelled this turn. as the very last entry for that faction after naval invasions and global modifiers (which I have set to 0)

It is posible it is a bug created by my rather unique format wherein the AI is actually told to attack everyone, invade_priority is then based on a number of individual factors, the AI will then plan invasions on it's higher priorities based on resources available. This allows a suprisingly flexible though (for now) rather unstable AI capable of effectively fighting multi-front wars, multiple coordinated invasions against a single opponant, even multi-faction coordinated invasions of a single opponant. Major problem I'm having at the moment is that want_peace cannot be assignd a numerical value.


The problem with alliance_against, I just discoverd on revewing some recent work, is that it is comulative over multiple turns, or decision runs. So a condition that has 'alliance_against="1"' over the course of 5 turns would result in a 5, add any multiple runs for a single turn (alliances made, wars declared, peace accepted, etc) and you can have the number jumping 10 or more points in five turns from a single decision entry giving a value of one. I've not seen any other vaues carry over in this manner, though I strongly suspect 'pts_alliance' which oddly dose not show in the LTGD log.

Lusted
11-21-2007, 18:00
With alliance_against, i found in my AI which i based off of vanilla but heavily modded, i had to add in a decision entry to give negative points for alliance_against v slaves because otherwise i was seeing loads of early game alliances which i didn't want.

And i also added in quite large negative pts_alliance values for catholic decisons on islamic factions and vice versa to reduce the number of alliances they make, but they still do it against common enemies etc.


It is posible it is a bug created by my rather unique format wherein the AI is actually told to attack everyone, invade_priority is then based on a number of individual factors, the AI will then plan invasions on it's higher priorities based on resources available.

I could definitely see something like that causing problems if you're telling the AI to attack everyone and then modifying the AI priority from there. I've had a bad enough time just trying to sort out the AI after adding continue="true" to the vanilla AI and then adding in some decision entries, let alone doing the major changes you have in your AI file.

alpaca
11-21-2007, 20:58
I had a weird "invasions canceled" case when testing a minimal AI flavor (only attack rebels immediately, defend fortified) without providing at_war in the faction attitude for the rebels. Basically, the factions in question would not attack at all if you don't use at_war in the slave defend decision

CavalryCmdr
11-22-2007, 00:18
I will happen occasionally, but I've never known them not to attack at all. Regardless, I also use a simple check at the begining of defence decisions;


<decision_entry>
<!--
At war call
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude continue="true" at_war="true"/>
</decision_entry>
Though this is more to help num_enemies be more consistant.

nikolai1962
11-22-2007, 05:44
Lusted With alliance_against, i found in my AI which i based off of vanilla but heavily modded, i had to add in a decision entry to give negative points for alliance_against v slaves because otherwise i was seeing loads of early game alliances which i didn't want.

And i also added in quite large negative pts_alliance values for catholic decisons on islamic factions and vice versa to reduce the number of alliances they make, but they still do it against common enemies etc.

The negative "pts_alliance" thing is useful to know. I'd stopped using "alliance_against" because you can get silly alliances forming.


CavalryCmdr The problem with alliance_against, I just discoverd on revewing some recent work, is that it is comulative over multiple turns, or decision runs.

Useful to know.


Alpaca I had a weird "invasions canceled" case when testing a minimal AI flavor (only attack rebels immediately, defend fortified) without providing at_war in the faction attitude for the rebels. Basically, the factions in question would not attack at all if you don't use at_war in the slave defend decision

I had that with my first "attack rebels only" testing profile. Had to add "atwar=true" to the decision. Odd. Forgotten about that.


CavalryCmdr The problem I've had with invasions being cancelled happend multiple times, if you run the LTGD log for say a 10 turn stretch it would happen say 3 times total. The only one I particularly remember nailing down the cause was Venice attacking Durazzo from Ragusa. So you could be right that it was infact two normal invasions attempted by the same army via diferent routs, which would also explain why it would cancel all invasions, the AI 'got confused.'

Does fit my more observational experience. There's a lot of odd things going on with naval landings. A few of the naval paths are perfectly smooth and don't require any help i.e they happen even with force_invade switched off e.g Tunis->Sardinia, Denmark->York (i think those are two of them it's been a while since i tested this) and then a bunch of others that don't happen unless force_invade is switched on. It's definitely easy to imagine how a forced invasion might interfere somehow with the campaign AI's processing.

You can (sometimes) create the smooth kind of naval landings by accident or trial and error by moving towns/ports around but it i've never managed to pin it down. Monkwarrior (i think) had a theory it was related to the closest region in a direct x or y direction which i think may be true but with some other factor involved, related to the town/port location i assume.

nikolai1962
11-22-2007, 06:07
Couple of minor things reminded of a thread question elesewhere:

1. in descr_faction_standings there's a "religion catholic" condition. Contrary to my and i imagine most people's assumptions "religion orthodox" and "religion islam" aren't implemented but you can use stuff like factions { russia, byzantium } instead for the same effect.

2. There's a factionstanding command in descr_faction_standings.txt and a FactionStanding condition in the docudemons. For probably obvious reasons it doesn't seem like the condition works in triggers in descr_faction_standings.txt. The GlobalStanding condition works.


~~~


CavalryCmdr Another point I think I left out in my essay post, there is a bug where if the AI attempts a forced invasion (Naval at least so 'forced' is more a guess) and a standard invasion from and to the same regions all invasions are cancelled. This is why if you look at the ai_db in Medimod you will see a strange entry...

Thinking about it more I think i have seen that hundreds of times but put it down to a path-finding glitch. Would possibly explain a common problem with naval landings especially those where a faction makes a landing on a region they are actually adjacent to but don't seem to realize they are.


So i think where the naval paths exist they count as neighbour and don't require a forceinvade but CA added a few forced naval landings in specific places where they weren't happening but were needed e.g Sicily.

Quoting myself here. Just wanted to clarify I don't mean that some coast/coast, coast/island paths would fit an "isneighbour=true" condition in the ai file just that they are a kind of halfway "sea neighbour" and the AI behaves a bit differently with them.

CavalryCmdr
11-22-2007, 06:49
Just wanted to clarify I don't mean that some coast/coast, coast/island paths would fit an "isneighbour=true" condition in the ai file just that they are a kind of halfway "sea neighbour" and the AI behaves a bit differently with them.
Ah, there are times when is_neighbour="false" but borders_all_our_regions="true" according to the LTGD log, and indeed apears to act accordingly. Do you think this is caused by these 'semi-border' regions? I suppose why is more just a curiosity as we really cant do anything about it except to include is_neighbour="true" with any borders_all_our_regions="true" decision entry.

nikolai1962
11-22-2007, 06:56
Interesting thought now you mention it. Sounds possible.

I really need to get into this log business instead of just guessing what is going on.

Trying to recall the vanilla region-pairs that had "automatic" naval landings. IIRC Stockholm->Stettin was one, Denmark->York, Tunis->Sardinia, Crete->Rhodes, umm... been too long since i was using the plain vanilla map. (nb they don't always go both ways so that adds another complication.)

Something to ponder.


I suppose why is more just a curiosity as we really cant do anything about it except to include is_neighbour="true" with any borders_all_our_regions="true" decision entry.

Not sure. Personally I don't really like land-bridges so if it was consistent in the ai file and you could create a "semi-neighbour" naval path for say, asia minor to constaninople, then you could use those conditions to give a higher priority in those cases instead of say, the turks, taking the long land route round the black sea.

Not that there's anything wrong with land-bridges i just like to see the AI doing naval stuff.

CavalryCmdr
11-22-2007, 07:43
Not sure. Personally I don't really like land-bridges so if it was consistent in the ai file and you could create a "semi-neighbour" naval path for say, asia minor to constaninople, then you could use those conditions to give a higher priority in those cases instead of say, the turks, taking the long land route round the black sea.
Ah, so it could actually be usefull to use is_neighbour="false" and borders_all_our_regions="true" in decision entries; if these semi-border reagions are in-fact responsible for that occurance.
I'll keep notes on when, exactly, I see this occuring. Though I tend to read the log at 10 turn intervals or when something specific happens I'm trying to eliminate or reproduce, so it's sometimes hard to know what reagions were involved. I dont really think this is important enough to really dedicate research to atm, maybe if I get bored.

A little something I've noticed but not really worked with, I'm sure most have noticed this one already.
In descr_regions.txt there are some hidden resources regarding guilds. In those setlements the AI will usually build that guild while all settlements without a guild resource usually get the thieves guild. Basically I'm wondering if those hidden resources work as a flag for the AI.

nikolai1962
11-22-2007, 08:28
Ah, so it could actually be usefull to use is_neighbour="false" and borders_all_our_regions="true" in decision entries; if these semi-border reagions are in-fact responsible for that occurance.
I'll keep notes on when, exactly, I see this occuring. Though I tend to read the log at 10 turn intervals or when something specific happens I'm trying to eliminate or reproduce, so it's sometimes hard to know what reagions were involved. I dont really think this is important enough to really dedicate research to atm, maybe if I get bored.

Same here. Now you've made me think it's possible I might look into it more if/when i get round to removing to removing the land bridges. Assuming i can make the replacement naval paths of course which is iffy.




A little something I've noticed but not really worked with, I'm sure most have noticed this one already.
In descr_regions.txt there are some hidden resources regarding guilds. In those setlements the AI will usually build that guild while all settlements without a guild resource usually get the thieves guild. Basically I'm wondering if those hidden resources work as a flag for the AI.

I'm sure they do. I think the reason the AI gets so many thieves guilds is cos they spam spies. I have agent limits on everything so they only get one spy per town. Haven't actually checked if that made a difference though.

Also, recently added (but not tested yet) putting assassin_city, merchant_city etc on the starting towns for egypt/byzies to control their agent recruitment and hopefully get them to get the specialist guilds. Which i thought was a nifty idea (if it works).

CavalryCmdr
11-22-2007, 09:05
I have agent limits on everything so they only get one spy per town.
Ofcourse, I cant belive I hadnt thought of that, I knew the cause.


Also, recently added (but not tested yet) putting assassin_city, merchant_city etc on the starting towns for egypt/byzies to control their agent recruitment and hopefully get them to get the specialist guilds. Which i thought was a nifty idea (if it works).
I must be missing something, if they are flags the AI is then programmed to look for them, so you wouldnt be able to just make-up flags for it. Are you using these to increase the agent limit, for example a building that would require these hidden resources?
However I would say adding 'merchants_guild' is likely to be recognized as a flag though it dose not appear in the vanilla descr_regions but other _guilds are, so perhaps they made a flag for all of them.

These hidden resources also have the same name (exactly, minus the guild_ at the begining) as the building tree name for that guild (as per export_descr_buildings.txt) I'm wondering if the AI is, instead of programmed to look for 'guild flags,' will recognize any building tree name and increase the priority for that building in that settlement, though I suspect most likely (as the name dose not include the guild_) that it will only work for guilds.

I'll definately be experimenting with this tommorow.

Lusted
11-22-2007, 10:09
The main reason the AI spams thieves Guilds is because of how easy they are to get, i modified the Guild file so now the AI and player see a more varied amount of Guilds which i achieved by changing the amount of points recruiting various agents and units gave, and by making it so that when a guild of a particular type is built, the overall faction score for that Guild is lowered in order to reduce the chances of more of the same Guild being built.


The negative "pts_alliance" thing is useful to know. I'd stopped using "alliance_against" because you can get silly alliances forming.

Well with my file i've now got it so factions generally ally against common enemies or against strongest neighbours, the only slight wierdness in it is the amount of catholic and islamic alliances which i could probably solve by increasing the negative pts_alliance value for the decisions i've set up to make those factions not want to ally.

uanime5
11-22-2007, 13:17
One thing I've noticed about M2TW is that the AI acts a lot like it did in MTW.

In MTW the AI would have most of it's army guarding a province and some guarding the settlement. This made sense since when you entered the province you automatically had to fight the AI army in the province and if you won the army would retreat to the settlement, giving it a larger force to defend the settlement (should you attack it). However in M2TW the player can avoid enemy armies in the province and attack the settlement directly. Thus the AI's tactic of sending out most of it's army to guard the province works against it.

Any ideas about how to make the AI to keep its soldiers garrisoned unless they want to attack a faction.

CavalryCmdr
11-22-2007, 15:13
which i could probably solve by increasing the negative pts_alliance value for the decisions i've set up to make those factions not want to ally.
Indeed, that will work provided you do not allow the alliance_against value to get too high.

One thing I've been wondering is if the pts_alliance value holds any sway when an AI faction is forced to chose between allies? With it not showing on the LTGD it's hard to say.


Any ideas about how to make the AI to keep its soldiers garrisoned unless they want to attack a faction.
It can be done usnig defend_fortified then disabling forts. Acceptable in vanilla IMO, but, with a little work, it appears forts can be considerably more usefull with the kingdoms.exe. Ironically, the AI is not too bad a fort placement, so they did consider that when they failed to consider so much about the campaign map, this also makes this option less desireable.

Lusted
11-22-2007, 15:21
Indeed, that will work provided you do not allow the alliance_against value to get too high.

That's the difficult thing. I likehaving the AI form alliance blocks against common enemies, but i want to limit how much Islamic and Catholic factions ally which proves difficult when they have common enemies that it is sensible for them to ally against.


It can be done usnig defend_fortified then disabling forts.

Yeah defend_fortified without disabled forts can result in some interesting AI garrisons, but still overall better garrisoning by the AI compared to vanilla. I've been watching a war in the latest campaign in my mod with interest given the big stacks the AI is using to invade and defend settlements with.

CavalryCmdr
11-22-2007, 19:13
That's the difficult thing. I likehaving the AI form alliance blocks against common enemies, but i want to limit how much Islamic and Catholic factions ally which proves difficult when they have common enemies that it is sensible for them to ally against.
I'm going to script alliances to last 10 turns rather then indefinate and see how the AI handles that. It's an easy, but long, script so it will take me awhile to finish it.


Yeah defend_fortified without disabled forts can result in some interesting AI garrisons, but still overall better garrisoning by the AI compared to vanilla.
Major problem with not disabling forts is that AI armies tend to get stuck inside the fort. Highly annoying when you capture thier last city with a full-stack army three steps away just sitting there watching. This can be helped with changing defend types, depending on different situations, particularly switching to frontline when ready to attack and deep when very weak, but it still happens occasionally.

nikolai1962
11-23-2007, 07:10
The merchant_city, assassin_city for the byzies was to add to their recruitment line in the EDB so they'd specialize their agent recruitment in particular cities and maybe beat the player to the guild HQ for once. But Lusted's idea seems like it may work better.

~~~

Update on post #5 point:

GiveMoney seems to trigger ten times a turn when it's regular tribute.

~~~

other people may have noticed this ages ago but i only noticed it recently. Your power rating label (supreme, weak, average) on the diplomacy screen effects what the AI will offer for trade rights etc. If you have a high power rating they generally offer something in exchange for trade rights. If you're weak they're more likely to demand payment for trade rights. Doesn't seem to be relative to their label just yours. Alliances increase it.

May be of interest as it probably affects a lot of things diplomatically. Especially so as your modding may have changed how likely it is for factions to be one thing or the other. For example in mine i have cheap units but low recruitment so the armies are quite big at the beginning and most of the factions counted as supreme quite early even though they were actually still quite weak. I've increased the points for each label in the descr_diplomacy.xml so there is more of a spread between the factions and the more powerful factions are percieved as such.


~~~


LustedThat's the difficult thing. I likehaving the AI form alliance blocks against common enemies, but i want to limit how much Islamic and Catholic factions ally which proves difficult when they have common enemies that it is sensible for them to ally against.

It was the excessive catholic-islamic alliances early game that put me off alliance_against. I'm doing alliances by how much the factions like each other now as you can control that a lot more with all the faction_standings triggers.

~~~

Definitely need to try that defend_fortified thing.


~~~


CavalryCmdrThese hidden resources also have the same name (exactly, minus the guild_ at the begining) as the building tree name for that guild (as per export_descr_buildings.txt) I'm wondering if the AI is, instead of programmed to look for 'guild flags,' will recognize any building tree name and increase the priority for that building in that settlement, though I suspect most likely (as the name dose not include the guild_) that it will only work for guilds.

I'll definately be experimenting with this tommorow.

Haven't done much with guilds yet but i recall reading a very informative tutorial on them somewhere. Worth looking for if you haven't come across it already.

uanime5
11-23-2007, 19:37
It can be done usnig defend_fortified then disabling forts. Acceptable in vanilla IMO, but, with a little work, it appears forts can be considerably more usefull with the kingdoms.exe. Ironically, the AI is not too bad a fort placement, so they did consider that when they failed to consider so much about the campaign map, this also makes this option less desireable.

Are there any guides on how to edit defend_fortified and siable forts? Alternatively are there some ready made files I can download that will do this for me?

CavalryCmdr
11-23-2007, 21:53
Are there any guides on how to edit defend_fortified and siable forts? Alternatively are there some ready made files I can download that will do this for me?
defend_fortified as a defend decision in descr_campaign_ai_db.xml, the closest thing to a guid I know of for that file is the link on the top post.

Easiest way to disable forts that I know of is to edit descr_cultures.txt

fort_cost 500
to say

fort_cost 100000 Thus making forts cost 100000. Just remember each culture has a seperate fort_cost line.

As for ready made files, Medimod 0.9 uses that method.

nikolai1962
11-27-2007, 03:26
Prompted by a question in a thread.

If you want factions to have a marriage alliance from the start of the game:

1. Have a decision entry that makes the factions want to ally, in mine i currently have:


<decision_entry>
<min_entry stance="Neutral" target_religion="catholic" is_neighbour="true"/>
<max_entry stance="Neutral" target_religion="catholic" turn_number="12" trusted_ally_enemy="false" target_is_shadow="false"/>
<faction_attitude can_force_invade="false" want_ally="true" pts_alliance="1"/>
</decision_entry>

This makes all the catholic factions want to ally with any neighbouring catholic faction up to turn 12 (while they're rebel-bashing).


2. Start princesses close to settlements of the faction you want the marriage alliance with.

3. Make sure the factions don't have any diplomats nearby to make the alliance.

4. Should get a marriage alliance.

Alternatively if you just want two specific factions to do this then use the method in post #2 and make separate profiles with a specific entry.

The princess should be within one turn away from the target faction in case their heir gets a marriage offer straight away. Probably best if you use a princess from the faction that moves first to ensure the target faction's heir doesn't get a marriage offer before the princess can move.

nikolai1962
11-27-2007, 09:57
AI army merging.

Problem: AI not merging their armies and particularly the times when they have lots of little stacks all standing round close together not doing anything.

Been trying to figure this out for my defensive AI profile, in particular looking at the the problem in light of two of the points CavalryCmdr makes in his page (listed above) viz

1. The attack and defend decisions needing to be in sync
2. The AI needing a point to mergo on e.g if it's defending it's frontline it needs to have a frontline (explained below)

Currently using defend_deep as the basis for testing the merging--may not be the best choice overall but it is fine for just testing this aspect.

Had three bits of progress (I think)...

1.
The AI is set to always be defend_minimal to the slave faction but various other things to the other AI factions depending on circumstances. In my simple profile it was initially either defend_deep if at peace and defend_frontline if at war.

I found the AI merging quite nicely as they expanded against neighbour rebels but going into multi-stack mess mode when they'd taken all the rebel regions and were still at peace with all their neighbour factions.

Because they were still at war with the non-neighbouring rebel regions they were still at defend_minimal towards the slave faction while being set to defend_deep with their neighbouring factions.

Changing the defend decison towards the slave faction to be the same as the other AI factions seemed to make the AI merge much better in those situations as they are in the same defense mode for all factions including slave. In my case that meant making the defend decisions towards the slave faction being defend_frontline if a neighbour and defend_deep if not, so the AI faction being processed was defend_deep to everybody in that case.

2.
The merging would also go wrong during crusades. In my simple AI profile I originally just had defend_frontline when at war but the AI usually won't have a frontline during crusades/jihads so i think that confused it. Adding a second decison so it was defend_deep when at_war but not a neighbour, and defend_frontline when at_war with a neighbour seems to have fixed that.

3.
There was also a third case more specific to my mod but another example of the attack and defend decisions being out of sync.

I'd set the AI to normally be defend_frontline when at war but to switch to defend_deep when they wanted a ceasefire (as a visual clue when playing). I also have very tight agent limits and few towns so there aren't many diplomats. So often what would happen is an AI faction would go into want peace mode and defend_deep but their single diplomat was on the other side of the map. So the faction would have defend_deep set in the defend decisons but still have invade_immediate or something in the attack decisons because they were still at war. This usually made them go into multi-stack mess mode.

Not sure how i'll fix that in mine but it is another example of how, if the attack and defense decisions don't fit together then the AI gets confused and they don't merge their armies.

~~~

Currently with defend_deep and everything in sync the AI is merging very nicely most of the time except when case 3 arises. They also seem to always keep a very big garrison in their capital--which is a nice improvement.

The improved merging may not even be because of the defend_deep bit, it may just be that now the decisons are in sync the AI isn't getting confused as much. I'm going to try setting them to be all defend_normal or something else just to see if it's the being out of sync that messes it up more than which actual defend decision it is using.

~~~

Also the AI sometimes seems to get confused when their group of regions got into a weird shape e.g in my test the english AI expanded right through the centre of the french regions so the french regions ended up in a kind of U shape. That seemed to confuse the french AI a bit, which is sort of understandable as you could see how that might make it hard for the AI to know what central point to defend.

~~~

Also, high brigand spawns made it merge a little bit less effectively as the individual mini-stacks would be chasing rebels instead of merging. I think most mods reduce the brigand spawn rate so that is probably only a minor thing.

~~~

A separate minor thing (maybe not minor in some situations)

If you start two factions at war they aren't counted in the num_enemies entry used in the campaign AI, (can't remember if CavCmdr mentioned that in his page or not). Might affect some things. Possibly why you have to have the "at_war"="true" bit with the slave faction.

CavalryCmdr
11-27-2007, 15:41
There was also a third case more specific to my mod but another example of the attack and defend decisions being out of sync.

I'd set the AI to normally be defend_frontline when at war but to switch to defend_deep when they wanted a ceasefire (as a visual clue when playing). I also have very tight agent limits and few towns so there aren't many diplomats. So often what would happen is an AI faction would go into want peace mode and defend_deep but their single diplomat was on the other side of the map. So the faction would have defend_deep set in the defend decisons but still have invade_immediate or something in the attack decisons because they were still at war. This usually made them go into multi-stack mess mode.

Effectively you need to link invade and defend decisions, using the same triggers as the 'defend deep' when wanting peace, switch invade to 'buildup,' 'start,' or even 'none.' This should (mostly) solve the small army issue. Invade decisions will overide defend, so the AI is attempting to follow it's invade orders without an intermediate merge point (such as 'frontline') so the armies have no reason to merge until they reach thier goal. Changing the invade to one of these three leaves only the defend target point, so the AI's armies wil merege there instead.

Lusted
11-27-2007, 15:47
That's something i did with my AI - have a defend decision for every invade decision and vice-versa, so that the AI builds up better. Though i think that's got slightly out of sync with recent changes i've made.

Also, nikolai, have you managed to make your AI aggressive whilst using defend_deep?

nikolai1962
11-28-2007, 04:23
Effectively you need to link invade and defend decisions, using the same triggers as the 'defend deep' when wanting peace, switch invade to 'buildup,' 'start,' or even 'none.' This should (mostly) solve the small army issue. Invade decisions will overide defend, so the AI is attempting to follow it's invade orders without an intermediate merge point (such as 'frontline') so the armies have no reason to merge until they reach thier goal. Changing the invade to one of these three leaves only the defend target point, so the AI's armies wil merege there instead.

Lol. I ran the test a few more times and was about to attempt to edit my post with a half-understood version of this :)

The above explanation is much clearer.

nikolai1962
11-28-2007, 04:37
That's something i did with my AI - have a defend decision for every invade decision and vice-versa, so that the AI builds up better. Though i think that's got slightly out of sync with recent changes i've made.

Also, nikolai, have you managed to make your AI aggressive whilst using defend_deep?

Hard to say exactly as I'm coming at this from a slightly different direction as I'm trying to perfect a very defensive AI profile. Basically I want 3/4 of the AI factions to very risk-averse at any one time. I want them to have big merged stacks that patrol their terriotory and watch over their core cities and I want them to only fight short little wars that don't leave their core cities undefended. So i'm actually trying to make them less aggressive. Most of my decison entries are a big list of reasons "not" to attack :)

On the other hand they do take the rebel regions in a reasonable time (mostly). I have them set to defend_frontline with adjacent rebel regions and invade_buildup which seems to work ok as a pair.

edit: Actually this might be something. The "frontline_balance" number is pretty wacky so maybe the game does calculate it based on armies in very close proximity to the actual border. In that case if the attack decisions were heavily influenced by the frontline_balance then it would make the AI very passive with defend_deep. My attack decisions are based on how much they dislike the target faction so that may be why it doesn't seem to affect them. Mine are currently just defend_deep until the "dislike" threshold is reached then they attack.

ps not saying defend_deep and defend_frontline are the best choices--they are just the ones i chose initially to try and test the merging as i wanted it as simple as possible for testing purposes.


~~~

Speaking of invade_buildup i always assumed it was a "holding" type order where'd they'd just buildup until a later turn when they passed the threshold for an invade_immediate. Doesn't seem to be--seems to just be a pause before attacking. I have them with just invade_buildup now against rebels and they invade as normal--just pause for a turn or two first. I think this is where most of the merging happens as per Cav's post above.

~~~

Btw Lusted or CavalryCmdr--any tips you can think of for making the AI the best at defending?

Lusted
11-28-2007, 10:47
Btw Lusted or CavalryCmdr--any tips you can think of for making the AI the best at defending?

My Ai has problems with garrisoning and defending well at times, it's something i'm hoping to improve.

CavalryCmdr
11-28-2007, 15:31
Speaking of invade_buildup i always assumed it was a "holding" type order where'd they'd just buildup until a later turn when they passed the threshold for an invade_immediate. Doesn't seem to be--seems to just be a pause before attacking. I have them with just invade_buildup now against rebels and they invade as normal--just pause for a turn or two first.
The AI behaves differently toward the Slave faction then other factions, any invade type toward the Slave faction will result in attacking as soon as they think they are strong enough. That said, Invade buildup is an agresive stance, and even on buildup the AI will attack other AI factions if they are overwhelmingly powerful. Much like invade immediate will build up thier forces if they are weaker then thier target. Unfortunately the AI will also have a tendency to lauch raid type attacks while on buildup if they do not have more pressing concerns. The best patrol-type defence I've found is invade none, defend deep toward neighbours and invade start, defend raids toward non neighbours. Problem here is they have a tendancy to not intercept invading armies, however they will concentrate more on building thier infrastucture while still recruiting a reasonable amount of troops.

The ai_db.xml only gives the AI a general 'stance' toward other factions, it dose not actually control the AI, so any invade type besides none is an agresive stance and can result in the AI attacking that faction. This is where manipulation of invade priority is very helpful, the AI will not invade a faction that has a much lower invade priority then another faction. For example if the ai_db gives an invade priority of 1000 toward slaves and only gets up to 400 toward everyone elts they will not attack unless invade_opportunistic is used, even if the only slave setlements left are the ones in america.

SigniferOne
11-28-2007, 23:17
Second thing...

May be obvious to people but just in case it isn't--if you want a faction to start as a vassal of another faction then you can rig the campaign AI file to make them do it in the first turn.

Say you wanted milan to be a vassal of hre for example.

1. Make a copy of the "catholic" profile in the campaign AI file
2. Rename it "catholic_milan"
3. Assign milan the ai_label "catholic_milan" in the strat file.
4. Add this clause at the top of the "catholic_milan" profile's <defend decisions> bit.




4. Repeat the process for hre, copy the catholic profile, rename the copy and assign it to hre.
5. Add this clause to the top of the new "catholic_hre" profile's <attack decisions>




6. Start hre and milan at war.
7. Make sure there's no milan diplomats around.
8. Start an hre diplomat next to milan
9. Job done.


edit: The order in which the two factions move may matter. The faction you want to be a vassal needs to have one turn to process their decison entries and decide they want to be a protectorate. So if the boss faction moves first their diplomat will be turned down on turn 1 (turn 0 in the code). Not sure if that would affect things. If you want it to definitely happen on the first turn then the "vassal" faction has to have their turn first.


Very good post Nikolai, definitely something worth trying out!

Question, the invade decision from HRE, won't that prompt an invasion, why would it send a diplomat instead?

Also, why wouldn't you want to have Milan diplomat around?

nikolai1962
11-29-2007, 02:56
SigniferOneVery good post Nikolai, definitely something worth trying out!

Question, the invade decision from HRE, won't that prompt an invasion, why would it send a diplomat instead?

Also, why wouldn't you want to have Milan diplomat around?

I've been trying to get "become a vassal" to work without the two factions being at war as i wanted a "peaceful annexation" type of vassal (for making the end game quicker). But can't seem to get it to work unless they're at war unfortunately.

So they will attack but they send a diplomat as well because of the "want_offer_protect" bit in their decision and they need to be kept at war until the offer is made. AI diplomats can still operate through a siege so that shouldn't be a problem. Keeping the Milan diplomat away is in case they ask for and get a ceasefire (not sure if this would mess things up or not--just a precaution).

nikolai1962
11-29-2007, 03:04
LustedMy Ai has problems with garrisoning and defending well at times, it's something i'm hoping to improve.

Yeah. I think the AI's defending is a bigger weak spot than it's attacking really. Hence trying to focus on that.

nikolai1962
11-29-2007, 04:08
CavalryCmdrThe AI behaves differently toward the Slave faction then other factions, any invade type toward the Slave faction will result in attacking as soon as they think they are strong enough. That said, Invade buildup is an agresive stance, and even on buildup the AI will attack other AI factions if they are overwhelmingly powerful. Much like invade immediate will build up thier forces if they are weaker then thier target. Unfortunately the AI will also have a tendency to lauch raid type attacks while on buildup if they do not have more pressing concerns. The best patrol-type defence I've found is invade none, defend deep toward neighbours and invade start, defend raids toward non neighbours. Problem here is they have a tendancy to not intercept invading armies, however they will concentrate more on building thier infrastucture while still recruiting a reasonable amount of troops.

The ai_db.xml only gives the AI a general 'stance' toward other factions, it dose not actually control the AI, so any invade type besides none is an agresive stance and can result in the AI attacking that faction. This is where manipulation of invade priority is very helpful, the AI will not invade a faction that has a much lower invade priority then another faction. For example if the ai_db gives an invade priority of 1000 toward slaves and only gets up to 400 toward everyone elts they will not attack unless invade_opportunistic is used, even if the only slave setlements left are the ones in america.

Mine may be working out a bit different because i currently have all the invade priorities mostly the same so the final priority is heavily influenced by faction standing and global standing and the factions just dislike the slave faction more than anyone else at game start. With mine it "seems" that the invade_buildup setting has a specific pause built into it to allow armies to merge. It may just appear that way though.

What i was mostly doing is trying out the defend settings with a view to how well the AI armies are merged when the faction is at peace with everybody. Usual caveats about how recruitment, unit costs etc may affect different mods but i set all the defend decisions to be the same just to look at the merging.

Pretty much replicates what CavCmdr says in his page linked at the top and fits what you'd expect but reproducing results never hurts so...

defend_deep: ok merging (a comparison would be 3-4 stacks of 3-4 units instead of 7-8 stacks of 1-2 units), heavily weighted to the capital or some other central spot they decide on, good garrison in the capital, not so good elsewhere.

defend_fortified: ok merging, less weighted to the capital so they try and cover more cities and more of them have ok garrisons, big downside is the actual forts they build and the armies staying in them forever. not a problem if you don't mind losing forts but i'd like to avoid doing that if possible.

defend_frontline: ok

normal and minimal: pretty useless purely from a merging point of view. The AI doesn't seem to try and merge with these settings.

advantage of deep is you can expect a big counter-attack stack if you invade. disadvantage is in a faction that is physically large--in terms of area, the counter-attack will take a long time to arrive. fortified is more likely to have a stack on guard but because the AI is trying to cover more places they are likely to be smaller stacks. So overall, purely in terms of defend decisons and merging/garrisons, defend_fortified would be best if it wasn't for the fort glitch.

Also, geography seems to matter with defend_frontline. In areas with a lot of narrow mountain passes etc the AI seemed to have bigger problems merging.

However, seems to me though that the majority of the AI's army merging happens as a result of the invade decisons. So currently i'm thinking that's where to look if you want to get the AI to merge more.

~~~

Ran through it quickly again with the default invade mode being invade_start instead of invade_none. This had a lot of interesting effects. Probably confused the AI a bit too but overall this seemed to increase the average level of merging with each setting. They also seemed to hold back a lot more e.g my french faction has 4 starting cities and armies and normally they'd all move out and attack a rebel city each on the 1st/2nd turn with invade_immediate or 2nd/3rd turn with invade_buildup. With invade_start set for all the other factions what happened was two of those starting armies moved to the capital, merged and waited, while the other two did the rebel bashing.

Worth experimenting with maybe, bearing in mind the points CavCmdr makes about it starting wars you may not want. I'm thinking of maybe randomly switching the AI between invade_none and invade_start with neighbouring factions they're at peace with to see if i can trick them into merging more.

Lusted
11-29-2007, 10:34
What i was mostly doing is trying out the defend settings with a view to how well the AI armies are merged when the faction is at peace with everybody. Usual caveats about how recruitment, unit costs etc may affect different mods but i set all the defend decisions to be the same just to look at the merging.

Pretty much replicates what CavCmdr says in his page linked at the top and fits what you'd expect but reproducing results never hurts so...

defend_deep: ok merging (a comparison would be 3-4 stacks of 3-4 units instead of 7-8 stacks of 1-2 units), heavily weighted to the capital or some other central spot they decide on, good garrison in the capital, not so good elsewhere.

defend_fortified: ok merging, less weighted to the capital so they try and cover more cities and more of them have ok garrisons, big downside is the actual forts they build and the armies staying in them forever. not a problem if you don't mind losing forts but i'd like to avoid doing that if possible.

defend_frontline: ok

normal and minimal: pretty useless purely from a merging point of view. The AI doesn't seem to try and merge with these settings.

advantage of deep is you can expect a big counter-attack stack if you invade. disadvantage is in a faction that is physically large--in terms of area, the counter-attack will take a long time to arrive. fortified is more likely to have a stack on guard but because the AI is trying to cover more places they are likely to be smaller stacks. So overall, purely in terms of defend decisons and merging/garrisons, defend_fortified would be best if it wasn't for the fort glitch.

Also, geography seems to matter with defend_frontline. In areas with a lot of narrow mountain passes etc the AI seemed to have bigger problems merging.

However, seems to me though that the majority of the AI's army merging happens as a result of the invade decisons. So currently i'm thinking that's where to look if you want to get the AI to merge more.

That's pretty much what i thought about those defend settings as well. I use a mix of deep and fortified in my mod but still have garrisoning problems, mainly with some settlements being defended well(i've watched some AI wars in my mod and some of it's been very good), but other times it will only have a couple of units in a settlement. Very frustrating at times. But hopefully matching all invade decisions with a defend decision should help a bit, but i've got to work out why my AI's suddenly gone passive since doing this.

And something for you guys to ponder over. I'm giving my campaign AI a bit of a go over, and yet it's suddenly become very passive. The only reason i can find for this is the fact that the LGTD log is showing it picking defend_fortified v every faction early in the game. Here are the defend decisions, and as you can see at the bottom is a decision that should make the AI choose defend_normal against non-neighbours.


<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<decision_entry>
<!--
DEFAULT: defend normal
-->
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> defend fortified
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, defend normal
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, defend foritfied
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, defend foritfied
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago, defend foritfied
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, defend normal
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, defend normal
-->
<min_entry global_standing="0.5" is_neighbour="true"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, defend normal
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, defend foritfied
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, defend foritfied
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, defend foritfied
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, defend foritfied
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, defend foritfied
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, defend normal
-->
<min_entry is_protectorate="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, defend normal
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> fortified defense
-->
<min_entry free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> fortified defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> fortified defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> defend fortified
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend fortified
-->
<min_entry frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend frontline
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend fortified
-->
<min_entry frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend fortified
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> defend fortified
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> defend normal
-->
<min_entry stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> defend normal
-->
<min_entry stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> defend frontline
-->
<min_entry stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> deep defense, sue for peace
-->
<min_entry is_neighbour="true" stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && num settlements 1 && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" borders_all_our_regions="true" num_settlements="1"/>
<max_entry frontline_balance="0.7" free_strength_balance="0.7" production_balance="1.0" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" num_settlements="1"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude defense="defend_normal"/>
</decision_entry>

<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, defend normal
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_normal"/>
</decision_entry>

And here is my invaded decisions just incase the problem might be in them:


<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
If they are the papal states and they like us, use defaults
(using their FS instead of ours, else it may not fire since papal states does not try to upset catholics)
-->
<min_entry target_faction="papal_states" target_faction_standing="-0.5"/>
<max_entry target_faction="papal_states"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, and we like them above a threshold, and our global standing is reasonable, use defaults
(this will stop factions from attacking some targets if it will cause excommunication)
-->
<min_entry faction_standing="-0.25" has_ceasehostilities="true" global_standing="-0.25"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, 50% chance to use defaults
(this will reduce chance of factions attacking some targets if it will cause excommunication)
-->
<min_entry has_ceasehostilities="true"/>
<max_entry rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>


<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade_priority="1000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> invade none
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> frontline defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> normal defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> conduct raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, invade immediate. If not our shadow, also want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, invade immediate. If our shadow, do not want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="false"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_builup" invade_priority="60" continue="true"/>
</decision_entry>

<!--
TRUSTED ALLY INVADE DECISIONS
-->


<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_immediate" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="1500" can_force_invade="true" continue="true"/>
</decision_entry>


<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="1500" can_force_invade="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" can_force_invade="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="2000" can_force_invade="true" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

CavalryCmdr
11-29-2007, 14:50
I belive true/false is considered by it's numeric equivilents (0/1) so this entry:
<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>
True > false so it is always returning a true argument, and not continuing. Try entering a min_entry target_human or commenting this argument out compleatly and test. I'd also continue this argument as 'fortified' against a non-neighbour is as confusing for the AI as 'frontline.'

Lusted
11-29-2007, 15:22
True > false so it is always returning a true argument, and not continuing. Try entering a min_entry target_human or commenting this argument out compleatly and test.

Thanks for the help, i'll give it a go.


I'd also continue this argument as 'fortified' against a non-neighbour is as confusing for the AI as 'frontline.'

Shoud be a is_neighbour="true", i had that in a lot of the defense entries but that was causing a crash so i removed mosty of them. Must have forgot to add it back in for that.

Lusted
11-29-2007, 17:16
Hmm, still getting completely passive AI even though that change worked, which is alarming given the fact my AI's gone from very quick early expansion to none at all.

Here's my system.log.txt if you wan to have a look at it.

http://uploaded.to/?id=8bymje

CavalryCmdr
11-30-2007, 01:14
Sorry, dial-up, anything much over 1 meg is beyond my capacity to download.

Is the AI truly pasive or just over cautious?

Without being able to see the LTGD, I suggest:
<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude defense="defend_normal"/>
</decision_entry>Seperate into is_neighbour and assign defend frontline, otherwise defend minimal. Since the slave faction will not appear on num_enemies, you could also dictate is_neighbour defence to require num_enemise 0 else defend normal, so thier slave neighbours dont take too much of thier attention if they have other enemies.

I would also assign all slave faction dealings as the first entries for both defence and offence so you know non of your other decisions are applied to the slave faction. I also, in contrast to all other factions, would assign constant invade priority to the slave faction and not use continue at all, or very little. I'd also put at_war="true" on them somewhere, preferably everywhere (read posts 10-12)

nikolai1962
11-30-2007, 02:26
LustedAlso, nikolai, have you managed to make your AI aggressive whilst using defend_deep?

Looked at this again in light of your original comment and may have a clue :)

The first tests i was just clicking end turn quick while watching France for army merging. Tried it again looking further afield.

Caveats--number of quick tests--could be mistaken but...

I set all the defend decisions to be defend_deep, both rebel/non-rebel and neighbour/not neighbour.

On my map i added a region to the west of egypt that the egypt AI would usually attack early on, around turn 5-6 usually. The settlement was quite a long way away from the nearest egypt settlement. With everything at defend_deep they suddenly stopped attacking it not until they had all the other closer adjacent rebels regions. I switched the setting to all be defend_minimal and they went back to attacking it early. Switched back to defend_deep but raised the invade priority for rebel regions by 200 and they attacked it early. Reduced the invade priority back to its original level and no attack.

It was a lucky example as the same effect is happening elsewhere on the map but much less obviously.

Possible Theory 1.
It almost seems like the attack decisions for individual settlements could be something like:

1. base invade priority
2. minus some number related to distance
3. minus some number related to garrison
4. plus some number related to income
5. plus/minus some number related to defend setting

The AI then picks the highest scoring targets that have a value above a certain threshhold.

Possible Theory 2:
The defend settings determine the relative proportions of an AI faction's units that are assigned to attack and defence. The end value being determined by how many of each target faction's regions they are adjacent/not-adjacent to. So with everything at defend_deep then the AI faction is close to a 100% defensive. If all factions were defend_minimal then the AI would be close to 100% aggressive. With rebels/non-rebels and adjacent/non-adjacent at different settings it ends up somewhere in the middle.


It could be a bit of both where each setting has an "invasion offset" which is used to modify the invade priority plus other settings that determine other aspects of the defend behaviour.

Anyway back to the egypt example....

Looking at the defend settings as a set with an increasing invade offset I bumped all the defend settings to the next level up from defend_minimal, which according to the list in the AI file would be defend_normal. The egypt AI would still attack the far city with this setting. I then increased it by one each time, and I've forgotten which, but i think it was defend_raid when it stopped attacking it until it was the last rebel region.

Also...

When i noticed this happening i looked around a bit. Factions like turks and hungary have a lot of adjacent rebel regions to potentially expand into and with the low defend settings they'd keep expanding that way even when their original cities were being blitzed by the byzies. Again, raising the defend settings by one level and re-trying both turks and hungary had *just enough* defenders to prevent an early byzie blitz at defend_raid.

A faction like France was almost completely (visually) unaffected by this as on my map they start in an almost circular cluster with an outer ring of very close rebel regions. Their actual defending might have been effected in a game but can't really test that yet.

Also, england and denmark--in both these cases they have rebel regions they almost completely ignore when the settings were all defend_deep. On my map I think it is because those regions start off very poor (motte and bailey castles with very low population). I knew it wasn't a pathing problem because they do take them eventually but with all the defend settings at defend_minimal they'd take them around turns 20-30 while with defend_deep it might be turn 50-60 or more. (Think it may that the pop/income passes a certain point).

So I think that's what is happening vis a vis passive AI at defend_deep.

The solution will vary with each mod as the different settings affect factions differently depending on how they're setup. Alternatively there may be a best average result using a setting somewhere from defend_raid upwards.

Increasing the invade priorities to over-ride the offset effect (if the theory is correct) seems to work too but in some cases that has the effect of making the AI blindly aggressive in one direction and not bothering to defend its core cities. I had all my invade priorities set to the same value which was good as it showed up the problems but i'm thinking that is part of why the invade/defend decisons need to be in sync. A low invade setting with a low priority and defend_deep would be very passive. A high invade setting with a high priority and defend_minimal might be blindly aggressive.

Pretty pleased with this. Might turn out to be a proper logical hook into how the AI behaves which will make it easier than guesswork.

In my case i want the AI factions to take the rebel regions rapidly but still have them weighted to defense. This should mean the influence of the rebel regions will be reduced over time as they are taken and the AI factions have more faction neighbours than rebel neighbours. So my original settings of defend_deep against all non-rebel targets, deep for non-adjacent rebels and frontline for adjacent rebels worked well in my case as by trial and error i'd got the settings AI to fit in with this new theory.

On the other hand defend_frontline may not be the best overall because of the things CavCmdr mentions about how they won't neccessarily intercept armies moving to attack cities. So maybe what would be best for me would be defend_deep for everything (or fortified if you don't mind losing forts) and cranking up the invade priorities slightly.

We shall see :dizzy2:

ps none of this helps merging as it was terrible.

~~~

CavCmdr

Opinions on the theory? Seems to fit your observations.

CavalryCmdr
11-30-2007, 05:48
Dosnt appear to directly contradict anything I've seen. Distance is a factor when deciding an invasion, I've no doubt about that, and increasing invade priority will over-ride it. I've not considered a 'value' for the different defence settings, just position when an invasion is called.

Let me see if I understand your theory:
Defence 'value' - invade priority offset = % troop strength used for defence.
Everything elts used for attack.
if invade priority offset > defence 'value,' AI is blindly agressive.
if invade priority offset < defence 'value,' AI is passive.
Therefore the preceived need to link invade and defence types.

Try, opportunistic invade setting against rebels with defend deep, following your theory, the AI should attack any rebel settlement provided they still maintain relative balance with other nearby armies. Provided your theory is correct, or near correct, this should achive almost exactly what your looking for. Invade priority dose not matter, only opportunity, so your defend deep should always override the attack, until that faction has the armies to spare.

Like I said I have not looked at it in that manner, but have not seen anything off-hand that contradicts your theory. I am quite confident I understand how invade_opportunistic works, so give the results of this test and I'll have a better idea about your theory. Logically speaking your theory is sound, so it could well be the 'missing link' in AI defence. (now if we could only figure out how to put them in the cities...)


I've been working with defend_fortified some more. With my current settings I have not yet seen the AI become 'stuck' inside a fort, it apears to be mobilizing properly for invasion and defence. I've only done general behaviour observasion so far, not detailed action. Ironically(?) these settings fit quite nicely into your theory as I understand it. Anyway, using fronline balance to dictate defence settings to default at fortified, if far weaker switch to deep, if much stronger switch to frontline. Corosponding invasion type (if at war) buildup, opportunistic and immediate.

Lusted
11-30-2007, 09:58
CavalryCmdr, i'm going to go try your suggestions now. I'll post up my 'old' campaign AI file incase you can see the difference between it and my current file that's causing the problem


<?xml version="1.0"?>
<root>
<!--

// The trusted ally global parameters specify the minimum faction standing thresholds for a target faction to be
// considered a trusted ally. We can use target faction standing parameters directly in invasion/defend decisions
// but the trusted ally data allows us to use additional entry parameters: trusted_ally_enemy and trusted_ally_protectorate
// that we cannot measure directly for a target faction. An AI faction may also try and aid its trusted allies (hence the
// reverse checks on standings to avoid helping allies it shouldn't)

<trusted_ally_fs_threshold float="0.4"/> // min threshold for how much we like the target faction to consider them a trusted ally
<trusted_ally_target_fs_threshold float="0.4"/> // min threshold for how much the target faction likes us to consider them a trusted ally
<trusted_ally_target_human_fs_threshold float="0.0"/> // min threshold for how much the target (human) faction likes us to consider them a trusted ally
<trusted_ally_gs_threshold float="-1.0"/> // min threshold for how trustworthy we are to consider the target faction a trusted ally
<trusted_ally_target_gs_threshold float="-0.1"/> // min threshold for how trustworthy is the target faction to consider them a trusted ally
<trusted_ally_enemy_auto_war bool="false"/> // flag to indicate if a faction automatically goes to war with a trusted allies enemy

<use_cheat_overrides bool="true"/> // determines if cheat overrides (force peace with ai, force attack with humans) are applied
<invade_priority_fs_modifier float="-400.0"/> // modifies the final invade priority for new faction targets by += (faction_standing * modifier) {makes factions more likely to start war with disliked targets}
<invade_priority_gs_modifier float="0.0f"/> // modifies the final invade priority for new faction targets by += (global_standing * modifier) {makes factions more likely to start war with untrustworthy targets}
<invade_priority_assistance_offset int="200"/> // modifies the final invade priority for new faction targets where military assistance has been asked by += (offset) {makes factions more likely to start war with military assistance targets}
<invade_priority_min int="50"/> // min clamp for final invade priorities calculated
<invade_priority_max int="1000"/> // max clamp for final invade priorities calculated


// Each faction has an 'ai_label' specified in the campaign descr_strat.txt. This ai_label must correspond to a 'faction_ai_label'
// entry specified in this database (e.g. 'default', 'catholic', 'papal_states'). The 'default' ai_label should always exist
// and is used if a specified ai_label cannot be found. Note that each ai_label is independent (i.e. 'catholic' ai_label does
// not inherit any data from 'default') hence care should be taken when adding new entries to ensure that any relevant global
// entries are added to all other ai_labels. Additionally, the ai_labels can be tested through event conditions and set through
// a script command, potentially allowing ai behaviour to be changed dynamically in game depending on current game state.

<faction_ai_label name="default"> :: The label for a following set of campaign ai faction parameters


// The ai_labels specify the structure of the long term goal director (LTGD) which drives the high level campaign AI.
// At the start of every factions turn (or when diplomacy changes), the LTGD is re-evaluated as follows:
// for every target faction (all other factions), evaluate the defend decisions
// for every target faction, evaluate the invasion decisions
// any invasion priorities are modified by the faction standing (relationship) towards the target
// depending on current game state, a new target with a high invasion priority may be selected to invade
// the LTGD can be debugged with the preferences '[log] level = ai.ltgd trace' and '[ai] ltgd_logging = true.


// The 'defend_decisions' entry specifies a list of decision entries related to ai defence strategies. To evaluate a defence
// strategy, a set of parameters is built and the list of decision entries is iterated until an entry satisfies the min and max
// conditions for the set of parameters. As soon as an entry is satisfied (min <= current <= max), the iteration ends. The decision
// is taken from the default 'faction_attitude' parameters with certain parameters overridden. The 'min_entry' specifies the minimum
// thresholds specified for evaluation and the 'max_entry' specifies the maximum. Note that care should be taken when entering new
// entries since as soon as the thresholds for an entry are successfully met, the iteration ends. An exception to this is the use of
// the 'continue' faction_attitude parameter, which allows the decision iteration to continue (This is useful for changing certain
// parameters of the faction_attitude but allowing the process to continue so other entries can apply additional modifications).

<defend_decisions> :: List of ai defend decisions. when choosing a decision, code will iterate from first to last until a set of thresholds succeeds

<decision_entry> :: An individual decision entry

<min_entry :: The minimum threshold for decision comparison
frontline_balance="0.0" :: ratio of factions frontline military strength vs the target
military_balance="0.0" :: ratio of factions overall military strength vs the target
production_balance="0.0" :: ratio of factions overall production strength vs the target
target_num_enemies="0" :: the number of enemies the target has
num_enemies="0" :: the number of enemies the faction has
has_alliance_against="false" :: is the faction part of an alliance against target
military_balance_plus_enemies="0.0" :: ratio of factions overall military strength vs the target (plus all of its enemies)
alliance_military_balance="0.0" :: ratio of factions (plus its allies) overall military strength vs the target
strongest_neighbour="false" :: is the target the factions strongest neighbour
most_desirable="false" :: is the target the factions most desirable target
faction_standing="-1.0" :: how much does the faction like the target
target_global_standing="-1.0" :: how trustworthy is the target to the rest of the world
target_faction_standing="-1.0" :: how much does the target faction like this faction
global_standing="-1.0" :: how trustworthy is this faction to the rest of the world
target_religion="catholic" :: the religion of the target (see descr_religions.txt)
enemy_excommunicated="false" :: is the target excommunicated
excommunicated="false" :: is this faction excommunicated
num_turns_allied="0" :: the number of turns since the faction agreed to an alliance with the target
num_turns_ceasfire="0" :: the number of turns since the faction has agreed to a ceasefire with the target (-1 for no agreement)
stance="Allied" :: diplomatic stance with the target (Allied, Neutral, AtWar)
target_faction="england" :: target faction label (see descr_sm_factions.txt)
target_human="false" :: is the target a human player
target_is_shadow="false" :: is the target this factions shadow faction
turn_number="0" :: the game turn number (starting at 0)
is_protectorate="false" :: is the target our protectorate
is_protectorate_of_catholic="false" :: is the target a protectorate of a non-excommunicated catholic faction
free_strength_balance="0.0" :: ratio of factions free military strength vs the target
borders_all_our_regions="false" :: does the target border on all the factions region groups
target_weakest_neighbour="false" :: is the faction the targets weakest neighbour
has_ceasehostilities="false" :: does the faction have a cease hostilities mission against the target from the papal faction
is_neighbour="false" :: does the target neighbour on any of the factions regions
trusted_ally="false" :: is the target a trusted ally (they like us more than fs_thresh, and their global standing > gs_thresh, and they are allied)
trusted_ally_enemy="false" :: is the target an enemy of a trusted ally
trusted_ally_protectorate="false" :: is the target a protectorate of a trusted ally
num_settlements="0" :: how many settlements does the faction own
rand="0.0" :: a random value
difficulty="easy"/> :: the chosen difficulty for the current local player (easy, medium, hard, very_hard)

<max_entry :: The maximum threshold for decision comparison
frontline_balance="999.0"
military_balance="999.0"
production_balance="999.0"
target_num_enemies="999"
num_enemies="999"
has_alliance_against="true"
military_balance_plus_enemies="999.0"
alliance_military_balance="999.0"
strongest_neighbour="true"
most_desirable="true"
faction_standing="1.0"
target_global_standing="1.0"
target_faction_standing="1.0"
global_standing="1.0"
target_religion="heretic"
enemy_excommunicated="true"
excommunicated="true"
num_turns_allied="999"
num_turns_ceasfire="999"
stance="AtWar"
target_faction="slave"
target_human="true"
target_is_shadow="true"
is_protectorate="true"
is_protectorate_of_catholic="true"
free_strength_balance="999.0"
borders_all_our_regions="true"
target_weakest_neighbour="true"
has_ceasehostilities="true"
is_neighbour="true"
trusted_ally="true"
trusted_ally_enemy="true"
trusted_ally_protectorate="true"
num_settlements="999"
rand="1.0"
difficulty="very_hard"/>

<faction_attitude :: A list of modifiers to apply if min and max entries above are successful
defense="defend_normal" :: The long term defense type (defend_minimal, defend_normal, defend_raid, defend_frontline, defend_fortified, defend_deep)
defend_priority="0" :: The defensive priority of achieving stance against this faction (NOT USED AT PRESENT) (additive with previous decisions this turn)
invade="invade_none" :: The long term invade type (invade_buildup, invade_immediate, invade_raids, invade_opportunistic, invade_start, invade_none)
invade_priority="0" :: priority of achieving invasion against this faction (additive with previous decisions this turn). Compared with priority for decisions against all other factions to choose highest. Value modified internally by faction standing.
at_war="false" :: are we at war with this enemy
want_peace="false" :: do we want to be at peace with this faction
want_ally="false" :: do we want to ally with this faction
want_be_protect="false" :: do we want to be a protectorate of this faction
want_offer_protect="false" :: do we want to offer protectorate status to this nation
force_invade="false" :: must we invade now
alliance_against="0" :: how much do we want to have an alliance against this nation (additive with previous decisions this turn)
pts_desire="0" :: points total for measuring our desire for this faction's territory (additive with previous decisions this turn)
pts_alliance="0" :: points total for measuring how much we want to be allies with these people (additive with previous decisions this turn)
can_force_invade="true" :: can naval or forced invasion settings overwrite invade parameters
continue="false"/> :: do we stop evaluating decision entries (false) or continue

</decision_entry>

</defend_decisions>


// The 'invasion_decisions' entry specifies a list of invasion entries related to ai invasion strategies. This process
// is virtually identical to the defence decision process but is evaluated as a separate stage.

<invasion_decisions> :: List of ai invasion decisions. when choosing a decision, code will iterate from first to last until a set of thresholds succeeds (uses identical data to defend decisions)

<decision_entry> :: An individual decision entry
<min_entry/> :: The minimum threshold for decision comparison
<max_entry/> :: The maximum threshold for decision comparison
<faction_attitude/> :: A list of modifiers to apply if min and max entries above are successful
</decision_entry>

</invasion_decisions>

-->


<!--
//////////////////////
// GLOBAL AI PARAMS //
//////////////////////
-->

<trusted_ally_fs_threshold float="0.3"/>
<trusted_ally_target_fs_threshold float="0.3"/>
<trusted_ally_target_human_fs_threshold float="0.3"/>
<trusted_ally_gs_threshold float="-0.1"/>
<trusted_ally_target_gs_threshold float="-0.1"/>
<trusted_ally_enemy_auto_war bool="false"/>

<use_cheat_overrides bool="false"/>
<invade_priority_fs_modifier float="-400.0"/>
<invade_priority_gs_modifier float="-200.0f"/>
<invade_priority_assistance_offset int="200"/>
<invade_priority_min int="50"/>
<invade_priority_max int="1500"/>

<!--
///////////////////////////////////////
// DEFAULT AI PARAMS. DO NOT REMOVE //
///////////////////////////////////////
-->

<faction_ai_label name="default">

<defend_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<!--
DEFAULTS AND V SLAVE
-->

<decision_entry>
<!--
default >>> fortified defense
-->
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we have any settlements, and we are at the very start of the game, and target is not human (cannot trust humans) >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" turn_number="10" target_human="false"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="true" turn_number="30"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="false" turn_number="30"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<!--
WHO TO BE AT PEACE WITH/ALLY WITH/MAKE PROTECTORATE
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && num settlements 1 && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true" num_settlements="1"/>
<max_entry frontline_balance="0.7" free_strength_balance="0.7" production_balance="1.0" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" num_settlements="1"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR NOT AT WAR
-->

<decision_entry>
<!--
if not our neighbour, and we have any settlements, use defaults
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> fortified defense
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && we are allied to him,
then >>> normal defense
-->
<max_entry target_weakest_neighbour="false" stance="Allied"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> fortified defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> fortified defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is less than
twice his && overall superior >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="0.5" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR AT WAR
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep"/>
</decision_entry>


<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="0.5"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>
<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> fortified defense
-->
<min_entry stance="AtWar" frontline_balance="1.0" is_neighbour="true" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, normal defense. If not our shadow, also want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude defense="defend_normal" want_offer_protect="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, defend normal. If our shadow, do not want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_normal" want_offer_protect="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>


<decision_entry>
<!--
if we're at war, and none of the previous rules apply,
then >>> fortified defense
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> invade none
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> frontline defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> normal defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> conduct raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, invade immediate. If not our shadow, also want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, invade immediate. If our shadow, do not want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="false"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_builup" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
TRUSTED ALLY INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_immediate" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

</invasion_decisions>


</faction_ai_label>


<!--
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PAPAL FACTION AI PARAMS. REQUIRES SPECIAL STUFF TO NOT ALLOW ATTACKING NON-EXCOMMUNICATED CATHOLIC FACTIONS //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->

<faction_ai_label name="papal_faction">

<defend_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<!--
DEFAULTS AND V SLAVE
-->

<decision_entry>
<!--
default >>> deep defense
-->
<faction_attitude defense="defend_deep" continue="true"/>
</decision_entry>

<!--
WHO TO BE AT PEACE WITH/ALLY WITH/MAKE PROTECTORATE
-->

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
don't ally with islamic factions
-->
<min_entry target_religion="islam"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
Make Papacy very unlikely to ally
-->
<min_entry faction_standing="0.6" target_global_standing="0.4" enemy_excommunicated="false"/>
<max_entry rand="0.25"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR AT WAR
-->

<decision_entry>
<!--
if we're at war, and none of the previous rules apply,
then >>> deep defense
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_deep" continue="true"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude invade_priority="-500" continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
Stop papal states attacking anyone for the first 20 turns
-->
<max_entry turn_number="20"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
if target is a non-excommunicated catholic faction, no invasion set up, cannot force invade
-->
<min_entry target_religion="catholic"/>
<max_entry target_religion="catholic" enemy_excommunicated="false"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, and we like them above a threshold, and our global standing is reasonable, use defaults
(this will stop factions from attacking some targets if it will cause excommunication)
-->
<min_entry faction_standing="-0.25" has_ceasehostilities="true" global_standing="-0.25"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, 50% chance to use defaults
(this will reduce chance of factions attacking some targets if it will cause excommunication)
-->
<min_entry has_ceasehostilities="true"/>
<max_entry rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
IMPROVEMENTS TO CRUSADES
-->

<decision_entry>
<!--
If Islamic, and very low faction standing, invade immediate.
-->
<min_entry faction_standing="-1.0" target_religion="islam"/>
<max_entry faction_standing="-0.7"/>
<faction_attitude can_force_invade="true" invade="invade_immediate" invade_priority="300" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

</invasion_decisions>


</faction_ai_label>


<!--
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CATHOLIC FACTION AI PARAMS. REQUIRES SPECIAL STUFF TO REDUCE ATTACKING NON-EXCOMMUNICATED CATHOLIC FACTIONS //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->

<faction_ai_label name="catholic">


<defend_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<!--
DEFAULTS AND V SLAVE
-->

<decision_entry>
<!--
default >>> fortified defense
-->
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we have any settlements, and we are at the very start of the game, and target is not human (cannot trust humans) >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" turn_number="10" target_human="false"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="true" turn_number="30"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="false" turn_number="30"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<!--
WHO TO BE AT PEACE WITH/ALLY WITH/MAKE PROTECTORATE
-->

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
don't ally with islamic factions
-->
<min_entry target_religion="islam"/>
<faction_attitude want_ally="false" pts_alliance="-20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude defense="defend_normal"/>
</decision_entry>

<decision_entry>
<!--
otherwise if target is non-excommunicated catholic faction, normal defense required
-->
<min_entry target_religion="catholic"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && num settlements 1 && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true" num_settlements="1"/>
<max_entry frontline_balance="0.7" free_strength_balance="0.7" production_balance="1.0" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" num_settlements="1"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR NOT AT WAR
-->

<decision_entry>
<!--
if not our neighbour, and we have any settlements, use defaults
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> fortified defense
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && we are allied to him,
then >>> normal defense
-->
<max_entry target_weakest_neighbour="false" stance="Allied"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> fortified defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> fortified defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is less than
twice his && overall superior >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="0.5" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR AT WAR
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep"/>
</decision_entry>


<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="0.5"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>
<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> fortified defense
-->
<min_entry stance="AtWar" frontline_balance="1.0" is_neighbour="true" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, normal defense. If not our shadow, also want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude defense="defend_normal" want_offer_protect="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, defend normal. If our shadow, do not want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_normal" want_offer_protect="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>


<decision_entry>
<!--
if we're at war, and none of the previous rules apply,
then >>> fortified defense
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
If they are the papal states and they like us, use defaults
(using their FS instead of ours, else it may not fire since papal states does not try to upset catholics)
-->
<min_entry target_faction="papal_states" target_faction_standing="-0.5"/>
<max_entry target_faction="papal_states"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, and we like them above a threshold, and our global standing is reasonable, use defaults
(this will stop factions from attacking some targets if it will cause excommunication)
-->
<min_entry faction_standing="-0.25" has_ceasehostilities="true" global_standing="-0.25"/>
</decision_entry>

<decision_entry>
<!--
If we have a cease hostilities mission against the target, 50% chance to use defaults
(this will reduce chance of factions attacking some targets if it will cause excommunication)
-->
<min_entry has_ceasehostilities="true"/>
<max_entry rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> invade none
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> frontline defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> normal defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>


<!--
DON'T ATTACK NON-EXCOMMUNICATED CATHOLICS
-->

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade="invade_none" invade_priority="-300" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if target is non-excommunicated catholic faction, and they don't mind us much, and they are not obviously untrustworthy, minimal defense required
-->
<min_entry target_religion="catholic"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade="invade_none" invade_priority="-300" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> conduct raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, invade immediate. If not our shadow, also want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, invade immediate. If our shadow, do not want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="false"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_builup" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
TRUSTED ALLY INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_immediate" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
IMPROVEMENTS TO CRUSADES
-->

<decision_entry>
<!--
If Islamic, and very low faction standing, invade immediate.
-->
<min_entry faction_standing="-1.0" target_religion="islam"/>
<max_entry faction_standing="-0.7"/>
<faction_attitude can_force_invade="true" invade="invade_immediate" invade_priority="300" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

</invasion_decisions>


</faction_ai_label>


<!--
///////////////////////////////////////
// MONGOL AI PARAMTERS //
///////////////////////////////////////
-->

<faction_ai_label name="mongol">

<defend_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<!--
DEFAULTS AND V SLAVE
-->

<decision_entry>
<!--
default >>> fortified defense
-->
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we have any settlements, and we are at the very start of the game, and target is not human (cannot trust humans) >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" turn_number="10" target_human="false"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="true" turn_number="30"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="false" turn_number="30"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<!--
WHO TO BE AT PEACE WITH/ALLY WITH/MAKE PROTECTORATE
-->

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && num settlements 1 && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true" num_settlements="1"/>
<max_entry frontline_balance="0.7" free_strength_balance="0.7" production_balance="1.0" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" num_settlements="1"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR NOT AT WAR
-->

<decision_entry>
<!--
if not our neighbour, and we have any settlements, use defaults
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> fortified defense
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && we are allied to him,
then >>> normal defense
-->
<max_entry target_weakest_neighbour="false" stance="Allied"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> fortified defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> fortified defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is less than
twice his && overall superior >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="0.5" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR AT WAR
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep"/>
</decision_entry>


<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="0.5"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>
<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> fortified defense
-->
<min_entry stance="AtWar" frontline_balance="1.0" is_neighbour="true" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, normal defense. If not our shadow, also want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude defense="defend_normal" want_offer_protect="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, defend normal. If our shadow, do not want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_normal" want_offer_protect="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>


<decision_entry>
<!--
if we're at war, and none of the previous rules apply,
then >>> fortified defense
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> invade none
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> frontline defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> normal defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> conduct raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, invade immediate. If not our shadow, also want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, invade immediate. If our shadow, do not want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="80" want_offer_protect="false"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
TRUSTED ALLY INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_immediate" invade_priority="65" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" invade_priority="55" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

</invasion_decisions>


</faction_ai_label>

<!--
///////////////////////////////////////
// ISLAMIC AI PARAMS. //
///////////////////////////////////////
-->

<faction_ai_label name="islam">

<defend_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING want_peace WITH A FACTION UNDER CERTAIN CONDITIONS. CONTINUES CHECKS FOR SUBSEQUENT DECISIONS
</decision_entry>
-->

<!--
DEFAULTS AND V SLAVE
-->

<decision_entry>
<!--
default >>> fortified defense
-->
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we have any settlements, and we are at the very start of the game, and target is not human (cannot trust humans) >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" turn_number="10" target_human="false"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="true" turn_number="30"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if human, fortified defense
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at the start of the game >>> minimal defense
-->
<min_entry num_settlements="1"/>
<max_entry stance="Neutral" is_neighbour="false" turn_number="30"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<!--
WHO TO BE AT PEACE WITH/ALLY WITH/MAKE PROTECTORATE
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && num settlements 1 && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" borders_all_our_regions="true" num_settlements="1"/>
<max_entry frontline_balance="0.7" free_strength_balance="0.7" production_balance="1.0" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> propose become protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" num_settlements="1"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude defense="defend_deep" want_peace="true" want_be_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if not our neighbour, and we have any settlements, and we are at war, and they are not a trusted allies enemy, use defaults + want peace
-->
<min_entry num_settlements="1" stance="AtWar" />
<max_entry is_neighbour="false" trusted_ally_enemy="false"/>
<faction_attitude want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, ally with them
-->
<min_entry trusted_ally_protectorate="true"/>
<faction_attitude want_ally="true"/>
</decision_entry>

<decision_entry>
<!--
If they are an enemy of a trusted ally, don't ally
-->
<min_entry trusted_ally_enemy="true"/>
<faction_attitude want_ally="false"/>
</decision_entry>

<decision_entry>
<!--
If alliance against, don't ally, randomised slightly.
-->
<min_entry has_alliance_against="true" />
<max_entry rand="0.65" />
<faction_attitude want_ally="false"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR NOT AT WAR
-->

<decision_entry>
<!--
if not our neighbour, and we have any settlements, use defaults
-->
<min_entry num_settlements="1"/>
<max_entry is_neighbour="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> fortified defense
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && we are allied to him,
then >>> normal defense
-->
<max_entry target_weakest_neighbour="false" stance="Allied"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> fortified defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> fortified defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is less than
twice his && overall superior >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="0.5" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> defend frontline
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> defend frontline
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> defend fortified
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> defend fortified
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> defend fortified
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<!--
DEFEND DECISIONS FOR AT WAR
-->

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> deep defense, sue for peace
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep"/>
</decision_entry>


<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry stance="AtWar" is_neighbour="true" free_strength_balance="0.5"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude defense="defend_deep" want_peace="true"/>
</decision_entry>
<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> fortified defense
-->
<min_entry stance="AtWar" frontline_balance="1.0" is_neighbour="true" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, normal defense. If not our shadow, also want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude defense="defend_normal" want_offer_protect="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, defend normal. If our shadow, do not want to offer protectorate
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_normal" want_offer_protect="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> frontline defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> fortified defense
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude defense="defend_fortified"/>
</decision_entry>


<decision_entry>
<!--
if we're at war, and none of the previous rules apply,
then >>> fortified defense
-->
<min_entry stance="AtWar"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR 'CAN_ATTACK_FACTION', NO INVASION IF SO
</decision_entry>
-->

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT: invade_none
-->
<faction_attitude continue="true"/>
</decision_entry>

<!--
ANALYSIS OF DIPLOMATIC AGREEMENTS AND FACTION STANDING
-->

<decision_entry>
<!--
want to ally with Islamic factions
-->
<min_entry target_religion="islam"/>
<faction_attitude pts_alliance = "5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
don't want to ally with Catholic factions
-->
<min_entry target_religion="catholic"/>
<faction_attitude pts_alliance = "-20" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
By default don't want to ally
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If trusted ally, there is a 90% chance to use defaults (no invasion), cannot force invade. allows even trusted allies to occasionally backstab
-->
<min_entry trusted_ally="true"/>
<max_entry rand="0.9"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, are somewhat trustworthy and have only been allied for a medium duration, no invasion set up, cannot force invade
-->
<min_entry global_standing="0.25"/>
<max_entry num_turns_allied="10" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and have only been allied for a short duration, no invasion set up, cannot force invade
-->
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a medium time ago and are somewhat trustworthy, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we have agreed to a ceasefire only a short time ago, no invasion set up, cannot force invade
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied and we are very trustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a trustworthy ally)
-->
<min_entry global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a lot and we are not untrustworthy, there is a 80% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we like them a bit and we are not very untrustworthy, there is a 65% chance to use defaults (no invasion), cannot force invade, (we are a friendly ally)
-->
<min_entry faction_standing="0.25" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.65"/>
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If we are allied, we don't mind them and we are not very untrustworthy, there is a 50% chance to use defaults (no invasion), (we are a partially friendly ally)
-->
<min_entry faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them, there is a 75% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.5" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.75"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we like them a bit, there is a 50% chance to use defaults (no invasion), (we are a friendly neutral)
-->
<min_entry faction_standing="0.25" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.5"/>
</decision_entry>

<decision_entry>
<!--
If we are neutral and we don't hate them, there is a 25% chance to use defaults (no invasion), (we are a partially friendly neutral)
-->
<min_entry faction_standing="0.0" stance="Neutral"/>
<max_entry stance="Neutral" rand="0.25"/>
</decision_entry>

<decision_entry>
<!--
If they are our protectorate, use defaults
-->
<min_entry is_protectorate="true" />
<faction_attitude can_force_invade="false"/>
</decision_entry>

<decision_entry>
<!--
If they are a protectorate of a trusted ally, use defaults
-->
<min_entry trusted_ally_protectorate="true"/>
</decision_entry>

<decision_entry>
<!--
Not interested in factions that are not our neighbour, use defaults, may be overridden by forced/naval attacks
-->
<max_entry is_neighbour="false"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry turn_number="30" target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1500" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we've more than twice his frontline strength, then >>> invade immediate
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_immediate" invade_priority="1200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
if we're superior on the frontline, then >>> invade buildup
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="1200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
special case the slaves faction - there are all sorts of things we don't want to do with the slaves
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_opportunistic" invade_priority="1200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war and it is very early in the game, do not invade (grabbing rebel regions instead)
-->
<max_entry stance="Neutral" turn_number="10"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is greater than his,
then >>> invade none
-->
<min_entry is_neighbour="true" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && his frontline strength is more than twice ours && our free strength is less than his,
then >>> fortified defense
-->
<max_entry is_neighbour="true" frontline_balance="0.5" free_strength_balance="1.0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are his weakest neighbour && he is not at war elsewhere && we are not at war elsewhere,
then >>> frontline defense
-->
<min_entry target_weakest_neighbour="true"/>
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are not his weakest neighbour && he is not at war elsewhere,
then >>> normal defense
-->
<max_entry target_num_enemies="0" num_enemies="0"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
ALLY AGAINST
-->

<decision_entry>
<!--
if we're at war,
then >>> alliance against
-->
<min_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if slaves,
then >>> alliance against
-->
<min_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than thrice as large as ours &&
his free strength is more than four times as large as ours, AND IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours, && IS NOT OUR SHADOW FACTION >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5" target_is_shadow="false"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && he borders all our groups && his frontline strength is more than twice as large as ours &&
his free strength is greater than twice ours >>> alliance against
-->
<min_entry stance="AtWar" borders_all_our_regions="true"/>
<max_entry frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> alliance against
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> alliance against
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> alliance against
-->
<min_entry frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> alliance against
-->
<min_entry frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> alliance against
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> alliance against
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="3.0" military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="3.0" military_balance_plus_enemies="2.0"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="55" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="35" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="30" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war with anyone else && our frontline strength is more than
thrice his && overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we are at war with someone else && our frontline strength is more than
thrice his && we're 2:1 superior overall against these factions >>> invade immediate
-->
<min_entry is_neighbour="true" num_enemies="1" frontline_balance="2.0" military_balance_plus_enemies="2.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="1"/>
<faction_attitude invade="invade_immediate" invade_priority="55" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && alliance against this faction && alliance is overall superior >>> invade immediate
-->
<min_entry is_neighbour="true" frontline_balance="2.0" has_alliance_against="true" alliance_military_balance="1.0" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
1.5 times his && we outproduce him >>> invade buildup
-->
<min_entry is_neighbour="true" frontline_balance="1.5" production_balance="1.5" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_imediate" invade_priority="60" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && frontline superiority && alliance against
this faction && alliance is superior overall && he is strongest neighbour >>> invade opportunistic
-->
<min_entry is_neighbour="true" frontline_balance="1.5" has_alliance_against="true" alliance_military_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_immediate" invade_priority="55" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && our frontline strength is more than
twice his && he outproduces us && he is our strongest neighbour >>> invade raids
-->
<min_entry is_neighbour="true" frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2" trusted_ally_enemy="true"/>
<max_entry num_enemies="0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is our strongest
neighbour, then >>> plan future invasion
-->
<min_entry production_balance="1.0" strongest_neighbour="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="45" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're not at war && we're not at war with anyone else && we outproduce him && he is most desireable,
then >>> plan future invasion
-->
<min_entry production_balance="1.0" most_desirable="true" trusted_ally_enemy="true"/>
<max_entry num_enemies="0"/>
<faction_attitude invade="invade_buildup" invade_priority="40" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.0" is_neighbour="true" production_balance="2.0" military_balance="2.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="2.5" is_neighbour="true" production_balance="2.5" military_balance="2.5"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
makes ai more aggressive
-->
<min_entry frontline_balance="3.0" is_neighbour="true" production_balance="3.0" military_balance="3.0"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<!--
MAKE SURE NOT TOO MANY FRONTS
-->

<decision_entry>
<!--
Reduce invade priority if at war with more than 1 enemies
-->
<min_entry num_enemies="1"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 2 enemies
-->
<min_entry num_enemies="2"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 3 enemies
-->
<min_entry num_enemies="3"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Reduce invade priority if at war with more than 4 enemies
-->
<min_entry num_enemies="4"/>
<faction_attitude invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty easy, less likely to attack.
-->
<max_entry target_human="true" difficulty="easy"/>
<faction_attitude invade_priority="-100" alliance_against="-1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty medium, no difference
-->
<max_entry target_human="true" difficulty="medium"/>
<faction_attitude invade_priority="0" alliance_against="0" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="hard"/>
<faction_attitude invade_priority="200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If human and difficulty very hard, less likely to attack.
-->
<max_entry target_human="true" difficulty="very_hard"/>
<faction_attitude invade_priority="400" alliance_against="1" continue="true"/>
</decision_entry>

<!--
INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && his frontline strength is less than ours && his free strength is greater than ours,
then >>> conduct raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<max_entry free_strength_balance="0.7"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him, && IS NOT OUR SHADOW FACTION >>> propose he become vassal, invade immediate. If not our shadow, also want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry target_is_shadow="false"/>
<faction_attitude invade="invade_immediate" invade_priority="90" want_offer_protect="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than five times his frontline strength && we're superior overall &&
we outproduce him >>> propose he become vassal, invade immediate. If our shadow, do not want to offer protectorate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="90" want_offer_protect="false"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_immediate" invade_priority="85" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_builup" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar"/>
<faction_attitude invade="invade_opportunistic" invade_priority="65" continue="true"/>
</decision_entry>

<!--
TRUSTED ALLY INVADE DECISIONS
-->

<decision_entry>
<!--
if we're at war && his frontline strength is more than twice ours && our free strength is greater than his
then >>> deep defense
-->
<min_entry is_neighbour="true" stance="AtWar" free_strength_balance="1.0" trusted_ally_enemy="true"/>
<max_entry frontline_balance="0.5"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && he outproduces us && he is
at war with more than one faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_buildup" invade_priority="85" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we've more than twice his frontline strength && we outproduce him && alliance
against this faction, then >>> invade immediate
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="2.0" production_balance="1.0" has_alliance_against="true"/>
<faction_attitude invade="invade_immediate" invade_priority="80" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && we outproduce him,
then >>> invade buildup
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" production_balance="1.0" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_immediate" invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war && we're superior on the frontline && he outproduces us,
then >>> invade raids
-->
<min_entry is_neighbour="true" stance="AtWar" frontline_balance="1.0" trusted_ally_enemy="true"/>
<max_entry production_balance="1.0"/>
<faction_attitude invade="invade_opportunistic" invade_priority="70" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we're at war,
then >>> invade opportunistic
-->
<min_entry stance="AtWar" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" invade_priority="65" continue="true"/>
</decision_entry>

<!--
<decision_entry>
SPECIAL CASE EXISTS HERE IN CODE FOR FORCING ATTACK ON HUMAN IF AT PEACE WITH EVERYONE FOR TOO LONG (hard = 4 turns, normal = 10 turns, easy = 20 turns)
</decision_entry>
-->

</invasion_decisions>


</faction_ai_label>



<!--
/////////////////////////////////////////////////////////////
// SLAVE FACTION AI PARAMS. THEY DON'T REALLY DO ANYTHING //
/////////////////////////////////////////////////////////////
-->

<faction_ai_label name="slave_faction">

<invasion_decisions>

<decision_entry>
<!--
Hopefully make rebels more aggressive
-->
<faction_attitude invade="invade_opportunistic" invade_priority="550"/>
</decision_entry>

<decision_entry>
<!--
Just use defaults
-->
</decision_entry>

</invasion_decisions>


<defend_decisions>

<decision_entry>
<!--
Always try and defend the settlements
-->
<faction_attitude defense="defend_fortified"/>
</decision_entry>

</defend_decisions>

</faction_ai_label>


</root>


Nikolai, interesting, sounds like it should be possible to have a fairly aggressive AI with good defense if you get the invade priority right with using defend deep.

EDIT: okay with those changes some AI factions are now expanding, but others aren't. And there are absolutely no alliances by turn 20. So still having a few problems.

EDIT: Further tweaks by adding in a decision entry to give a massive boost to invade priority v slaves, and changes to some of the alliance against decisions has improved things, still needs further work though.

uanime5
11-30-2007, 12:04
Lusted you forgot to change "has_ceasehostilities" to "has_cease_hostilities" in the AI file you posted.

Lusted
11-30-2007, 12:13
Lusted you forgot to change "has_ceasehostilities" to "has_cease_hostilities" in the AI file you posted.

That's the correct code for it, look at the top of the AI file. has_ceasehostilities is correct.

CavalryCmdr
11-30-2007, 16:18
Contrary to nikolai's post concerning has_cease_hostilities my math shows has_ceasehostilities dose work (as according to invade priority in the LTGD log) as of v 1.2, perhaps they changed it in 1.3/kingdoms.

Is there an easy way to get the txt out of the 'code' box so I can put it in my xml reader without highlighting and scrolling down the whole thing? I need to see it how I'm used to working with it in order to 'see' it properly, plain txt in a file that long gives me a headache.

Lusted, you should use a min/max setting for frontline balance, I like 0.01/100. If you've read the LTGD you will notice frontline balance tends to be somewhat erratic, follow the link in the title post and I explain how it works and how to use it properly, without min/max values in the ai_db, the AI will behave as erratically as frontline_balance.

Lusted
11-30-2007, 16:29
Lusted, you should use a min/max setting for frontline balance, I like 0.01/100. If you've read the LTGD you will notice frontline balance tends to be somewhat erratic, follow the link in the title post and I explain how it works and how to use it properly, without min/max values in the ai_db, the AI will behave as erratically as frontline_balance.

I haven't had problems with the frontline balance before, i'm mostly concerned with the reduced aggressiveness of my AI since making changes to it, as it is odd for it to go from really quite expansive early on, and in wars, to vanilla levels of expansion.

alpaca
11-30-2007, 18:16
Is there an easy way to get the txt out of the 'code' box so I can put it in my xml reader without highlighting and scrolling down the whole thing? I need to see it how I'm used to working with it in order to 'see' it properly, plain txt in a file that long gives me a headache.
Click before the first letter in the box, scroll it down, then hold shift and click near the end. That should select all the text.

CavalryCmdr
11-30-2007, 19:02
Thanks alpaca, I'll take a better look at the file soon.


I haven't had problems with the frontline balance beforeMajor problem with not using min/max is easy exploits by humans, it also can cause AI confusion when combined with large number of naval invasions.

nikolai1962
12-01-2007, 06:19
On the change from has_ceasehostilities to has_cease_hostilities--dunno, since i changed it i haven't had an AI faction get excommunicated except when they had 12+ settlements (as i set them to have a 50/50 chance of ignoring it under those conditions). Strange--maybe there is something else at play.

~~~

(Big caveat as always--i've hacked my original AI profile around to make it as simple as possible to change the settings but there's always a chance of human error)

That said...

On the defend settings.

(Edit to clarify. The testing up to now has all been...
1. All the invade decisions set to invade_buildup with just two invade priorities--one for neighbour and one for non-neighbour
2. The defend settings set to either:
a) All defend_deep
b) All defend_minimal
c) A mixture of those two, either
c1) deep for non-rebels, minimal for rebels
c2) deep for neighbours, minimal for non-neighbours
c3) deep for neighbour and non-rebel, minimal for everything else.)

I set everything to defend_deep (as it's the most extreme case) and had just two invade priorities (neighbour and non-neighbour). Then I lowered those invade_priorities a few hundred each--resulting in very slow or no expansion, then i kept increasing the invade priority by 20's and 50's until the AI would *just* take the last rebel settlement. This gave me a number of 850 which for my map is the (average) invade priority neccessary for when the AI is at it's most defensive.

It's just an average though. So it was the minimum neccessary to get the AI to take the regions it really doesn't want but above what is needed to stop the turks sending too many of their armies east against rebels and holding more back to defend against the byzies. But it's a decent average position (for my map and starting armies/garrisons etc).

The AI's reluctance to take some regions seems to be based on distance definitely but also other factors. On my map they always go for the towns first--income? Adjacency to capital seems like it may be relevant. Garrison size may be relevant. Either way it seems to me what is happening is:

1. The AI file generates an invade number for a particular faction.
2. The AI then scans the possible target cities of this faction and makes a calculation. I think it is taking the invade priority from the first step and then adding or subtracting various numbers related to distance, income and possibly quite a few others.
3. If the target is below some threshold then the AI won't attack it.
4. Above a certain threshold then the AI will attack the one (or more than one) with the highest final priority.

I think the defend settings, apart from any other things they do, have a specific number attached that is subtracted from the invade_priority. I think those numbers vary in line with their listing in the AI file:

minimal->normal->raid->frontline->fortified->deep.

So if you have a region that gets attacked first turn with a particular invade priority and defend_minimal, then you increase the defend setting step by step up to deep you'll usually hit a point where the AI stops attacking. Unless the invade priority is like 1500 or something.

Anyway, next test--defend_deep for neighbouring non-rebel factions, defend_minimal for everything else.

The interesting effect here was how the AI factions gradually got more defensive as they got more neighbours. The HRE was particularly affected by this. Going back to my nice clear-cut egypt example. With these settings they attacked the remote city early on but if they lost *and by that time had touched the expanding turks* they didn't attack it again until it was the last one. This example is so useful for testing as it seems to be just on the edge of the AI's attack list so it will switch on and off with every change.


So i think with invade_immediate, priority [some number] and defend_minimal the base invade_priority the game uses to calculate actual targets to attack will be [some number]. If the target faction has a defend_deep decision paired with the invade_immediate the base priority will be [some number] minus x. Where x is the defensive offset applied by defend_deep. In fact the calculation may be the same except defend_minimal has a defensive offset of zero (or possibly even adds some).

So, say for example the offsets were zero for defend_minimal and went up fifty with each defend level. Then invade_immediate with a priority of 850 would actually be:

850 with defend_minimal
800 with defend_normal
750 with defend_raid
etc

Some targets would still be attacked if the other numbers used to select targets work in their favour. So, say for example in the above case a priority of 850 got reduced to 500 by a paired defend_deep. But the target in question was close and rich and (number of other factors) then it might still be attacked. A further away target might drop below the threshold. The same target city, when the owning faction has been given a defend_raid setting in the AI file, might have a base priority of 750, which after the other factors are taken into account gives a modified priority which is above some threshold value so it still gets attacked.

(What's so interesting about this to me is it is explaining the 50%+ "path-finding" problems that seemed unfixable. And a huge amount of the AI inconsistencies i found when messing with the path-finding.)

Also...

I originally followed the vanilla AI in giving lowered priorities to regions that were not a neighbour. Increasing them gives naval landings all over the place. So i think that fits too--the invade priority set in the AI file is used as the base number in the individual target calculations.

If the theory is right then the settings in the AI file will never be perfect for all factions, all the time as the individual targets they are looking at will vary too much over time.

notes
1. If the monetary value of the target is somehow taken into account then the the AI should get more aggressive as the factions develop their cities--can't say i've ever noticed that but i wasn't looking for it.
2. Distance is definitely involved somehow--interesting question is whether it is the fixed total movement cost or the number of turns it takes to reach. Roads/higher base movement points would then make a difference to AI aggression.

~~~

Lot of typing, need to re-read previous posts in case i've missed something...

~~~

LustedCut and pasted your AI--will take a peek but i'm thinking the numbers theory is behind your problem if it's anything like my testing. On mine the same settings do affect factions differently depending on the geography, how many neighbours etc.

edit for some examples:

As mentioned the invade priority needed to get the AI factions to take the regions they want least is high enough to make the turks send all their armies against rebels and leave none to defend against the byzies.

Poland won't do anything until around turn 18. Then they'll suddenly fly into action and take whatever surrounding regions haven't been taken. I'm thinking there must be something about their initial target (Lithuania) that brings it below the threshold which changes at some point around turn 18. If the individual factors which select the individual targets could be figured out then I think the average AI attack/defend setting could still work for all factions by tweaking the start position, at least in the early game. Will see if i can figure out what is holding them up.

In my tests the HRE was *always* more passive than the other factions when the defend settings were either completely or partially defend_deep for neighbour factions. It was always confusing me before as on mine they have lots of starting armies. When i set all the defend settings to minimal (with the same invade priority as before) they expand like crazy.

Also the numbers that make a difference can be quite small e.g to stop sicily landing at marseilles before milan got around to attacking it i had to drop the non-neighbour invade priority from 820 to 800 (on my map).

nikolai1962
12-01-2007, 06:31
Contrary to nikolai's post concerning has_cease_hostilities my math shows has_ceasehostilities dose work (as according to invade priority in the LTGD log) as of v 1.2, perhaps they changed it in 1.3/kingdoms.

Oops, are you saying it works as a negative invade offset? This could be embarassing. Strange though--in mine i have it so they immediately go to invade_none, want_peace and defend_deep when they get a papal warning. Which they do every time. It's either


<decision_entry>
<min_entry stance="AtWar" has_cease_hostilities="true"/>
<max_entry stance="AtWar" num_settlements="11"/>
<faction_attitude want_peace="true"/>
</decision_entry>

or


<decision_entry>
<min_entry stance="AtWar" num_settlements="12" has_cease_hostilities="true" frontline_balance="2.0"/>
<max_entry stance="AtWar" rand="0.3"/>
faction_attitude want_peace="true"/>
</decision_entry>

with a similar pair of invade decisons where they switch to invade_none. (May not be clear now as i used to have the defend_deep on there too but i've changed it for this testing so all the defend settings are set at the top of the decisons so it's easier to change them all at once.)

Can't see how those decisions would work if "has_cease_hostilities" wasn't being registered. But maybe it is something else and i tested it wrong. Hmm :juggle2:

nikolai1962
12-01-2007, 06:55
Dosnt appear to directly contradict anything I've seen. Distance is a factor when deciding an invasion, I've no doubt about that, and increasing invade priority will over-ride it. I've not considered a 'value' for the different defence settings, just position when an invasion is called.

Let me see if I understand your theory:
Defence 'value' - invade priority offset = % troop strength used for defence.
Everything elts used for attack.
if invade priority offset > defence 'value,' AI is blindly agressive.
if invade priority offset < defence 'value,' AI is passive.
Therefore the preceived need to link invade and defence types.

There's two bits to it. One of which i'm less sure of. The first is that the defend setting for a faction acts as an invade_priority offset, either zero at defend_minimal and increasingly negative as you go up through the list or possibly a positive offset at minimal and then getting negative. Unless i'm testing it wrong (which is possible) then this seems to be the case.

The second bit is that the averaged set of defend settings for all target factions has some overall effect similar to say the slide bar for how much of your money the AI can spend when you have your cities auto-managed. The main reason I wonder about this is the AI *seems* to merge more when they are at peace with everybody and all the defend settings are at deep than it does when some of them are minimal. This may be due to something else or i may just be imagining it.


Try, opportunistic invade setting against rebels with defend deep, following your theory, the AI should attack any rebel settlement provided they still maintain relative balance with other nearby armies. Provided your theory is correct, or near correct, this should achive almost exactly what your looking for. Invade priority dose not matter, only opportunity, so your defend deep should always override the attack, until that faction has the armies to spare.

Like I said I have not looked at it in that manner, but have not seen anything off-hand that contradicts your theory. I am quite confident I understand how invade_opportunistic works, so give the results of this test and I'll have a better idea about your theory. Logically speaking your theory is sound, so it could well be the 'missing link' in AI defence. (now if we could only figure out how to put them in the cities...)

I'll try this out. Currently have everything at invade_buildup (having everything the same makes it easier to test). I did have oppurtunistic on the "is_neighbour=false" option for rebels. With invade_buildup they attack the islands much faster now. I'm not sure how oppurtunistic works so does that fit what you're saying? I'll add it back to both neighbour and non-neighbour and see what happens.



I've been working with defend_fortified some more. With my current settings I have not yet seen the AI become 'stuck' inside a fort, it apears to be mobilizing properly for invasion and defence. I've only done general behaviour observasion so far, not detailed action. Ironically(?) these settings fit quite nicely into your theory as I understand it. Anyway, using fronline balance to dictate defence settings to default at fortified, if far weaker switch to deep, if much stronger switch to frontline. Corosponding invasion type (if at war) buildup, opportunistic and immediate.

Pretty good news. Fortified does seem the best option overall. Deep tends to leave the outer ring lightly defended. In one of my tests the settings i had got the AI to put decent garrisons in a lot of their cities but i've forgotten which combination it was.

Lusted
12-01-2007, 19:31
Very interesting info nikolai and CavalryCmdr, i'm going to have a god at making somemajor changes to my latest AI code tomorrow.

Lusted
12-01-2007, 23:11
Very useful relevant find by Alpaca:

http://www.twcenter.net/forums/showthread.php?p=2437882#post2437882

alpaca
12-02-2007, 00:05
Yeah I also found another one but don't have time to document it right now:

diplomacy_costs <receiving_faction> <proposing_faction> <opt:target_faction> <opt:settlement_name> <opt:payment_amount> <opt:payment_years>

Try it our for yourself, it's fairly self-explanatory and useful. Although it's a real shame that the console doesn't work for that command, it'd be even more useful in that case. Anyways, you can probably already use it to investigate the effects of faction standing and the like on diplomacy costs.

Besides: Did you guys every have problems with island factions? I'm having problems with the Sicilian Emirates who don't properly expand to rebel settlements with a minimal AI file (defend minimal against non-neighbors, defend frontline against neighbors and immediately invade rebels but nobody else)

CavalryCmdr
12-02-2007, 04:50
Besides: Did you guys every have problems with island factions? I'm having problems with the Sicilian Emirates who don't properly expand to rebel settlements with a minimal AI file (defend minimal against non-neighbors, defend frontline against neighbors and immediately invade rebels but nobody else) Obviously, make sure the faction has 'prefers naval invasions true' in the descr_sm_factions and can_force_invade is set to true. Just stating the obvious, because sometimes thats the easiest to over-look, no offence intended. Try positioning a navy in the strat near several logical targets, giving them a choice seems to help them focus on one for some reason. Personally I'm still having trouble with Sicily getting 'stuck' on Tunis if the Moors get it first Sicily will usually just sit there until thier entire starting force goes rebel, and by then even hard level AI is so far in debt it cant do anything for a very long time. However if they dont get stuck, or the Moors dont get Tunis first, Sicily spreads like a deamon. One thing I've done that helps them (and Russia and Scotland, most factions that have the tendency to get 'stuck' early actually) is have a lower invade priority for the first 3 or 4 turns, then boost it up.


Pretty good news. Fortified does seem the best option overall. Deep tends to leave the outer ring lightly defended. In one of my tests the settings i had got the AI to put decent garrisons in a lot of their cities but i've forgotten which combination it was. With the settings I'm currently using the AI defends the frontline (defend_fortified) unless:
A- They are totally out-matched frontline_balance and military_balance, at which time they switch to defend_deep.
B- invade_immediate is activated, at which time they switch to defend_frontline.
In either case the AI seems to pull troops out of forts either to attack or defend settlements as nessasary. Unfortunately there is still alot of room for human manipulation, but it works reasonably well and you dont need to deactivate forts. If your interested:
defend_decisions
<decision_entry>
<!--
Slave faction really requires little attention
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" want_ally="false" pts_alliance="-10" want_offer_protect="false" want_be_protect="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
Slave faction really requires little attention
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" want_ally="false" pts_alliance="-10" want_offer_protect="false" want_be_protect="false" continue="false"/>
</decision_entry>

<!--
///////////////////////////////////////////////
//// Defense settings ////
///////////////////////////////////////////////
-->

<decision_entry>
<!--
If we are at war and fairly evenly matched
Defend fortified
-->
<min_entry stance="AtWar" military_balance="0.7" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are at war and he is stronger
Defend deep
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.7" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are at war and I am stronger
Defend raids
-->
<min_entry military_balance="1.75" is_neighbour="true"/>
<max_entry is_neighbour="true"/>
<faction_attitude defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we are allied
Defend minimal
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
If we do not border and he's little or no troops in my territory
Defend minimal
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
if we do not border and he's got allot of troops in my territory
Defend deep
-->
<min_entry is_neighbour="false" stance="AtWar"/>
<max_entry is_neighbour="false" stance="AtWar"/>
<faction_attitude defense="defend_raid" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Do not want to make important decisions too early
-->
<max_entry turn_number="15" num_enemies="0"/>
<faction_attitude defense="defend_minimal" want_peace="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
At war call
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude continue="true" at_war="true"/>
</decision_entry>
invasion_decisions
<decision_entry>
<!--
try countering disable attack, I have no idea if this dose anything!!
-->
<faction_attitude can_attack_faction="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
cancelation of invasions override
-->
<min_entry is_neighbour="true" borders_all_our_regions="true"/>
<max_entry is_neighbour="true" borders_all_our_regions="true" num_settlements="3"/>
<faction_attitude can_force_invade="false" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Invade slave faction
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="10" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Invade slave faction
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" turn_number="10" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" invade_priority="1750" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Invade slave faction
-->
<min_entry target_faction="slave" turn_number="10" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" invade_priority="1400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Invade slave faction
-->
<min_entry target_faction="slave" turn_number="10" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" invade_priority="900" continue="true"/>
</decision_entry>

<decision_entry>
<!--
Invade slave faction
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="1" continue="false"/>
</decision_entry>

<decision_entry>
<!--
ignore Mongols for now
-->
<min_entry target_faction="mongols"/>
<max_entry target_faction="mongols" turn_number="65"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
ignore timurids for now
-->
<min_entry target_faction="timurids"/>
<max_entry target_faction="timurids" turn_number="144"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
ignore Aztecs for now
-->
<min_entry target_faction="aztecs"/>
<max_entry target_faction="aztecs" turn_number="165"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
Da Pope
-->
<min_entry target_faction="papal_states"/>
<max_entry target_faction="papal_states"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
DEFAULT: invade_none
Kill humans mode allows for humans who insist on attacking too soon ;)
-->
<max_entry turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
/////////////////////////////////
//// Universal ////
//////////////////////////////////
-->

<decision_entry>
<!--
If I have just accepted a ceasefire this turn,
No invasion possible.
-->
<min_entry num_turns_ceasfire="0"/>
<max_entry num_turns_ceasfire="0"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
If I have just accepted an alliance,
No invasion possible.
-->
<min_entry stance="Allied" num_turns_allied="0"/>
<max_entry stance="Allied" num_turns_allied="1"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
Default, no invasion
-->
<faction_attitude continue="true" invade="invade_none"/>
</decision_entry>

<!--
////////////////////////////////////////////////////////////////
//// Invasion Type Neighbours ////
///////////////////////////////////////////////////////////////
-->

<decision_entry>
<!--
If my frontline is too weak, bolster my forces
-->
<min_entry is_neighbour="true" frontline_balance="0.01"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude continue="true" invade="invade_buildup"/>
</decision_entry>

<decision_entry>
<!--
If he is my allies enemy but we are not at war, start preperations
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude continue="true" invade="invade_start"/>
</decision_entry>

<decision_entry>
<!--
If we are at war build invasion forces
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude continue="true" invade="invade_buildup"/>
</decision_entry>

<decision_entry>
<!--
If we are at war, AND he is stronger then me, AND he is outproducing me, AND my frontline is not superior, attack opportune targets
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9" production_balance="0.9"/>
<faction_attitude continue="true" invade="invade_opportunistic"/>
</decision_entry>

<decision_entry>
<!--
If my frontline is powerful enough, attack now
-->
<min_entry is_neighbour="true" frontline_balance="2.5"/>
<max_entry is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude continue="true" invade="invade_immediate"/>
</decision_entry>

<!--
///////////////////////////////////////////////////////////////////////
//// Invasion Type Not Neighbours ////
///////////////////////////////////////////////////////////////////////
-->

<decision_entry>
<!--
If he is the enemy of an ally, start invasion preperations
-->
<min_entry trusted_ally_enemy="true" is_neighbour="false"/>
<max_entry trusted_ally_enemy="true" is_neighbour="false"/>
<faction_attitude continue="true" invade="invade_start"/>
</decision_entry>

<decision_entry>
<!--
If we are at war, build an invasion force
-->
<min_entry is_neighbour="false" stance="AtWar"/>
<max_entry is_neighbour="false" stance="AtWar"/>
<faction_attitude continue="true" invade="invade_buildup"/>
</decision_entry>

<decision_entry>
<!--
If he is an allies enemy AND I have the resources AND he is not too powerful, invade opportune targets
-->
<min_entry trusted_ally_enemy="true" is_neighbour="false" free_strength_balance="1.1" military_balance="0.75"/>
<max_entry trusted_ally_enemy="true" is_neighbour="false"/>
<faction_attitude continue="true" invade="invade_opportunistic"/>
</decision_entry>

<decision_entry>
<!--
If we are at war AND I have the resources AND he is not too powerful, invade opportune targets
-->
<min_entry is_neighbour="false" stance="AtWar" free_strength_balance="1.1" military_balance="0.75"/>
<max_entry is_neighbour="false" stance="AtWar"/>
<faction_attitude continue="true" invade="invade_opportunistic"/>
</decision_entry>

<!--
//////////////////////////////////////////////////////////////
//// Invasion Type Desperate ////
/////////////////////////////////////////////////////////////
-->

<decision_entry>
<!--
Invasion type ; If we have no hope of matching his military might,
Opportunity
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" free_strength_balance="0.666" alliance_military_balance="0.666" military_balance="0.666"/>
<faction_attitude continue="true" invade="invade_opportunistic"/>
</decision_entry>

<decision_entry>
<!--
Invasion type ; If we have no hope of matching his military might,
Opportunity
-->
<min_entry trusted_ally_enemy="true" num_settlements="3"/>
<max_entry trusted_ally_enemy="true" free_strength_balance="0.555" alliance_military_balance="0.555" military_balance="0.555"/>
<faction_attitude continue="true" invade="invade_opportunistic"/>
</decision_entry>


Oops, are you saying it works as a negative invade offset? This could be embarassing.
....

Can't see how those decisions would work if "has_cease_hostilities" wasn't being registered. But maybe it is something else and i tested it wrong. Hmm
I've never tried has_cease_hostilities, it may work. Honestly I've not specifically tested has_ceasehostilities, but I have done numerous math tests on invade priority (which is affected by has_ceasehostilities) and they always work out numerically according to the LTGD log's invade priority.
I will specifically test both shortly.


1. The AI file generates an invade number for a particular faction.
2. The AI then scans the possible target cities of this faction and makes a calculation. I think it is taking the invade priority from the first step and then adding or subtracting various numbers related to distance, income and possibly quite a few others.
3. If the target is below some threshold then the AI won't attack it.
4. Above a certain threshold then the AI will attack the one (or more than one) with the highest final priority.

This all fits in with my experiences, on #4, the AI will definately attack multiple targets if the invade_priority for each is within a cirtain range, that range depending on the precived strength of the considering faction.


I originally followed the vanilla AI in giving lowered priorities to regions that were not a neighbour. Increasing them gives naval landings all over the place. So i think that fits too--the invade priority set in the AI file is used as the base number in the individual target calculations. Diferent regions priorities with the base being the invade priority for the target faction is easily seen in the LTGD with naval invasions your given the final invade priority for the individual target settlements. I have a list of what province is what number for the vanilla map somewhere, I'll see if I can find it if anyone wants it.

@Lusted, I did some quick experiments with the AI profile you posted. I think nikolai1962 is correct in his view of defence type having a numerical offset on invade priority. By seperating the Slave faction to the top of the file as I sugested all factions spread reasonably well with a few exceptions, invariably they were factions easily threatend and took up defensive positions. I'll do a few more tests when I have the chance.

nikolai1962
12-02-2007, 10:21
Very useful relevant find by Alpaca:

Very useful.



Besides: Did you guys every have problems with island factions? I'm having problems with the Sicilian Emirates who don't properly expand to rebel settlements with a minimal AI file (defend minimal against non-neighbors, defend frontline against neighbors and immediately invade rebels but nobody else)

(Prefers naval and can_force_invade as CavalryCmdr said)

Also the actual invade_priority number is a determining factor for distance. On mine, with all the defend decisions at defend_deep a base invade priority of 800 is enough to get sicily to tunis and sardinia but not as far as ajaccio. Also, at that value sicily/milan won't hop to Palma from sardinia/corsica. An invade_priority of 820 (all defend_deep) is enough to get sicily to ajaccio and also marseilles, and from there to Palma.

With everything at defend_minimal a base invade_priority of 800 was enough.

Also ports. I got fed up with sicily glitching when they landed in durazzo so i moved their port over to the other side of Italy next to Naples. Seems to determine the basic direction they "look" for naval expansion. sicily only goes west and north now. Probably not directly relevant to your problem but useful generally for trying to set up naval stuff.

nikolai1962
12-02-2007, 11:09
Personally I'm still having trouble with Sicily getting 'stuck' on Tunis if the Moors get it first Sicily will usually just sit there until thier entire starting force goes rebel, and by then even hard level AI is so far in debt it cant do anything for a very long time. However if they dont get stuck, or the Moors dont get Tunis first, Sicily spreads like a deamon. One thing I've done that helps them (and Russia and Scotland, most factions that have the tendency to get 'stuck' early actually) is have a lower invade priority for the first 3 or 4 turns, then boost it up.

Noticed the same thing and can happen with sicily over durazzo too. I'm thinking it is a side-effect of forced invasions maybe? If they're assigned a target this way and then don't take it they seem to lose their way completely.

As a side-note to the second part the AI does seem to be more *efficiently* aggressive sometimes when they're a bit less aggressive overall. I've been thinking of having some early game mini-profiles for specific factions which get switched to the main one after x turns. On the other hand i've been thinking of giving factions like egypt, which have no neighbours and lots of rebels, an early game mini-profile which is extra-aggressive towards rebels. W



With the settings I'm currently using the AI defends the frontline (defend_fortified) unless...

Will defo try those out.

Currently going backwards to try and nail down some actual numbers and using a stripped-down testing mini-profile where it is easy to change all the settings. I tried the invade_oppurtunistic idea but very weird things happened so i thought it was time to stop editing my main profile and write this instead as otherwise i'm probaly getting wrong results through typos etc.

I want to see if i can pry out some approximate numbers relating to the offsets and also to distance at least.


<faction_ai_label name="testing">

<defend_decisions>

<decision_entry>
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_minimal"/>
</decision_entry>

<decision_entry>
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" defense="defend_minimal"/>
</decision_entry>

<decision_entry>
<min_entry is_neighbour="true"/>
<faction_attitude defense="defend_deep"/>
</decision_entry>

<decision_entry>
<faction_attitude defense="defend_minimal"/>
</decision_entry>

</defend_decisions>


<invasion_decisions>

<decision_entry>
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="820"/>
</decision_entry>

<decision_entry>
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude invade="invade_buildup" invade_priority="800"/>
</decision_entry>


<decision_entry>
<min_entry is_neighbour="true"/>
<faction_attitude invade="invade_none" can_force_invade="false"/>
</decision_entry>

<decision_entry>
<faction_attitude invade="invade_none" can_force_invade="false"/>
</decision_entry>

</invasion_decisions>


</faction_ai_label>



I've never tried has_cease_hostilities, it may work. Honestly I've not specifically tested has_ceasehostilities, but I have done numerous math tests on invade priority (which is affected by has_ceasehostilities) and they always work out numerically according to the LTGD log's invade priority.
I will specifically test both shortly.

I'll have to re-test it. Quite possible I've made a mistake.

Speaking of which one of my previous "seems to be" theories wasn't right. Having all the defend settings the same e.g defend_deep doesn't make them merge more. Just a side-effect of me mainly watching one faction at a time when testing. Factions with roughly circular terriotories centred on their capital can be made to merge almost 100% but it's more a function of the basic geometry it seems.



This all fits in with my experiences, on #4, the AI will definately attack multiple targets if the invade_priority for each is within a cirtain range, that range depending on the precived strength of the considering faction.

Diferent regions priorities with the base being the invade priority for the target faction is easily seen in the LTGD with naval invasions your given the final invade priority for the individual target settlements. I have a list of what province is what number for the vanilla map somewhere, I'll see if I can find it if anyone wants it.

Glad you mentioned that. I noticed those priorities being adjusted when i skimmed the log but i hadn't thought about using them to give me a baseline for the sort of number ranges the game is using. I could use a set of them to help figure it out. I'd definitely find a list of region id's useful if it's easy to paste here.

Currently it's looking like the ranges are quite small, (need to test a lot more specifically to be sure), but drops in 10s or 20s seem enough to significantly alter the distance the AI will mount naval landings.

Apart from anything else it does I'm thinking the invade priority acts as a kind of "desire filter" so, if the numbers being used by the game to decide the final invade priority are quite small, then too wide a variation in the set of invade_priorities in the AI file may end up having too exaggerated an effect i.e too aggressive or too passive.

Will see. I'm going to pick some test cities and use my simplified profile and try and nudge the invade priority up and down until i get roughly the number that is the minimum for a faction to attack then try and change settings to see if i can get some rough numbers. Will probably try a naval landing one as i can use the priority offsets in the log file as clues.

nikolai1962
12-02-2007, 11:55
Example of what i mean about having early game mini-profiles.

On my map Hungary has the first, uncontested shot, at Iasi and Bucharest but they always go for Zabgreb and Belgrad, I assume because of the gold mines, which are heavily contested by both Venice and HRE. So they often lose there plus, while they were fighting there, the byzies sneak in and grab Iasi and Bucharest leaving Hungary very weak.

If i have the base invade priority much higher Hungary seems less choosy and goes for Iasi and Bucharest and ends up (on average) in a better position long-term vis a vis the byzies. Trouble is having the base invade priorities too high makes the AI ignore their defences. So you get situations like Hungary continuing to expand into russia even though their core cities are being taken by the byzies.

May be possible with all the right settings to prevent this sort of thing generally but if not a mini-profile just for Hungary with a higher invade setting vs rebels that gets switched to the main profile after the first few turns might work. Somehow manipulating the percieved value of a region would work too but i'd want something that only tricked the AI into thinking a region was more valuable than it was as i don't want gold mines everywhere :)

There's a few factions like that which could possibly do with slightly different decisions early on. Denmark on mine needs quite a high invade priority to bother with the scandinavian regions and is currently determining the minimum invade priority i need for the whole map. That's another case where if i figured out something separate for denmark i could reduce the baseline invade priority for my defensive AI.

~~~

Typing the above jus made me realise something. I have my base invade priority set at the point where the least wanted city (Oslo) is *just* attacked. Denmark often loses these attacks because they send really tiny armies to get it. Just dawned on me (possibly obvious to everyone else) that the final invade priority may well influence the size of army the AI sends. Not so much at the beginning of the game when they attack with stacks you have set up in the strat file but after the first wave of rebel targets when their armies have been fragmented a bit by casualties, garrisons, new recruitment etc.

Relates to another problem i have with the early expansion on my map. I split zagreb into three regions. Two of the three have gold mines, the actual Zagreb doesn't. I've had endless problems getting venice to expand properly because however i set up their start armies they always reshuffled them into two armies--a huge one for taking one of the goldmine regions and a tiny one for zagreb. The more starting units i gave them just increased the size of the goldmine army leaving the zagreb one the same size. The AI always making the zagreb army just the right size to consistently *fail* to take zagreb. Obvious now i see it.

So thats another factor to take into account maybe. The final invade priority affecting AI army size.

alpaca
12-02-2007, 13:35
Sorry I didn't explain my problem properly (was a bit tired :sweatdrop: )

The actual problem is this: Sicily in II is much, much bigger than in vanilla, therefore it has 8 regions (may be 9, not quite sure). Not all of these belong to the Sicilian Emirates at the start. So I want them to try and take a few of the settlements, but they just seem to sit there like a duck. This doesn't seem to have anything to do with naval invasions as they didn't even plan any.

What's even weirder is that I think it worked with the vanilla profile, so maybe I'll just have to investigate a bit more.

Lusted
12-02-2007, 13:44
Thanks for all the info nikolai/CavalryCmdr, i'm going to go through and tweak my defend settings, and invade priorities today. I'm trying to decide between defend decision for every invade decision, or a smaller number of defend decisions to try and improve Ai defense of provinces.

nikolai1962
12-06-2007, 05:56
Sorry I didn't explain my problem properly (was a bit tired :sweatdrop: )

The actual problem is this: Sicily in II is much, much bigger than in vanilla, therefore it has 8 regions (may be 9, not quite sure). Not all of these belong to the Sicilian Emirates at the start. So I want them to try and take a few of the settlements, but they just seem to sit there like a duck. This doesn't seem to have anything to do with naval invasions as they didn't even plan any.

What's even weirder is that I think it worked with the vanilla profile, so maybe I'll just have to investigate a bit more.


Could just be the numbers possibly, as the invade priority seems to act as a kind of desire filter which includes distance between settlements as a factor in how desirable a target is?

~~~

@CavalryCmdr

Retried your opportunistic suggestion (without the spelling error this time). Works very well indeed for my "defensive" AI. Slower but more efficient and thereby ending up faster. Seems to be a lot less retreating going on with that setting so it may take more account of relative strength and attack more wisely. Very good tip.

nikolai1962
12-06-2007, 05:58
Thanks for all the info nikolai/CavalryCmdr, i'm going to go through and tweak my defend settings, and invade priorities today. I'm trying to decide between defend decision for every invade decision, or a smaller number of defend decisions to try and improve Ai defense of provinces.


Any feedback on what you think works best would be cool to hear. Particularly on the bit i bolded.

RL stuff is interfering with my testing at the moment but i want to try and figure out some numbers soon,, if it's possible.

Lusted
12-06-2007, 11:35
RL stuff is interfering with my testing at the moment but i want to try and figure out some numbers soon,, if it's possible.

Same, so i haven't had a chance to try my reduced defend decisions yet, will hopefully be doing some of that today.

What i'm thinking of doing is reducing the defend decisions to just defence options, then move all decisions relating to alliances, peace, protectorates etc. into the invade decisions so that those decisions can default to invade_none, whereas with defend decisions i'm worried that with multiple similar decisions but with one having a diplomatic decision and other the defend type define the diplomatic one might default to defend_normal or something.

alpaca
12-06-2007, 15:42
Could just be the numbers possibly, as the invade priority seems to act as a kind of desire filter which includes distance between settlements as a factor in how desirable a target is?
Probably not as other invade priorities are set to -1.

Lusted
12-07-2007, 11:17
I've embarked on a complete redo of my AI, starting from scratch, instead of modifying existing versions. I'll report back on how it goes as it should be interesting.

EDIT: early tests are promising, though i've got no code relating to alliances, wanting peace, protectorates in yet, or assigning invade priorities. I've based some of mine off of CavalryCmdrs work, but also doing a lot of it myself. Should be interesting to see how it performs once it's all done.

Lusted
12-07-2007, 22:30
Right, here is now the basic invade and defend code for my AI(heavily influenced by this topic and CavalryCmdrs code as you can probably tell) that i'm fairly happy with, though it's still not quite as aggressive v rebels as i would like and it's not doing as many naval invasions as i'd like(i probably need to make some tweaks to the force invade settings). I'm now going to add in the relevant religious coding for certain profiles so i can then run a few test campaigns and make adjustments, and further adjustments to diplomacy.

Invade:


<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-3" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.75"/>
<max_entry is_neighbour="true" faction_standing="0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.5"/>
<max_entry is_neighbour="true" faction_standing="0.25"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
IF NEIGHBOUR AND WEAKER FRONTLINE > INVADE BUILDUP
-->
<min_entry is_neighbour="true" frontline_balance="0.1"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLYS ENEMY AND NOT AT WAR > INVADE BUILDUP
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
IF NOT NEIGHBOUR
-->

<decision_entry>
<!--
IF ENEMY OF TRUSTED ALLY > INVADE BUILDUP
-->
<min_entry is_neighbour="false" trusted_ally_enemy="true"/>
<max_entry is_neighbour="false" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="false"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR + RESOURCES > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="false" military_balance="1.1" free_strength_balance="1.1"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>


<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVE > REALLY WANT TO INVADE FOR QUICK BULDUP OF EMPIRES
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="20000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

Defend:


<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

SigniferOne
12-08-2007, 00:48
Not the most productive comment, but I think exposing the AI will be one of M2TW's greatest things.

Lusted
12-08-2007, 13:33
And lo the reason why my AI's been less aggressive comes to light, and of course the reasons not in the campaign AI file. It was this line in the config_ai_battle.xml file that i'd increased for this round of AI testing but forgot about:

<friendly-to-enemy-strength-ratio>1.0</friendly-to-enemy-strength-ratio>

I had it at 1.2, changing it to 1.0 made the AI expand more early on. So i think i'll stick with that setting from now on.

SigniferOne
12-09-2007, 02:27
That ratio determines what, the proportion of friendly-to-enemy units that would be considered evenly matched?

Lusted
12-09-2007, 17:00
That ratio determines what, the proportion of friendly-to-enemy units that would be considered evenly matched?

I think so, i believe it is linked to the ratio rating you get on battles(eg evenly matched etc).

SigniferOne
12-10-2007, 01:31
To follow up, increasing the ratio (assuming we're right about what it means) would make larger armies think they're only equal to smaller armies, and thus be a lot less willing to engage in battles?

Lusted
12-10-2007, 10:33
To follow up, increasing the ratio (assuming we're right about what it means) would make larger armies think they're only equal to smaller armies, and thus be a lot less willing to engage in battles?

Yes, the Ai would want to engage other stacks only when at an advantage.

uanime5
12-10-2007, 13:01
Is it possible to make the AI want to ally with the player when the player is a small (low number of settlements) or weak (small army) faction but ally against the player when they become larger (many settlements) more powerful (large army)?

This would increase the usefulness of diplomacy because at the start of the game diplomactic agreements would benefit the player because they are less likely to be attacked but when the player is stronger they would act as a hinderance because the AI is more likely to ally against the player (if the AI allied factions would all declare war on and attack the player at the same time this would make the last part of the campaign more challenging than just annexing weaker factions).

Lusted
12-10-2007, 13:10
Is it possible to make the AI want to ally with the player when the player is a small (low number of settlements) or weak (small army) faction but ally against the player when they become larger (many settlements) more powerful (large army)?

Yeah that's pretty easy, just a simple decision for the ally with small human thing with a max settlement number of 5 or something which has a positive pts_alliance number, and then one with a min settlements of say 15, or uses the military_balance, and have that give a negative pts_alliance number and also have an alliance_against setting. All fairly easy to do.

SigniferOne
12-13-2007, 20:07
What's the story with vassalage? Have you guys noticed whether AI goes passive under vassalage, and is this intended behavior?

CavalryCmdr
12-14-2007, 04:28
Sorry, emergency RL issues came up...


@CavalryCmdr

Retried your opportunistic suggestion (without the spelling error this time). Works very well indeed for my "defensive" AI. Slower but more efficient and thereby ending up faster. Seems to be a lot less retreating going on with that setting so it may take more account of relative strength and attack more wisely. Very good tip.
In that case I'd say your ideas of how defend decisions offset invade priority are quite correct. Unfortunately invade_opportunistic is not ideal for the very reason it works well with your setup, it ignores invade priority completely, limiting control of the AI's behaviour specifically when fighting multiple fronts and should only be used when already at war with a faction, or with very strict decision settings.


To follow up, increasing the ratio (assuming we're right about what it means) would make larger armies think they're only equal to smaller armies, and thus be a lot less willing to engage in battles?
Trickyer to use then you'd think though as it also effects in-battle behaviour. Too high a setting can easily re-create the pasive battle AI bug, specifically in evenly matched battles.


Is it possible to make the AI want to ally with the player when the player is a small (low number of settlements) or weak (small army) faction but ally against the player when they become larger (many settlements) more powerful (large army)?
As Lusted said, easy, made even easier since vanilla descr_faction_standing.txt is already designd to create similar effects. However, doing so in a balanced manner to immitate 'intimidation' factor is a bit more complicated, specifically with 'alliance_against' being fubar.


What's the story with vassalage? Have you guys noticed whether AI goes passive under vassalage, and is this intended behavior?
According to the LTGD log the total for a vassal's invasion decision is "I'm a vassal so cannot attack." and it dosnt even prosess the invade decisions at all. This means a Vassal faction can only attack other armies in thier territory. I belive they still follow the hard-coded attack the human faction if use_cheat_overrides is set to true.

uanime5
12-15-2007, 17:09
Another thing you might want to change is the autoresolve, which has a limit so you can only kill / capture so many soldiers. While this is good for battles on the campaign map it is problematic when sieging the AI because autoresolving means you don't have to defeat the AI's whole army; leading to fewer casualties on your side, while the remaining soldiers in the AI armies all die when you capture the settlement. For sieges you should have to kill or capture most of the Ai's army when autoresolving.

Lusted
12-16-2007, 18:44
Here's my final campaign AI file if anyones interested in what i ended up with:


<?xml version="1.0"?>
<root>
<!--

// The trusted ally global parameters specify the minimum faction standing thresholds for a target faction to be
// considered a trusted ally. We can use target faction standing parameters directly in invasion/defend decisions
// but the trusted ally data allows us to use additional entry parameters: trusted_ally_enemy and trusted_ally_protectorate
// that we cannot measure directly for a target faction. An AI faction may also try and aid its trusted allies (hence the
// reverse checks on standings to avoid helping allies it shouldn't)

<trusted_ally_fs_threshold float="0.4"/> // min threshold for how much we like the target faction to consider them a trusted ally
<trusted_ally_target_fs_threshold float="0.4"/> // min threshold for how much the target faction likes us to consider them a trusted ally
<trusted_ally_target_human_fs_threshold float="0.0"/> // min threshold for how much the target (human) faction likes us to consider them a trusted ally
<trusted_ally_gs_threshold float="-1.0"/> // min threshold for how trustworthy we are to consider the target faction a trusted ally
<trusted_ally_target_gs_threshold float="-0.1"/> // min threshold for how trustworthy is the target faction to consider them a trusted ally
<trusted_ally_enemy_auto_war bool="false"/> // flag to indicate if a faction automatically goes to war with a trusted allies enemy

<use_cheat_overrides bool="true"/> // determines if cheat overrides (force peace with ai, force attack with humans) are applied
<invade_priority_fs_modifier float="-400.0"/> // modifies the final invade priority for new faction targets by += (faction_standing * modifier) {makes factions more likely to start war with disliked targets}
<invade_priority_gs_modifier float="0.0f"/> // modifies the final invade priority for new faction targets by += (global_standing * modifier) {makes factions more likely to start war with untrustworthy targets}
<invade_priority_assistance_offset int="200"/> // modifies the final invade priority for new faction targets where military assistance has been asked by += (offset) {makes factions more likely to start war with military assistance targets}
<invade_priority_min int="50"/> // min clamp for final invade priorities calculated
<invade_priority_max int="1000"/> // max clamp for final invade priorities calculated


// Each faction has an 'ai_label' specified in the campaign descr_strat.txt. This ai_label must correspond to a 'faction_ai_label'
// entry specified in this database (e.g. 'default', 'catholic', 'papal_states'). The 'default' ai_label should always exist
// and is used if a specified ai_label cannot be found. Note that each ai_label is independent (i.e. 'catholic' ai_label does
// not inherit any data from 'default') hence care should be taken when adding new entries to ensure that any relevant global
// entries are added to all other ai_labels. Additionally, the ai_labels can be tested through event conditions and set through
// a script command, potentially allowing ai behaviour to be changed dynamically in game depending on current game state.

<faction_ai_label name="default"> :: The label for a following set of campaign ai faction parameters


// The ai_labels specify the structure of the long term goal director (LTGD) which drives the high level campaign AI.
// At the start of every factions turn (or when diplomacy changes), the LTGD is re-evaluated as follows:
// for every target faction (all other factions), evaluate the defend decisions
// for every target faction, evaluate the invasion decisions
// any invasion priorities are modified by the faction standing (relationship) towards the target
// depending on current game state, a new target with a high invasion priority may be selected to invade
// the LTGD can be debugged with the preferences '[log] level = ai.ltgd trace' and '[ai] ltgd_logging = true.


// The 'defend_decisions' entry specifies a list of decision entries related to ai defence strategies. To evaluate a defence
// strategy, a set of parameters is built and the list of decision entries is iterated until an entry satisfies the min and max
// conditions for the set of parameters. As soon as an entry is satisfied (min <= current <= max), the iteration ends. The decision
// is taken from the default 'faction_attitude' parameters with certain parameters overridden. The 'min_entry' specifies the minimum
// thresholds specified for evaluation and the 'max_entry' specifies the maximum. Note that care should be taken when entering new
// entries since as soon as the thresholds for an entry are successfully met, the iteration ends. An exception to this is the use of
// the 'continue' faction_attitude parameter, which allows the decision iteration to continue (This is useful for changing certain
// parameters of the faction_attitude but allowing the process to continue so other entries can apply additional modifications).

<defend_decisions> :: List of ai defend decisions. when choosing a decision, code will iterate from first to last until a set of thresholds succeeds

<decision_entry> :: An individual decision entry

<min_entry :: The minimum threshold for decision comparison
frontline_balance="0.0" :: ratio of factions frontline military strength vs the target
military_balance="0.0" :: ratio of factions overall military strength vs the target
production_balance="0.0" :: ratio of factions overall production strength vs the target
target_num_enemies="0" :: the number of enemies the target has
num_enemies="0" :: the number of enemies the faction has
has_alliance_against="false" :: is the faction part of an alliance against target
military_balance_plus_enemies="0.0" :: ratio of factions overall military strength vs the target (plus all of its enemies)
alliance_military_balance="0.0" :: ratio of factions (plus its allies) overall military strength vs the target
strongest_neighbour="false" :: is the target the factions strongest neighbour
most_desirable="false" :: is the target the factions most desirable target
faction_standing="-1.0" :: how much does the faction like the target
target_global_standing="-1.0" :: how trustworthy is the target to the rest of the world
target_faction_standing="-1.0" :: how much does the target faction like this faction
global_standing="-1.0" :: how trustworthy is this faction to the rest of the world
target_religion="catholic" :: the religion of the target (see descr_religions.txt)
enemy_excommunicated="false" :: is the target excommunicated
excommunicated="false" :: is this faction excommunicated
num_turns_allied="0" :: the number of turns since the faction agreed to an alliance with the target
num_turns_ceasfire="0" :: the number of turns since the faction has agreed to a ceasefire with the target (-1 for no agreement)
stance="Allied" :: diplomatic stance with the target (Allied, Neutral, AtWar)
target_faction="england" :: target faction label (see descr_sm_factions.txt)
target_human="false" :: is the target a human player
target_is_shadow="false" :: is the target this factions shadow faction
turn_number="0" :: the game turn number (starting at 0)
is_protectorate="false" :: is the target our protectorate
is_protectorate_of_catholic="false" :: is the target a protectorate of a non-excommunicated catholic faction
free_strength_balance="0.0" :: ratio of factions free military strength vs the target
borders_all_our_regions="false" :: does the target border on all the factions region groups
target_weakest_neighbour="false" :: is the faction the targets weakest neighbour
has_ceasehostilities="false" :: does the faction have a cease hostilities mission against the target from the papal faction
is_neighbour="false" :: does the target neighbour on any of the factions regions
trusted_ally="false" :: is the target a trusted ally (they like us more than fs_thresh, and their global standing > gs_thresh, and they are allied)
trusted_ally_enemy="false" :: is the target an enemy of a trusted ally
trusted_ally_protectorate="false" :: is the target a protectorate of a trusted ally
num_settlements="0" :: how many settlements does the faction own
rand="0.0" :: a random value
difficulty="easy"/> :: the chosen difficulty for the current local player (easy, medium, hard, very_hard)

<max_entry :: The maximum threshold for decision comparison
frontline_balance="999.0"
military_balance="999.0"
production_balance="999.0"
target_num_enemies="999"
num_enemies="999"
has_alliance_against="true"
military_balance_plus_enemies="999.0"
alliance_military_balance="999.0"
strongest_neighbour="true"
most_desirable="true"
faction_standing="1.0"
target_global_standing="1.0"
target_faction_standing="1.0"
global_standing="1.0"
target_religion="heretic"
enemy_excommunicated="true"
excommunicated="true"
num_turns_allied="999"
num_turns_ceasfire="999"
stance="AtWar"
target_faction="slave"
target_human="true"
target_is_shadow="true"
is_protectorate="true"
is_protectorate_of_catholic="true"
free_strength_balance="999.0"
borders_all_our_regions="true"
target_weakest_neighbour="true"
has_ceasehostilities="true"
is_neighbour="true"
trusted_ally="true"
trusted_ally_enemy="true"
trusted_ally_protectorate="true"
num_settlements="999"
rand="1.0"
difficulty="very_hard"/>

<faction_attitude :: A list of modifiers to apply if min and max entries above are successful
defense="defend_normal" :: The long term defense type (defend_minimal, defend_normal, defend_raid, defend_frontline, defend_fortified, defend_deep)
defend_priority="0" :: The defensive priority of achieving stance against this faction (NOT USED AT PRESENT) (additive with previous decisions this turn)
invade="invade_none" :: The long term invade type (invade_buildup, invade_immediate, invade_raids, invade_opportunistic, invade_start, invade_none)
invade_priority="0" :: priority of achieving invasion against this faction (additive with previous decisions this turn). Compared with priority for decisions against all other factions to choose highest. Value modified internally by faction standing.
at_war="false" :: are we at war with this enemy
want_peace="false" :: do we want to be at peace with this faction
want_ally="false" :: do we want to ally with this faction
want_be_protect="false" :: do we want to be a protectorate of this faction
want_offer_protect="false" :: do we want to offer protectorate status to this nation
force_invade="false" :: must we invade now
alliance_against="0" :: how much do we want to have an alliance against this nation (additive with previous decisions this turn)
pts_desire="0" :: points total for measuring our desire for this faction's territory (additive with previous decisions this turn)
pts_alliance="0" :: points total for measuring how much we want to be allies with these people (additive with previous decisions this turn)
can_force_invade="true" :: can naval or forced invasion settings overwrite invade parameters
continue="false"/> :: do we stop evaluating decision entries (false) or continue

</decision_entry>

</defend_decisions>


// The 'invasion_decisions' entry specifies a list of invasion entries related to ai invasion strategies. This process
// is virtually identical to the defence decision process but is evaluated as a separate stage.

<invasion_decisions> :: List of ai invasion decisions. when choosing a decision, code will iterate from first to last until a set of thresholds succeeds (uses identical data to defend decisions)

<decision_entry> :: An individual decision entry
<min_entry/> :: The minimum threshold for decision comparison
<max_entry/> :: The maximum threshold for decision comparison
<faction_attitude/> :: A list of modifiers to apply if min and max entries above are successful
</decision_entry>

</invasion_decisions>

-->


<!--
//////////////////////
// GLOBAL AI PARAMS //
//////////////////////
-->

<trusted_ally_fs_threshold float="0.3"/>
<trusted_ally_target_fs_threshold float="0.3"/>
<trusted_ally_target_human_fs_threshold float="0.3"/>
<trusted_ally_gs_threshold float="-0.1"/>
<trusted_ally_target_gs_threshold float="-0.1"/>
<trusted_ally_enemy_auto_war bool="false"/>

<use_cheat_overrides bool="false"/>
<invade_priority_fs_modifier float="-400.0"/>
<invade_priority_gs_modifier float="-200.0f"/>
<invade_priority_assistance_offset int="200"/>
<invade_priority_min int="50"/>
<invade_priority_max int="1500"/>

<!--
///////////////////////////////////////
// DEFAULT AI PARAMS. DO NOT REMOVE //
///////////////////////////////////////
-->

<faction_ai_label name="default">

<defend_decisions>

<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

</defend_decisions>

<invasion_decisions>

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-2" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>
<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.75" free_strength_balance="0.75"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED AND LALST SETTLEMENT, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.8" free_strength_balance="0.8" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.75"/>
<max_entry is_neighbour="true" faction_standing="0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.5"/>
<max_entry is_neighbour="true" faction_standing="0.25"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
IF NEIGHBOUR AND WEAKER FRONTLINE > INVADE BUILDUP
-->
<min_entry is_neighbour="true" frontline_balance="0.1"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLYS ENEMY AND NOT AT WAR > INVADE BUILDUP
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
IF NOT NEIGHBOUR
-->

<decision_entry>
<!--
IF ENEMY OF TRUSTED ALLY > INVADE BUILDUP
-->
<min_entry is_neighbour="false" trusted_ally_enemy="true"/>
<max_entry is_neighbour="false" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="false"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR + RESOURCES > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="false" military_balance="1.1" free_strength_balance="1.1"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_opportunistic" continue="true" can_force_invade="true"/>
</decision_entry>

<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVE > REALLY WANT TO INVADE FOR QUICK BULDUP OF EMPIRES
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="20000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

</invasion_decisions>

</faction_ai_label>


<!--
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PAPAL FACTION AI PARAMS. REQUIRES SPECIAL STUFF TO NOT ALLOW ATTACKING NON-EXCOMMUNICATED CATHOLIC FACTIONS //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->

<faction_ai_label name="papal_faction">

<defend_decisions>

<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

</defend_decisions>

<invasion_decisions>

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
DON'T ALLY ISLAMIC FACTIONS
-->
<min_entry target_religion="islam"/>
<min_entry target_religion="islam"/>
<faction_attitude want_ally="false" pts_alliance="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
MAKE PAPACY UNLIKELY TO ALLY
-->
<min_entry faction_standing="0.6" target_global_standing="0.4" enemy_excommunicated="false"/>
<max_entry rand="0.15"/>
<faction_attitude want_ally="true" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-2" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>
<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.75" free_strength_balance="0.75"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED AND LALST SETTLEMENT, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.8" free_strength_balance="0.8" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.75"/>
<max_entry is_neighbour="true" faction_standing="-0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.5"/>
<max_entry is_neighbour="true" faction_standing="-0.25"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true" faction_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true" global_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
FOR CATHOLICS
-->

<decision_entry>
<!--
IF TARGET NOT EXCOMMUNICATED, CANNOT FORCE INVADE, INVADE NONE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" enemy_excommunicated="false"/>
<max_entry is_neighbour="true" enemy_excommunicated="false"/>
<faction_attitude can_force_invade="false" invade="invade_none" invade_priority="-400" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF CEASE HOSTILITIES, INVADE NONE, CANNOT FORCE INVADE, REDUCE INVADE PRIORITY
-->
<min_entry faction_standing="-0.25" has_ceasehostilities="true" global_standing="-0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" invade_priority="-250" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF CEASE HOSTILITIES, INVADE NONE, CANNOT FORCE INVADE, REDUCE INVADE PRIORITY, RANDOMISED SLIGHTLY
-->
<min_entry has_ceasehostilities="true"/>
<max_entry rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET NON-EXCOMMUNICATED CATHOLIC AND WE LIKE THEM, REDUCE INVADE PRIORITY
-->
<min_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET NON-EXCOMMUNICATED CATHOLIC, REDUCE INVADE PRIORITY
-->
<min_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
MAKE PAPACY INVADE LESS
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="100" continue="true"/>
</decision_entry>

<!--
IMPROVEMENTS TO CRUSADES
-->

<decision_entry>
<!--
IF ISLAMIC AND LOW FACTION STANDINGS, INCREASE INVADE PRIORITY
-->
<min_entry target_religion="islam" faction_standing="-1.0"/>
<max_entry target_religion="islam" faction_standing="-0.7"/>
<faction_attitude can_force_invade="true" invade="invade_immediate" invade_priority="1000" continue="true"/>
</decision_entry>

</invasion_decisions>

</faction_ai_label>


<!--
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CATHOLIC FACTION AI PARAMS. REQUIRES SPECIAL STUFF TO REDUCE ATTACKING NON-EXCOMMUNICATED CATHOLIC FACTIONS //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->

<faction_ai_label name="catholic">

<defend_decisions>

<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

</defend_decisions>

<invasion_decisions>

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
DON'T ALLY WITH ISLAMIC FACTIONS
-->
<min_entry target_religion="islam"/>
<max_entry target_religion="islam"/>
<faction_attitude want_ally="false" pts_alliance="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-2" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>
<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.75" free_strength_balance="0.75"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED AND LALST SETTLEMENT, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.8" free_strength_balance="0.8" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.75"/>
<max_entry is_neighbour="true" faction_standing="-0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.5"/>
<max_entry is_neighbour="true" faction_standing="-0.25"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true" faction_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true" global_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
FOR CATHOLICS
-->

<decision_entry>
<!--
IF PAPAL STATES AND LIKE US, INVADE NONE, CANNOT FORCE INVADE
-->
<min_entry target_faction="papal_states" target_faction_standing="-0.5"/>
<max_entry target_faction="papal_states"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF CEASE HOSTILITIES, INVADE NONE, CANNOT FORCE INVADE, REDUCE INVADE PRIORITY
-->
<min_entry faction_standing="-0.25" has_ceasehostilities="true" global_standing="-0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" invade_priority="-250" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF CEASE HOSTILITIES, INVADE NONE, CANNOT FORCE INVADE, REDUCE INVADE PRIORITY, RANDOMISED SLIGHTLY
-->
<min_entry has_ceasehostilities="true"/>
<max_entry rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET NON-EXCOMMUNICATED CATHOLIC AND WE LIKE THEM, REDUCE INVADE PRIORITY
-->
<min_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false" target_faction_standing="-0.1" target_global_standing="-0.1"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET NON-EXCOMMUNICATED CATHOLIC, REDUCE INVADE PRIORITY
-->
<min_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<max_entry stance="Neutral" target_religion="catholic" enemy_excommunicated="false" excommunicated="false"/>
<faction_attitude invade_priority="-800" continue="true"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
IF NEIGHBOUR AND WEAKER FRONTLINE > INVADE BUILDUP
-->
<min_entry is_neighbour="true" frontline_balance="0.1"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLYS ENEMY AND NOT AT WAR > INVADE BUILDUP
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
IF NOT NEIGHBOUR
-->

<decision_entry>
<!--
IF ENEMY OF TRUSTED ALLY > INVADE BUILDUP
-->
<min_entry is_neighbour="false" trusted_ally_enemy="true"/>
<max_entry is_neighbour="false" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="false"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR + RESOURCES > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="false" military_balance="1.1" free_strength_balance="1.1"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_opportunistic" continue="true" can_force_invade="true"/>
</decision_entry>

<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVE > REALLY WANT TO INVADE FOR QUICK BULDUP OF EMPIRES
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="20000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<!--
IMPROVEMENTS TO CRUSADES
-->

<decision_entry>
<!--
IF ISLAMIC AND LOW FACTION STANDINGS, INCREASE INVADE PRIORITY
-->
<min_entry target_religion="islam" faction_standing="-1.0"/>
<max_entry target_religion="islam" faction_standing="-0.7"/>
<faction_attitude can_force_invade="true" invade="invade_immediate" invade_priority="1000" continue="true"/>
</decision_entry>

</invasion_decisions>

</faction_ai_label>


<!--
///////////////////////////////////////
// MONGOL AI PARAMTERS //
///////////////////////////////////////
-->

<faction_ai_label name="mongol">

<defend_decisions>

<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

</defend_decisions>

<invasion_decisions>

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-2" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>
<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.75" free_strength_balance="0.75"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED AND LALST SETTLEMENT, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.8" free_strength_balance="0.8" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.75"/>
<max_entry is_neighbour="true" faction_standing="-0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.5"/>
<max_entry is_neighbour="true" faction_standing="-0.25"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true" faction_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true" global_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
IF NEIGHBOUR AND WEAKER FRONTLINE > INVADE BUILDUP
-->
<min_entry is_neighbour="true" frontline_balance="0.1"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLYS ENEMY AND NOT AT WAR > INVADE BUILDUP
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
IF NOT NEIGHBOUR
-->

<decision_entry>
<!--
IF ENEMY OF TRUSTED ALLY > INVADE BUILDUP
-->
<min_entry is_neighbour="false" trusted_ally_enemy="true"/>
<max_entry is_neighbour="false" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_opportunistic" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="false"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_opportunistic" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR + RESOURCES > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="false" military_balance="1.1" free_strength_balance="1.1"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_immediate" continue="true" can_force_invade="true"/>
</decision_entry>

<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVE > REALLY WANT TO INVADE FOR QUICK BULDUP OF EMPIRES
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="20000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

</invasion_decisions>

</faction_ai_label>

<!--
///////////////////////////////////////
// ISLAMIC AI PARAMS. //
///////////////////////////////////////
-->

<faction_ai_label name="islam">

<defend_decisions>

<!--
DEFEND
-->

<decision_entry>
<!--
IF AT WAR AND EVEN > DEFEND FORTIFIED
-->
<min_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND WEAKER > DEFEND DEEP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" military_balance="0.75" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND STRONGER > DEFEND FRONTLINE
-->
<min_entry stance="AtWar" military_balance="1.75" is_neighbour="true"/>
<max_entry stance="AtWar"is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY > DEFEND NORMAL
-->
<min_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<max_entry trusted_ally="true" stance="Allied" target_human="false" is_neighbour="true"/>
<faction_attitude defense="defend_normal" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND NOT AT WAR > DEFEND FORTIFIED
-->
<min_entry target_human="true" is_neighbour="true"/>
<max_entry target_human="true" is_neighbour="true"/>
<faction_attitude defense="defend_fortified" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF HUMAN AND AT WAR > DEFEND DEEP
-->
<min_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<max_entry stance="AtWar" target_human="true" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_deep" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry is_neighbour="false"/>
<max_entry is_neighbour="false"/>
<faction_attitude defense="defend_minimal" continue="true"/>
</decision_entry>

<!--
DEFEND v SLAVES
-->

<decision_entry>
<!--
IF SLAVE AND NOT NEIGHBOUR > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="false"/>
<max_entry target_faction="slave" is_neighbour="false"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR AND EARLY GAME > DEFEND MINIMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" turn_number="30" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_minimal" want_peace="false" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVE AND NEIGHBOUR > DEFEND NORMAL
-->
<min_entry target_faction="slave" is_neighbour="true"/>
<max_entry target_faction="slave" is_neighbour="true"/>
<faction_attitude at_war="true" defense="defend_frontline" want_peace="false" continue="false"/>
</decision_entry>

</defend_decisions>

<invasion_decisions>

<!--
DEFAULT
-->

<decision_entry>
<!--
DEFAULT INVADE NONE
-->
<faction_attitude invade="invade_none" continue="true"/>
</decision_entry>

<!--
DIPLOMACY
-->

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<max_entry turn_number="10"/>
<faction_attitude want_ally="false" pts_alliance="-5" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="11"/>
<max_entry turn_number="20"/>
<faction_attitude want_ally="false" pts_alliance="-10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
BY DEFAULT DON'T WANT TO ALLY
-->
<min_entry turn_number="21"/>
<faction_attitude want_ally="false" pts_alliance="-15" continue="true"/>
</decision_entry>

<decision_entry>
<!--
DON'T ALLY WITH CATHOLIC FACTIONS
-->
<min_entry target_religion="catholic"/>
<max_entry target_religion="catholic"/>
<faction_attitude want_ally="false" pts_alliance="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
WANT ALLY WITH ISLAMIC FACTIONS
-->
<min_entry target_religion="islam"/>
<max_entry target_religion="islam"/>
<faction_attitude want_ally="true" pts_alliance = "10" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry trusted_ally="true"/>
<max_entry trusted_ally="true" rand="0.9"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND TRUSTWORTHY AND ONLY ALLIED SHORT WHILE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry stance="Allied" global_standing="0.25"/>
<max_entry stance="Allied" num_turns_allied="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ONLY ALLIED FOR SHORT TIME, CANNOT FORCE INVADE, INVADE NONE
-->
<max_entry stance="Allied"/>
<max_entry num_turns_allied="3" stance="Allied"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO AND RELATIVELY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral" global_standing="0.25"/>
<max_entry num_turns_ceasfire="10" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AGREED TO CEASEFIRE SHORT TIME AGO, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry num_turns_ceasfire="0" stance="Neutral"/>
<max_entry num_turns_ceasfire="3" stance="Neutral"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND VERY TRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" global_standing="0.5"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIED AND LIKE THEM ALOT AND NOT UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.5" global_standing="-0.1"/>
<max_entry stance="Allied" rand="0.8"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>


<decision_entry>
<!--
IF ALLIED AND WE DON'T MIND THEM, AND NOT TOO UNTRUSTWORTHY, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Allied" faction_standing="0.0" global_standing="-0.25"/>
<max_entry stance="Allied" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.5"/>
<max_entry stance="Neutral" rand="0.75"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.25"/>
<max_entry stance="Neutral" rand="0.5"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
PARTIALLY FRIENDLY NEUTRAL, CANNOT FORCE INVADE, INVADE NONE, RANDOMISED SLIGHTLY
-->
<min_entry stance="Neutral" faction_standing="0.0"/>
<max_entry stance="Neutral" rand="0.25"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry is_protectorate="true" />
<max_entry is_protectorate="true" />
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY PROTECTORATE, CANNOT FORCE INVADE, INVADE NONE
-->
<min_entry trusted_ally_protectorate="true"/>
<max_entry trusted_ally_protectorate="true"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, ALLIANCE AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES, DON'T ALLY AGAINST
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude alliance_against="-2" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE MUCH STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER, ALLY AGAINST
-->
<min_entry stance="AtWar"/>
<max_entry stance="AtWar" frontline_balance="0.5" free_strength_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER ON FRONTLINE, ALLY AGAINST
-->
<min_entry stance="AtWar" free_strength_balance="1.0"/>
<max_entry stance="AtWar" frontline_balance="0.5"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY'RE STRONGER IN FREE STRENGTH, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry stance="AtWar" free_strength_balance="0.7"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND THEY OUTPRODUCE US, ALLY AGAINST
-->
<min_entry stance="AtWar" frontline_balance="1.0"/>
<max_entry production_balance="1.0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF NOT AT WAR AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" frontline_balance="2.0" target_num_enemies="2"/>
<max_entry strongest_neighbour="true" production_balance="1.0" num_enemies="0" />
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCE AND STRONGEST NEIGHBOUR, ALLY AGAINST
-->
<min_entry strongest_neighbour="true" production_balance="1.0"/>
<max_entry strongest_neighbour="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MOST DESIRABLE, ALLY AGAINST
-->
<min_entry most_desirable="true" production_balance="1.0"/>
<max_entry most_desirable="true" num_enemies="0"/>
<faction_attitude alliance_against="1" continue="true"/>
</decision_entry>
<decision_entry>
<!--
IF AT WAR AND VASTLY SUPERIOR, OFFER PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="5.0" military_balance="1.0" production_balance="1.0"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude want_offer_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND VASTLY OUTNUMBERED, WANT BE PROTECT
-->
<min_entry stance="AtWar" is_neighbour="true" />
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.3" free_strength_balance="0.3" production_balance="0.5" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.75" free_strength_balance="0.75"/>
<faction_attitude want_peace="true" continue="false"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND OUTNUMBERED AND LALST SETTLEMENT, WANT PEACE
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="0.8" free_strength_balance="0.8" num_settlements="3"/>
<faction_attitude want_peace="true" want_be_protect="true" continue="false"/>
</decision_entry>

<!--
DECIDE WHO TO INVADE
-->

<!--
DECIDE WHO TO INVADE
-->

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="1.0"/>
<max_entry is_neighbour="true" frontline_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="2.0"/>
<max_entry is_neighbour="true" frontline_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF STRONGER ON FRONTLINE, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" frontline_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="1.0"/>
<max_entry is_neighbour="true" military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="2.0"/>
<max_entry is_neighbour="true" military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF MORE POWERFUL MILITARY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET AT WAR WITH LOTS OF FACTIONS, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="1.0"/>
<max_entry is_neighbour="true" production_balance="2.0"/>
<faction_attitude invade_priority="25" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="2.0"/>
<max_entry is_neighbour="true" production_balance="3.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUT PRODUCE THEM, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" production_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE AGAINST, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" has_alliance_against="true"/>
<max_entry is_neighbour="true" has_alliance_against="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="1.0"/>
<max_entry is_neighbour="true" alliance_military_balance="2.0"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="2.0"/>
<max_entry is_neighbour="true" alliance_military_balance="3.0"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ALLIANCE MILITARY STRONGER, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" alliance_military_balance="3.0"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.75"/>
<max_entry is_neighbour="true" faction_standing="-0.5"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.5"/>
<max_entry is_neighbour="true" faction_standing="-0.25"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF DISLIKE FACTION, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="-0.25"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF UNTRUSTOWRTHY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.5"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" stance="AtWar"/>
<max_entry is_neighbour="true" stance="AtWar"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_human="true"/>
<max_entry is_neighbour="true" target_human="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="hard"/>
<max_entry is_neighbour="true" difficulty="hard"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TARGET HUMAN AND DIFFICULTY VERY HARD HARD, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" difficulty="very_hard"/>
<max_entry is_neighbour="true" difficulty="very_hard"/>
<faction_attitude invade_priority="150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKEST NEIGHBOUR, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" target_weakest_neighbour="true"/>
<max_entry is_neighbour="true" target_weakest_neighbour="true"/>
<faction_attitude invade_priority="50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY ENEMY, INCREASE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade_priority="75" continue="true"/>
</decision_entry>

<!--
DECIDE WHO NOT TO INVADE
-->

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="1"/>
<max_entry is_neighbour="true" num_enemies="2"/>
<faction_attitude invade_priority="-100" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="2"/>
<max_entry is_neighbour="true" num_enemies="3"/>
<faction_attitude invade_priority="-150" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF ENEMIES, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" num_enemies="3"/>
<max_entry is_neighbour="true"/>
<faction_attitude invade_priority="-200" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER FRONTLINE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" frontline_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF WEAKER MILITARY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" military_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF OUTPRODUCED, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" production_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF GOOD STANDINGS, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" faction_standing="0.35"/>
<max_entry is_neighbour="true" faction_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTWORTHY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" global_standing="0.4"/>
<max_entry is_neighbour="true" global_standing="1.0"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF LOW FREE STRENGTH VALUE, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true"/>
<max_entry is_neighbour="true" free_strength_balance="0.7"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLY, REDUCE INVADE PRIORITY
-->
<min_entry is_neighbour="true" trusted_ally="true"/>
<max_entry is_neighbour="true" trusted_ally="true"/>
<faction_attitude invade_priority="-50" continue="true"/>
</decision_entry>

<!--
EARLY GAME
-->

<decision_entry>
<!--
IF EARLY GAME, INVADE NONE
-->
<min_entry stance="Neutral"/>
<max_entry stance="Neutral" turn_number="10"/>
<faction_attitude can_force_invade="false" invade="invade_none" continue="false"/>
</decision_entry>

<!--
INVADES FOR NEIGHBOURS
-->

<decision_entry>
<!--
IF NEIGHBOUR AND WEAKER FRONTLINE > INVADE BUILDUP
-->
<min_entry is_neighbour="true" frontline_balance="0.1"/>
<max_entry is_neighbour="true" frontline_balance="0.9"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF TRUSTED ALLYS ENEMY AND NOT AT WAR > INVADE BUILDUP
-->
<min_entry is_neighbour="true" trusted_ally_enemy="true"/>
<max_entry is_neighbour="true" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true"/>
<faction_attitude invade="invade_buildup" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND HE IS SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="true"/>
<max_entry stance="AtWar" is_neighbour="true" military_balance="0.9" free_strength_balance="0.9"/>
<faction_attitude invade="invade_opportunistic" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry stance="AtWar" is_neighbour="true" frontline_balance="1.5"/>
<max_entry stance="AtWar" is_neighbour="true" frontline_balance="100.0"/>
<faction_attitude invade="invade_immediate" continue="true"/>
</decision_entry>

<!--
IF NOT NEIGHBOUR
-->

<decision_entry>
<!--
IF ENEMY OF TRUSTED ALLY > INVADE BUILDUP
-->
<min_entry is_neighbour="false" trusted_ally_enemy="true"/>
<max_entry is_neighbour="false" trusted_ally_enemy="true"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR > INVADE BUILDUP
-->
<min_entry stance="AtWar" is_neighbour="false"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_buildup" continue="true" can_force_invade="true"/>
</decision_entry>

<decision_entry>
<!--
IF AT WAR + RESOURCES > INVADE OPPORTUNISTIC
-->
<min_entry stance="AtWar" is_neighbour="false" military_balance="1.1" free_strength_balance="1.1"/>
<max_entry stance="AtWar" is_neighbour="false"/>
<faction_attitude invade="invade_opportunistic" continue="true" can_force_invade="true"/>
</decision_entry>

<!--
SLAVE
-->

<decision_entry>
<!--
IF SLAVE > REALLY WANT TO INVADE FOR QUICK BULDUP OF EMPIRES
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade_priority="20000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_opportunistic" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SLIGHTLY SUPERIOR > INVADE OPPORTUNISTIC
-->
<min_entry target_faction="slave" frontline_balance="1.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_buildup" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND SUPERIOR > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="2.0"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

<decision_entry>
<!--
IF SLAVES AND EARLY GAME > INVADE IMMEDIATE
-->
<min_entry target_faction="slave" frontline_balance="1.25"/>
<max_entry target_faction="slave" turn_number="30"/>
<faction_attitude at_war="true" invade="invade_immediate" invade_priority="2000" continue="true"/>
</decision_entry>

</invasion_decisions>

</faction_ai_label>



<!--
/////////////////////////////////////////////////////////////
// SLAVE FACTION AI PARAMS. THEY DON'T REALLY DO ANYTHING //
/////////////////////////////////////////////////////////////
-->

<faction_ai_label name="slave_faction">

<invasion_decisions>

<decision_entry>
<!--
Hopefully make rebels more aggressive
-->
<faction_attitude invade="invade_opportunistic" invade_priority="550"/>
</decision_entry>

<decision_entry>
<!--
Just use defaults
-->
</decision_entry>

</invasion_decisions>


<defend_decisions>

<decision_entry>
<!--
Always try and defend the settlements
-->
<faction_attitude defense="defend_fortified"/>
</decision_entry>

</defend_decisions>

</faction_ai_label>


</root>


And here's my diplomacy file:


<?xml version="1.0"?>
<root>
<item_modifiers>
<item name="offer_payment">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="offer_protectorate">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_alliance">
<cost modifier="0.5"/>
<faction_standing modifier="0.5"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_recommunication">
<cost modifier="1.0"/>
<faction_standing modifier="0.95"/>
<global_standing modifier="0.0"/>
</item>
<item name="offer_cardinal_vote">
<cost modifier="1.0"/>
<faction_standing modifier="0.35"/>
<global_standing modifier="0.25"/>
</item>
<item name="offer_marry_heir">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_marry_leader">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_marry_heir_to_princess">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_marry_leader_to_princess">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_ceasefire">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.35"/>
</item>
<item name="offer_trade_rights">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_military_access">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_map_information">
<cost modifier="0.25"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_yearly_payment">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.25"/>
</item>
<item name="offer_cede_region">
<cost modifier="2.5"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="offer_attack_faction">
<cost modifier="0.01"/>
<faction_standing modifier="0.5"/>
<global_standing modifier="0.75"/>
</item>
<item name="offer_threat_of_attack">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="stopping_offer_payment">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="declare_nullify_alliance">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="declare_cancel_trade_rights">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="declare_cancel_military_access">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="demand_payment">
<cost modifier="0.5"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="demand_protectorate">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="demand_recommunication">
<cost modifier="1.0"/>
<faction_standing modifier="0.95"/>
<global_standing modifier="0.0"/>
</item>
<item name="demand_cardinal_vote">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.25"/>
</item>
<item name="demand_military_access">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="demand_map_information">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="stopping_demand_payment">
<cost modifier="1.0"/>
<faction_standing modifier="0.0"/>
<global_standing modifier="0.0"/>
</item>
<item name="demand_yearly_payment">
<cost modifier="1.0"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.25"/>
</item>
<item name="demand_cede_region">
<cost modifier="3.5"/>
<faction_standing modifier="0.25"/>
<global_standing modifier="0.5"/>
</item>
<item name="demand_attack_faction">
<cost modifier="2.0"/>
<faction_standing modifier="0.5"/>
<global_standing modifier="0.5"/>
</item>
</item_modifiers>

<demeanours>
<!--
<demeanour_state name="ai_accepts">
<demeanour_entry>
<upper_threshold upper_thresh="0.1"/>
<diplomacy_text name="DDS_ACCEPT_LOW"/>
<character_voice name="Offer_Accepted_Close"/>
</demeanour_entry>
</demeanour_state>
-->
<demeanour_state name="new_offer">
<demeanour_entry>
<upper_threshold value="-5.0"/>
<diplomacy_text name="DDS_NEW_OFFER_WORSE"/>
<character_voice name="New_Offer_Worse"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="5.0"/>
<diplomacy_text name="DDS_NEW_OFFER_NEUTRAL"/>
<character_voice name="New_Offer_Neutral"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_NEW_OFFER_BETTER"/>
<character_voice name="New_Offer_Better"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_accepts">
<demeanour_entry>
<upper_threshold value="0.0"/>
<diplomacy_text name="DDS_ACCEPT_EXTORTION"/>
<character_voice name="Offer_Accepted_Extortion"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="1.0"/>
<diplomacy_text name="DDS_ACCEPT_LOW"/>
<character_voice name="Offer_Accepted_Close"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="10.0"/>
<diplomacy_text name="DDS_ACCEPT_MED"/>
<character_voice name="Offer_Accepted_Standard"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_ACCEPT_HIGH"/>
<character_voice name="Offer_Accepted_Generous"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_declines">
<demeanour_entry>
<upper_threshold value="-10.0"/>
<diplomacy_text name="DDS_DECLINE_HIGH"/>
<character_voice name="Offer_Declined_insulting"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-1.0"/>
<diplomacy_text name="DDS_DECLINE_MED"/>
<character_voice name="Offer_Declined_Standard"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_DECLINE_LOW"/>
<character_voice name="Offer_Declined_Close"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_rejects">
<demeanour_entry>
<upper_threshold value="-10.0"/>
<diplomacy_text name="DDS_REJECT_HIGH"/>
<character_voice name="Offer_Rejected_insulting"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-1.0"/>
<diplomacy_text name="DDS_REJECT_MED"/>
<character_voice name="Offer_Rejected_Standard"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_REJECT_LOW"/>
<character_voice name="Offer_Rejected_Close"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_counters">
<demeanour_entry>
<upper_threshold value="-10.0"/>
<diplomacy_text name="DDS_COUNTER_INSULTING"/>
<character_voice name="Offer_Countered_Insulting"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-1.0"/>
<diplomacy_text name="DDS_COUNTER_STANDARD"/>
<character_voice name="Offer_Countered_Standard"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_COUNTER_CLOSE"/>
<character_voice name="Offer_Countered_Close"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_counters_open">
<demeanour_entry>
<upper_threshold value="-1.0"/>
<diplomacy_text name="DDS_COUNTER_OPEN"/>
<character_voice name="Offer_Countered_Open_Negative"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="1.0"/>
<diplomacy_text name="DDS_COUNTER_OPEN"/>
<character_voice name="Offer_Countered_Open_Neutral"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_COUNTER_OPEN"/>
<character_voice name="Offer_Countered_Open_Positive"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_acknowledges_declare">
<demeanour_entry>
<upper_threshold value="-10.0"/>
<diplomacy_text name="DDS_DECLARE_UPSET"/>
<character_voice name="Demeanour_Declare_Upset"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-5.0"/>
<diplomacy_text name="DDS_DECLARE_ANNOYED"/>
<character_voice name="Demeanour_Declare_Annoyed"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_DECLARE_UNCONCERNED"/>
<character_voice name="Demeanour_Declare_Unconcerned"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="player_rejects">
<demeanour_entry>
<upper_threshold value="-1.5"/>
<diplomacy_text name="DDS_REACTION_OFFENDED"/>
<character_voice name="Demeanour_Reaction_Offended"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-0.75"/>
<diplomacy_text name="DDS_REACTION_DISAPPOINTED"/>
<character_voice name="Demeanour_Reaction_Disappointed"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_REACTION_NEUTRAL"/>
<character_voice name="Demeanour_Reaction_Neutral_Rejected"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="player_accepts">
<demeanour_entry>
<upper_threshold value="0.75"/>
<diplomacy_text name="DDS_REACTION_NEUTRAL"/>
<character_voice name="Demeanour_Reaction_Neutral"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="1.5"/>
<diplomacy_text name="DDS_REACTION_PLEASED"/>
<character_voice name="Demeanour_Reaction_Pleased"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_REACTION_ELATED"/>
<character_voice name="Demeanour_Reaction_Elated"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="ai_farewells">
<demeanour_entry>
<upper_threshold value="-5.0"/>
<character_voice name="Outro_Demeanour_Worse"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="5.0"/>
<character_voice name="Outro_Demeanour_Neutral"/>
</demeanour_entry>
<demeanour_entry>
<character_voice name="Outro_Demeanour_Better"/>
</demeanour_entry>
</demeanour_state>
<demeanour_state name="proposal_balance">
<demeanour_entry>
<upper_threshold value="-10.0"/>
<diplomacy_text name="DDS_BALANCE_VERY_DEMANDING"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="-5.0"/>
<diplomacy_text name="DDS_BALANCE_DEMANDING"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="5.0"/>
<diplomacy_text name="DDS_BALANCE_BALANCED"/>
</demeanour_entry>
<demeanour_entry>
<upper_threshold value="10.0"/>
<diplomacy_text name="DDS_BALANCE_GENEROUS"/>
</demeanour_entry>
<demeanour_entry>
<diplomacy_text name="DDS_BALANCE_VERY_GENEROUS"/>
</demeanour_entry>
</demeanour_state>
</demeanours>
<diplomacy_text_fields>
<text_field name="relations">
<text_entry>
<upper_threshold value="-0.8"/>
<diplomacy_text name="DT_RELATIONS_0"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.6"/>
<diplomacy_text name="DT_RELATIONS_1"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.4"/>
<diplomacy_text name="DT_RELATIONS_2"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.25"/>
<diplomacy_text name="DT_RELATIONS_3"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.1"/>
<diplomacy_text name="DT_RELATIONS_4"/>
</text_entry>
<text_entry>
<upper_threshold value="0.1"/>
<diplomacy_text name="DT_RELATIONS_5"/>
</text_entry>
<text_entry>
<upper_threshold value="0.25"/>
<diplomacy_text name="DT_RELATIONS_6"/>
</text_entry>
<text_entry>
<upper_threshold value="0.4"/>
<diplomacy_text name="DT_RELATIONS_7"/>
</text_entry>
<text_entry>
<upper_threshold value="0.6"/>
<diplomacy_text name="DT_RELATIONS_8"/>
</text_entry>
<text_entry>
<upper_threshold value="0.8"/>
<diplomacy_text name="DT_RELATIONS_9"/>
</text_entry>
<text_entry>
<diplomacy_text name="DT_RELATIONS_10"/>
</text_entry>
</text_field>
<text_field name="reputation">
<text_entry>
<upper_threshold value="-0.8"/>
<diplomacy_text name="DT_REPUTATION_0"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.6"/>
<diplomacy_text name="DT_REPUTATION_1"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.4"/>
<diplomacy_text name="DT_REPUTATION_2"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.25"/>
<diplomacy_text name="DT_REPUTATION_3"/>
</text_entry>
<text_entry>
<upper_threshold value="-0.1"/>
<diplomacy_text name="DT_REPUTATION_4"/>
</text_entry>
<text_entry>
<upper_threshold value="0.1"/>
<diplomacy_text name="DT_REPUTATION_5"/>
</text_entry>
<text_entry>
<upper_threshold value="0.25"/>
<diplomacy_text name="DT_REPUTATION_6"/>
</text_entry>
<text_entry>
<upper_threshold value="0.4"/>
<diplomacy_text name="DT_REPUTATION_7"/>
</text_entry>
<text_entry>
<upper_threshold value="0.6"/>
<diplomacy_text name="DT_REPUTATION_8"/>
</text_entry>
<text_entry>
<upper_threshold value="0.8"/>
<diplomacy_text name="DT_REPUTATION_9"/>
</text_entry>
<text_entry>
<diplomacy_text name="DT_REPUTATION_10"/>
</text_entry>
</text_field>
<text_field name="power">
<text_entry>
<upper_threshold value="5000.0"/>
<diplomacy_text name="DT_POWER_0"/>
</text_entry>
<text_entry>
<upper_threshold value="15000.0"/>
<diplomacy_text name="DT_POWER_1"/>
</text_entry>
<text_entry>
<upper_threshold value="25000.0"/>
<diplomacy_text name="DT_POWER_2"/>
</text_entry>
<text_entry>
<upper_threshold value="35000.0"/>
<diplomacy_text name="DT_POWER_3"/>
</text_entry>
<text_entry>
<upper_threshold value="45000.0"/>
<diplomacy_text name="DT_POWER_4"/>
</text_entry>
<text_entry>
<upper_threshold value="55000.0"/>
<diplomacy_text name="DT_POWER_5"/>
</text_entry>
<text_entry>
<upper_threshold value="65000.0"/>
<diplomacy_text name="DT_POWER_6"/>
</text_entry>
<text_entry>
<upper_threshold value="75000.0"/>
<diplomacy_text name="DT_POWER_7"/>
</text_entry>
<text_entry>
<upper_threshold value="85000.0"/>
<diplomacy_text name="DT_POWER_8"/>
</text_entry>
<text_entry>
<upper_threshold value="95000.0"/>
<diplomacy_text name="DT_POWER_9"/>
</text_entry>
<text_entry>
<diplomacy_text name="DT_POWER_10"/>
</text_entry>
</text_field>
<text_field name="wealth">
<text_entry>
<upper_threshold value="2500.0"/>
<diplomacy_text name="DT_WEALTH_0"/>
</text_entry>
<text_entry>
<upper_threshold value="7500.0"/>
<diplomacy_text name="DT_WEALTH_1"/>
</text_entry>
<text_entry>
<upper_threshold value="12500.0"/>
<diplomacy_text name="DT_WEALTH_2"/>
</text_entry>
<text_entry>
<upper_threshold value="17500.0"/>
<diplomacy_text name="DT_WEALTH_3"/>
</text_entry>
<text_entry>
<upper_threshold value="22500.0"/>
<diplomacy_text name="DT_WEALTH_4"/>
</text_entry>
<text_entry>
<upper_threshold value="27500.0"/>
<diplomacy_text name="DT_WEALTH_5"/>
</text_entry>
<text_entry>
<upper_threshold value="32500.0"/>
<diplomacy_text name="DT_WEALTH_6"/>
</text_entry>
<text_entry>
<upper_threshold value="37500.0"/>
<diplomacy_text name="DT_WEALTH_7"/>
</text_entry>
<text_entry>
<upper_threshold value="42500.0"/>
<diplomacy_text name="DT_WEALTH_8"/>
</text_entry>
<text_entry>
<upper_threshold value="47500.0"/>
<diplomacy_text name="DT_WEALTH_9"/>
</text_entry>
<text_entry>
<diplomacy_text name="DT_WEALTH_10"/>
</text_entry>
</text_field>
</diplomacy_text_fields>
</root>


And my faction standings file:



; faction standing parameters
; ===========================

; initialisation parameters

min_faction_standing -1.0
max_faction_standing 1.0

relations_improved_thresholds
{
0.25
0.4
0.6
}

relations_worsened_thresholds
{
-0.8
-0.4
-0.25
}

; trigger information
; faction_standing updated with the command:
; FactionStanding [AFFECTED_HANDLE] [affected_handle_parameters] opt:[MODIFER_HANDLE] opt:[modifier_handle_parameter_1] opt:[modifier_handle_parameter_1]
;
; Available AFFECTED_HANDLE's and their parameters are as follows:
;
; factions { [faction_label_1] [faction_label_2] [etc] } --> A list of factions to be affected, (own faction automatically excluded)
; target_faction --> the target_faction attached to the event, (own faction automatically excluded)
; religion [religion_label] --> all factions of the specified religion, (own faction automatically excluded)
; own_religion --> all factions of the same religion as the faction of the event, (own faction automatically excluded)
; target_religion --> all factions of the same religion as the target faction of the event, (own faction automatically excluded)
; global --> the faction of the event (i.e. own faction)
; exclude_factions { [faction_label_1] [faction_label_2] [etc] } --> A list of factions not to be affected, (own faction automatically excluded)
; allies --> all factions allied with the faction attached to the trigger
; enemies --> all factions at war with the faction attached to the trigger
; target_allies --> all factions allied with the target faction attached to the trigger
; target_enemies --> all factions at war with the target_faction attached to the trigger
;
; Available MODIFIER_HANDLE's and their corresponding parameters
;
; [value] --> add this 'value' to the affected faction standings
; amount [divisor] [value] --> for every 'divisor' unit of the event amount, add 'value' to the affected faction standings
; income [divisor] [value] --> for every 'divisor' unit of the event factions income, add 'value' to the affected faction standings
; normalise [target_faction_standing] [divisor] --> for each affected faction standing, add (target_faction_standing - faction_standing)/divisor
; per_unit [value] --> for each unit in the events army, add 'value' to the affected faction standings


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BUILD RELIGIOUS STRUCTURE ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;------------------------------------------
Trigger 0001_P_Build_Small_Church
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = small_church

FactionStanding factions { papal_states } 0.02

;------------------------------------------
Trigger 0002_P_Build_Church
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = church

FactionStanding factions { papal_states } 0.04

;------------------------------------------
Trigger 0003_P_Build_Abbey
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = abbey

FactionStanding factions { papal_states } 0.06

;------------------------------------------
Trigger 0004_P_Build_Cathedral
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = cathedral

FactionStanding factions { papal_states } 0.16

;------------------------------------------
Trigger 0005_P_Build_Huge_Cathedral
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = huge_cathedral

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0006_P_Build_Small_Chapel
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = small_chapel

FactionStanding factions { papal_states } 0.02

;------------------------------------------
Trigger 0007_P_Build_Chapel
WhenToTest BuildingCompleted

Condition SettlementBuildingFinished = chapel

FactionStanding factions { papal_states } 0.04

;------------------------------------------
Trigger 0008_P_Built_First_Small_Church_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction small_church = 1

FactionStanding factions { papal_states } 0.04

;------------------------------------------
Trigger 0009_P_Built_First_Church_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction church = 1

FactionStanding factions { papal_states } 0.08

;------------------------------------------
Trigger 0010_P_Built_First_Abbey_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction abbey = 1

FactionStanding factions { papal_states } 0.12

;------------------------------------------
Trigger 0011_P_Built_First_Cathedral_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction cathedral = 1

FactionStanding factions { papal_states } 0.16

;------------------------------------------
Trigger 0012_P_Built_First_Huge_Cathedral_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction huge_cathedral = 1

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0013_P_Built_First_Small_Chapel_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction small_chapel = 1

FactionStanding factions { papal_states } 0.04

;------------------------------------------
Trigger 0014_P_Built_First_Chapel_Faction
WhenToTest BuildingCompleted

Condition NumBuildingsCompletedFaction chapel = 1

FactionStanding factions { papal_states } 0.08

;------------------------------------------
Trigger 0015_P_Built_First_Cathedral_World
WhenToTest BuildingCompleted

Condition NumBuildingsCompleted cathedral = 1

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0016_P_Built_First_Huge_Cathedral_World
WhenToTest BuildingCompleted

Condition NumBuildingsCompleted huge_cathedral = 1

FactionStanding factions { papal_states } 0.2



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DESTROY RELIGIOUS STRUCTURE ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0017_P_Destroy_Small_Church
WhenToTest BuildingDestroyed

Condition BuildingName = small_church

FactionStanding factions { papal_states } -0.1

;------------------------------------------
Trigger 0018_P_Destroy_Church
WhenToTest BuildingDestroyed

Condition BuildingName = church

FactionStanding factions { papal_states } -0.2

;------------------------------------------
Trigger 0019_P_Destroy_Abbey
WhenToTest BuildingDestroyed

Condition BuildingName = abbey

FactionStanding factions { papal_states } -0.4

;------------------------------------------
Trigger 0020_P_Destroy_Cathedral
WhenToTest BuildingDestroyed

Condition BuildingName = cathedral

FactionStanding factions { papal_states } -0.6

;------------------------------------------
Trigger 0021_P_Destroy_Huge_Cathedral
WhenToTest BuildingDestroyed

Condition BuildingName = huge_cathedral

FactionStanding factions { papal_states } -1.0

;------------------------------------------
Trigger 0022_P_Destroy_Small_Chapel
WhenToTest BuildingDestroyed

Condition BuildingName = small_chapel

FactionStanding factions { papal_states } -0.1

;------------------------------------------
Trigger 0023_P_Destroy_Chapel
WhenToTest BuildingDestroyed

Condition BuildingName = chapel

FactionStanding factions { papal_states } -0.2

;
;;;; TBD buildings destroyed in battle


;;;;;;;;;;;;;;
;; CRUSADES ;;
;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0050_P_General_Arrives_Crusade_Target
WhenToTest GeneralArrivesCrusadeTargetRegion

Condition IsCrusade

FactionStanding factions { papal_states } 0.1
FactionStanding factions { papal_states } per_unit 0.001

;------------------------------------------
Trigger 0051_P_Heir_Arrives_Crusade_Target
WhenToTest GeneralArrivesCrusadeTargetRegion

Condition IsCrusade
and IsFactionHeir

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0052_P_King_Arrives_Crusade_Target
WhenToTest GeneralArrivesCrusadeTargetRegion

Condition IsCrusade
and IsFactionLeader

FactionStanding factions { papal_states } 0.6

;------------------------------------------
Trigger 0053_P_General_Takes_Crusade_Target
WhenToTest GeneralTakesCrusadeTarget

Condition IsCrusade

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0054_P_Heir_Takes_Crusade_Target
WhenToTest GeneralTakesCrusadeTarget

Condition IsCrusade
and IsFactionHeir

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0055_P_King_Takes_Crusade_Target
WhenToTest GeneralTakesCrusadeTarget

Condition IsCrusade
and IsFactionLeader

FactionStanding factions { papal_states } 0.6

;------------------------------------------
Trigger 0056_P_Army_Takes_Crusade_Target
WhenToTest ArmyTakesCrusadeTarget

Condition IsCrusade

FactionStanding factions { papal_states } per_unit 0.002

;------------------------------------------
Trigger 0057_P_Character_Attacks_Crusading_General
WhenToTest CharacterAttacksCrusadingGeneral

Condition IsTargetOnCrusade

FactionStanding factions { papal_states } -0.8

;------------------------------------------
Trigger 0058_P_Crusade_Attacks_Orthodox_General
WhenToTest GeneralAssaultsGeneral

Condition IsOnCrusade
and TargetFactionReligion orthodox

FactionStanding factions { papal_states } -0.4

;------------------------------------------
;Trigger 0059_P_Crusade_Attacks_Orthodox_Residence
; WhenToTest GeneralAssaultsResidence
;
; Condition IsOnCrusade
; and TargetFactionReligion orthodox
;
; FactionStanding factions { papal_states } -0.4


;;;;;;;;;;;;;;;;
;; CHARACTERS ;;
;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0030_P_Recruit_Priest_Papal
WhenToTest AgentCreated

Condition TrainedAgentType = priest
and FactionReligion catholic

FactionStanding factions { papal_states } 0.02

;------------------------------------------
Trigger 0031_P_Faction_Excommunicated
WhenToTest FactionExcommunicated

FactionStanding factions { papal_states } -1.0



;;;;;;;;;;;;;;
;; MISSIONS ;;
;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0100_Success_Pope_Min_Reward_Only
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_min_reward_only

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0101_Success_Pope_Min_Penalty_Min_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_min_penalty_min_reward

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0102_Success_Pope_Mod_Penalty_Min_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_mod_penalty_min_reward

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0103_Success_Pope_Rome_Min_Penalty_Min_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_rome_min_penalty_min_reward

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0104_Success_Pope_Cardinal_Mod_Penalty_Min_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_mod_penalty_min_reward

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0104_Success_Pope_Cardinal_Min_Penalty_Min_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_min_penalty_min_reward

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0105_Success_Pope_Mod_Reward_Only
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_mod_reward_only

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0106_Success_Pope_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_min_penalty_mod_reward

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0107_Success_Pope_Rome_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_rome_min_penalty_mod_reward

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0108_Success_Pope_Cardinal_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_min_penalty_mod_reward

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0109_Success_Pope_Cardinal_Mod_Reward_Only
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_mod_reward_only

FactionStanding factions { papal_states } 0.2

;------------------------------------------
Trigger 0110_Success_Pope_Major_Reward_Only
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_major_reward_only

FactionStanding factions { papal_states } 0.4

;------------------------------------------
Trigger 0111_Success_Pope_Rome_Min_Penalty_Major_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_rome_min_penalty_major_reward

FactionStanding factions { papal_states } 0.4

;------------------------------------------
Trigger 0112_Success_Pope_Cardinal_Major_Reward_Only
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_major_reward_only

FactionStanding factions { papal_states } 0.4

;------------------------------------------
Trigger 0113_Success_Pope_Cardinal_Min_Penalty_Major_Reward
WhenToTest LeaderMissionSuccess

Condition PaybackID pope_cardinal_min_penalty_major_reward

FactionStanding factions { papal_states } 0.4

;------------------------------------------
Trigger 0120_Fail_Pope_Min_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_min_penalty_only

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0121_Fail_Pope_Min_Penalty_Min_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_min_penalty_min_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0122_Fail_Pope_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_min_penalty_mod_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0123_Fail_Pope_Rome_Min_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_min_penalty_only

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0124_Fail_Pope_Rome_Min_Penalty_Min_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_min_penalty_min_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0125_Fail_Pope_Rome_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_min_penalty_mod_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0126_Fail_Pope_Rome_Min_Penalty_Major_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_min_penalty_major_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0127_Fail_Pope_Cardinal_Min_Penalty_Min_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_min_penalty_min_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0128_Fail_Pope_Cardinal_Min_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_min_penalty_only

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0129_Fail_Pope_Cardinal_Min_Penalty_Mod_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_min_penalty_mod_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0130_Fail_Pope_Cardinal_Min_Penalty_Major_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_min_penalty_major_reward

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0131_Fail_Pope_Mod_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_mod_penalty_only

FactionStanding factions { papal_states } -0.15

;------------------------------------------
Trigger 0132_Fail_Pope_Mod_Penalty_Min_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_mod_penalty_min_reward


FactionStanding factions { papal_states } -0.15
;------------------------------------------
Trigger 0133_Fail_Pope_Rome_Mod_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_mod_penalty_only

FactionStanding factions { papal_states } -0.15

;------------------------------------------
Trigger 0134_Fail_Pope_Cardinal_Mod_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_mod_penalty_only

FactionStanding factions { papal_states } -0.15

;------------------------------------------
Trigger 0135_Fail_Pope_Cardinal_Mod_Penalty_Min_Reward
WhenToTest LeaderMissionFailed

Condition PaybackID pope_cardinal_mod_penalty_min_reward

FactionStanding factions { papal_states } -0.15

;------------------------------------------
Trigger 0136_Fail_Pope_Major_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_major_penalty_only

FactionStanding factions { papal_states } -0.3

;------------------------------------------
Trigger 0137_Fail_Pope_Rome_Major_Penalty_Only
WhenToTest LeaderMissionFailed

Condition PaybackID pope_rome_major_penalty_only

FactionStanding factions { papal_states } -0.5



;;;;;;;;;;;;;;;
;; DIPLOMACY ;;
;;;;;;;;;;;;;;;


;------------------------------------------
Trigger 0033_P_Give_Money
WhenToTest GiveMoney

Condition TargetFactionType papal_states
and DiplomaticStanceFromFaction papal_states < AtWar

FactionStanding factions { papal_states } amount 50 0.002


;------------------------------------------
Trigger 0034_P_Give_Settlement
WhenToTest GiveSettlement

Condition TargetFactionType papal_states
and DiplomaticStanceFromFaction papal_states < AtWar

FactionStanding factions { papal_states } income 1000 0.06


;------------------------------------------
Trigger 0035_P_Give_Rome
WhenToTest GiveSettlement

Condition TargetFactionType papal_states
and SettlementName Rome
and DiplomaticStanceFromFaction papal_states < AtWar

FactionStanding factions { papal_states } 0.6


;------------------------------------------
Trigger 0036_P_Alliance_Declared
WhenToTest FactionAllianceDeclared

Condition TargetFactionType papal_states

FactionStanding factions { papal_states } 0.4


;------------------------------------------
Trigger 0037_P_Break_Alliance
WhenToTest FactionBreakAlliance

Condition TargetFactionType papal_states

FactionStanding factions { papal_states } -0.6


;------------------------------------------
Trigger 0038_P_Successful_Diplomacy
WhenToTest DiplomacyMission

Condition MissionSucceeded
and TargetFactionType papal_states

FactionStanding factions { papal_states } 0.05

;------------------------------------------
Trigger 0039_P_War_Declared
WhenToTest FactionWarDeclared

Condition TargetFactionType papal_states

FactionStanding factions { papal_states } -0.5


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CARDINALS AND ELECTIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;------------------------------------------
Trigger 0040_P_Cardinal_Promoted
WhenToTest CardinalPromoted

FactionStanding factions { papal_states } 0.1

;------------------------------------------
Trigger 0041_P_Cardinal_Removed
WhenToTest CardinalRemoved

FactionStanding factions { papal_states } -0.1

;------------------------------------------
Trigger 0042_P_Own_Pope_Elected
WhenToTest PopeElected

Condition FactionEqualsTarget

FactionStanding factions { papal_states } 0.8

;------------------------------------------
Trigger 0043_P_Allied_Pope_Elected
WhenToTest PopeElected

Condition DiplomaticStanceWithNewPope = Allied
and not FactionEqualsTarget

FactionStanding factions { papal_states } 0.4

;------------------------------------------
Trigger 0044_P_At_War_Pope_Elected
WhenToTest PopeElected

Condition DiplomaticStanceWithNewPope = AtWar
and not FactionEqualsTarget

FactionStanding factions { papal_states } -0.6

;------------------------------------------
Trigger 0045_P_Voted_For_Pope
WhenToTest VotedForPope

FactionStanding factions { papal_states } 0.35


;;;;;;;;;;
;; MISC ;;
;;;;;;;;;;


;------------------------------------------
Trigger 0046_P_Normalise
WhenToTest FactionTurnStart

FactionStanding factions { papal_states } normalise 0 50

;------------------------------------------
Trigger 0047_P_Inquisitor_Appointed
WhenToTest InquisitorAppointed

FactionStanding factions { papal_states } -0.2

;------------------------------------------
Trigger 0048_P_Assassin_Caught_Attacking_Pope
WhenToTest AssassinCaughtAttackingPope

FactionStanding factions { papal_states } -1.0

; Make the papal states dislike other religions
;------------------------------------------
Trigger 0049_P_Normalise_Non_catholic
WhenToTest FactionTurnStart

Condition not FactionReligion catholic

FactionStanding factions { papal_states } normalise -1 50



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TRANSGRESSIONS AGAINST CATHOLICS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0100_T_Invaded_Settlement
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_SETTLEMENT
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0101_T_Invaded_Fort
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_FORT
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.025

;------------------------------------------
Trigger 0102_T_Invaded_Watchtower
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_WATCHTOWER
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.0125

;------------------------------------------
Trigger 0103_T_Declared_War
WhenToTest Transgression

Condition TransgressionName = TC_DECLARED_WAR
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0104_T_Instigate_Siege
WhenToTest Transgression

Condition TransgressionName = TC_INSTIGATE_SIEGE
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0105_T_Threaten_War
WhenToTest Transgression

Condition TransgressionName = TC_THREATEN_WAR
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.0125

;------------------------------------------
Trigger 0106_T_Undeclared_Attack
WhenToTest Transgression

Condition TransgressionName = TC_UNDECLARED_ATTACK
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.05

;------------------------------------------
Trigger 0107_T_INSTIGATE_ASSAULT
WhenToTest Transgression

Condition TransgressionName = TC_INSTIGATE_ASSAULT
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.025

;------------------------------------------
Trigger 0108_T_BLOCKADE
WhenToTest Transgression

Condition TransgressionName = TC_BLOCKADE
and TargetFactionReligion catholic
and not TargetFactionExcommunicated

FactionStanding factions { papal_states } -0.0125



;;;;;;;;;;;;;;;;;;;;
;; TRANSGRESSIONS ;;
;;;;;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0049_T_Attacking_Crusading_General
WhenToTest Transgression

Condition TransgressionName = TC_ATTACKING_CRUSADING_GENERAL

FactionStanding target_religion normalise -1.0 10

;------------------------------------------
Trigger 0050_T_Invaded_Fort
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_FORT

FactionStanding target_faction normalise -1.0 10
FactionStanding target_allies normalise -1.0 800

;------------------------------------------
Trigger 0051_T_Stole_Back_Settlement
WhenToTest Transgression

Condition TransgressionName = TC_STOLE_BACK_SETTLEMENT

FactionStanding global -1.0
FactionStanding target_faction normalise -1.0 2
FactionStanding target_allies normalise -1.0 20

;------------------------------------------
Trigger 0052_T_Invaded_Settlement
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_SETTLEMENT

FactionStanding target_faction normalise -1.0 5
FactionStanding target_allies normalise -1.0 40

;------------------------------------------
Trigger 0053_T_Invaded_Watchtower
WhenToTest Transgression

Condition TransgressionName = TC_INVADED_WATCHTOWER

FactionStanding target_faction normalise -1.0 20
FactionStanding target_allies normalise -1.0 80

;------------------------------------------
Trigger 0055_T_Invasion_Neutral
WhenToTest Transgression

Condition TransgressionName = TC_INVASION
and not DiplomaticStanceFactions = Allied

FactionStanding target_faction normalise -1.0 50

;------------------------------------------
Trigger 0055a_T_Invasion
WhenToTest Transgression

Condition TransgressionName = TC_INVASION
and DiplomaticStanceFactions = Allied

FactionStanding target_faction normalise -1.0 100

;------------------------------------------
Trigger 0055b_T_Invasion_Flee
WhenToTest Transgression

Condition TransgressionName = TC_FLEE_INVASION

FactionStanding target_faction normalise -1.0 200

;------------------------------------------
Trigger 0055c_T_Invasion_Crusade
WhenToTest Transgression

Condition TransgressionName = TC_CRUSADE_INVASION
and FactionReligion catholic
and not TargetFactionReligion catholic
and not TargetFactionReligion orthodox

FactionStanding target_faction normalise -1.0 50
FactionStanding target_religion normalise -1.0 200

;------------------------------------------
Trigger 0055d_T_Invasion_Jihad
WhenToTest Transgression

Condition TransgressionName = TC_CRUSADE_INVASION
and FactionReligion islam
and not TargetFactionReligion islam

FactionStanding target_faction normalise -1.0 50
FactionStanding target_religion normalise -1.0 200

;------------------------------------------
Trigger 0056_T_Nullified_Alliance
WhenToTest Transgression

Condition TransgressionName = TC_NULLIFIED_ALLIANCE

FactionStanding global -0.05
FactionStanding target_faction normalise -0.4 5
FactionStanding target_allies normalise -0.2 20
FactionStanding target_enemies normalise 1.0 20

;------------------------------------------
Trigger 0057_T_Broke_Treaty_terms
WhenToTest Transgression

Condition TransgressionName = TC_BROKE_TREATY_TERMS

FactionStanding global -0.15
FactionStanding target_faction normalise -0.25 5
FactionStanding target_allies normalise -0.25 40

;------------------------------------------
;Trigger 0058_T_Diplomatic_Insult ; fired for every 1000 gold diplomacy proposal under balanced - 1
; WhenToTest Transgression
;
; Condition TransgressionName = TC_DIPLOMATIC_INSULT
;
; FactionStanding target_faction -0.001

;------------------------------------------
Trigger 0059_T_Dishonour
WhenToTest Transgression

Condition TransgressionName = TC_DISHONOUR

FactionStanding target_faction normalise -0.8 10
FactionStanding target_allies normalise -0.8 40

;------------------------------------------
Trigger 0060_T_Declared_War
WhenToTest Transgression

Condition TransgressionName = TC_DECLARED_WAR

FactionStanding target_faction normalise -0.8 4
FactionStanding target_allies normalise -0.8 20
FactionStanding target_enemies normalise 0.6 20

;------------------------------------------
Trigger 0061_T_Major_Assassination_Attempt
WhenToTest Transgression

Condition TransgressionName = TC_MAJOR_ASSASSINATION_ATTEMPT

FactionStanding target_faction normalise -0.8 5
FactionStanding target_allies normalise -0.8 40

;------------------------------------------
Trigger 0062_T_Minor_Assassination_Attempt
WhenToTest Transgression

Condition TransgressionName = TC_MINOR_ASSASSINATION_ATTEMPT

FactionStanding target_faction normalise -0.4 20
FactionStanding target_allies normalise -0.4 80

;------------------------------------------
Trigger 0063_T_Sabotage
WhenToTest Transgression

Condition TransgressionName = TC_SABOTAGE

FactionStanding target_faction normalise -0.4 5
FactionStanding target_allies normalise -0.4 40

;------------------------------------------
Trigger 0064_T_Bribed_Away_Army
WhenToTest Transgression

Condition TransgressionName = TC_BRIBED_AWAY_ARMY

FactionStanding target_faction normalise -0.5 10

;------------------------------------------
Trigger 0065_T_Bribed_Away_Character
WhenToTest Transgression

Condition TransgressionName = TC_BRIBED_AWAY_CHARACTER

FactionStanding target_faction normalise -0.7 5

;------------------------------------------
Trigger 0066_T_Bribed_Away_Settlement
WhenToTest Transgression

Condition TransgressionName = TC_BRIBED_AWAY_SETTLEMENT

FactionStanding global -0.15
FactionStanding target_faction normalise -0.8 5

;------------------------------------------
Trigger 0067_T_Bribed_Away_Fort
WhenToTest Transgression

Condition TransgressionName = TC_BRIBED_AWAY_FORT

FactionStanding target_faction normalise -0.75 10

;------------------------------------------
Trigger 0068_T_Battle_Engagement
WhenToTest Transgression

Condition TransgressionName = TC_BATTLE_ENGAGEMENT
and not TargetFactionType slave

FactionStanding target_faction normalise -0.8 10
FactionStanding target_allies normalise -0.6 80
FactionStanding target_enemies normalise 0.4 80

;------------------------------------------
Trigger 0069_T_Instigate_Siege
WhenToTest Transgression

Condition TransgressionName = TC_INSTIGATE_SIEGE

FactionStanding target_faction normalise -1.0 5
FactionStanding target_allies normalise -0.8 40

;------------------------------------------
Trigger 0070_T_Spying
WhenToTest Transgression

Condition TransgressionName = TC_SPYING

FactionStanding target_faction normalise -0.2 20
FactionStanding target_allies normalise -0.1 80

;------------------------------------------
Trigger 0071_T_Threaten_War
WhenToTest Transgression

Condition TransgressionName = TC_THREATEN_WAR

FactionStanding target_faction normalise -0.6 5

;------------------------------------------
Trigger 0072_T_Undeclared_Attack
WhenToTest Transgression

Condition TransgressionName = TC_UNDECLARED_ATTACK

FactionStanding target_faction normalise -1.0 5
FactionStanding target_allies normalise -0.8 40

;------------------------------------------
Trigger 0072_T_Undeclared_Attack_Withdraw
WhenToTest Transgression

Condition TransgressionName = TC_UNDECLARED_ATTACK_WITHDRAW

FactionStanding target_faction normalise -0.6 10
FactionStanding target_allies normalise -0.4 80

;------------------------------------------
Trigger 0073_T_INSTIGATE_ASSAULT
WhenToTest Transgression

Condition TransgressionName = TC_INSTIGATE_ASSAULT

FactionStanding target_faction normalise -0.75 5
FactionStanding target_allies normalise -0.6 40

;------------------------------------------
Trigger 0074_T_BLOCKADE
WhenToTest Transgression

Condition TransgressionName = TC_BLOCKADE

FactionStanding target_faction normalise -0.5 5
FactionStanding target_allies normalise -0.25 40



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DISHONEST TRANSGRESSIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0078b_DT_Break_Alliance_War
WhenToTest Transgression

Condition TransgressionName = TC_BROKE_ALLIANCE
and DiplomaticStanceFactions = AtWar

FactionStanding global -0.2
FactionStanding target_faction normalise -1.0 5
FactionStanding target_allies normalise -0.8 20

;------------------------------------------
Trigger 0078c_DT_Break_Alliance_Neutral
WhenToTest Transgression

Condition TransgressionName = TC_BROKE_ALLIANCE
and DiplomaticStanceFactions = Neutral

FactionStanding global -0.05
FactionStanding target_faction normalise -0.8 10
FactionStanding target_allies normalise -0.5 40




;;;;;;;;;;;;;;;;;
;; FORGIVENESS ;;
;;;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0079_F_Trade_Agreement
WhenToTest FactionTradeAgreementMade

FactionStanding target_faction 0.05
FactionStanding target_allies normalise 0.6 50

;------------------------------------------
Trigger 0080_F_Military_Assistance
WhenToTest Forgiveness

Condition ForgivenessName = FC_MILITARY_ASSISTANCE

FactionStanding global 0.2
FactionStanding target_faction 0.4
FactionStanding target_allies normalise 1.0 20

;------------------------------------------
Trigger 0081_F_Obvious_Bribe ; fired for every 1000 gold given as gift
WhenToTest Forgiveness

Condition ForgivenessName = FC_OBVIOUS_BRIBE

FactionStanding target_faction normalise 0.5 50

;------------------------------------------
;Trigger 0082_F_Update_Attitude
; WhenToTest UpdateAttitude
;
; Condition FactionStanding > 0.0
;
; FactionStanding target_faction 0.01

; Forming an alliance increases relationships (papal states already factored in above)
;------------------------------------------
Trigger 0082b_F_Alliance_Declared
WhenToTest FactionAllianceDeclared

Condition not TargetFactionType papal_states

FactionStanding target_faction 0.4
FactionStanding target_allies normalise 0.4 50

; Inter faction marriage increases relationships
;------------------------------------------
Trigger 0082c_P_Faction_Marriage
WhenToTest InterFactionMarriage

FactionStanding target_faction 0.4



;;;;;;;;;;;;;;;
;; DEMEANOUR ;;
;;;;;;;;;;;;;;;

;------------------------------------------
Trigger 0083_Demeanour
WhenToTest Demeanour

FactionStanding target_faction amount 1.0 0.005
FactionStanding target_allies amount 1.0 0.001



;;;;;;;;;;;;;;;;;;;;;;
;; AI Relationships ;;
;;;;;;;;;;;;;;;;;;;;;;


; Make allied factions like us a bit more
;------------------------------------------
Trigger 0083b_Update_Allies
WhenToTest FactionTurnStart

FactionStanding allies normalise 0.8 50


; Make enemy factions like us a bit less
;------------------------------------------
Trigger 0084b_Update_Enemies
WhenToTest FactionTurnStart

Condition not FactionType slave

FactionStanding enemies normalise -0.8 20


; Make allies of our allies like us a bit more
;------------------------------------------
Trigger 0083c_Update_Allies_Allies
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = Allied

FactionStanding target_allies normalise 0.8 100


; Make enemies of our allies like us a bit less
;------------------------------------------
Trigger 0084c_Update_Allies_Enemies
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = Allied

FactionStanding target_enemies normalise -0.8 100


; Make allies of our enemies like us a bit less
;------------------------------------------
Trigger 0083d_Update_Enemies_Allies
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = AtWar

FactionStanding target_allies normalise -0.8 100


; Make enemies of our enemies like us a bit more
;------------------------------------------
Trigger 0084d_Update_Enemies_Enemies
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = AtWar
and not TargetFactionType slave

FactionStanding target_enemies normalise 0.8 150


; Make other Catholic factions like the pope a bit more
;------------------------------------------
Trigger 0084_Update_Papal
WhenToTest FactionTurnStart

Condition FactionType Papal_States

FactionStanding own_religion normalise 1.0 50


; Make other factions like factions of the same religion a bit more
;------------------------------------------
Trigger 0085_Update_Religion
WhenToTest FactionTurnStart

FactionStanding own_religion normalise 1.0 100


; Make factions get a case of the 'tall poppy' syndrome. get narky about the larger factions
;------------------------------------------
Trigger 0086_Update_Tall_Poppy1
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall > 90
and FactionScoreRank overall <= 1

FactionStanding exclude_factions { } normalise -1.0 90

;------------------------------------------
Trigger 0087_Update_Tall_Poppy2
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall > 80
and FactionScoreRank overall <= 3

FactionStanding exclude_factions { } normalise -1.0 135

;------------------------------------------
Trigger 0088_Update_Tall_Poppy3
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall > 70
and FactionScoreRank overall <= 5

FactionStanding exclude_factions { } normalise -1.0 180


; Make factions try and band up with smaller factions
;------------------------------------------
Trigger 0089_Update_Band_Together1
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall < 30
and FactionScoreRank overall > 3

FactionStanding exclude_factions { } normalise 1.0 40

;------------------------------------------
Trigger 0090_Update_Band_Together2
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall < 20
and FactionScoreRank overall > 4

FactionStanding exclude_factions { } normalise 1.0 25

;------------------------------------------
Trigger 0091_Update_BandTogether3
WhenToTest FactionTurnStart

Condition FactionHasRank
and FactionScorePercent overall < 10
and FactionScoreRank overall > 5

FactionStanding exclude_factions { } normalise 1.0 10


; Adjust the AI relationships towards each faction based on difficulty level (AI factions have normal difficulty)
;------------------------------------------
Trigger 0092_Update_Easy_Difficulty
WhenToTest FactionTurnStart

Condition CampaignDifficulty = easy

FactionStanding exclude_factions { } normalise 1.0 50

;------------------------------------------
Trigger 0093_Update_Normal_Difficulty
WhenToTest FactionTurnStart

Condition CampaignDifficulty = medium

FactionStanding exclude_factions { } normalise 0.0 50

;------------------------------------------
Trigger 0094_Update_Hard_Difficulty
WhenToTest FactionTurnStart

Condition CampaignDifficulty = hard

FactionStanding exclude_factions { } normalise 0.0 50

;------------------------------------------
Trigger 0095_Update_Very_Hard_Difficulty
WhenToTest FactionTurnStart

Condition CampaignDifficulty = very_hard

FactionStanding exclude_factions { } normalise -0.5 50

;------------------------------------------
Trigger 0096_Increase_Global_Standing_New_Turn
WhenToTest FactionTurnStart

FactionStanding global normalise 0.05 200

;------------------------------------------
Trigger 0097_Increase_Global_Standing_When_Allied
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = Allied

FactionStanding global normalise 1.0 300

;------------------------------------------
Trigger 0098_Decrease_Global_Standing_When_War
WhenToTest UpdateAttitude

Condition DiplomaticStanceFactions = AtWar
and not TargetFactionType slave

FactionStanding global normalise -1.0 800



;------------------------------------------
Trigger 0099_prisoners_released_increase_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType release
and NumCapturedSoldiers > 80

FactionStanding global 0.03
FactionStanding target_faction normalise 0.8 20
FactionStanding target_allies normalise 0.6 40

;------------------------------------------
Trigger 0100_prisoners_executed_decrease_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType execute
and NumCapturedSoldiers > 80

FactionStanding global -0.025
FactionStanding target_faction normalise -0.8 20
FactionStanding target_allies normalise -0.6 40

;------------------------------------------
Trigger 0099b_prisoners_released_increase_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType release

FactionStanding global 0.01
FactionStanding target_faction normalise 1.0 80
FactionStanding target_allies normalise 1.0 160

;------------------------------------------
Trigger 0100b_prisoners_executed_decrease_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType execute

FactionStanding global -0.01
FactionStanding target_faction normalise -1.0 80
FactionStanding target_allies normalise -1.0 160

;------------------------------------------
Trigger 0099c_characters_released_increase_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType release
and NumCapturedCharacters > 0

FactionStanding global 0.05
FactionStanding target_faction normalise 1.0 20
FactionStanding target_allies normalise 1.0 40

;------------------------------------------
Trigger 0100c_characters_executed_decrease_global
WhenToTest FactionLeaderPrisonersRansomedCaptor

Condition RansomType execute
and NumCapturedCharacters > 0

FactionStanding global -0.05
FactionStanding target_faction normalise -1.0 20
FactionStanding target_allies normalise -1.0 40

;------------------------------------------
Trigger 0101_sack_settlement_decrease_global
WhenToTest SackSettlement

FactionStanding global -0.01
FactionStanding target_faction normalise -1.0 40
FactionStanding target_allies normalise -1.0 80
; FactionStanding target_enemies normalise 1.0 80

;------------------------------------------
Trigger 0102_extermination_decrease_global
WhenToTest ExterminatePopulation

FactionStanding global -0.04
FactionStanding target_faction normalise -1.0 20
FactionStanding target_allies normalise -1.0 40
; FactionStanding target_enemies normalise 1.0 40

;------------------------------------------
Trigger 0103_occupy_settlement_increase_global
WhenToTest OccupySettlement

FactionStanding global 0.05
FactionStanding target_faction normalise 1.0 20
FactionStanding target_allies normalise 1.0 40
; FactionStanding target_enemies normalise -1.0 40

;------------------------------------------
;Trigger 0102_city_razed_decrease_global
; WhenToTest CitySacked

FactionStanding global -0.05
FactionStanding target_faction normalise -1.0 10
FactionStanding target_allies normalise -1.0 20
; FactionStanding target_enemies normalise 1.0 20

; make all other factions hate the rebels
;------------------------------------------
Trigger 0103_Update_Slaves
WhenToTest FactionTurnStart

Condition FactionType slave

FactionStanding exclude_factions { } normalise -1.0 1

; make slaves hate all other factions
;------------------------------------------
;Trigger 0104_Update_Slaves_Reverse
; WhenToTest UpdateAttitude
;
; Condition Not FactionType slave
; and TargetFactionType slave
;
; FactionStanding target_faction normalise -1.0 1

; make factions like trustworthy factions more
;---------------------------------------------
Trigger 0105_Update_Trustworthy_Factions_Major
WhenToTest FactionTurnStart

Condition GlobalStanding > 0.4

FactionStanding exclude_factions { } normalise 1.0 40

Trigger 0106_Update_Trustworthy_Factions_Minor
WhenToTest FactionTurnStart

Condition GlobalStanding > 0.1

FactionStanding exclude_factions { } normalise 1.0 80

; make factions like untrustworthy factions less
;---------------------------------------------
Trigger 0107_Update_Untrustworthy_Factions_Major
WhenToTest FactionTurnStart

Condition GlobalStanding < -0.4

FactionStanding exclude_factions { } normalise -1.0 40

Trigger 0108_Update_Untrustworthy_Factions_Minor
WhenToTest FactionTurnStart

Condition GlobalStanding < 0.1

FactionStanding exclude_factions { } normalise -1.0 80

; make existing inter faction marriages improve relationships
;---------------------------------------------
Trigger 0109_Update_Marriages
WhenToTest UpdateAttitude

Condition NumFactionMarriages > 0

FactionStanding target_faction normalise 1.0 20

pike master
12-17-2007, 07:46
the army to army ratio i think is a good line to mess with although i havnt tinkered with it much. i understand the thinking behind it is because according to the military art a ratio of 5 to 1 is considered appropriate when attacking another country.

what will changing the can force invade to true do?

are the decision entries for invading a province related to individual armies or all the armies in that province?

what is the definition of front line strength?

is it the total of the units in a said province or are they the total number of units in close proximity to the enemy ai?

CavalryCmdr
12-18-2007, 07:42
military art a ratio of 5 to 1 is considered appropriate when attacking another country. You can do that, and the AI would build impresive armies that would probably do nothing, and would definately do nothing in battle. Anythong much over 1:1 tends to cause unreasonable passivity in battle. Also note Lusted's post, even a 1.2 caused expansion dificulties for the AI on the campaign level. I've not got Kingdoms yet, but I've been told it has, in the descr_campaign_db.xml a line like

<att_str_modifier float="0.8"/> <!-- modifies the effective attackers strength when determining the priority of making attack decision (i.e. att_def_strength_ratio = ((att_str*att_str_modifier)/def_str) -->

Which may be more forgiving to larger numbers, though seeing where the default is the same it's doubtfull.


are the decision entries for invading a province related to individual armies or all the armies in that province? Decision entries in the ai_db refer to a faction wide balance depending on what balance your using. When deciding whether to attack or not based on the army strength ratio it only consideres the target stack, disregarding even adjacent armies, on the up side the AI dose prefer to target the strongest single stack in the vacinity and match it's strength accordingly.

For the other questions refer to the link in the title post, you'll find probably the best explanation of force invade and frontline balance as you can find anywhere. As for whether it considers all units in a province or in the vacinity I'm not sure, though I belive it's distance related with the 'strength' of any given army reduced the further from the actual border it is, what province they are in is meaningles. I think this is why having troops onboard navies messes up the frontline balance, because the program is not designd to consider naval distances (thus also the constant troop loss when crusading armies are onboard a fleet regardless of how much closer you are to the target.) This is all just theory and speculation based on study of the LTGD log though if anyone dose KNOW how it works they are not forthcoming with the info.

pike master
12-19-2007, 06:20
ive been tweaking the campaign ai db and im still not seeing the ai turn really agressive.

if i went by a routine that the ai goes through i would never win.

a losing nation will only lose more if it will never fight battles and take risks. and the ai will not take risk and therefore will lose.

also i wonder if there is something that keeps the ai from finishing off the human opponent. they seem to do a good job of wasting each other but ive never seen an all out concerted attempt to knock me out of the game.

does this have something to do with the command lines pertaining to the faction not outliving the target faction?

i also noticed several lines in the campaign ai db where the ai would not attack another faction or factions until a certian number of turns expired. this is used at the first of the game where i think only rebels are targeted for the first 10 turns. i set this to 0 but im still not expecting much.

im beginning to figure out that the devs intended to make the ai not very aggressive so an inexperienced player would not get demolished. however i would have thought that would be what the easy settings are for.

there does not appear to be a drastic increase of aggression between minimum entries and maximum entries.

im almost tempted to change the force_invade line to true, to see if the ai will get more aggressive.

im beginning to wonder if most of the campaign ai is hardcoded and beyond modding.