namespace = HFP

# Hansa
narrative_event = {
	id = HFP.40000
	title = TITLE_HFP_40000
	desc = EVTDESC_HFP_40000
	picture = GFX_evt_busy_trading_dock_republic

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40000

		prestige = 500
	}
}

# Hansa Notification event
narrative_event = {
	id = HFP.40001
	title = TITLE_HFP_40001
	desc = EVTDESC_HFP_40001
	picture = GFX_evt_busy_trading_dock_republic

	is_triggered_only = yes

	trigger = {
		NOT = { has_landed_title = k_hansa }
	}

	option = {
		name = EVTOPTA_HFP_40001
	}
}

 #Switzerland
narrative_event = {
	id = HFP.40010
	title = TITLE_HFP_40010
	desc = EVTDESC_HFP_40010
	picture = GFX_evt_council
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40010

		prestige = 250
	}
}

# Swiss Notifications
narrative_event = {
	id = HFP.40012
	title = TITLE_HFP_40012
	desc = EVTDESC_HFP_40012
	picture = GFX_evt_throne_room
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	trigger = {
		NOT = { has_landed_title = k_switzerland }
	}

	option = {
		name = INTERESTING
	}
}

# Antioch
narrative_event = {
	id = HFP.40013
	title = EVTTITLE_HFP_40013
	desc = EVTDESC_HFP_40013
	picture = GFX_evt_western_knights_byzantine

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40013

		prestige = 500
	}
}

# Cyprus
narrative_event = {
	id = HFP.40014
	title = EVTTITLE_HFP_40014
	desc = EVTDESC_HFP_40014
	picture = GFX_evt_western_knights_byzantine

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40014

		prestige = 500
	}
}

# Merchant Republic Kingdoms
narrative_event = {
	id = HFP.40015
	title = EVTTITLE_HFP_40015
	desc = EVTDESC_HFP_40015
	picture = GFX_evt_busy_trading_dock_republic

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40015

		prestige = 250
	}
}

# Archduke of Austria
narrative_event = {
	id = HFP.40022
	title = EVTTITLE_HFP_40022
	picture = GFX_evt_book_carolingian_script

	desc = {
		text = EVTDESC_HFP_40022
		trigger = {
			e_hre = {
				OR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
				}
			}
		}
	}
	desc = {
		text = EVTDESC_HFP_40022_2
		trigger = {
			e_hre = {
				NOR = {
					has_law = succ_feudal_elective
					has_law = succ_hre_elective
				}
			}
		}
	}

	is_triggered_only = yes

	option = {
		name = EVTOPTA_HFP_40022

		trigger = { has_landed_title = k_austria }

		prestige = 500
	}

	option = {
		name = EVTOPTB_HFP_40022

		trigger = {
			NOT = { has_landed_title = k_austria }
		}
	}
}

# Gather the Eastern Marches
narrative_event = {
	id = HFP.40023
	title = EVTTITLE_HFP_40023
	desc = EVTDESC_HFP_40023
	picture = GFX_evt_book_carolingian_script

	is_triggered_only = yes
	major = yes

	major_trigger = {
		de_facto_liege_title = e_hre
	}

	option = {
		name = EVTOPTA_HFP_40023

		trigger = { has_landed_title = k_eastern_marches }

		prestige = 1000
	}

	option = {
		name = EVTOPTB_HFP_40023

		trigger = {
			NOT = { has_landed_title = k_eastern_marches }
		}
	}
}

# Restore the Byzantine Empire
narrative_event = {
	id = HFP.40024
	title = EVTTITLE_HFP_40024
	desc = EVTDESC_HFP_40024
	picture = GFX_evt_victory_arch_byzantine

	is_triggered_only = yes

	# Rejoin the Empire (Byzantine Culture Group only)
	option = {
		name = EVTOPTA_HFP_40024

		trigger = {
			culture_group = byzantine
			independent = yes
			lower_real_tier_than = EMPEROR
			controls_religion = no
		}

		set_defacto_liege = e_byzantium

		FROM = {
			letter_event = {
				id = HFP.40025
				days = 1
			}
		}

		ai_chance = {
			factor = 1

			mult_modifier = {
				factor = 2
				trait = content
			}

			mult_modifier = {
				factor = 2
				FROM = { trait = born_in_the_purple }
			}

			mult_modifier = {
				factor = 2

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

			mult_modifier = {
				factor = 0.5

				OR = {
					trait = proud
					trait = envious
					trait = ambitious
				}
			}

			mult_modifier = {
				factor = 0.5

				opinion = {
					who = FROM
					value < 10
				}
			}

			mult_modifier = {
				factor = 0.5
				real_tier = KING
			}

			mult_modifier = {
				factor = 2
				lower_real_tier_than = DUKE
			}
		}
	}

	# Choose not to rejoin the Empire (Byzantine Culture Group only)
	option = {
		name = EVTOPTB_HFP_40024

		trigger = {
			culture_group = byzantine
			NOT = { has_landed_title = e_byzantium }
		}

		ai_chance = { factor = 2 }
	}

	# For others
	option = {
		name = EVTOPTC_HFP_40024

		trigger = {
			NOT = { culture_group = byzantine }
		}
	}

	# For the Emperor
	option = {
		name = EVTOPTD_HFP_40024

		trigger = { has_landed_title = e_byzantium }
	}
}

# Letter event Swearing Fealty to new Byzantine Emperor
letter_event = {
	id = HFP.40025
	desc = EVTDESC_HFP_40025

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_HFP_40025
	}
}

# Making a new Eastern Marches Kingdom
character_event = {
	id = HFP.40026
	desc = EVTDESC_HFP_40026
	picture = GFX_evt_throne_room

	is_triggered_only = yes

	# Austria
	option = {
		name = EVTOPTA_HFP_40026

		if = {
			limit = { NOT = { has_landed_title = c_wien } }
			grant_title_no_opinion = c_wien
		}

		if = {
			limit = {
				capital_scope = {
					NOT = { province = c_wien }
				}
			}

			capital = c_wien
		}
	}

	# Styria
	option = {
		name = EVTOPTB_HFP_40026

		hidden_effect = {
			k_eastern_marches = {
				set_name = kingdom_of_styria_name
				adjective = d_styria
				set_coa = d_styria
			}
		}

		if = {
			limit = { NOT = { has_landed_title = c_graz } }
			grant_title_no_opinion = c_graz
		}

		if = {
			limit = {
				capital_scope = {
					NOT = { province = c_graz }
				}
			}

			capital = c_graz
		}
	}

	# Bavaria
	option = {
		name = EVTOPTC_HFP_40026

		hidden_effect = {
			k_eastern_marches = {
				set_name = kingdom_of_bavaria_name
				adjective = k_bavaria
				set_coa = k_bavaria
			}
		}

		if = {
			limit = { NOT = { has_landed_title = c_regensburg } }
			grant_title_no_opinion = c_regensburg
		}

		if = {
			limit = {
				capital_scope = {
					NOT = { province = c_regensburg }
				}
			}

			capital = c_regensburg
		}
	}

	# Carinthia
	option = {
		name = EVTOPTD_HFP_40026

		hidden_effect = {
			k_eastern_marches = {
				set_name = kingdom_of_carinthia_name
				adjective = k_carinthia
				set_coa = k_carinthia
			}
		}

		if = {
			limit = { NOT = { has_landed_title = c_villach } }
			grant_title_no_opinion = c_villach
		}

		if = {
			limit = {
				capital_scope = {
					NOT = { province = c_villach }
				}
			}

			capital = c_villach
		}
	}

	after = {
		hidden_effect = {
			primary_title = {
				k_eastern_marches = {
					if = {
						limit = { NOT = { is_title_active = THIS } }

						activate_title = {
							title = THIS
							status = yes
						}
					}

					copy_title_history = PREV
					copy_title_laws = PREV
					de_jure_liege = e_hre
					make_primary_title = yes
				}
			}

			grant_title_no_opinion = k_eastern_marches

			d_styria	 = { de_jure_liege = k_eastern_marches }
			d_osterreich = { de_jure_liege = k_eastern_marches }
			d_salzburg	 = { de_jure_liege = k_eastern_marches }
			d_bavaria	 = { de_jure_liege = k_eastern_marches }
			d_carinthia	 = { de_jure_liege = k_eastern_marches }
			d_friuli	 = { de_jure_liege = k_eastern_marches }
			d_carniola	 = { de_jure_liege = k_eastern_marches }
			d_tyrol		 = { de_jure_liege = k_eastern_marches }

			k_bavaria = {
				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_eastern_marches
				}

				destroy_landed_title = THIS

				activate_title = {
					title = THIS
					status = no
				}
			}

			k_carinthia = {
				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_eastern_marches
				}

				if = {
					limit = {
						OR = {
							holder = ROOT
							has_holder = no
						}
					}

					destroy_landed_title = THIS

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

			set_defacto_liege = e_hre
			narrative_event = { id = HFP.40023 }
		}
	}
}

# Complete Catholic/Fraticelli victory
narrative_event = {
	id = HFP.40027
	title = EVTTITLE_HFP_40027
	desc = EVTDESC_HFP_40027
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		is_playable = yes
	}

	option = {
		name = EVTOPTA_HFP_40027

		trigger = { religion_group = christian }

		if = {
			limit = { has_landed_title = e_outremer }

			prestige = 1000

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

				if = {
					limit = { is_female = yes }

					create_bloodline = {
						type = lord_of_outremer_bloodline
						inheritance = matrilineal
					}
				}
				else = {
					create_bloodline = {
						type = lord_of_outremer_bloodline
					}
				}

				set_bloodline_founder_religion_flag_effect = yes
			}
		}
	}

	option = {
		name = EVTOPTB_HFP_40027

		trigger = {
			NOT = { religion_group = christian }
		}

		ai_chance = {
			factor = 1

			trigger = {
				NOT = {
					any_liege = { religion = FROM }
				}
			}
		}
	}

	option = {
		name = EVTOPTC_HFP_40027

		trigger = { religion_group = muslim }

		# Workaround for automatic usurpation of theocratic characters
		FROM = {
			religion_scope = {
				save_event_target_as = target_religion
			}
		}

		convert_religion_failsafe_effect = yes

		ai_chance = {
			factor = 1

			trigger = {
				OR = {
					trait = cynical
					any_liege = { religion = FROM }
				}
			}
		}
	}
}

# Removes the prince / princess titles from the children of the Prince of Antioch
character_event = {
	id = HFP.40028

	is_triggered_only = yes # on_startup
	hide_window = yes

	trigger = {
		primary_title = {
			title = k_antioch
		}
	}

	immediate = {
		any_child = {
			limit = { has_minor_title = title_prince }
			remove_title = title_prince
		}
	}
}

# The Order of Calatrava has been formed
narrative_event = {
	id = HFP.40029
	title = EVTTITLE_HFP_40029
	desc = EVTDESC_HFP_40029
	picture = GFX_evt_melee
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = {
			text = EVTOPTA_HFP_40029
			trigger = { religion_group = FROM }
		}
		name = {
			text = EVTOPTB_HFP_40029
			trigger = {
				NOT = { religion_group = FROM }
			}
		}
	}
}

# The Order of Santiago has been formed
narrative_event = {
	id = HFP.40030
	title = EVTTITLE_HFP_40030
	desc = EVTDESC_HFP_40030
	picture = GFX_evt_magnificent_castle
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = {
			text = EVTOPTA_HFP_40030
			trigger = { religion_group = FROM }
		}
		name = {
			text = EVTOPTB_HFP_40030
			trigger = {
				NOT = { religion_group = FROM }
			}
		}
	}
}

# The Teutonic Order has been formed
narrative_event = {
	id = HFP.40031
	title = EVTTITLE_HFP_40031
	desc = EVTDESC_HFP_40031
	picture = GFX_evt_crusaders
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = {
			text = EVTOPTA_HFP_40031
			trigger = { religion_group = FROM }
		}
		name = {
			text = EVTOPTB_HFP_40031
			trigger = {
				NOT = { religion_group = FROM }
			}
		}
	}
}

# The Holy Sepulchre has been formed
narrative_event = {
	id = HFP.40032
	title = EVTTITLE_SOA_1609
	desc = EVTDESC_SOA_1609
	picture = GFX_evt_western_knights_byzantine
	border = GFX_event_narrative_frame_religion

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = {
			text = EVTOPTA_SOA_1609
			trigger = { religion = FROM }
		}
		name = {
			text = EVTOPTB_SOA_1609
			trigger = {
				NOT = { religion = FROM }
			}
		}
	}
}

# Romagna / Papal States usurpation event
character_event = {
	id = HFP.40033

	is_triggered_only = yes # on_new_holder(_inheritance/usurpation)
	hide_window = yes

	trigger = {
		FROM = { title = k_papal_state }
	}

	immediate = {
		if = {
			limit = {
				NOT = { has_landed_title = k_papacy }
			}

			grant_title_no_opinion = k_romagna
			destroy_landed_title = k_papal_state

			k_papal_state = {
				any_direct_de_jure_vassal_title = {
					de_jure_liege = k_romagna
				}

				dejure_liege_title = {
					k_romagna = {
						de_jure_liege = PREV
					}
				}
			}

			narrative_event = { id = HFP.40036 }
		}
	}
}

## Papal States becomes Romagna when the Pope holds no lands in Italy
# Narrative Event - Papacy has lost all their land, and thus any claim to the land in central Italy
narrative_event = {
	id = HFP.40037
	title = EVTTITLE_HFP_40037
	desc = EVTDESC_HFP_40037
	picture = GFX_evt_magnificent_castle

	is_triggered_only = yes
	major = yes

	major_trigger = {
		any_demesne_province = {
			region = world_europe_south_italy
			owned_by = PREV
		}
	}

	option = {
		name = INTERESTING
	}
}

# Narrative Event - Papal States usurped
narrative_event = {
	id = HFP.40036
	title = EVTTITLE_HFP_40036
	desc = EVTDESC_HFP_40036
	picture = GFX_evt_magnificent_castle

	is_triggered_only = yes
	major = yes

	major_trigger = {
		any_demesne_province = {
			region = world_europe_south_italy
			owned_by = PREV
		}
	}

	option = {
		name = {
			text = EVTOPTA_HFP_40036
			trigger = {
				NOT = { character = ROOT }
			}
		}
		name = {
			text = EVTOPTB_HFP_40036
			trigger = { character = ROOT }
		}
	}
}

# Narrative Event - Grand Stem Duchies in the HRE
narrative_event = {
	id = HFP.40038
	title = EVTTITLE_HFP_40038
	desc = EVTDESC_HFP_40038
	picture = GFX_evt_magnificent_castle

	is_triggered_only = yes
	major = yes

	major_trigger = {
		top_liege = {
			has_landed_title = e_hre
		}
	}

	option = {
		name = INTERESTING

		trigger = { character = ROOT }
	}

	option = {
		name = EVTOPTB_HFP_40038

		trigger = {
			NOT = { character = ROOT }
		}

		prestige = 500
	}
}

# The Slavic Union is formed
narrative_event = {
	id = HFP.99999
	title = EVTTITLE_HFP_99999
	desc = EVTDESC_HFP_99999
	picture = GFX_evt_pagan_reformation
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes
	major = yes

	major_trigger = {
		ai = no
	}

	option = {
		name = EVTOPTA_HFP_99999
	}
}

######
# Princely Elective Dynamic Elector titles

# On regular start
character_event = {
	id = HFP.24120

	is_triggered_only = yes # on_startup
	hide_window = yes

	only_independent = yes

	trigger = {
		has_landed_title = e_hre # Only if the original exists

		e_hre = {
			NOT = {
				persistent_event_target:hre_title_1_per = { always = yes } # If one exists already, all do
			}
		}
	}

	immediate = {
		princely_elective_german_elector_setup_effect = yes # Regular German setup
	}
}