namespace = Plus

# Plus.1150 to Plus.1199

#######################################
# HRE / Carolingian Empire Events
# Written by Rylock
#######################################

# Upon a new Carolingian emperor ascending to the throne
character_event = {
	id = Plus.1150

	is_triggered_only = yes
	hide_window = yes

	trigger = {
		FROM = {
			title = e_karling

			OR = {
				has_law = crown_authority_0
				has_law = crown_authority_1
			}
		}
	}

	immediate = {
		character_event = {
			id = Plus.1151
			days = 2
		}
	}
}

character_event = {
	id = Plus.1151

	is_triggered_only = yes
	hide_window = yes

	only_independent = yes

	trigger = {
		has_landed_title = e_karling
	}

	immediate = {
		# Send an acceptance event to all duke & king vassals
		any_vassal = {
			limit = { higher_real_tier_than = COUNT }

			character_event = {
				id = Plus.1152
				days = 3
			}
		}

		# Follow-up succeed-or-fail events (only one will be valid)
		narrative_event = { id = Plus.1161 days = 15 } # Coronated by the Pope
		narrative_event = { id = Plus.1162 days = 15 } # Empire dissolves
	}
}

# Event to Carolingian vassals -- do you accept the new emperor or declare independence?
character_event = {
	id = Plus.1152
	title = EVTNAME_Plus_1152
	desc = EVTDESC_Plus_1152
	picture = GFX_evt_council
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	trigger = {
		vassal_of = FROM
	}

	option = {
		name = EVTOPTA_Plus_1152 # Declare independence

		trigger = {
			in_revolt = no
			prisoner = no
			is_adult = yes
			is_incapable = no
		}

		set_defacto_liege = ROOT
		pf_liege_change_effect = yes

		FROM = {
			letter_event = { id = Plus.1153 }
		}

		ai_chance = {
			factor = 50

			trigger = {
				NAND = {
					religion = FROM
					is_close_relative = FROM
				}
			}

			mult_modifier = {
				factor = 0.5

				OR = {
					dynasty = FROM
					is_allied_with = FROM
				}
			}

			mult_modifier = {
				factor = 3
				# The emperor is not a Karling
				FROM = { NOT = { dynasty = 25061 } }
			}

			mult_modifier = {
				factor = 3
				NOT = { religion = FROM }
			}

			mult_modifier = {
				factor = 1.25

				NOT = { culture = FROM }

				NAND = { # German cultures are more accepting of each other
					FROM = { german_cultures_trigger = yes }
					german_cultures_trigger = yes
				}
			}

			mult_modifier = {
				factor = 1.25
				NOT = { culture_group = FROM }
			}

			mult_modifier = {
				factor = 10
				in_faction = faction_separatist
			}

			mult_modifier = {
				factor = 0.5
				year < 880
			}

			mult_modifier = {
				factor = 1.25
				year >= 900
			}

			mult_modifier = {
				factor = 1.25
				year >= 925
			}

			mult_modifier = {
				factor = 1.25
				year >= 950
			}

			mult_modifier = {
				factor = 1.25
				year >= 975
			}

			mult_modifier = {
				factor = 1.25
				year >= 1000
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < 0 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < -25 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < -50 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < -75 }
			}

			mult_modifier = {
				factor = 1.5
				relative_power = { who = FROM power >= 1.0 }
			}

			mult_modifier = {
				factor = 2
				relative_power = { who = FROM power >= 1.5 }
			}

			mult_modifier = {
				factor = 2.5
				relative_power = { who = FROM power >= 2.0 }
			}

			mult_modifier = {
				factor = 1.5

				any_allied_character = {
					independent = yes
					higher_real_tier_than = DUKE
					war = no
					NOT = { character = FROM }
				}
			}

			mult_modifier = {
				factor = 2
				trait = ambitious
			}

			mult_modifier = {
				factor = 1.5
				trait = envious
			}

			mult_modifier = {
				factor = 1.5
				trait = greedy
			}

			mult_modifier = {
				factor = 10
				trait = lunatic
			}

			mult_modifier = {
				factor = 0.1

				trait = possessed
				has_character_modifier = voice_of_jesus
			}

			mult_modifier = {
				factor = 10

				trait = possessed
				has_character_modifier = voice_of_satan
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1152 # Remain loyal vassal

		ai_chance = {
			factor = 50

			mult_modifier = {
				factor = 2

				OR = {
					dynasty = FROM
					is_allied_with = FROM
				}
			}

			mult_modifier = {
				factor = 3
				real_tier = DUKE
			}

			mult_modifier = {
				factor = 2
				e_karling = { has_law = crown_authority_1 }
			}

			mult_modifier = {
				factor = 2
				in_faction = faction_court
			}

			mult_modifier = {
				factor = 2
				year < 880
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value >= 25 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value >= 50 }
			}

			mult_modifier = {
				factor = 2
				opinion = { who = FROM value >= 75 }
			}

			mult_modifier = {
				factor = 1.5
				relative_power = { who = FROM power < 0.5 }
			}

			mult_modifier = {
				factor = 1.5
				relative_power = { who = FROM power < 0.25 }
			}

			mult_modifier = {
				factor = 1.5
				relative_power = { who = FROM power < 0.1 }
			}

			mult_modifier = {
				factor = 2
				trait = content
			}

			mult_modifier = {
				factor = 1.5
				trait = slothful
			}

			mult_modifier = {
				factor = 1.5
				trait = patient
			}

			mult_modifier = {
				factor = 1.5
				trait = humble
			}
		}
	}
}

# Notification to the new Carolingian emperor of a declaration of independence
letter_event = {
	id = Plus.1153
	desc = EVTDESC_Plus_1153

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1153

		FROM = {
			show_scope_change = no

			any_demesne_title = {
				limit = {
					higher_real_tier_than = COUNT
					NOT = { claimed_by = ROOT }
				}

				add_claim = ROOT
			}
		}

		opinion = {
			name = opinion_traitor
			who = ROOT
			years = 25
			multiplier = 2
		}
	}
}

# Carolingian Emperor has a large enough empire
narrative_event = {
	id = Plus.1161
	title = EVTNAME_Plus_1161
	desc = EVTDESC_Plus_1161
	picture = GFX_evt_cathedral
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	only_independent = yes

	trigger = {
		has_landed_title = e_karling
		num_of_count_titles_in_realm >= 100
	}

	option = {
		name = OK

		prestige = 100
	}
}

# Carolingian Emperor has a too-small domain, and the empire is dissolved
narrative_event = {
	id = Plus.1162
	title = EVTNAME_Plus_1162
	desc = EVTDESC_Plus_1162
	picture = GFX_evt_cathedral
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	only_independent = yes

	trigger = {
		has_landed_title = e_karling

		OR = {
			num_of_count_titles_in_realm < 100
			event_target:threatened_title = { title = e_karling }
		}
	}

	option = {
		name = EVTOPTA_Plus_1162

		set_character_flag = former_carolingian_emperor

		hidden_effect = {
			e_karling = {
				any_direct_de_jure_vassal_title = {
					if = { # TODO: Replace with region checks, to account for custom kingdoms, de jure drift
						limit = {
							OR = {
								title = k_italy
								title = k_burgundy
								title = k_lotharingia
								title = k_frisia
								title = k_germany
							}
						}

						de_jure_liege = e_hre
					}
					else = {
						de_jure_liege = e_placeholder
					}
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_germany
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_germany
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_germany
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_germany
					}

					remove_claim = PREV
				}

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

		e_karling = {
			show_scope_change = no

			set_global_flag = carolingian_empire_fallen
			destroy_landed_title = yes
		}

		if = {
			limit = { trait = crowned_by_pope }
			remove_trait = crowned_by_pope
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = END_OF_CAROLINGIAN_EMPIRE
				portrait = [Root.GetID]
				picture = GFX_evt_cathedral
			}
		}

		hidden_effect = {
			activate_title = {
				title = e_karling
				status = no
			}

			any_player = {
				narrative_event = { id = Plus.1163 }
			}
		}
	}
}

# Rulers informed of Carolingian Empire's demise
narrative_event = {
	id = Plus.1163
	title = EVTNAME_Plus_1163
	desc = EVTDESC_Plus_1163
	picture = GFX_evt_cathedral
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = {
			text = EVTOPTA_Plus_1163
			trigger = { religion_group = christian }
		}
		name = {
			text = EVTOPTB_Plus_1163
			trigger = { NOT = { religion_group = christian } }
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = END_OF_CAROLINGIAN_EMPIRE_NEWS
				picture = GFX_evt_cathedral
			}
		}
	}
}

# Rulers informed of land given to Pope
character_event = {
	id = Plus.1164
	desc = EVTDESC_Plus_1164
	picture = GFX_evt_pope
	border = GFX_event_normal_frame_religion

	is_triggered_only = yes

	immediate = {
		FROM = {
			rightful_religious_head_scope = {
				save_event_target_as = current_pope
			}
		}
	}

	option = {
		name = EVTOPTA_Plus_1164

		if = {
			limit = {
				any_demesne_title = {
					real_tier = COUNT

					NOR = {
						title = c_roma
						title = c_ravenna
						title = c_ferrara
						title = c_urbino
						title = c_spoleto
						title = c_orvieto
					}
				}
			}

			any_demesne_title = {
				show_scope_change = no

				limit = {
					OR = {
						title = c_roma
						title = c_ravenna
						title = c_ferrara
						title = c_urbino
						title = c_spoleto
						title = c_orvieto
					}
				}

				grant_title = event_target:current_pope
			}
		}
		else_if = {
			limit = { real_tier = KING }

			any_demesne_title = {
				show_scope_change = no

				limit = {
					location = { is_capital = no }

					OR = {
						title = c_roma
						title = c_ravenna
						title = c_ferrara
						title = c_urbino
						title = c_spoleto
						title = c_orvieto
					}
				}

				grant_title = event_target:current_pope
			}
		}
		else = {
			set_defacto_liege = event_target:current_pope
			pf_liege_change_effect = yes
		}
	}
}


### EVENTS TO FORM THE HRE AFTER CAROLINGIAN EMPIRE'S END

# Asking the pope for blessing to form the HRE
letter_event = {
	id = Plus.1155
	desc = EVTDESC_Plus_1176

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1176 # Accept

		wealth = 100

		FROM = {
			character_event = {
				id = Plus.1157
				days = 30
			}
		}

		ai_chance = {
			factor = 75

			mult_modifier = {
				factor = 1.2
				opinion = {
					who = FROM
					value >= 20
				}
			}

			mult_modifier = {
				factor = 1.2
				opinion = {
					who = FROM
					value >= 40
				}
			}

			mult_modifier = {
				factor = 1.2
				opinion = {
					who = FROM
					value >= 60
				}
			}

			mult_modifier = {
				factor = 1.2
				opinion = {
					who = FROM
					value >= 80
				}
			}

			mult_modifier = {
				factor = 1.2
				opinion = {
					who = FROM
					value >= 100
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = zealous }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = crusader }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 400 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 600 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 800 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 1000 }
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1176 # Reject

		FROM = {
			letter_event = {
				id = Plus.1156
				days = 30
			}
		}

		opinion = {
			name = coronation_rejected
			who = FROM
			years = 2
		}

		ai_chance = {
			factor = 25

			trigger = {
				FROM = { ai = no }
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -100
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -80
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -60
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -40
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -20
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < 0
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = {
					OR = {
						trait = lunatic
						trait = possessed
					}
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = { is_kinslayer_trigger = yes }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = cynical }
			}
		}
	}
}

# The pope refuses the coronation
letter_event = {
	id = Plus.1156
	desc = EVTDESC_Plus_1178

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1178 # Maybe we should try again later

		FROM = { clr_character_flag = approached_for_coronation }
		prestige = -50

		opinion = {
			name = coronation_rejected
			who = FROM
			years = 2
		}
	}
}

# The pope agrees to the coronation -- the HRE is formed
character_event = {
	id = Plus.1157
	title = EVTNAME_Plus_1157
	desc = EVTDESC_Plus_1157
	picture = GFX_evt_holy_emperor

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { NOT = { has_global_flag = carolingian_empire_fallen } }
			set_global_flag = carolingian_empire_fallen
		}

		# Reset East Francia to Germany
		k_germany = {
			set_name = ""
			adjective = ""
		}

		# Rename West Francia if it hasn't been already
		if = {
			limit = { NOT = { has_global_flag = west_francia_renamed } }

			set_global_flag = west_francia_renamed

			k_france = {
				set_name = ""
				adjective = ""
			}
		}

		# Reset ERE to Byzantine Empire in case Charlemagne was never crowned
		e_byzantium = {
			set_name = ""
			adjective = ""
		}

		e_hre = {
			set_pentarch_title = b_roma
		}

		# Stem duchy setup
		k_austria = { # Austria
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_arch_austria
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_arch_austria
				}

				k_arch_austria = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_arch_austria
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_arch_austria
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_arch_austria
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_arch_austria
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_bavaria = { # Bavaria
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_bavaria
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_bavaria
				}

				k_grand_bavaria = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_bavaria
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_bavaria
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_bavaria
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_bavaria
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_franconia = { # Franconia
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_franconia
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_franconia
				}

				k_grand_franconia = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_franconia
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_franconia
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_franconia
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_franconia
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_luxembourg = { # Luxembourg
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_luxembourg
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_luxembourg
				}

				k_grand_luxembourg = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_luxembourg
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_luxembourg
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_luxembourg
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_luxembourg
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_saxony = { # Saxony
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_saxony
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_saxony
				}

				k_grand_saxony = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_saxony
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_saxony
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_saxony
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_saxony
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_swabia = { # Swabia
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_swabia
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_swabia
				}

				k_grand_swabia = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_swabia
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_swabia
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_swabia
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_swabia
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_tuscany = { # Tuscany
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_tuscany
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_tuscany
				}

				k_grand_tuscany = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_tuscany
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_tuscany
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_tuscany
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_tuscany
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_naples = { # Naples
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_naples
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_naples
				}

				k_grand_naples = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_naples
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_naples
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_naples
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_naples
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		k_sicily = { # Sicily
			if = {
				limit = {
					has_holder = yes

					holder_scope = {
						OR = {
							character = ROOT
							vassal_of = ROOT
						}
					}
				}

				de_jure_liege = e_hre
			}
			else_if = {
				limit = {
					trigger_if = {
						limit = { is_titular = no }

						# Fully control at least one de jure duchy
						any_direct_de_jure_vassal_title = {
							ROOT = { completely_controls = PREV }
						}
					}
				}

				activate_title = {
					title = k_grand_sicily
					status = yes
				}

				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_grand_sicily
				}

				k_grand_sicily = {
					copy_title_history = PREV
					de_jure_liege = e_hre
				}

				any_claimant = {
					if = {
						limit = { has_pressed_claim = PREV }
						add_pressed_claim = k_grand_sicily
					}
					else_if = {
						limit = { has_claim = PREV }
						add_claim = k_grand_sicily
					}
					else_if = {
						limit = { has_weak_pressed_claim = PREV }
						add_weak_pressed_claim = k_grand_sicily
					}
					else_if = {
						limit = { has_weak_claim = PREV }
						add_weak_claim = k_grand_sicily
					}

					remove_claim = PREV
				}

				activate_title = {
					title = THIS
					status = no
				}
			}
		}

		if = { # Brandenburg check
			limit = {
				completely_controls = d_brandenburg
				completely_controls = d_meissen
				completely_controls = d_lausitz
			}

			k_brandenburg = {
				activate_title = {
					title = THIS
					status = yes
				}

				d_brandenburg = { de_jure_liege = PREV }
				d_meissen = { de_jure_liege = PREV }
				d_lausitz = { de_jure_liege = PREV }
			}
		}

		if = { # Milan check
			limit = {
				completely_controls = d_milano
				completely_controls = d_modena
			}

			k_grand_milan = {
				activate_title = {
					title = THIS
					status = yes
				}

				d_milano = { de_jure_liege = PREV }
				d_modena = { de_jure_liege = PREV }
			}
		}

		# Deal with k_germany if it is inactive (does this ever happen?)
		if = {
			limit = { NOT = { is_title_active = k_germany } }

			activate_title = {
				title = k_germany
				status = yes
			}

			if = {
				limit = { k_germany = { is_titular = yes } }

				k_lotharingia = {
					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_france } }
						de_jure_liege = k_france
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_aquitaine } }

						if = {
							limit = { has_global_flag = west_francia_united }
							de_jure_liege = k_france
						}
						else = {
							de_jure_liege = k_aquitaine
						}
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_frisia } }
						de_jure_liege = k_frisia
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_bohemia } }
						de_jure_liege = k_bohemia
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_pomerania } }
						de_jure_liege = k_pomerania
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_burgundy } }
						de_jure_liege = k_burgundy
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_italy } }
						de_jure_liege = k_italy
					}

					any_direct_de_jure_vassal_title = {
						limit = { capital_scope = { region = custom_poland } }
						de_jure_liege = k_poland
					}
				}
			}

			# Put whatever portion of k_germany that the emperor has conquered into the kingdom so it can be distributed between stem duchies
			any_realm_province = {
				limit = {
					duchy = {
						capital_scope = { region = custom_germany }

						OR = {
							has_holder = no
							holder_scope = { same_realm = ROOT }
						}
					}

					held_under_PREV = yes
				}

				duchy = { de_jure_liege = k_germany }
			}
		}

		# Either way, distribute k_germany to the stem duchies
		k_germany = {
			any_direct_de_jure_vassal_title = {
				if = {
					limit = { # Austria
						OR = {
							title = d_carinthia
							title = d_osterreich
							title = d_styria
							title = d_salzburg
						}
					}

					if = {
						limit = { is_title_active = k_austria }
						log = "HRE Creation: [This.GetName] assigned to de jure Kingdom"
						de_jure_liege = k_austria
					}
					else_if = {
						limit = { is_title_active = k_arch_austria }
						log = "HRE Creation: [This.GetName] assigned to de jure Archduchy"
						de_jure_liege = k_arch_austria
					}
				}
				else_if = {
					limit = { # Bavaria
						OR = {
							title = d_tyrol
							title = d_bavaria
							title = d_nordgau
						}
					}

					if = {
						limit = { is_title_active = k_bavaria }
						log = "HRE Creation: [This.GetName] assigned to de jure Kingdom"
						de_jure_liege = k_bavaria
					}
					else_if = {
						limit = { is_title_active = k_grand_bavaria }
						log = "HRE Creation: [This.GetName] assigned to de jure Archduchy"
						de_jure_liege = k_grand_bavaria
					}
				}
				else_if = {
					limit = { # Franconia
						OR = {
							title = d_thuringia
							title = d_franconia
							title = d_hesse
							title = d_rhine
						}
					}

					if = {
						limit = { is_title_active = k_franconia }
						log = "HRE Creation: [This.GetName] assigned to de jure Kingdom"
						de_jure_liege = k_franconia
					}
					else_if = {
						limit = { is_title_active = k_grand_franconia }
						log = "HRE Creation: [This.GetName] assigned to de jure Archduchy"
						de_jure_liege = k_grand_franconia
					}
				}
				else_if = {
					limit = { # Saxony
						OR = {
							title = d_westphalia # d_westphalia
							title = d_saxony # d_eastphalia
							title = d_angria
							title = d_holstein # d_nordalbingia
						}
					}

					if = {
						limit = { is_title_active = k_saxony }
						log = "HRE Creation: [This.GetName] assigned to de jure Kingdom"
						de_jure_liege = k_saxony
					}
					else_if = {
						limit = { is_title_active = k_grand_saxony }
						log = "HRE Creation: [This.GetName] assigned to de jure Archduchy"
						de_jure_liege = k_grand_saxony
					}
				}
				else_if = {
					limit = { # Swabia
						OR = {
							title = d_swiss
							title = d_baden
							title = d_swabia
							title = d_raetia
							title = d_thurgau
							title = d_alsace
						}
					}

					if = {
						limit = { is_title_active = k_swabia }
						log = "HRE Creation: [This.GetName] assigned to de jure Kingdom"
						de_jure_liege = k_swabia
					}
					else_if = {
						limit = { is_title_active = k_grand_swabia }
						log = "HRE Creation: [This.GetName] assigned to de jure Archduchy"
						de_jure_liege = k_grand_swabia
					}
				}
			}

			# TODO: Add de jure if controlled?
			any_direct_de_jure_vassal_title = {
				if = {
					limit = { capital_scope = { region = custom_france } }
					de_jure_liege = k_france
				}
				else_if = {
					limit = { capital_scope = { region = custom_aquitaine } }

					if = {
						limit = { has_global_flag = west_francia_united }
						de_jure_liege = k_france
					}
					else = {
						de_jure_liege = k_aquitaine
					}
				}
				else_if = {
					limit = {
						OR = {
							capital_scope = { region = custom_lotharingia }
							title = d_brabant
						}
					}

					de_jure_liege = k_lotharingia
				}
				else_if = {
					limit = { capital_scope = { region = custom_frisia } }
					de_jure_liege = k_frisia
				}
				else_if = {
					limit = { capital_scope = { region = custom_bohemia } }
					de_jure_liege = k_bohemia
				}
				else_if = {
					limit = { capital_scope = { region = custom_pomerania } }
					de_jure_liege = k_pomerania
				}
				else_if = {
					limit = { capital_scope = { region = custom_burgundy } }
					de_jure_liege = k_burgundy
				}
				else_if = {
					limit = { capital_scope = { region = custom_italy } }
					de_jure_liege = k_italy
				}
				else_if = {
					limit = { capital_scope = { region = custom_poland } }
					de_jure_liege = k_poland
				}
			}

			# Change Germany claims to HRE claims
			any_claimant = {
				if = {
					limit = { has_pressed_claim = PREV }
					add_pressed_claim = e_hre
				}
				else_if = {
					limit = { has_claim = PREV }
					add_claim = e_hre
				}
				else_if = {
					limit = { has_weak_pressed_claim = PREV }
					add_weak_pressed_claim = e_hre
				}
				else_if = {
					limit = { has_weak_claim = PREV }
					add_weak_claim = e_hre
				}

				remove_claim = PREV
			}
		}

		# Send notifications
		any_independent_ruler = {
			if = {
				limit = {
					religion = ROOT
					holy_order = no
					mercenary = no

					capital_scope = {
						OR = {
							empire = { title = e_hre }

							kingdom = {
								OR = {
									title = k_austria
									title = k_bavaria
									title = k_franconia
									title = k_saxony
									title = k_swabia
									title = k_lotharingia
									title = k_italy
									title = k_frisia
									title = k_burgundy
									title = k_luxembourg
									title = k_tuscany
									title = k_naples
									title = k_sicily
								}
							}
						}
					}
				}

				# Send notification to potential HRE vassals
				narrative_event = {
					id = Plus.1159
					days = 10
				}
			}
			else = {
				# Send notification to everyone else
				narrative_event = {
					id = Plus.1158
					days = 10
				}
			}
		}

		# Byzantine Emperor will be very upset
		if = {
			limit = {
				e_byzantium = { has_holder = yes }

				NOR = {
					has_global_flag = schism_happened
					has_global_flag = schism_prevented
				}
			}

			change_variable = {
				which = global_schism_tracker
				value = 1
			}

			rightful_religious_head_scope = {
				e_byzantium = {
					holder_scope = {
						opinion = {
							name = opinion_unhappy
							who = ROOT
							years = 100
						}

						opinion = {
							name = opinion_unhappy
							who = PREVPREV # Pope
							years = 100
							multiplier = 2
						}

						rightful_religious_head_scope = { # Ecumenical Patriarch
							opinion = {
								name = opinion_unhappy
								who = ROOT
								years = 100
							}

							opinion = {
								name = opinion_unhappy
								who = PREVPREVPREV # Pope
								years = 100
								multiplier = 2
							}
						}
					}
				}
			}

			narrative_event = {
				id = PlusGreatSchism.071
				days = 14
			}
		}
	}

	option = {
		name = EVTOPTA_Plus_1181 # This is the happiest day of my life

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE
				picture = GFX_evt_coronation
			}
		}

		if = {
			limit = { trait = crowned }
			remove_trait = crowned
		}
		else_if = {
			limit = { trait = crowned_by_vip }
			remove_trait = crowned_by_vip
		}
		else_if = {
			limit = { trait = crowned_by_relhead }
			remove_trait = crowned_by_relhead
		}

		add_trait = crowned_by_pope
		give_nickname = nick_the_great
		prestige = 500

		opinion = {
			name = opinion_grateful
			who = FROM
			years = 100
		}

		# Give the HRE title and destroy other imperial titles
		# Copy primary title laws but make HRE have princely elective & no CA
		primary_title = {
			show_scope_change = no

			e_hre = {
				show_scope_change = no

				set_title_flag = non_manual_law_change # No prestige loss
				grant_title = ROOT
				copy_title_laws = PREV
				add_law_w_cooldown = crown_authority_0
				add_law = succ_hre_elective
				copy_prev_gender_law_effect = yes
				set_title_flag = do_not_destroy
				set_global_flag = hre_formed
				clr_title_flag = non_manual_law_change # No prestige loss
			}
		}

		any_demesne_title = {
			show_scope_change = no

			limit = {
				tier = EMPEROR
				NOT = { title = e_hre }
			}

			hidden_effect = {
				any_direct_de_jure_vassal_title = {
					de_jure_liege = e_hre
				}
			}

			destroy_landed_title = THIS
		}

		add_artifact = crown_hre

		# Deactivate k_germany (SHOULD also remove the title from current holder but who knows with this mess?)
		# We do this in main event code to ensure it occurs after HRE has been granted
		activate_title = {
			title = k_germany
			status = no
		}

		any_demesne_title = {
			show_scope_change = no

			limit = {
				real_tier = KING

				NOR = {
					title = k_arch_austria
					title = k_austria
					title = k_grand_bavaria
					title = k_bavaria
					title = k_grand_franconia
					title = k_franconia
					title = k_grand_saxony
					title = k_saxony
					title = k_grand_swabia
					title = k_swabia
					title = k_grand_luxembourg
					title = k_luxembourg
					title = k_grand_tuscany
					title = k_tuscany
					title = k_grand_naples
					title = k_naples
					title = k_grand_sicily
					title = k_sicily
				}
			}

			if = {
				limit = {
					is_titular = no
					de_jure_liege = e_placeholder
				}

				de_jure_liege = e_hre
			}

			destroy_landed_title = THIS
		}
	}
}

# Rulers not within the traditional HRE boundaries informed of the coronation
narrative_event = {
	id = Plus.1158
	title = EVTNAME_Plus_1157
	desc = EVTDESC_CM_510
	picture = GFX_evt_holy_emperor
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes

	option = {
		name = OK

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE_NEWS
				picture = GFX_evt_coronation
			}
		}
	}
}

# Rulers within the traditional HRE boundaries informed of the coronation
narrative_event = {
	id = Plus.1159
	title = EVTNAME_Plus_1157
	desc = EVTDESC_CM_510
	picture = GFX_evt_holy_emperor
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes

	only_rulers = yes

	option = {
		name = EVTOPTA_Plus_1159 # Offer to become his vassal

		trigger = {
			lower_tier_than = FROM
			in_revolt = no

			OR = {
				lower_real_tier_than = king
				has_landed_title = k_austria
				has_landed_title = k_bavaria
				has_landed_title = k_franconia
				has_landed_title = k_saxony
				has_landed_title = k_swabia
				has_landed_title = k_tuscany
				has_landed_title = k_luxembourg
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE_NEWS
				picture = GFX_evt_coronation
			}
		}

		FROM = {
			show_scope_change = no

			letter_event = {
				id = Plus.1160
				tooltip = offer_to_become_vassal
			}
		}

		ai_chance = {
			factor = 50

			trigger = {
				num_of_king_titles < 2
				controls_religion = no

				NOR = {
					rightful_religious_head = ROOT
					trait = excommunicated
				}
			}

			mult_modifier = {
				factor = 3

				capital_scope = {
					empire = { title = e_hre }
				}
			}

			mult_modifier = {
				factor = 0.5
				real_tier = KING
			}

			mult_modifier = {
				factor = 1.5
				real_tier = COUNT
			}

			mult_modifier = {
				factor = 1.5
				trait = zealous
			}

			mult_modifier = {
				factor = 1.5

				any_realm_province = {
					has_province_flag = contingent_territory
					held_under_PREV = yes

					any_neighbor_province = {
						owner = {
							OR = {
								character = FROM
								is_vassal_or_below_of = FROM
							}
						}
					}
				}
			}


			mult_modifier = {
				factor = 1.2
				opinion = { who = FROM value >= 25 }
			}

			mult_modifier = {
				factor = 1.2
				opinion = { who = FROM value >= 50 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value >= 75 }
			}

			mult_modifier = {
				factor = 1.2
				dynasty = FROM
			}

			mult_modifier = {
				factor = 0.1

				OR = {
					reverse_has_truce = FROM
					has_non_aggression_pact_with = FROM
				}
			}

			mult_modifier = {
				factor = 1.5

				OR = {
					is_friend = FROM
					is_allied_with = FROM
				}
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1159 # Wish him well

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_FOUNDED_HRE_NEWS
				picture = GFX_evt_coronation
			}
		}

		ai_chance = {
			factor = 50

			mult_modifier = {
				factor = 3
				real_tier = KING
			}

			mult_modifier = {
				factor = 3

				capital_scope = {
					NOT = { empire = { title = e_hre } }
				}
			}

			mult_modifier = {
				factor = 2

				NOT = {
					any_realm_province = {
						has_province_flag = contingent_territory
						held_under_PREV = yes

						any_neighbor_province = {
							owner = {
								OR = {
									character = FROM
									is_vassal_or_below_of = FROM
								}
							}
						}
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				NOT = { culture = FROM }

				NAND = { # German cultures are more accepting of each other
					FROM = { german_cultures_trigger = yes }
					german_cultures_trigger = yes
				}
			}

			mult_modifier = {
				factor = 1.5
				trait = cynical
			}

			mult_modifier = {
				factor = 1.5
				trait = ambitious
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < 0 }
			}

			mult_modifier = {
				factor = 1.5
				opinion = { who = FROM value < -25 }
			}

			mult_modifier = {
				factor = 2
				opinion = { who = FROM value < -50 }
			}

			mult_modifier = {
				factor = 2
				opinion = { who = FROM value < -75 }
			}

			mult_modifier = {
				factor = 0.5
				is_rival = FROM
			}

			mult_modifier = {
				factor = 2
				realm_size >= 50
			}

			mult_modifier = {
				factor = 3
				realm_size >= 75
			}
		}
	}
}

# The ruler offers to become the new emperor's vassal
letter_event = {
	id = Plus.1160
	desc = EVTDESC_Plus_1160

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1160 # Accept

		FROM = {
			show_scope_change = no

			set_defacto_liege = ROOT
			pf_liege_change_effect = yes

			any_demesne_title = {
				show_scope_change = no

				limit = {
					real_tier = KING
					NOT = { de_jure_liege = e_hre }
				}

				de_jure_liege = e_hre
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1160 # Refuse

		ai_chance = { factor = 0 }
	}
}


### MAINTENANCE EVENTS

# Ruler has a stem duchy title but is not part of the HRE
character_event = {
	id = Plus.1170
	desc = EVTDESC_Plus_1170
	picture = GFX_evt_council

	is_triggered_only = yes # on_yearly_pulse

	only_rulers = yes
	war = no

	trigger = {
		OR = {
			has_landed_title = k_grand_saxony
			has_landed_title = k_grand_swabia
			has_landed_title = k_grand_franconia
			has_landed_title = k_grand_bavaria
			has_landed_title = k_grand_luxembourg
			has_landed_title = k_grand_tuscany
			has_landed_title = k_arch_austria
			has_landed_title = k_grand_sicily
			has_landed_title = k_grand_naples
		}

		NOR = {
			top_liege = { has_landed_title = e_hre }
			top_liege = { liege_before_war = { has_landed_title = e_hre } }
			liege_before_war = { has_landed_title = e_hre }
		}
	}

	option = {
		name = EXCELLENT

		if = {
			limit = { has_landed_title = k_grand_saxony }

			hidden_effect = {
				activate_title = {
					title = k_saxony
					status = yes
				}
			}

			k_grand_saxony = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_saxony
				}
			}

			hidden_effect = {
				k_saxony = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_saxony
					copy_title_history = k_grand_saxony
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_saxony = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_saxony
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_saxony
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_saxony
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_saxony
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_saxony = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_saxony = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_swabia }

			hidden_effect = {
				activate_title = {
					title = k_swabia
					status = yes
				}
			}

			k_grand_swabia = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_swabia
				}
			}

			hidden_effect = {
				k_swabia = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_swabia
					copy_title_history = k_grand_swabia
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_swabia = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_swabia
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_swabia
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_swabia
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_swabia
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_swabia = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_swabia = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_franconia }

			hidden_effect = {
				activate_title = {
					title = k_franconia
					status = yes
				}
			}

			k_grand_franconia = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_franconia
				}
			}

			hidden_effect = {
				k_franconia = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_franconia
					copy_title_history = k_grand_franconia
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_franconia = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_franconia
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_franconia
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_franconia
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_franconia
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_franconia = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_franconia = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_bavaria }

			hidden_effect = {
				activate_title = {
					title = k_bavaria
					status = yes
				}
			}

			k_grand_bavaria = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_bavaria
				}
			}

			hidden_effect = {
				k_bavaria = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_bavaria
					copy_title_history = k_grand_bavaria
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_bavaria = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_bavaria
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_bavaria
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_bavaria
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_bavaria
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_bavaria = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_bavaria = {
					destroy_landed_title = THIS

					activate_title = {
						title = k_grand_bavaria
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_luxembourg }

			hidden_effect = {
				activate_title = {
					title = k_luxembourg
					status = yes
				}
			}

			k_grand_luxembourg = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_luxembourg
				}
			}

			hidden_effect = {
				k_luxembourg = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_luxembourg
					copy_title_history = k_grand_luxembourg
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_luxembourg = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_luxembourg
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_luxembourg
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_luxembourg
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_luxembourg
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_luxembourg = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_luxembourg = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_tuscany }

			hidden_effect = {
				activate_title = {
					title = k_tuscany
					status = yes
				}
			}

			k_grand_tuscany = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_tuscany
				}
			}

			hidden_effect = {
				k_tuscany = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_tuscany
					copy_title_history = k_grand_tuscany
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_tuscany = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_tuscany
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_tuscany
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_tuscany
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_tuscany
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_tuscany = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_tuscany = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_arch_austria }

			hidden_effect = {
				activate_title = {
					title = k_austria
					status = yes
				}
			}

			k_arch_austria = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_austria
				}
			}

			hidden_effect = {
				k_austria = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_arch_austria
					copy_title_history = k_arch_austria
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_arch_austria = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_austria
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_austria
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_austria
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_austria
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_austria = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_arch_austria = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_naples }

			hidden_effect = {
				activate_title = {
					title = k_naples
					status = yes
				}
			}

			k_grand_naples = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_naples
				}
			}

			hidden_effect = {
				k_naples = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_naples
					copy_title_history = k_grand_naples
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_naples = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_naples
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_naples
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_naples
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_naples
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_naples = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_naples = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_grand_sicily }

			hidden_effect = {
				activate_title = {
					title = k_sicily
					status = yes
				}
			}

			k_grand_sicily = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_sicily
				}
			}

			hidden_effect = {
				k_sicily = {
					set_title_flag = non_manual_law_change # No prestige loss
					grant_title = ROOT
					copy_title_laws = k_grand_sicily
					copy_title_history = k_grand_sicily
					clr_title_flag = non_manual_law_change # No prestige loss
				}

				k_grand_sicily = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_sicily
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_sicily
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_sicily
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_sicily
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}
				}

				k_sicily = {
					de_jure_liege = event_target:djliege_title
					clear_event_target = djliege_title
				}

				k_grand_sicily = {
					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}
	}
}

# Ruler has a kingdom version of a stem duchy title but is part of the HRE
character_event = {
	id = Plus.1171
	desc = EVTDESC_Plus_1171
	picture = GFX_evt_council

	is_triggered_only = yes

	only_rulers = yes
	war = no

	trigger = {
		OR = {
			has_landed_title = k_saxony
			has_landed_title = k_swabia
			has_landed_title = k_franconia
			has_landed_title = k_bavaria
			has_landed_title = k_luxembourg
			has_landed_title = k_tuscany
			has_landed_title = k_austria
			# don't switch bohemia, sicily, naples, milan and brandenburg!
		}

		top_liege = { has_landed_title = e_hre }
	}

	option = {
		name = OK

		if = {
			limit = { has_landed_title = k_saxony }

			k_saxony = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_saxony
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_saxony
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_saxony
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_saxony
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_saxony
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_saxony = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_saxony
						copy_title_history = k_saxony
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_swabia }

			k_swabia = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_swabia
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_swabia
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_swabia
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_swabia
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_swabia
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_swabia = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_swabia
						copy_title_history = k_swabia
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_franconia }

			k_franconia = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_franconia
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_franconia
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_franconia
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_franconia
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_franconia
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_franconia = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_franconia
						copy_title_history = k_franconia
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_bavaria }

			k_bavaria = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_bavaria
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_bavaria
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_bavaria
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_bavaria
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_bavaria
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_bavaria = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_bavaria
						copy_title_history = k_bavaria
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_luxembourg }

			k_luxembourg = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_luxembourg
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_luxembourg
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_luxembourg
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_luxembourg
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_luxembourg
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_luxembourg = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_luxembourg
						copy_title_history = k_luxembourg
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_tuscany }

			k_tuscany = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_grand_tuscany
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_grand_tuscany
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_grand_tuscany
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_grand_tuscany
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_grand_tuscany
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_grand_tuscany = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_tuscany
						copy_title_history = k_tuscany
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}

		if = {
			limit = { has_landed_title = k_austria }

			k_austria = {
				show_scope_change = no

				any_direct_de_jure_vassal_title = {
					show_scope_change = no

					de_jure_liege = k_arch_austria
				}

				hidden_effect = {
					any_claimant = {
						if = {
							limit = { has_pressed_claim = PREV }
							add_pressed_claim = k_arch_austria
						}
						else_if = {
							limit = { has_claim = PREV }
							add_claim = k_arch_austria
						}
						else_if = {
							limit = { has_weak_pressed_claim = PREV }
							add_weak_pressed_claim = k_arch_austria
						}
						else_if = {
							limit = { has_weak_claim = PREV }
							add_weak_claim = k_arch_austria
						}

						remove_claim = PREV
					}

					dejure_liege_title = {
						save_event_target_as = djliege_title
					}

					k_arch_austria = {
						activate_title = {
							title = THIS
							status = yes
						}

						set_title_flag = non_manual_law_change # No prestige loss
						grant_title = ROOT
						copy_title_laws = k_austria
						copy_title_history = k_austria
						de_jure_liege = event_target:djliege_title
						clear_event_target = djliege_title
						clr_title_flag = non_manual_law_change # No prestige loss
					}

					destroy_landed_title = THIS

					activate_title = {
						title = THIS
						status = no
					}
				}
			}
		}
	}
}

### HRE -- Coronation events witten by Van Diemen

# Coronation inform Emperor -- triggered by decision: coronation
character_event = {
	id = Plus.1175 # formerly Plus.525
	desc = EVTDESC_Plus_1175
	picture = GFX_evt_pope

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1175 # I will ask the pope

		rightful_religious_head_scope = {
			letter_event = { id = Plus.1176 }
		}
	}
}

# Asking the pope for coronation
letter_event = {
	id = Plus.1176 # formerly 1000182428
	desc = EVTDESC_Plus_1176

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1176 # Accept

		wealth = 100

		FROM = {
			letter_event = { id = Plus.1177 }
		}

		ai_chance = {
			factor = 50

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 20
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 40
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 60
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 80
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 100
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = zealous }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = crusader }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 400 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 600 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 800 }
			}

			mult_modifier = {
				factor = 1.2
				FROM = { piety >= 1000 }
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1176 # Reject

		ai_chance = {
			factor = 50

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value <= -100
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -80
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -60
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -40
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -20
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < 0
				}
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = lunatic }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { is_kinslayer_trigger = yes }
			}

			mult_modifier = {
				factor = 2.0
				FROM = { trait = cynical }
			}
		}

		FROM = {
			letter_event = { id = Plus.1178 }
		}

		opinion = {
			name = coronation_rejected
			who = FROM
			years = 10
		}
	}
}

# Inform emperor that the pope agrees to the coronation & send out the invites to realm lords
letter_event = {
	id = Plus.1177 # formerly 1000182429
	desc = EVTDESC_Plus_1177

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1177 # Excellent, now invite all the lords

		hidden_effect = {
			any_vassal = {
				limit = {
					is_playable = yes
					religion_group = christian
					is_heretic = no
					is_adult = yes
					is_incapable = no
					prisoner = no
					NOT = { trait = excommunicated }
				}

				letter_event = { id = Plus.1179 } # Invitation to coronation
			}

			character_event = { id = Plus.1290 days = 59 } # Regnal name
			character_event = { id = Plus.1181 days = 60 } # Coronation begins
		}
	}
}

# Inform emperor that the pope rejects coronation
letter_event = {
	id = Plus.1178 # formerly 1000182430
	desc = EVTDESC_Plus_1178

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1178 # Maybe we should try again later

		clr_character_flag = wants_coronation
		prestige = -50

		opinion = {
			name = coronation_rejected
			who = FROM
			years = 2
		}
	}
}

# Coronation invites to realm lords
letter_event = {
	id = Plus.1179 # formerly 1000182431
	desc = EVTDESC_Plus_1179

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1179 # I will attend the ceremony

		set_character_flag = attend_coronation

		ai_chance = {
			factor = 80

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 20
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value >= 40
				}
			}

			mult_modifier = {
				factor = 1.6

				opinion = {
					who = FROM
					value >= 60
				}
			}

			mult_modifier = {
				factor = 2.0

				opinion = {
					who = FROM
					value >= 80
				}
			}

			mult_modifier = {
				factor = 2.0

				opinion = {
					who = FROM
					value >= 100
				}
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1179 # I have more important things to do

		FROM = {
			letter_event = { id = Plus.1180 }
		}

		ai_chance = {
			factor = 20

			mult_modifier = {
				factor = 4.0

				has_opinion_modifier = {
					name = attempted_murder
					who = FROM
				}
			}

			mult_modifier = {
				factor = 2.0

				has_opinion_modifier = {
					name = attempted_murder_of_spouse
					who = FROM
				}
			}

			mult_modifier = {
				factor = 4.0

				has_opinion_modifier = {
					name = attempted_murder_of_child
					who = FROM
				}
			}

			mult_modifier = {
				factor = 1.5

				has_opinion_modifier = {
					name = attempted_murder_of_vassal
					who = FROM
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -20
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -40
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -60
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -80
				}
			}

			mult_modifier = {
				factor = 1.2

				opinion = {
					who = FROM
					value < -99
				}
			}
		}
	}
}

# Inform Emperor of NOT attending ceremony
letter_event = {
	id = Plus.1180 # formerly 1000182432
	desc = EVTDESC_Plus_1180

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1180 # I have no words for such dishonour

		opinion = {
			name = insulted
			who = FROM
			years = 5
		}
	}
}

# Emperor crowned by pope
character_event = {
	id = Plus.1181 # formerly 1000182433
	title = EVTNAME_Plus_1181
	desc = EVTDESC_Plus_1181
	picture = GFX_evt_holy_emperor

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1181 # This is the happiest day of my life

		add_trait = crowned_by_pope
		prestige = 500

		custom_tooltip = {
			text = IMPERIAL_DECADENCE_MINUS_2

			primary_title = {
				change_variable = {
					which = imperial_decadence
					value = -2
				}
			}

			character_event = { id = Plus.1852 } # Change the decadence modifier
		}

		pf_court_plus2_effect = yes
		pf_tradition_plus4_effect = yes

		hidden_effect = {
			rightful_religious_head_scope = {
				reverse_opinion = {
					name = opinion_grateful
					who = ROOT
					months = 60
				}
			}

			any_vassal = {
				if = {
					limit = { has_character_flag = attend_coronation }

					character_event = { id = Plus.1182 }

					opinion = {
						name= opinion_attended_ceremony
						who = ROOT
						years = 5
					}
				}
				else = {
					letter_event = { id = Plus.1183 }
				}
			}

			clr_character_flag = wants_coronation

			if = {
				limit = { has_landed_title = e_hre }
				narrative_event = { id = Plus.1184 }
			}
		}

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PAPAL_CORONATION
				portrait = [Root.GetID]
				picture = GFX_evt_holy_emperor
			}
		}
	}
}

# Emperor crowned by pope - attended realm lords informed of ceremony
character_event = {
	id = Plus.1182 # formerly 1000182434
	desc = EVTDESC_Plus_1182
	picture = GFX_evt_holy_emperor

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1182 # The coronation was beautiful

		prestige = 20
		clr_character_flag = attend_coronation

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PAPAL_CORONATION_NEWS
				portrait = [From.GetID]
				picture = GFX_evt_holy_emperor
			}
		}
	}
}

# Emperor crowned by pope - non-attending realm lords informed of ceremony
letter_event = {
	id = Plus.1183 # formerly 1000182435
	desc = EVTDESC_Plus_1183

	is_triggered_only = yes

	option = {
		name = OK

		if = {
			limit = { ai = no }

			chronicle = {
				entry = CHRONICLE_PAPAL_CORONATION_NEWS
				portrait = [From.GetID]
				picture = GFX_evt_holy_emperor
			}
		}
	}
}

# HRE Coronation narrative event
narrative_event = {
	id = Plus.1184 # formerly 1000182436
	title = EVTNAME_Plus_1184
	desc = EVTDESC_Plus_1184
	picture = GFX_evt_holy_emperor
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = OK
	}
}


### AQUITAINE ABSORBED INTO WEST FRANCIA
# TODO: Turn into decision?
narrative_event = {
	id = Plus.1185
	title = EVTNAME_Plus_1185
	desc = EVTDESC_Plus_1185
	picture = GFX_evt_holy_emperor

	is_triggered_only = yes
	major = yes

	only_independent = yes
	war = no

	trigger = {
		k_france = {
			holder = ROOT
			is_primary_holder_title = yes
		}

		k_aquitaine = {
			holder = ROOT
			is_titular = no
		}

		year >= 869

		NOR = {
			trait = content
			trait = humble
			trait = excommunicated
			has_global_flag = west_francia_united
			has_character_flag = is_charlemagne # Probably redundant with the year trigger but better safe than sorry
		}
	}

	major_trigger = {
		ai = no

		OR = {
			culture = occitan
			culture = french

			capital_scope = {
				empire = {
					OR = {
						title = e_karling
						title = e_hre
					}
				}
			}
		}
	}

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 0.1

			k_france = { has_law = succ_gavelkind }

			any_child = {
				is_female = no

				NOR = {
					is_primary_heir = ROOT
					trait = bastard
				}
			}
		}

		mult_modifier = {
			factor = 2
			trait = ambitious
		}

		mult_modifier = {
			factor = 2
			trait = proud
		}
	}

	immediate = {
		set_global_flag = west_francia_united

		k_aquitaine = {
			any_direct_de_jure_vassal_title = {
				de_jure_liege = k_france
			}

			destroy_landed_title = THIS

			any_claimant = {
				if = {
					limit = { has_pressed_claim = PREV }
					add_pressed_claim = k_france
				}
				else_if = {
					limit = { has_claim = PREV }
					add_claim = k_france
				}
				else_if = {
					limit = { has_weak_pressed_claim = PREV }
					add_weak_pressed_claim = k_france
				}
				else_if = {
					limit = { has_weak_claim = PREV }
					add_weak_claim = k_france
				}

				remove_claim = PREV
			}
		}
	}

	option = {
		name = {
			text = EXCELLENT
			trigger = { character = ROOT }
		}
		name = {
			text = OK
			trigger = { NOT = { character = ROOT } }
		}
	}
}


### TREATY OF MEERSSEN EVENTS

# The Carolongian Emperor inherits both Lotharingia and Burgundy
character_event = {
	id = Plus.1186
	desc = EVTDESC_Plus_1186
	picture = GFX_evt_council

	is_triggered_only = yes

	only_independent = yes

	trigger = {
		has_landed_title = e_karling
		has_landed_title = k_lotharingia
		has_landed_title = k_burgundy
		num_of_king_titles >= 3

		k_germany = {
			holder_scope = {
				vassal_of = ROOT
				NOT = { has_landed_title = k_france }

				OR = {
					dynasty = ROOT
					is_close_relative = ROOT
				}
			}
		}

		k_france = {
			holder_scope = {
				vassal_of = ROOT
				NOT = { has_landed_title = k_germany }

				OR = {
					dynasty = ROOT
					is_close_relative = ROOT
				}
			}
		}

		NOR = {
			has_character_flag = faction_court_war
			has_character_flag = faction_prosperity_war
			has_character_flag = faction_glory_war
			has_character_flag = faction_tradition_war
			has_character_flag = faction_separatist_war
			has_character_flag = faction_pretender_war
			has_character_flag = faction_religious_war
			has_character_flag = faction_succession_war
			has_global_flag = treaty_of_meerssen
		}
	}

	immediate = {
		set_global_flag = treaty_of_meerssen

		k_france = {
			holder_scope = {
				save_event_target_as = king_of_france
			}
		}

		k_germany = {
			holder_scope = {
				save_event_target_as = king_of_germany
			}
		}
	}

	option = {
		name = EVTOPTA_Plus_1186 # Agree to the treaty

		ai_chance = {
			factor = 80

			mult_modifier = {
				factor = 0.5

				any_vassal = {
					OR = {
						has_landed_title = k_germany
						has_landed_title = k_france
					}

					is_close_relative = ROOT
					prisoner = yes
				}
			}

			mult_modifier = {
				factor = 2
				trait = content
			}

			mult_modifier = {
				factor = 2
				trait = humble
			}
		}

		pf_court_plus4_effect = yes
		pf_glory_plus2_effect = yes

		# Ruler of West Francia receives Bar and Verdun
		any_demesne_title = {
			show_scope_change = no

			limit = {
				OR = {
					title = c_bar
					title = c_verdun
				}
			}

			grant_title = event_target:king_of_france
		}

		# Ruler of West Francia takes any vassals in Bar, Flanders, Brabant, Burgundy, or Dauphine
		custom_tooltip = {
			text = GAINS_WESTERN_MIDDLE_FRANCIA

			hidden_effect = {
				any_vassal = {
					limit = {
						lower_real_tier_than = KING
						in_revolt = no

						capital_scope = {
							duchy = {
								OR = {
									# title = d_bar
									title = d_flanders
									title = d_brabant
									title = d_burgundy
									title = d_dauphine
								}
							}
						}
					}

					set_defacto_liege = event_target:king_of_france
					pf_liege_change_effect = yes
				}
			}
		}

		# Ruler of East Francia takes any vassals in Frisia
		custom_tooltip = {
			text = GAINS_FRISIA

			hidden_effect = {
				any_vassal = {
					limit = {
						lower_real_tier_than = KING
						in_revolt = no

						capital_scope = {
							kingdom = { title = k_frisia }

							duchy = {
								NOR = {
									title = d_flanders
									title = d_brabant
								}
							}
						}
					}

					set_defacto_liege = event_target:king_of_germany
					pf_liege_change_effect = yes
				}
			}
		}

		# Hugh receives the Duchy of Alsace
		if = {
			limit = {
				c_90102 = {
					is_vassal_or_below_of = ROOT
					is_alive = yes
				}
			}

			c_90102 = {
				save_event_target_as = hugues
			}

			if = {
				limit = {
					d_alsace = {
						holder_scope = { is_vassal_or_below_of = ROOT }
					}
				}

				custom_tooltip = {
					text = GRANTED_DUCHY_ALSACE

					d_alsace = {
						usurp_title = c_90102

						any_claimant = {
							limit = { higher_real_tier_than = DUKE }
							remove_claim = d_alsace
						}
					}
				}
			}
			else_if = {
				limit = {
					d_alsace = { has_holder = no }

					c_nordgau = {
						holder_scope = { is_vassal_or_below_of = ROOT }
					}
				}

				custom_tooltip = {
					text = GRANTED_DUCHY_ALSACE

					hidden_effect = {
						c_nordgau = {
							usurp_title = c_90102

							any_claimant = {
								limit = { higher_real_tier_than = DUKE }
								remove_claim = c_nordgau
							}
						}

						d_alsace = {
							gain_title = ROOT
							grant_title = c_90102

							any_claimant = {
								limit = { higher_real_tier_than = DUKE }
								remove_claim = d_alsace
							}
						}

						if = {
							limit = {
								c_sundgau = {
									holder_scope = { is_vassal_or_below_of = ROOT }
								}
							}

							c_sundgau = {
								holder_scope = {
									set_defacto_liege = c_90102
									pf_liege_change_effect = yes
								}
							}
						}

						hidden_effect = {
							set_defacto_liege = ROOT
							pf_liege_change_effect = yes
						}
					}
				}
			}
		}

		# If East Francia has a duke son, they take both kingdom titles
		if = {
			limit = {
				event_target:king_of_germany = {
					any_child = {
						lower_real_tier_than = KING
						is_female = no
						is_vassal_or_below_of = PREV
						prisoner = no
						NOT = { is_primary_heir = PREV }
					}
				}
			}

			event_target:king_of_germany = {
				show_scope_change = no

				random_child = {
					show_scope_change = no

					limit = {
						lower_real_tier_than = KING
						is_female = no
						is_vassal_or_below_of = PREV
						prisoner = no
						NOT = { is_primary_heir = PREV }
					}

					if = {
						limit = { c_lorraine = { holder = ROOT } }
						grant_title = c_lorraine
					}

					grant_title = k_lotharingia
					grant_title = k_burgundy

					hidden_effect = {
						ROOT = {
							any_vassal = {
								limit = {
									lower_real_tier_than = KING
									in_revolt = no

									capital_scope = {
										OR = {
											duchy = { title = d_transjurania }
											kingdom = { title = k_lotharingia }
										}
									}
								}

								set_defacto_liege = PREVPREV
								pf_liege_change_effect = yes
							}
						}
					}

					hidden_effect = {
						k_lotharingia = {
							set_title_flag = non_manual_law_change # No prestige loss
							make_primary_title = yes
							add_law = succ_gavelkind
							clr_title_flag = non_manual_law_change # No prestige loss
						}
					}
				}
			}
		}

		# If East Francia has no proper son, they split the kingdom titles
		else = {
			event_target:king_of_germany = {
				show_scope_change = no

				if = {
					limit = { c_lorraine = { holder = ROOT } }
					grant_title = c_lorraine
				}

				grant_title = k_lotharingia
			}

			event_target:king_of_france = {
				show_scope_change = no

				grant_title = k_burgundy
			}
		}

		# Notify the rulers
		hidden_effect = {
			any_vassal = {
				limit = {
					OR = {
						has_landed_title = k_france
						has_landed_title = k_germany
						has_landed_title = k_lotharingia
					}
				}

				character_event = { id = Plus.1187 }
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1186 # No, the inheritance is rightfully mine

		pf_court_minus4_effect = yes

		any_vassal = {
			show_scope_change = no

			limit = {
				OR = {
					has_landed_title = k_france
					has_landed_title = k_germany
				}
			}

			character_event = {
				id = Plus.1188
				tooltip = they_are_enraged
			}
		}

		hidden_effect = {
			c_90102 = {
				if = {
					limit = {
						is_alive = yes
						is_ruler = no
						ai = yes
					}

					if = {
						limit = { d_alsace = { has_holder = yes } }
						add_pressed_claim = d_alsace
					}

					add_pressed_claim = k_lotharingia
					add_trait = ambitious
					set_character_flag = flag_denied_title
				}
			}
		}

		ai_chance = {
			factor = 20

			mult_modifier = {
				factor = 0.5
				war = yes
			}

			mult_modifier = {
				factor = 2
				trait = ambitious
			}

			mult_modifier = {
				factor = 2
				trait = proud
			}
		}
	}
}

# Rulers informed of the Treaty of Meerssen
character_event = {
	id = Plus.1187
	title = EVTNAME_Plus_1187
	desc = EVTDESC_Plus_1187
	picture = GFX_evt_council

	is_triggered_only = yes

	option = {
		name = EXCELLENT
		prestige = 100

		opinion = {
			name = opinion_pleased
			who = FROM
			years = 5
			multiplier = 2
		}
	}
}

# Rulers informed that the emperor has refused the treaty
character_event = {
	id = Plus.1188
	desc = EVTDESC_Plus_1188
	picture = GFX_evt_council

	is_triggered_only = yes

	option = {
		name = EVTOPTA_Plus_1188 # This is not worth fighting over

		prestige = -100

		any_claim = {
			show_scope_change = no

			limit = {
				OR = {
					title = k_lotharingia
					title = k_burgundy
				}
			}

			remove_claim = ROOT
		}

		ai_chance = {
			factor = 25

			mult_modifier = {
				factor = 2
				war = yes
			}

			mult_modifier = {
				factor = 2
				trait = content
			}

			mult_modifier = {
				factor = 2
				trait = humble
			}
		}
	}

	option = {
		name = EVTOPTB_Plus_1188 # This cannot be allowed to stand!

		ai_chance = {
			factor = 75

			mult_modifier = {
				factor = 2
				trait = ambitious
			}

			mult_modifier = {
				factor = 2
				trait = proud
			}
		}

		opinion = {
			name = opinion_outraged
			who = FROM
			years = 5
		}

		add_pressed_claim = k_lotharingia
		add_pressed_claim = k_burgundy
	}
}