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

settlement_decisions = {

	convert_tribal_to_castle_anunnaki = {
		only_playable = yes
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		ai_check_interval = 1
		
		from_potential = {
			is_playable = yes
			OR = {
				is_feudal = yes
				is_republic = yes
			}
			higher_tier_than = BARON
			religion_group = ishtarian_group
		}
		
		potential = {
			holding_type = tribal
			holder_scope = {
				character = FROM
			}
		}
		allow = {
			FROM = {
				OR = {
					trait = giant_king
					AND = {
						prestige = 200
						religion = anunnaki
					}
					AND = {
						prestige = 300
						religion = ishtarian
					}
				}
			}
		}
		
		effect = {
			convert_to = CASTLE
			refill_holding_levy = yes 		
			
			if = {
				limit = {
					FROM = { NOT = { trait = giant_king } }
					religion = anunnaki
				}
				FROM = { prestige = -200 }
			}
			if = {
				limit = {
					FROM = { NOT = { trait = giant_king } }
					religion = ishtarian
				}
				FROM = { prestige = -300 }
			}
			
			hidden_tooltip = {
				location = { #Clear Tribal Great Pillars
					clr_province_flag = flag_great_pillar_norse
					clr_province_flag = flag_great_pillar_tengri
					clr_province_flag = flag_great_pillar_slavic
					clr_province_flag = flag_great_pillar_baltic
					clr_province_flag = flag_great_pillar_finnish
					clr_province_flag = flag_great_pillar_west_african
					clr_province_flag = flag_great_pillar_aztec
					clr_province_flag = flag_great_pillar_bon
					clr_province_flag = flag_great_pillar_zun
					clr_province_flag = flag_great_pillar_hellenic
				}
				if = {
					limit = {
						is_capital = yes
						dejure_liege_title = {
							location = {
								num_of_empty_holdings = 1
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = city
								}
							}
						}
					}
					random = {
						chance = 50
						location = {
							build_holding = {
								type = city
							}
						}
					}
				}
				if = {
					limit = {
						is_capital = yes
						dejure_liege_title = {
							location = {
								num_of_empty_holdings = 1
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = temple
								}
							}
						}
					}
					location = {
						build_holding = {
							type = temple
						}
					}
				}
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
			modifier = {			# favours castles on the coast
				factor = 1.5
				ROOT = { location = { port = yes } }
			}
			modifier = {			# disfavours castles if republic 
				factor = 0.25
				FROM = { is_republic = yes }
			}
		}
	}
	
	
	convert_tribal_to_city_anunnaki = {
		only_playable = yes
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		ai_check_interval = 1
		
		from_potential = {
			is_playable = yes
			OR = {
				is_feudal = yes
				is_republic = yes
			}
			higher_tier_than = BARON
			religion_group = ishtarian_group
		}
		
		potential = {
			holding_type = tribal
			holder_scope = {
				character = FROM
			}
		}
		allow = {
			FROM = {
				OR = {
					trait = giant_king
					AND = {
						prestige = 200
						religion = anunnaki
					}
					AND = {
						prestige = 300
						religion = ishtarian
					}
				}
			}
		}
		effect = {
			convert_to = CITY
			refill_holding_levy = yes 
			
			if = {
				limit = {
					FROM = { NOT = { trait = giant_king } }
					religion = anunnaki
				}
				FROM = { prestige = -200 }
			}
			if = {
				limit = {
					FROM = { NOT = { trait = giant_king } }
					religion = ishtarian
				}
				FROM = { prestige = -300 }
			}
			
			hidden_tooltip = {
				location = { #Clear Tribal Great Pillars
					clr_province_flag = flag_great_pillar_norse
					clr_province_flag = flag_great_pillar_tengri
					clr_province_flag = flag_great_pillar_slavic
					clr_province_flag = flag_great_pillar_baltic
					clr_province_flag = flag_great_pillar_finnish
					clr_province_flag = flag_great_pillar_west_african
					clr_province_flag = flag_great_pillar_aztec
					clr_province_flag = flag_great_pillar_bon
					clr_province_flag = flag_great_pillar_zun
					clr_province_flag = flag_great_pillar_hellenic
				}
				if = {
					limit = {
						is_capital = yes
						dejure_liege_title = {
							location = {
								num_of_empty_holdings = 1
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = castle
								}
							}
						}
					}
					random = {
						chance = 50
						location = {
							build_holding = {
								type = castle 
							}
						}
					}
				}
				
				if = {
					limit = {
						is_capital = yes
						dejure_liege_title = {
							location = {
								num_of_empty_holdings = 1
							}
							NOT = {
								any_direct_de_jure_vassal_title = {
									holding_type = temple
								}
							}
						}
					}
					location = {
						build_holding = {
							type = temple
						}
					}
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 1
			modifier = {			# disfavours cities on the coast 
				factor = 0.25
				ROOT = { location = { port = yes } }
			}
			modifier = {			# favours cities if republic 
				factor = 1.5
				FROM = { is_republic = yes }
			}
		}
	}
	
	
	
	
}	# closed decision bracket