Page 2 of 3 FirstFirst 123 LastLast
Results 31 to 60 of 85

Thread: Campaign/Diplomacy AI

  1. #31

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by CavalryCmdr
    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.
    It's not a map.

  2. #32

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by Lusted
    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?
    Last edited by nikolai1962; 11-28-2007 at 07:21.
    It's not a map.

  3. #33
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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.

  4. #34

    Default Re: Campaign/Diplomacy AI

    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.

  5. #35

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by nikolai1962
    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?

  6. #36

    Default Re: Campaign/Diplomacy AI

    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).
    Last edited by nikolai1962; 11-29-2007 at 02:57.
    It's not a map.

  7. #37

    Default Re: Campaign/Diplomacy AI

    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.
    It's not a map.

  8. #38

    Default Re: Campaign/Diplomacy AI

    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.
    Last edited by nikolai1962; 11-29-2007 at 04:15.
    It's not a map.

  9. #39
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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.

    Code:
    			<!--
    			<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:

    Code:
    			<!--
    			<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>
    			-->
    Last edited by Lusted; 11-29-2007 at 14:25.

  10. #40

    Default Re: Campaign/Diplomacy AI

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

  11. #41
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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.

  12. #42
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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

  13. #43

    Default Re: Campaign/Diplomacy AI

    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)

  14. #44

    Default Re: Campaign/Diplomacy AI

    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

    ps none of this helps merging as it was terrible.

    ~~~

    CavCmdr

    Opinions on the theory? Seems to fit your observations.
    Last edited by nikolai1962; 11-30-2007 at 02:46.
    It's not a map.

  15. #45

    Default Re: Campaign/Diplomacy AI

    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.

  16. #46
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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

    Code:
    <?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.
    Last edited by Lusted; 11-30-2007 at 10:33.

  17. #47

    Default Re: Campaign/Diplomacy AI

    Lusted you forgot to change "has_ceasehostilities" to "has_cease_hostilities" in the AI file you posted.
    4 Seasons (6 Empires battle for supremecy); 3.0 version
    Total War Eras (start at 970, 1080, 1200, 1300, 1400, or 1500); 2.4 version
    Eras Total Conquest (start at 1230, 1346, 1547); 1.2 version

  18. #48
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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.

  19. #49

    Default Re: Campaign/Diplomacy AI

    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.

  20. #50
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    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.

  21. #51
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by CavalryCmdr
    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.

  22. #52

    Default Re: Campaign/Diplomacy AI

    Thanks alpaca, I'll take a better look at the file soon.

    I haven't had problems with the frontline balance before
    Major 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.

  23. #53

    Default Re: Campaign/Diplomacy AI

    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).
    Last edited by nikolai1962; 12-01-2007 at 09:38.
    It's not a map.

  24. #54

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by CavalryCmdr
    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

    Code:
    <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

    Code:
    <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
    Last edited by nikolai1962; 12-01-2007 at 08:15.
    It's not a map.

  25. #55

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by CavalryCmdr
    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.

    Quote Originally Posted by CavalryCmdr
    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.


    Quote Originally Posted by CavalryCmdr
    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.
    Last edited by nikolai1962; 12-01-2007 at 08:32.
    It's not a map.

  26. #56
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    Very interesting info nikolai and CavalryCmdr, i'm going to have a god at making somemajor changes to my latest AI code tomorrow.

  27. #57
    blaaaaaaaaaarg! Senior Member Lusted's Avatar
    Join Date
    Feb 2005
    Posts
    1,773

    Default Re: Campaign/Diplomacy AI

    Very useful relevant find by Alpaca:

    http://www.twcenter.net/forums/showt...82#post2437882

  28. #58
    Harbinger of... saliva Member alpaca's Avatar
    Join Date
    Aug 2003
    Location
    Germany
    Posts
    2,767

    Default Re: Campaign/Diplomacy AI

    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)
    Last edited by alpaca; 12-02-2007 at 00:06.

  29. #59

    Default Re: Campaign/Diplomacy AI

    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
    Code:
    			<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
    Code:
    			<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.

  30. #60

    Default Re: Campaign/Diplomacy AI

    Quote Originally Posted by lusted
    Very useful relevant find by Alpaca:
    Very useful.


    Quote Originally Posted by alpaca
    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.
    Last edited by nikolai1962; 12-02-2007 at 10:28.
    It's not a map.

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO