###########################################
#                                         #
# Charlemagne Story Events                #
#                                         #
# ID CM.1000-CM.1999                      #
#                                         #
###########################################

# Written by Tobias Bodlund

namespace = CM


###########################################
# Charlemagne-Carloman rivalry            #
###########################################

# Charlemagne - setup
character_event = {
	id = CM.998

	is_triggered_only = yes # on_startup
	hide_window = yes

	only_independent = yes
	religion_group = christian
	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"

	trigger = {
		year < 780
		is_save_game = no

		NOR = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}

			has_character_flag = charlemagne_brother_rivalry
			has_character_flag = charlemagne_brother_rivalry_event
		}
	}

	immediate = {
		narrative_event = {
			id = CM.1000
			days = 1
		}
	}
}

# Carloman - Setup
character_event = {
	id = CM.999

	is_triggered_only = yes # on_startup
	hide_window = yes

	only_independent = yes
	religion_group = christian
	has_character_flag = is_carloman
	has_dlc = "Charlemagne"

	trigger = {
		year < 780
		is_save_game = no

		NOR = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}

			has_character_flag = charlemagne_brother_rivalry
			has_character_flag = charlemagne_brother_rivalry_event
		}
	}

	immediate = {
		narrative_event = {
			id = CM.1001
			days = 1
		}
	}
}

# Charlemagne rivalry with brother
narrative_event = {
	id = CM.1000
	title = EVTTITLE_CM_1000
	desc = EVTDESC_CM_1000
	picture = GFX_evt_rival_rulers
	border = GFX_event_narrative_frame_war
	portrait = c_144999 # Carloman

	is_triggered_only = yes

	immediate = {
		set_character_flag = charlemagne_brother_rivalry_event
	}

	option = {
		name = EVTOPTA_CM_1000

		set_character_flag = charlemagne_brother_rivalry
		add_rival = c_144999 # Carloman

		narrative_event = {
			id = CM.1010 # Marry a Lombard princess
			days = 10
		}

		character_event = {
			id = CM.1040# Legitimise Pepin?
			days = 50
		}

		narrative_event = {
			id = CM.1120 # Mother deals with Carloman
			days = 700
			random = 50
		}

		narrative_event = {
			id = CM.1027 # Bertrada talks to Charlemagne
			months = 1
			random = 30
		}
	}
}

# Carloman rivalry with brother
narrative_event = {
	id = CM.1001
	title = EVTTITLE_CM_1000
	desc = EVTDESC_CM_1000
	picture = GFX_evt_rival_rulers
	border = GFX_event_narrative_frame_war
	portrait = c_6392 # Charlemagne

	is_triggered_only = yes

	immediate = {
		set_character_flag = charlemagne_brother_rivalry_event
	}

	option = {
		name = EVTOPTA_CM_1000

		set_character_flag = charlemagne_brother_rivalry
		add_rival = c_6392 # Charlemagne

		letter_event = {
			id = CM.1024 # Bertrada sends letter to Carloman
			months = 1
			random = 30
		}
	}
}

# Notify Carloman of Charlemagne's death, give him titles
narrative_event = {
	id = CM.1002
	title = EVTTITLE_CM_1002
	desc = EVTDESC_CM_1002
	picture = GFX_evt_emissary

	is_triggered_only = yes # CM.1069

	option = {
		name = EVTOPTA_CM_1002
	}
}

# Notify Charlemagne of Carloman's death, give him titles
narrative_event = {
	id = CM.1003
	title = EVTTITLE_CM_1003
	desc = EVTDESC_CM_1002
	picture = GFX_evt_emissary

	is_triggered_only = yes # CM.1068

	option = {
		name = EVTOPTA_CM_1002
	}
}

###########################################
# Desiderata the Lombard Princess         #
###########################################

# Marriage to Desiderata
narrative_event = {
	id = CM.1010
	title = EVTTITLE_CM_1010
	desc = EVTDESC_CM_1010
	picture = GFX_evt_marriage
	portrait = k_italy

	is_triggered_only = yes

	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"
	only_capable = yes
	prisoner = no
	is_married = no

	trigger = {
		is_rival = c_144999 # Carloman

		k_lombardy = {
			holder_scope = {
				culture = longobard
				ai = yes

				any_child = {
					is_female = yes
					is_marriage_adult = yes
					is_married = no
				}
			}
		}
	}

	immediate = {
		k_lombardy = {
			holder_scope = {
				random_child = {
					limit = {
						is_female = yes
						is_marriage_adult = yes
						is_married = no
					}

					save_global_event_target_as = lombard_daughter
				}
			}
		}
	}

	option = {
		name = EVTOPTA_CM_1010 # Marry her

		add_spouse = event_target:lombard_daughter
		show_portrait = event_target:lombard_daughter
	}

	option = {
		name = EVTOPTB_CM_1010 # No Lombards in my bed!

		prestige = -30
	}
}

# Divorce from Desiderata
narrative_event = {
	id = CM.1011
	title = EVTTITLE_CM_1011
	desc = EVTDESC_CM_1011
	picture = GFX_evt_scandal

	is_triggered_only = yes # on_yearly_pulse

	only_playable = yes
	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"
	only_capable = yes

	trigger = {
		# The following also works if event target doesn't exist
		# is_married = event_target:lombard_daughter
		event_target:lombard_daughter = { is_married = ROOT }

		NOR = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}

			has_character_flag = nagged_about_lombard_queen
		}

		year >= 770
		year < 850

		OR = {
			culture = french
			culture = frankish
		}

		c_144999 = { # Carloman
			NOT = {
				any_spouse = { culture = longobard }
			}
		}
	}

	fail_trigger_effect = {
		clear_global_event_target = lombard_daughter
	}

	immediate = {
		set_character_flag = nagged_about_lombard_queen
	}

	option = {
		name = EVTOPTA_CM_1011 # Divorce her

		piety = -100
		remove_spouse = event_target:lombard_daughter
		clear_global_event_target = lombard_daughter

		event_target:lombard_daughter = {
			show_scope_change = no

			move_character = father

			father = {
				show_scope_change = no

				set_character_flag = charlemagne_enemy

				opinion = {
					name = opinion_furious
					who = ROOT
					years = 10
				}

				if = {
					limit = { is_allied_with = ROOT }

					ROOT = {
						show_scope_change = no
						break_alliance = PREV
					}
				}

				if = {
					limit = { has_non_aggression_pact_with = ROOT }

					reverse_remove_opinion = {
						name = in_non_aggression_pact
						who = ROOT
					}

					opinion = {
						name = broken_non_aggression_pact
						who = ROOT
						years = 3
					}
				}
			}

			mother = {
				show_scope_change = no

				opinion = {
					name = opinion_furious
					who = ROOT
					years = 10
				}
			}

			any_child = {
				show_scope_change = no

				limit = {
					is_child_of = ROOT
					NOT = { culture = ROOT }
				}

				culture = ROOT
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1011 # No, she's my wife

		custom_tooltip = {
			text = most_lords_angry

			any_realm_lord = {
				limit = {
					OR = {
						culture = french
						culture = frankish
					}

					NOT = {
						any_spouse = {
							culture = longobard
						}
					}
				}

				opinion = {
					name = opinion_angry
					who = ROOT
					years = 5
				}
			}
		}
	}
}

###########################################
# Queen Bertrada                          #
###########################################

# Charlemagne dies and Bertrada approaches Carloman for reconciliation
character_event = {
	id = CM.1020

	is_triggered_only = yes # CM.1069
	hide_window = yes

	immediate = {
		if = {
			limit = { prisoner = yes }

			repeat_event = {
				id = CM.1020 # Try again later
				days = 30
			}
		}
		else = {
			c_144999 = { # Carloman
				narrative_event = { id = CM.1021 }
			}
		}
	}
}

# Carloman receives her and gives his response
narrative_event = {
	id = CM.1021
	title = EVTTITLE_CM_1021
	desc = EVTDESC_CM_1021
	picture = GFX_evt_daughter_asking_father

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1021 # I forgive you, Mother

		FROM = {
			show_scope_change = no

			move_character = ROOT

			opinion = {
				name = opinion_very_grateful
				who = ROOT
				years = 100
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1021 # Begone, witch

		reverse_opinion = {
			name = opinion_bitter
			who = FROM
			years = 100
		}
	}
}

# Bertrada sends letter to Carloman, asking him to stop petulantly interfering with his older brother's plans
letter_event = {
	id = CM.1024
	desc = EVTDESC_CM_1024

	is_triggered_only = yes

	only_playable = yes
	has_character_flag = is_carloman
	has_dlc = "Charlemagne"
	only_capable = yes
	prisoner = no

	trigger = {
		has_character_flag = charlemagne_brother_rivalry
		year < 780

		c_6392 = { # Charlemagne
			is_alive = yes
			sibling = ROOT
		}

		mother = {
			is_alive = yes
			prisoner = no
			NOT = { has_character_flag = bertrada_carloman_talk }
		}

		NOT = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	fail_trigger_effect = {
		if = {
			limit = {
				has_character_flag = charlemagne_brother_rivalry
				year < 780

				c_6392 = { # Charlemagne
					is_alive = yes
				}

				mother = {
					is_alive = yes
					NOT = { has_character_flag = bertrada_carloman_talk }
				}

				NOT = {
					has_game_rule = {
						name = charlemagne_story
						value = off
					}
				}
			}

			repeat_event = {
				id = CM.1024
				months = 2
			}
		}
	}

	immediate = {
		mother = {
			set_character_flag = bertrada_carloman_talk
		}
	}

	option = {
		name = EVTOPTA_CM_1024

		opinion = {
			name = opinion_unappreciated
			who = mother
			years = 10
		}

		reverse_opinion = {
			name = opinion_disapprove
			who = mother
			years = 5
		}
	}
}

# Bertrada talks to Charlemagne, expressing her support
narrative_event = {
	id = CM.1027
	title = EVTTITLE_CM_1027
	desc = EVTDESC_CM_1027
	picture = GFX_evt_daughter_asking_father
	portrait = mother

	is_triggered_only = yes

	only_playable = yes
	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"
	only_capable = yes
	prisoner = no

	trigger = {
		has_character_flag = charlemagne_brother_rivalry
		year < 780

		c_144999 = { # Carloman
			is_alive = yes
		}

		mother = {
			is_alive = yes
			prisoner = no
			NOT = { has_character_flag = bertrada_charlemagne_talk }
		}

		NOT = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	fail_trigger_effect = {
		if = {
			limit = {
				has_character_flag = charlemagne_brother_rivalry
				year < 780

				c_144999 = { # Carloman
					is_alive = yes
				}

				mother = {
					is_alive = yes
					NOT = { has_character_flag = bertrada_charlemagne_talk }
				}

				NOT = {
					has_game_rule = {
						name = charlemagne_story
						value = off
					}
				}
			}

			repeat_event = {
				id = CM.1027
				months = 2
			}
		}
	}

	immediate = {
		mother = {
			set_character_flag = bertrada_charlemagne_talk
		}
	}

	option = {
		name = EVTOPTA_CM_1027

		opinion = {
			name = opinion_pleased
			who = mother
			years = 5
		}

		reverse_opinion = {
			name = opinion_favorite
			who = mother
			years = 5
		}
	}
}

##################
# Pepin le Bossu #
##################

character_event = {
	id = CM.1040
	desc = EVTDESC_CM_1040
	picture = GFX_evt_child_play
	portrait = c_90094 # Pepin 'le Bossu'

	is_triggered_only = yes

	trigger = {
		any_child = {
			has_character_flag = is_pepin_le_bossu
			trait = bastard
		}
	}

	option = {
		name = EVTOPTA_CM_1040

		piety = -20

		c_90094 = { # Pepin 'le Bossu'
			show_scope_change = no

			dynasty = 25061
			remove_trait = bastard
			add_trait = legit_bastard
			give_nickname = nick_the_hunchback
			recalc_succession = yes

			mother = {
				show_scope_change = no

				opinion = {
					name = legitimized_child
					who = ROOT
					years = 10
				}
			}
		}

		any_spouse = {
			show_scope_change = no

			if = {
				limit = {
					NOT = { is_mother = c_90094 } # Pepin 'le Bossu'
				}

				opinion = {
					name = legitimized_bastard
					who = ROOT
					years = 20
				}
			}
		}

		ai_chance = { factor = 0 }
	}

	option = {
		name = EVTOPTB_CM_1040

		c_90094 = { # Pepin 'le Bossu'
			show_scope_change = no

			prestige = -50
			give_nickname = nick_the_hunchback
		}
	}
}


###########################################
# Roland                                  #
###########################################

# Roland arrives at court
narrative_event = {
	id = CM.1050
	title = EVTTITLE_CM_1050
	desc = EVTDESC_CM_1050
	picture = GFX_evt_emissary
	portrait = new_character

	is_triggered_only = yes # on_bi_yearly_pulse
	hide_from = yes

	only_independent = yes
	religion_group = christian
	has_character_flag = is_charlemagne
	only_capable = yes
	min_age = 16
	prisoner = no
	has_dlc = "Charlemagne"

	trigger = {
		higher_real_tier_than = DUKE

		c_144999 = { # Carloman
			is_alive = no
		}

		NOR = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}

			has_global_flag = roland_spawned
		}
	}

	immediate = {
		set_global_flag = roland_spawned

		create_character = {
			random_traits = no
			name = "Roland"
			dynasty = 726
			religion = ROOT
			culture = breton
			age = 25
			add_trait = honest
			add_trait = brave
			add_trait = tough_soldier
			add_trait = strong
			add_trait = attractive
			add_trait = aggressive_leader

			attributes = {
				diplomacy = 11
				martial = 12
				stewardship = 8
				intrigue = 5
				learning = 8
			}
		}

		new_character = {
			set_character_flag = is_roland
			set_character_flag = hero_knight
			save_global_event_target_as = roland

			opinion = {
				name = opinion_loyal_servant
				who = ROOT
				years = 100
			}
		}
	}

	option = {
		name = EVTOPTA_CM_1050

		character_event = {
			id = CM.1052
			days = 350
			tooltip = roland_arrives
		}
	}

	option = {
		name = EVTOPTB_CM_1050

		prestige = -5

		hidden_effect = {
			new_character = {
				death = { death_reason = death_missing }
			}
		}

		ai_chance = { factor = 0 }
	}
}

# Roland is a good friend
character_event = {
	id = CM.1052
	desc = EVTDESC_CM_1052
	picture = GFX_evt_courtiers_talking

	is_triggered_only = yes

	trigger = {
		NOT = { is_friend = new_character }
	}

	option = {
		name = EVTOPTA_CM_1052

		add_friend = new_character
	}
}



# Roland is very brave on campaign - setup
character_event = {
	id = CM.1058

	is_triggered_only = yes # on_command_unit/on_command_subunit
	hide_window = yes

	has_character_flag = is_roland
	has_dlc = "Charlemagne"

	trigger = {
		vassal_of = c_6392
		NOT = { has_character_flag = roland_brave }
	}

	immediate = {
		c_6392 = {
			narrative_event = {
				id = CM.1053
				months = 1
				random = 60
			}
		}
	}
}

# Roland is very brave on campaign
narrative_event = {
	id = CM.1053
	title = EVTTITLE_CM_1053
	desc = EVTDESC_CM_1053
	picture = GFX_evt_melee
	border = GFX_event_narrative_frame_war

	is_triggered_only = yes

	only_playable = yes
	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"
	war = yes
	only_capable = yes
	prisoner = no

	trigger = {
		event_target:roland = {
			in_command = yes
			vassal_of = ROOT
			NOT = { has_character_flag = roland_brave }
		}
	}

	immediate = {
		event_target:roland = {
			set_character_flag = roland_brave
		}
	}

	option = {
		name = EVTOPTA_CM_1053

		event_target:roland = {
			show_scope_change = no

			prestige = 30
		}
	}
}

# Roland dies heroically in winning battle
character_event = {
	id = CM.1054

	is_triggered_only = yes # on_battle_won, random_events
	hide_window = yes

	has_character_flag = is_roland
	has_dlc = "Charlemagne"

	immediate = {
		liege = {
			narrative_event = { id = CM.1055 }
		}
	}
}

narrative_event = {
	id = CM.1055
	title = EVTTITLE_CM_1055
	desc = EVTDESC_CM_1055
	picture = GFX_evt_pale_rider
	border = GFX_event_narrative_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1055

		FROM = {
			show_scope_change = no

			death = { death_reason = death_battle }
		}

		prestige = 100
	}
}

# Roland dies heroically in losing battle
character_event = {
	id = CM.1056

	is_triggered_only = yes # on_battle_lost, random_events
	hide_window = yes

	has_character_flag = is_roland
	has_dlc = "Charlemagne"

	immediate = {
		liege = {
			narrative_event = { id = CM.1057 }
		}
	}
}

narrative_event = {
	id = CM.1057
	title = EVTTITLE_CM_1055
	desc = EVTDESC_CM_1057
	picture = GFX_evt_pale_rider
	border = GFX_event_narrative_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1055

		FROM = {
			show_scope_change = no

			death = { death_reason = death_battle }
		}

		prestige = 100
	}
}

###########################################
# Carloman or Charlemagne dies            #
###########################################

# Carloman dies
character_event = {
	id = CM.1068

	is_triggered_only = yes # on_death
	hide_window = yes

	has_character_flag = is_carloman
	has_dlc = "Charlemagne"

	trigger = {
		trigger_if = {
			limit = { ai = no }

			c_6392 = { # Charlemagne
				ai = no
				is_primary_heir = ROOT
			}
		}

		# To ensure he has certain power and to avoid problems with ruler designer
		c_6392 = { # Charlemagne
			independent = yes
			higher_real_tier_than = DUKE
		}

		NOT = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	immediate = {
		any_demesne_title = {
			grant_title = c_6392 # Charlemagne
		}

		c_6392 = { # Charlemagne
			narrative_event = { id = CM.1003 }
		}

		any_spouse = {
			if = {
				limit = {
					c_6392 = { # Charlemagne
						independent = yes

						trigger_if = {
							limit = { ROOT = { ai = no } }

							ai = no
							is_primary_heir = ROOT
						}
					}

					OR = {
						trait = pregnant

						any_child = {
							is_child_of = c_144999 # Carloman
						}
					}
				}

				character_event = { id = CM.1075 } # Flee to foreign court?
			}
		}
	}
}

# Charlemagne dies
character_event = {
	id = CM.1069

	is_triggered_only = yes # on_death
	hide_window = yes

	has_character_flag = is_charlemagne
	has_dlc = "Charlemagne"

	trigger = {
		trigger_if = {
			limit = { ai = no }

			c_144999 = { # Carloman
				ai = no
				is_primary_heir = ROOT
			}
		}

		# To ensure he has certain power and to avoid problems with ruler designer
		c_144999 = { # Carloman
			independent = yes
			higher_real_tier_than = DUKE
		}

		NOT = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	immediate = {
		any_demesne_title = {
			grant_title = c_144999 # Carloman
		}

		c_144999 = { # Carloman
			narrative_event = { id = CM.1002 }
		}

		mother = {
			if = {
				limit = {
					is_alive = yes
					NOT = { vassal_of = c_144999 } # Carloman
				}
			}

			character_event = {
				id = CM.1020 # Bertrada approaches Carloman for reconciliation
				months = 1
			}
		}
	}
}

###########################################
# Ogier the Dane                          #
###########################################

# Ogier arrives
narrative_event = {
	id = CM.1070
	title = EVTTITLE_CM_1070
	desc = EVTDESC_CM_1070
	picture = GFX_evt_emissary

	is_triggered_only = yes # on_yearly_pulse, random_events, ogier_the_dane

	only_independent = yes
	religion_group = christian
	has_dlc = "Charlemagne"
	min_age = 16
	only_capable = yes
	prisoner = no

	trigger = {
		trigger_if = {
			limit = { character = c_6392 } # Charlemagne
			c_144999 = { is_alive = no } # Carloman
		}
		trigger_else = {
			c_6392 = { independent = no } # Charlemagne
			c_144999 = { independent = no } # Carloman
		}

		higher_real_tier_than = DUKE
		year < 820

		OR = {
			culture = french
			culture = frankish
		}

		NOR = {
			has_global_flag = ogier_spawned

			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	immediate = {
		set_global_flag = ogier_spawned

		create_character = {
			random_traits = no
			dynasty = random
			religion = ROOT
			culture = norse
			age = 35
			add_trait = honest
			add_trait = zealous
			add_trait = skilled_tactician
			add_trait = strong
			add_trait = trickster

			attributes = {
				diplomacy = 11
				martial = 12
				stewardship = 8
				intrigue = 5
				learning = 8
			}
		}

		new_character = {
			set_name = "Ogier"
			set_character_flag = is_ogier
			set_character_flag = hero_knight
		}
	}

	option = {
		name = EVTOPTA_CM_1070

		custom_tooltip = {
			text = ogier_arrives

			new_character = {
				opinion = {
					name = opinion_loyal_servant
					who = ROOT
					years = 100
				}
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1070

		prestige = -5

		hidden_effect = {
			new_character = {
				death = { death_reason = death_missing }
			}
		}

		ai_chance = { factor = 0 }
	}
}

###########################################
# Carloman's family flees after his death #
###########################################

# Wife
character_event = {
	id = CM.1075

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		location = {
			save_event_target_as = old_location
		}

		random_independent_ruler = {
			limit = {
				is_catholic_branch = yes
				is_feudal = yes
				is_heretic = no
				higher_tier_than = COUNT
			}

			preferred_limit = {
				has_character_flag = charlemagne_enemy
			}

			preferred_limit = {
				has_landed_title = k_italy
			}

			preferred_limit = {
				higher_tier_than = DUKE
			}

			character_event = { id = CM.1076 }
		}
	}
}

# Foreign ruler receives Carloman's wife and children
character_event = {
	id = CM.1076
	desc = EVTDESC_CM_1076
	picture = GFX_evt_emissary

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1076 # Grant refuge

		FROM = {
			set_character_flag = carloman_refugee_wife

			hidden_effect = { # CleanSlate: Hopefully this stops her from wandering back to her parents in France
				add_trait = in_hiding
				set_character_flag = no_court_invites
				diplomatic_immunity = yes
				will_not_marry_effect = yes
			}

			any_child = {
				limit = { at_location = event_target:old_location }

				move_character = ROOT
				hidden_effect = { add_trait = in_hiding }
			}

			move_character = ROOT

			opinion = {
				name = opinion_saved_me_and_child
				who = ROOT
				years = 10
			}

			character_event = {
				id = CM.1079
				days = 10
			}
		}

		prestige = 300

		c_6392 = { # Charlemagne
			show_scope_change = no

			opinion = {
				name = opinion_furious
				who = ROOT
				years = 10
			}

			add_claim = ROOT # Grants claim on ROOT's primary title

			character_event = {
				id = CM.1077
				days = 1
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1076 # Don't grant refuge

		prestige = -30

		c_6392 = { # Charlemagne
			show_scope_change = no

			opinion = {
				name = opinion_approves
				who = ROOT
				years = 10
			}

			character_event = { id = CM.1078 }
		}

		ai_chance = { factor = 0 }
	}
}

# Refuge - notify Charlemagne
character_event = {
	id = CM.1077
	desc = EVTDESC_CM_1077
	picture = GFX_evt_spymaster

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_CM_1077

		tooltip = {
			add_claim = FROM
		}
	}
}

# No refuge - notify Charlemagne and receive wife and children
character_event = {
	id = CM.1078
	desc = EVTDESC_CM_1078
	picture = GFX_evt_emissary

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1078

		FROMFROM = {
			show_scope_change = no

			move_character = ROOT
			set_christian_ascetic_effect = yes

			any_child = {
				show_scope_change = no

				limit = {
					is_child_of = c_144999 # Carloman
					at_location = FROMFROM
				}

				move_character = ROOT
				set_christian_ascetic_effect = yes
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1078

		FROMFROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution_hanging
				killer = ROOT
			}

			any_child = {
				show_scope_change = no

				limit = {
					is_child_of = c_144999 # Carloman
					at_location = FROMFROM
				}

				death = {
					death_reason = death_execution_hanging
					killer = ROOT
				}
			}
		}

		add_trait_fully_silently_cruel_effect = yes
	}
}

# Dead Carloman's refugee wife surrenders to Charlemagne
character_event = {
	id = CM.1079

	is_triggered_only = yes
	hide_window = yes

	has_character_flag = carloman_refugee_wife
	only_capable = yes
	prisoner = no

	trigger = {
		is_vassal_or_below_of = c_6392 # Charlemagne

		any_child = {
			is_child_of = c_144999 # Carloman
			at_location = ROOT
		}
	}

	fail_trigger_effect = {
		if = {
			limit = {
				has_character_flag = carloman_refugee_wife

				c_6392 = { is_alive = yes } # Charlemagne

				any_child = {
					is_child_of = c_144999 # Carloman
				}
			}

			repeat_event = {
				id = CM.1079
				days = 10
			}
		}
		else = {
			clr_character_flag = no_court_invites
			diplomatic_immunity = no
			remove_trait = in_hiding
			remove_trait = cannot_marry
			remove_character_modifier = will_not_marry

			any_child = {
				limit = { is_child_of = c_144999 } # Carloman
				remove_trait = in_hiding
			}
		}
	}

	immediate = {
		clr_character_flag = carloman_refugee_wife
		clr_character_flag = no_court_invites
		diplomatic_immunity = no
		remove_trait = in_hiding
		remove_trait = cannot_marry
		remove_character_modifier = will_not_marry

		any_child = {
			limit = {
				is_child_of = c_144999 # Carloman
				is_vassal_or_below_of = c_6392
			}

			remove_trait = in_hiding
		}

		location = {
			save_event_target_as = old_location
		}

		c_6392 = { # Charlemagne
			character_event = { id = CM.1080 }
		}
	}
}

# Charlemagne receives Carloman's surrendered wife and children
character_event = {
	id = CM.1080
	desc = EVTDESC_CM_1080
	picture = GFX_evt_emissary

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1080

		FROM = {
			show_scope_change = no

			move_character = ROOT
			set_christian_ascetic_effect = yes

			any_child = {
				show_scope_change = no

				limit = {
					is_child_of = c_144999 # Carloman
					at_location = event_target:old_location
				}

				move_character = ROOT
				set_christian_ascetic_effect = yes
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1080

		FROM = {
			show_scope_change = no

			death = {
				death_reason = death_execution_hanging
				killer = ROOT
			}

			any_child = {
				show_scope_change = no

				limit = {
					is_child_of = c_144999 # Carloman
					at_location = event_target:old_location
				}

				death = {
					death_reason = death_execution_hanging
					killer = ROOT
				}
			}
		}

		add_trait_fully_silently_cruel_effect = yes
	}
}

# If Carloman's widow dies, remove her children from hiding so their not stuck in hiding forever
character_event = {
	id = CM.1081

	is_triggered_only = yes # on_death
	hide_window = yes

	has_character_flag = carloman_refugee_wife

	immediate = {
		any_child = {
			limit = { is_child_of = c_144999 } # Carloman
			remove_trait = in_hiding
		}
	}
}

###########################################
# The Saxon Wars                          #
###########################################

# Saxon wars begin
narrative_event = {
	id = CM.1100
	title = EVTTITLE_CM_1100
	desc = EVTDESC_CM_1100
	picture = GFX_evt_irminsul_shrine

	is_triggered_only = yes # on_yearly_pulse

	only_independent = yes
	religion_group = christian
	has_dlc = "Charlemagne"
	only_capable = yes
	min_age = 16
	prisoner = no
	war = no

	trigger = {
		higher_real_tier_than = DUKE
		year >= 772

		trigger_if = {
			limit = {
				c_6392 = { # Charlemagne
					independent = yes
				}
			}

			character = c_6392 # Charlemagne
		}
		trigger_else = {
			OR = {
				culture = frankish
				culture = french
			}

			is_feudal = yes
			year < 830
		}

		k_saxony = {
			is_contested = no

			holder_scope = {
				culture = saxon
				religion_openly_germanic_or_reformed_trigger = yes

				reverse_realm_levy_diff = {
					who = ROOT
					value >= 7500
				}

				NOR = {
					reverse_has_truce = ROOT
					is_allied_with = ROOT
					has_non_aggression_pact_with = ROOT
					is_married = ROOT
					pays_tribute_to = ROOT
				}
			}
		}

		NOR = {
			has_global_flag = saxon_wars

			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	option = {
		name = EVTOPTA_CM_1100 # Attack

		piety = 50
		add_claim = k_saxony

		war = {
			target = k_saxony
			casus_belli = claim
			thirdparty_title = k_saxony
			infamy = 0
		}

		set_global_flag = saxon_wars
	}

	option = {

		name = EVTOPTB_CM_1100 # Not now

		prestige = -100
		piety = -100
		set_global_flag = saxon_wars

		ai_chance = { factor = 0 }
	}
}

# Destruction of Irminsul ( **on_siege_over_winner** )
narrative_event = {
	id = CM.1101
	title = EVTTITLE_CM_1101
	desc = EVTDESC_CM_1101
	picture = GFX_evt_irminsul_burning

	is_triggered_only = yes # on_siege_over_winner

	religion_group = christian
	has_global_flag = saxon_wars
	has_dlc = "Charlemagne"

	trigger = {
		FROM = {
			title = b_paderborn
			is_holy_site = german_pagan

			holder_scope = {
				top_liege = {
					any_war = {
						attacker = { character = ROOT }
					}
				}
			}
		}

		NOT = { has_global_flag = irminsul }
	}

	immediate = {
		set_global_flag = irminsul
	}

	option = {
		name = EVTOPTA_CM_1101 # Burn it!

		prestige = 50
		piety = 100

		FROM = {
			show_scope_change = no

			location = {
				show_scope_change = no

				clr_province_flag = flag_great_pillar_norse_irminsul # Will permanently deactivate the building
			}

			holder_scope = {
				show_scope_change = no

				religion_authority = {
					name = irminsul_destroyed
					years = 10
				}
			}
		}

		b_eresburg = {
			show_scope_change = no

			destroy_settlement = THIS
		}

		custom_tooltip = {
			text = sacrilege_tooltip

			log = "Irminsul has been destroyed!"

			any_character = {
				limit = { religion_openly_norse_or_reformed_trigger = yes }

				add_character_modifier = { # Prevents rebuilding one immediately after
					name = recently_destroyed_great_pillar_cooldown
					years = 30
				}

				opinion = {
					name = opinion_sacrilege
					who = ROOT
					years = 10
				}
			}

			any_player = {
				limit = {
					independent = yes

					OR = {
						religion_openly_norse_or_reformed_trigger = yes
						religion_group = christian
					}

					NOT = { character = ROOT }
				}

				narrative_event = { id = CM.1102 } # Notify players of this
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1101 # Keep it and build a new Christian church on the site

		wealth = -50
		prestige = 20
		piety = 20

		ai_chance = { factor = 0 }
	}

	option = {
		name = EVTOPTC_CM_1101 # Leave it be

		piety = -30

		ai_chance = { factor = 0 }
	}
}

# Notify all Germanic and Christian players of destruction of Irminsul
narrative_event = {
	id = CM.1102
	title = EVTTITLE_CM_1102
	desc = EVTDESC_CM_1102
	picture = GFX_evt_irminsul_burning

	is_triggered_only = yes

	option = {
		name = {
			text = EVTOPTA_CM_1102
			trigger = {
				culture = saxon
				religion_openly_norse_or_reformed_trigger = yes
			}
		}
		name = {
			text = EVTOPTB_CM_1102
			trigger = {
				NOT = { culture = saxon }
				religion_openly_norse_or_reformed_trigger = yes
			}
		}
		name = {
			text = EVTOPTC_CM_1102
			trigger = { religion_group = christian }
		}
	}
}

# Blood court of Verden
narrative_event = {
	id = CM.1104
	title = EVTTITLE_CM_1104
	desc = EVTDESC_CM_1104
	picture = GFX_evt_beheading

	is_triggered_only = yes # on_yearly_pulse

	only_independent = yes
	religion_group = christian
	has_global_flag = saxon_wars
	has_dlc = "Charlemagne"
	only_capable = yes
	min_age = 16
	prisoner = no
	war = no

	trigger = {
		higher_real_tier_than = DUKE
		year < 900

		NOR = {
			has_global_flag = blood_court_of_verden
			culture = saxon
			religion_group = pagan_group
		}

		any_realm_province = {
			culture = saxon
			religion_openly_norse_or_reformed_trigger = yes
			held_under_PREV = yes
		}

		any_courtier = {
			prisoner = yes
			host = { character = ROOT }
			culture = saxon
			religion_openly_norse_or_reformed_trigger = yes
		}
	}

	immediate = {
		set_global_flag = blood_court_of_verden
	}

	option = {
		name = EVTOPTA_CM_1104 # Executions

		prestige = 100

		add_trait_fully_silently_cruel_effect = yes
		add_trait_fully_silently_zealous_effect = yes

		any_courtier = {
			show_scope_change = no

			limit = {
				prisoner = yes
				host = { character = ROOT }
				culture = saxon
				religion_openly_norse_or_reformed_trigger = yes
			}

			death = {
				death_reason = death_execution_beheading
				killer = ROOT
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1104 # Stay your hand

		prestige = -5
	}
}

# Emergence of Widukind
narrative_event = {
	id = CM.1105
	title = EVTTITLE_CM_1105
	desc = EVTDESC_CM_1105
	picture = GFX_evt_bandits

	is_triggered_only = yes # on_bi_yearly_pulse

	only_independent = yes
	has_dlc = "Charlemagne"
	has_global_flag = saxon_wars

	trigger = {
		trigger_if = {
			limit = {
				OR = {
					c_6392 = { is_alive = yes } # Charlemagne
					c_144999 = { is_alive = yes } # Carloman
				}
			}

			OR = {
				character = c_6392 # Charlemagne
				character = c_144999 # Carloman
			}
		}

		higher_real_tier_than = DUKE

		k_saxony = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_vassal_or_below_of = ROOT
					}
				}

				any_direct_de_jure_vassal_title = {
					holder_scope = {
						OR = {
							character = ROOT
							is_vassal_or_below_of = ROOT
						}
					}
				}
			}
		}

		any_realm_province = {
			culture = saxon
			religion_openly_norse_or_reformed_trigger = yes
			held_under_PREV = yes
		}

		NOR = {
			has_global_flag = widukind_spawned
			culture = saxon
			religion_group = pagan_group
		}
	}

	immediate = {
		set_global_flag = widukind_spawned
		set_character_flag = widukind_enemy
	}

	option = {
		name = EVTOPTA_CM_1105

		hidden_effect = {
			random_realm_province = {
				limit = {
					culture = saxon
					religion_openly_norse_or_reformed_trigger = yes
					held_under_PREV = yes
				}

				save_event_target_as = widukind_province_spawn
			}

			create_character = {
				random_traits = no
				dynasty = 7282
				religion = event_target:widukind_province_spawn
				culture = saxon
				age = 35
				female = no
				add_trait = honest
				add_trait = brave
				add_trait = diligent
				add_trait = proud
				add_trait = brilliant_strategist
				add_trait = aggressive_leader

				attributes = {
					diplomacy = 10
					martial = 10
					stewardship = 5
					intrigue = 6
					learning = 7
				}
			}

			new_character = {
				set_name = "Widukind"
				set_character_flag = is_widukind
				prestige = 100
				piety = 50

				save_global_event_target_as = widukind

				create_title = {
					tier = DUKE
					landless = yes
					temporary = yes
					culture = saxon
					name = WIDUKIND_ARMY
					holder = THIS
				}

				set_defacto_liege = THIS
			}

			# Give Widukind his claims
			k_saxony = {
				add_claim = event_target:widukind

				any_direct_de_jure_vassal_title = {
					add_claim = event_target:widukind
				}
			}

			# Widukind gets his army
			while = {
				count = 3

				spawn_unit = {
					owner = event_target:widukind
					province = event_target:widukind_province_spawn
					home = event_target:widukind_province_spawn
					attrition = 1.0

					troops = {
						archers = { 1000 1000 }
						light_infantry = { 1500 1500 }
						heavy_infantry = { 1000 1000 }
						light_cavalry = { 500 500 }
					}
				}
			}

			# Pick the most relevant target
			k_saxony = {
				if = {
					limit = {
						holder_scope = {
							OR = {
								character = ROOT
								is_vassal_or_below_of = ROOT
							}
						}
					}

					save_event_target_as = widukind_target
				}
				else = {
					random_direct_de_jure_vassal_title = {
						limit = {
							holder_scope = {
								OR = {
									character = ROOT
									is_vassal_or_below_of = ROOT
								}
							}
						}

						save_event_target_as = widukind_target
					}
				}
			}

			# Of course you realize, this means war.
			event_target:widukind = {
				war = {
					target = ROOT
					casus_belli = claim
					thirdparty_title = event_target:widukind_target
				}
			}

			clear_event_target = widukind_target
			clear_event_target = widukind_province_spawn
		}
	}
}

# Baptism of Widukind
narrative_event = {
	id = CM.1108
	title = EVTTITLE_CM_1108
	desc = EVTDESC_CM_1108
	picture = GFX_evt_bandits
	border = GFX_event_narrative_frame_religion
	portrait = event_target:widukind

	is_triggered_only = yes # on_yearly_pulse

	only_independent = yes
	religion_group = christian
	has_character_flag = widukind_enemy
	has_dlc = "Charlemagne"
	only_capable = yes
	min_age = 16
	prisoner = no
	war = no

	trigger = {
		higher_real_tier_than = DUKE

		event_target:widukind = {
			is_ruler = no
			prisoner = no
			religion_group = pagan_group
			is_incapable = no
		}
	}

	option = {
		name = EVTOPTA_CM_1108 # Accept him and baptize him

		event_target:widukind = {
			show_scope_change = no

			move_character = ROOT
			religion = ROOT
			remove_trait = zealous
			add_trait = sympathy_pagans
			set_character_flag = hero_knight
		}
	}

	option = {
		name = EVTOPTB_CM_1108 # Invite him here then kill him

		prestige = 30

		event_target:widukind = {
			show_scope_change = no

			move_character = ROOT

			death = {
				death_reason = death_execution_beheading
				killer = ROOT
			}
		}

		if = {
			limit = {
				NOT = { trait = deceitful }
			}

			remove_trait_silently_honest_effect = yes
			add_trait = deceitful
		}
	}

	option = {
		name = EVTOPTC_CM_1108 # Ignore him

		prestige = 10
	}

	after = {
		clear_global_event_target = widukind
	}
}

############################################
# Bertrada and Charlemagne murder Carloman #
############################################

# Bertrada suggests course of action - only hinting at murder
narrative_event = {
	id = CM.1120
	title = EVTTITLE_CM_1120
	desc = EVTDESC_CM_1120
	picture = GFX_evt_daughter_asking_father
	portrait = mother

	is_triggered_only = yes

	trigger = {
		c_144999 = { # Carloman
			is_alive = yes
		}

		mother = {
			is_alive = yes
			prisoner = no
		}
	}

	option = {
		name = EVTOPTA_CM_1120 # Yes do something

		c_144999 = { # Carloman
			character_event = {
				id = CM.1121
				days = 30
				random = 10
			}
		}

		ai_chance = { factor = 70 }
	}

	option = {
		name = EVTOPTB_CM_1120 # No

		ai_chance = { factor = 30 }
	}
}

# Bertrada comes to see Carloman
character_event = {
	id = CM.1121
	desc = EVTDESC_CM_1121
	picture = GFX_evt_emissary

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1121

		narrative_event = { id = CM.1122 } # Invite her in
	}

	option = {
		name = EVTOPTB_CM_1121 # Send her away

		ai_chance = { factor = 0 }
	}
}

# Bertrada offers Carloman poisoned wine
narrative_event = {
	id = CM.1122
	title = EVTTITLE_CM_1122
	desc = EVTDESC_CM_1122
	picture = GFX_evt_courtiers_talking

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1122

		character_event = { id = CM.1123 } # Drink the wine...
	}

	option = {
		name = EVTOPTB_CM_1122 # I don't trust you, please leave

		trigger = {
			NOT = { trait = drunkard }
		}

		remove_trait_silently_trusting_effect = yes

		ai_chance = { factor = 0 }
	}
}

# Carloman feels sick (poisoned)
character_event = {
	id = CM.1123
	desc = EVTDESC_CM_1123
	picture = GFX_evt_bad_news

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1123

		if = {
			limit = { ai = yes }

			character_event = {
				id = CM.1124 # Death a few days later
				days = 5
				random = 3
			}
		}
		else_if = {
			limit = { is_ill = yes }

			add_trait = infirm

			if = {
				limit = {
					NOT = { trait = pneumonic }
				}

				if = {
					limit = { has_dlc = "Reapers" }

					set_character_flag = disease_not_serious
					add_trait = vomiting

					character_event = {
						id = RIP.11005
						days = 10
						random = 30
					}
				}
				else = {
					add_trait_silently_ill_effect = yes
				}
			}
		}
	}
}

character_event = {
	id = CM.1124

	is_triggered_only = yes
	hide_window = yes

	immediate = {
		death = { death_reason = death_natural }
	}
}

# Vassal switches sides between Charlemagne/Carloman
letter_event = {
	id = CM.1132
	desc = EVTDESC_CM_1132
	portrait = event_target:switching_vassal

	is_triggered_only = yes # on_yearly_pulse, random_events

	has_dlc = "Charlemagne"
	has_character_flag = charlemagne_brother_rivalry

	trigger = {
		any_sibling = {
			has_character_flag = charlemagne_brother_rivalry
		}

		year < 820

		NOT = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}

		any_vassal = {
			ai = yes

			opinion = {
				who = ROOT
				value < 0
			}
		}

		trigger_if = {
			limit = { prestige < 0 }

			any_sibling = {
				has_character_flag = charlemagne_brother_rivalry
				prestige > 300
			}
		}
		trigger_else_if = {
			limit = { prestige < 200 }

			any_sibling = {
				has_character_flag = charlemagne_brother_rivalry
				prestige >= 1000
			}
		}
		trigger_else = {
			prestige < 1000

			any_sibling = {
				has_character_flag = charlemagne_brother_rivalry
				prestige >= 10000
			}
		}

		in_revolt = no
		pf_war_trait_trigger = no
	}

	weight_multiplier = {
		factor = 15
	}

	immediate = {
		random_vassal = {
			limit = {
				ai = yes

				opinion = {
					who = ROOT
					value < 0
				}
			}

			save_event_target_as = switching_vassal
		}
	}

	option = {
		name = EVTOPTA_CM_1132

		random_sibling = {
			show_scope_change = no

			limit = { has_character_flag = charlemagne_brother_rivalry }

			event_target:switching_vassal = {
				show_scope_change = no

				set_defacto_liege = PREV
				pf_liege_change_effect = yes
			}
		}
	}
}

###################################################################
#                                                                 #
# Bertrada meddles in everything CM.1150-1399                     #
#                                                                 #
# Any of these events can happen to any player character's mother #
# if she gets the flag meddling_mother                            #
###################################################################

# Your mother starts to meddle in your affairs (hidden)
character_event = {
	id = CM.1150

	is_triggered_only = yes # on_yearly_pulse, random_events
	hide_window = yes

	ai = no
	has_dlc = "Charlemagne"

	trigger = {
		mother = {
			is_alive = yes
			vassal_of = ROOT
			is_ruler = no

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

	weight_multiplier = {
		factor = 1

		mult_modifier = {
			factor = 5
			mother = { culture = mongol }
		}
	}

	immediate = {
		mother = {
			set_character_flag = meddling_mother
		}
	}
}

# Mother dislikes your spouse
character_event = {
	id = CM.1160
	desc = EVTDESC_CM_1160
	picture = GFX_evt_daughter_asking_father

	is_triggered_only = yes # on_yearly_pulse, random_events

	ai = no
	is_married = yes
	has_dlc = "Charlemagne"
	min_age = 16
	only_capable = yes
	prisoner = no
	in_command = no

	trigger = {
		is_inaccessible_trigger = no
		has_polygamy = no

		mother = {
			has_character_flag = meddling_mother
			is_ascetic_trigger = no
			is_incapable = no
			prisoner = no
		}

		spouse = {
			is_ruler = no
			vassal_of = ROOT

			OR = {
				trait = ambitious
				trait = proud
				trait = diligent
				is_smart_trigger = yes
			}

			NOR = {
				is_mother = ROOT
				has_character_flag = meddling_mother_conflict
			}
		}
	}

	weight_multiplier = {
		factor = 10
	}

	immediate = {
		spouse = {
			set_character_flag = meddling_mother_conflict
			save_event_target_as = target_spouse
		}

		mother = {
			save_event_target_as = target_mother
		}
	}

	option = {
		name = EVTOPTA_CM_1160 # Yes mother

		set_character_flag = meddling_mother_gone_too_far

		spouse = {
			show_scope_change = no

			if = {
				limit = { is_lover = ROOT }
				remove_lover = ROOT
			}

			opinion = {
				name = opinion_bitter
				who = ROOT
				years = 5
			}
		}

		event_target:target_mother = {
			show_scope_change = no

			opinion = {
				name = opinion_dislike
				who = event_target:target_spouse
				years = 100
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1160 # No mother

		event_target:target_mother = {
			show_scope_change = no

			opinion = {
				name = opinion_hate
				who = event_target:target_spouse
				years = 100
			}

			reverse_opinion = {
				name = opinion_dislike
				who = event_target:target_spouse
				years = 100
			}

			opinion = {
				name = opinion_angry
				who = ROOT
				years = 3
			}
		}
	}

	option = {
		name = EVTOPTC_CM_1160  # Send her to a convent

		trigger = {
			mother = { has_character_flag = meddling_mother_gone_too_far }
			religion_group = christian
			NOT = { trait = craven }
		}

		event_target:target_mother = {
			show_scope_change = no

			set_christian_ascetic_effect = yes

			opinion = {
				name = opinion_hate
				who = event_target:target_spouse
				years = 100
			}

			opinion = {
				name = opinion_bitter
				who = ROOT
				years = 10
			}
		}
	}
}

# Mother dislikes your councillor

character_event = {
	id = CM.1172
	desc = EVTDESC_CM_1172
	picture = GFX_evt_daughter_asking_father

	is_triggered_only = yes # on_yearly_pulse, random_events

	ai = no
	min_age = 16
	only_capable = yes
	has_dlc = "Charlemagne"
	in_command = no
	prisoner = no

	trigger = {
		is_inaccessible_trigger = no

		mother = {
			has_character_flag = meddling_mother
			is_ascetic_trigger = no
			is_incapable = no
			prisoner = no
		}

		any_courtier = {
			is_councillor = yes

			OR = {
				trait = ambitious
				trait = proud
				trait = diligent
				is_smart_trigger = yes
			}

			NOR = {
				has_character_flag = meddling_mother_conflict
				is_mother = ROOT
				is_parent_of = ROOT
			}
		}
	}

	weight_multiplier = {
		factor = 10
	}

	immediate = {
		any_courtier = {
			limit = {
				is_councillor = yes

				OR = {
					trait = ambitious
					trait = proud
					trait = diligent
					is_smart_trigger = yes
				}

				vassal_of = ROOT
				NOT = { is_parent_of = ROOT }
			}

			score_value = {
				value = 10
				interesting_courtier_selection_score = yes
			}

			set_character_flag = meddling_mother_conflict
			save_event_target_as = target_councillor
		}

		mother = {
			save_event_target_as = target_mother
		}
	}

	option = {
		name = EVTOPTA_CM_1172 # Yes mother

		set_character_flag = meddling_mother_gone_too_far

		event_target:target_councillor = {
			show_scope_change = no

			if = {
				limit = { is_lover = ROOT }
				remove_lover = ROOT
			}

			trigger_switch = {
				on_trigger = has_job_title

				job_chancellor = { remove_title = job_chancellor }
				job_marshal    = { remove_title = job_marshal }
				job_treasurer  = { remove_title = job_treasurer }
				job_spymaster  = { remove_title = job_spymaster }
				job_spiritual  = { remove_title = job_spiritual }
			}

			if = {
				limit = { is_ruler = no }
				banish = yes
			}

			prestige = -30

			opinion = {
				name = opinion_fired_from_council
				who = ROOT
				years = 5
			}
		}

		event_target:target_mother = {
			show_scope_change = no

			opinion = {
				who = event_target:target_councillor
				years = 100
				name = opinion_dislike
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1172 # No mother

		event_target:target_mother = {
			show_scope_change = no

			prestige = -30

			opinion = {
				name = opinion_hate
				who = event_target:target_councillor
				years = 100
			}

			reverse_opinion = {
				name = opinion_dislike
				who = event_target:target_councillor
				years = 100
			}

			opinion = {
				name = opinion_angry
				who = ROOT
				years = 3
			}
		}
	}

	option = {
		name = EVTOPTC_CM_1172 # Send her to a convent

		trigger = {
			mother = { has_character_flag = meddling_mother_gone_too_far }
			religion_group = christian
			NOT = { trait = craven }
		}

		event_target:target_mother = {
			show_scope_change = no

			set_christian_ascetic_effect = yes

			opinion = {
				name = opinion_hate
				who = event_target:target_councillor
				years = 100
			}

			opinion = {
				name = opinion_bitter
				who = ROOT
				years = 10
			}
		}
	}
}

# Mother insists on being regent
character_event = {
	id = CM.1180

	is_triggered_only = yes # on_yearly_pulse, random_events
	hide_window = yes

	ai = no
	has_dlc = "Charlemagne"
	in_command = no
	prisoner = no

	trigger = {
		has_regent = yes

		mother = {
			has_character_flag = meddling_mother
			is_ascetic_trigger = no
			is_incapable = no
			prisoner = no
			NOT = { has_minor_title = title_regent }
		}

		regent = {
			ai = yes
			NOT = { has_character_flag = meddling_mother_conflict }
		}

		is_inaccessible_trigger = no
	}

	weight_multiplier = {
		factor = 100
	}

	immediate = {
		mother = {
			save_event_target_as = target_mother
		}

		regent = {
			set_character_flag = meddling_mother_conflict
			character_event = { id = CM.1181 }
		}
	}
}

character_event = {
	id = CM.1181
	desc = EVTDESC_CM_1181
	picture = GFX_evt_throne_room

	is_triggered_only = yes

	option = {
		name = I_SEE

		tooltip = {
			remove_title = title_regent

			event_target:target_mother = {
				show_scope_change = no

				give_minor_title = title_regent
			}
		}

		FROM = {
			character_event = { id = CM.1182 }
		}
	}

	option = {
		name = EVTOPTB_CM_1181 # Fight it

		add_rival = event_target:target_mother

		ai_chance = { factor = 0 }
	}
}

character_event = {
	id = CM.1182
	desc = EVTDESC_CM_1182
	picture = GFX_evt_throne_room

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1182 # Mother knows best

		trigger = {
			NOT = { has_character_flag = meddling_mother_gone_too_far }
		}

		set_character_flag = meddling_mother_gone_too_far

		FROM = {
			show_scope_change = no

			remove_title = title_regent
		}

		mother = {
			show_scope_change = no

			give_minor_title = title_regent
		}
	}

	option = {
		name = EVTOPTB_CM_1182 # Hmm, who really rules here?

		trigger = { has_character_flag = meddling_mother_gone_too_far }

		FROM = {
			show_scope_change = no

			remove_title = title_regent
		}

		mother = {
			show_scope_change = no

			give_minor_title = title_regent
		}
	}
}

# Mother seduces your spouse
character_event = {
	id = CM.1192
	desc = EVTDESC_CM_1192
	picture = GFX_evt_lovers

	is_triggered_only = yes

	ai = no
	is_married = yes
	has_dlc = "Charlemagne"
	min_age = 16
	only_capable = yes
	prisoner = no
	in_command = no

	trigger = {
		is_inaccessible_trigger = no

		mother = {
			has_character_flag = meddling_mother
			is_ascetic_trigger = no
			is_incapable = no
			prisoner = no
		}

		any_spouse = {
			ROOT = {
				mother = {
					is_valid_romance_target = PREVPREV
				}
			}

			vassal_of = ROOT
			ai = yes

			OR = {
				trait = humble
				trait = slow
				trait = dull
				trait = stressed
				trait = depressed
				has_fair_trait_trigger = yes
			}

			NOR = {
				trait = celibate
				has_character_flag = meddling_mother_conflict
				is_mother = ROOT
			}
		}
	}

	weight_multiplier = {
		factor = 10
	}

	immediate = {
		mother = {
			save_event_target_as = target_mother
		}

		random_spouse = {
			limit = {
				is_valid_romance_target = event_target:target_mother
				vassal_of = ROOT
				ai = yes

				OR = {
					trait = humble
					trait = slow
					trait = dull
					trait = stressed
					trait = depressed
					has_fair_trait_trigger = yes
				}

				NOR = {
					trait = celibate
					has_character_flag = meddling_mother_conflict
					is_mother = ROOT
				}
			}

			save_event_target_as = target_spouse
			add_lover = event_target:target_mother
		}
	}

	option = {
		name = EVTOPTA_CM_1192 # Accept

		set_character_flag = meddling_mother_gone_too_far
	}

	option = {
		name = EVTOPTB_CM_1192 # Send spouse to convent

		set_character_flag = meddling_mother_gone_too_far
		remove_spouse = event_target:target_spouse

		event_target:target_spouse = {
			show_scope_change = no

			set_christian_ascetic_effect = yes
		}
	}

	option = {
		name = EVTOPTC_CM_1192  # Send mother to a convent

		trigger = {
			religion_group = christian
			NOT = { trait = craven }

			mother = {
				has_character_flag = meddling_mother_gone_too_far
				vassal_of = ROOT
				is_ruler = no
			}
		}

		event_target:target_mother = {
			show_scope_change = no

			set_christian_ascetic_effect = yes
			remove_lover = event_target:target_spouse

			opinion = {
				name = opinion_hate
				who = event_target:target_spouse
				years = 100
			}

			opinion = {
				name = opinion_bitter
				who = ROOT
				years = 10
			}
		}
	}

	option = {
		name = EVTOPTD_CM_1192  # Send them both to the orders

		trigger = {
			mother = {
				has_character_flag = meddling_mother_gone_too_far
				vassal_of = ROOT
				is_ruler = no
			}

			religion_group = christian
			NOT = { trait = craven }
		}

		event_target:target_spouse = {
			show_scope_change = no

			set_christian_ascetic_effect = yes
		}

		event_target:target_mother = {
			show_scope_change = no

			set_christian_ascetic_effect = yes
			remove_lover = event_target:target_spouse

			opinion = {
				name = opinion_hate
				who = event_target:target_spouse
				years = 100
			}

			opinion = {
				name = opinion_bitter
				who = ROOT
				years = 10
			}
		}
	}

	option = {
		name = EVTOPTE_CM_1192 # The dungeon

		trigger = {
			has_character_flag = meddling_mother_gone_too_far
			NOT = { religion_group = christian }
		}

		reverse_imprison = mother
		reverse_imprison = event_target:target_spouse
	}
}

#################################
#  Spanish Campaign             #
#  CM.1400-1499                 #
#################################

# Umayyad vassal calls upon Charlemagne to support rebellion in exchange for vassalization
character_event = {
	id = CM.1400

	is_triggered_only = yes # on_yearly_pulse
	hide_window = yes

	only_independent = yes
	religion_group = christian
	has_dlc = "Charlemagne"
	min_age = 16
	only_capable = yes
	prisoner = no
	war = no

	trigger = {
		# Charlemagne, or Carloman, or any Frankish or French King or above before 820
		trigger_if = {
			limit = {
				c_6392 = { # Charlemagne
					independent = yes
				}
			}

			character = c_6392 # Charlemagne
		}
		trigger_else_if = {
			limit = {
				c_144999 = { # Carloman
					independent = yes
				}
			}

			character = c_144999 # Carloman
		}
		trigger_else = {
			OR = {
				culture = french
				culture = frankish
			}
		}

		higher_real_tier_than = DUKE
		year >= 777
		year < 820

		# Umayyads rule in Spain
		any_independent_ruler = {
			dynasty = 597 # Umayyad

			OR = {
				has_landed_title = e_hispania
				has_landed_title = k_andalusia
			}

			any_vassal = {
				is_adult = yes
				is_incapable = no
				prisoner = no
				lower_real_tier_than = ROOT
				higher_real_tier_than = BARON

				NOR = {
					is_friend = PREV
					dynasty = 597 # Umayyad
				}
			}
		}

		in_revolt = no
		pf_war_trait_trigger = no

		NOR = {
			has_game_rule = {
				name = charlemagne_story
				value = off
			}

			has_global_flag = charlemagne_spain_intervention
		}
	}

	immediate = {
		set_global_flag = charlemagne_spain_intervention

		# Umayyads rule in Spain
		random_independent_ruler = {
			limit = {
				dynasty = 597 # Umayyad

				OR = {
					has_landed_title = e_hispania
					has_landed_title = k_andalusia
				}

				any_vassal = {
					is_adult = yes
					is_incapable = no
					prisoner = no
					lower_real_tier_than = ROOT
					higher_real_tier_than = BARON

					NOR = {
						is_friend = PREV
						dynasty = 597 # Umayyad
					}
				}
			}

			random_vassal = {
				limit = {
					is_adult = yes
					is_incapable = no
					prisoner = no
					lower_real_tier_than = ROOT
					num_of_vassals >= 1
					NOT = { dynasty = 597 } # Umayyad
				}

				preferred_limit = {
					real_tier = KING
				}

				preferred_limit = {
					real_tier = DUKE
				}

				character_event = { id = CM.1401 }
			}
		}
	}
}

# Umayyad vassal - ask Charlemagne for support?
character_event = {
	id = CM.1401
	desc = EVTDESC_CM_1401
	picture = GFX_evt_throne_room
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { ai = yes }

			opinion = {
				name = opinion_hate
				who = liege
				years = 5
			}

			add_rival = liege
		}
	}

	option = {
		name = EVTOPTA_CM_1401 # Send a message to Charlemagne

		FROM = {
			narrative_event = {
				id = CM.1402
				days = 20
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1401 # Don't send it

		random = {
			chance = 30
			add_trait_fully_content_effect = yes
		}

		ai_chance = { factor = 0 }
	}
}

# Frankish King receives embassy
narrative_event = {
	id = CM.1402
	title = EVTTITLE_CM_1402
	desc = EVTDESC_CM_1402
	picture = GFX_evt_emissary
	border = GFX_event_narrative_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1402 # Sign an agreement and prepare for war

		FROM = {
			character_event = {
				id = CM.1404
				days = 20
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1402 # Decline

		prestige = -30

		FROM = {
			character_event = {
				id = CM.1403
				days = 20
			}
		}

		ai_chance = { factor = 0 }
	}
}

# Vassal receives negative answer from Franks
character_event = {
	id = CM.1403
	desc = EVTDESC_CM_1403
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	ai = no

	option = {
		name = EVTOPTA_CM_1403
	}
}

# Vassal receives positive answer from Franks
character_event = {
	id = CM.1404
	desc = EVTDESC_CM_1404
	picture = GFX_evt_emissary
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1404 # Prepare for war

		character_event = {
			id = CM.1405 # Prepare for war
			months = 2
		}
	}
}

# Vassal declares independence war
character_event = {
	id = CM.1405
	desc = EVTDESC_CM_1405
	picture = GFX_evt_large_army
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	immediate = {
		liege = {
			save_event_target_as = target_liege
		}
	}

	option = {
		name = EVTOPTA_CM_1405 # Declares independence war

		war = {
			target = event_target:target_liege
			casus_belli = bid_for_independence
		}

		FROMFROM = {
			character_event = {
				id = CM.1406 # Calls on Frankish ally
				days = 20
			}
		}
	}
}

# Frankish King decides whether to honor promise or not
character_event = {
	id = CM.1406
	desc = EVTDESC_CM_1406
	picture = GFX_evt_large_army
	border = GFX_event_normal_frame_war

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1406 # Go to war

		FROM = {
			show_scope_change = no

			set_character_flag = supported_by_franks

			opinion = {
				name = honored_alliance
				who = ROOT
				years = 10
			}
		}

		join_attacker_wars = FROM
		set_character_flag = intervention_in_spain

		ai_chance = {
			factor = 80

			mult_modifier = {
				factor = 1.5
				trait = brave
			}

			mult_modifier = {
				factor = 0.5

				any_war = {
					using_cb = bid_for_independence
					attacker = { character = FROM }

					defender = {
						realm_levy_diff = {
							who = ROOT
							value >= 1000
						}
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				any_war = {
					using_cb = bid_for_independence
					attacker = { character = FROM }

					defender = {
						realm_levy_diff = {
							who = ROOT
							value >= 10000
						}
					}
				}
			}

			mult_modifier = {
				factor = 5

				any_war = {
					using_cb = bid_for_independence
					attacker = { character = FROM }

					defender = {
						reverse_realm_levy_diff = {
							who = ROOT
							value >= 2500
						}
					}
				}
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1406 # Betray promise

		prestige = -100

		FROM = {
			show_scope_change = no

			opinion = {
				name = opinion_betrayed
				who = ROOT
				years = 10
			}

			character_event = {
				id = CM.1410
				days = 20
			}
		}

		add_trait_fully_silently_deceitful_effect = yes

		ai_chance = {
			factor = 20

			trigger = {
				NOT = { trait = honest }
			}

			mult_modifier = {
				factor = 2
				trait = deceitful
			}
		}
	}
}

# Peace is concluded with established independence
character_event = {
	id = CM.1407

	is_triggered_only = yes # OFFER_PEACE_INTERACTION_ACCEPT_EVENT
	hide_window = yes

	only_independent = yes

	trigger = {
		OR = {
			has_character_flag = supported_by_franks
			FROM = { has_character_flag = supported_by_franks }
		}

		any_independent_ruler = {
			has_character_flag = intervention_in_spain
			higher_real_tier_than = ROOT
		}
	}

	immediate = {
		if = {
			limit = { has_character_flag = supported_by_franks }

			clr_character_flag = supported_by_franks
			character_event = { id = CM.1408 }
		}

		FROM = {
			if = {
				limit = { has_character_flag = supported_by_franks }

				clr_character_flag = supported_by_franks
				character_event = { id = CM.1408 }
			}
		}
	}
}

# Fulfill promise to Frankish king?
character_event = {
	id = CM.1408
	desc = EVTDESC_CM_1408
	picture = GFX_evt_throne_room
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = EVTOPTA_CM_1408 # Fullfill promise

		random_independent_ruler = {
			show_scope_change = no

			limit = { has_character_flag = intervention_in_spain }

			set_defacto_vassal = ROOT

			opinion = {
				name = honored_alliance
				who = ROOT
				years = 10
			}

			ROOT = {
				show_scope_change = no

				religion = PREV

				hidden_effect = {
					any_courtier = {
						limit = {
							is_ruler = no
							prisoner = no
							is_incapable = no
							NOT = { trait = zealous }
						}

						religion = PREV
					}
				}
			}
		}

		ai_chance = {
			factor = 80

			mult_modifier = {
				factor = 0.5
				trait = deceitful
			}
		}
	}

	option = {
		name = EVTOPTB_CM_1408 # Betray promise

		prestige = -50

		random_independent_ruler = {
			show_scope_change = no

			limit = { has_character_flag = intervention_in_spain }

			opinion = {
				name = opinion_betrayed
				who = ROOT
				years = 10
			}

			character_event = {
				id = CM.1409 # Betray promise
				days = 20
			}
		}

		add_trait_fully_silently_deceitful_effect = yes

		ai_chance = {
			factor = 20

			mult_modifier = {
				factor = 0.5
				trait = honest
			}

			mult_modifier = {
				factor = 0.1

				any_independent_ruler = {
					has_character_flag = intervention_in_spain
					religion = ROOT
				}
			}
		}
	}
}

# Frankish King is notified of betrayal
character_event = {
	id = CM.1409
	desc = EVTDESC_CM_1409
	picture = GFX_evt_throne_room_arabic
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	option = {
		name = {
			text = EVTOPTA_CM_1409
			trigger = {
				NOT = { culture = FROM }
			}
		}
		name = {
			text = EVTOPTB_CM_1409
			trigger = { culture = FROM }
		}

		add_claim = FROM

		tooltip = {
			opinion = {
				name = opinion_betrayed
				who = FROM
				years = 10
			}
		}
	}
}

# Umayyad vassal is notified of Frankish betrayal
character_event = {
	id = CM.1410
	desc = EVTDESC_CM_1410
	picture = GFX_evt_throne_room
	border = GFX_event_normal_frame_diplomacy

	is_triggered_only = yes

	ai = no

	option = {
		name = {
			text = EVTOPTA_CM_1409
			trigger = {
				NOT = { culture = FROM }
			}
		}
		name = {
			text = EVTOPTB_CM_1409
			trigger = { culture = FROM }
		}

		tooltip = {
			opinion = {
				name = opinion_betrayed
				who = FROM
				years = 10
			}
		}
	}
}

##########################
# Coronation to Emperor  #
##########################

# Coronation of Charlemagne
narrative_event = {
	id = CM.1500
	title = EVTTITLE_CM_1500
	desc = EVTDESC_CM_1500
	picture = GFX_evt_coronation

	is_triggered_only = yes # on_create_title
	major = yes

	has_dlc = "Charlemagne"
	has_character_flag = is_charlemagne

	trigger = {
		real_tier = EMPEROR

		NOR = {
			has_character_flag = charlemagne_coronation

			has_game_rule = {
				name = charlemagne_story
				value = off
			}
		}
	}

	major_trigger = {
		ai = no

		capital_scope = {
			ROOT = {
				capital_scope = {
					distance = {
						where = PREVPREV
						distance < 1200
					}
				}
			}
		}
	}

	immediate = {
		set_character_flag = charlemagne_coronation

		# Reset Eastern Roman Empire to Byzantine Empire
		e_byzantium = {
			set_name = ""
			adjective = ""
		}

		remove_character_modifiers = {
			name = uncrowned_modifier
			amount = 30
		}

		religion_head = {
			save_event_target_as = coronation_priest

			ROOT = {
				save_persistent_event_target = {
					name = coronation_priest_per
					scope = PREV
				}
			}
		}
	}

	option = {
		name = EVTOPTA_CM_510

		trigger = {
			OR = {
				character = ROOT
				vassal_of = ROOT

				trigger_if = {
					limit = { dynasty = ROOT }
					NOT = { is_rival = ROOT }
				}
			}
		}

		if = {
			limit = { has_character_flag = is_charlemagne }

			if = {
				limit = {
					NOR = {
						has_landed_title = e_hre
						has_landed_title = e_karling
					}
				}
				add_trait = crowned
			}
			else = {
				add_trait = crowned_by_pope
			}

			add_artifact = crown_hre

			if = {
				limit = { has_nickname = no }
				give_nickname = nick_the_great
			}
		}
	}

	option = {
		name = {
			text = EVTOPTB_CM_510
			trigger = {
				religion = ROOT
				NOT = { has_landed_title = e_byzantium }
			}
		}
		name = {
			text = EVTOPTC_CM_510
			trigger = {
				NOR = {
					religion = ROOT
					has_landed_title = e_byzantium
				}
			}
		}
		name = {
			text = EVTOPTD_CM_510
			trigger = { has_landed_title = e_byzantium }
		}

		trigger = {
			NOR = {
				character = ROOT
				vassal_of = ROOT
			}

			trigger_if = {
				limit = { dynasty = ROOT }
				is_rival = ROOT
			}
		}
	}
}