Awesome, with some testing I got it to work! I also made it so the AI will always build a fort in their capital regardless of adjacency, because a level 1 fort is silly for a capital province.
I present to you my new and improved AI fort placement logic. It now does the following:
Doesn't build forts on islands.
Always builds forts in their capital
Really doesn't want to build forts with overlapping zones of control
Prefers to build forts in open terrain so that it can smash your face in when you try to siege it. (Just like I prefer to do)
Prefers to build forts in provinces with lots of building slots so it can build better stuff in low building slot provinces.
Doesn't always prioritize adjacency to the enemy, instead preferring large zones of control. After the large zones of control are filled it will still fill in overlapping zones, but never intentionally makes adjacent forts.
A bit more testing is needed to determine if preventing overlapping zone of control *period* is a good idea or not. It might be better to just 'strongly discourage' it.
Code:
fort_15th = {
cost = 200
time = 30
modifier = {
fort_level = 2
}
onmap = yes
influencing_fort = yes
ai_will_do = {
factor = 1500
modifier = {
factor = 10
is_capital = yes
}
modifier = {
factor = 1.05
allowed_num_of_buildings = 4
}
modifier = {
factor = 0
AND {
island = yes
NOT = { is_capital = yes }
}
}
modifier = {
factor = 0.1
is_overseas = yes
}
modifier = {
factor = 0
AND {
any_neighbor_province = {
owned_by = ROOT
OR = {
has_building = fort_15th
has_building = fort_16th
has_building = fort_17th
has_building = fort_18th
has_construction = building
}
}
NOT = { is_capital = yes }
}
}
modifier = {
factor = 0.8
AND {
any_neighbor_province = {
owned_by = ROOT
any_neighbor_province = {
owned_by = ROOT
OR = {
has_building = fort_15th
has_building = fort_16th
has_building = fort_17th
has_building = fort_18th
has_construction = building
}
}
}
NOT = { is_capital = yes }
}
}
modifier = {
factor = 0.8
OR = {
has_terrain = forest
has_terrain = hills
has_terrain = mountain
has_terrain = marsh
has_terrain = highlands
has_terrain = jungle
}
}
}
}