﻿##############################################
#
# CULTURE
#
##############################################
	

##############################################
#
# HRE Foundation Fixes
#
##############################################
restore_holy_roman_empire_decision_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

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

	#Add de jures.
	hidden_effect = {
		title:k_italy = { # Italy is where the Pope is, we know you may not hold the kingdom but we are gonna flip it anyways. This is required to be held in Succession Expanded anyways.
			set_de_jure_liege_title = title:e_hre
		}
		title:k_romagna = { # We are gonna flip the dejure of Romagna as well for border neatness, tis a silly kingdom anyways.
			set_de_jure_liege_title = title:e_hre
		}
		if = {
			limit = {
				exists = global_var:SE_is_loaded
			}
			every_held_title = {
				limit = {
					tier = tier_kingdom
					NOR = {
						this = title:k_italy
						this = title:k_romagna
					}
				}
				set_de_jure_liege_title = title:e_hre
		    } 
		}
		else = { # If Succession Expanded is not used (Why?) You will have to own East Francia. Please flip the rest of Germany along with it for neatness.
			title:k_east_francia = {
				set_de_jure_liege_title = title:e_hre
			}
			title:k_lotharingia = {
				set_de_jure_liege_title = title:e_hre
			}
			title:k_bavaria = {
				set_de_jure_liege_title = title:e_hre
			}
		}
	}

	#Sort title laws.
	if = {
		limit = {
			NOT = {
				exists = global_var:SE_is_loaded #We cannot yoink East Francia if you don't hold it. Poor East Francian king gets to hold onto his rump state.
			}
		}
		destroy_title = title:k_east_francia
	}
	title:e_hre = {
		add_title_law = 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_tt
	}
	custom_tooltip = restore_holy_roman_empire_decision_effects_de_jure.tt

	#And add a bit of prestige for the trouble.
	add_prestige = massive_prestige_value
}