﻿unite_the_western_slavs_decision_effects = {
	title:e_sclavinia = { save_scope_as = sclavinia } #For localisation
	#Prestige
	add_prestige = massive_prestige_gain
	if = { 
		limit = { 
			OR = { 
				has_faith = faith:orthodox
				has_faith = faith:catholic
			}
			has_culture = culture:polish
		}
		add_legitimacy = 150
	}

	#Innovations

	#Laws
	if = {
		limit = { has_realm_law = crown_authority_0 }
		add_realm_law_skip_effects = crown_authority_2
	}
	else_if = {
		limit = {
			OR = {
				has_realm_law = crown_authority_1
				has_realm_law = crown_authority_2
			}
		}
		add_realm_law_skip_effects = crown_authority_3
	}

	#Handle de jure drift & destructions of other kingdom titles
	if = { 
		limit = { has_global_variable = provinces_established_sclavinia }
		title:k_wielkopolska = { add_to_list = west_slavic_kingdoms }
		title:k_malopolska = { add_to_list = west_slavic_kingdoms }
		title:k_litewska = { add_to_list = west_slavic_kingdoms }
	}
	title:k_poland = { add_to_list = west_slavic_kingdoms }
	title:k_pomerania = { add_to_list = west_slavic_kingdoms }
	title:k_polabia = { add_to_list = west_slavic_kingdoms }
	title:k_bohemia = { add_to_list = west_slavic_kingdoms }
	title:k_moravia = { add_to_list = west_slavic_kingdoms }
	if = { 
		limit = { game_start_date < 1000.1.1 }
		title:k_transdanubia = { add_to_list = west_slavic_kingdoms }
		title:k_carinthia = { add_to_list = west_slavic_kingdoms }
	}
	hidden_effect = {
		if = { 
			limit = { 
				has_faith = faith:orthodox 
				has_culture = culture:polish 
			}
			set_artifact_rarity_illustrious = yes
			create_artifact = {	
				name = sclavinia_korona
				description = sclavinia_korona_orthodox_desc
				type = helmet
				visuals = crown_court
				wealth = scope:wealth
				quality = scope:quality
				history = {
					type = created
					recipient = ROOT
					actor = title:e_byzantium.holder
					location = title:e_byzantium.holder.capital_province
				}
				template = reichskrone_template
				modifier = sclavinia_korona_orthodox_empire_modifier
				save_scope_as = newly_created_artifact
				decaying = no
			}
			scope:newly_created_artifact = {
				set_variable = { name = historical_unique_artifact value = yes }
				set_variable = {
					name = artifact_succession_title
					value = title:k_poland
				}
				set_variable = {
					name = sclavinia_plock_diadem
					value = yes
				}
				save_scope_as = epic
			}
		}
		if = { 
			limit = { 
				has_faith = faith:catholic 
				has_culture = culture:polish 
			}
			set_artifact_rarity_illustrious = yes
			create_artifact = {	
				name = sclavinia_korona
				description = sclavinia_korona_roman_catholic_desc
				type = helmet
				visuals = crown_court
				wealth = scope:wealth
				quality = scope:quality
				history = {
					type = created
					recipient = ROOT
					actor = title:k_papal_state.holder
					location = title:k_papal_state.holder.capital_province
				}
				template = reichskrone_template
				modifier = sclavinia_korona_orthodox_empire_modifier
				save_scope_as = newly_created_artifact
				decaying = no
			}
			scope:newly_created_artifact = {
				set_variable = { name = historical_unique_artifact value = yes }
				set_variable = {
					name = artifact_succession_title
					value = title:k_poland
				}
				set_variable = {
					name = sclavinia_plock_diadem
					value = yes
				}
				save_scope_as = epic
			}
			set_global_variable = {
				name = roman_catholic_hre_unlock_sclavinia
				value = yes
			}
		}
	}
	if = { 
		limit = { 
			OR = { 
				has_faith = faith:orthodox 
				has_faith = faith:catholic
			}
			has_culture = culture:polish
		}
		send_interface_toast = {
			type = event_toast_effect_good
			left_icon = scope:newly_created_artifact
			title = sclavinia_korona_orthodox_desc_toast
			show_as_tooltip = { 
				create_artifact = {	
					name = sclavinia_korona
				}
			}
		}
	}
	hidden_effect = {
		if = {
			limit = {
				is_target_in_global_variable_list = {
					name = unavailable_unique_decisions
					target = flag:flag_formed_saxony
				}
			}
			title:d_meissen = { set_de_jure_liege_title = title:k_polabia }
			title:d_lausitz = { set_de_jure_liege_title = title:k_polabia }
			title:d_anhalt = { set_de_jure_liege_title = title:k_polabia }
		}
		scope:western_slav_uniter = {
			every_in_list = {
				list = west_slavic_kingdoms
				set_de_jure_liege_title = title:e_sclavinia
			}
			title:e_wendish_empire = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_kingdom }
					set_de_jure_liege_title = title:e_sclavinia
				}
			}
			title:e_samovia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_kingdom }
					set_de_jure_liege_title = title:e_sclavinia
				}
			}
			if = {
				limit = { 
					has_culture = culture:slovien
					game_start_date < 1000.1.1
				}
				title:e_sclavinia = { 
					set_coa = e_samovia_sclavinia
					set_capital_county = title:c_olomouc
					set_color_from_title = title:e_samovia
				}
				set_global_variable = {
					name = samovia_sclavinia_united
					value = yes
				}
			}
			if = {
				limit = { 
					has_culture = culture:slovien
					game_start_date > 1000.1.1
				}
				title:e_sclavinia = { 
					set_coa = e_samovia_sclavinia
					set_capital_county = title:c_nyitra
					set_color_from_title = title:e_samovia
				}
				set_global_variable = {
					name = samovia_sclavinia_united
					value = yes
				}
			}
			if = {
				limit = { 
					has_culture = culture:czech
				}
				title:e_sclavinia = { 
					set_coa = e_bohemia_sclavinia
					set_capital_county = title:c_praha
					set_color_from_title = title:e_samovia
				}
				set_global_variable = {
					name = samovia_sclavinia_united
					value = yes
				}
			}
			if = { 
				limit = { game_start_date < 1000.1.1 }
				title:d_istria = { set_de_jure_liege_title = title:k_croatia }
				title:d_carinthia = { set_de_jure_liege_title = title:k_carinthia }
				title:d_steyermark = { set_de_jure_liege_title = title:k_carinthia }
				title:d_krain = { set_de_jure_liege_title = title:k_carinthia }
				title:c_gorz = { set_de_jure_liege_title = title:d_krain }
			}
			else = { 
				title:d_nyitra = { set_de_jure_liege_title = title:k_moravia }
				title:d_hont = { set_de_jure_liege_title = title:k_moravia }
				title:k_moravia = { 
					set_title_name = d_nyitra 
					set_coa = title:d_nyitra 
					set_capital_county = title:c_nyitra
				}
			}		
		}
		scope:western_slav_uniter = {
			primary_title = { 
				title:e_sclavinia = {
					copy_title_history = PREV
				}
			}
			create_title_and_vassal_change = {
				type = created
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			title:e_sclavinia = {
				change_title_holder = {
					holder = ROOT
					change = scope:title_change
				}
			}
			resolve_title_and_vassal_change = scope:title_change
			set_primary_title_to = title:e_sclavinia
			destroy_title = title:e_wendish_empire
			destroy_title = title:e_samovia
		}
		if = { 
			limit = { has_faith = faith:orthodox }
			title:e_slavia = { set_title_name = pansklabonia_sclavinia }
		}
		else = { 
			title:e_slavia = { set_title_name = omnisclavinia_sclavinia }
		}
	}
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia1
	set_primary_title_to = title:e_sclavinia
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia2
	culture = {
		add_random_innovation = culture_group_military
		add_random_innovation = culture_group_civic
	}
}
orthodox_unite_the_western_slavs_decision_effects = {
	add_prestige = massive_prestige_gain
	add_legitimacy = 350
	#Innovations

	#Laws
	if = {
		limit = { has_realm_law = crown_authority_0 }
		add_realm_law_skip_effects = crown_authority_2
	}
	else_if = {
		limit = {
			OR = {
				has_realm_law = crown_authority_1
				has_realm_law = crown_authority_2
			}
		}
		add_realm_law_skip_effects = crown_authority_3
	}
	
	title:k_pomerania = { add_to_list = west_slavic_kingdoms }
	title:k_polabia = { add_to_list = west_slavic_kingdoms }
	title:k_bohemia = { add_to_list = west_slavic_kingdoms }
	title:k_moravia = { add_to_list = west_slavic_kingdoms }
	title:k_croatia = { add_to_list = west_slavic_kingdoms }
	title:k_serbia = { add_to_list = west_slavic_kingdoms }
	title:k_bulgaria = { add_to_list = west_slavic_kingdoms }
	if = { 
		limit = { game_start_date < 1000.1.1 }
		title:k_transdanubia = { add_to_list = west_slavic_kingdoms }
	}
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia3
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia4
	hidden_effect = {
		title:k_poland = { 
			set_de_jure_liege_title = title:e_byzantium 
			set_coa = e_sclavinia
			set_color_from_title = title:e_sclavinia
		}
		every_in_list = {
			list = west_slavic_kingdoms

			#De jure shift all held west slavic titles into your primary title
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_duchy }
				set_de_jure_liege_title = title:k_poland
			}
		}
		every_in_list = {
			list = west_slavic_kingdoms
				limit = { 
					holder = { this = ROOT }
				}
			#Destroys them all!
			scope:western_slav_uniter = { destroy_title = prev }
		}
		title:d_meissen = { set_de_jure_liege_title = title:k_poland }
		title:d_lausitz = { set_de_jure_liege_title = title:k_poland }
		title:d_anhalt = { set_de_jure_liege_title = title:k_poland }
		title:d_istria = { set_de_jure_liege_title = title:k_poland }
		title:d_carinthia = { set_de_jure_liege_title = title:k_poland }
		title:d_steyermark = { set_de_jure_liege_title = title:k_poland }
		title:d_krain = { set_de_jure_liege_title = title:k_poland }
		title:c_gorz = { set_de_jure_liege_title = title:d_krain } 
		title:d_nyitra = { set_de_jure_liege_title = title:k_poland }
		title:d_hont = { set_de_jure_liege_title = title:k_poland }
		title:d_ungvar = { set_de_jure_liege_title = title:k_poland }
		title:d_philippopolis = { set_de_jure_liege_title = title:k_thessalonika }
		title:c_kran = { set_de_jure_liege_title = title:d_turnovo }
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		title:e_byzantium.holder = { 
			save_scope_as = vassal_orthodox_empire_transfer_sclavinia 
			every_vassal = { 
				limit = {
					OR = { 
						culture = { has_cultural_pillar = heritage_west_slavic }
						culture = { has_cultural_pillar = heritage_south_slavic }
					}
				}
				every_held_title = { 
					limit = { tier = tier_kingdom }
					ROOT = { destroy_title = prev }
				}
			}
			every_vassal_or_below = { 
				limit = {
					OR = { 
						culture = { has_cultural_pillar = heritage_west_slavic }
						culture = { has_cultural_pillar = heritage_south_slavic }
					}
					NOT = { liege = { culture = { has_cultural_pillar = heritage_west_slavic } } }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_south_slavic } } }
				}
				change_liege = { 
					liege = ROOT
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			save_scope_as = vassal_orthodox_empire_transfer_sclavinia 
			every_vassal_or_below = { 
				limit = {
					NOT = { culture = { has_cultural_pillar = heritage_west_slavic } }
					NOT = { culture = { has_cultural_pillar = heritage_south_slavic } }					
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_poland
						OR = { 
							tier = tier_duchy
							tier = tier_county
						} 
					}
					change_title_holder = { 
						holder = root
						change = scope:title_change
					}  
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_poland
					OR = { 
						tier = tier_duchy
						tier = tier_county
					} 
				}
				change_title_holder = { 
					holder = root
					change = scope:title_change
				}  
			}
		}
		resolve_title_and_vassal_change = scope:title_change
		scope:western_slav_uniter = { 
			every_vassal = { 
				every_held_title = { 
					limit = { tier = tier_kingdom }
					ROOT = { destroy_title = prev }
				}
			}
		}
		scope:western_slav_uniter = {
			every_held_title = { 
				limit = { tier = tier_empire }
				scope:western_slav_uniter = { destroy_title = prev }
			}
		}
	}
	create_title_and_vassal_change = {
		type = swear_fealty
		save_scope_as = change
	}
	change_liege = { 
		liege = scope:vassal_orthodox_empire_transfer_sclavinia 
		change = scope:change
	}
	ROOT = { 
		add_opinion = {
			modifier = became_vassal
			target = scope:vassal_orthodox_empire_transfer_sclavinia 
			opinion = 10
		}
	} 
	hidden_effect = {
		set_artifact_rarity_illustrious = yes
		create_artifact = {	
			name = sclavinia_korona
			description = sclavinia_korona_orthodox_desc
			type = helmet
			visuals = crown_court
			wealth = scope:wealth
			quality = scope:quality
			history = {
				type = created
				recipient = ROOT
				actor = title:e_byzantium.holder
				location = title:e_byzantium.holder.capital_province
			}
			template = reichskrone_template
			modifier = sclavinia_korona_orthodox_modifier
			save_scope_as = newly_created_artifact
			decaying = no
		}
		scope:newly_created_artifact = {
			set_variable = { name = historical_unique_artifact value = yes }
			set_variable = {
				name = artifact_succession_title
				value = title:k_poland
			}
			set_variable = {
				name = sclavinia_plock_diadem
				value = yes
			}
			save_scope_as = epic
		}
	}                                                                                                
	send_interface_toast = {
		type = event_toast_effect_good
		left_icon = scope:newly_created_artifact
		title = sclavinia_korona_orthodox_desc_toast
		show_as_tooltip = { 
			create_artifact = {	
				name = sclavinia_korona
			}
		}
	}
	resolve_title_and_vassal_change = scope:change
	title:k_poland = { 
		set_title_name = k_sklabonia
	}
	set_global_variable = { 
		name = sclavinia_poland_vassalized_byzantine
		value = yes
	}
	culture = {
		add_random_innovation = culture_group_military
		add_random_innovation = culture_group_civic
	}
}
roman_catholic_unite_the_western_slavs_decision_effects = {
	add_prestige = massive_prestige_gain
	add_legitimacy = 350
	#Innovations

	#Laws
	if = {
		limit = { has_realm_law = crown_authority_0 }
		add_realm_law_skip_effects = crown_authority_2
	}
	else_if = {
		limit = {
			OR = {
				has_realm_law = crown_authority_1
				has_realm_law = crown_authority_2
			}
		}
		add_realm_law_skip_effects = crown_authority_3
	}
	
	title:k_pomerania = { add_to_list = west_slavic_kingdoms }
	title:k_polabia = { add_to_list = west_slavic_kingdoms }
	title:k_bohemia = { add_to_list = west_slavic_kingdoms }
	title:k_moravia = { add_to_list = west_slavic_kingdoms }
	if = { 
		limit = { game_start_date < 1000.1.1 }
		title:k_transdanubia = { add_to_list = west_slavic_kingdoms }
	}
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia_roman_catholic1
	custom_tooltip = unite_the_western_slavs_decision_titles_tt_sclavinia_roman_catholic2
	hidden_effect = {
		title:k_poland = { 
			set_de_jure_liege_title = title:e_hre 
			set_coa = e_sclavinia
			set_color_from_title = title:e_sclavinia
		}
		every_in_list = {
			list = west_slavic_kingdoms

			#De jure shift all held west slavic titles into your primary title
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_duchy }
				set_de_jure_liege_title = title:k_poland
			}
		}
		title:d_meissen = { set_de_jure_liege_title = title:k_poland }
		title:d_lausitz = { set_de_jure_liege_title = title:k_poland }
		title:d_anhalt = { set_de_jure_liege_title = title:k_poland }
		if = { 
			limit = { game_start_date < 1000.1.1 }
			title:d_istria = { set_de_jure_liege_title = title:k_poland }
			title:d_carinthia = { set_de_jure_liege_title = title:k_poland }
			title:d_steyermark = { set_de_jure_liege_title = title:k_poland }
			title:d_krain = { set_de_jure_liege_title = title:k_poland }
			title:c_gorz = { set_de_jure_liege_title = title:d_krain } 
		}
		title:d_nyitra = { set_de_jure_liege_title = title:k_poland }
		title:d_hont = { set_de_jure_liege_title = title:k_poland }
		every_in_list = {
			list = west_slavic_kingdoms
				limit = { 
					holder = { this = ROOT }
				}
			#Destroys them all!
			scope:western_slav_uniter = { destroy_title = prev }
		}
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		title:e_hre.holder = { 
			save_scope_as = vassal_orthodox_empire_transfer_sclavinia 
			every_vassal = { 
				limit = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					NOT = { has_title = title:k_poland }
				}
				every_held_title = { 
					limit = { tier = tier_kingdom }
					ROOT = { destroy_title = prev }
				}
			}
			every_vassal_or_below = { 
				limit = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_west_slavic } } }
				}
				change_liege = { 
					liege = ROOT
					change = scope:change
				}
			}   
			resolve_title_and_vassal_change = scope:change
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			every_vassal_or_below = {
				limit = { NOT = { culture = { has_cultural_pillar = heritage_west_slavic } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_poland
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}
					change_title_holder = {
						holder = ROOT
						change = scope:title_change
					}
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_poland
					OR = { 
						tier = tier_duchy
						tier = tier_county
					} 
				}
				change_title_holder = { 
					holder = root
					change = scope:title_change
				}  
			}
		}
		resolve_title_and_vassal_change = scope:title_change
		scope:western_slav_uniter = { 
			every_vassal = { 
				every_held_title = { 
					limit = { tier = tier_kingdom }
					ROOT = { destroy_title = prev }
				}
			}
		}
		scope:western_slav_uniter = {
			every_held_title = { 
				limit = { tier = tier_empire }
				scope:western_slav_uniter = { destroy_title = prev }
			}
		}
	}
	create_title_and_vassal_change = {
		type = swear_fealty
		save_scope_as = change
	}
	change_liege = { 
		liege = scope:vassal_orthodox_empire_transfer_sclavinia 
		change = scope:change
	}
	ROOT = { 
		add_opinion = {
			modifier = became_vassal
			target = scope:vassal_orthodox_empire_transfer_sclavinia 
			opinion = 10
		}
	} 
	if = { 
		limit = { NOT = { has_global_variable = have_diadem_already_sclavinia } }
		hidden_effect = {
			set_artifact_rarity_illustrious = yes
			create_artifact = {	
				name = sclavinia_korona
				description = sclavinia_korona_roman_catholic_hre_desc
				type = helmet
				visuals = crown_court
				wealth = scope:wealth
				quality = scope:quality
				history = {
					type = created
					recipient = ROOT
					actor = title:e_hre.holder
					location = title:e_hre.holder.capital_province
				}
				template = reichskrone_template
				modifier = sclavinia_korona_roman_catholic_modifier
				save_scope_as = newly_created_artifact
				decaying = no
			}
			scope:newly_created_artifact = {
				set_variable = { name = historical_unique_artifact value = yes }
				set_variable = {
					name = artifact_succession_title
					value = title:k_poland
				}
				set_variable = {
					name = sclavinia_plock_diadem
					value = yes
				}
				save_scope_as = epic
			}
		}                                                                                                
		send_interface_toast = {
			type = event_toast_effect_good
			left_icon = scope:newly_created_artifact
			title = sclavinia_korona_orthodox_desc_toast
			show_as_tooltip = { 
				create_artifact = {	
					name = sclavinia_korona
				}
			}
		}
	}
	resolve_title_and_vassal_change = scope:change
	title:k_poland = {
		set_title_name = e_sclavinia
	}
	set_global_variable = { 
		name = sclavinia_poland_vassalized_hre
		value = yes
	}
	culture = {
		add_random_innovation = culture_group_military
		add_random_innovation = culture_group_civic
	}
}
unite_the_slavs_decision_effects = {
	#Prestige
	add_prestige = massive_prestige_gain

	#Innovations
	custom_tooltip = unite_the_slavs_decision_effects_innovations_tt
	hidden_effect = {
		#Add all Slavic cultures in the realm in a list
		every_vassal_or_below = {
			limit = {
				OR = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					culture = { has_cultural_pillar = heritage_east_slavic }
					culture = { has_cultural_pillar = heritage_south_slavic }
				}
				save_temporary_scope_as = slavic_vassal
				NOT = {
					any_in_list = {
						list = slavic_cultures
						this = scope:slavic_vassal.culture
					}
				}
			}
			culture = {
				add_to_list = slavic_cultures
			}
		}
		#Add innovations from 3 random cultures
		every_in_list = {
			list = slavic_cultures
			save_scope_as = culture_getting_innovations

			set_while_counter_variable_effect = yes
			while = {
				limit = { var:while_counter < 3 }
				random_in_list = {
					limit = { scope:culture_getting_innovations = { can_get_innovation_from = prev } }
					list = slavic_cultures
					scope:culture_getting_innovations = { get_random_innovation_from = prev }
				}
				increase_while_counter_variable_effect = yes
			}
			remove_while_counter_variable_effect = yes
		}
	}

	#Create the title and make it primary
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_slavia = {
		change_title_holder = {
			holder = root
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change

	set_primary_title_to = title:e_slavia
	title:e_slavia = { save_scope_as = slavia } #For localisation

	#Destroy the other three empires if I have them
	if = {
		limit = { has_title = title:e_russia }
		destroy_title = title:e_russia
	}
	if = {
		limit = { has_title = title:e_wendish_empire }
		destroy_title = title:e_wendish_empire
	}
	if = {
		limit = { has_title = title:e_carpathia }
		destroy_title = title:e_carpathia
	}
	if = {
		limit = { has_title = title:e_samovia }
		destroy_title = title:e_samovia
	}
	if = {
		limit = { has_title = title:e_sclavinia }
		destroy_title = title:e_sclavinia
	}

	###Handle de jure drift and empire destruction###

	#First: add all the kingdoms
	if = { 
		limit = { has_global_variable = provinces_established_sclavinia }
		title:k_wielkopolska = { add_to_list = slavic_kingdoms }
		title:k_malopolska = { add_to_list = slavic_kingdoms }
		title:k_litewska = { add_to_list = slavic_kingdoms }
	}
	else = { 	   
		title:k_white_rus = { add_to_list = slavic_kingdoms }
		title:k_galicia-volhynia = { add_to_list = slavic_kingdoms }
		title:k_ruthenia = { add_to_list = slavic_kingdoms }
	}
	title:k_poland = { add_to_list = slavic_kingdoms }
	title:k_pomerania = { add_to_list = slavic_kingdoms }
	title:k_bohemia = { add_to_list = slavic_kingdoms }
	title:k_moravia = { add_to_list = slavic_kingdoms }
	title:k_croatia = { add_to_list = slavic_kingdoms }
	title:k_serbia = { add_to_list = slavic_kingdoms }
	title:k_bulgaria = { add_to_list = slavic_kingdoms }
	title:k_dacia = { add_to_list = slavic_kingdoms }
	title:k_moldavia = { add_to_list = slavic_kingdoms }
	title:k_novgorod = { add_to_list = slavic_kingdoms }
	title:k_hungary = { add_to_list = slavic_kingdoms }
	title:k_polabia = { add_to_list = slavic_kingdoms }
	if = { 
		limit = { game_start_date < 1000.1.1 }
		title:k_transdanubia = { add_to_list = slavic_kingdoms }
	}
	else = { 
		title:d_nyitra = { set_de_jure_liege_title = title:k_moravia }
		title:d_hont = { set_de_jure_liege_title = title:k_moravia }
		title:k_moravia = { set_title_name = d_nyitra set_coa = title:d_nyitra set_capital_county = title:c_nyitra }
	}
	title:k_carinthia = { add_to_list = slavic_kingdoms }
	hidden_effect = {
		title:d_istria = { set_de_jure_liege_title = title:k_croatia }
		title:d_carinthia = { set_de_jure_liege_title = title:k_carinthia }
		title:d_steyermark = { set_de_jure_liege_title = title:k_carinthia }
		title:d_krain = { set_de_jure_liege_title = title:k_carinthia }
		title:c_gorz = { set_de_jure_liege_title = title:d_krain }
	}
	if = {
		limit = { has_dlc_feature = legends }
		create_legend_seed = {
			type = legitimizing
			quality = illustrious
			chronicle = new_title
			properties = {
				title = title:e_slavia
				founder = root
			}
		}
	}
	# Inform players of the de jure drift
	title:e_slavia = { custom_tooltip = unite_the_slavs_decision_titles_tt } #Scope change for tooltip formatting.

	# Actually do the de jure drift
	hidden_effect = {
		every_in_list = {
			list = slavic_kingdoms

			set_de_jure_liege_title = title:e_slavia
		}
	}
	title:e_russia = {
		every_in_de_jure_hierarchy = {
			limit = { tier = tier_kingdom }
			set_de_jure_liege_title = title:e_slavia
		}
	}
	title:e_wendish_empire = {
		every_in_de_jure_hierarchy = {
			limit = { tier = tier_kingdom }
			set_de_jure_liege_title = title:e_slavia
		}
	}
	title:e_carpathia = {
		every_in_de_jure_hierarchy = {
			limit = { tier = tier_kingdom }
			set_de_jure_liege_title = title:e_slavia
		}
	}
	title:e_samovia = {
		every_in_de_jure_hierarchy = {
			limit = { tier = tier_kingdom }
			set_de_jure_liege_title = title:e_slavia
		}
	}
	title:e_sclavinia = {
		every_in_de_jure_hierarchy = {
			limit = { tier = tier_kingdom }
			set_de_jure_liege_title = title:e_slavia
		}
	}
	set_global_variable = {
		name = unite_the_slavs_decision_effects_sclavinia
		value = yes
	}
}
unite_the_slavs_decision_effects_slavic_ere = {
	#Prestige
	add_prestige = massive_prestige_gain
	add_legitimacy = 350
	#Innovations
	
	custom_tooltip = unite_the_slavs_decision_effects_innovations_tt
	hidden_effect = {
		#Add all Slavic cultures in the realm in a list
		every_vassal_or_below = {
			limit = {
				OR = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					culture = { has_cultural_pillar = heritage_east_slavic }
					culture = { has_cultural_pillar = heritage_south_slavic }
				}
				save_temporary_scope_as = slavic_vassal
				NOT = {
					any_in_list = {
						list = slavic_cultures
						this = scope:slavic_vassal.culture
					}
				}
			}
			culture = {
				add_to_list = slavic_cultures
			}
		}
		#Add innovations from 3 random cultures
		every_in_list = {
			list = slavic_cultures
			save_scope_as = culture_getting_innovations

			set_while_counter_variable_effect = yes
			while = {
				limit = { var:while_counter < 3 }
				random_in_list = {
					limit = { scope:culture_getting_innovations = { can_get_innovation_from = prev } }
					list = slavic_cultures
					scope:culture_getting_innovations = { get_random_innovation_from = prev }
				}
				increase_while_counter_variable_effect = yes
			}
			remove_while_counter_variable_effect = yes
		}
	}
	title:e_byzantium = { save_scope_as = slavia } #For localisation


	###Handle de jure drift and empire destruction###

	#First: add all the kingdoms
	title:k_moldavia = { add_to_list = slavic_kingdoms }
	title:k_white_rus = { add_to_list = slavic_kingdoms }
	title:k_galicia-volhynia = { add_to_list = slavic_kingdoms }
	title:k_ruthenia = { add_to_list = slavic_kingdoms }
	
	if = {
		limit = { has_dlc_feature = legends }
		create_legend_seed = {
			type = legitimizing
			quality = illustrious
			chronicle = new_title
			properties = {
				title = title:e_slavia
				founder = root
			}
		}
	}
	# Inform players of the de jure drift
	title:e_byzantium = { custom_tooltip = unite_the_slavs_decision_titles_tt_sclavinia } #Scope change for tooltip formatting.

	# Actually do the de jure drift
	hidden_effect = {
		title:k_hungary = { set_de_jure_liege_title = title:e_byzantium }
		title:k_dacia = { set_de_jure_liege_title = title:e_byzantium }
		title:k_novgorod = { set_de_jure_liege_title = title:e_byzantium }
		every_in_list = {
			list = slavic_kingdoms

			#De jure shift all held west slavic titles into your primary title
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_duchy }
				set_de_jure_liege_title = title:k_novgorod
			}
		}
		every_in_list = {
			list = slavic_kingdoms
				limit = { 
					holder = { this = ROOT }
				}
			#Destroys them all!
			scope:slav_uniter = { destroy_title = prev }
		}
		title:k_novgorod = { 
			set_capital_county = title:c_kiev
			set_title_name = antia_sclavinia
			set_color_from_title = title:k_white_rus
		}
	}
	hidden_effect = { 
		if = { #Usurp if not held personally.
			limit = {
				NOT = { title:k_novgorod.holder = { this = root } }
			}
			create_title_and_vassal_change = {
				type = created
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			title:k_novgorod = {
				change_title_holder = {
					holder = root
					change = scope:title_change
				}
			}
			resolve_title_and_vassal_change = scope:title_change
		}
	}
	set_global_variable = {
		name = unite_the_slavs_decision_effects_sclavinia
		value = yes
	}
}
lechits_getting_feudal_sclavinia_effect = {
	if = {
		limit = { dynasty = { this = dynasty:2001004 } }
		dynasty = { set_dynasty_name="Lędziański" }
		house = { set_house_name="Lędziański" }
		set_global_variable = {
			name = ledzianski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001006 } }
		dynasty = { set_dynasty_name="Mazowiecki" }
		house = { set_house_name="Mazowiecki" }
		set_global_variable = {
			name = mazowiecki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001005 } }
		dynasty = { set_dynasty_name="Sandomierski" }
		house = { set_house_name="Sandomierski" }
		set_global_variable = {
			name = sandomierski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001003 } }
		dynasty = { set_dynasty_name="Wiślański" }
		house = { set_house_name="Wiślański" }
		set_global_variable = {
			name = wislanski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001007 } }
		dynasty = { set_dynasty_name="Goplański" }
		house = { set_house_name="Goplański" }
		set_global_variable = {
			name = goplanski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001008 } }
		dynasty = { set_dynasty_name="Sieradzki" }
		house = { set_house_name="Sieradzki" }
		set_global_variable = {
			name = leczycki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:9127 } }
		dynasty = { set_dynasty_name="Śląski" }
		house = { set_house_name="Śląski" }
		set_global_variable = {
			name = slaski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:699 } NOT = { has_global_variable = piast_renamed_sclavinia } }
		dynasty = { set_dynasty_name="Polański" }
		house = { set_house_name="Polański" }
		set_global_variable = {
			name = polanski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001009 } }
		dynasty = { set_dynasty_name="Kaszubski" }
		house = { set_house_name="Kaszubski" }
		set_global_variable = {
			name = kaszubski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001010 } }
		dynasty = { set_dynasty_name="Słowiński" }
		house = { set_house_name="Słowiński" }
		set_global_variable = {
			name = slowinski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001011 } }
		dynasty = { set_dynasty_name="Woliński" }
		house = { set_house_name="Woliński" }
		set_global_variable = {
			name = wolinski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001012 } }
		dynasty = { set_dynasty_name="Pyrzycki" }
		house = { set_house_name="Pyrzycki" }
		set_global_variable = {
			name = pyrzycki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001015 } }
		dynasty = { set_dynasty_name="Lubuski" }
		house = { set_house_name="Lubuski" }
		set_global_variable = {
			name = lubuski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:1042804 } }
		dynasty = { set_dynasty_name="Milczański" }
		house = { set_house_name="Milczański" }
		set_global_variable = {
			name = milczanski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:1042806 } }
		dynasty = { set_dynasty_name="Łużycki" }
		house = { set_house_name="Łużycki" }
		set_global_variable = {
			name = luzycki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001323 } }
		dynasty = { set_dynasty_name="Redarski" }
		house = { set_house_name="Redarski" }
		set_global_variable = {
			name = redarski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:9605 } }
		dynasty = { set_dynasty_name="Hawelski" }
		house = { set_house_name="Hawelski" }
		set_global_variable = {
			name = hawelski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001013 } }
		dynasty = { set_dynasty_name="Czrezpieniański" }
		house = { set_house_name="Czrezpieniański" }
		set_global_variable = {
			name = wielecki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:2001014 } }
		dynasty = { set_dynasty_name="Ranowski" }
		house = { set_house_name="Ranowski" }
		set_global_variable = {
			name = ranowski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:1042800 } }
		dynasty = { set_dynasty_name="Rereski" }
		house = { set_house_name="Rereski" }
		set_global_variable = {
			name = obodrycki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:9607 } }
		dynasty = { set_dynasty_name="Płoniański" }
		house = { set_house_name="Płoniański" }
		set_global_variable = {
			name = sprewanski_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:9129 } }
		dynasty = { set_dynasty_name="Głubczycki" }
		house = { set_house_name="Głubczycki" }
		set_global_variable = {
			name = glubczycki_renamed_sclavinia
			value = yes
		}
	}
	if = {
		limit = { dynasty = { this = dynasty:9128 } }
		dynasty = { set_dynasty_name="Opolski" }
		house = { set_house_name="Opolski" }
		set_global_variable = {
			name = opolski_renamed_sclavinia
			value = yes
		}
	}
}
restore_holy_roman_empire_decision_sclavinia_scripted_effect = {
	save_scope_as = founder
	create_title_and_vassal_change = {
		type = created
		save_scope_as = title_change
		add_claim_on_loss = no
	}
	title:e_hre = {
		change_title_holder = {
			holder = root
			change = scope:title_change
		}
	}
	resolve_title_and_vassal_change = scope:title_change
	set_primary_title_to = title:e_hre

	#Papal hook management.
	if = {
		limit = {
			faith.religious_head = {
				exists = this
				opinion = {
					target = root
					value < high_positive_opinion
				}
			}
			OR = {
				has_weak_hook = faith.religious_head
				has_strong_usable_hook = faith.religious_head
			}
		}
		use_hook = faith.religious_head
	}
	#Sort title laws.
	title:e_hre = {
		set_title_name = e_wre
		set_coa = e_hre_sclavinia
		set_capital_county = title:k_poland.title_capital_county
		add_title_law = reformed_princely_elective_succession_law
		if = {	#Add Salic law.
			limit = {
				root = {
					OR = {
						has_realm_law = male_preference_law
						has_realm_law = male_only_law
					}
				}
			}
			add_title_law = male_only_law
		}
		if = {	#Ignore Salic law.
			limit = {
				root = { has_realm_law = equal_law }
			}
			add_title_law = equal_law
		}
		if = {	#Invert Salic law. Take that, Clovis, y'big nerd.
			limit = {
				root = {
					OR = {
						has_realm_law = female_preference_law
						has_realm_law = female_only_law
					}
				}
			}
			add_title_law = female_only_law
		}
		custom_tooltip = hre_elector_list_creation_sclavinia_tt
	}

	#Add de jures.
	hidden_effect = {
		title:e_sclavinia = {
			every_in_de_jure_hierarchy = {
				limit = { tier = tier_duchy }
				set_de_jure_liege_title = title:k_poland
			}
		}
		every_held_title = {
			limit = {
				tier = tier_kingdom
				NOT = {	#The Pope retains vague dibs on Italy.
					any_this_title_or_de_jure_above = { this = title:e_italy }
				}
				save_temporary_scope_as = this_title
				#root = { completely_controls = scope:this_title }
			}
			set_de_jure_liege_title = title:e_hre
		}
		every_vassal = {
			every_held_title = {
				limit = {
					tier = tier_kingdom
					NOT = {	#The Pope retains vague dibs on Italy.
						any_this_title_or_de_jure_above = { this = title:e_italy }
					}
					save_temporary_scope_as = this_title
					#prev = { completely_controls = scope:this_title }
				}
				set_de_jure_liege_title = title:e_hre
			}
		}
		every_vassal = {
			limit = {
				is_ai = yes
			}
			every_held_title = {
				limit = {
					tier = tier_kingdom
					NOT = {
						this = title:k_poland
						this = title:k_east_francia
						this = title:k_france
						this = title:k_italy
					}
				}
				root = {
					destroy_title = prev
				}
			}
		}
		every_held_title = {
			limit = {
				tier >= tier_kingdom
				NOT = {
					this = title:e_hre
					this = title:k_poland
					this = title:k_east_francia
					this = title:k_france
					this = title:k_italy
				}
				save_temporary_scope_as = this_title
			}
			root = {
				destroy_title = prev
			}
		}
		title:k_poland = { 
			set_coa = e_sclavinia
			set_color_from_title = title:e_sclavinia
			set_title_name = e_sclavinia
		}
		title:k_pomerania = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_polabia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_bohemia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_moravia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_transdanubia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_carinthia = { set_de_jure_liege_title = title:e_sclavinia }
		if = {	#If Germania is nae a thing, merge it into the HRE.
			limit = { 
				OR = {
					NOT = { exists = title:e_germany.holder }
					title:e_germany.holder ?= root
				}
				title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
			}
			title:k_bavaria = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_east_francia
				}
				set_de_jure_liege_title = title:e_germany
			}
			title:k_lotharingia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_east_francia
				}
				set_de_jure_liege_title = title:e_germany
			}
			title:k_frisia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_east_francia
				}  
				set_de_jure_liege_title = title:e_germany
			} 
			title:d_transjurania = { set_de_jure_liege_title = title:k_east_francia }
			title:k_east_francia = { 
				set_coa = e_germany
				set_color_from_title = title:e_germany
				set_title_name = e_germany
				set_de_jure_liege_title = title:e_hre
			}  
			set_global_variable = {
				name = kingdom_of_germania_established_sclavinia
				value = yes
			} 
			set_global_variable = {
				name = east_francia_renamed
				value = yes
			}
		}  
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = no
		}
		every_vassal_or_below = { 
			limit = {
				culture = { has_cultural_pillar = heritage_west_slavic }
				NOT = { liege = { culture = { has_cultural_pillar = heritage_west_slavic } } }
			}
			change_liege = { 
				liege = ROOT
				change = scope:change
			}
		}   
		resolve_title_and_vassal_change = scope:change
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = title_change
			add_claim_on_loss = no
		}
		every_vassal_or_below = {
			limit = { NOT = { culture = { has_cultural_pillar = heritage_west_slavic } } } 
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_poland
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}
				change_title_holder = {
					holder = ROOT
					change = scope:title_change
				}
			}
		}
		resolve_title_and_vassal_change = scope:title_change
		if = {	#If Germania is nae a thing, merge it into the HRE.
			limit = {
				has_title = title:k_east_francia
			}
			ordered_vassal_or_below = { 
				limit = {
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_central_germanic }
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_east_francia = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		} 
		if = {	#If Germania is nae a thing, merge it into the HRE.
			limit = {
				any_vassal = { has_title = title:k_east_francia 
				NOT = { culture = { has_cultural_pillar = heritage_central_germanic } } }
			}
			ordered_vassal_or_below = { 
				limit = {
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_central_germanic } 
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_east_francia = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}   
		if = {	#If Germania is nae a thing, merge it into the HRE.
			limit = {
				NOT = { exists = title:k_east_francia.holder }
				title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
			}
			ordered_vassal_or_below = { 
				limit = {
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_central_germanic }         
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_east_francia = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}    
		if = { 
			limit = { has_global_variable = kingdom_of_germania_established_sclavinia }
			every_vassal_or_below = {
				limit = { NOT = { culture = { has_cultural_pillar = heritage_central_germanic } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_east_francia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_east_francia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_east_francia
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_east_francia.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_central_germanic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_central_germanic } } }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_east_francia.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
		} 
		if = { # Merge Francia into the HRE under certain conditions
			limit = {
				OR = {
					NOT = { exists = title:e_france.holder }
					title:e_france.holder ?= root
				}
				title:k_france = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_burgundy = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_france
				}
				set_de_jure_liege_title = title:e_france
			}
			title:k_aquitaine = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_france
				} 
				set_de_jure_liege_title = title:e_france
			}
			title:k_brittany = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_france
				}
				set_de_jure_liege_title = title:e_france
			}     
			title:d_brabant = { set_de_jure_liege_title = title:k_france }
			title:d_luxembourg = { set_de_jure_liege_title = title:k_france }
			title:d_bar = { set_de_jure_liege_title = title:k_france }
			title:k_france = { 
				set_coa = e_france
				set_color_from_title = title:e_france
				set_title_name = gallia_sclavinia
				set_de_jure_liege_title = title:e_hre
			}  
			set_global_variable = {
				name = kingdom_of_gallia_established_sclavinia
				value = yes
			} 
			set_global_variable = {
				name = west_francia_renamed
				value = yes
			}   
		}
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_france
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_frankish }   
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_france = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_france 
				NOT = { culture = { has_cultural_pillar = heritage_frankish } } }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_frankish }     
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_france = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_france.holder }
				title:k_france = { target_is_de_jure_liege_or_above = title:e_hre }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
					has_government = feudal_government
					culture = { has_cultural_pillar = heritage_frankish }       
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_france = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_gallia_established_sclavinia }
			every_vassal_or_below = {
				limit = { NOT = { culture = { has_cultural_pillar = heritage_frankish } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_france
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_france.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_france
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_france.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_frankish }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_frankish } } }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_france.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
		}
	}
	custom_tooltip = restore_holy_roman_empire_decision_effects_de_jure.sclavinia
	custom_tooltip = kingdom_of_sclavinia_established_sclavinia
	if = {	#If Germania is nae a thing, merge it into the HRE.
		limit = {
			OR = { 
				title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
				AND = { 
					OR = {
						NOT = { exists = title:e_germany.holder }
						title:e_germany.holder ?= root
					}
					OR = {
						has_title = title:k_east_francia
						any_vassal = { has_title = title:k_east_francia }
					}
				}
			}
		}
		custom_tooltip = kingdom_of_germania_established_sclavinia
	}
	if = { # Merge Francia into the HRE under certain conditions
		limit = {
			OR = { 
				title:k_france = { target_is_de_jure_liege_or_above = title:e_hre }
				AND = {
					OR = {
						NOT = { exists = title:e_france.holder }
						title:e_france.holder ?= root
					}
					OR = {
						has_title = title:k_france
						any_vassal = { has_title = title:k_france }
					}
				}
			}
		} 
		custom_tooltip = kingdom_of_gallia_established_sclavinia
	} 
	#And add a bit of prestige for the trouble.
	add_prestige = massive_prestige_value    
	add_legitimacy = 350  
	custom_tooltip = establish_kingdoms_sclavinia_tooltip
}
reform_holy_roman_empire_sclavinia_decision_scripted_effect = { 
	#Sort title laws.
	title:e_hre = {
		set_title_name = e_wre     
		set_coa = e_germany
		add_title_law = reformed_princely_elective_succession_law
		custom_tooltip = hre_elector_list_creation_sclavinia_tt
	}
	hidden_effect = {
		title:k_pomerania = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_polabia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_bohemia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_moravia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_transdanubia = { set_de_jure_liege_title = title:e_sclavinia }
		title:k_carinthia = { set_de_jure_liege_title = title:e_sclavinia }
		title:d_istria = { set_de_jure_liege_title = title:k_croatia }
		title:d_carinthia = { set_de_jure_liege_title = title:k_poland }
		title:d_steyermark = { set_de_jure_liege_title = title:k_poland }
		title:d_krain = { set_de_jure_liege_title = title:k_poland }
		title:c_gorz = { set_de_jure_liege_title = title:d_krain } 
		title:e_hre.holder = {
			every_held_title = {
				limit = {
					tier = tier_kingdom
					NOT = {	#The Pope retains vague dibs on Italy.
						any_this_title_or_de_jure_above = { this = title:e_italy }
					}
					save_temporary_scope_as = this_title
					#root = { completely_controls = scope:this_title }
				}
				set_de_jure_liege_title = title:e_hre
			}
			every_vassal = {
				every_held_title = {
					limit = {
						tier = tier_kingdom
						NOT = {	#The Pope retains vague dibs on Italy.
							any_this_title_or_de_jure_above = { this = title:e_italy }
						}
						save_temporary_scope_as = this_title
						#prev = { completely_controls = scope:this_title }
					}
					set_de_jure_liege_title = title:e_hre
				}
			}
			every_vassal = {
				limit = {
					is_ai = yes
				}
				every_held_title = {
					limit = {
						tier = tier_kingdom
						NOT = {
							this = title:k_poland
							this = title:k_east_francia
							this = title:k_france
							this = title:k_italy
						}
					}
					root = {
						destroy_title = prev
					}
				}
			}
			every_held_title = {
				limit = {
					tier >= tier_kingdom
					NOT = {
						this = title:e_hre
						this = title:k_poland
						this = title:k_east_francia
						this = title:k_france
						this = title:k_italy
					}
					save_temporary_scope_as = this_title
				}
				root = {
					destroy_title = prev
				}
			}
			if = {
				limit = { 
					OR = {
						NOT = { exists = title:e_germany.holder }
						title:e_germany.holder ?= root
					}
					title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
				}
				title:k_bavaria = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_east_francia
					}
					set_de_jure_liege_title = title:e_germany
				}
				title:k_lotharingia = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_east_francia
					}
					set_de_jure_liege_title = title:e_germany
				}
				title:k_frisia = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_east_francia
					}  
					set_de_jure_liege_title = title:e_germany
				} 
				title:d_transjurania = { set_de_jure_liege_title = title:k_east_francia }
				title:k_east_francia = { 
					set_coa = e_germany
					set_color_from_title = title:e_germany
					set_title_name = e_germany
					set_de_jure_liege_title = title:e_hre
				}  
				set_global_variable = {
					name = kingdom_of_germania_established_sclavinia
					value = yes
				} 
				set_global_variable = {
					name = east_francia_renamed
					value = yes
				} 
			}         
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_vassal_or_below = { 
				limit = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_west_slavic } } }
				}
				change_liege = { 
					liege = ROOT
					change = scope:change
				}
			}   
			resolve_title_and_vassal_change = scope:change
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			every_vassal_or_below = {
				limit = { NOT = { culture = { has_cultural_pillar = heritage_west_slavic } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_poland
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}
					change_title_holder = {
						holder = ROOT
						change = scope:title_change
					}
				}
			}
			resolve_title_and_vassal_change = scope:title_change
			if = {	#If Germania is nae a thing, merge it into the HRE.
				limit = {
					has_title = title:k_east_francia
				}
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_central_germanic } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_east_francia = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
				else = {
					ordered_vassal_or_below = { 
						limit = {
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_central_germanic }     
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change_title
							add_claim_on_loss = no
						}
						title:k_east_francia = {
							change_title_holder = {
								holder = prev
								change = scope:change_title
							}
						}
						resolve_title_and_vassal_change = scope:change_title
					}
				}
			} 
			if = {	#If Germania is nae a thing, merge it into the HRE.
				limit = {
					any_vassal = { has_title = title:k_east_francia 
					NOT = { culture = { has_cultural_pillar = heritage_central_germanic } } }
				}
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_central_germanic } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_east_francia = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
				else = {
					ordered_vassal_or_below = { 
						limit = {
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_central_germanic }  
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change_title
							add_claim_on_loss = no
						}
						title:k_east_francia = {
							change_title_holder = {
								holder = prev
								change = scope:change_title
							}
						}
						resolve_title_and_vassal_change = scope:change_title
					}
				}
			}    
			if = {	#If Germania is nae a thing, merge it into the HRE.
				limit = {
					NOT = { exists = title:k_east_francia.holder }
					title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
				}
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_central_germanic } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_east_francia = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
				else = {
					ordered_vassal_or_below = { 
						limit = {
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_east_francia }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_central_germanic }         
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = created
							save_scope_as = title_change
							add_claim_on_loss = no
						}
						title:k_east_francia = {
							change_title_holder = {
								holder = prev
								change = scope:title_change
							}
						}
						resolve_title_and_vassal_change = scope:title_change
					}
				}
			}    
			if = { 
				limit = { has_global_variable = kingdom_of_germania_established_sclavinia }
				every_vassal_or_below = {
					limit = { NOT = { culture = { has_cultural_pillar = heritage_central_germanic } } } 
					every_held_title = { 
						limit = { 
							target_is_de_jure_liege_or_above = title:k_east_francia
							OR = { 
								tier = tier_duchy
								tier = tier_county
							}
						}	
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = title_change
							add_claim_on_loss = no
						}
						change_title_holder = {
							holder = title:k_east_francia.holder
							change = scope:title_change
						}  
						resolve_title_and_vassal_change = scope:title_change
					}
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_east_francia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_east_francia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
				every_vassal_or_below = {
					limit = { 
						culture = { has_cultural_pillar = heritage_central_germanic }
						NOT = { liege = { culture = { has_cultural_pillar = heritage_central_germanic } } }					
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					change_liege = { 
						liege = title:k_east_francia.holder
						change = scope:change_title
					}         
					resolve_title_and_vassal_change = scope:change_title
				}
			}
			if = {
				limit = {
					OR = {
						NOT = { exists = title:e_france.holder }
						title:e_france.holder ?= root
					}
					title:k_france = { # If core West Francia is part of the HRE
						target_is_de_jure_liege_or_above = title:e_hre
					}
				}
				title:k_burgundy = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_france
					}
					set_de_jure_liege_title = title:e_france
				}
				title:k_aquitaine = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_france
					} 
					set_de_jure_liege_title = title:e_france
				}
				title:k_brittany = {
					every_in_de_jure_hierarchy = {
						limit = { tier = tier_duchy }
						set_de_jure_liege_title = title:k_france
					}
					set_de_jure_liege_title = title:e_france
				} 
				title:d_brabant = { set_de_jure_liege_title = title:k_france }
				title:d_luxembourg = { set_de_jure_liege_title = title:k_france }
				title:d_bar = { set_de_jure_liege_title = title:k_france } 
				title:k_france = { 
					set_coa = e_france
					set_color_from_title = title:e_france
					set_title_name = gallia_sclavinia
					set_de_jure_liege_title = title:e_hre
				}  
				set_global_variable = {
					name = kingdom_of_gallia_established_sclavinia
					value = yes
				} 
				set_global_variable = {
					name = west_francia_renamed
					value = yes
				} 
			}      
			if = {	#Merge Francia into the HRE under certain conditions
				limit = {
					has_title = title:k_france
				}
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_frankish } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_france = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
				else = { 
					ordered_vassal_or_below = { 
						limit = { 		 
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_frankish }   
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change_title
							add_claim_on_loss = no
						}
						title:k_france = {
							change_title_holder = {
								holder = prev
								change = scope:change_title
							}
						}
						resolve_title_and_vassal_change = scope:change_title
					}
				}
			}     
			if = {	#Merge Francia into the HRE under certain conditions
				limit = {
					any_vassal = { has_title = title:k_france 
					NOT = { culture = { has_cultural_pillar = heritage_frankish } } }
				}
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_frankish } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_france = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
				else = { 
					ordered_vassal_or_below = { 
						limit = { 		 
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_frankish } 
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = change_title
							add_claim_on_loss = no
						}
						title:k_france = {
							change_title_holder = {
								holder = prev
								change = scope:change_title
							}
						}
						resolve_title_and_vassal_change = scope:change_title
					}
				}
			}    
			if = {	#Merge Francia into the HRE under certain conditions
				limit = {
					NOT = { exists = title:k_france.holder }
					title:k_france = { target_is_de_jure_liege_or_above = title:e_hre }
				}  
				if = { 
					limit = { 
						title:e_hre.holder = { culture = { has_cultural_pillar = heritage_frankish } }
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_france = {
						change_title_holder = {
							holder = title:e_hre.holder
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
				else = {
					ordered_vassal_or_below = { 
						limit = { 		 
							capital_province.county = { target_is_de_jure_liege_or_above = title:k_france }
							has_government = feudal_government
							culture = { has_cultural_pillar = heritage_frankish }     
							has_faith = faith:catholic
						}
						order_by = sub_realm_size
						create_title_and_vassal_change = {
							type = created
							save_scope_as = title_change
							add_claim_on_loss = no
						}
						title:k_france = {
							change_title_holder = {
								holder = prev
								change = scope:title_change
							}
						}
						resolve_title_and_vassal_change = scope:title_change
					}
				}
			}
			if = { 
				limit = { has_global_variable = kingdom_of_gallia_established_sclavinia }
				every_vassal_or_below = {
					limit = { NOT = { culture = { has_cultural_pillar = heritage_frankish } } } 
					every_held_title = { 
						limit = { 
							target_is_de_jure_liege_or_above = title:k_france
							OR = { 
								tier = tier_duchy
								tier = tier_county
							}
						}	
						create_title_and_vassal_change = {
							type = granted
							save_scope_as = title_change
							add_claim_on_loss = no
						}
						change_title_holder = {
							holder = title:k_france.holder
							change = scope:title_change
						}  
						resolve_title_and_vassal_change = scope:title_change
					}
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_france
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_france.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
				every_vassal_or_below = {
					limit = { 
						culture = { has_cultural_pillar = heritage_frankish }
						NOT = { liege = { culture = { has_cultural_pillar = heritage_frankish } } }					
					}
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change
						add_claim_on_loss = no
					}
					change_liege = { 
						liege = title:k_france.holder
						change = scope:change
					}         
					resolve_title_and_vassal_change = scope:change
				} 
			}
		}
	}   
	custom_tooltip = restore_holy_roman_empire_decision_effects_de_jure.sclavinia_reform
	if = {	#If Germania is nae a thing, merge it into the HRE.
		limit = {
			title:e_hre.holder = { 
				OR = { 
					title:k_east_francia = { target_is_de_jure_liege_or_above = title:e_hre }
					AND = { 
						OR = {
							NOT = { exists = title:e_germany.holder }
							title:e_germany.holder ?= root
						}
						OR = {
							has_title = title:k_east_francia
							any_vassal = { has_title = title:k_east_francia }
						}
					}
				}
			}
		}
		custom_tooltip = kingdom_of_germania_established_sclavinia
	}
	if = { # Merge Francia into the HRE under certain conditions
		limit = {
			title:e_hre.holder = {
				OR = { 
					title:k_france = { target_is_de_jure_liege_or_above = title:e_hre }
					AND = {
						OR = {
							NOT = { exists = title:e_france.holder }
							title:e_france.holder ?= root
						}
						OR = {
							has_title = title:k_france
							any_vassal = { has_title = title:k_france }
						}
					}
				}
			}
		} 
		custom_tooltip = kingdom_of_gallia_established_sclavinia
	}
	custom_tooltip = establish_kingdoms_sclavinia_tooltip
}
create_roman_empire_sclavinia_scripted_effect = {
	add_trait = augustus
	#Create Roman Empire, shift dejure/history/laws, destroy e_hre.
	every_held_title = { #Should shift all dejure of all Empires owned at the time.
		title_tier = empire

		set_de_jure_liege_title = title:h_roman_empire
	}
	every_empire = {
		limit = {
			NOT = { exists = hegemony }
			any_de_jure_county = {
				percent >= 0.6
				holder = {
					OR = {
						this = root
						any_liege_or_above = { this = root }
					}
				}
			}
		}
		set_de_jure_liege_title = title:h_roman_empire
	}
	create_title_and_vassal_change = {
		type = created
		save_scope_as = change
		add_claim_on_loss = no
	}
	title:h_roman_empire = {
		change_title_holder = {
			holder = root
			change = scope:change
		}
		set_variable = {
			name = variable_restored_hre #Used for flavor later.
			value = yes
		}	
		copy_title_history = title:e_hre   
	}
	resolve_title_and_vassal_change = scope:change
	if = { # Move your Title MaAs to your new title if you have any
		limit = {
			government_allows = administrative
			primary_title = {
				any_title_maa_regiment = {  }
			}
		}
		hidden_effect = {
			primary_title = { transfer_title_maa_ownership = title:h_roman_empire }
		}
	}
	if = { # If you have founded the Varangian Guard, you get to keep the benefits (you are not likely to have done it here, but better safe than sorry)
		limit = {
			primary_title = { has_variable = founded_varangian_guard }
		}
		hidden_effect = {
			title:h_roman_empire = { set_variable = founded_varangian_guard }
		}
	}
	hidden_effect = { set_primary_title_to = title:h_roman_empire }
	every_held_title = { #Should destroy all other Empires owned at the time.
		title_tier = empire

		root = { destroy_title = prev }
	}

	if = { #Automatically move capital to Rome.
		limit = {
			NOT = { capital_county = { this = title:c_roma } }
			exists = title:h_roman_empire.holder
			NOT = { has_global_variable = sclavinia_imperium_universalis }
		}
		hidden_effect = {
			if = { #Usurp if not held personally.
				limit = {
					NOT = { title:c_roma.holder = { this = root } }
				}
				create_title_and_vassal_change = {
					type = returned
					save_scope_as = change
					add_claim_on_loss = no
				}
				title:c_roma = {
					change_title_holder = {
						holder = root
						change = scope:change
					}
				}
				resolve_title_and_vassal_change = scope:change
			}
		}
		title:h_roman_empire.holder = { set_realm_capital = title:c_roma }
	}
	hidden_effect = {
		create_story = restoring_roman_provinces_story
		add_character_flag = flag_restorer_of_rome #used for Eulogy.
	}
}
kingdom_of_hispania_decision_effect = {
	hidden_effect = {
		title:k_castille = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_castille = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_andalusia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_badajoz = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				} 
				set_de_jure_liege_title = title:e_spain
			}
			title:k_valencia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_asturias = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_aragon = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_navarra = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_leon = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_spanish_galicia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			}
			title:k_portugal = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_castille
				}
				set_de_jure_liege_title = title:e_spain
			} 
			title:d_barcelona = { set_de_jure_liege_title = title:k_castille }
			title:k_castille = { 
				set_color_from_title = title:e_spain
				set_title_name = e_spain
				set_de_jure_liege_title = title:e_hre
				set_capital_county = title:c_santiago
				set_coa = k_asturias
			}      
			if = { 
				limit = { title:k_andalusia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_andalusia
			}
			if = { 
				limit = { title:k_badajoz = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_badajoz
			}
			if = { 
				limit = { title:k_valencia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_valencia
			}
			if = { 
				limit = { title:k_asturias = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_asturias
			}
			if = { 
				limit = { title:k_aragon = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_aragon
			}
			if = { 
				limit = { title:k_navarra = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_navarra
			}
			if = { 
				limit = { title:k_leon = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_leon
			}
			if = { 
				limit = { title:k_spanish_galicia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_spanish_galicia
			}
			if = { 
				limit = { title:k_portugal = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_portugal
			}
			set_global_variable = {
				name = kingdom_of_hispania_established_sclavinia
				value = yes
			} 
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_castille
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_iberian } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_iberian }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_castille = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_castille 
				NAND = { 
					culture = { has_cultural_pillar = heritage_iberian }
					has_faith = faith:catholic 
				}
			} }
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_iberian } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_iberian }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_castille = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_castille.holder }
				title:k_castille = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_iberian } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_iberian }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_castille = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}         
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_castille 
				NAND = { 
					culture = { has_cultural_pillar = heritage_iberian }
					has_faith = faith:catholic 
				}
			} }
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}   
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_castille
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}  
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_castille.holder }
				title:k_castille = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_castille = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_hispania_established_sclavinia }
			every_vassal_or_below = {
				limit = { 
					NAND = { 
						culture = { has_cultural_pillar = heritage_iberian }
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					} 
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_castille
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_castille.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_castille
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_castille.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_iberian }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_iberian } } }			
					any_held_title = { target_is_de_jure_liege_or_above = title:k_castille }				
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_castille.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_iberian }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_castille } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_castille }							
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_castille.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_iberian }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_castille }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_castille
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_castille.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}						
		}
	}
}
kingdom_of_britannia_decision_effect = {
	hidden_effect = {
		title:k_england = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_england = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_wales = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_scotland = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				} 
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_ireland = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_cornwall = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_mann_the_isles = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_daneland = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_danelaw = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:k_brittany = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_england
				}
				set_de_jure_liege_title = title:e_britannia
			}
			title:d_brittany = { set_de_jure_liege_title = title:k_england }
			title:k_england = { 
				set_coa = e_britannia
				set_color_from_title = title:e_britannia
				set_title_name = e_britannia
				set_de_jure_liege_title = title:e_hre
			}   
			if = { 
				limit = { title:k_wales = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_wales
			}
			if = { 
				limit = { title:k_scotland = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_scotland
			}
			if = { 
				limit = { title:k_ireland = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_ireland
			}
			if = { 
				limit = { title:k_cornwall = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_cornwall
			}
			if = { 
				limit = { title:k_mann_the_isles = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_mann_the_isles
			}
			if = { 
				limit = { title:k_brittany = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_brittany
			}
			if = { 
				limit = { title:k_daneland = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_daneland
			}
			if = { 
				limit = { title:k_danelaw = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_danelaw
			} 
			set_global_variable = {
				name = kingdom_of_britannia_established_sclavinia
				value = yes
			} 
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_england
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_england = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_england 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }  
						has_faith = faith:catholic
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_england = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_england.holder }
				title:k_england = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_england = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_england 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }  
						has_faith = faith:catholic
					}
				}
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}   
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_england
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_england.holder }
				title:k_england = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_england = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_britannia_established_sclavinia }
			every_vassal_or_below = {
				limit = { 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }					
					}
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_england
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_england.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_england
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_england.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
					NOT = { liege = { culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } } } }			
					any_held_title = { target_is_de_jure_liege_or_above = title:k_england }				
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_england.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_england } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_england }							
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_england.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_goidelic has_cultural_pillar = heritage_brythonic has_cultural_pillar = heritage_west_germanic } }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_england }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_england
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_england.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}						
		}
	}
}
kingdom_of_dacia_decision_effect = {
	hidden_effect = {
		title:k_hungary = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_hungary = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_moldavia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_hungary
				}
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_dacia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_hungary
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:d_vidin = { set_de_jure_liege_title = title:k_hungary } 
			title:k_hungary = { 
				set_coa = k_dacia
				set_color_from_title = title:e_carpathia
				set_title_name = k_dacia_sclavinia
				set_de_jure_liege_title = title:e_hre
			}       
			if = { 
				limit = { title:k_dacia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_dacia
			}
			if = { 
				limit = { title:k_moldavia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_moldavia
			}
			set_global_variable = {
				name = kingdom_of_dacia_established_sclavinia
				value = yes
			}
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_vassal_or_below = { 
				limit = {
					culture = { has_cultural_pillar = heritage_west_slavic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_west_slavic } } }
				}
				change_liege = { 
					liege = ROOT
					change = scope:change
				}
			}   
			resolve_title_and_vassal_change = scope:change
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			every_vassal_or_below = {
				limit = { NOT = { culture = { has_cultural_pillar = heritage_west_slavic } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_poland
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}
					change_title_holder = {
						holder = ROOT
						change = scope:title_change
					}
				}
			}
			resolve_title_and_vassal_change = scope:title_change			
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_hungary
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_hungary = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_hungary 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } 
						has_faith = faith:catholic
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_hungary = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_hungary.holder }
				title:k_hungary = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_hungary = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_hungary 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } 
						has_faith = faith:catholic
					}
				}
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_hungary
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}		
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_hungary.holder }
				title:k_hungary = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_hungary = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_dacia_established_sclavinia }
			every_vassal_or_below = {
				limit = { 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					} 
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_hungary
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_hungary.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_hungary
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_hungary.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
					NOT = { liege = { culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } } } }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_hungary } 				
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_hungary.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_hungary } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_hungary }							
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_hungary.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_magyar has_cultural_pillar = heritage_vlach } }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_hungary }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_hungary
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_hungary.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_africa_decision_effect = {
	hidden_effect = {
		title:k_africa = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_africa = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_maghreb = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_africa
				}
				set_de_jure_liege_title = title:e_maghreb
			}
			title:k_tahert = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_africa
				} 
				set_de_jure_liege_title = title:e_maghreb
			}
			title:k_egypt = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_africa
				} 
				set_de_jure_liege_title = title:e_arabia
			} 
			title:k_canarias = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_africa
				} 
				set_de_jure_liege_title = title:e_maghreb
			} 
			title:k_africa = { 
				set_de_jure_liege_title = title:e_hre
			}          
			title:e_maghreb = { 
				set_capital_county = title:c_wadan
			}  
			if = { 
				limit = { title:k_maghreb = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_maghreb
			}       
			if = { 
				limit = { title:k_tahert = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_tahert
			}
			if = { 
				limit = { title:k_egypt = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_egypt
			}
			if = { 
				limit = { title:k_canarias = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_canarias
			}
			set_global_variable = {
				name = kingdom_of_africa_established_sclavinia
				value = yes
			}			
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_africa
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_africa }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_africa = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_africa.holder }
				title:k_africa = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_africa }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_africa = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_africa_established_sclavinia }
			every_vassal_or_below = {
				limit = { NOT = { 
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian } 
					} } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_africa
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_africa.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_africa
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_africa.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
					faith.religious_head_title = title:k_papal_state
					faith = { has_doctrine = special_doctrine_ecumenical_christian }
					liege = { OR = { 
						NOT = { has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian } }
						has_title = scope:e_hre_re_sclavinia
					} }
					any_held_title = { target_is_de_jure_liege_or_above = title:k_africa } 				
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_africa.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
					faith.religious_head_title = title:k_papal_state
					faith = { has_doctrine = special_doctrine_ecumenical_christian }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_africa } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_africa }							
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_africa.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
					faith.religious_head_title = title:k_papal_state
					faith = { has_doctrine = special_doctrine_ecumenical_christian }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_africa }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_africa
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_africa.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_hierosolyma_decision_effect = {
	hidden_effect = {
		title:k_jerusalem = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_jerusalem = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_syria = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_jerusalem
				}
				set_de_jure_liege_title = title:e_arabia
			}
			title:k_jazira = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_jerusalem
				} 
				set_de_jure_liege_title = title:e_arabia
			}
			title:d_sinai = { set_de_jure_liege_title = title:k_jerusalem }
			title:d_amman = { set_de_jure_liege_title = title:k_jerusalem }
			title:d_samarra = { set_de_jure_liege_title = title:k_jerusalem }
			title:d_baghdad = { set_de_jure_liege_title = title:k_jerusalem }
			title:d_kermanshah = { set_de_jure_liege_title = title:k_jerusalem }
			title:k_jerusalem = { 
				set_de_jure_liege_title = title:e_hre
				set_title_name = k_hierosolyma_sclavinia
			}        
			title:e_arabia = { 
				set_capital_county = title:c_sanaa
			}         
			title:k_mesopotamia = { 
				set_capital_county = title:c_kufa
			}    
			if = { 
				limit = { title:k_syria = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_syria
			}       
			if = { 
				limit = { title:k_jazira = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_jazira
			}
			set_global_variable = {
				name = kingdom_of_hierosolyma_established_sclavinia
				value = yes
			}			
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_jerusalem
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_jerusalem }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_jerusalem = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_jerusalem.holder }
				title:k_jerusalem = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_jerusalem }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_jerusalem = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_hierosolyma_established_sclavinia }
			every_vassal_or_below = {
				limit = { NOT = { has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian } } } 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_jerusalem
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_jerusalem.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_jerusalem
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_jerusalem.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					liege = { OR = { 
						NOT = { has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian } }
						has_title = scope:e_hre_re_sclavinia
					} }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_jerusalem } 				
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_jerusalem.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_jerusalem } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_jerusalem }							
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_jerusalem.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_jerusalem }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_jerusalem
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_jerusalem.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_graecia_decision_effect = {
	hidden_effect = {
		title:k_thessalonika = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_thessalonika = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_epirus = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				}
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_hellas = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_krete = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_cyprus = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_nikaea = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_anatolia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_pontus = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_armenia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:k_georgia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_thessalonika
				} 
				set_de_jure_liege_title = title:e_carpathia
			}
			title:d_edessa = { set_de_jure_liege_title = title:k_thessalonika }
			title:d_antioch = { set_de_jure_liege_title = title:k_thessalonika }
			title:d_diyarbakr = { set_de_jure_liege_title = title:k_thessalonika }
			title:d_philippopolis = { set_de_jure_liege_title = title:k_thessalonika }
			title:d_shirvan = { set_de_jure_liege_title = title:k_thessalonika }
			title:k_thessalonika = { 
				set_coa = e_latin_empire
				set_color_from_title = title:k_hellas
				set_title_name = k_graecia_sclavinia
				set_de_jure_liege_title = title:e_hre
				set_capital_county = title:c_attica
			}       
			if = { 
				limit = { title:k_epirus = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_epirus
			}
			if = { 
				limit = { title:k_hellas = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_hellas
			}
			if = { 
				limit = { title:k_krete = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_krete
			}
			if = { 
				limit = { title:k_cyprus = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_cyprus
			}
			if = { 
				limit = { title:k_nikaea = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_nikaea
			}
			if = { 
				limit = { title:k_anatolia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_anatolia
			}
			if = { 
				limit = { title:k_pontus = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_pontus
			}
			if = { 
				limit = { title:k_armenia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_armenia
			}
			if = { 
				limit = { title:k_georgia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_georgia
			}
			set_global_variable = {
				name = kingdom_of_graecia_established_sclavinia
				value = yes
			}		
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_thessalonika
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_thessalonika = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_thessalonika 
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } 
						has_faith = faith:catholic 
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_thessalonika = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_thessalonika.holder }
				title:k_thessalonika = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
						has_government = feudal_government
						culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_thessalonika = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}       
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_thessalonika 
				NAND = { 
					culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } 
					has_faith = faith:catholic 
				} }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}  
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_thessalonika
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_thessalonika.holder }
				title:k_thessalonika = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_thessalonika = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_graecia_established_sclavinia }
			every_vassal_or_below = {
				limit = {
					NAND = { 
						culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } 
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					}
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_thessalonika
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_thessalonika.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_thessalonika
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_thessalonika.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
					NOT = { liege = { culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } } } }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_thessalonika }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_thessalonika.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_thessalonika } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_thessalonika }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_thessalonika.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { OR = { has_cultural_pillar = heritage_byzantine has_cultural_pillar = heritage_caucasian has_cultural_pillar = heritage_albanian } }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_thessalonika }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_thessalonika
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_thessalonika.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_sclavonia_decision_effect = {
	hidden_effect = {
		title:k_croatia = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_croatia = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_bosnia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_croatia
				}
				set_de_jure_liege_title = title:e_byzantium
			}
			title:k_serbia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_croatia
				} 
				set_de_jure_liege_title = title:e_byzantium
			}
			title:k_bulgaria = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_croatia
				} 
				set_de_jure_liege_title = title:e_byzantium
			}
			title:d_syrmia = { set_de_jure_liege_title = title:k_croatia }
			title:d_istria = { set_de_jure_liege_title = title:k_croatia }
			title:k_croatia = { 
				set_coa = k_bulgaria
				set_title_name = k_sclavonia_sclavinia
				set_de_jure_liege_title = title:e_hre
			}       
			if = { 
				limit = { title:k_bosnia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_bosnia
			}
			if = { 
				limit = { title:k_serbia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_serbia
			}
			if = { 
				limit = { title:k_bulgaria = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_bulgaria
			}
			set_global_variable = {
				name = kingdom_of_sclavonia_established_sclavinia
				value = yes
			}	
			set_variable = kingdom_of_sclavonia_established_sclavinia			
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_croatia
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_south_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_south_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_croatia = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_croatia 
					NAND = { 
						culture = { has_cultural_pillar = heritage_south_slavic } 
						has_faith = faith:catholic 
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_south_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_south_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_croatia = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_croatia.holder }
				title:k_croatia = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_south_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_south_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_croatia = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}       
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_croatia 
				NAND = { 
					culture = { has_cultural_pillar = heritage_south_slavic } 
					has_faith = faith:catholic 
				} }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}  
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_croatia
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_croatia.holder }
				title:k_croatia = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_croatia = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_sclavonia_established_sclavinia }
			every_vassal_or_below = {
				limit = {
					NAND = { 
						culture = { has_cultural_pillar = heritage_south_slavic } 
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					}
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_croatia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_croatia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_croatia
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_croatia.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_south_slavic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_south_slavic } } }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_croatia }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_croatia.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_south_slavic }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_croatia } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_croatia }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_croatia.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_south_slavic }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_croatia }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_croatia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_croatia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_normannia_decision_effect = {
	hidden_effect = {
		title:k_denmark = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_denmark = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_norway = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_denmark
				}
				set_de_jure_liege_title = title:e_scandinavia
			}
			title:k_sweden = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_denmark
				} 
				set_de_jure_liege_title = title:e_scandinavia
			}
			title:k_denmark = { 
				set_coa = e_north_sea
				set_color_from_title = title:k_sweden
				set_title_name = k_normannia_sclavinia
				set_de_jure_liege_title = title:e_hre
				set_capital_county = title:c_skane
			}     
			title:e_scandinavia = { 
				set_capital_county = title:c_finland
			}       
			if = { 
				limit = { title:k_norway = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_norway
			}
			if = { 
				limit = { title:k_sweden = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_sweden
			}
			set_global_variable = {
				name = kingdom_of_normannia_established_sclavinia
				value = yes
			}		
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_denmark
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_north_germanic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_north_germanic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_denmark = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_denmark 
					NAND = { 
						culture = { has_cultural_pillar = heritage_north_germanic } 
						has_faith = faith:catholic 
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_north_germanic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_north_germanic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_denmark = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_denmark.holder }
				title:k_denmark = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_north_germanic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_north_germanic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_denmark = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}       
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_denmark 
				NAND = { 
					culture = { has_cultural_pillar = heritage_north_germanic } 
					has_faith = faith:catholic 
				} }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}  
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_denmark
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_denmark.holder }
				title:k_denmark = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_denmark = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_normannia_established_sclavinia }
			every_vassal_or_below = {
				limit = {
					NAND = { 
						culture = { has_cultural_pillar = heritage_north_germanic } 
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian } 
					}
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_denmark
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_denmark.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_denmark
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_denmark.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_north_germanic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_north_germanic } } }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_denmark }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_denmark.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_north_germanic }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = { target_is_de_facto_liege_or_above = title:k_denmark } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_denmark }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_denmark.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_north_germanic }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_denmark }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_denmark
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_denmark.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}
kingdom_of_ruthenia_decision_effect = {
	hidden_effect = {
		title:k_ruthenia = { set_de_jure_liege_title = title:e_hre }
		if = {
			limit = {
				title:k_ruthenia = { # If core West Francia is part of the HRE
					target_is_de_jure_liege_or_above = title:e_hre
				}
			}
			title:k_novgorod = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_ruthenia
				}
				set_de_jure_liege_title = title:e_russia
			}
			title:k_white_rus = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_ruthenia
				} 
				set_de_jure_liege_title = title:e_russia
			}
			title:k_galicia-volhynia = {
				every_in_de_jure_hierarchy = {
					limit = { tier = tier_duchy }
					set_de_jure_liege_title = title:k_ruthenia
				} 
				set_de_jure_liege_title = title:e_russia
			}     
			title:k_opolye = { 
				set_capital_county = title:c_ryazan
			}
			title:d_bukovina = { set_de_jure_liege_title = title:k_ruthenia }
			title:d_opolye = { set_de_jure_liege_title = title:k_ruthenia }
			title:k_ruthenia = { 
				set_color_from_title = title:e_russia
				set_de_jure_liege_title = title:e_hre
			}       
			if = { 
				limit = { title:k_novgorod = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_novgorod
			}
			if = { 
				limit = { title:k_white_rus = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_white_rus
			}
			if = { 
				limit = { title:k_galicia-volhynia = { target_is_de_facto_liege_or_above = scope:e_hre_re_sclavinia  } }
				destroy_title = title:k_galicia-volhynia
			}
			set_global_variable = {
				name = kingdom_of_ruthenia_established_sclavinia
				value = yes
			}		
			set_variable = kingdom_of_ruthenia_established_sclavinia
		}      
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_ruthenia
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_east_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_east_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_ruthenia = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}     
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_ruthenia 
					NAND = { 
						culture = { has_cultural_pillar = heritage_east_slavic } 
						has_faith = faith:catholic 
					}
				}
			}
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_east_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
			else = { 
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_east_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = change_title
						add_claim_on_loss = no
					}
					title:k_ruthenia = {
						change_title_holder = {
							holder = prev
							change = scope:change_title
						}
					}
					resolve_title_and_vassal_change = scope:change_title
				}
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_ruthenia.holder }
				title:k_ruthenia = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			if = { 
				limit = { 
					scope:e_hre_re_sclavinia.holder = { culture = { has_cultural_pillar = heritage_east_slavic } }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = scope:e_hre_re_sclavinia.holder
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
			else = {
				ordered_vassal_or_below = { 
					limit = { 		 
						capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
						has_government = feudal_government
						culture = { has_cultural_pillar = heritage_east_slavic }
						has_faith = faith:catholic
					}
					order_by = sub_realm_size
					create_title_and_vassal_change = {
						type = created
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					title:k_ruthenia = {
						change_title_holder = {
							holder = prev
							change = scope:title_change
						}
					}
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}       
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				any_vassal = { has_title = title:k_ruthenia 
				NAND = { 
					culture = { has_cultural_pillar = heritage_east_slavic } 
					has_faith = faith:catholic 
				} }
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}  
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				has_title = title:k_ruthenia
			}
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change_title
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = prev
						change = scope:change_title
					}
				}
				resolve_title_and_vassal_change = scope:change_title
			}
		}    
		if = {	#Merge Francia into the HRE under certain conditions
			limit = {
				NOT = { exists = title:k_ruthenia.holder }
				title:k_ruthenia = { target_is_de_jure_liege_or_above = title:e_hre }
			}  
			ordered_vassal_or_below = { 
				limit = { 		 
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
					has_government = feudal_government
					has_faith = faith:catholic
				}
				order_by = sub_realm_size
				create_title_and_vassal_change = {
					type = created
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				title:k_ruthenia = {
					change_title_holder = {
						holder = prev
						change = scope:title_change
					}
				}
				resolve_title_and_vassal_change = scope:title_change
			}
		}
		if = { 
			limit = { has_global_variable = kingdom_of_ruthenia_established_sclavinia }
			every_vassal_or_below = {
				limit = {
					NAND = { 
						culture = { has_cultural_pillar = heritage_east_slavic } 
						has_religion = religion:christianity_religion
						faith.religious_head_title = title:k_papal_state
						faith = { has_doctrine = special_doctrine_ecumenical_christian }
					}
				} 
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_ruthenia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_ruthenia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
			every_held_title = { 
				limit = { 
					target_is_de_jure_liege_or_above = title:k_ruthenia
					OR = { 
						tier = tier_duchy
						tier = tier_county
					}
				}	
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = title_change
					add_claim_on_loss = no
				}
				change_title_holder = {
					holder = title:k_ruthenia.holder
					change = scope:title_change
				}  
				resolve_title_and_vassal_change = scope:title_change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_east_slavic }
					NOT = { liege = { culture = { has_cultural_pillar = heritage_east_slavic } } }		
					any_held_title = { target_is_de_jure_liege_or_above = title:k_ruthenia }					
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_ruthenia.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_east_slavic }
					highest_held_title_tier < tier_kingdom
					liege = { highest_held_title_tier = tier_kingdom } 
					NOT = { primary_title = {  target_is_de_facto_liege_or_above = title:k_ruthenia } }
					capital_province.county = { target_is_de_jure_liege_or_above = title:k_ruthenia }
				}
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = change
					add_claim_on_loss = no
				}
				change_liege = { 
					liege = title:k_ruthenia.holder
					change = scope:change
				}         
				resolve_title_and_vassal_change = scope:change
			}  
			every_vassal_or_below = {
				limit = { 
					culture = { has_cultural_pillar = heritage_east_slavic }
					highest_held_title_tier = tier_kingdom
					NOT = { has_title = title:k_ruthenia }
				}
				every_held_title = { 
					limit = { 
						target_is_de_jure_liege_or_above = title:k_ruthenia
						OR = { 
							tier = tier_duchy
							tier = tier_county
						}
					}	
					create_title_and_vassal_change = {
						type = granted
						save_scope_as = title_change
						add_claim_on_loss = no
					}
					change_title_holder = {
						holder = title:k_ruthenia.holder
						change = scope:title_change
					}  
					resolve_title_and_vassal_change = scope:title_change
				}
			}
		}
	}
}