####################################################
# Sacrum Imperium Romanum events
# By Sergei Ivanov
####################################################
namespace = SIR

character_event = {
    id = SIR.1
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		offmap_hre = {
			check_variable = { which = imperial_authority value >= 30 }
			check_variable = { which = imperial_authority value < 35 }
		}
    }

	immediate = {
		offmap_hre = {
			set_variable = { which = imperial_authority value = 100 }
		}
	}
}

# on_death
character_event = {
    id = SIR.10
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		is_member_of_hre = yes
    }

	immediate = {
		any_demesne_title = {
			set_title_flag = temporarily_obligation
		}
		offmap_hre = {
			governor = {
				ROOT = {
					set_defacto_liege = PREV
				}
			}
		}
	}
}

character_event = {
    id = SIR.11
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		offmap_hre = {
			has_status = hre_shattered
			governor = { character = ROOT }
		}
    }

	immediate = {
		any_demesne_title = {
			limit = {
				NOT = {
					tier = EMPEROR
					#title = e_hre
				}
			}
			set_title_flag = temporarily_obligation
		}		
	}
}

# on_new_holder_inheritance
character_event = {
    id = SIR.20
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		offmap_hre = {
			has_status = hre_shattered
		}
		FROM = {
			has_title_flag = temporarily_obligation
		}
    }

	immediate = {
		if = { # inherit titles is not a primary_title, nothing happen
			limit = {
				primary_title = {
					FROM = {
						tier = PREV
						NOT = { title = PREV }
					}
				}
			}
		}
		else_if = { # inherit titles is a primary_title and becomes direct vassal of emperor
			limit = {
				primary_title = {
					title = FROM
				}
				liege = {
					is_offmap_governor = offmap_hre
				}
			}
			top_liege = {
				ROOT = {
					set_defacto_liege = THIS
					offmap_hre_tributaries_join_effect = yes
				}
			}
		}
		else = { # inherited titles is a primary_title but not direct vassal of emperor
		}
		FROM = {
			clr_title_flag = temporarily_obligation
		}
	}
}

# on_new_holder_inheritance
character_event = {
    id = SIR.21
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		offmap_hre = {
			has_status = hre_shattered
			governor = {
				ROOT = {
					liege = { character = PREVPREV }
					primary_title = {
						OR = {
							tier = KING
							dejure_liege_title = {
								NOR = { 
									has_holder = yes
									holder_scope = {
										character = PREVPREVPREVPREV
									}
								}
							}
						}						
					}
				}
			}
		}
		FROM = { # for not death scenario only. e.g abdication
			NOT = { has_title_flag = temporarily_obligation }
		}
    }

	immediate = {
		log = "----------------"
		log = "[Root.GetBestName] ([From.GetName]) is now a direct vassal of HRE"
		log = "Exception handled"
		log = "----------------"
		set_defacto_liege = THIS
		offmap_hre_tributaries_join_effect = yes
	}
}

# ROOT is the character, FROM is the title, FROMFROM is the old holder
# on_new_holder_usurpation, transfer all hre tributaries to new holder
character_event = {
    id = SIR.30
    hide_window = yes

    is_triggered_only = yes

    trigger = {
		offmap_hre = {
			has_status = hre_shattered
		}
		FROM = {
			title = e_hre
		}
	}
	
	immediate = {
		FROMFROM = {
			any_tributary = {
				limit = {
					is_tributary = {
						type = hre_prince_0
						suzerain = PREV
					}
				}			
				remove_tributary = PREV
				ROOT = {
					make_tributary = { who = PREV tributary_type = hre_prince_0 }
				}
			}
			any_tributary = {
				limit = {
					is_tributary = {
						type = hre_prince_1
						suzerain = PREV
					}
				}			
				remove_tributary = PREV
				ROOT = {
					make_tributary = { who = PREV tributary_type = hre_prince_1 }
				}
			}
			any_tributary = {
				limit = {
					is_tributary = {
						type = hre_free_imp_city
						suzerain = PREV
					}
				}			
				remove_tributary = PREV
				ROOT = {
					make_tributary = { who = PREV tributary_type = hre_free_imp_city }
				}
			}
			
			# set_defacto_liege = THIS # Not working here
			offmap_hre_tributaries_join_effect = yes
			offmap_hre_ruler_name_sync_effect = yes
		}
	}
}

# An offmap power changes its governor. Triggers for the new governor
# Root = New governor/ruler
# From = Old governor/ruler
# FromFrom = Offmap
# on_offmap_governor_changed
character_event = {
	id = SIR.40
	
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
		FROMFROM = {
			is_offmap_tag = offmap_hre
			has_status = hre_shattered
		}
	}
	
	immediate = {
		# Exception handler
		# In case of tributaries going with other titles
		any_playable_ruler = {
			limit = {
				suzerain = {
					NOT = { is_offmap_governor = offmap_hre }
					PREV = {
						OR = {
							is_tributary = { type = hre_prince_0 suzerain = THIS }
							is_tributary = { type = hre_prince_1 suzerain = THIS }
							is_tributary = { type = hre_free_imp_city suzerain = THIS }
						}
					}
				}
			}
			suzerain = {
				remove_tributary = PREV
			}
			offmap_hre_tributaries_join_effect = yes
		}
	}
	
	after = {
		print_hre_government_update_effect = yes
		offmap_hre_government_de_facto_maintain_effect = yes
		offmap_hre_ruler_name_sync_effect = yes
	}
}

# Interregnum Check
character_event = {
	id = SIR.41

	is_triggered_only = yes
	
	hide_window = yes
 
	trigger = {
		is_offmap_governor = offmap_hre
		FROMFROM = {
			NOT = { has_status = hre_shattered }
			NOT = { has_offmap_flag = hre_interregum_happened }
		}
		NOR = {
			num_of_count_titles = 3
			dynastic_prestige = 300
		}
		FROM = {
			NOR = {
				num_of_count_titles = 3
				dynastic_prestige = 300
				trigger_if = {
					limit = { religion = catholic }
					OR = {
						trait = crowned_by_myself
						trait = crowned_by_pope
						trait = crowned_by_bishop
						trait = crowned_by_priest
					}
				}
			}			
		}
		OR = {
			AND = {
				start_date < 1066.9.15
				total_years_played = 300
			}
			AND = {
				start_date >= 1066.9.15
				year = 1200
			}
		}
	}
    
	immediate = {
		FROMFROM = {
			set_offmap_flag = hre_interregum_happened
		}
	}
}

# An offmap power changes its ruler. Triggers for the new ruler
# Root = New ruler
# From = Old ruler
# FromFrom = Offmap
# on_offmap_ruler_changed
character_event = {
	id = SIR.50
	
	hide_window = yes
	offmap = only
	
	is_triggered_only = yes

	trigger = { is_offmap_tag = offmap_hre }
    
	immediate = {
		print_hre_ruler_update_effect = yes
		offmap_hre_ruler_name_sync_effect = yes
	}
}

# The HRE title being contested
character_event = {
	id = SIR.60

	is_triggered_only = yes
	
	hide_window = yes
 
	trigger = {
		always = no # Disabled Intentionally
		offmap_hre = {
			NOT = { has_status = hre_shattered }
		}
		FROM = {
			any_war = {
				war_title = e_hre
			}
		}
	}
    
	immediate = {
		offmap_hre = {
			set_offmap_flag = hre_title_contested
		}
	}
}

# Emperor is Dead - Ping
# In case of on_new_holder_inheritance fires before character switch - Player can't see this
character_event = {
	id = SIR.110
	
	is_triggered_only = yes
	
	hide_window = yes
	
	trigger = {
		offmap_power = {
			has_status = hre_shattered
			NOT = { has_offmap_flag = proclaim_erbkaisertum }
		}
		FROM = { title = e_hre }
		FROMFROM = {
			is_dying = yes
			dynasty = ROOT
		}
		was_conceived_a_bastard = no
	}
    
	immediate = {
		narrative_event = { id = SIR.120 days = 1 }
	}
}

# Emperor is Dead - Actual
narrative_event = {
	id = SIR.120
	title = EVTNAME_SIR_120
	desc = EVTDESC_SIR_120
	picture = "GFX_evt_died_funeral"
	border = "GFX_event_narrative_frame_diplomacy"
	show_from_from_from = yes

	major = yes
	is_triggered_only = yes
	only_playable = yes
	
	trigger = {
	}
    
	immediate = {
		#offmap_power = {
		offmap_hre = {
			change_variable = { which = imperial_authority which = 10 }
			imperial_authority_bounds_checking_effect = yes
			if = {
				limit = {
					check_variable = { which = imperial_authority value > 100 }
				}
				set_variable = { which = imperial_authority value = 100 }
			}
			else_if = {
				limit = {
					check_variable = { which = imperial_authority value < 0 }
				}
				set_variable = { which = imperial_authority value = 0 }
			}
		}
	}
	
	option = {
		name = EXCELLENT
	}
}

# The Shadow Kingdom events
# Root = Governor
# From = Offmap

# The Kingdom of Italy
narrative_event = {
	id = SIR.210
	title = EVTNAME_SIR_210
	desc = EVTDESC_SIR_210
	picture = "GFX_evt_magnificent_castle"
	border = "GFX_event_narrative_frame_diplomacy"
	
	major = yes
	hide_from = yes
	is_triggered_only = yes
	only_playable = yes
	
	trigger = {
		is_offmap_governor = offmap_hre
		any_province = {
			duchy = {
				OR = {
					title = d_verona
					title = d_susa
					title = d_lombardia
					title = d_genoa
					title = d_modena
					title = d_toscana
					title = d_pisa
				}
			}
			empire = {
				NOT = {
					title = e_hre
				}
			}
			holder_scope = {
				top_liege = {
					NOR = {
						character = ROOT
						is_member_of_hre = yes
					}
				}
			}
		}
		FROM = {
			is_offmap_tag = offmap_hre
			has_status = hre_shattered
			NOT = { has_offmap_flag = hre_shadow_kingdom }
		}
	}
	
	major_trigger = {
		is_member_of_hre = yes
	}
    
	immediate = {
		FROM = {
			set_offmap_flag = hre_shadow_kingdom
		}
	}
	
	option = {
		name = EVTOPTA_SIR_210 # A grave matter.
	}
}

narrative_event = {
	id = SIR.220
	title = EVTNAME_SIR_220
	desc = EVTDESC_SIR_220
	picture = "GFX_evt_magnificent_castle"
	border = "GFX_event_narrative_frame_diplomacy"

	major = yes
	hide_from = yes
	is_triggered_only = yes
	only_playable = yes
	
	trigger = {
		is_offmap_governor = offmap_hre
		any_province = {
			duchy = {
				OR = {
					title = d_verona
					title = d_susa
					title = d_lombardia
					title = d_genoa
					title = d_modena
					title = d_toscana
					title = d_pisa
				}
			}
			empire = { # yet assimilated
				NOT = {
					title = e_hre
				}
			}
			holder_scope = {
				top_liege = {
					NOR = {
						character = ROOT
						is_member_of_hre = yes
					}
				}
			}
		}
		FROM = {
			is_offmap_tag = offmap_hre
			has_status = hre_shattered
			had_flag = {
				flag = hre_shadow_kingdom days = 10950
			}
			NOR = {
				has_offmap_flag = hre_italians_leave
				has_offmap_flag = hre_holy_empire
			}
		}
	}
	
	major_trigger = {
		is_member_of_hre = yes
		capital_scope = {
			duchy = {
				OR = {
					title = d_verona
					title = d_susa
					title = d_lombardia
					title = d_genoa
					title = d_modena
					title = d_toscana
					title = d_pisa
				}
			}
			empire = {
				NOT = {
					title = e_hre
				}
			}
		}
	}
    
	immediate = {
		FROM = {
			set_offmap_flag = hre_italians_leave
		}
	}
	
	option = {
		name = EVTOPTA_SIR_220 # The Empire does not concern us.
		trigger = {
			capital_scope = {
				duchy = {
					OR = {
						title = d_verona
						title = d_susa
						title = d_lombardia
						title = d_genoa
						title = d_modena
						title = d_toscana
						title = d_pisa
					}
				}
				empire = {
					NOT = {
						title = e_hre
					}
				}
			}
			OR = {
				opinion = {
					who = ROOT
					value <= 50
				}
				is_foe = ROOT
			}
		}
		# effect: leave hre immediately
		remove_tributary = ROOT
		ai_chance = {
			factor = 10 
			modifier = {
				factor = 10
				is_foe = ROOT
			}
			modifier = {
				factor = 10
				real_tier = KING
			}
			modifier = {
				factor = 1.5
				opinion = {
					who = ROOT
					value <= -30
				}
			}
			modifier = {
				factor = 1.5
				opinion = {
					who = ROOT
					value <= -10
				}
			}
			modifier = {
				factor = 1.5
				opinion = {
					who = ROOT
					value <= 10
				}
			}
			modifier = {
				factor = 0.5
				opinion = {
					who = ROOT
					value >= 30
				}
			}
		}
	}
	
	option = {
		name = EVTOPTB_SIR_220 # Our country is a natural part of the Empire.
		trigger = {
			capital_scope = {
				duchy = {
					OR = {
						title = d_verona
						title = d_susa
						title = d_lombardia
						title = d_genoa
						title = d_modena
						title = d_toscana
						title = d_pisa
					}
				}
				empire = {
					NOT = {
						title = e_hre
					}
				}
			}
		}
		capital_scope = {
			add_province_modifier = {
				name = peasant_unrest
				duration = 730
				stacking = yes
			}
		}
		ai_chance = {
			factor = 10
		}
	}
	
	option = {
		name = EVTOPTC_SIR_220
		trigger = {
			character = ROOT
		}
	}
}

# on_decade_pulse
# The Pope and the Emperor
narrative_event = {
	id = SIR.230
	title = EVTNAME_SIR_230
	desc = EVTDESC_SIR_230
	picture = "GFX_evt_cathedral"
	border = "GFX_event_narrative_frame_diplomacy"
	
	only_playable = yes
	religion = catholic
	is_triggered_only = yes
	
	trigger = {
		always = no # Intentionally disabled
		controls_religion = yes # Let it happen for the Pope. He's always around.
		NOR = {
			realm_size = 10
			is_member_of_hre = yes
		}
		is_tributary = no
		independent = yes
		
		any_province = {
			duchy = {
				OR = {
					title = d_verona
					title = d_susa
					title = d_lombardia
					title = d_genoa
					title = d_modena
					title = d_toscana
					title = d_pisa
				}
			}
			holder_scope = {
				top_liege = {
					OR = {
						character = ROOT
						is_member_of_hre = yes
					}
				}
			}
		}
		offmap_hre = {
			has_status = hre_shattered
			has_offmap_flag = hre_shadow_kingdom
			NOT = { has_offmap_flag = hre_italians_leave }
		}
	}
	
	immediate = {
		offmap_hre = {
			set_offmap_flag = hre_holy_empire
		}
	}
	
	option = {
		name = EVTOPTA_SIR_230 # We will join the Empire.
		# hre_ask_join_interaction_effect = yes
		# offmap_hre = { governor = { narrative_event = { id = SIR.240 } }
	}
	
	option = {
		name = EVTOPTB_SIR_230
		prestige = 5
	}
}

# on_offmap_monthly_pulse
# Happens once a month on a random day. Triggers for the governor
# Root = Governor
# From = Offmap
character_event = {
	id = SIR.510

	is_triggered_only = yes
	
	hide_window = yes
 
	trigger = {
		FROM = {
			is_offmap_tag = offmap_hre
			has_status = hre_shattered
		}
	}
    
	immediate = {
		# Do IA math work here, CPU heavy maybe?
		FROM = { set_variable = { which = imperial_authority_monthly value = 0 } }
		# every Free City in the Empire.
		any_tributary = {
			limit = {
				is_tributary = {
					type = hre_free_imp_city
					suzerain = ROOT
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.005 } }
		}
		# every Prince over 25 in the Empire.
		any_tributary = {
			limit = {
				is_member_of_hre = yes
				NOT = {
					is_tributary = {
						type = hre_free_imp_city
						suzerain = ROOT
					}
				}
				age = 25
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.003 } }
		}
		# every Prince below 25 in the Empire.
		any_tributary = {
			limit = {
				is_member_of_hre = yes
				NOT = {
					is_tributary = {
						type = hre_free_imp_city
						suzerain = ROOT
					}
				}
				NOT = { age = 25 }
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = -0.003 } }
		}
		# every heretic or heathen prince in the Empire.
		any_tributary = {
			limit = {
				is_member_of_hre = yes
				NOT = { religion = ROOT }
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = -0.01 } }
		}
		# every province owned by a ruler not in the Empire
		any_province = {
			limit = {
				empire = {
					title = e_hre
				}
				holder_scope = {
					top_liege = {
						NOR = {
							character = ROOT
							is_member_of_hre = yes
						}
					}
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = -0.005 } }
		}
		# emperor crowned
		if = {
			limit = {
				OR = {
					trait = crowned_by_myself
					trait = crowned_by_pope
					trait = crowned_by_bishop
					trait = crowned_by_priest
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.1 } }
		}
		# Reforms
		# Call Reichsreform
		if = {
			limit = {
				FROM = {
					has_offmap_flag = call_for_reichsreform
					check_variable = { which = imperial_authority value <= 30 }
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.5 } }
		}
		# Institute Reichsregiment/Gemeiner Pfennig
		if = {
			limit = {
				FROM = {
					OR = {
						has_offmap_flag = institute_reichsregiment
						has_offmap_flag = gemeiner_pfennig
					}
					check_variable = { which = imperial_authority value <= 45 }
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.5 } }
		}
		# Ewiger Landfriede/Perpetual Diet
		if = {
			limit = {
				FROM = {
					OR = {
						has_offmap_flag = ewiger_landfriede
						has_offmap_flag = establish_the_reichstag_collegia
					}
					check_variable = { which = imperial_authority value <= 60 }
				}
			}
			FROM = { change_variable = { which = imperial_authority_monthly value = 0.5 } }
		}
		# Proclaim Erbkaisertum
		if = {
			limit = {
				FROM = {
					has_offmap_flag = proclaim_erbkaisertum
					check_variable = { which = imperial_authority_monthly value >= 0 }
				}
			}
			FROM = { multiply_variable = { which = imperial_authority_monthly value = 1.25 } }
		}
		else_if = {
			limit = {
				FROM = {
					has_offmap_flag = proclaim_erbkaisertum
					check_variable = { which = imperial_authority_monthly value <= 0 }
				}
			}
			FROM = { multiply_variable = { which = imperial_authority_monthly value = 0.75 } }
		}
		# Privilegia Revoked
		if = {
			limit = {
				FROM = {
					has_offmap_flag = privilegia_revoked
					check_variable = { which = imperial_authority_monthly value >= 0 }
				}
			}
			FROM = { multiply_variable = { which = imperial_authority_monthly value = 1.25 } }
		}
		else_if = {
			limit = {
				FROM = {
					has_offmap_flag = privilegia_revoked
					check_variable = { which = imperial_authority_monthly value <= 0 }
				}
			}
			FROM = { multiply_variable = { which = imperial_authority_monthly value = 0.75 } }
		}
		# AI cheats
		if = {
			limit = {
				ai = yes
				FROM = {
					check_variable = { which = imperial_authority_monthly value <= 0 }
				}
			}
			FROM = { multiply_variable = { which = imperial_authority_monthly value = 0.75 } }
		}
		
		FROM = {
			change_variable = { which = imperial_authority which = imperial_authority_monthly }
			imperial_authority_bounds_checking_effect = yes
		}		
	}
}

# Emperor is an infidel
character_event = {
	id = SIR.520
	desc = EVTDESC_SIR_520
	picture = GFX_evt_heretic
	border = GFX_event_normal_frame_diplomacy
	portrait = event_target:hre_faithful_prince

	is_triggered_only = yes

	trigger = {
		always = no # Intentionally disabled
		FROM = {
			is_offmap_tag = offmap_hre
		}
		NOR = {
			religion = catholic
			religion = fraticelli
		}
		any_tributary = {
			is_member_of_hre = yes
			OR = {
				religion = catholic
				religion = fraticelli
			}
		}
	}
    
	immediate = {
		random_tributary = {
			limit = {
				is_member_of_hre = yes
				OR = {
					religion = catholic
					religion = fraticelli
				}
			}
			save_event_target_as = hre_faithful_prince
		}
	}
	
	option = {
		name = EVTOPTA_SIR_520 # Of course I will convert.;Bien sr que je vais me convertir.;Natrlich konvertiere ich.;;Por supuesto que me convertir.;;;;;;;;;x
		religion = event_target:hre_faithful_prince
	}
	
	option = {
		name = EVTOPTB_SIR_520 # Force election e_hre only
		hidden_tooltip = {
			hre_hold_election_effect = yes
			set_defacto_liege = THIS
		}
		custom_tooltip = { text = EVTOPTC_SIR_520_TT }
	}
}

# on_offmap_monthly_pulse
character_event = {
	id = SIR.620
	hide_window = yes
	is_triggered_only = yes
	trigger = {
		FROM = {
			is_offmap_tag = offmap_hre
		}
		NOT = { demesne_size = 1 }
	}
	
	immediate = {
		narrative_event = { id = SIR.630 }
	}
}

narrative_event = {
	id = SIR.630
	title = EVTNAME_SIR_630
	desc = EVTDESC_SIR_630
	picture = "GFX_evt_end_of_days"
	border = "GFX_event_narrative_frame_diplomacy"	
	
	major = yes
	only_playable = yes
	is_triggered_only = yes
	
	trigger = {}
	
	major_trigger = {
		capital_scope = {
			OR = {
				region = world_europe
				region = world_asia_minor
				region = world_africa_north
			}
		}
	}
	
	immediate = {
		set_global_flag = hre_removed
		any_tributary = {
			limit = { is_member_of_hre = yes }
			remove_tributary = ROOT
		}
		any_artifact = {
			limit = { artifact_type = crown_hre }
			unsafe_destroy_artifact = yes
		}
		if = {
			limit = {
				has_nickname = no
			}
			give_nickname = nick_the_messy
		}
		offmap_hre = {
			set_offmap_flag = hre_dismantled
		}
		e_hre = {
			# resetup e_italia e_francia e_germania e_britannia e_hispania
			any_direct_de_jure_vassal_title = { # k_
				capital_scope = { # default capital, there shall be one or it's a bad setup
					trigger_switch = {
						on_trigger = region
						
						world_europe_west_brittania = {
							PREV = { de_jure_liege = e_britannia }
						}
						world_europe_west_germania = {
							PREV = { de_jure_liege = e_germany }
						}
						world_europe_west_francia = {
							PREV = { de_jure_liege = e_france }
						}
						world_europe_west_iberia = {
							PREV = { de_jure_liege = e_spain }
						}
						world_europe_north = {
							PREV = { de_jure_liege = e_scandinavia }
						}
						world_europe_south_italy = {
							PREV = { de_jure_liege = e_italy }
						}
						world_europe_east = {
							PREV = { de_jure_liege = e_wendish_empire }
						}
						world_africa_north = {
							PREV = { de_jure_liege = e_maghreb }
						}
						fallback = { # world_europe_south_east, world_middle_east_jerusalemand so on
							PREV = { de_jure_liege = e_roman_empire }
						}
					}
				}
			}
			if = {
				limit = {
					e_britannia = {
						is_titular = no
					}
				}					
				activate_title = {
					title = e_britannia
					status = yes
				}
			}
			if = {
				limit = {
					e_germany = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_germany
					status = yes
				}
			}
			if = {
				limit = {
					e_france = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_france
					status = yes
				}
			}
			if = {
				limit = {
					e_spain = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_spain
					status = yes
				}
			}
			if = {
				limit = {
					e_scandinavia = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_scandinavia
					status = yes
				}
			}
			if = {
				limit = {
					e_italy = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_italy
					status = yes
				}
			}
			if = {
				limit = {
					e_wendish_empire = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_wendish_empire
					status = yes
				}
			}
			if = {
				limit = {
					e_maghreb = {
						is_titular = no
					}
				}
				activate_title = {
					title = e_maghreb
					status = yes
				}
			}
			if = {
				limit = {
					e_roman_empire = {
						NOT = { is_title_active = THIS }
					}
				}
				e_roman_empire = {
					any_direct_de_jure_vassal_title = {
						de_jure_liege = e_byzantium
					}
				}
			}
			# Can't help if player used to create HRE from e_arabia or e_persia...lol
			
			set_title_landless = {
				title = THIS
				status = no
			}
			unsafe_destroy_landed_title = THIS
		}
		activate_title = {
			title = e_hre
			status = no
		}
	}
	
	option = {
		name = OK
	}
}

# 7X0 Call of Imperial Diet eventchain
# 8X0 Imperial Reform narrative_event
character_event = {
	id = SIR.710
	desc = EVTDESC_SIR_710
	picture = "GFX_evt_council"
	
	only_playable = yes
	
	trigger = {
		offmap_hre = {
			has_status = hre_shattered
			check_variable = { which = imperial_authority value > 50 }
			NOR = {
				has_offmap_flag = hre_dismantled
				#
			}
		}
		is_offmap_governor = offmap_hre
		war = no
		prisoner = no
		NOT = { is_inaccessible_trigger = yes }
		NOR = {
			had_character_flag = {
				flag = host_an_imp_diet
				years <= 1
			}
			has_character_flag = do_not_disturb
		}
	}
	
	mean_time_to_happen = {
		months = 2400
		
		modifier = {
			factor = 0.9
			offmap_hre = {
				check_variable = { which = imperial_authority value > 65 }
			}
		}
		modifier = {
			factor = 0.9
			offmap_hre = {
				check_variable = { which = imperial_authority value > 70 }
			}
		}
		modifier = {
			factor = 0.9
			offmap_hre = {
				check_variable = { which = imperial_authority value > 75 }
			}
		}
		modifier = {
			factor = 0.9
			offmap_hre = {
				check_variable = { which = imperial_authority value > 80 }
			}
		}
		modifier = {
			factor = 0.8
			offmap_hre = {
				check_variable = { which = imperial_authority value > 85 }
			}
		}
		modifier = {
			factor = 0.8
			offmap_hre = {
				check_variable = { which = imperial_authority value > 90 }
			}
		}
		modifier = {
			factor = 0.7
			offmap_hre = {
				check_variable = { which = imperial_authority value > 95 }
			}
		}
	}
	
	immediate = {
		clr_character_flag = host_an_imp_diet
		set_character_flag = host_an_imp_diet
		set_character_flag = do_not_disturb
		character_event = { id = SIR.720 days = 15 random = 5 }
		character_event = { id = SIR.750 days = 30 }
	}
	
	option = {
		name = OK
	}
}

character_event = {
	id = SIR.720
	desc = {
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
		}
		text = EVTDESC_SIR_720_A
	}
	desc = {
		trigger = {
			NAND = {
				wealth = diet_reformation_cost
				prestige = diet_reformation_pres
			}
		}
		text = EVTDESC_SIR_720_B
	}
	picture = "GFX_evt_council"
	
	only_playable = yes
	is_triggered_only = yes
	
	trigger = {
		offmap_hre = {
			has_status = hre_shattered
			NOR = {
				has_offmap_flag = hre_dismantled
				#
			}
		}
		is_offmap_governor = offmap_hre
		war = no
		has_character_flag = host_an_imp_diet
	}
	
	immediate = {
		set_variable = { which = diet_reformation_cost value = 500 }
		set_variable = { which = diet_reformation_cost_coef value = 0 }
		
		export_to_variable = { which = diet_yearly_income value = yearly_income }
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = call_for_reichsreform 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = institute_reichsregiment 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = enact_gemeiner_pfennig 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = ewiger_landfriede 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = establish_the_reichstag_collegia 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = curtail_the_imperial_estates 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = revoke_the_privilegia 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = proclaim_erbkaisertum 
				}
			}
			change_variable = { which = diet_reformation_cost_coef value = 1 }
		}
		multiply_variable = { which = diet_reformation_cost which = diet_reformation_cost_coef }
		if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 70 }
				}
			}
			multiply_variable = { which = diet_yearly_income value = 0.9 }
		}
		else_if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 80 }
				}
			}
			multiply_variable = { which = diet_yearly_income value = 0.8 }
		}
		else_if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 90 }
				}
			}
			multiply_variable = { which = diet_yearly_income value = 0.7 }
		}
		multiply_variable = { which = diet_yearly_income value = 3 }
		change_variable = { which = diet_reformation_cost which = diet_yearly_income }
		divide_variable = { which = diet_reformation_cost value = 1 }
		
		set_variable = { which = diet_reformation_pres value = 1000 }
		set_variable = { which = diet_reformation_pres_coef value = 0 }
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = call_for_reichsreform 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = institute_reichsregiment 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = enact_gemeiner_pfennig 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = ewiger_landfriede 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = establish_the_reichstag_collegia 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = curtail_the_imperial_estates 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = revoke_the_privilegia 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		if = {
			limit = {
				offmap_hre = {
					has_offmap_flag = proclaim_erbkaisertum 
				}
			}
			change_variable = { which = diet_reformation_pres_coef value = 1 }
		}
		multiply_variable = { which = diet_reformation_pres which = diet_reformation_pres_coef }
		if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 70 }
				}
			}
			multiply_variable = { which = diet_reformation_pres value = 0.9 }
		}
		else_if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 80 }
				}
			}
			multiply_variable = { which = diet_reformation_pres value = 0.8 }
		}
		else_if = {
			limit = {
				offmap_hre = {
					check_variable = { which = imperial_authority which > 90 }
				}
			}
			multiply_variable = { which = diet_reformation_pres value = 0.7 }
		}
		set_variable = { which = diet_reformation_cost_neg value = 0 }
		set_variable = { which = diet_reformation_pres_neg value = 0 }
		subtract_variable = { which = diet_reformation_cost_neg which = diet_reformation_cost }
		subtract_variable = { which = diet_reformation_pres_neg which = diet_reformation_pres }
	}
	
	option = {
		name = EVTOPTA_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				NOT = {
					has_offmap_flag = call_for_reichsreform
				}
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = call_for_reichsreform
			}
		}
		custom_tooltip = {
			text = EVTOPTA_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTB_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				NOT = { has_offmap_flag = institute_reichsregiment }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = institute_reichsregiment
			}
		}
		custom_tooltip = {
			text = EVTOPTB_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTC_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				NOT = { has_offmap_flag = enact_gemeiner_pfennig }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = enact_gemeiner_pfennig
			}
		}
		custom_tooltip = {
			text = EVTOPTC_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		offmap_hre_tributaries_sync_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTD_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				has_offmap_flag = institute_reichsregiment
				has_offmap_flag = enact_gemeiner_pfennig
				NOT = { has_offmap_flag = ewiger_landfriede }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = ewiger_landfriede
			}
		}
		custom_tooltip = {
			text = EVTOPTD_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		offmap_hre_tributaries_sync_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTE_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				has_offmap_flag = institute_reichsregiment
				has_offmap_flag = enact_gemeiner_pfennig
				NOT = { has_offmap_flag = establish_the_reichstag_collegia }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = establish_the_reichstag_collegia
			}
		}
		custom_tooltip = {
			text = EVTOPTE_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTF_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				has_offmap_flag = institute_reichsregiment
				has_offmap_flag = enact_gemeiner_pfennig
				NOT = { has_offmap_flag = curtail_the_imperial_estates }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = curtail_the_imperial_estates
			}
		}
		custom_tooltip = {
			text = EVTOPTF_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		offmap_hre_tributaries_sync_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTG_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				has_offmap_flag = institute_reichsregiment
				has_offmap_flag = enact_gemeiner_pfennig
				has_offmap_flag = ewiger_landfriede
				has_offmap_flag = establish_the_reichstag_collegia
				has_offmap_flag = curtail_the_imperial_estates
				NOT = { has_offmap_flag = revoke_the_privilegia }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = revoke_the_privilegia
			}
		}
		custom_tooltip = {
			text = EVTOPTG_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		offmap_hre_revoke_the_privilegia_effect = yes
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTH_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
			offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				has_offmap_flag = institute_reichsregiment
				has_offmap_flag = enact_gemeiner_pfennig
				has_offmap_flag = ewiger_landfriede
				has_offmap_flag = establish_the_reichstag_collegia
				has_offmap_flag = curtail_the_imperial_estates
				NOT = { has_offmap_flag = proclaim_erbkaisertum }
			}
		}
		hidden_tooltip = {
			offmap_hre = {
				set_offmap_flag = proclaim_erbkaisertum
			}
		}
		custom_tooltip = {
			text = EVTOPTH_SIR_720_TT
		}
		offmap_hre_reform_detract_effect = yes
		e_hre = { add_law = succ_primogeniture }
		ai_chance = { factor = 0 }
	}
	
	option = {
		name = EVTOPTI_SIR_720
		trigger = {
			wealth = diet_reformation_cost
			prestige = diet_reformation_pres
		}
		clr_character_flag = do_not_disturb
	}
	
	option = {
		name = ALAS
		trigger = {
			NAND = {
				wealth = diet_reformation_cost
				prestige = diet_reformation_pres
			}
		}
		clr_character_flag = do_not_disturb
	}
}

#Fallback
character_event = {
	id = SIR.750
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		has_character_flag = host_an_imp_diet
	}

	immediate = {
		clr_character_flag = do_not_disturb
	}
}

narrative_event = {
	id = SIR.810
	title = EVTNAME_HRE_1350 # Golden Bull of [Root.current_year.GetValue]
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = call_for_reichsreform
				NOT = {
					had_flag = {
						flag = call_for_reichsreform
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_A
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = institute_reichsregiment
				NOT = {
					had_flag = {
						flag = institute_reichsregiment
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_B
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = enact_gemeiner_pfennig
				NOT = {
					had_flag = {
						flag = enact_gemeiner_pfennig
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_C
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = ewiger_landfriede
				NOT = {
					had_flag = {
						flag = ewiger_landfriede
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_D
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = establish_the_reichstag_collegia
				NOT = {
					had_flag = {
						flag = establish_the_reichstag_collegia
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_E
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = curtail_the_imperial_estates
				NOT = {
					had_flag = {
						flag = curtail_the_imperial_estates
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_F
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = privilegia_revoked
				NOT = {
					had_flag = {
						flag = privilegia_revoked
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_G
    }
	desc = {
    	trigger = {
    		offmap_hre = {
				has_offmap_flag = proclaim_erbkaisertum
				NOT = {
					had_flag = {
						flag = proclaim_erbkaisertum
						days = 1
					}
				}
			}
    	}
    	text = EVTDESC_SIR_810_H
    }
	picture = "GFX_evt_bloodlines"
	border = "GFX_event_narrative_frame_diplomacy"
	
	only_playable = yes
	major = yes
	is_triggered_only = yes
	
	trigger = {
		always = no # Disabled for now
	}
	
	major_trigger = {
		is_member_of_hre = yes
	}
	
	immediate = {
		export_to_variable = {
			which = current_year
			value = year
		}
	}
	
	option = {
		name = EXCELLENT
	}
}

narrative_event = {
	id = SIR.1350
	title = EVTNAME_HRE_1350
	desc = EVTDESC_HRE_1350

	#major = yes
	
	#hide_from = yes
	
	picture = "GFX_evt_bloodlines"
	border = "GFX_event_narrative_frame_diplomacy"
	
	only_playable = yes
	religion = catholic
	
	trigger = {
		e_hre = {
			holder_scope = {
				character = ROOT
				war = no
			}
			has_law = succ_feudal_elective
		}
		offmap_hre = {
			OR = {
				AND = {
					has_offmap_flag = hre_interregum_happened
					#year = 1350
					year = 1336
				}
				had_flag = {
					flag = hre_interregum_happened
					years >= 100
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 36
	}
	
	#major_trigger = {
	#	religion = ROOT
	#}
	
	immediate = {
		hidden_tooltip = {
			offmap_hre = {
				set_status = hre_shattered
				set_offmap_flag = hre_diet_metz_enacted
				set_variable = {
					which = imperial_authority
					value = 45
				}
			}
			set_government_type = sacred_confederacy_government
			e_hre = {
				if = {
					limit = {
						OR = {
							AND = {
								has_dlc = "Conclave"
								has_law = succession_voting_power_0
							}
							has_law = crown_authority_4
						}
					}
					offmap_hre = {
						change_variable = {
							which = imperial_authority
							value = 15
						}
					}
				}
				else_if = {
					limit = {
						OR = {
							AND = {
								has_dlc = "Conclave"
								has_law = succession_voting_power_1
							}
							has_law = crown_authority_0
						}
					}
					offmap_hre = {
						change_variable = {
							which = imperial_authority
							value = -15
						}
					}
				}
				add_law = {
					law = succ_hre_elective
					opinion_effect = no
				}
				set_title_landless = { title = THIS status = yes }
			}
			offmap_hre_government_de_facto_maintain_effect = yes
			offmap_hre_ruler_name_sync_effect = yes
			export_to_variable = {
				which = global_current_year
				value = year
			}
		}
	}
	
	option = {
		name = EVTOPTA8000 # I guess I have no choice...
		trigger = {
			any_realm_title = {
				title = e_hre
			}
		}
	}
	option = {
		name = CURSES
		trigger = {
			NOT = {
				any_realm_title = {
					title = e_hre
				}
			}
			OR = {
				has_claim = e_hre
				is_heir = e_hre
			}
		}
	}
	option = {
		name = EVTOPTA_MNM_4610 # EVTOPTB_HRE_1350;That's nice, I guess.;C'est bien, je suppose.;Das ist ganz nett, denke ich.;;Est bien, supongo.;;;;;;;;;x
		trigger = {
			NOT = {
				any_realm_title = {
					title = e_hre
				}
			}
			NOR = {
				has_claim = e_hre
				is_heir = e_hre
			}
		}
	}
	
	after = {
		hidden_tooltip = {
			set_variable = {
				which = global_current_year
				value = 0
			}
		}
	}
}
