###################################################
##	EP3 Decision Events
##
##	0001 - 0006 	Triumph Decision
##	1000 			Find Charioteer Decision
##  2000 			Governor Confirmation Decision
##	3000			Restore Greece Decision
##	3100			Prepare Greek Fire Dromons
##	3200			Mass Arrests Decision
##	4000			Re-establish the original Eastern Empire
##  4010 - 4019		Ask for help/a crusade
##	4020 - 4029		Evagelize the Slavs
##	4030			Recreate the ERE
##	4040			Reintroduce the Grain Dole
##  4050			Consolidate Rule
##	4060			Convert to Feudalism from Administrative
##	4070			Convert to Administrative from Feudalism
##	5001			Knight of the Swan
##  7000 			Gather Provisions
##  4080			Found Salon
##  4090			Renounce Governorship
##  5000			Commission Icon
##  5010			Hire Chief Eunuch
##  5020 - 5021		Embrace Heresy
###################################################

namespace = ep3_decisions_event

scripted_trigger ep3_decisions_event_valid_prisoner_trigger = {
	exists = scope:triumph_enemy_defeated
	OR = {
		# they are vassals or knights of the defeated
		liege = scope:triumph_enemy_defeated
		liege.liege = scope:triumph_enemy_defeated
		liege.liege.liege = scope:triumph_enemy_defeated
		# they are the defeated (e.g. pretender or previous liege)
		this = scope:triumph_enemy_defeated
		# they participated recently in a rebellion war vs you
		any_memory = {
			memory_age_years < 5
			OR = { # Using a rebellious CB
				var:war_cb ?= flag:war_memory_cb_independence
				var:war_cb ?= flag:war_memory_cb_tyranny
				var:war_cb ?= flag:war_memory_cb_depose
				var:war_cb ?= flag:war_memory_cb_fracture
			}
			OR = {
				AND = { # Personally lost the war
        		    memory_owner = scope:triumph_enemy_defeated
					has_memory_type = war_lost
					var:war_attacker = scope:triumph_enemy_defeated
				}
				AND = { # Joined the losing war
					has_memory_type = joined_allys_war
					var:war_attacker = scope:triumph_enemy_defeated
					var:war_ally = scope:triumph_enemy_defeated
				}
				AND = { # Personally lost the war you started
        		    memory_owner = scope:triumph_enemy_defeated
					has_memory_type = war_lost
					var:war_attacker = root
				}
				AND = { # Joined the losing war you started
					has_memory_type = joined_allys_war
					var:war_attacker = root
					var:war_ally = scope:triumph_enemy_defeated
				}
			}
		}
	}
	# no "women and children"
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:triumph_enemy_defeated }
	is_adult = yes
}

scripted_trigger ep3_decisions_event_valid_hostage_trigger = {
	exists = scope:triumph_enemy_defeated
	is_hostage = yes
	warden = root
	home_court = scope:triumph_enemy_defeated
	location = root.location
	age >= 7
}

# Parade through the city
ep3_decisions_event.0001 = {
	type = character_event
	window = fullscreen_event
	title = ep3_decisions_event.0001.t
	desc = {
		desc = ep3_decisions_event.0001.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					# In Constantinople
					location = province:496
				}
				desc = ep3_decisions_event.0001.desc_const
			}
			desc = ep3_decisions_event.0001.desc_other
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = var:ep3_valid_triumph_victory
				}
				desc = ep3_decisions_event.0001.desc
			}
			desc = ep3_decisions_event.0001.desc_no_war
		}
		desc = ep3_decisions_event.0001.desc_end
	}
	theme = emperor
	override_background = { reference = ep3_triumph }

	immediate = {
		play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Byzantine_Flavor/ep3_mx_sting_byzantineflavor_hold_triumph"
		# if we have won a war, save the defeated enemy
		var:ep3_valid_triumph_victory ?= {
			save_scope_as = triumph_enemy_defeated
		}
		# if we have relevant prisoners, find one
		if = {
			limit = {
				any_prisoner = {
					ep3_decisions_event_valid_prisoner_trigger = yes
				}
			}
			random_prisoner = {
				limit = {
					this = scope:triumph_enemy_defeated
				}
				alternative_limit = {
					ep3_decisions_event_valid_prisoner_trigger = yes
					is_landed = yes
				}
				alternative_limit = {
					ep3_decisions_event_valid_prisoner_trigger = yes
				}
				save_scope_as = valid_prisoner
			}
		}
		# if we have a relevant hostage, save them
		if = {
			limit = {
				any_courtier = {
					ep3_decisions_event_valid_hostage_trigger = yes
				}
			}
			random_courtier = {
				limit = {
					ep3_decisions_event_valid_hostage_trigger = yes
				}
				save_scope_as = enemy_hostage
			}
		}
		# if we have a relevant artifact, save it
		if = {
			limit = {
				exists = scope:triumph_enemy_defeated
				exists = var:byz_valid_for_trophy
				var:byz_valid_for_trophy = {
					save_temporary_scope_as = artifact_check
				}
				scope:artifact_check = {
					previous_owner ?= scope:triumph_enemy_defeated
				}
			}
			var:byz_valid_for_trophy = {
				save_scope_as = sacked_artifact
			}
		}
		# Create a memory right away
		create_character_memory = {
			type = byz_held_triumph
		}
		#Used in loc
		scope:new_memory = {
			set_variable = {
				name = triumph_location
				value = root.location
			}
		}
		#Used in loc
		root.location = { save_scope_as = t_location }
		#Otherwise the error log screams
		if = {
			limit = {
				any_memory = {
					has_variable = triumph_location
				}
			}
		}
		#Add legitimacy
		add_legitimacy = medium_legitimacy_gain
	}

	#Option A: to the Hippodrome
	option = {
		name = ep3_decisions_event.0001.a
		flavor = ep3_decisions_event.0001.a.flavor
		custom_tooltip = ep3_decisions_event.0001.a.tt
		add_character_flag = triumph_hippodrome
		trigger_event = {
			id = ep3_decisions_event.0002
			days = 1
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = cynical
				add = 50
			}
			modifier = {
				has_trait = ambitious
				add = 50
			}
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_boldness = 0.5
			}
		}
	}

	#Option B: to Hagia Sophia
	option = {
		name = ep3_decisions_event.0001.b
		flavor = ep3_decisions_event.0001.b.flavor
		custom_tooltip = ep3_decisions_event.0001.b.tt
		add_character_flag = triumph_hagia_sophia
		trigger_event = {
			id = ep3_decisions_event.0003
			days = 1
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = humble
				add = 50
			}
			modifier = {
				has_trait = zealous
				add = 50
			}
			modifier = {
				has_trait = content
				add = 50
			}
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	after = {
		remove_variable = ep3_valid_triumph_victory
		remove_variable = byz_valid_for_trophy
	}
}

# At the Hippodrome
ep3_decisions_event.0002 = {
	type = character_event
	title = ep3_decisions_event.0002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:triumph_enemy_defeated }
				desc = ep3_decisions_event.0002.desc_enemy
			}
			desc = ep3_decisions_event.0002.desc_no_war
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:triumph_enemy_defeated
					exists = scope:valid_prisoner
				}
				desc = ep3_decisions_event.0002.desc_prisoner
			}
			desc = ep3_decisions_event.0002.desc_no_prisoner
		}
		triggered_desc = {
			trigger = {
				exists = scope:triumph_enemy_defeated
				exists = scope:sacked_artifact
			}
			desc = ep3_decisions_event.0002.desc_artifact
		}
		triggered_desc = {
			trigger = {
				exists = scope:enemy_hostage
			}
			desc = ep3_decisions_event.0002.desc_hostage
		}
		desc = ep3_decisions_event.0002.desc_conclusion
	}
	theme = emperor
	override_background = { reference = ep3_hippodrome_track }
	left_portrait = {
		character = root
		animation = jockey_wave
		camera = camera_event_horse_left
	}
	right_portrait = {
		trigger = {
			exists = scope:valid_prisoner
		}
		character = scope:valid_prisoner
		override_imprisonment_visuals = yes
		animation = prisonhouse
		outfit_tags = { beggar_rags }
	}
	lower_right_portrait = scope:enemy_hostage
	artifact = {
		position = lower_left_portrait
		target = scope:sacked_artifact
	}

	#Option A: humiliate the prisoners
	option = {
		name = ep3_decisions_event.0002.a
		flavor = ep3_decisions_event.0002.a.tt
		trigger = { exists = scope:valid_prisoner }
		trigger_event = {
			id = ep3_decisions_event.0004
			days = 1
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = just
				add = 50
			}
			modifier = {
				has_trait = vengeful
				add = 100
			}
			modifier = {
				has_trait = sadistic
				add = 50
			}
			modifier = {
				has_trait = callous
				add = 50
			}
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}

	#Option B: parade and distribute the spoils to the crowd
	option = {
		name = ep3_decisions_event.0002.b
		flavor = ep3_decisions_event.0002.b.tt
		trigger = {
			exists = scope:triumph_enemy_defeated
			NOT = { exists = scope:sacked_artifact }
		}
		remove_treasury_or_gold = minor_treasury_or_gold_value
		change_influence = major_influence_gain
		add_legitimacy = minor_legitimacy_gain
		trigger_event = ep3_decisions_event.0007
		stress_impact = {
			greedy = major_stress_impact_gain
			generous = medium_stress_impact_loss
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = greedy
				add = -100
			}
			ai_value_modifier = {
				ai_greed = -0.5
				ai_sociability = 0.5
			}
		}
	}

	#Option E: parade the spoils, destroy the symbols, and distribute the gold
	option = {
		name = ep3_decisions_event.0002.e
		flavor = ep3_decisions_event.0002.e.tt
		trigger = {
			exists = scope:triumph_enemy_defeated
			exists = scope:sacked_artifact
		}
		change_influence = major_influence_gain
		add_prestige = major_prestige_gain
		destroy_artifact = scope:sacked_artifact
		add_legitimacy = minor_legitimacy_gain
		if = {
			limit = {
				scope:triumph_enemy_defeated.culture != root.culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:triumph_enemy_defeated.culture
					value = medium_negative_culture_acceptance
					desc = cultural_acceptance_triumph_offensive
				}
			}
		}
		if = {
			limit = {
				scope:triumph_enemy_defeated = { is_alive = yes }
			}
			scope:triumph_enemy_defeated = {
				add_opinion = {
					target = root
					modifier = disrespect_opinion
					opinion = -50
				}
			}
		}
		trigger_event = ep3_decisions_event.0007
		stress_impact = {
			greedy = minor_stress_impact_gain
			generous = medium_stress_impact_loss
			zealous = medium_stress_impact_loss
			paranoid = medium_stress_impact_loss
		}
		ai_chance = {
			base = 250
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 0.75
				ai_rationality = -0.25
			}
		}
	}

	#Option C: distribute gold and food to the crowd
	option = {
		name = ep3_decisions_event.0002.c
		flavor = ep3_decisions_event.0002.c.tt
		trigger = { 
			NOT = { exists = scope:triumph_enemy_defeated }
		}
		# This is a correspective of option B, but all the money must come from your own pockets
		remove_short_term_gold = major_gold_value
		change_influence = major_influence_gain
		add_legitimacy = minor_legitimacy_gain
		trigger_event = ep3_decisions_event.0007
		stress_impact = {
			greedy = major_stress_impact_gain
			generous = medium_stress_impact_loss
			gregarious = medium_stress_impact_loss
			ambitious = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -100
			}
			ai_value_modifier = {
				ai_greed = -1
				ai_sociability = 0.5
			}
		}
	}

	#Option D: address the crowd
	option = {
		name = ep3_decisions_event.0002.d
		flavor = ep3_decisions_event.0002.d.tt
		custom_tooltip = ep3_decisions_event.0002.d.custom_tooltip
		trigger_event = {
			id = ep3_decisions_event.0005
			days = 1
		}
		ai_chance = {
			base = 150
			modifier = {
				has_trait = arrogant
				add = 50
			}
			modifier = {
				has_trait = gregarious
				add = 50
			}
			ai_value_modifier = {
				ai_energy = 0.5
				ai_boldness = 0.5
			}
		}
	}
}

# At Hagia Sophia
ep3_decisions_event.0003 = {
	type = character_event
	title = ep3_decisions_event.0003.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:triumph_enemy_defeated }
				desc = ep3_decisions_event.0003.desc
			}
			desc = ep3_decisions_event.0003.desc_no_war
		}
		triggered_desc = {
			trigger = {
				exists = scope:enemy_hostage
			}
			desc = ep3_decisions_event.0003.desc_hostage
		}
	}
	theme = emperor
	override_background = { reference = ep3_hagia_sophia }
	left_portrait = {
		character = scope:actor
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	right_portrait = {
		trigger = {
			exists = scope:enemy_hostage
		}
		character = scope:enemy_hostage
		animation = sadness
	}
	lower_right_portrait = scope:triumph_enemy_defeated
	artifact = {
		position = lower_left_portrait
		target = scope:sacked_artifact
	}

	immediate = {
		
	}

	#Option C: hostage
	option = {
		name = ep3_decisions_event.0003.c
		flavor = ep3_decisions_event.0003.c.tt
		trigger = { exists = scope:enemy_hostage }
		if = {
			limit = {
				scope:triumph_enemy_defeated.culture != root.culture
			}
			culture = {
				change_cultural_acceptance = {
					target = scope:triumph_enemy_defeated.culture
					value = low_positive_culture_acceptance
					desc = cultural_acceptance_triumph_peace
				}
			}
		}
		add_diplomacy_lifestyle_xp = major_lifestyle_xp
		if = {
			limit = {
				scope:triumph_enemy_defeated = { is_alive = yes }
			}
			scope:triumph_enemy_defeated = {
				add_opinion = {
					target = root
					modifier = respect_opinion
					opinion = 50
				}
			}
		}
		scope:enemy_hostage = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 50
			}
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = forgiving
				add = 100
			}
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 0.5
			}
		}
	}

	#Option B: dedicate to God
	option = {
		name = ep3_decisions_event.0003.b
		trigger = {
			exists = scope:triumph_enemy_defeated
			NOT = { exists = scope:sacked_artifact }
		}
		add_piety = major_piety_gain
		add_character_modifier = {
			modifier = ep3_triumph_of_god_modifier
			years = 10
		}
		ai_chance = {
			base = 200
			modifier = {
				has_trait = zealous
				add = 50
			}
			modifier = {
				has_trait = humble
				add = 100
			}
			ai_value_modifier = {
				ai_zeal = 1
			}
		}
	}

	#Option D: dedicate the spoils to God
	option = {
		name = ep3_decisions_event.0003.d
		trigger = {
			exists = scope:triumph_enemy_defeated
			exists = scope:sacked_artifact
		}
		custom_tooltip = ep3_decisions_event.0003.d.tt_artifact
		hidden_effect = { destroy_artifact = scope:sacked_artifact }
		add_piety = massive_piety_gain
		add_legitimacy = minor_legitimacy_gain
		add_character_modifier = {
			modifier = ep3_triumph_of_god_modifier
			years = 10
		}
		faith = {
			change_fervor = {
				value = 1
				desc = fervor_gain_triumph_of_god
			}
		}
		ai_chance = {
			base = 250
			modifier = {
				has_trait = zealous
				add = 100
			}
			modifier = {
				has_trait = greedy
				add = -150
			}
			ai_value_modifier = {
				ai_zeal = 1
				ai_vengefulness = 0.5
			}
		}
	}

	#Option A: receive blessing
	option = {
		name = ep3_decisions_event.0003.a
		add_piety = medium_piety_gain
		add_character_modifier = {
			modifier = ep3_blessed_in_triumph_modifier
			years = 10
		}
		add_legitimacy = minor_legitimacy_gain
		ai_chance = {
			base = 100
			modifier = {
				has_trait = arrogant
				add = 50
			}
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	after = { trigger_event = ep3_decisions_event.0007 }
}

# Deal with the prisoners
ep3_decisions_event.0004 = {
	type = character_event
	title = ep3_decisions_event.0004.t
	desc = {
		desc = ep3_decisions_event.0004.desc
		triggered_desc = {
			trigger = {
				exists = scope:enemy_hostage
			}
			desc = ep3_decisions_event.0004.desc_hostage
		}
	}
	theme = emperor
	override_background = { reference = ep3_hippodrome }
	left_portrait = {
		character = root
		animation = war_defender
	}
	right_portrait = {
		character = scope:valid_prisoner
		override_imprisonment_visuals = yes
		animation = prisonhouse
		outfit_tags = { beggar_rags }
	}
	lower_center_portrait = scope:enemy_hostage

	immediate = {
		# needed in the blinding effects
		save_scope_as = actor
		scope:valid_prisoner = { save_scope_as = recipient }
	}

	#Option A: blind
	option = {
		name = ep3_decisions_event.0004.a
		trigger = {
			scope:valid_prisoner = {
				NOT = { has_trait = blind }
			}
		}
		# Effects, opinions, and stress for blinding
		blind_recipient_effect = yes
		blind_opinion_effect = yes
		blind_castrate_and_disfigure_effect = yes #stress is here
		# The people love a traditionally Byzantine show of strength
		# You uphold the Byzantine traditions
		add_character_modifier = {
			modifier = ep3_triumph_traditional_punishments_modifier
			years = 5
		}
		change_influence = medium_influence_gain
		add_legitimacy = minor_legitimacy_gain
		if = {
			limit = {
				exists = scope:enemy_hostage
			}
			scope:enemy_hostage = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -20
				}
			}
		}
		if = {
			limit = {
				scope:triumph_enemy_defeated = { is_alive = yes }
			}
			scope:triumph_enemy_defeated = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -20
				}
			}
		}
		ai_chance = {
			base = 300
			ai_value_modifier = {
				ai_vengefulness = 0.5
			}
		}
	}

	#Option B: execute
	option = {
		name = ep3_decisions_event.0004.b
		execute_prisoner_effect = { #stress is here
            VICTIM = scope:valid_prisoner
            EXECUTIONER = root
        }
		# The people are afraid of the show of strength
		add_character_modifier = {
			modifier = ep3_triumph_public_executioner_modifier
			years = 5
		}
		if = {
			limit = {
				exists = scope:enemy_hostage
			}
			scope:enemy_hostage = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -30
				}
			}
		}
		if = {
			limit = {
				scope:triumph_enemy_defeated = { is_alive = yes }
			}
			scope:triumph_enemy_defeated = {
				add_opinion = {
					target = root
					modifier = cruelty_opinion
					opinion = -30
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = callous
				add = 50
			}
			modifier = {
				has_trait = sadistic
				add = 100
			}
			modifier = {
				has_trait = paranoid
				add = 50
			}
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_boldness = 0.5
			}
		}
	}

	#Option C: pardon
	option = {
		name = ep3_decisions_event.0004.c
		scope:valid_prisoner = { release_from_prison = yes }
		if = {
			limit = {
				can_add_hook = {
					target = scope:valid_prisoner
					type = indebted_hook
				}
			}
			add_hook = {
				target = scope:valid_prisoner
				type = indebted_hook
			}
		}
		# The people think you are nice
		change_influence = major_influence_gain
		if = {
			limit = {
				exists = scope:enemy_hostage
			}
			scope:enemy_hostage = {
				add_opinion = {
					target = root
					modifier = merciful_opinion
					opinion = 20
				}
			}
		}
		if = {
			limit = {
				scope:triumph_enemy_defeated = { is_alive = yes }
			}
			scope:triumph_enemy_defeated = {
				add_opinion = {
					target = root
					modifier = merciful_opinion
					opinion = 30
				}
			}
		}
		stress_impact = {
			callous = medium_stress_impact_gain
			sadistic = medium_stress_impact_gain
			vengeful = major_stress_impact_gain
			paranoid = major_stress_impact_gain
			trusting = medium_stress_impact_loss
			forgiving = major_stress_impact_loss
			compassionate = major_stress_impact_loss
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = forgiving
				add = 100
			}
			modifier = {
				has_trait = content
				add = 50
			}
			modifier = {
				has_trait = compassionate
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 1
			}
		}
	}

	after = { trigger_event = ep3_decisions_event.0007 }
}

# Make a speech
ep3_decisions_event.0005 = {
	type = character_event
	title = ep3_decisions_event.0005.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:triumph_enemy_defeated }
				desc = ep3_decisions_event.0005.desc_victory
			}
			desc = ep3_decisions_event.0005.desc_no_war
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:triumph_enemy_defeated
					exists = scope:valid_prisoner
				}
				desc = ep3_decisions_event.0005.desc_prisoner
			}
			desc = ep3_decisions_event.0005.desc_politics
		}
		triggered_desc = {
			trigger = {
				exists = scope:enemy_hostage
			}
			desc = ep3_decisions_event.0005.desc_hostage
		}
	}
	theme = emperor
	override_background = { reference = ep3_hippodrome }
	left_portrait = {
		character = root
		animation = war_defender
	}
	right_portrait = {
		trigger = {
			exists = scope:enemy_hostage
		}
		character = scope:enemy_hostage
		animation = sadness
	}
	lower_center_portrait = scope:valid_prisoner

	immediate = {
		# The people are excited to see and hear you
		add_prestige = medium_prestige_gain
	}

	#Option A: promise victories
	option = {
		name = ep3_decisions_event.0005.a
		flavor = ep3_decisions_event.0005.tt
		duel = {
			value = average_skill_rating
			skill = martial
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.a.success
				send_interface_toast = {
					title = ep3_decisions_event.success
					left_icon = root
					custom_tooltip = ep3_decisions_event.a.tt
					add_character_modifier = {
						modifier = ep3_triumph_promised_victories_modifier
						years = 10
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.a.failure
				send_interface_toast = {
					title = ep3_decisions_event.failure
					left_icon = root
					custom_tooltip = ep3_decisions_event.a.tt_no
				}
			}
		}
		add_character_flag = triumph_promised_victories
		ai_chance = {
			base = 100
			modifier = {
				has_trait = wrathful
				add = 50
			}
			modifier = {
				has_trait = ambitious
				add = 50
			}
			modifier = {
				has_trait = brave
				add = 50
			}
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_energy = 0.5
				ai_boldness = 0.5
			}
		}
	}

	#Option B: promise stability
	option = {
		name = ep3_decisions_event.0005.b
		flavor = ep3_decisions_event.0005.tt
		duel = {
			value = average_skill_rating
			skill = diplomacy
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.b.success
				send_interface_toast = {
					title = ep3_decisions_event.success
					left_icon = root
					custom_tooltip = ep3_decisions_event.b.tt
					add_character_modifier = {
						modifier = ep3_triumph_promised_stability_modifier
						years = 10
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.a.failure
				send_interface_toast = {
					title = ep3_decisions_event.failure
					left_icon = root
					custom_tooltip = ep3_decisions_event.b.tt_no
				}
			}
		}
		add_character_flag = triumph_promised_stability
		ai_chance = {
			base = 100
			modifier = {
				has_trait = zealous
				add = 50
			}
			modifier = {
				has_trait = just
				add = 50
			}
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_compassion = 0.5
			}
		}
	}

	#Option C: promise prosperity
	option = {
		name = ep3_decisions_event.0005.c
		flavor = ep3_decisions_event.0005.tt
		duel = {
			value = average_skill_rating
			skill = stewardship
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.c.success
				send_interface_toast = {
					title = ep3_decisions_event.success
					left_icon = root
					custom_tooltip = ep3_decisions_event.c.tt
					add_character_modifier = {
						modifier = ep3_triumph_promised_prosperity_modifier
						years = 10
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = ep3_decisions_event.0005.a.failure
				send_interface_toast = {
					title = ep3_decisions_event.failure
					left_icon = root
					custom_tooltip = ep3_decisions_event.c.tt_no
				}
			}
		}
		add_character_flag = triumph_promised_prosperity
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = 50
			}
			modifier = {
				has_trait = diligent
				add = 50
			}
			ai_value_modifier = {
				ai_greed = 1
			}
		}
	}

	after = {
		trigger_event = ep3_decisions_event.0007
		trigger_event = {
			id = ep3_decisions_event.0006
			months = { 45 59 }
		}
	}
}

# Follow-up, some years later
ep3_decisions_event.0006 = {
	type = character_event
	title = ep3_decisions_event.0006.t
	desc = {
		desc = ep3_decisions_event.0006.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = triumph_promised_victories }
				desc = ep3_decisions_event.0006.desc_victory
			}
			triggered_desc = {
				trigger = { has_character_flag = triumph_promised_stability }
				desc = ep3_decisions_event.0006.desc_stability
			}
			triggered_desc = {
				trigger = { has_character_flag = triumph_promised_prosperity }
				desc = ep3_decisions_event.0006.desc_prosperity
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = triumph_promise_kept
				}
				desc = ep3_decisions_event.0006.desc_yes
			}
			desc = ep3_decisions_event.0006.desc_no
		}
	}
	theme = emperor
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_character_flag = triumph_promise_kept }
			animation = happiness
		}
		triggered_animation = {
			trigger = { NOT = { has_character_flag = triumph_promise_kept } }
			animation = shame
		}
	}
	right_portrait = {
		character = scope:talker
		animation = worry
	}

	trigger = {
		OR = {
			has_character_flag = triumph_promised_prosperity
			has_character_flag = triumph_promised_victories
			has_character_flag = triumph_promised_stability
		}
	}

	immediate = {
		random_memory = {
			memory_type = byz_held_triumph
			limit = {
				memory_age_years < 5
			}
			save_scope_as = triumph_memory
		}
		if = {
			limit = {
				has_character_flag = triumph_promised_victories
				has_variable = ep3_valid_triumph_victory
			}
			add_character_flag = triumph_promise_kept
		}
		else_if = {
			limit = {
				has_character_flag = triumph_promised_stability
				NOT = {
					any_memory = {
						memory_age_years < scope:triumph_memory.memory_age_years
						OR = {
							var:war_cb ?= flag:war_memory_cb_independence
							var:war_cb ?= flag:war_memory_cb_tyranny
							var:war_cb ?= flag:war_memory_cb_depose
							var:war_cb ?= flag:war_memory_cb_fracture
						}
					}
				}
			}
			add_character_flag = triumph_promise_kept
		}
		else_if = {
			limit = {
				has_character_flag = triumph_promised_prosperity
			}
			add_character_flag = triumph_promise_kept
		}
		if = {
			limit = {
				exists = cp:councillor_steward
				cp:councillor_steward = {
					is_available_ai_adult = yes
					location = root.location
				}
			}
			cp:councillor_steward = { save_scope_as = talker }
		}
		else_if = {
			limit = {
				any_courtier_or_guest = {
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					is_adult = yes
				}
			}
			random_courtier_or_guest = {
				limit = {
					is_of_major_or_minor_interest_trigger = { CHARACTER = root }
					is_adult = yes
				}
				save_scope_as = talker
			}
		}
		else = {
			random_courtier_or_guest = {
				limit = { is_adult = yes } #There should always be at least one to grab
				save_scope_as = talker
			}
		}
	}

	#Promise kept
	option = {
		name = ep3_decisions_event.0006.a
		trigger = { has_character_flag = triumph_promise_kept }
		change_influence = major_influence_gain
		# The people believe in you
		add_legitimacy = minor_legitimacy_gain
	}

	#Promise not kept
	option = {
		name = ep3_decisions_event.0006.b
		trigger = { NOT = { has_character_flag = triumph_promise_kept } }
		change_influence = minor_influence_loss
		# The people are disappointed
		add_legitimacy = minor_legitimacy_loss
	}

	after = {
		remove_character_flag = triumph_promised_prosperity
		remove_character_flag = triumph_promised_victories
		remove_character_flag = triumph_promised_stability
		remove_character_flag = triumph_promise_kept
	}
}

# Conclusion Event
ep3_decisions_event.0007 = {
	type = character_event
	window = fullscreen_event
	title = ep3_decisions_event.0007.t
	desc = {
		desc = ep3_decisions_event.0007.desc
		first_valid = {
			triggered_desc = {
				trigger = { has_character_flag = triumph_hagia_sophia }
				desc = ep3_decisions_event.0007.hagia_sophia
			}
			desc = ep3_decisions_event.0007.hippodrome
		}
	}
	theme = emperor
	override_background = { reference = ep3_triumph }

	immediate = {
		play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Byzantine_Flavor/ep3_mx_sting_byzantineflavor_hold_triumph"
		change_influence = major_influence_gain
	}

	option = { 
		name = ep3_decisions_event.0007.a
		custom_tooltip = ep3_decisions_event.0007.a.tt
	}

	after = {
		if = {
			limit = { has_character_flag = triumph_hippodrome }
			remove_character_flag = triumph_hippodrome
		}
		if = {
			limit = { has_character_flag = triumph_hagia_sophia}
			remove_character_flag = triumph_hagia_sophia
		}
	}
}

##############################################
### Find a Charioteer
### by Chad Uhl
scripted_trigger mediocre_charioteer_trigger = {
	can_be_employed_as = charioteer_court_position
	is_available_healthy_ai_adult = yes
	has_any_charioteer_trait = no
	prowess >= 7
}

scripted_trigger good_charioteer_trigger = {
	can_be_employed_as = charioteer_court_position
	is_available_healthy_ai_adult = yes
	has_any_charioteer_trait = yes
	has_trait = education_martial
	prowess >= 14
}

ep3_decisions_event.1000 = {
	type = character_event
	title = ep3_decisions_event.1000.t
	desc = {
		desc = ep3_decisions_event.1000.desc
		triggered_desc = {
			trigger = { exists = scope:stolen_charioteer }
			desc = ep3_decisions_event.1000.desc.stolen_charioteer
		}
	}
	theme = administrative
	
	left_portrait = {
		character = scope:mediocre_charioteer
		animation = happiness
	}
	right_portrait = {
		character = scope:good_charioteer
		animation = personality_honorable
	}
	lower_center_portrait = scope:stolen_charioteer

	immediate = {
		# Find a mediocre one
		if = { # check for a mediocre character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					mediocre_charioteer_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { mediocre_charioteer_trigger = yes }
				save_scope_as = mediocre_charioteer
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				age = { 16 30 }
				culture = root.location.culture
				faith = root.location.faith
				random_traits_list = {
					count = 1
					education_martial_1 = {}
					education_intrigue_1 = {}
					education_intrigue_2 = {}
				}
				random_traits_list = {
					count = 2
					ambitious = {}
					arrogant = {}
					deceitful = {}
					diligent = {}
					impatient = {}
					honest = {}
					brave = {}
					lustful = {}
					wrathful = {}
				}
				random_traits = yes
				prowess = {
					min_template_low_skill
					max_template_average_skill
				}
				save_scope_as = mediocre_charioteer
			}
		}

		# Find a good one
		if = { # check for a GOOD character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					good_charioteer_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { good_charioteer_trigger = yes }
				save_scope_as = good_charioteer
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				age = { 16 30 }
				culture = root.location.culture
				faith = root.location.faith
				random_traits_list = {
					count = 1
					education_martial_1 = {}
					education_martial_2 = {}
					education_martial_3 = {}
				}
				random_traits_list = {
					count = 2
					ambitious = {}
					arrogant = {}
					deceitful = {}
					diligent = {}
					impatient = {}
					honest = {}
					brave = {}
					lustful = {}
					wrathful = {}
				}
				random_traits = yes
				prowess = {
					min_template_decent_skill
					max_template_decent_skill
				}
				save_scope_as = good_charioteer
			}
			hidden_effect = {
				scope:good_charioteer = {
					if = {
						limit = { has_any_charioteer_trait = no }
						random_list = {
							1 = {
								add_trait = charioteer_green
								add_trait_xp = {
									trait = charioteer_green
									value = 10
								}
							}
							1 = {
								add_trait = charioteer_blue
								add_trait_xp = {
									trait = charioteer_blue
									value = 10
								}
							}
							1 = {
								add_trait = charioteer_white
								add_trait_xp = {
									trait = charioteer_white
									value = 10
								}
							}
							1 = {
								add_trait = charioteer_red
								add_trait_xp = {
									trait = charioteer_red
									value = 10
								}
							}
						}
					}
				}
			}
		}

		# Optional: Steal one from another character (only for human players)
		if = {
			limit = { is_ai = no }
		}
		top_liege = {
			every_vassal_or_below = {
				limit = {
					employs_court_position = charioteer_court_position
					is_ai = yes
				}
				court_position:charioteer_court_position = {
					add_to_list = charioteers
				}
			}
		}
		if = {
			limit = { list_size:charioteers >= 1 }
			random_in_list = {
				list = charioteers
				save_scope_as = stolen_charioteer
			}
		}

	}

	option = { 
		name = ep3_decisions_event.1000.a
		custom_tooltip = ep3_decisions_event.1000.a.aptitude
		pay_treasury_or_gold = {
			target = scope:mediocre_charioteer
			value = low_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:mediocre_charioteer }
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:mediocre_charioteer
					COURT_POS = charioteer_court_position
				}
			}
			appoint_court_position = {
				recipient = scope:mediocre_charioteer
				court_position = charioteer_court_position
			}
		}
		else_if = {
			limit = {
				employs_court_position = charioteer_court_position
			}
			random_court_position_holder = {
				type = charioteer_court_position
				save_scope_as = current_charioteer
			}
			replace_court_position = {
				recipient = scope:mediocre_charioteer
				holder = scope:current_charioteer
				court_position = charioteer_court_position
			}
		}
	}

	option = {
		name = ep3_decisions_event.1000.b
		custom_tooltip = ep3_decisions_event.1000.b.aptitude
		pay_treasury_or_gold = {
			target = scope:good_charioteer
			value = high_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:good_charioteer }
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:good_charioteer
					COURT_POS = charioteer_court_position
				}
			}
			appoint_court_position = {
				recipient = scope:good_charioteer
				court_position = charioteer_court_position
			}
		}
		else_if = {
			limit = {
				employs_court_position = charioteer_court_position
			}
			random_court_position_holder = {
				type = charioteer_court_position
				save_scope_as = current_charioteer
			}
			replace_court_position = {
				recipient = scope:good_charioteer
				holder = scope:current_charioteer
				court_position = charioteer_court_position
			}
		}
	}
	
	option = {
		name = ep3_decisions_event.1000.c
		custom_tooltip = ep3_decisions_event.1000.c.aptitude
		trigger = { exists = scope:stolen_charioteer }
		pay_treasury_or_gold = {
			target = scope:stolen_charioteer
			value = high_skill_court_physician_cost
		}
		change_influence = medium_influence_loss
		hidden_effect = { add_courtier = scope:stolen_charioteer }
		if = {
			limit = {
				can_appoint_char_to_court_position = {
					CHAR = scope:stolen_charioteer
					COURT_POS = charioteer_court_position
				}
			}
			appoint_court_position = {
				recipient = scope:stolen_charioteer
				court_position = charioteer_court_position
			}
		}
		else_if = {
			limit = {
				employs_court_position = charioteer_court_position
			}
			random_court_position_holder = {
				type = charioteer_court_position
				save_scope_as = current_charioteer
			}
			replace_court_position = {
				recipient = scope:stolen_charioteer
				holder = scope:current_charioteer
				court_position = charioteer_court_position
			}
		}
	}

	option = {
		name = ep3_decisions_event.1000.d
	}
}

##############################################
### Find a Bookmaker
### by Chad Uhl
scripted_trigger mediocre_bookmaker_trigger = {
	can_be_employed_as = bookmaker_court_position
	is_available_healthy_ai_adult = yes
	stewardship >= 7
}

scripted_trigger good_bookmaker_trigger = {
	can_be_employed_as = bookmaker_court_position
	is_available_healthy_ai_adult = yes
	stewardship >= 14
	has_trait = education_stewardship
}

ep3_decisions_event.1010 = {
	type = character_event
	title = ep3_decisions_event.1010.t
	desc = ep3_decisions_event.1010.desc
	theme = administrative
	
	left_portrait = {
		character = scope:mediocre_bookmaker
		animation = happiness
	}
	right_portrait = {
		character = scope:good_bookmaker
		animation = personality_honorable
	}

	immediate = {
		# Find a mediocre one
		if = { # check for a mediocre character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					mediocre_bookmaker_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { mediocre_bookmaker_trigger = yes }
				save_scope_as = mediocre_bookmaker
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				age = { 16 30 }
				culture = root.location.culture
				faith = root.location.faith
				random_traits_list = {
					count = 1
					education_stewardship_1 = {}
					education_intrigue_1 = {}
					education_intrigue_2 = {}
				}
				random_traits = yes
				stewardship = {
					min_template_low_skill
					max_template_average_skill
				}
				save_scope_as = mediocre_bookmaker
			}
		}

		# Find a good one
		if = { # check for a GOOD character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					good_bookmaker_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { good_bookmaker_trigger = yes }
				save_scope_as = good_bookmaker
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = root_soldier_female_chance
				age = { 16 30 }
				culture = root.location.culture
				faith = root.location.faith
				random_traits_list = {
					count = 1
					education_stewardship_1 = {}
					education_stewardship_2 = {}
					education_stewardship_3 = {}
				}
				random_traits = yes
				stewardship = {
					min_template_decent_skill
					max_template_decent_skill
				}
				save_scope_as = good_bookmaker
			}
		}
	}

	option = { 
		name = ep3_decisions_event.1010.a
		custom_tooltip = ep3_decisions_event.1010.a.aptitude
		pay_treasury_or_gold = {
			target = scope:mediocre_bookmaker
			value = low_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:mediocre_bookmaker }
		court_position_grant_effect = {
			CANDIDATE = scope:mediocre_bookmaker
			POS = bookmaker
			EMPLOYER = root
		}
	}

	option = {
		name = ep3_decisions_event.1010.b
		custom_tooltip = ep3_decisions_event.1010.b.aptitude
		pay_treasury_or_gold = {
			target = scope:good_bookmaker
			value = high_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:good_bookmaker }
		court_position_grant_effect = {
			CANDIDATE = scope:good_bookmaker
			POS = bookmaker
			EMPLOYER = root
		}
	}

	option = {
		name = ep3_decisions_event.1000.d
	}
}



##############################################
# Confirm Governorship
# directed by Joe Parkin
# based on the book by P. Homage
#
# 2001 -> Liege welcomes Governor
# 2002 -> Governor learns of rejection (end)
# 2010 -> Liege receives Governor
# 2011 -> Governor learns of result (end)
# 2080 -> Confirmation invalidated info
# 2090 -> Invalidation handling

scripted_trigger admin_confirmation_valid_trigger = { # Confirmation is still valid
	is_alive = yes
	is_imprisoned = no
	var:confirmation_liege_scope ?= {
		is_alive = yes 
		is_imprisoned = no 
	}
	liege ?= var:confirmation_liege_scope
}

scripted_effect admin_confirmation_refuse_effect = {
	scope:confirmation_vassal = {
		change_influence = medium_influence_loss
		add_opinion = {
			modifier = refusal_opinion
			target = scope:confirmation_liege
			opinion = -20
		}
	}
}

scripted_effect admin_confirmation_clear_variable_effect = {
	current_travel_plan ?= {
		if = {
			limit = { is_paused = yes }
			resume_travel_plan = yes 
		}
	}
	# Vassal
	if = {
		limit = { has_variable = confirmation_cooldown_vassal }
		remove_variable = confirmation_cooldown_vassal
	}
	# Liege
	if = {
		limit = { has_variable = confirmation_liege_scope }
		remove_variable = confirmation_liege_scope
	}
}

ep3_decisions_event.2001 = {
	type = letter_event
	opening = ep3_decisions_event.2001.opening
	sender = {
		character = scope:confirmation_vassal
		animation = throne_room_bow_1
	}
	desc = ep3_decisions_event.2001.desc

	trigger = {
		scope:confirmation_vassal = {
			is_alive = yes
			is_imprisoned = no
		}
	}

	on_trigger_fail = {
		scope:confirmation_vassal = {
			if = {
				limit = { is_alive = no }
				trigger_event = ep3_decisions_event.2090
			}
		}
	}

	option = {
		name = ep3_decisions_event.2001.a
		trigger = {
			scope:confirmation_vassal = { admin_confirmation_valid_trigger = yes }
		}
		custom_tooltip = ep3_decisions_event.2001.a.tt
		trigger_event = ep3_decisions_event.2010
		ai_chance = { base = 100 }
	}

	option = {
		name = ep3_decisions_event.2001.b
		flavor = ep3_decisions_event.2001.b.tt
		admin_confirmation_refuse_effect = yes
		scope:confirmation_vassal = {
			trigger_event = { on_action = admin_confirmation_invalid_on_action }
		}
		if = {
			limit = {
				NOT = { has_relation_rival = scope:confirmation_vassal }
			}
			stress_impact = {
				arrogant = medium_stress_impact_gain
				just = medium_stress_impact_gain
			}
		}
		else = {
			stress_impact = { base = medium_stress_impact_loss }
		}
		ai_chance = {
			base = -4
			modifier = {
				add = 5
				opinion = {
					target = scope:confirmation_vassal
					value < 0
				}
			}
			modifier = {
				add = 45
				has_relation_rival = scope:confirmation_vassal
			}
		}
	}
}

ep3_decisions_event.2002 = {
	type = letter_event
	opening = ep3_decisions_event.2002.opening
	desc = ep3_decisions_event.2002.desc
	sender = scope:confirmation_liege

	trigger = { admin_confirmation_valid_trigger = yes }

	immediate = {
		show_as_tooltip = { admin_confirmation_refuse_effect = yes }
	}

	option = {
		name = ep3_decisions_event.2002.a
	}

	after = { admin_confirmation_clear_variable_effect = yes }
}

scripted_effect admin_confirmation_liege_reward_effect = {
	scope:confirmation_liege = {
		if = {
			limit = { has_royal_court = yes has_dlc_feature = royal_court }
			change_current_court_grandeur = miniscule_court_grandeur_gain
		}
		add_prestige = minor_prestige_gain
		change_influence = minor_influence_gain
		dynasty = { add_dynasty_prestige = miniscule_dynasty_prestige_gain }
	}
}

scripted_effect admin_confirmation_vassal_reward_effect = {
	scope:confirmation_vassal = { admin_confirmation_vassal_reward_guts_effect = yes }
	admin_confirmation_clear_variable_effect = yes
}

# Liege receives Governor
ep3_decisions_event.2010 = {
	type = character_event # to avoid too much in the court for ruler
	title = ep3_decisions_event.2010.t
	desc = {
		desc = ep3_decisions_event.2010.desc
		#What kind of theme is it?
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_civilian
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_civilian
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_military
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_military
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_frontier
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_frontier
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_imperial
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_imperial
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_naval
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_naval
			}
			#Is small
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						OR = {
							AND = {
								highest_held_title_tier = tier_kingdom
								sub_realm_size <= 5
							}
							AND = {
								highest_held_title_tier = tier_duchy
								sub_realm_size <= 2
							}
							AND = {
								highest_held_title_tier <= tier_county
								sub_realm_size <= 1
							}
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_small
			}
			#Is big
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						OR = {
							AND = {
								highest_held_title_tier = tier_kingdom
								sub_realm_size >= 20
							}
							AND = {
								highest_held_title_tier <= tier_duchy
								sub_realm_size >= 8
							}
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_theme_big
			}

			desc = ep3_decisions_event.2010.desc_theme_balanced
		}
		#Who lives there?
		first_valid = {
			#Friendly foreigners
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal.capital_county.culture = {
						this != root.culture
						cultural_acceptance = {
							target = root.culture
							value >= 30
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_cool_foreigners
			}
			#Weird foreigners
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal.capital_county.culture = {
						this != root.culture
					}
				}
				desc = ep3_decisions_event.2010.desc_weird_foreigners
			}
			#Same culture as emperor
			desc = ep3_decisions_event.2010.desc_same_culture
		}
		#What faith are they?
		first_valid = {
			#State faith, but not emperor's faith
			triggered_desc = {
				trigger = {
					faith != scope:confirmation_vassal.capital_county.faith
					primary_title.state_faith = {
						this = scope:confirmation_vassal.capital_county.faith
					}
				}
				desc = ep3_decisions_event.2010.desc_state_faith
			}
			#Awful heretics
			triggered_desc = {
				trigger = {
					faith != scope:confirmation_vassal.capital_county.faith
					faith = {
						faith_hostility_level = {
							target = scope:confirmation_vassal.capital_county.faith
							value >= faith_hostile_level
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_heretic_faith
			}
			#Different faith,but alright
			triggered_desc = {
				trigger = {
					faith != scope:confirmation_vassal.capital_county.faith
				}
				desc = ep3_decisions_event.2010.desc_accepted_faith
			}
			#Emperor's faith
			desc = ep3_decisions_event.2010.desc_my_faith
		}
		#Does he like you?
		random_valid = {
			triggered_desc = {
				trigger = {
					#He hates you
					scope:confirmation_vassal = {
						opinion = {
							target = root
							value < -50
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_hate
			}
			triggered_desc = {
				trigger = {
					#He loves you
					scope:confirmation_vassal = {
						opinion = {
							target = root
							value > 50
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_love
			}
			triggered_desc = {
				trigger = {
					#He is old as shit and meh on you
					scope:confirmation_vassal = {
						age > 55
						health < fine_health
					}
				}
				desc = ep3_decisions_event.2010.desc_decrepit
			}
			triggered_desc = {
				trigger = {
					#He is young as shit and meh on you
					scope:confirmation_vassal = {
						age < 25
					}
				}
				desc = ep3_decisions_event.2010.desc_young
			}
			triggered_desc = {
				trigger = {
					#He sucks at his job
					scope:confirmation_vassal = {
						governor_efficiency < 0.75
					}
				}
				desc = ep3_decisions_event.2010.desc_incompetent
			}
			triggered_desc = {
				trigger = {
					#He's great at his job'
					scope:confirmation_vassal = {
						governor_efficiency > 1.25
					}
				}
				desc = ep3_decisions_event.2010.desc_skilled
			}
			#He's just meh
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						NOR = {
							opinion = {
								target = root
								value > 50
							}
							opinion = {
								target = root
								value < -50
							}
							AND = {
								age > 55
								health < fine_health
							}
							age < 25
							governor_efficiency < 0.75
							governor_efficiency > 1.25
						}
					}
				}
				desc = ep3_decisions_event.2010.desc_generic_outro
			}
			
		}
	}
	theme = emperor
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_duty" }

	left_portrait = scope:confirmation_liege
	right_portrait = {
		character = scope:confirmation_vassal
		animation = throne_room_bow_1
	}

	trigger = {
		#is_available = yes
		scope:confirmation_vassal = {
			is_alive = yes
			is_imprisoned = no
		}
	}

	immediate = {
		save_opinion_value_as = {
			name = opinion_of_petitioner
			target = scope:confirmation_vassal
		}
		scope:confirmation_vassal = {
			save_scope_as = second
			assign_quirk_effect = yes
		}
	}


	option = {
		name = ep3_decisions_event.2010.a
		show_as_tooltip = {
			scope:confirmation_vassal = {
				add_prestige = minor_prestige_gain
				change_influence = medium_influence_gain
			}
		}
	}

	after = {
		admin_confirmation_liege_reward_effect = yes
		scope:confirmation_vassal = { trigger_event = ep3_decisions_event.2011 }
	}
}

# Governor learns of result (end)
ep3_decisions_event.2011 = {
	type = court_event
	title = ep3_decisions_event.2010.t
	desc = {
		desc = ep3_decisions_event.2011.desc
		#Is this administration a shitshow?
		random_valid = {
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						age <= 20
					}
				}
				desc = ep3_decisions_event.2011.desc_child
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						faith = {
							NOR = {
								this = scope:confirmation_liege.primary_title.state_faith
								this = scope:confirmation_liege.capital_county.faith
							}
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_heretic
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						is_at_war = yes
						any_character_war = {
							OR = {
								AND = {
									is_attacker = scope:confirmation_liege
									attacker_war_score <= 60
								}
								AND = {
									is_defender = scope:confirmation_liege
									defender_war_score <= 60
								}
							}
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_war
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						OR = {
							AND = {
								diplomacy < average_skill_rating
								stewardship < average_skill_rating
								martial < average_skill_rating
								intrigue < average_skill_rating
								learning < average_skill_rating
							}
							capital_county = {
								county_control < 90
							}
							legitimacy_level < 2
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_poorly_run
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						OR = {
							AND = {
								diplomacy >= average_skill_rating
								stewardship >= average_skill_rating
								martial >= average_skill_rating
								intrigue >= average_skill_rating
								learning >= average_skill_rating
							}
							AND = {
								has_trait = governor
								has_trait_xp = {
									trait = governor
									value >= 75
								}
								
							}
							legitimacy_level >= 4
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_well_run
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						OR = {
							AND = {
								is_female = yes
								has_realm_law = male_preference_law
							}
							AND = {
								is_male = yes
								has_realm_law = female_preference_law
							}
						}
						legitimacy_level < 5
					}
				}
				desc = ep3_decisions_event.2011.desc_gender
			}
			desc = ep3_decisions_event.2011.desc_typical_palace
		}
		#What does emperor think of you?
		first_valid = {
			#Loathes you
			triggered_desc = {
				trigger = {
					reverse_opinion = {
						target = scope:confirmation_liege
						value < -50
					}
				}
				desc = ep3_decisions_event.2011.desc_hate
			}
			#Loves you
			triggered_desc = {
				trigger = {
					reverse_opinion = {
						target = scope:confirmation_liege
						value > 50
					}
				}
				desc = ep3_decisions_event.2011.desc_love
			}
			#meh
			desc = ep3_decisions_event.2011.desc_meh
		}
		#What kind of theme do you have?
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_civilian
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_civilian
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_military
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_military
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_frontier
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_frontier
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_imperial
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_imperial
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						vassal_contract_has_flag = admin_theme_naval
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_naval
			}
			#Is small
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						OR = {
							AND = {
								highest_held_title_tier = tier_kingdom
								sub_realm_size <= 5
							}
							AND = {
								highest_held_title_tier = tier_duchy
								sub_realm_size <= 2
							}
							AND = {
								highest_held_title_tier <= tier_county
								sub_realm_size <= 1
							}
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_small
			}
			#Is big
			triggered_desc = {
				trigger = {
					scope:confirmation_vassal = {
						OR = {
							AND = {
								highest_held_title_tier = tier_kingdom
								sub_realm_size >= 20
							}
							AND = {
								highest_held_title_tier <= tier_duchy
								sub_realm_size >= 8
							}
						}
					}
				}
				desc = ep3_decisions_event.2011.desc_theme_big
			}
			desc = ep3_decisions_event.2011.desc_theme_balanced
		}
		desc = ep3_decisions_event.2011.desc_outro
	}
	theme = administrative
	override_sound = { reference = "event:/SFX/Events/Themes/sfx_event_theme_type_duty" }
	court_scene = {
		button_position_character = scope:confirmation_liege
		court_owner = scope:confirmation_liege
		show_timeout_info = no
		roles = {
		    scope:confirmation_vassal = {
				group = petitioners_group
				animation = throne_room_bow_1
		    }
		}
	}

	trigger = { admin_confirmation_valid_trigger = yes }

	immediate = {
		scope:confirmation_liege = {
			save_scope_as = second
			assign_quirk_effect = yes
			if = {
				limit = { has_royal_court = yes }
				open_view_data = {
					view = royal_court
					secondary_actor = scope:confirmation_vassal
					player = scope:confirmation_vassal
				}
			}
		}
	}


	option = {
		name = ep3_decisions_event.2011.a
	}

	after = {
		admin_confirmation_vassal_reward_effect = yes
		if = {
			limit = {
				scope:confirmation_liege = { has_royal_court = yes }
			}
			close_view = {
				view = royal_court
				player = scope:confirmation_vassal
			}
		}
	}
}

#Confirmation no longer available
ep3_decisions_event.2080 = {
	type = character_event
	title = ep3_decisions_event.2080.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						NOT = { government_allows = administrative }
						primary_title.tier = scope:confirmation_liege.primary_title.tier
					}
				}
				desc = ep3_decisions_event.2080.desc.court
			}
			triggered_desc = {
				trigger = { is_imprisoned = yes }
				desc = ep3_decisions_event.2080.desc.imprisoned
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						is_alive = no
						killer ?= root
					}
				}
				desc = ep3_decisions_event.2080.desc.liege_dead_me
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = { is_alive = no }
				}
				desc = ep3_decisions_event.2080.desc.liege_dead
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = {
						is_imprisoned = yes
						imprisoner ?= root
					}
				}
				desc = ep3_decisions_event.2080.desc.liege_imprisoned_me
			}
			triggered_desc = {
				trigger = {
					scope:confirmation_liege = { is_imprisoned = yes }
				}
				desc = ep3_decisions_event.2080.desc.liege_imprisoned
			}
		}
		triggered_desc = {
			trigger = {
				exists = liege
				NOR = {
					liege = root
					liege = scope:confirmation_liege
				}
				AND = { # Of the Emperor
					top_liege ?= { highest_held_title_tier = tier_empire }
					government_allows = administrative
					liege ?= top_liege
				}
			}
			desc = ep3_decisions_event.2080.desc.new_liege
		}
		triggered_desc = {
			trigger = {
				scope:confirmation_liege = { is_alive = yes }
				exists = liege
				liege != root
			}
			desc = ep3_decisions_event.2080.desc
		}
	}
	theme = administrative
	left_portrait = {
		character = scope:confirmation_liege
		triggered_animation = {
			trigger = { is_imprisoned = yes }
			animation = prisondungeon
		}
		triggered_animation = {
			trigger = { is_alive = no }
			animation = idle
		}
		triggered_animation = {
			trigger = { is_available = no }
			animation = dismissal
		}
	}
	right_portrait = {
		character = liege
		trigger = {
			liege != scope:confirmation_liege
		}
	}

	trigger = { admin_confirmation_valid_trigger = no }

	immediate = {
		# Transfer the variable to a scope for loc & such.
		var:homage_liege_scope ?= { save_scope_as = homage_liege }
	}

	option = {
		name = {
			text = ep3_decisions_event.2080.a_court
			trigger = { has_royal_court = yes }
		}
		name = {
			text = ep3_decisions_event.2080.a_prison
			trigger = { is_imprisoned = yes }
		}
		name = {
			text = ep3_decisions_event.2080.a_liege
			trigger = {
				scope:confirmation_liege = {
					is_alive = yes
					is_imprisoned = no
				}
			}
		}
		name = {
			text = ep3_decisions_event.2080.a
			trigger = { always = yes }
		}
	}

	after = { admin_confirmation_clear_variable_effect = yes }
}

# Invalidation handling
ep3_decisions_event.2090 = {
	hidden = yes
	immediate = {
		if = {
			limit = {
				scope:confirmation_liege = {
					OR = {
						is_alive = no 
						is_imprisoned = yes
						is_travelling = yes
					}
				}
			}
			send_interface_toast = {
				title = admin_confirmation_costs_refunded
				left_icon = root 
				if = { # Remove variable preventing you
					limit = { has_variable = confirmation_grace }
					remove_variable = confirmation_grace
				}
				# Refund any costs
				add_prestige = standard_activity_cost
			}
			trigger_event = ep3_decisions_event.2080
		}
		else = {
			scope:confirmation_liege = { trigger_event = ep3_decisions_event.2001 }
		}
		current_travel_plan ?= {
			delay_travel_plan = { days = 90 }
		}
	}
}


#########################################################
### Restore Backwater Greek Counties Decision Events
### by Chad Uhl

# Event for the Governor when they've completely removed the backwater modifiers
ep3_decisions_event.3000 = {
	type = letter_event
	opening = ep3_decisions_event.3001.opening
	desc = ep3_decisions_event.3000.desc
	sender = top_liege
	
	immediate = {
		show_as_tooltip = {
			every_sub_realm_county = {
				limit = {
					title_province = {
						geographical_region = greek_backwater_modifier_region
					}
				}
				remove_county_modifier = backwater_county_modifier
			}
		}
	}

	option = { 
		name = ep3_decisions_event.3000.a
		# Big influence gain
		change_influence = massive_influence_gain
		# Modifier to improve Stewardship, which in turn improves Governor Efficiency
		add_character_modifier = {
			modifier = restored_greek_theme_modifier
		}
		# Let the player know that they are getting boosted governor efficiency
		custom_tooltip = restored_greek_theme_gov_efficiency_tt
		# Improve relationship with the emperor
		reverse_add_opinion = {
			target = liege
			modifier = impressed_opinion
			opinion = 20
		}
	}
}

# Event for the emperor when all the counties of Greece have been rid of the backwater modifier
ep3_decisions_event.3001 = {
	type = character_event
	title = ep3_decisions_event.3001.t
	desc = ep3_decisions_event.3001.desc
	theme = emperor
	override_background = { reference = council_chamber }
	
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:interlocutor
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}

	trigger = {
		any_sub_realm_county = {
			title_province = { geographical_region = greek_backwater_modifier_region }
		}
		any_sub_realm_county = {
			count = 0
			title_province = {
				geographical_region = greek_backwater_modifier_region
			}
			has_county_modifier = backwater_county_modifier
		}
	}

	# If the emperor isn't valid for this event yet, check next year
	on_trigger_fail = {
		if = { # If the emperor no longer holds any county in this region, then we remove all the modifiers and just call it quits
			limit = {
				any_sub_realm_county = {
					count = 0
					title_province = {
						geographical_region = greek_backwater_modifier_region
					}
				}
			}
			every_county_in_region = {
				region = greek_backwater_modifier_region
				limit = {
					has_county_modifier = backwater_county_modifier
				}
				remove_county_modifier = backwater_county_modifier
			}
		}
		else = { # If the emperor still holds counties in Greece, we will check all this again in a year to see the status
			trigger_event = {
				id = ep3_decisions_event.3001
				years = 1
			}
		}
	}

	immediate = {
		# Find an interlocutor
		if = {
			limit = { exists = cp:councillor_steward }
			cp:councillor_steward = { save_scope_as = interlocutor }
		}
		else_if = {
			limit = { exists = cp:councillor_chancellor }
			cp:councillor_chancellor = { save_scope_as = interlocutor }
		}
		else_if = {
			limit = {
				any_councillor = { } 
			}
			random_councillor = {
				save_scope_as = interlocutor
			}
		}
		else = {
			ordered_vassal = {
				order_by = stewardship
				save_scope_as = interlocutor
			}
		}

		# Create the tooltip showing that all the modifiers have been removed
		show_as_tooltip = {
			custom_tooltip = {
				text = every_county_in_greece_tt
				every_county_in_region = {
					region = greek_backwater_modifier_region
					limit = {
						holder = {
							OR = {
								this = root
								any_liege_or_above = {
									this = root
								}
							}
						}
					}
					remove_county_modifier = backwater_county_modifier
				}
			}
		}
	}

	option = { # Celebrate the Empire's wealth and abundance
		name = ep3_decisions_event.3001.a
		add_legitimacy = minor_legitimacy_gain
		change_influence = major_influence_gain 
	}
}


#########################################################
### Prepare Greek Fire Dromons
### by Jason Cantalini

# Event for the holder of constantinople when they opt into the decision
ep3_decisions_event.3100 = {
	type = character_event
	title = ep3_decisions_event.3100.t
	desc = ep3_decisions_event.3100.desc
	theme = war
	override_background = { reference = docks }
	
	left_portrait = {
		character = root
		animation = debating
	}
	right_portrait = {
		character = scope:aide
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}

	immediate = {
		# Find an interlocutor
		if = {
			limit = { exists = cp:councillor_marshal }
			cp:councillor_steward = { save_scope_as = aide }
		}
		else_if = {
			limit = { exists = cp:councillor_steward }
			cp:councillor_chancellor = { save_scope_as = aide }
		}
		else_if = {
			limit = {
				any_councillor = { } 
			}
			random_councillor = {
				save_scope_as = aide
			}
		}
		else_if = {
			limit = {
				vassal_count >= 1
			}
			ordered_vassal = {
				order_by = martial
				save_scope_as = aide
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_alive = yes
				}
			}
			ordered_courtier = {
				order_by = martial
				save_scope_as = aide
			}
		}
		else = {
			random_pool_character = {
				province = root.capital_province
				limit = {
					is_adult = yes
				}
				save_scope_as = aide
			}
		}
	}

	option = { #Use the city's native capabilities to produce what's needed
		name = ep3_decisions_event.3100.a
		trigger = {
			influence >= major_influence_value
		}
		show_as_unavailable = { influence < massive_influence_value }
		save_scope_as = actor
		add_character_flag = {
			flag = took_greek_fire_decision_flag
			years = 10
		}
		begin_scheme_with_agents_effect = {
			SCHEME_TYPE = prepare_fire_dromons_scheme
			TARGET_TYPE = target_title
			TARGET_SCOPE = root.capital_county
			# Success.
			AGENT_1 = agent_alchemist
			AGENT_2 = agent_draughtsman
			# Speed.
			AGENT_3 = agent_drillmaster
			AGENT_4 = agent_supplier
			AGENT_5 = agent_bureaucrat_title
		}
		custom_tooltip = defensive_fire_dromons_success_tooltip
		custom_tooltip = defensive_fire_dromons_custom_desc
		custom_tooltip = defensive_fire_dromons_buildings_desc
		change_influence = major_influence_loss
		
		stress_impact = {
			compassionate = medium_stress_impact_gain
			calm = miniscule_stress_impact_gain
			content = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				factor = 0
				influence < massive_influence_value
			}
			modifier = {
				factor = 0
			}
		}
	}
	option = { #Have the latins manufacture ships
		name = ep3_decisions_event.3100.b
		trigger = {
			treasury >= major_gold_value_static_max
		}
		show_as_unavailable = { treasury < massive_gold_value_static_max }
		save_scope_as = actor
		add_character_flag = {
			flag = took_greek_fire_decision_flag
			years = 10
		}
		begin_scheme_with_agents_effect = {
			SCHEME_TYPE = prepare_fire_dromons_scheme
			TARGET_TYPE = target_title
			TARGET_SCOPE = root.capital_county
			# Success.
			AGENT_1 = agent_alchemist
			AGENT_2 = agent_draughtsman
			# Speed.
			AGENT_3 = agent_drillmaster
			AGENT_4 = agent_supplier
			AGENT_5 = agent_bureaucrat_title
		}
		custom_tooltip = defensive_fire_dromons_success_tooltip
		custom_tooltip = defensive_fire_dromons_custom_desc
		custom_tooltip = defensive_fire_dromons_buildings_desc
		remove_treasury_or_gold = major_gold_value_static_max
		
		stress_impact = {
			compassionate = medium_stress_impact_gain
			paranoid = minor_stress_impact_gain
			calm = miniscule_stress_impact_gain
			content = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -0.5
			}
			modifier = {
				factor = 0
				treasury < massive_gold_value_static_max
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = paranoid
				}
			}
		}
	}
	option = { #Actually... never mind
		name = ep3_decisions_event.3100.c
		remove_decision_cooldown = prepare_greek_fire_dromons_decision
		stress_impact = {
			sadistic = minor_stress_impact_gain
			callous = miniscule_stress_impact_gain
			ambitious = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					has_trait = compassionate
					has_trait = calm
					has_trait = content
				}
			}
		}
	}
}


#########################################################
### Mass Arrests Decision Events
### by Chad Uhl

#ep3_decisions_event.3200 = {
#	type = character_event
#	title = ep3_decisions_event.3200.t
#	desc = ep3_decisions_event.3200.desc
#	theme = emperor
#
#	left_portrait = {
#		character = scope:pf_1.house_head
#		animation = spymaster
#	}
#	right_portrait = {
#		character = scope:pf_2.house_head
#		animation = scheme
#	}
#	lower_left_portrait = scope:pf_3.house_head
#	lower_center_portrait = scope:pf_4.house_head
#	lower_right_portrait = scope:pf_5.house_head
#	
#	immediate = {
#		every_powerful_family = {
#			limit = { NOT = { root.house ?= this } }
#			add_to_list = powerful_families
#		}
#		ordered_powerful_family = {
#			limit = {
#				NOR = {
#					root.house ?= this
#					scope:pf_1 ?= this
#					scope:pf_2 ?= this
#					scope:pf_3 ?= this
#					scope:pf_4 ?= this
#					scope:pf_5 ?= this
#				}
#			}
#			order_by = house_power_score
#			max = 5
#			check_range_bounds = no
#
#			if = {
#				limit = {
#					exists = scope:pf_4
#					list_size:powerful_families >= 5
#				}
#				save_scope_as = pf_5
#			}
#			else_if = {
#				limit = {
#					exists = scope:pf_3
#					list_size:powerful_families >= 4
#				}
#				save_scope_as = pf_4
#			}
#			else_if = {
#				limit = {
#					exists = scope:pf_2
#					list_size:powerful_families >= 3
#				}
#				save_scope_as = pf_3
#			}
#			else_if = {
#				limit = {
#					exists = scope:pf_1
#					list_size:powerful_families >= 2
#				}
#				save_scope_as = pf_2
#			}
#			else = {
#				save_scope_as = pf_1
#			}
#		}
#	}
#
#	option = {
#		name = ep3_decisions_event.3200.a
#		trigger = { exists = scope:pf_1 }
#		highlight_portrait = scope:pf_1.house_head
#		scope:pf_1 = { 3200_house_member_effect = yes }
#		add_legitimacy = medium_legitimacy_loss
#		add_tyranny = massive_tyranny_gain
#
#		if = {
#			limit = { scope:pf_1.house_head = { is_ai = yes } }
#			trigger_event = {
#				id = ep3_decisions_event.3201 
#				days = 5
#			}
#		}
#
#		ai_chance = {
#			base = 50
#			modifier = {
#				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pf_1.house_head }
#				factor = 0
#			}
#			modifier = {
#				has_relation_nemesis = scope:pf_1.house_head
#				add = 100
#			}
#			modifier = {
#				has_relation_rival = scope:pf_1.house_head
#				add = 50
#			}
#		}
#	}
#
#	option = {
#		name = ep3_decisions_event.3200.b
#		trigger = { exists = scope:pf_2 }
#		highlight_portrait = scope:pf_2.house_head
#		scope:pf_2 = { 3200_house_member_effect = yes }
#		add_legitimacy = medium_legitimacy_loss
#		add_tyranny = massive_tyranny_gain
#
#		if = {
#			limit = { scope:pf_2.house_head = { is_ai = yes } }
#			trigger_event = {
#				id = ep3_decisions_event.3201 
#				days = 5
#			}
#		}
#
#		ai_chance = {
#			base = 40
#			modifier = {
#				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pf_2.house_head }
#				factor = 0
#			}
#			modifier = {
#				has_relation_nemesis = scope:pf_2.house_head
#				add = 100
#			}
#			modifier = {
#				has_relation_rival = scope:pf_2.house_head
#				add = 50
#			}
#		}
#	}
#	
#	option = {
#		name = ep3_decisions_event.3200.c
#		trigger = { exists = scope:pf_3 }
#		highlight_portrait = scope:pf_3.house_head
#		scope:pf_3 = { 3200_house_member_effect = yes }
#		add_legitimacy = medium_legitimacy_loss
#		add_tyranny = massive_tyranny_gain
#
#		if = {
#			limit = { scope:pf_3.house_head = { is_ai = yes } }
#			trigger_event = {
#				id = ep3_decisions_event.3201 
#				days = 5
#			}
#		}
#
#		ai_chance = {
#			base = 30
#			modifier = {
#				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pf_3.house_head }
#				factor = 0
#			}
#			modifier = {
#				has_relation_nemesis = scope:pf_3.house_head
#				add = 100
#			}
#			modifier = {
#				has_relation_rival = scope:pf_3.house_head
#				add = 50
#			}
#		}
#	}
#	
#	option = {
#		name = ep3_decisions_event.3200.d
#		trigger = { exists = scope:pf_4 }
#		highlight_portrait = scope:pf_4.house_head
#		scope:pf_4 = { 3200_house_member_effect = yes }
#		add_legitimacy = medium_legitimacy_loss
#		add_tyranny = massive_tyranny_gain
#
#		if = {
#			limit = { scope:pf_4.house_head = { is_ai = yes } }
#			trigger_event = {
#				id = ep3_decisions_event.3201 
#				days = 5
#			}
#		}
#
#		ai_chance = {
#			base = 20
#			modifier = {
#				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pf_4.house_head }
#				factor = 0
#			}
#			modifier = {
#				has_relation_nemesis = scope:pf_4.house_head
#				add = 100
#			}
#			modifier = {
#				has_relation_rival = scope:pf_4.house_head
#				add = 50
#			}
#		}
#	}
#	
#	option = {
#		name = ep3_decisions_event.3200.e
#		trigger = { exists = scope:pf_5 }
#		highlight_portrait = scope:pf_5.house_head
#		scope:pf_5 = { 3200_house_member_effect = yes }
#		add_legitimacy = medium_legitimacy_loss
#		add_tyranny = massive_tyranny_gain
#
#		if = {
#			limit = { scope:pf_5.house_head = { is_ai = yes } }
#			trigger_event = {
#				id = ep3_decisions_event.3201 
#				days = 5
#			}
#		}
#
#		ai_chance = {
#			base = 10
#			modifier = {
#				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:pf_5.house_head }
#				factor = 0
#			}
#			modifier = {
#				has_relation_nemesis = scope:pf_5.house_head
#				add = 100
#			}
#			modifier = {
#				has_relation_rival = scope:pf_5.house_head
#				add = 50
#			}
#		}
#	}
#
#	option = { # I changed my mind
#		name = ep3_decisions_event.3200.f
#		remove_decision_cooldown = mass_arrests_decision
#	}
#}

# House head begs for release
ep3_decisions_event.3201 = {
	type = character_event
	title = ep3_decisions_event.3201.t
	desc = ep3_decisions_event.3201.desc
	theme = emperor

	left_portrait = {
		character = scope:imprisoned_house_head
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = root
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	
	trigger = {
		scope:imprisoned_house_head = {
			is_alive = yes
			is_imprisoned_by = root
		}
	}

	option = { # Release Them
		name = ep3_decisions_event.3201.a
		scope:imprisoned_house_head = {
			release_from_prison = yes
		}
		if = {
			limit = {
				can_add_hook = {
					target = scope:imprisoned_house_head
					type = liege_favour_strong_hook
				}
			}
			add_hook = {
				target = scope:imprisoned_house_head
				type = liege_favour_strong_hook
			}
		}
		
		scope:imprisoned_house_head = {
			if = {
				limit = {
					NOR = {
						# Cannot have any of these traits
						has_trait = vengeful
						has_trait = wrathful
						has_trait = ambitious
						
						# And not already be loyal
						has_trait = loyal
						
						# And not be a rival
						NOT = { has_relation_rival = root }
					}
					is_ai = yes
				}
				random = {
					chance = {
						value = 15
						if = {
							limit = {
								has_trait = craven
							}
							add = 15
						}
						if = {
							limit = {
								has_trait = content
							}
							add = 10
						}
						if = {
							limit = {
								has_trait = forgiving
							}
							add = 5
						}
						if = {
							limit = {
								has_trait = honest
							}
							add = 5
						}
						if = {
							limit = {
								has_trait = trusting
							}
							add = 5
						}
					}
					add_trait = loyal
				}
			}
		}

		ai_chance = {
			base = 50
			modifier = {
				has_trait = vengeful
				factor = 0
			}
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = trusting
				}
				factor = 2
			}
		}
	}

	option = { # No
		name = ep3_decisions_event.3201.b
		add_dread = medium_dread_gain

		ai_chance = {
			base = 50
			modifier = {
				OR = {
					has_trait = forgiving
					has_trait = trusting
				}
				factor = 0
			}
		}
	}
}


#########################################################
### Re-establish the original Eastern Empire
### by Claudia Baldassi

ep3_decisions_event.4000 = {
	type = character_event
	title = ep3_decisions_event.4000.t
	desc = ep3_decisions_event.4000.desc
	theme = emperor
	override_background = { reference = ep3_hippodrome_track }
	left_portrait = {
		character = root
		animation = jockey_wave
		camera = camera_event_horse_left
	}

	immediate = {
		play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Byzantine_Flavor/ep3_mx_sting_byzantineflavor_hold_triumph"
		retake_eastern_provinces_decision_effect = yes
		create_character_memory = {
			type = byz_theodosian_border_memory
		}
	}

	option = {
		name = ep3_decisions_event.4000.a
	}
}

scripted_effect send_help_from_called_effect = {
	scope:caller = {
		pay_treasury_or_gold = {
			target = scope:called
			value = major_treasury_or_gold_value
		}
		spawn_army = {
			levies = 4000
			men_at_arms = {
				type = conrois
				men = 500
			}
			location = scope:caller.capital_province
			origin = scope:called.capital_province
			war = scope:our_war
			name = ep3_religious_volunteers_army
		}
	}
	scope:called = {
		add_character_modifier = {
			modifier = ep3_sent_help_to_east_modifier
			years = 10
		}
	}
}

#Ask an ally for war help
ep3_decisions_event.4010 = {
	type = letter_event
	opening = ep3_decisions_event.4010.t
	desc = ep3_decisions_event.4010.desc
	sender = scope:caller

	immediate = {
		save_scope_as = called
		faith.religious_head = { save_scope_as = pope }
	}

	#Option A: we will help
	option = {
		name = ep3_decisions_event.4010.a
		scope:caller = {
			trigger_event = {
				id = ep3_decisions_event.4015
				days = 2
			}
		}
		show_as_tooltip = {
			send_help_from_called_effect = yes
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 0.5
				ai_sociability = 0.5
			}
		}
	}
	#Option B: ask the pope
	option = {
		name = ep3_decisions_event.4010.b
		flavor = ep3_decisions_event.4010.b.tt_2
		save_scope_as = sponsor
		scope:pope = {
			trigger_event = {
				id = ep3_decisions_event.4012
				days = 2
			}
		}
		scope:caller = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4010.b.tt
	  			left_icon = root
	  			right_icon = scope:pope
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:pope
				multiplier = 1
			}
			opinion_modifier = {
				who = scope:pope
				opinion_target = root
				multiplier = 2
			}
		}
	}
	#Option C: no
	option = {
		name = ep3_decisions_event.4010.c
		scope:caller = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4010.c.tt
	  			left_icon = scope:called
			}
		}
		ai_chance = {
			base = 25
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = -2
			}
		}
	}
}

scripted_trigger ask_help_valid_for_crusades_trigger = {
# There is in the world a christian faith with crusades and a HoF to call them (mainly Catholic)
	religion:christianity_religion = {
		exists = var:variable_ghw_unlocked
		NOT = { exists = var:variable_first_ghw_cooldown }
	}
	scope:pope = { 
		is_imprisoned = no
		faith = {
			has_doctrine_parameter = great_holy_wars_active
			fervor >= 60
		}
	}
}

#Ask the pope
ep3_decisions_event.4011 = {
	type = letter_event
	opening = ep3_decisions_event.4010.t
	desc = ep3_decisions_event.4010.desc
	sender = scope:caller

	immediate = {
		save_scope_as = called
		save_scope_as = pope
	}

	#Option A: send help
	option = {
		name = ep3_decisions_event.4010.a
		scope:caller = {
			trigger_event = {
				id = ep3_decisions_event.4015
				days = 2
			}
		}
		show_as_tooltip = {
			send_help_from_called_effect = yes
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 0.5
			}
		}
	}
	#Option B: call crusade
	option = {
		name = ep3_decisions_event.4011.b
		trigger = {
			faith = {
				NOT = { exists = great_holy_war }
			}
			ask_help_valid_for_crusades_trigger = yes
		}
		if = {
			limit = {
				faith = {
					fervor >= 60
					fervor < 75
				}
			}
			faith = {
				change_fervor = {
					value = minor_fervor_value
					desc = called_for_help_fervor
				}
			}
		}
		scope:caller = {
			trigger_event = {
				id = ep3_decisions_event.4013
				days = 3
			}
		}
		ai_chance = {
			base = 100
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = 2
			}
			ai_value_modifier = {
				ai_zeal = 2
			}
		}
	}
	#Option C: no
	option = {
		name = ep3_decisions_event.4011.c
		scope:caller = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4010.c.tt
	  			left_icon = scope:called
			}
		}
		ai_chance = {
			base = 25
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = -2
			}
		}
	}
}

#The ally asks the pope
ep3_decisions_event.4012 = {
	type = letter_event
	opening = ep3_decisions_event.4012.t
	desc = ep3_decisions_event.4012.desc
	sender = scope:sponsor

	immediate = {
		save_scope_as = called
		save_scope_as = pope
	}

	#Option A: send help
	option = {
		name = ep3_decisions_event.4012.a
		scope:caller = {
			trigger_event = {
				id = ep3_decisions_event.4015
				days = 2
			}
		}
		scope:sponsor = {
			send_interface_toast = {
				title = ep3_decisions_event.4012.a.tt
				left_icon = scope:pope
				right_icon = scope:caller
				show_as_tooltip = {
					send_help_from_called_effect = yes
				}
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = 0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = 0.5
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:sponsor
				multiplier = 1
			}
		}
	}
	#Option B: call crusade
	option = {
		name = ep3_decisions_event.4012.b
		trigger = {
			faith = {
				NOT = { exists = great_holy_war }
			}
			ask_help_valid_for_crusades_trigger = yes
		}
		if = {
			limit = {
				faith = {
					fervor >= 60
					fervor < 75
				}
			}
			faith = {
				change_fervor = {
					value = minor_fervor_value
					desc = called_for_help_fervor
				}
			}
		}
		scope:caller = {
			trigger_event = {
				id = ep3_decisions_event.4013
				days = 3
			}
		}
		scope:sponsor = {
			send_interface_toast = {
				title = ep3_decisions_event.4012.b.tt
				left_icon = scope:pope
				right_icon = scope:caller
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = 1
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:sponsor
				multiplier = 2
			}
		}
	}
	#Option C: no
	option = {
		name = ep3_decisions_event.4011.c
		scope:caller = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4010.c.tt
	  			left_icon = scope:called
			}
		}
		scope:sponsor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4010.c.tt
	  			left_icon = scope:called
			}
		}
		ai_chance = {
			base = 25
			opinion_modifier = {
				who = root
				opinion_target = scope:caller
				multiplier = -1
			}
			opinion_modifier = {
				who = root
				opinion_target = scope:sponsor
				multiplier = -2
			}
		}
	}
}

#The pope asks for support for a crusade
ep3_decisions_event.4013 = {
	type = letter_event
	opening = ep3_decisions_event.4013.t
	desc = ep3_decisions_event.4013.desc
	sender = scope:pope

	#Option A: pledge to send money
	option = {
		name = ep3_decisions_event.4013.a
		custom_tooltip = ep3_decisions_event.4013.a.tt
		add_character_flag = pledged_money_to_crusade_support
		create_character_memory = {
			type = western_help_pope
			participants = { pope = scope:pope enemy = scope:enemy }
		}
		scope:pope = {
			trigger_event = {
				id = ep3_decisions_event.4014
				days = 3
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_vengefulness = 1
				ai_greed = -0.5
			}
			modifier = {
				scope:our_war = {
					is_defender = root
					attacker_war_score > 30
				}
				add = 50
			}
			modifier = {
				scope:our_war = {
					is_defender = root
					attacker_war_score > 60
				}
				add = 100
			}
			modifier = {
				scope:our_war = {
					is_attacker = root
					defender_war_score > 30
				}
				add = 50
			}
			modifier = {
				scope:our_war = {
					is_attacker = root
					defender_war_score > 60
				}
				add = 100
			}
			modifier = {
				factor = 0
				gold <= massive_gold_value
			}
		}
	}
	#Option B: nevermind then
	option = {
		name = ep3_decisions_event.4013.b
		scope:pope = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4013.b.tt
	  			left_icon = scope:caller
			}
		}
		scope:sponsor ?= {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4013.b.tt
	  			left_icon = scope:caller
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
}

scripted_effect ask_help_crusade_setup_effect = {
	great_holy_war = {
		set_war_declarer = scope:ghw_sponsor
		if = {
			limit = { is_directed_ghw = no }
			undirected_ghw_recipient_selection_effect = yes
		}
	}
	if = {
		limit = { scope:ghw_sponsor.gold > 0 }
		great_holy_war = {
			change_war_chest_gold = {
				value = scope:ghw_sponsor.gold
				divide = 2
				max = 5000
			}
		}
		scope:ghw_sponsor = {
			remove_short_term_gold = {
				value = gold
				divide = 2
				max = 5000
			}
		}
	}
	great_holy_war = {
		pledge_attacker = scope:ghw_sponsor
		set_variable = {
			name = redirect_cost
			value = 500
		}
	}
	#If no Claimant or Title Holder is available to be the Papal choice and the Crusade has not proceeded far enough to have a favoritebeneficiary, select a fallback Recipient so that the CB's tooltip does not appear incomplete.
	if = { #Random Courtier in the Pope's court.
		limit = {
			NOT = { exists = faith.great_holy_war.ghw_title_recipient }
			exists = scope:ghw_sponsor
			exists = scope:the_faith.great_holy_war
			scope:ghw_sponsor = {
				any_courtier = {
					is_adult = yes
					is_ai = yes
					NOR = {
						has_trait = excommunicated
						has_trait = incapable
						has_trait = devoted
					}
					faith = scope:the_faith
				}
			}
		}
		scope:ghw_sponsor = {
			random_courtier = {
				alternative_limit = {
					scope:the_faith = { has_doctrine = doctrine_gender_male_dominated }
					is_male = yes
					is_adult = yes
					is_ai = yes
					NOR = {
						has_trait = excommunicated
						has_trait = incapable
						has_trait = devoted
					}
					faith = scope:the_faith
				}
				alternative_limit = {
					scope:the_faith = { has_doctrine = doctrine_gender_female_dominated }
					is_female = yes
					is_adult = yes
					is_ai = yes
					NOR = {
						has_trait = excommunicated
						has_trait = incapable
						has_trait = devoted
					}
					faith = scope:the_faith
				}
				limit = {
					is_adult = yes
					is_ai = yes
					NOR = {
						has_trait = excommunicated
						has_trait = incapable
						has_trait = devoted
					}
					faith = scope:the_faith
				}
				save_scope_as = fallback_recipient
				add_character_flag = flag_is_ghw_fallback_recipient
			}
		}
	}
	else_if = { #Else Generate a fallback recipient.
		limit = {
			NOT = { exists = faith.great_holy_war.ghw_title_recipient }
		}
		create_character = {
			location = scope:ghw_sponsor.capital_province
			template = new_commander_character
			faith = scope:the_faith
			culture = scope:ghw_sponsor.culture
			save_scope_as = fallback_recipient
			gender_female_chance = {
				if = {
					limit = {
						scope:the_faith = { has_doctrine = doctrine_gender_male_dominated }
					}
					add = 0
				}
				else_if = {
					limit = {
						scope:the_faith = { has_doctrine = doctrine_gender_female_dominated }
					}
					add = 100
				}
				else = {
					add = 50
				}
			}
		}
		scope:fallback_recipient = { add_character_flag = flag_is_ghw_fallback_recipient }
	}
	great_holy_war = {
		set_variable = {
			name = var_fallback_recipient
			value = scope:fallback_recipient
		}
	}
	every_player = { #Inform players
		limit = {
			faith = scope:the_faith
			highest_held_title_tier >= tier_county
			this != scope:ghw_sponsor
		}
		trigger_event = great_holy_war.0003 #Send event immediately for player, then delay it for all the AIs.
	}
	every_player = { #Inform defending players
		limit = {
			OR = {
				faith = scope:target_faith #All infidels.
				any_liege_or_above = {
					scope:the_faith.great_holy_war = { has_pledged_defender = prev }
				}
				AND = {
					faith != scope:the_faith
					scope:the_faith.great_holy_war = { has_pledged_defender = prev }
				}
			}
		}
		trigger_event = great_holy_war.0050
	}
	#Attackers Pledge to the Crusade. (AI only)
	every_faith_ruler = {
		limit = {
			is_ai = yes
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOR = {
				this = scope:ghw_sponsor
				scope:the_faith.great_holy_war = { has_pledged_attacker = prev }
				target_is_liege_or_above = scope:target_character
			}
		}
		trigger_event = {
			#AI pledging. There is a chance the AI might pledge after the Crusade starts, but it's a lot less likely.
			id = great_holy_war.0020
			days = { 50 450 }
		}
	}
	every_faith_holy_order = {
		trigger_event = {
			#Holy orders always join
			id = great_holy_war.0090
			days = { 30 60 }
		}
	}
	#Defenders Pledge to the Crusade. (AI only)
	scope:target_character = {
		religion = {
			every_faith = {
				every_faith_ruler = {
					limit = {
						is_ai = yes
						is_landed = yes
						highest_held_title_tier >= tier_county
						NOT = {
							scope:the_faith.great_holy_war = { has_pledged_defender = prev }
						}
					}
					trigger_event = {
						#AI counterpledging. Unlike attackers, defenders should be selected much faster during the preparation phase and then stop.
						id = great_holy_war.0021
						days = { 25 150 }
					}
				}
			}
		}
		faith = {
			every_faith_holy_order = {
				trigger_event = {
					# Holy orders always join
					id = great_holy_war.0091
					days = { 30 60 }
				}
			}
		}
	}
}

#Responded yes to the pope
ep3_decisions_event.4014 = {
	type = letter_event
	opening = ep3_decisions_event.4010.t
	desc = ep3_decisions_event.4014.desc
	sender = scope:caller

	#Option A: unleash the crusade!
	option = {
		name = ep3_decisions_event.4014.a
		faith = { save_scope_as = the_faith }
		save_scope_as = ghw_sponsor
		scope:enemy = { save_scope_as = target_character }
		# Launch the preparation phase
		faith = {
			start_great_holy_war = {
				target_character = scope:target_character
				target_title = scope:target_kingdom
				delay = { 365 545 }
			}
		}
		scope:target_character.faith = { save_scope_as = target_faith }
		faith = { ask_help_crusade_setup_effect = yes }
		if = {
			limit = {
				scope:caller = {
					has_character_flag = pledged_money_to_crusade_support
				}
			}
			scope:caller = {
				send_interface_toast = {
					title = ep3_decisions_event.4014.a.tt
					left_icon = scope:ghw_sponsor
					remove_treasury_or_gold = massive_treasury_or_gold_value
					scope:ghw_sponsor.faith.great_holy_war = {
						change_war_chest_gold = {
							value = scope:caller.massive_gold_value
						}
					}
				}
			}
		}
	}
	after = {
	 	scope:caller = { remove_character_flag = pledged_money_to_crusade_support }
	}
}

#Called offers help in exchange for something
ep3_decisions_event.4015 = {
	type = letter_event
	opening = ep3_decisions_event.4013.t
	desc = ep3_decisions_event.4015.desc
	sender = scope:called

	#Option A: accept
	option = {
		name = ep3_decisions_event.4015.a
		scope:called = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4015.a.tt
	  			left_icon = scope:caller
	  			scope:caller = {
	  				pay_treasury_or_gold = {
	  					target = scope:called
	  					value = major_treasury_or_gold_value
	  				}
	  				spawn_army = {
	  					levies = 4000
	  					men_at_arms = {
	  						type = conrois
	  						men = 500
	  					}
	  					location = scope:caller.capital_province
	  					origin = scope:called.capital_province
	  					war = scope:our_war
	  					name = ep3_religious_volunteers_army
	  				}
	  				create_character_memory = {
						type = western_help_ally
						participants = { ally = scope:called enemy = scope:enemy }
					}
	  			}
	  			add_character_modifier = {
	  				modifier = ep3_sent_help_to_east_modifier
	  				years = 10
	  			}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				scope:our_war = {
					is_defender = root
					attacker_war_score > 30
				}
				add = 50
			}
			modifier = {
				scope:our_war = {
					is_defender = root
					attacker_war_score > 60
				}
				add = 100
			}
			modifier = {
				scope:our_war = {
					is_attacker = root
					defender_war_score > 30
				}
				add = 50
			}
			modifier = {
				scope:our_war = {
					is_attacker = root
					defender_war_score > 60
				}
				add = 100
			}
			ai_value_modifier = {
				ai_greed = -0.5
			}
			modifier = {
				factor = 0
				treasury_or_gold <= major_treasury_or_gold_value
			}
		}
	}

	#Option B: refuse
	option = {
		name = ep3_decisions_event.4015.b
		scope:called = {
			send_interface_toast = {
				type = event_toast_effect_neutral
	  			title = ep3_decisions_event.4013.b.tt
	  			left_icon = scope:caller
			}
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}
}


ep3_decisions_event.4020 = {
	type = character_event
	title = ep3_decisions_event.4020.t
	desc = ep3_decisions_event.4020.desc
	theme = emperor
	override_background = { reference = ep3_hagia_sophia }
	
	left_portrait = {
		character = root
		animation = prayer
	}
	right_portrait = {
		character = scope:evangelizer
		animation = wedding_priest
	}
	lower_right_portrait = scope:pagan

	immediate = {
		if = {
			limit = {
				has_title = title:e_byzantium
			}
			random_neighboring_and_across_water_top_liege_realm_owner = {
				limit = {
					valid_for_pagan_conversion_trigger = yes
				}
				save_scope_as = pagan
			}
		}
		else = {
			random_neighboring_and_across_water_realm_same_rank_owner = {
				limit = {
					valid_for_pagan_conversion_trigger = yes
				}
				save_scope_as = pagan
			}
		}
		scope:pagan.primary_title = { save_scope_as = title_to_convert }
		random_pool_character = {
			province = root.location
			limit = {
				faith = root.faith
				learning >= 18
			}
			save_scope_as = evangelizer
		}
		if = {
			limit = {
				NOT = { exists = scope:evangelizer }
			}
			random_list = {
				25 = {
					trigger = { NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_female } } }
					create_character = {
						location = root.location
						name = "Kyrillos"
						template = ep3_evangelizer_template
						gender_female_chance = 0
						save_scope_as = evangelizer
					}
				}
				25 = {
					trigger = { NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_female } } }
					create_character = {
						location = root.location
						name = "Methodios"
						template = ep3_evangelizer_template
						gender_female_chance = 0
						save_scope_as = evangelizer
					}
				}
				25 = {
					trigger = { NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_female } } }
					create_character = {
						location = root.location
						name = "Konstantinos"
						template = ep3_evangelizer_template
						gender_female_chance = 0
						save_scope_as = evangelizer
					}
				}
				25 = {
					trigger = { NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_female } } }
					create_character = {
						location = root.location
						name = "Michael"
						template = ep3_evangelizer_template
						gender_female_chance = 0
						save_scope_as = evangelizer
					}
				}
				25 = {
					trigger = { NOT = { root.faith = { has_doctrine_parameter = clergy_must_be_male } } }
					create_character = {
						location = root.location
						template = ep3_evangelizer_template
						gender_female_chance = 100
						save_scope_as = evangelizer
					}
				}
			}
		}
		add_courtier = scope:evangelizer
		save_scope_as = sender
		location = { save_scope_as = starting_point }
	}

	option = {
		name = ep3_decisions_event.4020.a
		custom_tooltip = ep3_decisions_event.4020.a.tt
		scope:evangelizer = {
			start_travel_plan = {
				destination = scope:pagan.capital_province
				on_arrival_event = ep3_decisions_event.4021
				on_arrival_destinations = all
				return_trip = no # One way
			}
		}
	}
}

ep3_decisions_event.4021 = {
	hidden = yes

	immediate = {
		#scope:evangelizer = { set_location = { location = scope:pagan.capital_province stick_to_location = yes } }
		scope:pagan = { add_visiting_courtier = scope:evangelizer }
		if = {
			limit = {
				scope:pagan = {
					OR = {
						is_alive = no
						is_landed = no
					}
				}
			}
			scope:title_to_convert.holder = { save_scope_as = pagan }
		}
		scope:pagan.faith = { save_scope_as = old_faith }
		# Player event for scope:pagan
		if = {
			limit = {
				scope:pagan = { is_ai = no }
			}
			scope:pagan = {
				trigger_event = {
					id = ep3_decisions_event.4022
					days = 1
				}
			}
		}
		# AI event for the evangelizer
		else = {
			scope:evangelizer = {
				trigger_event = {
					id = ep3_decisions_event.4023
					days = 1
				}
			}
		}
	}
}

ep3_decisions_event.4022 = {
	type = character_event
	title = ep3_decisions_event.4020.t
	desc = ep3_decisions_event.4022.desc
	theme = emperor
	
	trigger = {
		scope:evangelizer = { is_alive = yes }
	}

	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:evangelizer
		animation = wedding_priest
	}
	lower_right_portrait = scope:sender

	#Option A: hear them out
	option = {
		name = ep3_decisions_event.4022.a
		create_character_memory = {
			type = was_evangelized_memory
			participants = { missionary = scope:evangelizer sender = scope:sender }
		}
		set_character_faith_with_conversion = scope:evangelizer.faith
		custom_tooltip = ep3_decisions_event.4022.a.tt
		custom_tooltip = negotiated_alliance_delay_tt
		show_as_tooltip = {
			create_alliance = {
				target = scope:sender
				allied_through_owner = scope:pagan
				allied_through_target = scope:sender
			}
			scope:sender = {
				add_opinion = {
					target = scope:pagan
					modifier = event_negotiated_alliance_opinion
				}
			}
		}
		scope:evangelizer = {
			add_character_flag = success_conversion
		}
		scope:sender = {
			create_character_memory = {
				type = evangelized_memory
				participants = { missionary = scope:evangelizer pagan = scope:pagan }
			}
		}
		stress_impact = {
			zealous = major_stress_impact_gain
			content = major_stress_impact_gain
			craven = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
	}

	#Option C: no thanks with stab
	option = {
		name = ep3_decisions_event.4022.c
		flavor = ep3_decisions_event.4022.c.tt
		add_piety = major_piety_gain
		scope:evangelizer = {
			death = {
				death_reason = death_execution
				killer = root
			}
		}
		scope:sender = {
			trigger_event = {
				id = ep3_decisions_event.4026
				days = 3
			}
		}
		scope:pagan = {
			add_character_flag = do_not_disturb_preachers
		}
		scope:title_to_convert = {
			set_variable = do_not_disturb_preachers
		}
		stress_impact = {
			compassionate = major_stress_impact_gain
			calm = major_stress_impact_gain
			gregarious = medium_stress_impact_gain
			zealous = medium_stress_impact_gain
		}
	}

	#Option B: no thanks
	option = {
		name = ep3_decisions_event.4022.b
		add_piety = medium_piety_gain
		scope:evangelizer = {
			add_character_flag = failed_conversion
		}
	}

	after = {
		if = {
			limit = {
				scope:sender = { is_alive = yes }
				scope:evangelizer = { is_alive = yes }
			}
			scope:evangelizer = {
				start_travel_plan = {
					destination = scope:sender.location
					on_arrival_event = ep3_decisions_event.4024
					on_arrival_destinations = all
					return_trip = no # One way
				}
			}
		}
		else_if = {
			limit = {
				scope:evangelizer = { is_alive = yes }
			}
			scope:evangelizer = {
				start_travel_plan = {
					destination = scope:starting_point
					on_arrival_event = ep3_decisions_event.4024
					on_arrival_destinations = all
					return_trip = no # One way
				}
			}
		}
	}
}

ep3_decisions_event.4023 = {
	type = character_event
	title = ep3_decisions_event.4023.t
	desc = ep3_decisions_event.4023.desc
	theme = emperor
	
	trigger = {
		scope:evangelizer = { is_alive = yes }
	}

	left_portrait = {
		character = root
		animation = wedding_priest
	}
	right_portrait = {
		character = scope:pagan
		animation = thinking
	}
	lower_right_portrait = scope:sender

	immediate = {
		scope:evangelizer = {
			duel = {
				skill = learning
				target = scope:pagan
				50 = { # Convert
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					modifier = {
						scope:pagan = {
							has_trait = fickle
						}
						add = 10
					}
					modifier = {
						scope:pagan = {
							has_trait = craven
						}
						add = 10
					}
					modifier = {
						scope:pagan = {
							has_trait = intellect_bad
						}
						add = 10
					}
					scope:pagan = {
						set_character_faith_with_conversion = scope:evangelizer.faith
						create_character_memory = {
							type = was_evangelized_memory
							participants = { missionary = scope:evangelizer sender = scope:sender }
						}
					}
					scope:sender = {
						create_character_memory = {
							type = evangelized_memory
							participants = { missionary = scope:evangelizer pagan = scope:pagan }
						}
					}
					show_as_tooltip = {
						scope:pagan = {
							create_alliance = {
								target = scope:sender
								allied_through_owner = scope:pagan
								allied_through_target = scope:sender
							}
						}
						scope:sender = {
							add_opinion = {
								target = scope:pagan
								modifier = event_negotiated_alliance_opinion
							}
						}
					}
					scope:evangelizer = {
						add_character_flag = success_conversion
					}
				}
				50 = { # Not convert
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					modifier = {
						scope:pagan = {
							has_trait = theologian
						}
						add = 10
					}
					modifier = {
						scope:pagan = {
							has_trait = stubborn
						}
						add = 10
					}
					scope:pagan = { add_piety = medium_piety_gain }
					scope:evangelizer = {
						add_character_flag = failed_conversion
					}
				}
				5 = { # They _really_ don't wanna convert
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					modifier = {
						scope:pagan = {
							has_trait = sadistic
						}
						add = 5
					}
					modifier = {
						scope:pagan = {
							has_trait = callous
						}
						add = 5
					}
					modifier = {
						scope:pagan = {
							has_trait = torturer
						}
						add = 5
					}
					scope:pagan = { add_piety = major_piety_gain }
					scope:evangelizer = {
						death = {
							death_reason = death_execution
							killer = root
						}
					}
					scope:sender = {
						trigger_event = {
							id = ep3_decisions_event.4026
							days = 3
						}
					}
					scope:pagan = {
						add_character_flag = do_not_disturb_preachers
					}
					scope:title_to_convert = {
						set_variable = do_not_disturb_preachers
					}
				}
			}
		}
	}

	option = {
		name = ep3_decisions_event.4023.a
	}

	after = {
		if = {
			limit = {
				scope:sender = { is_alive = yes }
				scope:evangelizer = { is_alive = yes }
			}
			scope:evangelizer = {
				start_travel_plan = {
					destination = scope:sender.location
					on_arrival_event = ep3_decisions_event.4024
					on_arrival_destinations = all
					return_trip = no # One way
				}
			}
		}
		else_if = {
			limit = {
				scope:evangelizer = { is_alive = yes }
			}
			scope:evangelizer = {
				start_travel_plan = {
					destination = scope:starting_point
					on_arrival_event = ep3_decisions_event.4024
					on_arrival_destinations = all
					return_trip = no # One way
				}
			}
		}
	}
}

ep3_decisions_event.4024 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				scope:sender = { is_alive = yes }
			}
			scope:sender = {
				save_scope_as = recipient
				trigger_event = {
					id = ep3_decisions_event.4025
					days = 1
				}
			}
		}
		else = {
			scope:starting_point.barony.holder.top_liege = {
				save_scope_as = new_sender
				save_scope_as = recipient
				trigger_event = {
					id = ep3_decisions_event.4025
					days = 1
				}
			}
		}
	}
}

ep3_decisions_event.4025 = {
	type = character_event
	title = ep3_decisions_event.4020.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:new_sender
				}
				desc = ep3_decisions_event.4025.desc_new
			}
			desc = ep3_decisions_event.4025.desc_old
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:evangelizer = {
						has_character_flag = success_conversion
					}
				}
				desc = ep3_decisions_event.4025.desc_success
			}
			desc = ep3_decisions_event.4025.desc_failure
		}
	}
	theme = emperor

	left_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = {
				scope:evangelizer = { has_character_flag = success_conversion }
			}
			animation = prayer
		}
		triggered_animation = {
			trigger = {
				scope:evangelizer = { has_character_flag = failed_conversion }
			}
			animation = disapproval
		}
	}
	right_portrait = {
		character = scope:evangelizer
		animation = wedding_priest
	}
	lower_right_portrait = scope:pagan

	immediate = {
		if = {
			limit = {
				scope:evangelizer = {
					has_character_flag = success_conversion
				}
			}
			show_as_tooltip = {
				scope:pagan = {
					set_character_faith_with_conversion = scope:evangelizer.faith
				}
			}
			custom_tooltip = ep3_decisions_event.4025.a.tt
			scope:pagan = {
				create_alliance = {
					target = scope:sender
					allied_through_owner = scope:pagan
					allied_through_target = scope:sender
				}
			}
			scope:sender = {
				add_opinion = {
					target = scope:pagan
					modifier = event_negotiated_alliance_opinion
				}
			}
			gain_holy_legend_seed_tooltip_effect = yes
			hidden_effect = {
				legend_seed_great_deed_faith_effect = {
					ANTAGONIST = scope:pagan
					OLD_FAITH = scope:old_faith
				}
			}
		}
	}

	option = {
		name = ep3_decisions_event.4025.a
		trigger = {
			scope:evangelizer = {
				has_character_flag = success_conversion
			}
		}
		change_influence = major_influence_gain
		add_prestige = major_prestige_gain
	}

	option = {
		name = ep3_decisions_event.4025.b
		trigger = {
			scope:evangelizer = {
				has_character_flag = failed_conversion
			}
		}
		change_influence = medium_influence_gain
		add_prestige = medium_prestige_gain
	}
}

ep3_decisions_event.4026 = {
	type = character_event
	title = ep3_decisions_event.4020.t
	desc = ep3_decisions_event.4026.desc
	theme = emperor

	left_portrait = {
		character = root
		animation = anger
	}
	lower_right_portrait = scope:pagan
	lower_left_portrait = scope:evangelizer

	immediate = {
		show_as_tooltip = {
			scope:evangelizer = {
				death = {
					death_reason = death_execution
					killer = scope:pagan
				}
			}
		}
	}

	# Option A: they will pay!
	option = {
		name = ep3_decisions_event.4026.a
		change_influence = medium_influence_gain
		add_prestige = medium_prestige_gain
		if = {
			limit = {
				can_set_relation_rival_trigger = { CHARACTER = scope:pagan }
			}
			set_relation_rival = {
				reason = rival_killed_religious_emissary
				target = scope:pagan
			}
		}
		if = {
			limit = {
				is_ai = yes
			}
			add_opinion = {
				target = scope:pagan
				modifier = hate_opinion
				opinion = -50
			}
		}
		ai_chance = {
			ai_value_modifier = {
				ai_vengefulness = 1
			}
		}
	}
}

ep3_decisions_event.4030 = {
	type = character_event
	title = ep3_decisions_event.4030.t
	desc = ep3_decisions_event.4030.desc
	theme = byzantine
	override_background = { reference = ep3_constantinople }
	override_effect_2d = {
		reference = legend_glow
	}
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
	}

	immediate = {
		recreate_ere_decision_effect = yes
		create_character_memory = {
			type = reformed_ere_memory
		}
	}

	option = {
		name = ep3_decisions_event.4030.a
	}
}

ep3_decisions_event.4040 = {
	type = character_event
	title = ep3_decisions_event.4040.t
	desc = ep3_decisions_event.4040.desc
	theme = emperor
	override_background = { reference = ep3_constantinople }

	left_portrait = {
		character = root
		animation = war_over_win
	}

	immediate = {
		show_as_tooltip = {
			reinstitute_grain_dole_decision_effect = yes
		}
		create_character_memory = {
			type = grain_dole_memory
		}
	}

	option = {
		name = ep3_decisions_event.4040.a
	}
}

# Consolidate Rule
ep3_decisions_event.4050 = {
	type = character_event
	title = ep3_decisions_event.4050.t
	desc = {
		desc = ep3_decisions_event.4050.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:head_of_faith = {
						OR = {
							opinion = {
								target = root
								value <= -75
							}
							has_relation_rival = root
						}
					}
				}
				desc = ep3_decisions_event.4050.desc.hate
			}
			desc = ep3_decisions_event.4050.desc.other
		}
		desc = ep3_decisions_event.4050.desc.outro
	}
	theme = emperor
	override_background = { reference = temple }

	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = arrogant }
			animation = disapproval
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = zealous
					has_trait = humble
					has_trait = content
				}
			}
			animation = obsequious_bow
		}
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	
	right_portrait = {
		character = scope:head_of_faith
		triggered_animation = {
			trigger = {
				OR = {
					opinion = {
						target = root
						value <= -75
					}
					has_relation_rival = root
				}
			}
			animation = war_over_win
		}
		animation = admiration
	}

	immediate = {
		faith.religious_head = {
			save_scope_as = head_of_faith
		}
	}

	option = {
		name = ep3_decisions_event.4050.a
		add_character_modifier = {
			modifier = ep3_consolidated_rule_modifier
			years = 15
		}
	}
	
	option = {
		name = ep3_decisions_event.4050.b
		add_legitimacy = major_legitimacy_gain
	}
	
	option = {
		name = ep3_decisions_event.4050.c
		trigger = {
			scope:head_of_faith = {
				OR = {
					opinion = {
						target = root
						value <= -75
					}
					has_relation_rival = root
				}
			}
			can_add_hook = {
				target = scope:head_of_faith
				type = loyalty_hook
			}
		}
		add_hook = {
			type = loyalty_hook
			target = scope:head_of_faith
		}
	}
}


#########################################################
### Convert to Administrative from Feudalism

ep3_decisions_event.4060 = {
	type = character_event
	title = ep3_decisions_event.4060.t
	desc = {
		desc = ep3_decisions_event.4060.desc
		first_valid = { #We talk a bit about the biggest non coverted vassal if there is one.
			triggered_desc = {
				trigger = {
					exists = scope:obstinate_vassal
					trigger_if = {
						limit = { exists = scope:non_de_jure_vassal }
						scope:obstinate_vassal.sub_realm_size >= scope:non_de_jure_vassal.sub_realm_size
					}
					trigger_if = {
						limit = { exists = scope:non_state_faith_vassal }
						scope:obstinate_vassal.sub_realm_size >= scope:non_state_faith_vassal.sub_realm_size
					}
				}
				desc = ep3_decisions_event.4060.resistance.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:non_state_faith_vassal
					trigger_if = {
						limit = { exists = scope:non_de_jure_vassal }
						scope:non_state_faith_vassal.sub_realm_size >= scope:non_de_jure_vassal.sub_realm_size
					}
					trigger_if = {
						limit = { exists = scope:obstinate_vassal }
						scope:non_state_faith_vassal.sub_realm_size >= scope:obstinate_vassal.sub_realm_size
					}
				}
				desc = ep3_decisions_event.4060.state_faith.desc
			}
			triggered_desc = {
				trigger = {
					exists = scope:non_de_jure_vassal
					trigger_if = {
						limit = { exists = scope:non_state_faith_vassal }
						scope:non_de_jure_vassal.sub_realm_size >= scope:non_state_faith_vassal.sub_realm_size
					}
					trigger_if = {
						limit = { exists = scope:obstinate_vassal }
						scope:non_de_jure_vassal.sub_realm_size >= scope:obstinate_vassal.sub_realm_size
					}
				}
				desc = ep3_decisions_event.4060.de_jure.desc
			}
		}
		desc = ep3_decisions_event.4060.outro.desc
	}
	theme = emperor
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	lower_right_portrait = {
		character = scope:obstinate_vassal
	}
	lower_center_portrait = {
		character = scope:non_state_faith_vassal
	}
	lower_left_portrait = {
		character = scope:non_de_jure_vassal
	}


	immediate = {
		show_as_tooltip = {
			switch = {
				trigger = has_government
			 	japan_administrative_government = { change_government = japan_administrative_government }
			 	celestial_government = { change_government = celestial_government }
			 	meritocratic_government = { change_government = meritocratic_government }
			 	steppe_admin_government = { change_government = steppe_admin_government }
			 	fallback = { change_government = administrative_government }
			}
			if = {
				limit = {
					NOT = { has_character_flag = latin_emp_force_admin_flag }
					top_liege = this
				}
				add_character_modifier = { modifier = first_admin_emperor }
			}
		}
		hidden_effect = {
			ordered_vassal = {
				limit = {
					NOR = {
						government_has_flag = government_is_theocracy 
						government_has_flag = government_is_republic
						government_has_flag = government_is_landless_adventurer
						government_has_flag = government_is_tribal
						government_has_flag = government_is_administrative
					}
					primary_title = {
						target_is_de_jure_liege_or_above = scope:administrative_liege.primary_title #We only auto convert de jure vassals
					}
				}
				order_by = sub_realm_size
				save_scope_as = non_de_jure_vassal
			}
			ordered_vassal = {
				limit = {
					NOR = {
						government_has_flag = government_is_theocracy 
						government_has_flag = government_is_republic
						government_has_flag = government_is_landless_adventurer
						government_has_flag = government_is_tribal
						government_has_flag = government_is_administrative
						primary_title = {
							target_is_de_jure_liege_or_above = scope:administrative_liege.primary_title #We only auto convert de jure vassals
						}
					}
					faith = scope:administrative_liege.faith #The future state faith
				}
				order_by = sub_realm_size
				position = 0
				save_scope_as = non_state_faith_vassal
			}
			ordered_vassal = {
				limit = {
					NOR = {
						government_has_flag = government_is_theocracy 
						government_has_flag = government_is_republic
						government_has_flag = government_is_landless_adventurer
						government_has_flag = government_is_tribal
						government_has_flag = government_is_administrative
						primary_title = {
							target_is_de_jure_liege_or_above = scope:administrative_liege.primary_title #We only auto convert de jure vassals
						}
						faith = scope:administrative_liege.faith #The future state faith
					}
				}
				order_by = sub_realm_size
				save_scope_as = obstinate_vassal
			}
			every_vassal_or_below = {
				limit = {
					is_ai = no
				}
				trigger_event = {
					id = ep3_decisions_event.4065
				}
			}
		}
	}
	#Finally some Law and Order
	option = {
		name = ep3_decisions_event.4060.a
		if = {
			limit = {
				OR = {
					exists = scope:non_de_jure_vassal
					exists = scope:obstinate_vassal
					exists = scope:non_state_faith_vassal
				}
			}
			custom_tooltip = vassal_did_not_become_administrative
		}
	}
}

#Vassals get notified
ep3_decisions_event.4065 = {
	type = letter_event
	opening = ep3_decisions_event.4065.opening
	desc = ep3_decisions_event.4065.desc
	sender = {
		character = scope:actor
		triggered_animation = {
			trigger = { OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion } }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	option = {
		name = ep3_decisions_event.4065.a
		trigger = {
			OR = {
				ep3_vassal_will_become_admin = yes
				exists = scope:great_yuan_ruler
			}
		}
		change_to_administrative_effect = yes
		#Specifically for when great yuan is formed
		if = {
			limit = {
				exists = scope:great_yuan_ruler
			}
			hidden_effect = { #This again only converts subvassals if they are AI - this event should also have triggered for other humans down the chain.
				every_vassal = { #Everyone below also converts (could be Counts, could be Dukes)
					limit = {
						tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
						is_ai = yes
					}	
					change_to_administrative_effect = yes
					every_vassal = { #Everyone below also converts (Could be Counts, could be Barons)
						limit = {
							tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
							is_ai = yes
						}	
						change_to_administrative_effect = yes
						every_vassal = { #Everyone below also converts (could be Barons)
							limit = {
								tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
								is_ai = yes
							}	
							change_to_administrative_effect = yes
							every_vassal = { #Everyone below also converts (could be Barons)
								limit = {
									tgp_mongol_vassal_will_become_admin = yes #We still don't want mayors and bishops
									is_ai = yes
								}	
								change_to_administrative_effect = yes
							}
						}
					}
				}
			}
		}
		#Firing from normal admin creation
		else = {
			hidden_effect = { #This again only converts subvassals if they are AI - this event should also have triggered for other humans down the chain.
				every_vassal = { #Everyone below also converts (could be Counts, could be Dukes)
					limit = {
						ep3_vassal_will_become_admin = yes #We still don't want mayors and bishops
						is_ai = yes
					}	
					change_to_administrative_effect = yes
					every_vassal = { #Everyone below also converts (Could be Counts, could be Barons)
						limit = {
							ep3_vassal_will_become_admin = yes #We still don't want mayors and bishops
							is_ai = yes
						}	
						change_to_administrative_effect = yes
						every_vassal = { #Everyone below also converts (could be Barons)
							limit = {
								ep3_vassal_will_become_admin = yes #We still don't want mayors and bishops
								is_ai = yes
							}	
							change_to_administrative_effect = yes
							every_vassal = { #Everyone below also converts (could be Barons)
								limit = {
									ep3_vassal_will_become_admin = yes #We still don't want mayors and bishops
									is_ai = yes
								}	
								change_to_administrative_effect = yes
							}
						}
					}
				}
			}
		}
	}
	option = {
		name = ep3_decisions_event.4065.b
		trigger = {
			ep3_vassal_will_become_admin = yes
		}
		scope:actor = {
			add_opinion = {
				modifier = annoyed_opinion
				opinion = -20
				target = root
			}
		}
	}
	option = {
		name = ep3_decisions_event.4065.c
		trigger = {
			ep3_vassal_will_become_admin = no
		}
	}
}

#########################################################
### Convert to Feudalism from Administrative

ep3_decisions_event.4070 = {
	type = character_event
	title = ep3_decisions_event.4070.t
	desc = ep3_decisions_event.4070.desc
	theme = emperor
	override_background = { reference = throne_room }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { has_trait = arrogant }
			animation = personality_callous
		}
		triggered_animation = {
			trigger = { has_trait = craven }
			animation = worry
		}
		animation = personality_bold
	}
	immediate = {
		show_as_tooltip = { 
			if = {
				limit = { ep3_is_clan_inclined_trigger = yes }
				change_government = clan_government 
			}
			else = { change_government = feudal_government }
		}
	}
	option = {
		name = ep3_decisions_event.4070.a
	}
}

#Vassals get notified
ep3_decisions_event.4075 = {
	type = letter_event
	opening = ep3_decisions_event.4075.opening
	desc = ep3_decisions_event.4070.desc
	sender = {
		character = scope:actor
		animation = personality_rational
	}
	immediate = {
		show_as_tooltip = { 
			if = {
				limit = { ep3_is_clan_inclined_trigger = yes }
				change_government = clan_government 
			}
			else = { change_government = feudal_government }
		}
	}
	#You are now a king! ... or duke. Or count?
	option = {
		name = ep3_decisions_event.4075.a
	}
}

##################################################
# Gather Provisions
# by Joe Parkin
# 7000-7009
##################################################

scripted_effect determine_provision_count_effect = {
	save_scope_value_as = {
		name = $NAME$_provisions_count
		value = {
			integer_range = {
				min = 200
				max = 400
			}
			multiply = {
				value = 1
				add = {
					value = $CHAR$.$SKILL$
					multiply = 0.01
				}
				if = {
					limit = {
						domicile ?= { has_domicile_parameter = camp_improves_gather_provisions_decision }
					}
					add = 0.5
				}
			}
			ceiling = yes
		}
	}
}

ep3_decisions_event.7000 = {
	type = character_event
	title = ep3_decisions_event.7000.t
	desc = {
		desc = ep3_decisions_event.7000.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					location = {
						OR = {
							has_province_modifier = winter_mild_modifier
							has_province_modifier = winter_normal_modifier
							has_province_modifier = winter_harsh_modifier
						}
					}
				}
				desc = ep3_decisions_event.7000.winter_forage
			}
			triggered_desc = {
				trigger = {
					location = {
						OR = {
							terrain = desert
							terrain = desert_mountains
							terrain = taiga
						}
					}
				}
				desc = ep3_decisions_event.7000.difficult_forage
			}
			triggered_desc = {
				trigger = {
					location = {
						OR = {
							terrain = farmlands
							terrain = floodplains
							terrain = wetlands
						}
					}
				}
				desc = ep3_decisions_event.7000.difficult_hunt
			}
			triggered_desc = {
				trigger = {
					location = {
						OR = {
							terrain = forest
							terrain = hills
							terrain = plains
						}
					}
				}
				desc = ep3_decisions_event.7000.good
			}
			desc = ep3_decisions_event.7000.fallback
		}
	}
	theme = hunting
	override_background = { reference = terrain }
	left_portrait = {
		character = root
		animation = survey
	}
	right_portrait = {
		character = scope:portrait
		triggered_animation = {
			trigger = { has_court_position = chief_forager_camp_officer }
			animation = admiration
		}
		triggered_animation = {
			trigger = { has_court_position = huntperson_camp_officer }
			scripted_animation = bow_closed_blunt
		}
	}
	lower_right_portrait = {
		character = scope:huntperson
		trigger = {
			exists = scope:huntperson
			exists = scope:portrait
			scope:huntperson != scope:portrait
		}
	}

	immediate = {
		save_scope_as = camp_owner
		location = { save_scope_as = forage_province }
		court_position:chief_forager_camp_officer ?= {
			save_scope_as = chief_forager
			save_scope_as = portrait
		}
		court_position:huntperson_camp_officer ?= {
			save_scope_as = huntperson
			if = {
				limit = { NOT = { exists = scope:portrait } }
				save_scope_as = portrait
			}
		}
		determine_provision_count_effect = { NAME = learning CHAR = scope:camp_owner SKILL = learning }
		determine_provision_count_effect = { NAME = prowess CHAR = scope:camp_owner SKILL = prowess }
		if = {
			limit = {
				has_perk = golden_aplomb_perk
			}
			set_variable = {
				name = has_golden_aplomb_perk
				value = flag:yes
			}
		}
		else = {
			set_variable = {
				name = has_golden_aplomb_perk
				value = flag:no
			}
		}
	}

	option = { # Forage
		name = ep3_decisions_event.7000.a
		flavor = ep3_decisions_event.7000.a_foraging
		duel = {
			skill = learning
			value = decent_skill_rating
			1 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.crit_success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.7000.a.crit_success
					left_icon = root
					domicile ?= {
						change_provisions = {
							value = {
								value = scope:forage_province.gather_provisions_forage_base_value
								multiply = 1.5
							}
						}
					}
				}
			}
			9 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.7000.a.success
					left_icon = root
					domicile ?= {
						change_provisions = {
							value = {
								value = scope:forage_province.gather_provisions_forage_base_value
							}
						}
					}
				}
			}
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_decisions_event.7000.a.failure
					left_icon = root
					custom_tooltip = ep3_decisions_event.7000.no_provisions_tt
				}
			}
			2 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.crit_failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_decisions_event.7000.a.failure
					left_icon = root
					if = {
						limit = {
							location = {
								OR = {
									has_province_modifier = winter_mild_modifier
									has_province_modifier = winter_normal_modifier
									has_province_modifier = winter_harsh_modifier
								}
							}
							NOR = {
								has_character_modifier = travel_mild_frostbite_modifier
								has_character_modifier = travel_severe_frostbite_modifier
							}
						}
						add_character_modifier = {
							modifier = travel_mild_frostbite_modifier
							years = 3
						}
					}
					else_if = {
						limit = {
							NOT = { has_trait = ill } 
							location = {
								OR = {
									terrain = floodplains
									terrain = wetlands
									terrain = oasis
									terrain = farmlands
									terrain = plains
								}
							}
						}
						contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
					}
					else = {
						increase_wounds_effect = { REASON = wild_animal }
					}
				}
			}
		}
		ai_chance = {
			base = 1
			modifier = { add = learning }
		}
	}

	option = { # Hunt
		name = ep3_decisions_event.7000.b
		flavor = ep3_decisions_event.7000.b_trapping
		duel = {
			skill = prowess
			value = decent_skill_rating
			1 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.crit_success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.7000.a.crit_success
					left_icon = root
					domicile ?= {
						change_provisions = {
							value = {
								value = scope:forage_province.gather_provisions_hunt_base_value
								multiply = 1.5
							}
						}
					}
				}
			}
			9 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.success
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.7000.a.success
					left_icon = root
					domicile ?= {
						change_provisions = {
							value = {
								value = scope:forage_province.gather_provisions_hunt_base_value
							}
						}
					}
				}
			}
			8 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_decisions_event.7000.a.failure
					left_icon = root
					custom_tooltip = ep3_decisions_event.7000.no_provisions_tt
				}
			}
			2 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = 1
				}
				desc = ep3_decisions_event.7000.a.crit_failure
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ep3_decisions_event.7000.a.crit_failure
					left_icon = root
					increase_wounds_effect = { REASON = wild_animal }
				}
			}
		}
		ai_chance = {
			base = 1
			modifier = { add = prowess }
		}
	}

	option = { # Send Chief Forager
		flavor = ep3_decisions_event.7000.a_flavor
		name = {
			trigger = { NOT = { exists = scope:chief_forager } }
			text = ep3_decisions_event.7000.c
		}
		name = {
			trigger = { exists = scope:chief_forager }
			text = ep3_decisions_event.7000.c.named
		}
		trigger = { employs_court_position = chief_forager_camp_officer }
		reason = have_chief_forager
		show_as_unavailable = { always = yes }
		scope:chief_forager ?= {
			duel = {
				skill = learning
				value = decent_skill_rating
				2 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.c.crit_success
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_decisions_event.7000.c.crit_success
							left_icon = scope:chief_forager
							domicile ?= {
								change_provisions = {
									value = {
										value = scope:forage_province.gather_provisions_forage_base_value
										multiply = 1.75
									}
								}
							}
						}
					}
				}
				8 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.c.success
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_decisions_event.7000.c.success
							left_icon = scope:chief_forager
							domicile ?= {
								change_provisions = {
									value = {
										value = scope:forage_province.gather_provisions_forage_base_value
										multiply = 1.25
									}
								}
							}
						}
					}
				}
				9 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.c.failure
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_decisions_event.7000.c.failure
							left_icon = scope:chief_forager
							custom_tooltip = ep3_decisions_event.7000.no_provisions_tt
						}
					}
				}
				1 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.c.crit_failure
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_decisions_event.7000.c.crit_failure
							left_icon = scope:chief_forager
							scope:chief_forager = {
								if = {
									limit = {
										location = {
											OR = {
												has_province_modifier = winter_mild_modifier
												has_province_modifier = winter_normal_modifier
												has_province_modifier = winter_harsh_modifier
											}
										}
										NOR = {
											has_character_modifier = travel_mild_frostbite_modifier
											has_character_modifier = travel_severe_frostbite_modifier
										}
									}
									add_character_modifier = {
										modifier = travel_mild_frostbite_modifier
										years = 3
									}
								}
								else_if = {
									limit = {
										NOT = { has_trait = ill }
										location = {
											OR = {
												terrain = floodplains
												terrain = wetlands
												terrain = oasis
												terrain = farmlands
												terrain = plains
											}
										}
									}
									contract_disease_effect = { DISEASE = ill TREATMENT_EVENT = yes }
								}
								else = {
									increase_wounds_effect = { REASON = wild_animal }
								}
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 1
			modifier = {
				exists = court_position:chief_forager_camp_officer
				add = court_position:chief_forager_camp_officer.learning
			}
		}
	}

	option = { # Send Huntperson
		flavor = ep3_decisions_event.7000.b_flavor
		name = {
			trigger = { NOT = { exists = scope:huntperson } }
			text = ep3_decisions_event.7000.d
		}
		name = {
			trigger = { exists = scope:huntperson }
			text = ep3_decisions_event.7000.d.named
		}
		trigger = { employs_court_position = huntperson_camp_officer }
		reason = have_huntperson
		show_as_unavailable = { always = yes }
		scope:huntperson ?= {
			duel = {
				skill = prowess
				value = decent_skill_rating
				2 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.d.crit_success
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_decisions_event.7000.d.crit_success
							left_icon = scope:huntperson
							domicile ?= {
								change_provisions = {
									value = {
										value = scope:forage_province.gather_provisions_hunt_base_value
										multiply = 1.75
									}
								}
							}
						}
					}
				}
				8 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.d.success
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_good
							title = ep3_decisions_event.7000.d.success
							left_icon = scope:huntperson
							domicile ?= {
								change_provisions = {
									value = {
										value = scope:forage_province.gather_provisions_hunt_base_value
										multiply = 1.25
									}
								}
							}
						}
					}
				}
				9 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.d.failure
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_decisions_event.7000.d.failure
							left_icon = scope:huntperson
							custom_tooltip = ep3_decisions_event.7000.no_provisions_tt
						}
					}
				}
				1 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = 1
					}
					desc = ep3_decisions_event.7000.d.crit_failure
					scope:camp_owner = {
						send_interface_toast = {
							type = event_toast_effect_bad
							title = ep3_decisions_event.7000.d.crit_failure
							left_icon = scope:huntperson
							scope:huntperson = {
								increase_wounds_effect = { REASON = wild_animal }
							}
						}
					}
				}
			}
		}
		ai_chance = {
			base = 1
			modifier = {
				exists = court_position:huntperson_camp_officer
				add = court_position:huntperson_camp_officer.prowess
			}
		}
	}
	after = {
		remove_variable = has_golden_aplomb_perk
	}
}

# Found Salon
ep3_decisions_event.4080 = {
	type = character_event
	title = ep3_decisions_event.4080.t
	desc = {
		desc = ep3_decisions_event.4080.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					root = character:andalusian_0003
				}
				desc = ep3_decisions_event.4080.wallada
			}
			desc = ep3_decisions_event.4080.heir
		}
		desc = ep3_decisions_event.4080.desc.outro
	}
	theme = violet_poet
	override_background = { reference = courtyard }

	left_portrait = {
		character = root
		animation = personality_honorable
	}

	immediate = {
		location = {
			save_scope_as = location
		}
	}

	option = {
		name = ep3_decisions_event.4080.a
		if = {
			limit = {
				exists = dynasty
			}
			dynasty = {
				add_dynasty_prestige = medium_dynasty_prestige_gain
			}
		}
		add_prestige = major_prestige_gain
		scope:location = {
			add_province_modifier = {
				modifier = ep3_poets_salon_modifier
				years = 250
			}
		}
		add_character_modifier = {
			modifier = ep3_founded_salon_modifier
		}
	}
}

#########################################################
### Renounce Governorship

ep3_decisions_event.4090 = {
	type = character_event
	title = ep3_decisions_event.4090.t
	desc = ep3_decisions_event.4090.desc
	theme = administrative
	override_background = { reference = estate }
	right_portrait = {
		character = root
		triggered_animation = {
			trigger = {	government_allows = merit }
			animation = writing
		}
		triggered_animation = {
			trigger = {	has_trait_benevolent_trigger = yes }
			animation = worry
		}
		animation = scheme
	}
	lower_left_portrait = scope:new_governor
	
	immediate = {
		liege = { save_scope_as = liege } #For loc
	}
	
	option = {
		name = ep3_decisions_event.4090.a
		name = {
			trigger = {
				government_allows = merit
			}
			text = ep3_decisions_event.4090.a_merit
		}
		
		if = {
			limit = {
				involved_activity ?= {
					has_activity_type = activity_imperial_examination
				}
			}
			set_activity_intent = imperial_exam_taker_intent
		}

		if = {
			limit = {
				government_allows = merit
			}
			add_character_modifier = {
				modifier = ep3_renounced_governorship_merit
				years = 15
			}
			set_appointment_timeout = {
				years = 3
				desc = appointment_timeout_desc_retired_governor
			}
		}
		else = {
			add_gold = massive_gold_value
			add_character_modifier = {
				modifier = ep3_renounced_governorship
				years = 15
			}
		}
		force_step_down_landed_titles = yes
		if = {
			limit = {
				tgp_is_any_minister = yes
			}
			liege = { save_scope_as = councillor_liege } # Needed for the effect
			fired_minister_position_effect = yes
		}
		tgp_step_down_title_recipient_tooltip_effect = yes
	}
}

#########################################################
### Knight of the Swan

ep3_decisions_event.5001 = {
	type = character_event
	title = ep3_decisions_event.5001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:adoring_fan = { is_spouse_of = root }
				}
				desc = ep3_decisions_event.5001.desc.spouse
			}
			desc = ep3_decisions_event.5001.desc.intro
		}
		desc = ep3_decisions_event.5001.desc
	}
	theme = laamp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				scope:adoring_fan = { is_spouse_of = root }
			}
			animation = ecstasy
		}
		triggered_animation = {
			trigger = {
				has_trait = arrogant
			}
			animation = hero_flex
		}
		triggered_animation = {
			trigger = {
				has_trait = humble
			}
			animation = shame
		}
		animation = laugh
	}
	right_portrait = {
		character = scope:adoring_fan
		animation = admiration
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	override_effect_2d = {
		reference = legend_glow
	}
	override_background = { reference = ce1_legendary_spring }
	
	immediate = {
		dummy_opposite_gender_effect = { TARGET = root }
		hidden_effect_new_object = {
			save_scope_as = owner
			set_artifact_rarity_illustrious = yes
			create_artifact = {
				name = artifact_knight_of_the_swan_name
				description = artifact_knight_of_the_swan
				type = armor_mail
				visuals = armor
				modifier = artifact_armor_knight_of_the_swan_artifact_modifier
				wealth = 400
				quality = 400
				save_scope_as = newly_created_artifact
			}
		}
		add_character_flag = wear_armor
		if = { # If your spouse likes you we grab them
			limit = {
				any_spouse = {
					is_available_healthy_ai_adult = yes
					has_any_good_relationship_with_root_trigger = yes
				}
			}
			random_spouse = {
				limit = {
					is_available_healthy_ai_adult = yes
					has_any_good_relationship_with_root_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 5
						has_relation_lover = root
					}
					modifier = {
						add = 3
						this = root.primary_spouse
					}
				}
				save_scope_as = adoring_fan
			}
		}
		else_if = {
			limit = {
				any_courtier_or_guest = {
					is_available_ai_adult = yes
				}
			}
			ordered_courtier_or_guest = {
				limit = { is_available_healthy_ai_adult = yes }
				order_by = sum_of_all_skills_value
				save_scope_as = adoring_fan
			}
		}		
		else = {
			create_character = {
				location = root.location
				template = ep3_common_fan_character
				gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
				faith = root.capital_county.faith
				culture = root.capital_county.culture
				save_scope_as = adoring_fan
			}
		}
	}
	
	option = { # Are you into protecting peasants
		name = ep3_decisions_event.5001.a
		add_character_modifier = { # Permanent
			modifier = ep3_valiant_knight_modifier
		}
		
		stress_impact = {
			seducer = major_stress_impact_gain
			rakish = major_stress_impact_gain
			lustful = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = seducer
					has_trait = rakish
					has_trait = lustful
					has_trait = craven
				}
			}
		}
	}
	
	option = { #...or are you into saving ladies
		name = ep3_decisions_event.5001.b
		custom_tooltip = ep3_courteous_knight_var_tt
		add_character_modifier = { # Permanent
			modifier = ep3_courteous_knight_modifier
		}
		
		stress_impact = {
			celibate = major_stress_impact_gain
			chaste = medium_stress_impact_gain
			just = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = celibate
					has_trait = chaste
					has_trait = just
					has_trait = callous
				}
			}
		}
	}
	
	after = {
		disburse_knight_errant_decision_rewards_effect = yes
		trigger_event = { # We give you a Legendary Sighting - also added to the regular event triggers so if it doesn't trigger here it will eventually
			id = hunt.2510
			days = { 30 90 } 
		}
		trigger_event = { # Someone from your family may take an interest in you - also added to the laamp on_action, so if it doesn't trigger here it will eventually
			id = ep3_decisions_event.5002
			days = { 30 90 } 
		}
	}
}

scripted_trigger ep3_decisions_event_5002_family_trigger = {
	is_available_healthy_ai_adult = yes
	OR = {
		is_landed = yes
		NOT = { is_courtier_of = root }
	}
	NOT = { is_spouse_of = root }
	OR = {
		has_relation_rival = root
		has_relation_potential_rival = root
		opinion = {
			target = root
			value <= 0
		}
	}
}

ep3_decisions_event.5002 = {
	type = character_event
	title = ep3_decisions_event.5002.t
	desc = ep3_decisions_event.5002.desc
	theme = laamp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = humble
					has_trait = calm
				}
			}
			animation = dismissal
		}
		animation = anger
	}
	right_portrait = {
		character = scope:my_rival
		animation = disapproval
	}
	
	trigger = {
		is_available = yes
		is_landed = no
		any_close_or_extended_family_member = {
			ep3_decisions_event_5002_family_trigger = yes
		}
		NOT = { has_variable = had_ep3_decisions_event_5002 }
	}
	
	immediate = {
		set_variable = had_ep3_decisions_event_5002
		# We try to find someone that doesn't like you
		random_close_or_extended_family_member = {
			limit = {
				ep3_decisions_event_5002_family_trigger = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 50
					has_relation_rival = root
				}
				modifier = { 
					add = 25
					has_relation_potential_rival = root
				}
				modifier = {
					add = 25
					opinion = {
						target = root
						value <= -25
					}
				}
				modifier = { 
					add = 25
					is_landed = yes
				}
			}
			save_scope_as = my_rival
		}
	}
	
	option = { # You got a point
		name = ep3_decisions_event.5002.a
		custom_tooltip = {
			text = ep3_decisions_event_5002_a_tt
			set_variable = ep3_grace_to_the_family_var
		}
		scope:my_rival = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 15
			}
		}
		stress_impact = {
			arrogant = major_stress_impact_gain
			wrathful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = arrogant
					has_trait = wrathful
				}
			}
		}
	}
	
	option = { # Screw you
		name = ep3_decisions_event.5002.b
		if = {
			limit = {
				can_set_relation_rival_trigger = { CHARACTER = scope:my_rival }
			}
			set_relation_rival = {
				target = scope:my_rival
				reason = rival_called_me_a_disgrace
			}
		}
		add_character_modifier = {
			modifier = ep3_black_sheep
			years = 10
		}
		stress_impact = {
			arrogant = major_stress_impact_loss
			wrathful = major_stress_impact_loss
			calm = medium_stress_impact_gain
			humble = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = calm
					has_trait = humble
					has_trait = ambitious
				}
			}
		}
	}
}

#########################################################
### Commission Icon Artifact
ep3_decisions_event.5000 = {
	type = character_event
	title = ep3_decisions_event.5000.t
	desc = ep3_decisions_event.5000.desc
	theme = faith
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:local_artisan
		animation = obsequious_bow
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	override_effect_2d = {
		reference = legend_glow
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		if = {
			limit = {
				scope:commission_trinket_icon = yes
			}
			create_artifact_trinket_icon_effect = { OWNER = root PAINTER = scope:local_artisan }
		}
		else_if = {
			limit = {
				scope:commission_court_icon_large = yes
			}
			create_artifact_court_icon_large_effect = { OWNER = root PAINTER = scope:local_artisan }
		}
		else = {
			create_artifact_court_icon_small_effect = { OWNER = root PAINTER = scope:local_artisan }
		}
	}

	option = { # well done
		name = ep3_decisions_event.5030.a
		show_as_tooltip = {
			scope:newly_created_artifact = { set_owner = root }
		}
	}
}

### Hire Chief Eunuch
scripted_trigger mediocre_eunuch_trigger = {
	has_trait = eunuch
	can_be_employed_as = chief_eunuch_court_position
	is_available_healthy_ai_adult = yes
	diplomacy > average_skill_rating
	intrigue > average_skill_rating
}

scripted_trigger good_eunuch_trigger = {
	has_trait = eunuch
	can_be_employed_as = chief_eunuch_court_position
	is_available_healthy_ai_adult = yes
	NOR = {
		is_landed = yes
		has_trait = blind
	}
	OR = {
		has_trait = education_diplomacy
		has_trait = education_intrigue
	}
	diplomacy >= good_skill_level
	intrigue >= good_skill_level
}

ep3_decisions_event.5010 = {
	type = character_event
	title = ep3_decisions_event.5010.t
	desc = ep3_decisions_event.5010.desc
	theme = administrative
	
	left_portrait = {
		character = scope:mediocre_eunuch
		animation = happiness
	}
	right_portrait = {
		character = scope:good_eunuch
		animation = personality_honorable
	}

	immediate = {
		# Find a mediocre one
		if = { # check for a mediocre character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					mediocre_eunuch_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { mediocre_eunuch_trigger = yes }
				save_scope_as = mediocre_eunuch
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = 0
				age = { 16 65 }
				culture = root.location.culture
				faith = root.location.faith
				random_traits_list = {
					count = 1
					education_diplomacy_1 = {}
					education_diplomacy_2 = {}
					education_intrigue_1 = {}
					education_intrigue_2 = {}
				}
				random_traits_list = {
					count = 1
					eunuch_1 = {}
					beardless_eunuch = {}
				}
				random_traits = yes
				diplomacy = {
					min_template_low_skill
					max_template_average_skill
				}
				intrigue = {
					min_template_low_skill
					max_template_average_skill
				}
				save_scope_as = mediocre_eunuch
			}
		}

		# Find a good one
		if = { # check for a GOOD character in the pool
			limit = {
				any_pool_character = {
					province = root.capital_province
					good_eunuch_trigger = yes
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = { good_eunuch_trigger = yes }
				save_scope_as = good_eunuch
			}
		}
		else = { # otherwise create one
			create_character = {
				location = root.capital_province
				gender_female_chance = 0
				age = { 16 65 }
				culture = root.culture
				faith = root.faith
				random_traits_list = {
					count = 1
					education_diplomacy_3 = {}
					education_diplomacy_4 = {}
					education_intrigue_3 = {}
					education_intrigue_4 = {}
				}
				random_traits_list = {
					count = 1
					eunuch_1 = {}
					beardless_eunuch = {}
				}
				random_traits = yes
				diplomacy = {
					min_template_average_skill
					max_template_medium_skill
				}
				intrigue = {
					min_template_average_skill
					max_template_medium_skill
				}
				save_scope_as = good_eunuch
			}
		}
	}

	option = { 
		name = ep3_decisions_event.5010.a
		pay_treasury_or_gold = {
			target = scope:mediocre_eunuch
			value = low_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:mediocre_eunuch }
		court_position_grant_effect = { POS = chief_eunuch CANDIDATE = scope:mediocre_eunuch EMPLOYER = root }
	}

	option = {
		name = ep3_decisions_event.5010.b
		pay_treasury_or_gold = {
			target = scope:good_eunuch
			value = high_skill_court_physician_cost
		}
		hidden_effect = { add_courtier = scope:good_eunuch }
		court_position_grant_effect = { POS = chief_eunuch CANDIDATE = scope:good_eunuch EMPLOYER = root }
	}

	option = {
		name = ep3_decisions_event.1000.d
	}
}

### Embrace Heresy
ep3_decisions_event.5020 = {
	type = character_event
	title = ep3_decisions_event.5020.t
	desc = {
		desc = ep3_decisions_event.5020.desc
		triggered_desc = {
			trigger = {
				exists = scope:heresy_2
			}
			desc = ep3_decisions_event.5020.desc_more
		}
	}
	theme = faith
	
	left_portrait = {
		character = root
		animation = scheme
	}

	immediate = {
		top_liege ?= {
			every_realm_county = {
				limit = {
					OR = {
						faith = {
							faith_is_interesting_heresy_to_state_faith_trigger = yes
						}
						any_neighboring_county = {
							holder.top_liege ?= {
								this != root.top_liege
							}
							faith = {
								faith_is_interesting_heresy_to_state_faith_trigger = yes
							}
						}
					}
				}
				every_neighboring_county = {
					limit = {
						holder.top_liege ?= {
							this != root.top_liege
						}
						faith = {
							faith_is_interesting_heresy_to_state_faith_trigger = yes
						}
					}
					faith = {
						add_to_list = available_heresies
					}
				}
				if = {
					limit = {
						faith = {
							faith_is_interesting_heresy_to_state_faith_trigger = yes
						}
					}
					faith = {
						add_to_list = available_heresies
					}
				}
			}
		}
		ordered_in_list = {
			list = available_heresies
			order_by = num_county_followers
			position = 1
			save_scope_as = heresy_1
		}
		ordered_in_list = {
			list = available_heresies
			limit = { this != scope:heresy_1 }
			order_by = num_county_followers
			position = 1
			save_scope_as = heresy_2
		}
		ordered_in_list = {
			list = available_heresies
			limit = {
				this != scope:heresy_1
				this != scope:heresy_2
			}
			order_by = num_county_followers
			position = 1
			save_scope_as = heresy_3
		}
	}

	option = { 
		name = ep3_decisions_event.5020.a
		set_character_faith_with_conversion = scope:heresy_1
		add_heresiarch_trait_effect = yes
		# Otherwise the conversion event will remove the trait
		add_character_flag = converted_by_heresy_decision
		scope:heresy_1 = { save_scope_as = heresy }
		custom_tooltip = unlocks_demand_state_faith_decision
		top_liege ?= {
			every_vassal = {
				limit = {
					faith = scope:heresy_1
				}
				root = {
					if = {
						limit = {
							can_add_hook = {
								target = prev
								type = influence_hook
							}
						}
						add_hook = {
							target = prev
							type = influence_hook
						}
					}
				}
			}
		}
		change_influence = {
			value = minor_influence_gain
			multiply = number_of_counties_with_heresy_1
			min = 150
		}
	}

	option = {
		name = ep3_decisions_event.5020.b
		trigger = {
			exists = scope:heresy_2
		}
		set_character_faith_with_conversion = scope:heresy_2
		add_heresiarch_trait_effect = yes
		# Otherwise the conversion event will remove the trait
		add_character_flag = converted_by_heresy_decision
		scope:heresy_2 = { save_scope_as = heresy }
		custom_tooltip = unlocks_demand_state_faith_decision
		top_liege ?= {
			every_vassal = {
				limit = {
					faith = scope:heresy_2
				}
				root = {
					if = {
						limit = {
							can_add_hook = {
								target = prev
								type = influence_hook
							}
						}
						add_hook = {
							target = prev
							type = influence_hook
						}
					}
				}
			}
		}
		change_influence = {
			value = minor_influence_gain
			multiply = number_of_counties_with_heresy_2
			min = 150
		}
	}

	option = {
		name = ep3_decisions_event.5020.c
		trigger = {
			exists = scope:heresy_3
		}
		set_character_faith_with_conversion = scope:heresy_3
		add_heresiarch_trait_effect = yes
		# Otherwise the conversion event will remove the trait
		add_character_flag = converted_by_heresy_decision
		scope:heresy_3 = { save_scope_as = heresy }
		custom_tooltip = unlocks_demand_state_faith_decision
		top_liege ?= {
			every_vassal = {
				limit = {
					faith = scope:heresy_3
				}
				root = {
					if = {
						limit = {
							can_add_hook = {
								target = prev
								type = influence_hook
							}
						}
						add_hook = {
							target = prev
							type = influence_hook
						}
					}
				}
			}
		}
		change_influence = {
			value = minor_influence_gain
			multiply = number_of_counties_with_heresy_3
			min = 150
		}
	}

	option = {
		name = ep3_decisions_event.5020.d
	}

	after = {
		if = {
			limit = {
				exists = scope:heresy
			}
			set_variable = {
				name = heresy_embraced
				value = scope:heresy
				years = 50
			}
		}
	}
}

ep3_decisions_event.5021 = {
	type = character_event
	title = ep3_decisions_event.5021.t
	desc = ep3_decisions_event.5021.desc
	theme = faith
	
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:heretic
		animation = scheme
	}

	# Option A: change state faith
	option = {
		name = ep3_decisions_event.5021.a
		scope:heretic = {
			send_interface_message = {
				type = event_generic_good
				title = ep3_decisions_event.5021.a.tt
				left_icon = root
				root = {
					primary_title = { set_state_faith = scope:heresy }
					add_opinion = {
						target = scope:heretic
						modifier = forced_state_heresy_opinion
						opinion = -50
					}
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = number_of_counties_with_heresy_acceptance
			}
			modifier = {
				add = number_of_vassals_with_heresy_acceptance
			}
			modifier = {
				add = influence_difference_value
			}
			modifier = {
				scope:heretic.house = { is_powerful_family = yes }
				add = 25
			}
			modifier = {
				scope:heretic.house = { is_dominant_family = yes }
				add = 25
			}
			modifier = {
				scope:heretic = {
					domicile ?= {
						has_domicile_parameter = more_successful_heresies
						location.county.faith = scope:heretic.faith
					}
				}
				add = 25
			}
		}
	}

	# Option B: change state faith and convert
	option = {
		name = ep3_decisions_event.5021.b
		scope:heretic = {
			send_interface_message = {
				type = event_generic_good
				title = ep3_decisions_event.5021.a.tt
				left_icon = root
				root = {
					primary_title = { set_state_faith = scope:heresy }
					set_character_faith_with_conversion = scope:heresy
					add_opinion = {
						target = scope:heretic
						modifier = forced_state_heresy_opinion
						opinion = -50
					}
				}
			}
		}
		ai_chance = {
			base = 0
			modifier = {
				add = number_of_counties_with_heresy_acceptance
			}
			modifier = {
				add = number_of_vassals_with_heresy_acceptance
			}
			modifier = {
				add = influence_difference_value
			}
			modifier = {
				scope:heretic.house = { is_powerful_family = yes }
				add = 25
			}
			modifier = {
				scope:heretic.house = { is_dominant_family = yes }
				add = 25
			}
			modifier = {
				has_trait = cynical
				add = 20
			}
			modifier = {
				scope:heretic = {
					domicile ?= {
						has_domicile_parameter = more_successful_heresies
						location.county.faith = scope:heretic.faith
					}
				}
				add = 15
			}
			modifier = {
				has_trait = zealous
				factor = 0
			}
		}
	}

	# Option C: just no
	option = {
		name = ep3_decisions_event.5021.c
		scope:heretic = {
			send_interface_message = {
				type = event_generic_bad
				title = ep3_decisions_event.5021.c.tt
				left_icon = root
			}
		}
		ai_chance = {
			base = 250
		}
	}
}

### Commission Silk Regalia
ep3_decisions_event.5030 = {
	type = character_event
	title = ep3_decisions_event.5030.t
	desc = ep3_decisions_event.5030.desc
	theme = inspiration_complete
	override_background = { reference = study }
	left_portrait = {
		character = root
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:local_artisan
		animation = obsequious_bow
	}
	artifact = {
		target = scope:newly_created_artifact
		position = lower_center_portrait
	}
	override_effect_2d = {
		reference = legend_glow
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		hidden_effect = {
			set_artifact_rarity_famed = yes
			create_artifact_regalia_effect = {
				OWNER = root
				SMITH = scope:local_artisan
			}
			scope:newly_created_artifact = {
				set_artifact_name = silk_regalia_name
				set_artifact_description = silk_regalia_description
			}
		}
	}

	option = { # well done
		name = ep3_decisions_event.5000.a
		show_as_tooltip = {
			scope:newly_created_artifact = { set_owner = root }
		}
	}
}

#########################################################
### Separatist Uprising
ep3_decisions_event.6001 = {
	type = character_event
	title = ep3_decisions_event.6001.t
	desc = {
		desc = ep3_decisions_event.6001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:spouse
					scope:spouse = {
						culture = root.culture
					}
				}
				desc = ep3_decisions_event.6001.desc.spouse_same_culture
			}
			triggered_desc = {
				trigger = {
					exists = scope:spouse
					scope:spouse = {
						culture != root.culture
					}
				}
				desc = ep3_decisions_event.6001.desc.spouse_diff_culture
			}
			desc = ep3_decisions_event.6001.desc.no_spouse
		}
		desc = ep3_decisions_event.6001.desc.outro
	}
	theme = laamp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = callous
					has_trait = ambitious
				}
			}
			animation = scheme
		}
		animation = marshal_shield
	}
	right_portrait = {
		trigger = { exists = scope:spouse }
		character = scope:spouse
		animation = admiration
	}
	lower_right_portrait = scope:liege
	
	immediate = {
		location.county = { save_scope_as = county }
		save_scope_as = laamp
		location.duchy.holder.top_liege = { save_scope_as = liege }
		if = {
			limit = { exists = location.county.kingdom }
			location.county.kingdom = { save_scope_as = kingdom_title }
		}
		scope:liege = { save_scope_as = target_military }
		if = {
			limit = {
				any_spouse = {
					is_available_healthy_ai_adult = yes
					has_any_good_relationship_with_root_trigger = yes
				}
			}
			random_spouse = {
				limit = {
					is_available_healthy_ai_adult = yes
					has_any_good_relationship_with_root_trigger = yes
				}
				weight = {
					base = 1
					modifier = {
						add = 5
						has_relation_lover = root
					}
					modifier = {
						add = 3
						this = root.primary_spouse
					}
				}
				save_scope_as = spouse
			}
		}
	}
	
	option = { # Go to war NOW
		name = ep3_decisions_event.6001.a
		set_variable = separatist_uprising_decision_var
		add_to_variable_list = {
			name = separatist_uprising_decision_target_var
			target = scope:liege
		}
		add_character_modifier = {
			modifier = ep3_separatist_uprising
			years = 15
		}
		add_pressed_claim = location.duchy
		spawn_army = {
			name = culture_separatists
			levies = {
				value = 500
				multiply = { 
					value = scope:liege.primary_title.tier
				}
			}
			location = root.location
			origin = root.location
			inheritable = no
		}
		spawn_army = {
			name = culture_separatists
			levies = {
				value = 500
				multiply = { 
					value = scope:liege.primary_title.tier
				}
			}
			location = root.location
			origin = root.location
			inheritable = no
		}
		spawn_army = {
			name = culture_separatists
			men_at_arms = {
				type = handpicked_faithful
				stacks = 2
			}
			location = root.location
			origin = root.location
			inheritable = no
		}
		spawn_army = {
			name = culture_separatists
			men_at_arms = {
				type = handpicked_faithful
				stacks = 2
			}
			location = root.location
			origin = root.location
			inheritable = no
		}
		spawn_army = {
			name = culture_separatists
			men_at_arms = {
				type = handpicked_faithful
				stacks = 2
			}
			location = root.location
			origin = root.location
			inheritable = no
		}
		start_war = {
			cb = claim_cb
			target = location.duchy.holder.top_liege
			claimant = root
			target_title = location.duchy
		}
		stress_impact = {
			calm = major_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				root_military_strength_higher_than_military_target_value > target_military_strength_root_value
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = reckless
					has_trait = wrathful
					has_trait = brave
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = calm
					has_trait = craven
				}
			}
			modifier = { # Asen and Peter always try to go to war with you
				add = 1000
				primary_title = title:d_laamp_asen
			}
		}
	}
	
	option = { # Just the claim pls
		name = ep3_decisions_event.6001.b
		set_variable = separatist_uprising_decision_var
		add_gold = major_gold_value
		add_pressed_claim = location.duchy
		
		stress_impact = {
			celibate = major_stress_impact_gain
			chaste = medium_stress_impact_gain
			just = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				root_military_strength_higher_than_military_target_value < target_military_strength_root_value
			}
			modifier = { # Asen and Peter always try to go to war with you
				factor = 0
				primary_title = title:d_laamp_asen
			}
		}
	}
	
	option = { # Pacifist route
		name = ep3_decisions_event.6001.c
		show_as_unavailable = { always = yes } # We let you know that this route exists
		trigger = {
			# Friend or Lover
			trigger_if = {
				limit = {
					OR = {
						can_set_relation_potential_lover_trigger = { CHARACTER = scope:liege }
						can_set_relation_lover_trigger = { CHARACTER = scope:liege }
					}
				}
				custom_tooltip = {
					text = separatist_uprising_decision_pacifist_option_friend_lover_tt
					calc_true_if = {
						amount >= 3
						any_spouse = {
							is_lowborn = no
							culture = root.location.county.culture
						}
						faith = root.location.county.faith
						any_hooked_character = { this = scope:liege }
						OR = {
							has_relation_friend = scope:liege
							has_relation_lover = scope:liege
						}
						prestige_level > scope:liege.prestige_level
					}
				}
			}
			# Only Friend
			trigger_else = {
				custom_tooltip = {
					text = separatist_uprising_decision_pacifist_option_friend_tt
					calc_true_if = {
						amount >= 3
						any_spouse = {
							is_lowborn = no
							culture = root.location.county.culture
						}
						faith = root.location.county.faith
						any_hooked_character = { this = scope:liege }
						has_relation_friend = scope:liege
						prestige_level > scope:liege.prestige_level
					}
				}
			}
			location.duchy = {
				any_de_jure_county = {
					this != scope:liege.capital_county
				}
			}
		}
		scope:liege = { save_scope_as = new_liege }
		set_variable = separatist_uprising_decision_var
		set_variable = became_landed_through_separatist_uprising_var
		location.duchy = {
			add_to_list = transfer_titles
			# All De Jure Counties held by the liege will be moved over
			every_de_jure_county = {
				limit = {
					holder = scope:liege
					this != scope:liege.capital_county
				}
				add_to_list = transfer_titles
			}
			# If no counties can be taken from the liege, grab one from vassals
			if = {
				limit = {
					NOT = {
						any_in_list = {
							list = transfer_titles
							tier = tier_county
						}
					}
				}
				random_de_jure_county = {
					limit = {
						holder = { any_liege_or_above = { this = scope:liege } }
					}
					weight = {
						base = 1
						modifier = {
							add = 100
							NOR = { 
								holder.primary_title = this 
								holder.capital_county = this
							}
						}
					}
					add_to_list = transfer_titles
				}
			}
			holder ?= {
				if = { # Handle noble family heads you are stealing duchy from
					limit = {
						highest_held_title_tier = tier_duchy
						any_held_title = { is_noble_family_title = yes }
						any_held_title = {
							count = 1
							title_tier = duchy
							is_noble_family_title = no
						}
					}
					if = { # Give titles to heir, keep noble family
						limit = { primary_heir.house ?= house }
						primary_heir = { save_scope_as = old_heir }
						every_held_title = {
							limit = {
								NOR = {
									is_landless_type_title = yes
									is_noble_family_title = yes
								}
							}
							add_to_list = heir_titles
						}
					}
					else = { # Give titles to adventurer
						every_held_title = {
							limit = {
								NOR = {
									is_landless_type_title = yes
									is_noble_family_title = yes
								}
							}
							add_to_list = transfer_titles
						}
					}
				}
			}
		}
		if = {
			limit = {
				exists = scope:old_heir
				any_in_list = { list = heir_titles }
			}
			hidden_effect = {
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = heir_change
					add_claim_on_loss = no
				}
				every_in_list = {
					list = heir_titles
					limit = { tier >= tier_county }
					change_title_holder_include_vassals = {
						holder = scope:old_heir
						change = scope:heir_change
					}
				}
				resolve_title_and_vassal_change = scope:heir_change
			}
		}
		ep3_become_landed_transfer_no_ennobled_modifier_effect = {
			TITLE_RECEIVER = root
			TITLE_LIST = transfer_titles
			TYPE = granted
			REASON = flag:culture_champion
		}
		hidden_effect = {
			scope:old_heir ?= {
				create_title_and_vassal_change = {
					type = granted
					save_scope_as = heir_change2
					add_claim_on_loss = no
				}
				change_liege = {
					liege = root
					change = scope:heir_change2
				}
				resolve_title_and_vassal_change = scope:heir_change2	
			}
			every_courtier = {
				set_variable = {
					name = former_camp_leader
					value = root
				}
				add_trait = adventurer_follower
			}
		}
		add_pressed_claim = scope:kingdom_title
		# Messages for nearby players
		create_landed_ruler_message_effect = {
			LANDED = root
			FLAVOR_CHAR = scope:new_liege
			FLAVOR_TITLE = scope:new_primary_title
			REASON = flag:culture_champion
		}
		stress_impact = {
			celibate = major_stress_impact_gain
			chaste = medium_stress_impact_gain
			just = medium_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = celibate
					has_trait = chaste
					has_trait = just
					has_trait = callous
				}
			}
			modifier = { # Asen and Peter always try to go to war with you
				factor = 0
				primary_title = title:d_laamp_asen
			}
		}
	}
	
	option = { # Let me think about it
		name = ep3_decisions_event.6001.d
		
		ai_chance = {
			base = 0
		}
	}
}

# We give out the Populist Leader trait
ep3_decisions_event.6002 = {
	type = character_event
	title = ep3_decisions_event.6002.t
	desc = ep3_decisions_event.6002.desc
	theme = laamp
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = arrogant
					has_trait = callous
					has_trait = ambitious
				}
			}
			animation = chess_cocky
		}
		animation = celebrate_sword
	}
	lower_right_portrait = scope:defender
	
	option = { # Wahoo
		name = ep3_decisions_event.6002.a
		if = {
			limit = {
				has_trait = peasant_leader
			}
			remove_trait = peasant_leader
			add_trait_force_tooltip = populist_leader
		}
		else = {
			add_trait_force_tooltip = populist_leader
		}
		if = { # If you are Todor we remove your op Modifier
			limit = { has_character_modifier = ep3_master_todor_modifier }
			remove_character_modifier = ep3_master_todor_modifier
		}
		stress_impact = {
			brave = medium_stress_impact_loss
			ambitious = medium_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}
}


##################################################
# Go Fish
# by Alexander Windahl
# 9001-9030
##################################################
ep3_decisions_event.9001 = {
	type = character_event
	title = ep3_decisions_event.9001.t
	desc = {
		desc = ep3_decisions_event.9001.desc

		triggered_desc = {
			trigger = {
					exists = scope:potential_friend
				}
			desc = ep3_decisions_event.9001.friend
		}

		first_valid = {
			triggered_desc = {
				trigger = {
					location = {
						#only ice-fish if water is frozen
							has_province_modifier = winter_harsh_modifier 

					}
				}
				desc = ep3_decisions_event.9001.ice_fishing
			}
			desc = ep3_decisions_event.9001.fishing
		}
	}

	theme = travel_sea
	override_background = { reference = bp1_docks_tribal }
	override_effect_2d = {
		trigger = {
			exists = scope:rain_day
		}
  		reference = rain	
	}

	left_portrait = {
		character = root
		animation = ecstasy
	}
	right_portrait = {
		character = scope:potential_friend
		animation = admiration
	}

	immediate = {
		save_scope_as = camp_owner
		location = { save_scope_as = fishing_province }
		random_relation = {
			type = potential_friend
			limit = {
				this != scope:camp_owner
				is_physically_able_ai_adult = yes
				location = scope:fishing_province
			}
			save_scope_as = potential_friend
		}
		random_rain_snow_chance_effect = yes
	}

	option = { # Fish alone
		name = ep3_decisions_event.9001.a

		stress_impact = {
			reclusive = minor_stress_impact_loss
		}

		ai_chance = {
			base = 1
		}

		custom_tooltip = ep3_decisions_event.9001.a.tt

		trigger_event = { id = ep3_decisions_event.9010 }
	}

	option = { # Fish with your potential_friend
		trigger = {
			 exists = scope:potential_friend
		}
		name = ep3_decisions_event.9001.b
		
		scope:potential_friend = {
				add_opinion = {
					target = root
					modifier = happy_opinion
					opinion = 10
				}
			}
		
		ai_chance = {
			base = 1
		}

		custom_tooltip = ep3_decisions_event.9001.b.tt

		trigger_event = { id = ep3_decisions_event.9020 }
	}

	option = { # Rent a boat
		add_character_flag = {
			flag = ocean
			years = 2
		}
		if = {
			limit = {
				has_character_flag = ocean
			}
		}
		name = ep3_decisions_event.9001.c

		trigger = {
			short_term_gold >= medium_gold_value
			trigger_if = {
				limit = {
					is_ai = yes
				}
				short_term_gold >= 500
			}
		}
		remove_short_term_gold = minor_gold_value

		custom_tooltip = ep3_decisions_event.9001.c.tt
		
		ai_chance = {
			base = 1
		}

		trigger_event = { id = ep3_decisions_event.9030 }
	}
}

ep3_decisions_event.9010 = { # Fish Alone 
	type = character_event
	title = ep3_decisions_event.9010.t
	desc = {
		desc = ep3_decisions_event.9010.desc
	}

	theme = travel_sea
	override_background = { reference = bp1_docks_tribal }
	override_effect_2d = {
		trigger = {
			exists = scope:rain_day
		}
  		reference = rain	
	}

	left_portrait = {
		character = root
		animation = hunting_knife_start
	}

	option = {
		name = ep3_decisions_event.9010.a

		duel = {
			skill = prowess
			value = 22
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.nofish
					left_icon = root
					add_stress = minor_stress_impact_loss
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.9030.a.fish
					left_icon = root
					stress_impact = {
						base = miniscule_stress_impact_loss
						ambitious = medium_stress_impact_loss
					}
					domicile = {
						change_provisions = miniscule_provisions_value
					}
				}
			}
		}
		ai_chance = {
			base = 1
		}
	}

	option = {
		trigger = {
			NOT = {
				has_trait = wrathful
			}
		}
		name = ep3_decisions_event.9010.b
			
		random_list = {
			99 = { #nothing happens
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9010.b.nothing
					left_icon = root
					stress_impact = {
						base = medium_stress_impact_loss
						calm = medium_stress_impact_loss
					}
				}
			}
			1 = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.9010.b.trait
					left_icon = root
					add_trait = calm 
					stress_impact = {
						base = medium_stress_impact_loss
						calm = medium_stress_impact_loss
					}	
				}
			}
		}
		ai_chance = {
			base = 1
		}
	}
}


ep3_decisions_event.9020 = { # Fish With Your potential_friend
	type = character_event
	title = ep3_decisions_event.9020.t
	desc = {
		desc = ep3_decisions_event.9020.desc
	}

	theme = travel_sea
	override_background = { reference = bp1_docks_tribal }
	override_effect_2d = {
		trigger = {
			exists = scope:rain_day
		}
  		reference = rain	
	}

	left_portrait = {
		character = root
		animation = laugh
	}

	right_portrait = {
		character = scope:potential_friend
		animation = happiness
	}

	option = { #Become friends!
		name = ep3_decisions_event.9020.a

		progress_towards_friend_effect = {
			CHARACTER = scope:potential_friend
			OPINION = yes
			REASON = friend_fishing_trip
		}

		random_list = {
			99 = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.nofish
					left_icon = root
					right_icon = scope:potential_friend
					add_stress = medium_stress_impact_loss
				}
			}
			1 = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.fish
					left_icon = root
					right_icon = scope:potential_friend
					stress_impact = {
						base = miniscule_stress_impact_loss
						ambitious = major_stress_impact_loss
					}
					domicile = {
						change_provisions = miniscule_provisions_value
					}
				}		
			}
		}

		ai_chance = {
			base = 1
		}
	}

	option = { #Actually, the fish are more important
		name = ep3_decisions_event.9020.b

		duel = {
			skill = prowess
			value = 20
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.nofish
					left_icon = root
					right_icon = scope:potential_friend
					add_stress = medium_stress_impact_loss
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.9030.a.fish
					left_icon = root
					right_icon = scope:potential_friend
					stress_impact = {
						base = miniscule_stress_impact_loss
						ambitious = major_stress_impact_loss
					}
					domicile = {
						change_provisions = miniscule_provisions_value
					}	
				}			
			}
		}

		ai_chance = {
			base = 1
		}
	}
}

ep3_decisions_event.9030 = { # Fish On A Boat, your potential friend will join you
	type = character_event
	title = ep3_decisions_event.9030.t
	desc = {
		desc = ep3_decisions_event.9030.desc

		triggered_desc = {
			trigger = {
					exists = scope:potential_friend
				}
			desc = ep3_decisions_event.9030.friend
		}
	}

	theme = travel_sea
	override_background = { reference = ocean }
	override_effect_2d = {
		trigger = {
			exists = scope:rain_day
		}
  		reference = rain	
	}

	left_portrait = {
		character = root
		animation = happiness
	}

	right_portrait = {
		character = scope:potential_friend
		animation = personality_content
	}

	option = { #You fish
		name = ep3_decisions_event.9030.a

		duel = {
			skill = prowess
			value = 30
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.nofish
					left_icon = root
					right_icon = scope:potential_friend
					add_stress = major_stress_impact_loss
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.9030.a.fish
					left_icon = root
					right_icon = scope:potential_friend
					stress_impact = {
						base = minor_stress_impact_loss
						ambitious = major_stress_impact_loss
					}
					domicile = {
						change_provisions = minor_provisions_value
					}				
				}
			}
		}

		ai_chance = {
			base = 1
		}
	}

	option = { #Have your buddy fish
		name = ep3_decisions_event.9030.b
		trigger = {
			exists = scope:potential_friend
		}
		
		progress_towards_friend_effect = {
			CHARACTER = scope:potential_friend
			OPINION = yes
			REASON = friend_fishing_trip
		}

		random_list = {
			80 = {
				send_interface_toast = {
					type = event_toast_effect_neutral
					title = ep3_decisions_event.9030.a.nofish
					left_icon = root
					right_icon = scope:potential_friend
					add_stress = major_stress_impact_loss
				}
			}
			20 = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = ep3_decisions_event.9030.a.fishfriend
					left_icon = scope:potential_friend
					add_stress = minor_stress_impact_loss
					domicile = {
						change_provisions = minor_provisions_value
					}		
				}		
			}
		}

		ai_chance = {
			base = 1
		}
	}
}
