Log in

View Full Version : campaign_db_ai



FactionHeir
04-04-2007, 15:09
Hi,

I've been taking a second look after my first modifications on this file and noticed that at the start, following is noted:


<root>
<!--
<trusted_ally_fs_threshold float="0.8"/> // min threshold for how much we like the target faction to consider them a trusted ally
<trusted_ally_target_fs_threshold float="0.8"/> // min threshold for how much does the target faction like us to consider them a trusted ally
<trusted_ally_gs_threshold float="0.2"/> // min threshold for how trustworthy is the target faction to consider them a trusted ally

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

<invasion_decisions> :: List of ai invasion 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 traget 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
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

<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"
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"


What I don't quite understand is whether for example
is_neighbour
has to always be in the max entry section if its true and in the min entry if its false? Because by default, the devs somehow have it sometimes in min sometimes in max regardless of value. That is really confusing me and I don't know whether it actually matters where its located.

Re Berengario I
04-04-2007, 15:28
Example:
<max_entry is_neighbour="false" />
<max_entry is_neighbour="true" />

The game selects ALL the factions

<max_entry is_neighbour="true" />
<max_entry is_neighbour="true" />

The game selects only the factions that share borders with the actual faction processed

<max_entry is_neighbour="false" />
<max_entry is_neighbour="false" />

The game selects only the factions that don't share borders with the actual faction processed

FactionHeir
04-04-2007, 15:33
Ermm concerning your post, do you mean
<min_entry is_neighbour="false" />
<max_entry is_neighbour="false" />

for instance or really a duplication?
Also, how come the default file has for example only the condition under either max or min but never under both?

<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_minimal"/>
</decision_entry>

Re Berengario I
04-04-2007, 19:44
Ermm concerning your post, do you mean
<min_entry is_neighbour="false" />
<max_entry is_neighbour="false" />

for instance or really a duplication?
Also, how come the default file has for example only the condition under either max or min but never under both?

<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_minimal"/>
</decision_entry>


Because the others are already set as default as you listed in your first post. I usually rewrite them for my own practical logical understanding.

FactionHeir
04-04-2007, 19:52
Ahhhh now I understand what you mean.
is_neighbour is set to false by default in min and true by default in max and you basically have to set it to false in max and true in min in the conditions.

FactionHeir
04-04-2007, 21:56
OK maybe i don't understand you properly.

The game sets is_neighbour = true by default under max.
In this code:
<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>

it then sets it to false under max too, so according to your above description, this would result in all factions being processed, but that would mean this section is going against what it should be doing?!?


[edit]
OK, I just gave it a bit more thought. So in default,
min -> is_neighbour = false
max -> is_neighbour = true

in code:
max -> is_neighbour = false

yielding
min AND max -> is_neighbour = false.

So your above first posted code was actually meant to read min and then max instead of both!

FactionHeir
04-04-2007, 22:09
Still on the same file but different question:

What exactly does alliance_against do? not the one in the min/max entry but in the faction attitude entry? That one isn't commented and seems to range between 1 and 8 where mentioned at all.
Does it by chance determine how hard it is to obtain an alliance with a faction? In that case, what is the actual range of that value and what happens if you get rid of the entry?

Lusted
04-04-2007, 22:36
alliance_against refers to the size of an aliance fighting a nation, and the number refers to the number of nations in that alliance.

FactionHeir
04-04-2007, 22:54
Hmm so its alliances against the faction calling the decision or against their target? (the file doesn't seem to specify)

Lusted
04-04-2007, 22:58
It's the faction making the decision i believe as it is used mostly in vassal decisions.

FactionHeir
04-04-2007, 23:04
I would like to think so (it would make my work much easier to know it exactly), but following kind of eludes me:



<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 frontline_balance="2.0" strongest_neighbour="true" target_num_enemies="2"/>
<max_entry num_enemies="1" production_balance="1.0"/>
<faction_attitude invade="invade_raids" invade_priority="250" alliance_against="6"/>
</decision_entry>

So it sets the AI's faction attitude to invade at a priority of 250 (very low) using raids. But what does the alliance_against mean in this case? Form alliance of 5 other nations against the target? Only if the target has 6 alliances against the AI faction making the decision?


Personally, I've been thinking maybe alliance_against means how difficult an alliance with the target should be to obtain if the target was to initiate diplomacy, but I may be wrong

Re Berengario I
04-05-2007, 03:40
No it's a priority setting (it seems to range from 1 to 10) which tells the AI to seek allegiances against the target

FactionHeir
04-05-2007, 11:59
Ahhh that would make a lot of sense then. 10 means highest priority to seek alliance against it then?

Thanks!

FactionHeir
04-05-2007, 13:21
Hmmm I'm now evaluating all those numbers for the different balances. I understand them well enough (except for free_strength_balance) but I'm wondering whether its intentional CA has things always go up to 1.0 (i.e. max) and then 1.0 for min so all cases are covered.
They also have the default which means do nothing if no condition if met.

So if I were to change those balances and didn't have them coincide exactly, it would mean the AI would stay passive and go bash rebels instead, right?

While there is a portion in the code which is commented out reading how there should be a condition to make the AI always attack the human if not at war, I wonder whether it is in another file, because the AI actually does do that (instead of reverting to staying passive).

I can have an AI bordered in on all my regions, put full stacks in each settlement there and our of the blue they will tend to attack me with some puny besieging force or blockade one of my ports. I'm wondering how I can control that problem...

nikolai1962
04-07-2007, 04:27
While there is a portion in the code which is commented out reading how there should be a condition to make the AI always attack the human if not at war, I wonder whether it is in another file, because the AI actually does do that (instead of reverting to staying passive).


For testing map changes I made a quick AI profile and set it in the strat file for all factions. It only allows for attacking rebs and that is all they do (apart from jihads/crusades), so i don't think there is hidden hardcode to make the AI attack the player.

There *is* the thing in the faction standings file that makes the AI gradually dislike the human player on H and VH. Also the faction standing trigger for gradually diliking the top factions (which the human will be after a while) but in my testing with my attack_rebels_only profile i never get attacked (or asked for alliance).

alpaca
04-07-2007, 14:04
Hmm but if that is true, what about naval invasions? They are 100% handled by the hardcode.

Re Berengario I
04-07-2007, 14:35
I can have an AI bordered in on all my regions, put full stacks in each settlement there and our of the blue they will tend to attack me with some puny besieging force or blockade one of my ports. I'm wondering how I can control that problem...

<faction_attitude (...) can_force_invade="false"/>

This will stop the AI to follow the infamous missions (conquer settlement, block port) the council gives.

You need to tune it though because otherway you'll have a very, and I mean very, passive AI.

For example in AD I stopped all this stuff for catholics against catholics or when the relationship with and/or the global rep of the target faction weren't bad enough.

FactionHeir
04-07-2007, 15:05
Hmmm can_force_invade would only apply to if there was something forcing the AI to invade though? I don't see something in the code calling for that when not at war with a faction or being overwhelmed.
At the same time, council missions are never aggressive towards nations at war (at least not for the player). But then maybe there is something in the hardcode we don't know about (random port blockading of an ally for a turn for example)

Re Berengario I
04-07-2007, 16:19
Hmmm can_force_invade would only apply to if there was something forcing the AI to invade though? I don't see something in the code calling for that when not at war with a faction or being overwhelmed.
At the same time, council missions are never aggressive towards nations at war (at least not for the player). But then maybe there is something in the hardcode we don't know about (random port blockading of an ally for a turn for example)

Mate, strip down the AI xml file and start playing with just one value at time and one setting at time and see how the AI behaves. It's the only way you can understand how the AI is influenced by the various settings.

nikolai1962
04-09-2007, 07:33
Hmm but if that is true, what about naval invasions? They are 100% handled by the hardcode.

I've got force_invade set to false too, maybe that stops that. They only attack rebs apart from crusades/jihads. profile is:


<faction_ai_label name="active">

<invasion_decisions>

<decision_entry>
<min_entry target_faction="slave"/>
<max_entry target_faction="slave"/>
<faction_attitude at_war="true" invade="invade_immediate"/>
</decision_entry>

<decision_entry>
<faction_attitude invade="invade_none" can_force_invade="false"/>
</decision_entry>

</invasion_decisions>


<defend_decisions>

<decision_entry>
<faction_attitude defense="defend_normal"/>
</decision_entry>

</defend_decisions>

</faction_ai_label>

edit: should mention i've only been testing map changes at medium difficulty. may have something to do with it.

edit: forgot to say. i don't think naval invasions are 100% hardcode/missions. some naval invasions between certain pairs of regions happen on their own (due to map and path-finding working) most of the time the path-finding doesn't work over sea so that's why they use missions to compensate (as they seem to work independently e.g RTW romans with senate). that's my opinion anyway.

edit2: another thing to remember is the AI is often stuck. an army may have been given orders to attack a city and got stuck on it's path along the way or after retreating. when another faction takes the city (including yours) then the stack becomes unstuck again but often it will then move next to the city it was supposed to have attacked. i think these cases may not follow the normal logic as set out in the AI file. same thing for ships ordered to attack and then a ceasefire is agreed. ship may not get it's orders cleared.

alpaca
04-09-2007, 19:33
Well force_invade=false stops all invasions except those handled by the XML file I think, so yes, it'd stop them.
Also, on medium you won't experience the forced invasions to any large extent anyways. Try very hard, you'll get stuff like Sicily attacking you in Spain with a tiny stack or some ally blockading your ports and being excommunicated because of it...

nikolai1962
04-10-2007, 07:34
Yep, just saying you get some naval invasions between particular pairs of regions with force_invade set to false. scotland still lands near bruges for example..

Re Berengario I
04-10-2007, 12:00
Yep, just saying you get some naval invasions between particular pairs of regions with force_invade set to false. scotland still lands near bruges for example..

Because Bruges is the nearest rebel province they can get, it is not a mission, it's the XML. To stop naval invasion you could try to remove this possibility in the descr_sm_factions with "prefers_naval_invasions" set to no.

I still don't see how it could be desiderable but whatever.

Btw, when you use the frontline balance to determine your invasion priorities take in count that the value is faction-wise, aka all the border, and not just a border with a region.
So for example if you use frontline balance with rebel faction and the faction is bordering the rebels in a lot of points (for example Russia in vanilla) the XML value is the overall balancing of the troops in the bordering regions. So even if one region is pratically ungarrisoned the AI can't easily take advantage of it if the others bordering regions are filled with troops.

Once the invasion is triggered though it seems that the AI will automatically attack the softest target/nearest target (it should be an algorithm which calculates desiderability based on these 2 factors), but this is a hardcoded behaviour I presume.