decisions = {

	create_leon = {
		is_high_prio = yes
		ai_check_interval = 60

		only_independent = yes

		potential = {
			has_landed_title = k_asturias
			real_tier = KING
			k_leon = { has_holder = no }

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			primary_title = { title = k_asturias }
			independent = yes
			completely_controls = d_leon
			completely_controls = d_asturias
			war = no
			is_not_in_regency_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			custom_tooltip = { text = asturias_becomes_leon_tooltip }

			k_asturias = {
				show_scope_change = no

				dejure_liege_title = {
					save_event_target_as = old_imperial_liege
				}

				k_leon = {
					show_scope_change = no

					grant_title = ROOT

					hidden_effect = {
						set_title_flag = non_manual_law_change # No prestige loss
						make_primary_title = yes
						copy_title_laws = PREV
						copy_title_history = PREV
						de_jure_liege = event_target:old_imperial_liege # Add Leon to Asturia's imperial liege
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				hidden_effect = {
					de_jure_liege = e_placeholder # Remove Asturias from the previous de Jure liege

					any_direct_de_jure_vassal_title = {
						de_jure_liege = k_leon
					}

					destroy_landed_title = THIS

					activate_title = {
						title = k_asturias
						status = no
					}
				}
			}

			if = {
				limit = {
					has_landed_title = c_leon

					capital_scope = {
						NOT = { province_id = c_leon }
					}
				}

				capital = c_leon
			}

			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}

			character_event = { id = 62920 } # Notify

			any_player = {
				limit = {
					NOT = { character = ROOT }

					capital_scope = {
						region = world_europe_west_iberia
					}
				}

				character_event = { id = 62921 } # Notify
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	create_castille = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_castilla
			independent = yes
			real_tier = DUKE
			year >= 1000

			k_castille = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_castilla
			prestige >= 1000
			wealth >= 100
			war = no
			is_not_in_regency_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			wealth = -100
			prestige = 500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			k_castille = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			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_landed_title = c_burgos

					capital_scope = {
						NOT = { province_id = c_burgos }
					}
				}

				capital = c_burgos
			}

			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}

			character_event = { id = 62922 } # Notify

			any_player = {
				limit = {
					NOT = { character = ROOT }

					capital_scope = {
						region = world_europe_west_iberia
					}
				}

				character_event = { id = 62923 } # Notify
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	create_portugal = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_portucale
			real_tier = DUKE
			year >= 1000

			k_portugal = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_portucale
			independent = yes
			prestige >= 1000
			wealth >= 100
			war = no
			is_not_in_regency_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			wealth = -100
			prestige = 500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			k_portugal = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			d_portucale = {
				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

					capital_scope = {
						NOT = { province_id = c_porto }
					}
				}

				capital = c_porto
			}

			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}

			character_event = { id = 62924 } # Notify

			any_player = {
				limit = {
					NOT = { character = ROOT }

					capital_scope = {
						region = world_europe_west_iberia
					}
				}

				character_event = { id = 62925 } # Notify
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	create_aragon = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_aragon
			real_tier = DUKE

			k_aragon = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_aragon
			independent = yes
			prestige >= 1000
			wealth >= 100
			war = no
			is_not_in_regency_trigger = yes
			is_inaccessible_trigger = no
		}

		effect = {
			wealth = -100
			prestige = 500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			k_aragon = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			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
				}
			}

			if = {
				limit = {
					has_landed_title = c_zaragoza

					capital_scope = {
						NOT = { province_id = c_zaragoza }
					}
				}

				capital = c_zaragoza
			}

			character_event = { id = 62926 } # Notify

			any_player = {
				limit = {
					NOT = { character = ROOT }

					capital_scope = {
						region = world_europe_west_iberia
					}
				}

				character_event = { id = 62927 } # Notify
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	create_antioch = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_antioch
			lower_real_tier_than = DUKE
			religion = catholic

			k_antioch = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_antioch
			num_of_duke_titles >= 2
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 1000
			}

			wealth >= 100
		}

		effect = {
			wealth = -100

			primary_title = {
				save_event_target_as = current_primary_title
			}

			k_antioch = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			d_antioch = {
				show_scope_change = no

				de_jure_liege = k_antioch
			}

			if = {
				limit = { has_landed_title = d_tripoli }

				d_tripoli = {
					show_scope_change = no

					de_jure_liege = k_antioch
				}
			}

			if = {
				limit = { has_landed_title = d_edessa }

				d_edessa = {
					show_scope_change = no

					de_jure_liege = k_antioch
				}
			}

			if = {
				limit = { has_landed_title = d_aleppo }

				d_aleppo = {
					show_scope_change = no

					de_jure_liege = k_antioch
				}
			}

			if = {
				limit = {
					has_landed_title = c_antioch

					capital_scope = {
						NOT = { province_id = c_antioch }
					}
				}

				capital = c_antioch
			}

			narrative_event = { id = HFP.40013 } # Notify
		}
	}

	create_cyprus = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_cyprus
			lower_real_tier_than = KING
			religion = catholic # TODO: Catholic branch?

			k_cyprus = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_cyprus
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 1000
			}

			wealth >= 100
		}

		effect = {
			wealth = -100

			primary_title = {
				save_event_target_as = current_primary_title
			}

			k_cyprus = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			d_cyprus = {
				show_scope_change = no

				de_jure_liege = k_cyprus
			}

			if = {
				limit = {
					has_landed_title = c_famagusta

					capital_scope = {
						NOT = { province_id = c_famagusta }
					}
				}

				capital = c_famagusta
			}

			narrative_event = { id = HFP.40014 } # Notify
		}
	}

	create_powys = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = c_powys
			has_landed_title = c_shrewsbury
			has_landed_title = c_hereford
			lower_real_tier_than = DUKE

			d_powys = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			is_adult = yes
			independent = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 500
			}

			wealth >= 100
		}

		effect = {
			wealth = -100
			prestige = 250

			primary_title = {
				save_event_target_as = current_primary_title
			}

			d_powys = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			c_powys      = { show_scope_change = no de_jure_liege = d_powys }
			c_shrewsbury = { show_scope_change = no de_jure_liege = d_powys }
			c_hereford   = { show_scope_change = no de_jure_liege = d_powys }
		}
	}

	create_kingdom_amalfi = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_amalfi
			is_republic = yes
			lower_real_tier_than = KING

			k_amalfi = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = c_amalfi
			num_of_duke_titles >= 2
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 500
				wealth >= 500
			}
		}

		effect = {
			wealth = -500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			c_amalfi = {
				show_scope_change = no

				de_jure_liege = d_amalfi
			}

			d_amalfi = {
				show_scope_change = no

				de_jure_liege = k_amalfi
			}

			k_amalfi = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			narrative_event = { id = HFP.40015 } # Notify
		}
	}

	create_kingdom_pisa = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_pisa
			is_republic = yes
			lower_real_tier_than = KING

			k_pisa = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = c_pisa
			has_landed_title = c_piombino
			num_of_duke_titles >= 2
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 500
				wealth >= 500
			}
		}

		effect = {
			wealth = -500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			d_pisa = {
				show_scope_change = no

				de_jure_liege = k_pisa
			}

			k_pisa = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			narrative_event = { id = HFP.40015 } # Notify
		}
	}

	create_kingdom_venice = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_venice
			is_republic = yes
			lower_real_tier_than = KING

			k_venice = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = c_venezia
			num_of_duke_titles >= 2
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 500
				wealth >= 500
			}
		}

		effect = {
			wealth = -500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			d_venice = {
				show_scope_change = no

				de_jure_liege = k_venice
			}

			k_venice = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			narrative_event = { id = HFP.40015 } # Notify
		}
	}

	create_kingdom_genoa = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = d_genoa
			is_republic = yes
			lower_real_tier_than = KING

			k_genoa = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = c_genoa
			num_of_duke_titles >= 2
			independent = yes
			is_adult = yes
			war = no
			is_incapable = no

			trigger_if = {
				limit = { ai = no }
				prestige >= 500
				wealth >= 500
			}
		}

		effect = {
			wealth = -500

			primary_title = {
				save_event_target_as = current_primary_title
			}

			d_genoa = {
				show_scope_change = no

				de_jure_liege = k_genoa
			}

			k_genoa = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = event_target:current_primary_title
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			narrative_event = { id = HFP.40015 } # Notify
		}
	}

	create_the_hansa = {
		ai_check_interval = 120

		is_high_prio = yes

		ai = no

		potential = {
			has_dlc = "The Republic"
			has_landed_title = d_mecklemburg
			is_government_potential = merchant_republic_government
			lower_real_tier_than = KING
			religion_group = christian

			top_liege = {
				has_landed_title = e_hre
			}

			OR = {
				culture = german
				culture = saxon
				culture = pomeranian
			}

			k_hansa = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = d_mecklemburg
			has_landed_title = c_lubeck

			capital_scope = {
				province_id = c_lubeck
			}

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}

			is_adult = yes
			war = no
			prestige >= 1000
			wealth   >= 1000
		}

		effect = {
			wealth = -1000

			custom_tooltip = {
				text = create_the_hansa_tooltip

				if = {
					limit = {
						c_lubeck = {
							capital_holding = {
								NOT = { holding_type = city }
							}
						}
					}

					if = {
						limit = {
							is_title_active = b_lubeck

							b_lubeck = {
								holding_type = city
							}
						}

						ROOT = {
							b_lubeck = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_ratzeburg

							b_ratzeburg = {
								holding_type = city
							}
						}

						ROOT = {
							b_ratzeburg = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_travemunde

							b_travemunde = {
								holding_type = city
							}
						}

						ROOT = {
							b_travemunde = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_schlutup

							b_schlutup = {
								holding_type = city
							}
						}

						ROOT = {
							b_schlutup = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_starigard

							b_starigard = {
								holding_type = city
							}
						}

						ROOT = {
							b_starigard = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_weslo

							b_weslo = {
								holding_type = city
							}
						}

						ROOT = {
							b_weslo = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_bucu

							b_bucu = {
								holding_type = city
							}
						}

						ROOT = {
							b_bucu = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
					else_if = {
						limit = {
							is_title_active = b_wulfsdorf

							b_wulfsdorf = {
								holding_type = city
							}
						}

						ROOT = {
							b_wulfsdorf = {
								grant_title = PREV
								make_capital_holding = yes
							}
						}
					}
				}

				create_family_palace = yes
				set_government_type = merchant_republic_government

				if = {
					limit = {
						num_of_government_vassals = {
							government = merchant_republic_government
							value < 1
						}
					}

					# Gives random vassals a family palace
					any_unique_dynasty_vassal = {
						count = 4

						limit = {
							OR = {
								is_republic = yes
								is_tribal = yes
							}

							is_female = no
							is_patrician = no
							prisoner = no
							is_incapable = no
							is_adult = yes
							is_lowborn = no
						}

						create_family_palace = yes
					}
				}

				if = {
					limit = {
						ai = no
						is_ironman = yes
					}

					set_character_flag = achievement_res_publica
				}

				if = {
					limit = { ai = no }

					chronicle = {
						entry = CHRONICLE_FOUNDED_MERCHANT_REPUBLIC
						picture = GFX_evt_busy_trading_dock_republic
					}
				}

				e_hre = {
					holder_scope = {
						k_hansa = {
							grant_title = PREV
						}
					}
				}

				primary_title = {
					k_hansa = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				k_hansa = {
					grant_title_no_opinion = ROOT
					make_primary_title = yes
				}

				d_mecklemburg = {
					de_jure_liege = k_hansa
				}

				k_hansa = {
					de_jure_liege = e_hre
				}

				narrative_event = { id = HFP.40000 }

				set_global_flag = hansa_formed

				e_hre = {
					holder_scope = {
						any_vassal = {
							limit = {
								NOT = { character = ROOT }
							}

							narrative_event = {
								id = HFP.40001 # Notify
								days = 1
							}
						}
					}
				}
			}
		}
	}

	form_the_eastern_marches = {
		is_high_prio = yes

		ai = no

		potential = {
			primary_title = {
				title = k_bavaria
			}

			k_austria = {
				is_titular = yes
			}

			real_tier = KING
			religion_group = christian

			top_liege = {
				has_landed_title = e_hre
			}

			OR = {
				culture = german
				culture = frankish
			}

			NOR = {
				has_global_flag = eastern_marches_created

				has_alternate_start_setting = {
					setting = dejure
					option = random
				}
				has_alternate_start_setting = {
					setting = title_names
					option = random
				}
				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_styria
			completely_controls = d_osterreich
			completely_controls = d_salzburg
			completely_controls = d_bavaria
			completely_controls = d_carinthia
			completely_controls = d_friuli
			completely_controls = d_carniola
			completely_controls = d_tyrol

			is_adult = yes
			war = no
			prestige >= 1500
			wealth    >= 500
		}

		effect = {
			wealth = -500

			custom_tooltip = {
				text = eastern_marches_austria_TT

				set_global_flag = eastern_marches_created
				character_event = { id = HFP.40026 }
			}
		}
	}

	create_archduchy_of_austria = {
		ai_check_interval = 120

		is_high_prio = yes

		only_playable = yes

		potential = {
			OR = {
				has_landed_title = d_osterreich
				has_landed_title = d_styria
			}

			top_liege = {
				has_landed_title = e_hre
			}

			religion_group = christian
			real_tier = DUKE
			is_adult = yes

			k_austria = {
				has_holder = no
				is_titular = yes
			}

			k_eastern_marches = {
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			completely_controls = d_osterreich
			completely_controls = d_styria

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}

			custom_tooltip = {
				text = emperor_likes_you_quite_a_lot_TT

				e_hre = {
					holder_scope = {
						opinion = {
							who = ROOT
							value >= 50
						}
					}
				}
			}

			is_adult = yes
			war = no

			OR = {
				prestige >= 3000

				AND = {
					intrigue >= 20
					prestige >= 1000
				}

				AND = {
					custom_tooltip = {
						text = same_dynasty_as_emperor_TT

						e_hre = {
							holder_scope = {
								dynasty = ROOT
							}
						}
					}

					prestige >= 1000
				}
			}

			wealth >= 1000
		}

		effect = {
			wealth = -1000

			custom_tooltip = {
				text = create_archduchy_of_austria_TT

				primary_title = {
					k_austria = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						copy_title_history = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				grant_title_no_opinion = k_austria
				set_defacto_liege = e_hre

				d_osterreich = {
					de_jure_liege = k_austria
				}

				d_styria = {
					de_jure_liege = k_austria
				}

				k_austria = {
					de_jure_liege = e_hre
				}

				any_player = {
					limit = { de_facto_liege_title = e_hre }
					narrative_event = { id = HFP.40022 } # Notify
				}
			}

			if = {
				limit = { has_landed_title = d_salzburg }

				d_salzburg = {
					show_scope_change = no

					de_jure_liege = k_austria
				}
			}

			if = {
				limit = {
					has_landed_title = d_salzburg
					has_landed_title = d_tyrol
				}

				d_tyrol = {
					show_scope_change = no

					de_jure_liege = k_austria
				}
			}
		}
	}

	form_the_outremer = {
		is_high_prio = yes

		ai = no

		potential = {
			any_demesne_title = {
				higher_real_tier_than = DUKE
				region = world_near_east
			}

			OR = {
				religion = catholic
				religion = fraticelli
			}

			NOR = {
				has_landed_title = e_byzantium
				has_landed_title = e_roman_empire
				has_landed_title = e_hre
			}

			e_outremer = {
				is_titular = yes
				has_holder = no
			}

			is_alternate_start = no
		}

		allow = {
			independent = yes
			is_adult = yes
			war = no
			prestige >= 5000

			custom_tooltip = {
				text = owns_jerusalem_tt
				has_landed_title = c_jerusalem
			}

			custom_tooltip = {
				text = completely_control_near_east_TT
				completely_controls_region = world_near_east
			}
		}

		effect = {
			custom_tooltip = {
				text = create_outremer_tt

				primary_title = {
					e_outremer = {
						grant_title_no_opinion = ROOT
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						copy_title_history = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}
			}

			if = {
				limit = {
					OR = {
						d_shiite    = { has_holder = yes }
						d_sunni     = { has_holder = yes }
						d_ibadi     = { has_holder = yes }
						d_kharijite = { has_holder = yes }
						d_yazidi    = { has_holder = yes }
						d_hurufi    = { has_holder = yes }
					}
				}

				custom_tooltip = {
					text = destroy_muslim_leadership

					destroy_landed_title = d_shiite
					destroy_landed_title = d_sunni
					destroy_landed_title = d_ibadi
					destroy_landed_title = d_kharijite
					destroy_landed_title = d_yazidi
					destroy_landed_title = d_hurufi
				}
			}

			hidden_effect = {
				any_demesne_title = {
					limit = {
						tier = EMPEROR
						NOT = { title = e_outremer }
					}

					destroy_landed_title = THIS
				}

				capital = c_jerusalem

				any_landed_title = {
					limit = {
						tier = KING
						region = world_middle_east
					}

					de_jure_liege = e_outremer
				}

				if = {
					limit = { completely_controls = k_egypt }

					k_egypt = {
						de_jure_liege = e_outremer
					}
				}
			}

			set_global_flag = destroyed_caliphates
			narrative_event = { id = HFP.40027 } # Notify

			if = {
				limit = {
					ai = no
					is_ironman = yes
				}

				set_character_flag = achievement_deus_vult
			}
		}
	}

	restore_byzantine_empire = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			e_byzantium = {
				has_holder = no
			}

			culture_group = byzantine
			higher_tier_than = DUKE

			OR = {
				religion_group = christian
				religion_openly_hellenic_or_reformed_trigger = yes
			}

			NOR = {
				has_landed_title = e_hre
				has_landed_title = e_latin_empire
			}

			e_roman_empire = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			has_landed_title = c_constantinopolis
			completely_controls = d_opsikion
			completely_controls = d_abydos
			completely_controls = d_adrianopolis

			c_thrake = {
				holder_scope = {
					OR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}
			}

			c_kaliopolis = {
				holder_scope = {
					OR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}
			}

			war = no
			prestige >= 4000
		}

		effect = {
			custom_tooltip = {
				text = restore_byzantine_empire_TT

				primary_title = {
					save_event_target_as = current_primary_title
				}

				e_byzantium = {
					set_title_flag = non_manual_law_change # No prestige loss
					copy_title_laws = event_target:current_primary_title
					add_law = succ_byzantine_elective

					# Ensure imperial government can be restored
					if = {
						limit = { has_dlc = "Conclave" }
						add_law = ze_administration_laws_2
					}
					else = {
						add_law = imperial_administration
					}

					clr_title_flag = non_manual_law_change # No prestige loss
				}

				grant_title = e_byzantium
				switch_to_imperial_effect = yes
				capital = c_constantinopolis

				any_demesne_title = {
					limit = {
						NOT = { title = e_byzantium }
						higher_tier_than = DUKE
					}

					destroy_landed_title = THIS
				}

				k_thrace = {
					de_jure_liege = e_byzantium
				}

				if = {
					limit = { religion = orthodox }

					k_orthodox = {
						holder_scope = {
							grant_title_no_opinion = b_hagiasophia
						}

						set_defacto_liege = e_byzantium
					}
				}

				any_player = {
					limit = { is_within_diplo_range = ROOT }
					narrative_event = { id = HFP.40024 } # Notify
				}
			}
		}
	}

	create_switzerland = {
		ai_check_interval = 60

		is_high_prio = yes

		only_playable = yes

		potential = {
			OR = {
				has_landed_title = d_thurgau
				has_landed_title = d_raetia
			}

			lower_real_tier_than = KING
			religion_group = christian

			top_liege = {
				has_landed_title = e_hre
			}

			OR = {
				culture = german
				culture = frankish
				culture = french
				culture = occitan
				culture = italian
				culture = lombard
			}

			k_switzerland = {
				has_holder = no
				is_titular = yes
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			is_adult = yes
			war = no
			prestige = 3000
			wealth = 500

			completely_controls = c_bern
			completely_controls = c_schwyz
			completely_controls = c_neuchatel
			completely_controls = c_zurichgau
			completely_controls = c_basel
			completely_controls = c_thurgau
			completely_controls = c_vaud
			completely_controls = c_chur

			has_landed_title = d_thurgau
			has_landed_title = d_raetia

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}
		}

		effect = {
			wealth = -500

			custom_tooltip = {
				text = custom_create_switzerland_tooltip

				d_transjurania = {
					de_jure_liege = k_switzerland
				}

				k_switzerland = {
					de_jure_liege = e_hre
				}

				e_hre = {
					holder_scope = {
						k_switzerland = {
							grant_title = PREV
						}
					}
				}

				primary_title = {
					k_switzerland = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				k_switzerland = {
					grant_title_no_opinion = ROOT
				}

				destroy_landed_title = d_raetia
				destroy_landed_title = d_thurgau
				grant_title_no_opinion = d_swiss

				d_thurgau = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = d_swiss
					}
				}

				d_raetia = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = d_swiss
					}
				}

				d_swiss = {
					de_jure_liege = k_switzerland
				}

				narrative_event = { id = HFP.40010 } # Notify

				any_player = {
					limit = {
						top_liege = {
							has_landed_title = e_hre
						}
						NOT = { has_landed_title = k_switzerland }
					}

					narrative_event = { id = HFP.40012 } # Notify
				}
			}
		}
	}

	ai_claim_county_if_baron = {
		ai_check_interval = 36

		is_high_prio = yes

		only_playable = yes
		ai = yes

		potential = {
			war = no
			is_landed = yes
			higher_real_tier_than = COUNT
			is_patrician = no
			num_of_count_titles	== 0

			any_vassal = {
				ai = yes
				num_of_count_titles > 0
			}
		}

		allow = {
		}

		effect = {
			random_vassal = {
				limit = {
					ai = yes
					num_of_count_titles > 0
				}

				random_demesne_title = {
					limit = { tier = COUNT }

					preferred_limit = {
						location = { is_capital = no }
					}

					usurp_title = PREV
				}
			}
		}

		ai_will_do = {
			factor = 1
		}
	}

	form_lcr = {
		ai_check_interval = 60

		is_high_prio = yes

		only_independent = yes

		potential = {
			independent = yes
			higher_real_tier_than = DUKE

			###  	Must be Slavic of Lech, Czech or Rus lineage
			OR = {
				culture = russian
				culture = polish
				culture = bohemian
				culture = volhynian
				culture = ilmenian
				culture = severian
				culture = pomeranian
			}

			e_slavic_union = {
				is_titular = yes
				has_holder = no
			}

			is_alternate_start = no
		}

		allow = {
			# Control Czech, Poland & Rus
			completely_controls = k_bohemia
			completely_controls = k_poland
			completely_controls = k_galicia-volhynia
			completely_controls = k_ruthenia
			completely_controls = k_chernigov
			completely_controls = k_vladimir
			completely_controls = k_novgorod

			is_adult = yes
			prestige >= 5000
			war = no
			is_incapable = no
			is_vice_royalty = no
		}

		effect = {
			custom_tooltip = {
				text = form_lcr_tt

				primary_title = {
					e_slavic_union = {
						set_title_flag = non_manual_law_change # No prestige loss
						grant_title_no_opinion = ROOT
						copy_title_laws = PREV
						copy_title_history = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}
			}

			if = {
				limit = { has_dlc = "Holy Fury" }

				if = {
					limit = { is_female = yes }

					create_bloodline = {
						type = lcr_female
					}

					new_bloodline = {
						set_description = lcr_female_desc
					}
				}
				else = {
					create_bloodline = {
						type = lcr_male
					}

					new_bloodline = {
						set_description = lcr_male_desc
					}
				}
			}

			hidden_effect = {
				if = {
					limit = {
						ai = no
						is_ironman = yes
					}

					set_character_flag = achievement_lcr
				}

				any_demesne_title = {
					limit = {
						real_tier = EMPEROR
						NOT = { title = e_slavic_union }
					}

					destroy_landed_title = THIS
				}

				### Slavic kingdoms go to LCR
				k_bohemia          = { de_jure_liege = e_slavic_union }
				k_poland           = { de_jure_liege = e_slavic_union }
				k_galicia-volhynia = { de_jure_liege = e_slavic_union }
				k_ruthenia         = { de_jure_liege = e_slavic_union }
				k_chernigov        = { de_jure_liege = e_slavic_union }
				k_vladimir         = { de_jure_liege = e_slavic_union }
				k_novgorod         = { de_jure_liege = e_slavic_union }

				### If you also completely control Pomerania, it's added to LCR as well
				if = {
					limit = { completely_controls = k_pomerania }
					k_pomerania = { de_jure_liege = e_slavic_union }
				}

				narrative_event = { id = HFP.99999 }
			}
		}
	}

	stem_duchy_of_saxony = {
		ai_check_interval = 120

		is_high_prio = yes

		only_playable = yes

		potential = {
			lower_real_tier_than = KING

			capital_scope = {
				OR = {
					province = c_oldenburg
					province = c_osnabruck
					province = c_munster
					province = c_paderborn
					province = c_braunschweig
					province = c_luneburg
					province = c_bremen
					province = c_werben
					province = c_hadeln
					province = c_minden
					province = c_verden
					province = c_magdeburg
				}
			}

			top_liege = {
				has_landed_title = e_hre
			}

			k_grand_saxony = {
				is_titular = yes
			}

			is_alternate_start = no
		}

		allow = {
			prestige >= 3000

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}

			real_tier = DUKE
			completely_controls = c_hadeln
			completely_controls = c_bremen
			completely_controls = c_verden
			completely_controls = c_luneburg
			completely_controls = c_braunschweig
			completely_controls = c_werben
			completely_controls = c_magdeburg
			completely_controls = c_oldenburg
			completely_controls = c_minden
			completely_controls = c_osnabruck
			completely_controls = c_paderborn
			completely_controls = c_munster
		}

		effect = {
			grant_title_no_opinion = k_grand_saxony

			hidden_effect = {
				set_defacto_liege = e_hre

				primary_title = {
					k_grand_saxony = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				d_saxony          = { de_jure_liege = k_grand_saxony }
				d_brunswick       = { de_jure_liege = k_grand_saxony }
				d_westphalia      = { de_jure_liege = k_grand_saxony }
				d_angria          = { de_jure_liege = k_grand_saxony }
				d_bremen          = { de_jure_liege = k_grand_saxony }

				narrative_event = { id = HFP.40038 } # Notify
			}
		}
	}

	stem_duchy_of_franconia = {
		ai_check_interval = 120

		is_high_prio = yes

		only_playable = yes

		potential = {
			capital_scope = {
				OR = {
					province = c_fritzlar
					province = c_aschaffenburg
					province = c_mainz
					province = c_worms
					province = c_wurzburg
					province = c_bamberg
					province = c_frankfurt
					province = c_weinsberg
					province = c_marburg
				}
			}

			top_liege = {
				has_landed_title = e_hre
			}

			lower_real_tier_than = KING

			k_grand_franconia = {
				is_titular = yes
			}

			is_alternate_start = no
		}

		allow = {
			prestige >= 3000

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}

			real_tier = DUKE
			completely_controls = c_bamberg
			completely_controls = c_wurzburg
			completely_controls = c_aschaffenburg
			completely_controls = c_weinsberg
			completely_controls = c_worms
			completely_controls = c_mainz
			completely_controls = c_frankfurt
			completely_controls = c_marburg
			completely_controls = c_fritzlar
		}

		effect = {
			grant_title_no_opinion = k_grand_franconia

			hidden_effect = {
				primary_title = {
					k_grand_franconia = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				d_franconia = { de_jure_liege = k_grand_franconia }
				d_rhine     = { de_jure_liege = k_grand_franconia }
				d_hesse     = { de_jure_liege = k_grand_franconia }

				set_defacto_liege = e_hre

				any_player = {
					limit = {
						top_liege = {
							has_landed_title = e_hre
						}
					}

					narrative_event = { id = HFP.40038 } # Notify
				}
			}
		}
	}

	stem_duchy_of_swabia = {
		ai_check_interval = 120

		is_high_prio = yes

		only_playable = yes

		potential = {
			capital_scope = {
				OR = {
					province = c_baden
					province = c_nordgau
					province = c_sundgau
					province = c_schwaben
					province = c_breisgau
					province = c_furstenberg
					province = c_ulm
					province = c_wurttemberg
					province = c_augsburg

					AND = {
						province = c_zurichgau
						d_thurgau = { is_titular = no }
					}

					AND = {
						province = c_thurgau
						d_thurgau = { is_titular = no }
					}

					AND = {
						province = c_schwyz
						d_raetia = { is_titular = no }
					}

					AND = {
						province = c_chur
						d_raetia = { is_titular = no }
					}
				}
			}

			top_liege = {
				has_landed_title = e_hre
			}

			lower_real_tier_than = KING

			k_grand_swabia = {
				is_titular = yes
			}

			is_alternate_start = no
		}

		allow = {
			prestige >= 3000

			custom_tooltip = {
				text = emperor_has_hre

				liege = {
					has_landed_title = e_hre
				}
			}

			real_tier = DUKE
			completely_controls = c_ulm
			completely_controls = c_augsburg
			completely_controls = c_schwaben
			completely_controls = c_wurttemberg
			completely_controls = c_furstenberg
			completely_controls = c_baden
			completely_controls = c_breisgau
			completely_controls = c_nordgau
			completely_controls = c_sundgau

			trigger_if = {
				limit = {
					d_thurgau = { is_titular = no }
				}

				completely_controls = c_thurgau
			}

			trigger_if = {
				limit = {
					d_thurgau = { is_titular = no }
				}

				completely_controls = c_zurichgau
			}

			trigger_if = {
				limit = {
					d_raetia = { is_titular = no }
				}

				completely_controls = c_chur
			}

			trigger_if = {
				limit = {
					d_raetia = { is_titular = no }
				}

				completely_controls = c_schwyz
			}
		}

		effect = {
			grant_title_no_opinion = k_grand_swabia

			hidden_effect = {
				set_defacto_liege = e_hre

				primary_title = {
					k_grand_swabia = {
						set_title_flag = non_manual_law_change # No prestige loss
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				d_swabia = { de_jure_liege = k_grand_swabia }
				d_baden  = { de_jure_liege = k_grand_swabia }
				d_alsace = { de_jure_liege = k_grand_swabia }

				d_thurgau = {
					if = {
						limit = { is_titular = no }
						de_jure_liege = k_grand_swabia
					}
				}

				d_raetia = {
					if = {
						limit = { is_titular = no }
						de_jure_liege = k_grand_swabia
					}
				}

				any_player = {
					limit = {
						top_liege = {
							has_landed_title = e_hre
						}
					}

					narrative_event = { id = HFP.40038 } # Notify
				}
			}
		}
	}

	create_bosnia = {
		is_high_prio = yes
		ai_check_interval = 24

		only_independent = yes

		potential = {
			culture = bosnian
			holy_order = no

			k_bosnia = {
				has_holder = no
			}

			NOR = {
				has_alternate_start_setting = {
					setting = dejure
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random
				}

				has_alternate_start_setting = {
					setting = title_names
					option = random_including_duchies
				}
			}
		}

		allow = {
			independent = yes
			culture = bosnian
			completely_controls = d_bosnia
			completely_controls = d_hum
			lower_real_tier_than = DUKE
			prestige >= 1500
			wealth >= 300
		}

		effect = {
			k_bosnia = {
				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = d_bosnia
				clr_title_flag = non_manual_law_change # No prestige loss
			}

			hidden_effect = {
				d_bosnia = {
					empire = {
						k_bosnia = {
							de_jure_liege = PREV
						}
					}
				}
			}

			d_bosnia = { de_jure_liege = k_bosnia }
			d_hum    = { de_jure_liege = k_bosnia }

			prestige >= 1000
			wealth   >= -300
		}

		ai_will_do = {
			factor = 1
		}
	}

	### POPE RELATED EVENTS ###
	recreate_the_papal_guards = {
		ai_check_interval = 120

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_landed_title = k_papacy
			NOT = { is_title_active = d_papal_guards }
		}

		allow = {
			num_of_count_titles > 0
		}

		effect = {
			create_random_soldier = {
				random_traits = yes
				dynasty = random
			}

			new_character = {
				grant_title_no_opinion = d_papal_guards

				set_defacto_liege = ROOT
			}
		}
	}

	create_russian_empire = {
		ai_check_interval = 120

		is_high_prio = yes

		only_independent = yes

		potential = {
			has_landed_title = e_rus
			culture = russian
			NOT = { has_landed_title = e_russia }
		}

		allow = {
			completely_controls = k_galicia-volhynia
			completely_controls = k_ruthenia
			completely_controls = k_chernigov
			completely_controls = k_novgorod
			completely_controls = k_vladimir
			completely_controls = k_nenets
			completely_controls = k_perm
			completely_controls = k_volga_bulgaria
			completely_controls = k_khazaria
			completely_controls = k_alania
			completely_controls = k_crimea
		}

		effect = {
			e_rus = {
				show_scope_change = no

				e_russia = {
					show_scope_change = no

					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT

					hidden_effect = {
						make_primary_title = yes
						copy_title_laws = PREV
						clr_title_flag = non_manual_law_change # No prestige loss
					}
				}

				hidden_effect = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = e_russia
					}

					destroy_landed_title = THIS

					activate_title = {
						title = e_rus
						status = no
					}
				}
			}

			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}

			custom_tooltip = { text = russian_empire_cheaper_tribal_upgrades }

			k_galicia-volhynia = { show_scope_change = no de_jure_liege = e_russia }
			k_ruthenia         = { show_scope_change = no de_jure_liege = e_russia }
			k_chernigov        = { show_scope_change = no de_jure_liege = e_russia }
			k_novgorod         = { show_scope_change = no de_jure_liege = e_russia }
			k_vladimir         = { show_scope_change = no de_jure_liege = e_russia }
			k_nenets           = { show_scope_change = no de_jure_liege = e_russia }
			k_perm             = { show_scope_change = no de_jure_liege = e_russia }
			k_volga_bulgaria   = { show_scope_change = no de_jure_liege = e_russia }
			k_khazaria         = { show_scope_change = no de_jure_liege = e_russia }
			k_alania           = { show_scope_change = no de_jure_liege = e_russia }
			k_crimea           = { show_scope_change = no de_jure_liege = e_russia }

			character_event = { id = HFP.16001 } # Notify

			any_player = {
				limit = { NOT = { character = ROOT } }
				character_event = { id = HFP.16002 } # Notify
			}
		}

		ai_will_do = {
			factor = 1
		}
	}
}