﻿
namespace = bookmark


###############################
# 867 - WRATH OF THE NORTHMEN #
###############################

###Æthelred isn't as cool as Alfred so we kill him
bookmark.0001 = { #by Mathilda Bjarnehed
	type = character_event
	hidden = yes
	
	trigger = {
		this = character:33358 #Æthelred
		is_ai = yes
		player_heir ?= character:7627 #Alfred the Great
	}

	immediate = {
		if = {
			limit = { is_at_war = yes }

			random_list = {
				20 = { #Very wounded
					increase_wounds_effect = { REASON = battle }
					if = {
						limit = { is_alive = yes }
						increase_wounds_effect = { REASON = battle }
					}
					if = {
						limit = { is_alive = yes }
						increase_wounds_effect = { REASON = battle }
					}
					if = {
						limit = { is_alive = yes }
						increase_wounds_effect = { REASON = battle }
					}
				}
				80 = { #Killed
					random_war_enemy = {
						if = {
							limit = { is_commanding_army = yes }
							save_scope_as = killer
						}
						else = {
							random_knight = {
								save_scope_as = killer
							}
						}
					}
					if = {
						limit = { exists = scope:killer }
						death = {
							death_reason = death_hunting_accident
							killer = scope:killer
						}
					}
				}
			}	
		}
		else = {
			random_list = {
				10 = { #Cancer
					contract_disease_effect = { DISEASE = cancer TREATMENT_EVENT = no }
				}
				90 = { #Hunting accident
					death = {
						death_reason = death_hunting_accident
					}
				}
			}	
		}
	}
}
		
### Alfred is pretty cool so we give him a nickname
bookmark.0002 = { #by Mathilda Bjarnehed
	type = character_event
	title = bookmark.0002.t
	desc = bookmark.0002.desc
	theme = crown
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	
	trigger = {
		is_ai = no
		top_liege = this
	}

	#Resend
	on_trigger_fail = {
		if = {
			limit = { is_ai = no }
			trigger_event = {
				id = bookmark.0002
				days = 1800 #~5 years
			}
		}
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		capital_province = { save_scope_as = capital }
		random_realm_province = {
			limit = { this != scope:capital }
			save_scope_as = province
		}
		give_nickname = nick_the_great
	}

	option = {
		name = bookmark.0002.a
	}
}

### The Ragnarsson brothers catch King Aella ##
# The event can trigger when you imprison Aella as one of his sons
# It also works for other norse!

bookmark.0003 = { #by Mathilda Bjarnehed
	type = character_event
	hidden = yes
	
	trigger = {
		scope:imprisoner.faith = { trait_is_virtue = vengeful }
		scope:imprisoner = {
			any_close_family_member = {
				even_if_dead = yes
				killer ?= root
				save_temporary_scope_as = killed_character
			}
		}
		#If the imprisoner don't know you're the killer you might reveal yourself if you're dumb or not sneaky
		trigger_if = {
			limit = {
				any_secret = {
					type = secret_murder
					secret_target = scope:killed_character
					NOT = { any_secret_knower = { this = scope:imprisoner } }
				}
			}
			OR = {
				has_trait = intellect_bad
				has_trait = dull
				intrigue <= medium_skill_rating
			}
			NOR = {
				has_trait = shrewd
				has_trait = intellect_good
				has_trait = schemer
			}
		}
		trigger_if = {
			limit = { this = character:163103 } #Aella
			NOT = {
				is_target_in_global_variable_list = {
					name = triggered_bookmark_events
					target = flag:bookmark_867_northmen_aellas_capture
				}
			}
		}
	}

	immediate = {
		if = {
			limit = { this = character:163103 } #Aella
			add_to_global_variable_list = {
				name = triggered_bookmark_events
				target = flag:bookmark_867_northmen_aellas_capture
			}
		}
		save_scope_as = prisoner

		scope:imprisoner = {
			random_close_family_member = {
				even_if_dead = yes
				limit = {
					killer ?= root
					this = character:163109 #Lodbrok
				}
				alternative_limit = {
					killer ?= root
				}
				save_scope_as = dead
			}
			trigger_event = {
				id = bookmark.0004
				days = 1
			}
		}
	}
}

bookmark.0004 = { #by Mathilda Bjarnehed
	type = character_event
	title = bookmark.0004.t
	desc = {
		first_valid = {
			triggered_desc = {
			    trigger = { #You did not know they had killed your family-member
					scope:prisoner = {
						any_secret = {
	    					type = secret_murder
	    					secret_target = scope:dead
	    					NOT = { any_secret_knower = { this = root } }
	    				}
					}
			    }
			    desc = bookmark.0004.desc_unknown
			}
			desc = bookmark.0004.desc
		}
	}
	theme = dungeon
	left_portrait = {
		character = scope:prisoner
		animation = fear
	}
	lower_right_portrait = scope:dead

	trigger = {
		NOT = {
			any_in_list = {
				list = captured_rivals
				this = scope:prisoner
			}
		}
	}
	
	immediate = {
		play_music_cue = "mx_cue_murder"
		if = {
			limit = {
				scope:prisoner = {
					any_secret = {
    					type = secret_murder
    					secret_target = scope:dead
    					NOT = { any_secret_knower = { this = root } }
    				}
				}
			}
			scope:prisoner = {
				random_secret = {
					type = secret_murder
					limit = {
						secret_target = scope:dead
						NOT = { any_secret_knower = { this = root } }
					}
					reveal_to = root
				}
			}
		}
	}

	#Blood eagle
	option = {
		name = bookmark.0004.a
		
		add_dread = medium_dread_gain
		add_prestige = medium_prestige_gain
		scope:prisoner = {
			death = {
				death_reason = death_execution_blood_eagle
				killer = root
			}
		}
		scope:dead = {
			every_close_family_member = {
				custom = bookmark.0004.a.custom
				limit = { this != root }
				add_opinion = {
					modifier = pleased_opinion
					opinion = 30
					target = root
				}
			}
		}
		execute_opinion_effect = { VICTIM = scope:prisoner EXECUTIONER = root }

		ai_chance = {
			base = 50
			modifier = {
				scope:dead = character:163109 #Lodbrok
				add = 1000
			}
		}
	}

	#Sacrifice to Odin
	option = {
		name = bookmark.0004.b
		trigger = { faith = { has_doctrine_parameter = human_sacrifice_active } }

		add_piety = major_piety_gain
		scope:prisoner = {
			death = {
				death_reason = death_execution_blood_eagle
				killer = root
			}
		}
		scope:dead = {
			every_close_family_member = {
				custom = bookmark.0004.a.custom
				limit = { this != root }
				add_opinion = {
					modifier = pleased_opinion
					opinion = 30
					target = root
				}
			}
		}
		execute_opinion_effect = { VICTIM = scope:prisoner EXECUTIONER = root }

		ai_chance = {
			base = 50
		}
	}
	
	#I have other plans...
	option = {
		name = bookmark.0004.c
		
		ai_chance = {
			base = 0
			modifier = {
				ai_vengefulness <= medium_negative_ai_value
				add = 100
			}
		}
	}
}

###############################
# 867 - THE GREAT ADVENTURERS #
###############################

###	Daurama takes Bawo under her wing.
bookmark.0101 = {
	type = character_event
	title = bookmark.0101.t
	desc = {
		desc = bookmark.0101.desc_intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:bayajidda = { is_alive = yes }
				}
				desc = bookmark.0101.desc_living
			}
			desc = bookmark.0101.desc_dead
		}
	}
	theme = crown
	left_portrait = {
		character = root
		animation = personality_rational
	}
	right_portrait = {
		character = scope:bayajidda
	}
	lower_center_portrait = {
		character = scope:bewo
	}

	trigger = {
		is_ai = no
		character:251181 = { is_alive = yes }
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		character:251180 = { save_scope_as = bayajidda }
		character:251181 = { save_scope_as = bewo }
		character:251252 = { save_scope_as = shawata }
		title:k_hausaland = { save_scope_as = hausaland}
	}

	# Remember your heritage, my child.
	option = {
		name = bookmark.0101.a

		#Move Bewo to Daurama's house.
		custom_tooltip = bookmark.0101.a.tt
		character:251181 = { set_house = root.house }
		add_courtier = character:251181 #Move him to your court

		#Bayajidda is, understandably, a little hurt by all this.
		character:251180 = {
			add_opinion = {
				modifier = hurt_opinion
				target = root
				opinion = -20
			}
		}

		ai_chance = {
			base = 0	#The AI should never get this event, but if they do, shouldn't opt in.
		}
	}
	
	# He is my blood, whatever his name.
	option = {
		name = bookmark.0101.b

		character:251180 = {
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 40
			}
		}
		custom_tooltip = bookmark.0101.b.tt

		ai_chance = {
			base = 100	#AI doesn't get this event, but should always pick no.
		}
	}

	# The Magajiya will continue to rule!
	option = {
		name = bookmark.0101.c

		add_realm_law_skip_effects = female_preference_law
		scope:bewo = { 
			set_house = root.house
			add_trait = disinherited
		}
		scope:shawata = {	
			if = {
				limit = {
					is_alive = yes
					OR = {
						matrilinear_marriage = yes
						is_married = no
					}
				}
				custom_tooltip = bookmark.0101.c.tt
			}
			else = {
				custom_tooltip = bookmark.0101.b.tt
			}
		}
		

		ai_chance = {
			base = 0	#The AI should never get this event, but if they do, shouldn't opt in.
		}
	}
}
###Radhanites were influential in Khazaria, so we spawn a bunch of them
bookmark.0200 = { #by James Beaumont
	type = character_event
	hidden = yes
	
	trigger = {
		this = title:e_caspian-pontic_steppe.holder #Khagan of Khazaria
		is_alive = yes
		is_landed = yes
	}

	immediate = {
		create_character = {
			location = title:e_caspian-pontic_steppe.holder.capital_province
			trait = lifestyle_mystic
			random_traits = yes
			faith = faith:kabarism
			culture = culture:radhanite
			gender_female_chance = {
				if = {
					limit = { faith:kabarism = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { faith:kabarism = { has_doctrine = doctrine_gender_female_dominated } }
					add = 100
				}
				else = {
					add = 50
				}
			}
			save_scope_as = new_courtier
		}
		title:e_caspian-pontic_steppe.holder = { add_courtier = scope:new_courtier }
		create_character = {
			location = title:e_caspian-pontic_steppe.holder.capital_province
			faith = faith:kabarism
			culture = culture:radhanite
			random_traits_list = {
				count = 1
				education_learning_2 = {}
				education_learning_3 = {}
				education_learning_4 = {}
			}
			random_traits = yes
			gender_female_chance = {
				if = {
					limit = { faith:kabarism = { has_doctrine = doctrine_gender_male_dominated } }
					add = 0
				}
				else_if = {
					limit = { faith:kabarism = { has_doctrine = doctrine_gender_female_dominated } }
					add = 100
				}
				else = {
					add = 50
				}
			}
			save_scope_as = new_courtier
		}
		title:e_caspian-pontic_steppe.holder = { add_courtier = scope:new_courtier }
		create_character = {
			location = title:e_caspian-pontic_steppe.holder.capital_province
			age = { 18 35 }
			random_traits_list = {
				count = 1
				education_martial_2 = {}
				education_martial_3 = {}
				education_martial_4 = {}
			}
			random_traits_list = {
				count = 1
				brave = {}
				just = {}
			}
			random_traits_list = { #Something nice
				honest = {}
				gregarious = {}
				trusting = {}
				compassionate = {}
				generous = {}
				humble = {}
				calm = {}
			}
			random_traits_list = {
				count = 1
				lustful = {}
				chaste = {}
				wrathful = {}
				arrogant = {}
				impatient = {}
				patient = {}
				impatient  = {}
				ambitious = {}
				cynical = {}
				zealous = {}
				stubborn = {}
			}
			random_traits = no
			martial = {
				min_template_decent_skill
				max_template_decent_skill
			}
			prowess = {
				min_template_decent_skill
				max_template_decent_skill
			}
			faith = faith:kabarism
			culture = culture:radhanite
			gender_female_chance = {
				add = 25
			}
			save_scope_as = new_courtier
		}
		title:e_caspian-pontic_steppe.holder = { add_courtier = scope:new_courtier }
		create_character = {
			location = title:e_caspian-pontic_steppe.holder.capital_province
			random_traits = yes
			faith = faith:kabarism
			culture = culture:radhanite
			gender_female_chance = {
				add = 25
			}
			save_scope_as = new_courtier
		}
		title:e_caspian-pontic_steppe.holder = { add_courtier = scope:new_courtier }
		create_character = {
			location = title:e_caspian-pontic_steppe.holder.capital_province
			random_traits = yes
			faith = faith:kabarism
			culture = culture:radhanite
			gender_female_chance = {
				add = 25
			}
			save_scope_as = new_courtier
		}
		title:e_caspian-pontic_steppe.holder = { add_courtier = scope:new_courtier }
	}
}

##############
# 867 - MISC #
##############

##################################################
# In Memory of Your Good Taste
# by Ewan Cowhig Croft & Stu Taylor
# 0211 - 0220
##################################################

#	Basileios has just murdered Michael.
## Credit to Stu Taylor of Dead Good Comics for the title line and entire lead-in to this event.
bookmark.0211 = {
	type = character_event
	title = bookmark.0211.t
	desc = bookmark.0211.desc
	theme = murder_scheme
	left_portrait = {
		character = scope:basil
		animation = toast_goblet
		outfit_tags = { military_outfit no_cloak no_headgear }
	}
	right_portrait = {
		character = scope:michael
		animation = map_fear
	}
	override_background = { reference = ep3_byzantine_feast }

	trigger = { is_alive = yes }

	immediate = {
		play_music_cue = "mx_cue_murder"
		character:1700 = { save_scope_as = basil }
		character:70490 = {
			save_scope_as = michael
			# Remove his nickname, which we have to leave on him for future bookmarks otherwise.
			hidden_effect = { remove_nickname = yes }
		}
	}

	# Michael the Drunkard.
	option = {
		name = bookmark.0211.a
		flavor = bookmark.0211.a.flavour
		
		scope:michael = { give_nickname = nick_the_drunkard_michael_iii }
		add_legitimacy_effect = { LEGITIMACY = major_legitimacy_gain }

		# No stress, no AI.
	}
	
	# Michael the Pious.
	option = {
		name = bookmark.0211.b
		trigger = { is_ai = no }
		flavor = bookmark.0211.b.flavour

		scope:michael = { give_nickname = nick_the_pious_michael_iii }
		add_piety = massive_piety_gain

		# No stress, no AI.
	}
	
	# Michael the Young.
	option = {
		name = bookmark.0211.c
		trigger = { is_ai = no }
		flavor = bookmark.0211.c.flavour

		scope:michael = { give_nickname = nick_the_young_michael_iii }

		domicile ?= {
			switch = {
				trigger = has_domicile_building
				vineyard_05 = { add_domicile_building = vineyard_06 }
				vineyard_04 = { add_domicile_building = vineyard_05 }
				vineyard_03 = { add_domicile_building = vineyard_04 }
				vineyard_02 = { add_domicile_building = vineyard_03 }
				vineyard_01 = { add_domicile_building = vineyard_02 }
				fallback = {
					if = {
						limit = { free_external_domicile_building_slots >= 1 }
						add_domicile_building = vineyard_01
					}
					else = {
						root = { add_prestige = major_prestige_gain }
					}
				}
			}
		}

		# No stress, no AI.
	}
}


#########################
# 1066 - RAGS TO RICHES #
#########################

###	Matilda start-up event
bookmark.1066 = {
	type = character_event
	title = bookmark.1066.t
	desc = bookmark.1066.desc
	theme = marriage
	override_background = { reference = ep2_wedding_ceremony }
	override_effect_2d = {
		reference = rain	
	}
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:hunchback
		animation = ecstasy
	}
	lower_right_portrait = {
		character = scope:hunchbacks_father
	}
	lower_left_portrait = {
		character = scope:mum
	}

	trigger = {
		#this = character:7757
	}

	immediate = {
		play_music_cue = "mx_cue_succession"
		character:20248 = { save_scope_as = hunchback }
		character:11030 = { save_scope_as = hunchbacks_father }
		mother = { save_scope_as = mum }
		hidden_effect = {
			add_opinion = {
				target = scope:hunchback
				modifier = disgusted_opinion
				opinion = -75
			}
		}
	}

	option = { # Murder the husband, with a *hefty* bonus (*Potentially* Historical Option)
		name = bookmark.1066.a
		flavor = bookmark.1066.a_flavor
		
		marry = scope:hunchback
		
		if = {
			limit = {
				NOT = {
					any_scheme = {
						type = murder
						scheme_target_character = scope:hunchback
					}
				}
			}
			start_scheme = {
				target_character = scope:hunchback
				type = murder
			}
		}
		custom_tooltip = diplomacy_family.2250.b.tt
		hidden_effect = {
			random_scheme = {
				type = murder
				limit = {
					scheme_target_character = scope:hunchback
				}
				add_scheme_modifier = {
					type = massive_extra_success_chance_modifier
				}
			}
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Physically abandon and permanently avoid him (Historical Option)
		name = bookmark.1066.b
		flavor = bookmark.1066.b_flavor
		
		add_character_modifier = {
			modifier = abandoned_marriage_modifier
		}
		
		if = {
			limit = {
				betrothed ?= scope:hunchback
			}
			break_betrothal = scope:hunchback
		}
		else_if = {
			limit = {
				is_spouse_of = scope:hunchback
			}
			divorce_effect = {
				DIVORCER = root
				DIVORCEE = scope:hunchback
			}
		}
		
		scope:hunchbacks_father = {
			if = {
				limit = {
					NOT = {
						scope:hunchback = {
							is_courtier_of = scope:hunchbacks_father
						}
					}
				}
				add_courtier = scope:hunchback
			}
		}
		
		reverse_add_opinion = {
			target = scope:hunchback
			modifier = abandoned_me_opinion
			years = 30
			opinion = -50
		}
		
		reverse_add_opinion = {
			target = scope:hunchbacks_father
			modifier = insulted_opinion
			years = 30
			opinion = -50
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Use your influence to flip the lineality of the marriage
		name = bookmark.1066.c
		flavor = bookmark.1066.c_flavor
		
		add_piety = -100
		
		marry_matrilineal = scope:hunchback
		
		reverse_add_opinion = {
			target = scope:hunchbacks_father
			modifier = annoyed_opinion
			opinion = -20
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				scope:hunchbacks_father = {
					is_ai = no
				}
			}
		}
	}

	option = { # Just hope he dies...
		name = bookmark.1066.d
		flavor = lineality_warning
		add_internal_flag = dangerous
		
		marry = scope:hunchback

		ai_chance = {
			base = 100
		}
	}
}

# Matilda, a witch or not?
bookmark.1067 = {
	type = character_event
	title = bookmark.1067.t
	desc = bookmark.1067.desc
	theme = faith
	override_background = { reference = bp1_bonfire }
	override_effect_2d = {
		reference = smoke	
	}
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	
	right_portrait = {
		character = scope:witch
		animation = happy_teacher
	}

	trigger = {
		NOR = {
			is_witch_trigger = yes
			has_trait = lifestyle_herbalist
		}
	}

	immediate = {
		play_music_cue = "mx_cue_epic_sacral_moment"
		if = {
			limit = {
				any_pool_character = {
					province = root.location
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					is_female = yes
					age > root.age
					age >= 25
					has_education_intrigue_trigger = yes
				}
			}
			random_pool_character = {
				province = root.location
				limit = {
					is_physically_able_ai_adult = yes
					has_no_particular_noble_roots_trigger = yes
					is_female = yes
					age > root.age
					age >= 25
					has_education_intrigue_trigger = yes
				}
				save_scope_as = witch
			}
		}
		else = {
			hidden_effect = {
				create_character = {
					template = witchy_template
					gender_female_chance = 100
					location = root.location
					culture = root.location.culture
					faith = root.location.faith
					dynasty = none
					save_scope_as = witch
				}
			}
		}
		hidden_effect = {
			scope:witch ?= {
				if = {
					limit = {
						NOT = {
							has_trait = eccentric
						}
					}
					add_trait = eccentric
				}
				give_witch_secret_or_trait_effect = yes
			}
		}
	}

	option = { # Embrace the knowledge
		name = bookmark.1067.a
		flavor = bookmark.1067.a_flavor
		add_internal_flag = dangerous
		
		set_focus = intrigue_skulduggery_focus
		
		add_intrigue_lifestyle_perk_points = 5
		
		give_witch_secret_or_trait_effect = yes
		
		add_trait = lifestyle_herbalist

		ai_chance = {
			base = 25
		}
	}

	option = { # No, I'm pious!
		name = bookmark.1067.b
		flavor = bookmark.1067.b_flavor
		
		add_learning_lifestyle_xp = major_lifestyle_experience
		
		add_piety = 500
		
		add_learning_skill = 2

		ai_chance = {
			base = 75
		}
	}
}

# Vratislav chooses whether to lay claims, or appease the emperor
bookmark.1068 = {
	type = character_event
	title = bookmark.1068.t
	desc = bookmark.1068.desc
	theme = war
	override_background = { reference = ep2_travel_bridge }
	left_portrait = {
		character = root
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:emperor
		animation = personality_cynical
	}

	trigger = {
		exists = title:d_meissen.holder
		exists = title:d_lausitz.holder
		NOR = {
			has_claim_on = title:d_meissen
			has_claim_on = title:d_lausitz
			title:d_lausitz.holder = root
			title:d_meissen.holder = root
		}
		title:e_hre.holder ?= {
			this != root
		}
		is_vassal_of = title:e_hre.holder
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		title:e_hre.holder = {
			save_scope_as = emperor
		}
	}

	option = { # Lay claim to the lands
		name = bookmark.1068.a
		flavor = bookmark.1068.a_flavor
		add_pressed_claim = title:d_meissen
		add_pressed_claim = title:d_lausitz

		ai_chance = {
			base = 25
		}
	}

	option = { # Appease the Emperor
		name = bookmark.1068.b
		flavor = bookmark.1068.b_flavor
		
		add_prestige = 500
		add_legitimacy_effect = { LEGITIMACY = medium_legitimacy_gain }
		
		scope:emperor = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
		}
		
		if = {
			limit = {
				scope:emperor = { is_ai = yes }
				can_add_hook = {
					target = scope:emperor
					type = favor_hook
				}
			}
			add_hook = {
				type = favor_hook
				target = scope:emperor
			}
		}

		ai_chance = {
			base = 75
		}
	}
}

# The matter of Jaromir
bookmark.1069 = {
	type = character_event
	title = bookmark.1069.t
	desc = bookmark.1069.desc
	theme = faith
	override_background = { reference = holy_site_generic }
	override_effect_2d = {
		reference = rain
	}
	left_portrait = {
		character = character:john_monk
		animation = prayer
	}
	right_portrait = {
		character = scope:jaromir
		animation = dismissal
	}
	lower_right_portrait = root.faith.religious_head

	trigger = {
		character:528 ?= {
			is_alive = yes
			is_councillor_of = root
		}
		character:john_monk ?= {
			is_alive = yes
		}
	}

	immediate = {
		play_music_cue = "mx_cue_negative"
		character:528 = {
			save_scope_as = jaromir
		}
		character:john_monk = {
			save_scope_as = john_monk
		}
	}

	option = { # Replace Jaromir with John
		name = bookmark.1069.a
		flavor = bookmark.1069.a_flavor
		
		faith.religious_head = {
			add_opinion = {
				target = root
				modifier = impious_opinion
				opinion = -30
			}
		}
		
		create_title_and_vassal_change = {
  			type = granted
  			save_scope_as = change
  		}
  		title:c_opava = {
	  		change_title_holder = {
				holder = scope:john_monk
				change = scope:change
				take_baronies = no
			}
  		}
		resolve_title_and_vassal_change = scope:change
		scope:john_monk = {
			hidden_effect = {
				change_government = theocracy_government
			}
		}
		if = {
			limit = { character:528 = { is_councillor_of = root } }
			fire_councillor = character:528
		}
		assign_councillor_type = {
			type = councillor_court_chaplain
			remove_existing_councillor = yes
			target = character:john_monk
		}
		add_character_flag = {
			flag = bishop_assignment
			days = 1
		}
		ai_chance = {
			base = 25
		}
	}

	option = { # Make great concessions to Jaromir
		name = bookmark.1069.b
		flavor = bookmark.1069.b_flavor
		
		pay_short_term_gold = {
			target = scope:jaromir
			gold = medium_gold_value
		}
		
		scope:jaromir = {
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 30
			}
			remove_relation_rival = root
		}

		ai_chance = {
			base = 75
		}
	}

	option = { # Make great concessions to Jaromir
		name = bookmark.1069.c
		flavor = bookmark.1069.c_flavor

		ai_chance = {
			base = 75
		}
	}
	
	after = {
		hidden_effect = {
			if = {
				limit = {
					has_character_flag = bishop_assignment
				}
				assign_councillor_type = {
					type = councillor_court_chaplain
					remove_existing_councillor = yes
					target = character:john_monk
				}
			}
		}
	}
}

# A Norman Sicily
bookmark.1070 = {
	type = character_event
	title = bookmark.1070.t
	desc = bookmark.1070.desc
	theme = war
	override_background = { reference = terrain }
	
	left_portrait = {
		character = root
		animation = hunting_knife_start
	}
	
	lower_right_portrait = scope:pope
	lower_left_portrait = scope:emperor

	trigger = {
		
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		
		title:e_hre.holder = { save_scope_as = emperor }
		root.faith.religious_head = { save_scope_as = pope }
		
		custom_tooltip = claim_sicily
		hidden_effect = {
			add_pressed_claim = title:d_salerno
			add_pressed_claim = title:c_napoli
			add_pressed_claim = title:d_capua
			add_pressed_claim = title:c_siracusa
			add_pressed_claim = title:c_agrigento
			add_pressed_claim = title:c_palermo
		}
	}

	option = {
		name = bookmark.1070.a
		
		add_pressed_claim = title:d_benevento
		add_pressed_claim = title:d_spoleto
		show_as_tooltip = {
			spawn_army = {
				levies = 750
				location = root.capital_province
				name = norman_highwaymen
			}
		}
		hidden_effect = {
			spawn_army = {
				levies = 125
				men_at_arms = {
					type = bowmen
					men = 50
				}
				men_at_arms = {
					type = light_horsemen
					men = 50
				}
				men_at_arms = {
					type = conrois
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				levies = 125
				men_at_arms = {
					type = bowmen
					men = 50
				}
				men_at_arms = {
					type = light_horsemen
					men = 50
				}
				men_at_arms = {
					type = conrois
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				levies = 125
				men_at_arms = {
					type = bowmen
					men = 50
				}
				men_at_arms = {
					type = light_horsemen
					men = 50
				}
				men_at_arms = {
					type = conrois
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
		}
		
		scope:emperor = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -30
			}
		}
		
		scope:pope = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -30
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	option = {
		name = bookmark.1070.b
		
		add_pressed_claim = title:d_benevento
		
		show_as_tooltip = {
			spawn_army = {
				levies = 500
				location = root.capital_province
				name = norman_highwaymen
			}
		}
		hidden_effect = {
			spawn_army = {
				levies = 125
				men_at_arms = {
					type = bowmen
					men = 50
				}
				men_at_arms = {
					type = light_horsemen
					men = 50
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				levies = 125
				men_at_arms = {
					type = bowmen
					men = 50
				}
				men_at_arms = {
					type = light_horsemen
					men = 50
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
		}
		
		scope:pope = {
			add_opinion = {
				target = root
				modifier = angry_opinion
				opinion = -30
			}
		}

		ai_chance = {
			base = 100
		}
	}

	option = {
		name = bookmark.1070.c
		
		spawn_army = {
			levies = 125
			men_at_arms = {
				type = bowmen
				men = 50
			}
			men_at_arms = {
				type = light_horsemen
				men = 50
			}
			men_at_arms = {
				type = armored_horsemen
				men = 25
			}
			location = root.capital_province
			name = norman_highwaymen
		}

		ai_chance = {
			base = 100
		}
	}
}

# The Pretender Monk
bookmark.1071 = {
	type = character_event
	title = bookmark.1071.t
	desc = bookmark.1071.desc
	theme = martial
	override_background = { reference = throne_room }
	
	left_portrait = {
		character = root
		animation = thinking
	}
	
	right_portrait = {
		character = scope:raiktor
		animation = beg
	}

	trigger = {
		gold >= 100
		is_at_war = no
		title:e_byzantium.holder ?= {
			this != root
		}
	}
	
	on_trigger_fail = {
		if = {
			limit = {
				title:e_byzantium.holder ?= {
					this != root
				}
			}
			trigger_event = {
				id = bookmark.1071
				days = 25
			}
		}
	}

	immediate = {
		title:e_byzantium.holder ?= { save_scope_as = byz_emperor }
		create_character = {
			template = monk_character_template
			name = Raiktor
			culture = culture:greek
			faith = faith:orthodox
			age = 30
			gender_female_chance = 0
			save_scope_as = raiktor
			employer = root
			intrigue = { min_template_high_skill max_template_high_skill }
			learning = { min_template_high_skill max_template_high_skill }
		}
		hidden_effect = {
			scope:raiktor = {
				add_unpressed_claim = title:e_byzantium
				if = {
					limit = {
						has_trait = honest
					}
					remove_trait = honest
				}
				add_trait = deceitful
				add_trait = historical_character
				add_character_flag = raiktor
				set_variable = {
					name = show_historical_gui
					value = 1
				}
			}
		}
	}

	option = {
		name = bookmark.1071.a
		
		flavor = hard_raiktor_war
		
		custom_tooltip = start_raiktor_war
		custom_tooltip = gain_war_troops
		
		hidden_effect = {
			start_war = {
				cb = raiktor_claim_cb
				target = title:e_byzantium.holder
				claimant = scope:raiktor
				target_title = title:e_byzantium
			}
			random_character_war = {
				limit = {
					using_cb = raiktor_claim_cb
				}
				save_scope_as = war
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
		}
		
		ai_chance = {
			base = 10
			modifier = {
				factor = 0.1
				title:e_byzantium.holder ?= { is_ai = no }
			}
		}
	}

	option = {
		name = bookmark.1071.b
		
		flavor = easy_raiktor_war
		
		custom_tooltip = start_raiktor_conquest_war
		custom_tooltip = gain_war_troops
		
		hidden_effect = {
			start_war = {
				cb = raiktor_conquest_cb
				target = title:e_byzantium.holder
				claimant = scope:raiktor
				target_title = title:c_dyrrachion
				target_title = title:c_avlonas
				target_title = title:c_buthrotum
			}
			random_character_war = {
				limit = {
					using_cb = raiktor_conquest_cb
				}
				save_scope_as = war
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
			
			spawn_army = {
				war = scope:war
				levies = 300
				men_at_arms = {
					type = bowmen
					men = 100
				}
				men_at_arms = {
					type = light_horsemen
					men = 75
				}
				men_at_arms = {
					type = armored_horsemen
					men = 25
				}
				location = root.capital_province
				name = norman_highwaymen
			}
		}

		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				title:e_byzantium.holder ?= { is_ai = no }
			}
		}
	}

	option = {
		name = bookmark.1071.c
		
		scope:raiktor = { select_and_move_to_pool_effect = yes }

		ai_chance = {
			base = 10
			modifier = {
				factor = 10
				title:e_byzantium.holder ?= { is_ai = no }
			}
		}
	}
}

# Conquering Cordoba
bookmark.1072 = {
	type = character_event
	title = bookmark.1072.t
	desc = bookmark.1072.desc
	theme = martial
	override_background = { reference = terrain_scope }
	
	left_portrait = {
		character = root
		animation = spymaster
	}
	
	right_portrait = {
		character = title:c_cordoba.holder
		animation = steward
	}

	trigger = {
		exists = title:c_cordoba.holder
		NOT = { title:c_cordoba.holder = root }
	}

	immediate = {
		title:c_cordoba.holder = { save_scope_as = cordoba_holder }
		title:c_cordoba.title_province = { save_scope_as = background_terrain_scope }
	}

	option = {
		name = bookmark.1072.a
		trait = schemer
		
		custom_tooltip = intrigue_challenge
		add_character_flag = intrigue_duel_on_attack
		
		custom_tooltip = start_cordoba_war
		hidden_effect = {
			if = {
				limit = {
					title:c_cordoba.holder = {
						has_title = title:c_cabra
					}
				}
				start_war = {
					cb = county_conquest_cb
					target = title:c_cordoba.holder
					target_title = title:c_cordoba
					target_title = title:c_cabra
				}
			}
			else = {
				start_war = {
					cb = county_conquest_cb
					target = title:c_cordoba.holder
					target_title = title:c_cordoba
				}
			}
		}
		
		ai_chance = {
			base = 90
		}
	}

	option = {
		name = bookmark.1072.b
		
		spawn_army = {
			levies = 100
			men_at_arms = {
				type = abudrar
				men = 100
			}
			men_at_arms = {
				type = light_horsemen
				men = 50
			}
			location = root.capital_province
			name = event_troop_default_name
		}
		
		custom_tooltip = start_cordoba_war
		hidden_effect = {
			if = {
				limit = {
					title:c_cordoba.holder = {
						has_title = title:c_cabra
					}
				}
				start_war = {
					cb = county_conquest_cb
					target = title:c_cordoba.holder
					target_title = title:c_cordoba
					target_title = title:c_cabra
				}
			}
			else = {
				start_war = {
					cb = county_conquest_cb
					target = title:c_cordoba.holder
					target_title = title:c_cordoba
				}
			}
		}

		ai_chance = {
			base = 10
		}
	}

	option = {
		name = bookmark.1072.c
		
		ai_chance = {
			base = 0
		}
	}
}

# The Seljuk Scion
bookmark.1073 = {
	type = character_event
	title = bookmark.1073.t
	desc = bookmark.1073.desc
	theme = martial
	override_background = { reference = terrain_scope }
	
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:alp_arslan
		animation = war_over_win
	}
	lower_left_portrait = scope:qutalmish
	lower_right_portrait = scope:tughril

	immediate = {
		character:3040 = { save_scope_as = alp_arslan }
		character:3033 = { save_scope_as = qutalmish }
		character:3038 = { save_scope_as = tughril }
		title:e_persia.title_capital_county.title_province = { save_scope_as = background_terrain_scope }
		show_as_tooltip = {
			scope:alp_arslan = {
				set_relation_rival = { reason = rival_killed_parent target = root }
			}
			add_realm_law = camp_purpose_mercenaries
		}
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
			}
			spawn_army = {
				name = event_troop_default_name
				men_at_arms = {
					type = horse_archers
					stacks = 2
				}
				men_at_arms = {
					type = steppe_raiders
					stacks = 2
				}
				men_at_arms = {
					type = heavy_horse_archers
					stacks = 2
				}
				location = root.location
				origin = root.location
			}
		}
		else = {
			spawn_army = {
				name = event_troop_default_name
				men_at_arms = {
					type = horse_archers
					stacks = 2
				}
				men_at_arms = {
					type = steppe_raiders
					stacks = 2
				}
				men_at_arms = {
					type = heavy_horse_archers
					stacks = 2
				}
				location = root.location
				origin = root.location
			}
		}
	}

	option = {
		name = bookmark.1073.a
		add_prestige_level = 1
		if = {
			limit = {
				has_mpo_dlc_trigger = yes
			}
			spawn_army = {
				name = event_troop_default_name
				men_at_arms = {
					type = horse_archers
					stacks = 2
				}
				men_at_arms = {
					type = steppe_raiders
					stacks = 2
				}
				men_at_arms = {
					type = heavy_horse_archers
					stacks = 2
				}
				location = root.location
				origin = root.location
			}
		}
		else = {
			spawn_army = {
				name = event_troop_default_name
				men_at_arms = {
					type = horse_archers
					stacks = 2
				}
				men_at_arms = {
					type = light_horsemen
					stacks = 2
				}
				men_at_arms = {
					type = light_footmen
					stacks = 2
				}
				location = root.location
				origin = root.location
			}
		}
		ai_chance = {
			base = 90
		}
	}

	option = {
		name = bookmark.1073.b
		add_unpressed_claim = title:e_persia
		add_realm_law = camp_purpose_legitimists
		scope:alp_arslan = {
			set_relation_nemesis = { reason = rival_killed_parent target = root }
		}
		ai_chance = {
			base = 10
		}
	}
}

###We let the player decide which dynasty Sibylla's son will belong to avoid undesirable potential game overs
bookmark.0300 = {
	type = character_event
	title = bookmark.0300.t
	desc = bookmark.0300.desc

	theme = family
	left_portrait = {
		character = root
		animation = personality_rational
	}
	lower_center_portrait = {
		character = scope:dead_husband
		animation = dead
	}
	right_portrait = {
		character = scope:baby_baudouin
	}

	trigger = {
		is_ai = no
		character:223541 = {
			is_ai = yes
			is_alive = yes
		}
	}

	immediate = {
		character:223541 = { save_scope_as = baby_baudouin }
		character:223540 = { save_scope_as = dead_husband }
	}

	option = {
		name = bookmark.0300.a

		character:223541 = { set_house = root.house }

		ai_chance = {
			base = 0 # The AI shouldn't get this event, but should want to maintain the status quo if it did
		}
	}
	
	option = {
		name = bookmark.0300.b
		
		ai_chance = {
			base = 100	# AI doesn't get this event, but should always pick no.
		}
		custom_tooltip = bookmark.0300.b.tt
	}
}

bookmark.0400 = {
	type = character_event
	title = bookmark.0400.t
	desc = bookmark.0400.desc

	theme = family

	left_portrait = {
		character = root
		animation = disapproval
	}
	lower_left_portrait = {
		character = scope:brother
	}
	lower_right_portrait = {
		character = scope:child
	}
	right_portrait = {
		character = scope:emperor
		animation = pain
	}

	trigger = {
		is_ai = no
		character:206651 = { # your husband
			is_alive = yes
			is_ai = yes
			is_landed = yes
		}
		character:206653 = { # your child
			is_alive = yes
			is_ai = yes
			top_liege = root.top_liege
		}
		character:tangut_liang_2 = { # your brother
			is_alive = yes
			is_ai = yes
			top_liege = root.top_liege
		}
	}

	immediate = {
		character:206651 = { save_scope_as = emperor }
		character:206653 = { save_scope_as = child }
		character:tangut_liang_2 = { save_scope_as = brother }
		scope:emperor.primary_title = { save_scope_as = xia }
	}
	
	option = {
		name = bookmark.0400.a

		custom_tooltip = {
			text = bookmark.0400.a.tt

			scope:emperor = {
				every_held_title = {
					limit = {
						tier >= tier_county
						is_landless_type_title = no
					}
					add_to_list = titles_to_transfer
				}
			}

			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
				add_claim_on_loss = yes
			}

			every_in_list = {
				list = titles_to_transfer
				change_title_holder = {
					holder = root
					change = scope:change
				}
			}

			scope:emperor = {
				every_vassal = {
					limit = {
						NOT = {
							this = root
						}
					}
					change_liege = {
						LIEGE = root
						CHANGE = scope:change
					}
				}
			}

			resolve_title_and_vassal_change = scope:change

			scope:emperor = {
				death = {
					death_reason = death_wounds
				}
			}
		}

		if = {
			limit = { 
				exists = cp:councillor_chancellor
				cp:councillor_chancellor != character:tangut_liang_2
			}
			fire_councillor = cp:councillor_chancellor
			assign_councillor_type = {
				type = councillor_chancellor
				target = character:tangut_liang_2
			}
		}

		every_child = {
			limit = {
				house != root.house
			}
			set_house = root.house
		}

		ai_chance = {
			base = 0
		}
	}

	option = {
		name = bookmark.0400.b

		custom_tooltip = {
			text = bookmark.0400.b.tt
			add_character_flag = has_had_diarch_intro_event_flag

			scope:emperor = {
				designate_diarch = root
				try_start_diarchy = regency
				set_diarchy_swing = 100
				if = {
					limit = { 
						exists = cp:councillor_chancellor
						cp:councillor_chancellor != character:tangut_liang_2
					}
					fire_councillor = cp:councillor_chancellor
					scope:brother = {
						set_employer = scope:emperor
					}
					assign_councillor_type = {
						type = councillor_chancellor
						target = character:tangut_liang_2
					}
				}
			}
		}
		change_influence = monumental_influence_gain
		add_prestige = monumental_prestige_gain

		ai_chance = {
			base = 100
		}
	}
	option = {
		name = bookmark.0400.c

		custom_tooltip = {
			text = bookmark.0400.c.tt
			add_character_flag = has_had_diarch_intro_event_flag

			scope:emperor = {
				death = {
					death_reason = death_wounds
				}
			}
			scope:brother = {
				set_employer = scope:child
			}
			scope:child = {
				set_diarch = root
				set_diarchy_swing = 100
				if = {
					limit = { 
						exists = cp:councillor_chancellor
						cp:councillor_chancellor != character:tangut_liang_2
					}
					fire_councillor = cp:councillor_chancellor
					assign_councillor_type = {
						type = councillor_chancellor
						target = character:tangut_liang_2
					}
				}
			}
		}
		change_influence = monumental_influence_gain
		add_prestige = monumental_prestige_gain

		ai_chance = {
			base = 0
		}
	}
	after = {
		add_hook = {
			type = loyalty_hook
			target = scope:brother
		}

		scope:brother = {
			change_influence = massive_influence_gain
			add_prestige = massive_prestige_gain
		}
	}
}
