# 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 = {
	
	tribal_build_city = {
		filter = owned
		ai_target_filter = owned
		
		from_potential = {
			is_feudal = yes
		}
		potential = {
			tier = COUNT
			location = {
				num_of_empty_holdings = 1
				has_province_modifier = new_buildings_timer
				NOT = { has_province_modifier = building_new_city }
				NOT = { any_province_holding = { holding_type = city } }
			}
		}
		allow = {
			is_occupied = no
			location = {
				culture = FROM
				num_of_empty_holdings = 1
			}
			FROM = {
				war = no
				wealth = 100
				custom_tooltip = {
					text = NOT_BUILDING_CITY
					hidden_tooltip = {
						NOT = {
							any_demesne_province = { has_province_modifier = building_new_city }
						}
					}
				}
			}
		}
		effect = {
			FROM = {
				wealth = -100
			}
			location = {
				custom_tooltip = {
					text = CITY_CONSTRUCTION_BEGINS
					hidden_tooltip = {
						set_province_flag = tribal_build_city
						add_province_modifier = {
							name = building_new_city
							duration = -1
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.05
				always = yes
			}
			modifier = {
				factor = 5
				location = { is_capital = yes }
			}
			modifier = {
				factor = 3
				location = {
					OR = {
						has_building = tb_market_town_3
						has_building = tb_market_town_4
					}
				}
			}
			modifier = {
				factor = 2
				location = {
					OR = {
						has_building = tb_market_town_1
						has_building = tb_market_town_2
					}
				}
			}
			modifier = {
				factor = 1.5
				location = {
					OR = {
						has_building = tb_shipyard_1
						has_building = tb_shipyard_2
						has_building = tb_shipyard_3
						has_building = tb_shipyard_4
					}
				}
			}
			modifier = {
				factor = 0
				FROM = { has_character_modifier = ai_austerity }
			}
		}
	}

	tribal_build_temple = {
		filter = owned
		ai_target_filter = owned
		
		from_potential = {
			is_feudal = yes
		}
		potential = {
			tier = COUNT
			location = {
				num_of_empty_holdings = 1
				has_province_modifier = new_buildings_timer
				NOT = { has_province_modifier = building_new_temple }
				NOT = { any_province_holding = { holding_type = temple } }
			}
		}
		allow = {
			is_occupied = no
			location = {
				religion = FROM
				culture = FROM
				num_of_empty_holdings = 1
			}
			FROM = {
				war = no
				wealth = 100
				custom_tooltip = {
					text = NOT_BUILDING_TEMPLE
					hidden_tooltip = {
						NOT = {
							any_demesne_province = { has_province_modifier = building_new_temple }
						}
					}
				}
				custom_tooltip = {
					text = HAS_POSSIBLE_TEMPLE_BUILDER
					hidden_tooltip = {
						any_courtier = {
							is_adult = yes
							prisoner = no
							religion = PREV
							culture = PREV
							is_ruler = no
							health = 4
							OR = {
								trait = detached_priest
								trait = martial_cleric
								trait = scholarly_theologian
								trait = mastermind_theologian
								AND = {
									learning = 8
									trait = zealous
								}
							}
							OR = {
								is_female = no
								religion_allows_female_temple_holders = yes
							}
							OR = {
								NOT = { dynasty = 0 }
								trait = ambitious
								trait = zealous
							}
							NOR = {
								trait = incapable
								trait = cynical
								trait = content
								trait = stressed
								trait = depressed
								trait = imbecile
								any_heir_title = { always = yes }
								has_character_modifier = planning_new_temple
								has_character_modifier = planning_claimant_adventure
								has_character_modifier = planning_duchy_adventure
								has_character_flag = claimant_adventurer
							}
						}
					}
				}
			}
		}
		effect = {
			FROM = {
				wealth = -100
				piety = 25
				character_event = { id = Plus.1422 tooltip = FIND_TEMPLE_BUILDER }
			}
			hidden_tooltip = {
				location = {
					set_province_flag = building_new_temple_check
					add_province_modifier = {
						name = building_new_temple
						duration = -1
					}
				}
			}
		}
	}

	establish_tribe = {
		filter = owned
		ai_target_filter = owned
		
		from_potential = {
			is_tribal = yes
		}
		potential = {
			tier = COUNT
			location = {
				num_of_empty_holdings = 1
				NOT = { num_of_settlements = 1 }
				NOT = { has_province_modifier = building_new_city }
				NOT = { has_province_modifier = building_new_temple }
			}
		}
		allow = {
			is_occupied = no
			location = {
				NOT = { num_of_settlements = 1 }
			}
			FROM = {
				war = no
				prestige = 100
			}
		}
		effect = {
			FROM = {
				prestige = -100
			}
			location = {
				build_holding = { type = tribal }
				hidden_tooltip = {
					any_province_holding = { make_capital_holding = yes }
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
				always = yes
			}
		}
	}
	
	establish_castle = {
		filter = owned
		ai_target_filter = owned
		
		from_potential = {
			is_tribal = no
			is_nomadic = no
		}
		potential = {
			tier = COUNT
			location = {
				num_of_empty_holdings = 1
				NOT = { num_of_settlements = 1 }
				NOT = { has_province_modifier = building_new_city }
				NOT = { has_province_modifier = building_new_temple }
			}
		}
		allow = {
			is_occupied = no
			location = {
				NOT = { num_of_settlements = 1 }
			}
			FROM = {
				war = no
				wealth = 100
			}
		}
		effect = {
			FROM = {
				wealth = -100
			}
			location = {
				build_holding = { type = castle }
				hidden_tooltip = {
					any_province_holding = { make_capital_holding = yes }
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.1
				always = yes
			}
			modifier = {
				factor = 0
				FROM = { has_character_modifier = ai_austerity }
			}
		}
	}
	
	constantinople_emperor_revoke = {
		filter = vassal_owned
		ai_target_filter = vassal_owned
		is_high_prio = yes
		
		from_potential = {
			has_landed_title = e_byzantium
			e_byzantium = { is_primary_holder_title = yes }
			OR = {
				religion = chalcedonian
				religion = orthodox
				religion = bogomilist
				religion = monothelite
				religion = iconoclast
			}
		}
		potential = {
			OR = {
				AND = {
					title = b_hagiasophia
					holder_scope = { NOT = { religion = FROM } }
				}
				AND = {
					title = c_byzantion
					NOT = { holder = FROM }
				}
			}
		}
		allow = {
			FROM = { has_regent = no }
		}
		effect = {
			usurp_title = FROM
		}
		ai_will_do = {
			factor = 1
		}
	}
	
    raise_flag = { # Flag only the county capital
        filter = realm_owned
       
        from_potential = {
            ai = no
        }
        potential = {
            holder_scope = {
                has_character_modifier = nhv_explained
                NOT = { has_character_modifier = nhv_shut_off }
            }
            owner = { character = FROM }
            hidden_tooltip = {
                location = {
                    NOT = { has_province_flag = keep_it }
                }
            }
            real_tier = COUNT
        }
        allow = {
            always = yes
        }
        effect = {
            location = {
                set_province_flag = keep_it
            }
        }
        revoke_allowed = {
            always = no
        }
        ai_will_do = {
            factor = 0
        }
    }
	
	raise_all_flag = { # Flag everything owned in the county
        filter = realm_owned
       
        from_potential = {
            ai = no
        }
        potential = {
            holder_scope = {
                has_character_modifier = nhv_explained
                NOT = { has_character_modifier = nhv_shut_off }
            }
            owner = { character = FROM }
            hidden_tooltip = {
                location = {
                    NOT = { has_province_flag = keep_it }
                }
            }
            real_tier = COUNT
        }
        allow = {
            always = yes
        }
        effect = {
            location = {
                set_province_flag = keep_it
                set_province_flag = keep_baronies
            }
        }
        revoke_allowed = {
            always = no
        }
        ai_will_do = {
            factor = 0
        }
    }	

    lower_flag = { # Unflag the county
        filter = realm_owned
       
        from_potential = {
            ai = no
        }
        potential = {
            holder_scope = {
                has_character_modifier = nhv_explained
                NOT = { has_character_modifier = nhv_shut_off }
            }
            owner = { character = FROM }
            hidden_tooltip = {
                location = {
                    has_province_flag = keep_it
                }
            }
            real_tier = COUNT
        }
        allow = {
            always = yes
        }
        effect = {
            location = {
                clr_province_flag = keep_it
                clr_province_flag = keep_baronies
            }
        }
        revoke_allowed = {
            always = no
        }
        ai_will_do = {
            factor = 0
        }
    }

	scourge_province = {
		filter = owned
		ai_target_filter = owned
		
		from_potential = {
			religion_group = pagan_group
			is_reformed_religion = no
			pacifist = no
		}
		potential = {
			tier = COUNT
			location = {
				NOT = { religion = FROM }
			}
		}
		allow = {
			is_occupied = no
			location = {
				NOT = { has_province_modifier = peasant_unrest }
			}
			FROM = {
				piety = 100
			}
		}
		effect = {
			hidden_tooltip = {
				location = {
					province_event = { id = Plus.960 }
				}
			}
		}
		ai_will_do = {
			factor = 1
			modifier = {
				factor = 0.05
				always = yes
			}
			modifier = {
				factor = 0
				FROM = { religion = tengri_pagan }
			}
			modifier = {
				factor = 0
				FROM = {
					NAND = {
						trait = cruel
						trait = zealous
					}
				}
			}
		}
	}
}

