decisions = {
	create_leon = {
		is_high_prio = yes
		only_independent = yes
		ai_check_interval = 60
		
		potential = {
			tier = KING
			has_landed_title = k_asturias
			k_leon = { has_holder = no }
			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random_including_duchies
				}
			}
		}

		allow = {
			is_adult = yes
			war = no
			NOT = { trait = incapable }
			primary_title = { title = k_asturias }
			completely_controls = d_leon
			#completely_controls = d_asturias
			is_vice_royalty = no
		}
		effect = {
			activate_title = { title = k_leon status = yes }
			k_asturias = {
				show_scope_change = no
				k_leon = {
					show_scope_change = no
					grant_title = ROOT
					hidden_tooltip = { make_primary_title = yes }
					copy_title_laws = PREV
					copy_title_history = PREV
				}
				hidden_tooltip = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = k_leon
					}
					destroy_landed_title = THIS
				}
			}
			if = {
				limit = {
					has_landed_title = c_leon
					NOT = { capital_scope = { province_id = 190 } }

				}
				c_leon = { 
					show_scope_change = no
					ROOT = { 
						show_scope_change = no
						capital = PREV 
					} 
				}
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			activate_title = { title = k_asturias status = no }
			
			hidden_tooltip = {
				character_event = { id = 62920 }
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62921 }
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	
	create_castille = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 60
		
		potential = {
			NOT = { 
				higher_tier_than = DUKE 
			}
			has_landed_title = d_castilla
			k_castille = {
				has_holder = no
			}
			k_castille = {
				is_titular = yes
			}
			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random_including_duchies
				}
			}
		}
		allow = {
			is_adult = yes
			independent = yes
			war = no
			NOT = { trait = incapable }
			completely_controls = d_castilla
			conditional_tooltip =  {
				trigger = {
					ai = no
				}

				prestige = 1000
			}
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			primary_title = {
				save_event_target_as = current_primary_title
			}
			activate_title = { title = k_castille status = yes }
			k_castille = {
				show_scope_change = no
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
			}
			d_castilla = {
				show_scope_change = no
				de_jure_liege = k_castille
			}
			if = {
				limit = { completely_controls = d_toledo }
				d_toledo = {
					show_scope_change = no
					de_jure_liege = k_castille
				}
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62923 }
				}
			}
			if = {
				limit = {
					has_landed_title = c_burgos
					NOT = { capital_scope = { province_id = 199 } }

				}
				c_burgos = { 
					show_scope_change = no
					ROOT = { 
						show_scope_change = no
						capital = PREV 
					} 
				}
			}
			hidden_tooltip = { character_event = { id = 62922 } }
		}
		ai_will_do = {
			factor = 1
		}
	}

	create_portugal = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 60
		
		potential = {
			NOT = { 
				higher_tier_than = DUKE 
			}
			has_landed_title = d_porto
			k_portugal = {
				has_holder = no
			}
			k_portugal = {
				is_titular = yes
			}
			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random_including_duchies
				}
			}
		}
		allow = {
			is_adult = yes
			independent = yes
			war = no
			NOT = { trait = incapable }
			completely_controls = d_porto
			conditional_tooltip = {
				trigger = {
					ai = no
				}

				prestige = 1000
			}
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			primary_title = {
				save_event_target_as = current_primary_title
			}
			k_portugal = {
				show_scope_change = no
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
			}
			d_porto = {
				show_scope_change = no
				de_jure_liege = k_portugal
			}
			if = {
				limit = { completely_controls = d_beja }
				d_beja = {
					show_scope_change = no
					de_jure_liege = k_portugal
				}
			}
			if = {
				limit = {
					has_landed_title = c_porto
					NOT = { capital_scope = { province_id = 158 } }

				}
				c_porto = { 
					show_scope_change = no
					ROOT = { 
						show_scope_change = no
						capital = PREV 
					} 
				}
			}
			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62925 }
				}
			}
			hidden_tooltip = { character_event = { id = 62924 } }
		}
		ai_will_do = {
			factor = 1
		}
	}

	create_aragon = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 60
		
		potential = {
			NOT = { 
				higher_tier_than = DUKE 
			}
			has_landed_title = d_aragon
			k_aragon = {
				has_holder = no
			}
			k_aragon = {
				is_titular = yes
			}
			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random
				}
				has_alternate_start_setting = {
					setting = title_names
					value = random_including_duchies
				}
			}
		}
		allow = {
			is_adult = yes
			independent = yes
			war = no
			NOT = { trait = incapable }
			completely_controls = d_aragon
			conditional_tooltip = {
				trigger = {
					ai = no
				}

				prestige = 1000
			}
			wealth = 100
		}
		effect = {
			wealth = -100
			prestige = 500
			primary_title = {
				save_event_target_as = current_primary_title
			}
			k_aragon = {
				show_scope_change = no
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
			}
			d_aragon = {
				show_scope_change = no
				de_jure_liege = k_aragon
			}
			if = {
				limit = { completely_controls = d_barcelona }
				d_barcelona = {
					show_scope_change = no
					de_jure_liege = k_aragon
				}
			}
			hidden_tooltip = {
				any_playable_ruler = {
					limit = {
						ai = no
						capital_scope = {
							region = world_europe_west_iberia
						}
					}
					character_event = { id = 62927 }
				}
			}
			hidden_tooltip = { character_event = { id = 62926 } }
		}
		ai_will_do = {
			factor = 1
		}
	}

	ai_claim_county_if_baron = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 24

		potential = {
			higher_tier_than = COUNT
			war = no
			is_landed = yes
			is_patrician = no
			num_of_count_titles < 1
			any_realm_title = {
				tier = COUNT
				owner = { ai = yes }
			}
			ai = yes
		}
		effect = {
			random_realm_title = {
				limit = {
					tier = COUNT
					owner = { ai = yes }
				}
				preferred_limit = {
					location = { is_capital = no }
				}
				usurp_title_plus_barony_if_unlanded = { target = ROOT type = revoke }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}

	### POPE RELATED EVENTS ### 
	recreate_the_papal_guards = {
		is_high_prio = yes
		only_playable = yes
		ai_check_interval = 120

		potential = {
			has_landed_title = k_papal_state
			NOT = {
				is_title_active = d_papal_guards
			}
		}
		allow = {
			num_of_count_titles > 0
		}
		effect = {
			activate_title = { title = d_papal_guards status = yes }
			create_random_soldier = {
				random_traits = yes
				dynasty = random
			}
			new_character = {
				grant_title_no_opinion = d_papal_guards
				set_defacto_liege = ROOT
			}
		}
	}
}
