# Title decisions are possible vs _all_ titles and are shown in the Title Diplomacy View, not the Intrigue View. The taker is in the FROM scope.
#
# filter = [capital/primary_title/owned/vassal_owned/sub_realm_owned/realm_owned/dynasty_owned/all]
# ai_target_filter = [capital/primary_title/owned/vassal_owned/sub_realm_owned/realm_owned/dynasty_owned/all] (which titles for which the AI evaluates the decision.)
#	owned: all titles owned by the AI
#	vassal_owned: all titles owned by direct vassal rulers of the AI's employer
#	sub_realm_owned: all titles below the AI's employer
#	realm_owned: all titles in the same top realm as the AI
#	dynasty_owned: all titles owned by members of the same dynasty
#	all: all titles (Avoid if possible. VERY CPU-HEAVY!)
#

title_decisions = {
	abandon_province = {
		# filter = sub_realm_owned # CleanSlate: Nonfunctional

		ai = no

		from_potential = {
			is_nomadic = yes
			has_dlc = "Horse Lords"
		}

		potential = {
			tier = COUNT

			location = {
				owner = {
					OR = {
						character = FROM
						is_vassal_or_below_of = FROM
					}
				}

				any_neighbor_province = {
					owner = {
						NOT = { same_realm = FROM }
					}
				}
			}
		}

		allow = {
			location = {
				num_of_settlements == 0
			}

			has_siege = no

			FROM = {
				war = no
			}

			location = {
				NOT = { has_province_modifier = nomads_exploited_land }
			}
		}

		effect = {
			holder_scope = {
				show_scope_change = no

				capital_holding = {
					show_scope_change = no

					add_holding_modifier = {
						name = nomad_population_boom
						years = 8
						stacking = yes
					}
				}

				hidden_effect = {
					top_liege = {
						if = {
							limit = { NOT = { character = PREV } }

							capital_holding = {
								add_holding_modifier = {
									name = nomad_population_boom_spillover
									years = 8
									stacking = yes
								}
							}
						}

						any_vassal = {
							limit = {
								clan = yes
								NOT = { character = PREVPREV }
							}

							capital_holding = {
								add_holding_modifier = {
									name = nomad_population_boom_spillover
									years = 8
									stacking = yes
								}
							}
						}
					}
				}
			}

			location = {
				show_scope_change = no

				random_neighbor_province = {
					show_scope_change = no

					limit = {
						owner = {
							NOT = {
								same_realm = FROM
							}
						}
					}

					owner = {
						show_scope_change = no

						grant_title = ROOT
					}
				}
			}

			location = {
				show_scope_change = no

				add_province_modifier = {
					name = nomads_exploited_land
					years = 8
				}
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	reclaim_nomad_province = {
		# filter = sub_realm_owned # CleanSlate: Nonfunctional
		ai_target_filter = sub_realm_owned
		ai_check_interval = 36

		is_high_prio = yes

		ai = no

		from_potential = {
			always = no # Disabled in CK2Plus
			is_nomadic = yes
			has_dlc = "Horse Lords"

			trigger_if = {
				limit = { ai = yes }
				war = no
			}

			any_realm_province = {
				has_province_modifier = nomad_agitation
				held_under_PREV = yes
			}
		}

		potential = {
			tier = COUNT

			location = {
				has_province_modifier = nomad_agitation

				owner = {
					is_vassal_or_below_of = FROM
					is_nomadic = no
					ai = yes
				}
			}
		}

		allow = {
			FROM = {
				war = no
			}

			location = {
				has_province_modifier = nomad_agitation
			}
		}

		effect = {
			location = {
				show_scope_change = no

				ROOT = {
					show_scope_change = no

					grant_title = FROM
				}

				remove_province_modifier = nomad_agitation
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	set_crown_focus = { # High Prio version
		# filter = owned # CleanSlate: Nonfunctional
		ai_target_filter = owned
		ai_check_interval = 12

		is_high_prio = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			is_nomadic = no
			higher_real_tier_than = COUNT

			NOT = {
				any_demesne_province = {
					has_province_flag = crown_focus_province
					owned_by = PREV
				}
			}
		}

		potential = {
			holder = FROM
			tier = COUNT
		}

		allow = {
			location = {
				capital_holding = {
					has_siege = no
					is_occupied = no
				}
			}

			FROM = {
				trigger_if = {
					limit = { independent = yes }
					higher_real_tier_than = COUNT
				}
				trigger_else = {
					OR = {
						AND = {
							independent = yes
							higher_real_tier_than = COUNT
						}

						AND = {
							real_tier = DUKE
							realm_size >= 35
						}

						AND = {
							real_tier = KING
							realm_size >= 55
						}

						is_merchant_republic = yes

						# AI only
						hidden_trigger = {
							OR = {
								is_republic = yes
								government = order_government
							}
						}
					}
				}
			}
		}

		effect = {
			FROM = {
				any_demesne_province = {
					limit = {
						has_province_flag = crown_focus_province
						owned_by = PREV
					}

					clr_province_flag = crown_focus_province
				}
			}

			location = {
				set_province_flag = crown_focus_province
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	move_crown_focus = {
		filter = owned
		ai_target_filter = owned
		ai_check_interval = 120

		only_playable = yes

		from_potential = {
			has_dlc = "Reapers"
			is_nomadic = no
			higher_tier_than = COUNT

			any_demesne_province = {
				has_province_flag = crown_focus_province
				owned_by = PREV
			}
		}

		potential = {
			holder = FROM
			tier = COUNT

			NOT = {
				location = {
					has_province_flag = crown_focus_province
				}
			}
		}

		allow = {
			hidden_trigger = {
				FROM = {
					trigger_if = {
						limit = { ai = yes }

						NOT = {
							any_demesne_province = {
								has_province_flag = crown_focus_province
								owned_by = PREV
							}
						}
					}
				}
			}

			location = {
				capital_holding = {
					has_siege = no
					is_occupied = no
				}
			}

			FROM = {
				trigger_if = {
					limit = { independent = yes }
					higher_tier_than = COUNT
				}
				trigger_else = {
					OR = {
						AND = {
							independent = yes
							higher_tier_than = COUNT
						}

						AND = {
							tier = DUKE
							realm_size >= 35
						}

						AND = {
							tier = KING
							realm_size >= 55
						}

						is_merchant_republic = yes

						# AI only
						hidden_trigger = {
							OR = {
								is_republic = yes
								government = order_government
							}
						}
					}
				}
			}
		}

		effect = {
			FROM = {
				any_demesne_province = {
					limit = {
						has_province_flag = crown_focus_province
						owned_by = PREV
					}

					clr_province_flag = crown_focus_province
				}
			}

			location = {
				set_province_flag = crown_focus_province
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

}