namespace = bp2_hostage_system

###
### WAR EXECUTION/SPARING
###

scripted_effect bp2_new_war_joiner_save_hostages_effect = {
	# Tidy up previous scopes
	every_in_list = {
		list = hostages
		remove_from_list = hostages
	}
	clear_saved_scope = hostage
	every_in_list = {
		list = my_hostages
		remove_from_list = my_hostages
	}
	clear_saved_scope = my_hostage
	# Save our hostages from participants, who we have not previously spared
	every_warden_hostage = {
		limit = {
			home_court ?= { is_at_war_with = root }
			NOT = {
				has_opinion_modifier = {
					target = root
					modifier = spared_me_opinion
				}
			}
			save_temporary_scope_as = hostage_temp
			scope:war = { is_participant = scope:hostage_temp.home_court }
		}
		add_to_list = hostages
	}
	random_in_list = {
		list = hostages
		weight = {
			base = 1
			is_of_major_interest_to_weight_up_modifier = { CHARACTER = home_court }
			is_of_minor_interest_to_weight_up_modifier = { CHARACTER = home_court }
		}
		save_scope_as = hostage
		home_court = { save_scope_as = hostage_home_court }
	}
	# Save hostages of participants that we have, who have not been spared previously
	if = {
		limit = {
			any_home_court_hostage = {
				warden ?= { is_at_war_with = root }
				save_temporary_scope_as = hostage_temp
				NOT = {
					has_opinion_modifier = {
						target = scope:hostage_temp.warden
						modifier = spared_me_opinion
					}
				}
				scope:war = { is_participant = scope:hostage_temp.warden }
			}
		}
		every_home_court_hostage = {
			limit = {
				warden ?= { is_at_war_with = root }
				save_temporary_scope_as = hostage_temp
				NOT = {
					has_opinion_modifier = {
						target = scope:hostage_temp.warden
						modifier = spared_me_opinion
					}
				}
				scope:war = { is_participant = scope:hostage_temp.warden }
			}
			add_to_list = my_hostages
		}
		random_in_list = {
			list = my_hostages
			weight = {
				base = 1
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
			}
			save_scope_as = my_hostage
		}
	}
}

scripted_effect bp2_execute_hostages_option_effect = {
	save_scope_as = hostage_warden
	every_in_list = {
		list = hostages
		save_scope_as = hostage
		home_court = { save_scope_as = hostage_home_court }
		show_as_tooltip = { bp2_execute_hostage_effect = yes }
		scope:hostage_home_court = {
			trigger_event = { id = bp2_hostage_system.0140 days = 1 }
		}	
	}
}

scripted_effect bp2_spared_hostage_option_effect = {
	save_scope_as = hostage_sparer
	every_in_list = {
		list = hostages
		add_opinion = {
			target = scope:hostage_sparer
			modifier = spared_me_opinion
			opinion = 40
		}
	}
	scope:hostage_home_court = {
		if = {
			limit = { is_ai = yes}
			if = {
				limit = {
					NOT = {
						any_in_list = {
							list = hostages
							has_character_flag = byz_claimant_flag
						}
					}
				}
				add_opinion = {
					target = scope:hostage_sparer
					modifier = spared_hostage_opinion
					opinion = 20
				}
			}
		}
		trigger_event = { id = bp2_hostage_system.0141 days = 1 }
	}
	hidden_effect = {
		scope:hostage_home_court = {
			send_interface_toast = {
				title = hostage_spared_toast
				left_icon = scope:hostage
				right_icon = scope:hostage_sparer
				show_as_tooltip = {
					scope:hostage = {
						add_opinion = {
							target = scope:hostage_sparer
							modifier = spared_me_opinion
							opinion = 40
						}
					}
				}
			}
		}
		scope:hostage_sparer = {
			send_interface_toast = {
				title = hostage_spared_toast
				left_icon = scope:hostage
				right_icon = scope:hostage_home_court
				show_as_tooltip = {
					scope:hostage = {
						add_opinion = {
							target = scope:hostage_sparer
							modifier = spared_me_opinion
							opinion = 40
						}
					}
				}
			}
		}
	}
}

# Declare war and have hostage to execute
bp2_hostage_system.0100 = {
	type = character_event
	title = bp2_hostage_system.0100.t
	desc = {
		desc = bp2_hostage_system.0100.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:victim } 
				desc = bp2_hostage_system.0100.executed_hostage
			}
			triggered_desc = {
				trigger = { exists = scope:hostage_sparer } 
				desc = bp2_hostage_system.0100.spared_hostage
			}
			desc = bp2_hostage_system.0100.desc
		}
		triggered_desc = {
			trigger = {
				scope:my_hostage ?= {
					is_alive = yes
					home_court = root
				}
				NOT = { exists = scope:hostage_sparer }
			}
			desc = bp2_hostage_system.0100.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:hostage
		animation = beg
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_home_court
	
	immediate = {
		# Tidy up previous scopes
		every_in_list = {
			list = hostages
			remove_from_list = hostages
		}
		clear_saved_scope = hostage
		every_in_list = {
			list = my_hostages
			remove_from_list = my_hostages
		}
		clear_saved_scope = my_hostage
		# Save our hostages from participants, who we have not previously spared
		every_warden_hostage = {
			limit = {
				home_court ?= scope:defender
				NOT = {
					has_opinion_modifier = {
						target = root
						modifier = spared_me_opinion
					}
				}
				scope:war = { is_participant = scope:defender }
			}
			add_to_list = hostages
		}
		random_in_list = {
			list = hostages
			weight = {
				base = 1
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = home_court }
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = home_court }
			}
			save_scope_as = hostage
		}
		scope:defender = { save_scope_as = hostage_home_court }
		# Save hostages of participants that we have, who have not been spared previously
		if = {
			limit = {
				any_home_court_hostage = {
					warden ?= scope:defender
					save_temporary_scope_as = hostage_temp
					NOT = {
						has_opinion_modifier = {
							target = scope:defender
							modifier = spared_me_opinion
						}
					}
					scope:war = { is_participant = scope:defender }
				}
			}
			every_home_court_hostage = {
				limit = {
					warden ?= scope:defender
					save_temporary_scope_as = hostage_temp
					NOT = {
						has_opinion_modifier = {
							target = scope:defender
							modifier = spared_me_opinion
						}
					}
					scope:war = { is_participant = scope:defender }
				}
				add_to_list = my_hostages
			}
			random_in_list = {
				list = my_hostages
				weight = {
					base = 1
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				}
				save_scope_as = my_hostage
			}
		}
	}
	
	option = {
		trigger = {
			NOT = {
				any_in_list = {
					list = hostages
					has_character_flag = byz_claimant_flag
				}
			}
		}
		name = bp2_hostage_system.0100.a
		bp2_execute_hostages_option_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				exists = scope:victim
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_vengefulness = 0.25
			}
		}
	}
	
	option = {
		name = bp2_hostage_system.0100.b
		bp2_spared_hostage_option_effect = yes
		ai_chance = {
			base = 0
			opinion_modifier = {
				opinion_target = scope:hostage
				multiplier = 1
			}
			opinion_modifier = {
				opinion_target = scope:hostage_home_court
				multiplier = 0.5
			}
			modifier = {
				exists = scope:hostage_sparer
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_vengefulness = -0.25
			}
		}
	}
}

# Attacked and have hostage to execute
bp2_hostage_system.0110 = {
	type = character_event
	title = bp2_hostage_system.0110.t
	desc = {
		desc = bp2_hostage_system.0110.desc
		triggered_desc = {
			trigger = {
				scope:my_hostage ?= {
					is_alive = yes
					home_court = root
				}
				NOT = { exists = scope:hostage_sparer }
			}
			desc = bp2_hostage_system.0100.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = beg
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:attacker
	
	immediate = {
		# Tidy up previous scopes
		every_in_list = {
			list = hostages
			remove_from_list = hostages
		}
		clear_saved_scope = hostage
		every_in_list = {
			list = my_hostages
			remove_from_list = my_hostages
		}
		clear_saved_scope = my_hostage
		# Save our hostages from participants, who we have not previously spared
		every_warden_hostage = {
			limit = {
				home_court ?= scope:attacker
				NOT = {
					has_opinion_modifier = {
						target = root
						modifier = spared_me_opinion
					}
				}
				scope:war = { is_participant = scope:attacker }
			}
			add_to_list = hostages
		}
		random_in_list = {
			list = hostages
			weight = {
				base = 1
				is_of_major_interest_to_weight_up_modifier = { CHARACTER = home_court }
				is_of_minor_interest_to_weight_up_modifier = { CHARACTER = home_court }
			}
			save_scope_as = hostage
		}
		scope:attacker = { save_scope_as = hostage_home_court }
		# Save hostages of participants that we have, who have not been spared previously
		if = {
			limit = {
				any_home_court_hostage = {
					warden ?= scope:attacker
					save_temporary_scope_as = hostage_temp
					NOT = {
						has_opinion_modifier = {
							target = scope:attacker
							modifier = spared_me_opinion
						}
					}
					scope:war = { is_participant = scope:attacker }
				}
			}
			every_home_court_hostage = {
				limit = {
					warden ?= scope:attacker
					save_temporary_scope_as = hostage_temp
					NOT = {
						has_opinion_modifier = {
							target = scope:attacker
							modifier = spared_me_opinion
						}
					}
					scope:war = { is_participant = scope:attacker }
				}
				add_to_list = my_hostages
			}
			random_in_list = {
				list = my_hostages
				weight = {
					base = 1
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				}
				save_scope_as = my_hostage
			}
		}
	}
	
	option = {
		trigger = {
			NOT = {
				any_in_list = {
					list = hostages
					has_character_flag = byz_claimant_flag
				}
			}
		}
		name = bp2_hostage_system.0110.a
		bp2_execute_hostages_option_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				exists = scope:victim
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_vengefulness = 0.25
			}
		}
	}
	
	option = {
		name = bp2_hostage_system.0110.b
		bp2_spared_hostage_option_effect = yes
		ai_chance = {
			base = 0
			opinion_modifier = {
				opinion_target = scope:hostage
				multiplier = 1
			}
			opinion_modifier = {
				opinion_target = scope:hostage_home_court
				multiplier = 0.5
			}
			modifier = {
				exists = scope:hostage_sparer
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_vengefulness = -0.25
			}
		}
	}
}

# Joined war and have hostage to execute
bp2_hostage_system.0120 = {
	type = character_event
	title = bp2_hostage_system.0120.t
	desc = {
		desc = bp2_hostage_system.0120.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:victim } 
				desc = bp2_hostage_system.0100.executed_hostage
			}
			triggered_desc = {
				trigger = { exists = scope:hostage_sparer } 
				desc = bp2_hostage_system.0100.spared_hostage
			}
			desc = bp2_hostage_system.0120.desc
		}
		triggered_desc = {
			trigger = {
				scope:my_hostage ?= {
					is_alive = yes
					home_court = root
				}
				NOT = { exists = scope:hostage_sparer }
			}
			desc = bp2_hostage_system.0100.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = beg
	}
	lower_left_portrait = scope:my_hostage
	lower_center_portrait = scope:war_joiner_ally
	lower_right_portrait = scope:hostage_home_court
	
	trigger = {
		any_warden_hostage = {
			home_court ?= { is_at_war_with = root }
			save_temporary_scope_as = hostage_temp
		}
		scope:war = { is_participant = scope:hostage_temp.home_court }
	}
	
	immediate = {
		save_scope_as = new_participant
		bp2_new_war_joiner_save_hostages_effect = yes
	}
	
	option = {
		trigger = {
			NOT = {
				any_in_list = {
					list = hostages
					has_character_flag = byz_claimant_flag
				}
			}
		}
		name = bp2_hostage_system.0120.a
		bp2_execute_hostages_option_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				exists = scope:victim
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_vengefulness = 0.25
			}
		}
	}
	
	option = {
		name = bp2_hostage_system.0120.b
		bp2_spared_hostage_option_effect = yes
		ai_chance = {
			base = 0
			opinion_modifier = {
				opinion_target = scope:hostage
				multiplier = 1
			}
			opinion_modifier = {
				opinion_target = scope:hostage_home_court
				multiplier = 0.5
			}
			modifier = {
				exists = scope:hostage_sparer
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_vengefulness = -0.25
			}
		}
	}
}

# Existing war participant and have hostage to execute from new war joiner
bp2_hostage_system.0130 = {
	type = character_event
	title = bp2_hostage_system.0130.t
	desc = {
		desc = bp2_hostage_system.0130.desc
		triggered_desc = {
			trigger = {
				scope:my_hostage ?= {
					is_alive = yes
					home_court = root
				}
				NOT = { exists = scope:hostage_sparer }
			}
			desc = bp2_hostage_system.0100.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = war_over_win
	}
	right_portrait = {
		character = scope:hostage
		animation = beg
	}
	lower_left_portrait = scope:my_hostage
	lower_center_portrait = scope:war_joiner_ally
	lower_right_portrait = scope:hostage_home_court
	cooldown = { days = 1 }
	
	trigger = {
		any_warden_hostage = { home_court ?= scope:war_joiner }
	}
	
	immediate = {
		save_scope_as = existing_participant
		bp2_new_war_joiner_save_hostages_effect = yes
	}
	
	option = {
		name = bp2_hostage_system.0130.a
		bp2_execute_hostages_option_effect = yes
		ai_chance = {
			base = 100
			modifier = {
				exists = scope:victim
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = -0.25
				ai_vengefulness = 0.25
			}
		}
	}
	
	option = {
		name = bp2_hostage_system.0130.b
		bp2_spared_hostage_option_effect = yes
		ai_chance = {
			base = 0
			opinion_modifier = {
				opinion_target = scope:hostage
				multiplier = 1
			}
			opinion_modifier = {
				opinion_target = scope:hostage_home_court
				multiplier = 0.5
			}
			modifier = {
				exists = scope:hostage_sparer
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_vengefulness = -0.25
			}
		}
	}
}

# Inform home court of hostage execution
bp2_hostage_system.0140 = {
	type = letter_event
	opening = { desc = bp2_hostage_system.0140.opening }
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:executioner = scope:war.primary_attacker }
				desc = bp2_hostage_system.0140.attacker
			}
			triggered_desc = {
				trigger = { scope:executioner = scope:war.primary_defender }
				desc = bp2_hostage_system.0140.defender
			}
			triggered_desc = {
				trigger = {
					scope:executioner = { is_attacker_in_war = scope:war }
				}	
				desc = bp2_hostage_system.0140.attacker_ally
			}
			triggered_desc = {
				trigger = {
					scope:executioner = { is_defender_in_war = scope:war }
				}	
				desc = bp2_hostage_system.0140.defender_ally
			}
		}
	}
	sender = {
		character = scope:executioner
		animation = dismissal
	}
	cooldown = { days = 1 }
	
	immediate = {
		every_in_list = {
			list = hostages
			limit = { home_court = root }
			save_scope_as = hostage
			home_court = { save_scope_as = home_court }
			bp2_execute_hostage_effect = yes
		}
	}
	
	option = {
		name = {
			text = bp2_hostage_system.0140.a.attacker
			trigger = { scope:executioner = scope:war.primary_attacker }
		}
		name = {
			text = bp2_hostage_system.0140.a.defender
			trigger = { scope:executioner = scope:war.primary_defender }
		}
		name = {
			text = bp2_hostage_system.0140.a.attacker_ally
			trigger = {
				scope:executioner = { is_attacker_in_war = scope:war }
			}
		}
		name = {
			text = bp2_hostage_system.0140.a.defender_ally
			trigger = {
				scope:executioner = { is_defender_in_war = scope:war }
			}
		}
	}

	after = {
		clear_saved_scope = my_hostage
		clear_saved_scope = hostage
		if = {
			limit = {
				is_attacker_in_war = scope:war
				any_warden_hostage = {
					home_court ?= scope:executioner
				}
			}
			if = {
				limit = { this = scope:war.primary_attacker }
				trigger_event = { id = bp2_hostage_system.0100 days = 3 }
			}
			else = {
				trigger_event = { id = bp2_hostage_system.0120 days = 3 }
			}
		}
	}
}

# Inform home court of hostage sparing
bp2_hostage_system.0141 = {
	type = letter_event
	opening = { desc = bp2_hostage_system.0141.opening }
	desc = {
		desc = bp2_hostage_system.0141.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:hostage_sparer = scope:war.primary_attacker }
				desc = bp2_hostage_system.0141.attacker
			}
			triggered_desc = {
				trigger = { scope:hostage_sparer = scope:war.primary_defender }
				desc = bp2_hostage_system.0141.defender
			}
			triggered_desc = {
				trigger = {
					scope:hostage_sparer = { is_attacker_in_war = scope:war }
				}	
				desc = bp2_hostage_system.0141.attacker_ally
			}
			triggered_desc = {
				trigger = {
					scope:hostage_sparer = { is_defender_in_war = scope:war }
				}	
				desc = bp2_hostage_system.0141.defender_ally
			}
		}
		triggered_desc = {
			trigger = {
				exists = scope:my_hostage
				NOT = {
					scope:my_hostage = {
						has_opinion_modifier = {
							target = root
							modifier = spared_me_opinion
						}
					}
				}
			}
			desc = bp2_hostage_system.0141.request
		}
	}
	sender = {
		character = scope:hostage_sparer
		animation = dismissal
	}
	cooldown = { days = 1 }
	
	immediate = {
		show_as_tooltip = {
			every_in_list = {
				list = hostages
				add_opinion = {
					target = scope:hostage_sparer
					modifier = spared_me_opinion
					opinion = 40
				}
			}
		}
	}
	
	option = {
		name = {
			text = bp2_hostage_system.0141.a.attacker
			trigger = { scope:hostage_sparer = scope:war.primary_attacker }
		}
		name = {
			text = bp2_hostage_system.0141.a.defender
			trigger = { scope:hostage_sparer = scope:war.primary_defender }
		}
		name = {
			text = bp2_hostage_system.0141.a.attacker_ally
			trigger = {
				scope:hostage_sparer = { is_attacker_in_war = scope:war }
			}
		}
		name = {
			text = bp2_hostage_system.0141.a.defender_ally
			trigger = {
				scope:hostage_sparer = { is_defender_in_war = scope:war }
			}
		}
	}

	after = {
		clear_saved_scope = my_hostage
		clear_saved_scope = hostage
		if = {
			limit = {
				is_attacker_in_war = scope:war
				any_warden_hostage = {
					home_court ?= scope:hostage_sparer
				}
			}
			if = {
				limit = { this = scope:war.primary_attacker }
				trigger_event = { id = bp2_hostage_system.0100 days = 3 }
			}
			else = {
				trigger_event = { id = bp2_hostage_system.0120 days = 3 }
			}
		}
	}
}

###
### COMING OF AGE
###

# Hostage comes of age
bp2_hostage_system.0200 = {
	type = character_event
	title = bp2_hostage_system.0200.t
	desc = {
		desc = bp2_hostage_system.0200.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:my_hostage ?= {
						is_alive = yes
						home_court = root
					}
				}
				desc = bp2_hostage_system.0200.my_hostage
			}
			desc = bp2_hostage_system.0200.closing
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = war_over_win
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_home_court
	
	trigger = {
		scope:hostage = { is_hostage_of = root }
		NOT = {
			any_home_court_hostage = {
				is_travelling = yes
				OR = {
					exists = var:short_hostage_duration
					exists = var:long_hostage_duration
					exists = var:hostage_duration
				}
			}
		}
	}

	immediate = {
		save_scope_as = hostage_warden
		scope:hostage.home_court = {
			save_scope_as = hostage_home_court
			if = {
				limit = {
					any_warden_hostage = { home_court ?= root }
				}
				every_warden_hostage = {
					limit = { home_court ?= root }
					add_to_list = my_hostages
				}
				random_in_list = {
					list = my_hostages
					weight = {
						base = 1
						is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
						is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
					}
					save_scope_as = my_hostage
				}
			}
		}
		if = {
			limit = {
				scope:hostage = {
					NOT = { has_relation_rival = root }
				}
			}
			if = {
				limit = {
					can_set_relation_friend_trigger = { CHARACTER = scope:hostage }
					reverse_opinion = {
						target = scope:hostage
						value >= 25
					}
				}
				progress_towards_friend_effect = {
					REASON = friend_well_treated_hostage
					CHARACTER = scope:hostage
					OPINION = default_friend_opinion
				}
			}
			scope:hostage = {
				save_opinion_value_as = {
					name = warden_opinion
					target = warden
				}
			}
			random_list = {
				0 = {
					modifier = { add = var:hook_chance }
					add_hook = {
						type = hostage_loyalty
						target = scope:hostage
					}
				}
				100 = {
					modifier = {
						add = {
							value = 0
							subtract = var:hook_chance
						}
					}
					custom_tooltip = bp2_hostage_hook_failed_tt
				}
			}
		}
	}
	
	option = { # Send home
		name = bp2_hostage_system.0200.a
		trigger = {
			NAND = {
				is_ai = yes
				scope:hostage_warden.house ?= scope:hostage.house
				scope:hostage.house != scope:hostage_home_court.house
			}
		}
		show_as_tooltip = {
			bp2_return_hostage_effect = { HOSTAGE = scope:hostage }
		}
		if = {
			limit = {
				exists = scope:my_hostage
				scope:hostage_home_court = { is_ai = yes }
				scope:my_hostage = { is_adult = yes }
			}
			custom_tooltip = hostage_more_likely_to_return_tt
		}
		scope:hostage_home_court = {
			trigger_event = { id = bp2_hostage_system.0201 days = 1 }
		}
		ai_chance = {
			base = 25
			bp2_hostage_return_personality_modifier = {
				WARDEN = root
				HOME_COURT = scope:hostage_home_court
			}
			modifier = {
				scope:hostage = {
					has_character_flag = byz_claimant_flag
				}
				factor = 0
			}
			min = 0
		}
	}

	option = { # Keep
		name = {
			text = bp2_hostage_system.0200.b
			trigger = {
				NOT = { exists = scope:my_hostage }
			}
		}
		name = {
			text = bp2_hostage_system.0200.b.my_hostage
			trigger = {
				scope:my_hostage ?= { is_adult = no }
			}
		}
		custom_tooltip = {
			text = halved_hostage_prestige_tt
			add_character_flag = {
				flag = halved_hostage_prestige_income
				years = hostage_adulthood_retained_halved_prestige_duration_value
			}
		}
		scope:hostage_home_court = {
			show_as_tooltip = {
				add_opinion = {
					modifier = angry_opinion
					opinion = -15
					target = root
				}
			}
			trigger_event = { id = bp2_hostage_system.0202 days = 1 }
		}
		ai_chance = {
			base = 10
			modifier = {
				scope:hostage_warden.house ?= scope:hostage.house
				scope:hostage.house != scope:hostage_home_court.house
				add = 1000
			}
		}
	}

	after = {
		remove_variable = hook_chance
	}
}

# Hostage comes of age and returned
bp2_hostage_system.0201 = {
	type = character_event
	title = bp2_hostage_system.0200.t
	desc = {
		desc = bp2_hostage_system.0201.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:my_hostage ?= {
						is_alive = yes
						is_adult = yes
						home_court = scope:hostage_warden
					}
				}
				desc = bp2_hostage_system.0201.my_hostage_adult
			}
			triggered_desc = {
				trigger = {
					scope:my_hostage ?= {
						is_alive = yes
						home_court = scope:hostage_warden
					}
				}
				desc = bp2_hostage_system.0201.my_hostage
			}
		}
	}
	theme = hostage
	override_background = { reference = courtyard }
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:hostage
		animation = admiration
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_warden

	immediate = {
		bp2_return_hostage_effect = { HOSTAGE = scope:hostage }
	}
	
	option = { # Ok
		name = bp2_hostage_system.0201.a
		trigger = {
			NOT = { exists = scope:my_hostage }
		}
	}

	option = { # Return hostage aswell
		name = bp2_hostage_system.0201.b
		trigger = { exists = scope:my_hostage }
		show_as_tooltip = {
			bp2_return_hostage_effect = { HOSTAGE = scope:my_hostage }
		}
		scope:hostage_warden = {
			trigger_event = { id = bp2_hostage_system.0203 days = 1 }
		}
		ai_chance = {
			base = 25
			bp2_hostage_return_personality_modifier = {
				WARDEN = root
				HOME_COURT = scope:hostage_warden
			}
			min = 0
		}
	}

	option = { # Keep hostage
		name = {
			text = bp2_hostage_system.0201.c.adult
			trigger = {
				scope:my_hostage = { is_adult = yes }
			}
		}
		name = {
			text = bp2_hostage_system.0201.c
			trigger = {
				scope:my_hostage = { is_adult = no }
			}
		}
		trigger = { exists = scope:my_hostage }
		scope:hostage_warden = {
			custom_tooltip = {
				text = halved_hostage_prestige_tt
				add_character_flag = {
					flag = halved_hostage_prestige_income
					years = hostage_adulthood_retained_halved_prestige_duration_value
				}
			}
			show_as_tooltip = {
				add_opinion = {
					modifier = angry_opinion
					opinion = -15
					target = root
				}
			}
			trigger_event = { id = bp2_hostage_system.0204 days = 1 }
		}
		ai_chance = {
			base = 10
			modifier = {
				scope:my_hostage = { is_adult = no }
				add = 40
			}
		}
	}
}

# Hostage comes of age and retained
bp2_hostage_system.0202 = {
	type = character_event
	title = bp2_hostage_system.0202.t
	desc = bp2_hostage_system.0202.desc
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = happiness
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_warden
	
	immediate = {
		scope:hostage_warden = { custom_tooltip = halved_hostage_prestige_tt }
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				modifier = angry_opinion
				opinion = -15
				target = scope:hostage_warden
			}
		}
	}

	option = {
		name = bp2_hostage_system.0202.a
	}
}

# Hostage returned in return
bp2_hostage_system.0203 = {
	type = character_event
	title = bp2_hostage_system.0203.t
	desc = {
		desc = bp2_hostage_system.0203.desc
		desc = bp2_hostage_system.0203.closing
	}
	theme = hostage
	override_background = { reference = courtyard }
	left_portrait = {
		character = root
		animation = happiness
	}
	right_portrait = {
		character = scope:my_hostage
		animation = admiration
	}
	lower_right_portrait = scope:hostage
	lower_left_portrait = scope:hostage_home_court

	immediate = {
		bp2_return_hostage_effect = { HOSTAGE = scope:my_hostage }
	}
	
	option = {
		name = bp2_hostage_system.0201.a
	}
}

# Hostage retained in return
bp2_hostage_system.0204 = {
	type = character_event
	title = bp2_hostage_system.0202.t
	desc = {
		desc = bp2_hostage_system.0203.desc
		desc = bp2_hostage_system.0204.closing
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = happiness
	}
	lower_left_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_home_court
	
	immediate = {
		scope:hostage_home_court = { custom_tooltip = halved_hostage_prestige_tt }
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				modifier = angry_opinion
				opinion = -15
				target = scope:hostage_home_court
			}
		}
	}

	option = {
		name = bp2_hostage_system.0202.a
	}
}

###
### DEATH
###

# Hostage has died - warden
bp2_hostage_system.0300 = {
	type = character_event
	title = bp2_hostage_system.0300.t
	desc = {
		desc = bp2_hostage_system.0300.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:hostage.killer ?= root }
				desc = bp2_hostage_system.0300.killer
			}
			triggered_desc = {
				trigger = {
					scope:hostage = { had_gruesome_death_trigger = yes}
				}
				desc = bp2_hostage_system.0300.violent
			}
			desc = bp2_hostage_system.0300.fallback
		}
		desc = bp2_hostage_system.0300.desc
		triggered_desc = {
			trigger = {
				any_home_court_hostage = { warden ?= scope:hostage_home_court }
			}
			desc = bp2_hostage_system.0300.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = pain
	}
	lower_center_portrait = scope:my_hostage
	lower_right_portrait = scope:hostage_home_court
	
	trigger = {
		scope:hostage = {
			NAND = {
				killer = root
				death_reason = death_hostage_execution
			}
		}
	}

	immediate = {
		play_music_cue = mx_cue_death
		show_as_tooltip = {
			scope:hostage = { # Reason not shown in tooltip
				death = { death_reason = death_fight }
			}
		}
		if = {
			limit = {
				scope:hostage_home_court = { is_ai = yes }
			}
			if = { # You killed a *HOSTAGE*!
				limit = {
					scope:hostage.killer ?= root
					NOT = {
						any_secret = {
							type = secret_murder
							secret_target = scope:hostage
						}
					}
				}
				reverse_add_opinion = {
					target = scope:hostage_home_court
					modifier = killed_hostage_opinion
				}
			}
			else = { # Hostage died on your watch
				reverse_add_opinion = {
					target = scope:hostage_home_court
					modifier = hostage_died_opinion
				}
			}
		}
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:hostage_home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:hostage_home_court }
				save_scope_as = my_hostage
			}
		}
	}

	option = {
		name = bp2_hostage_system.0300.a
	}

	after = {
		custom_tooltip = hostage_death_reluctance_tt
		scope:hostage_home_court = {
			trigger_event = { id = bp2_hostage_system.0301 days = 1 }
		}
	}
}

# Hostage has died - home court
bp2_hostage_system.0301 = {
	type = letter_event
	opening = { desc = bp2_hostage_system.0301.opening }
	desc = {
		desc = bp2_hostage_system.0301.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:hostage.killer ?= scope:hostage_warden
					NOT = {
						scope:hostage_warden = {
							any_secret = {
								type = secret_murder
								secret_target = scope:hostage
							}
						}
					}
				}
				desc = bp2_hostage_system.0301.killer
			}
			triggered_desc = {
				trigger = {
					scope:hostage = { had_gruesome_death_trigger = yes }
				}
				desc = bp2_hostage_system.0301.violent
			}
			desc = bp2_hostage_system.0301.fallback
		}
		desc = bp2_hostage_system.0301.desc
		triggered_desc = {
			trigger = { exists = scope:my_hostage }
			desc = bp2_hostage_system.0301.my_hostage
		}
	}
	sender = {
		character = scope:hostage_warden
		animation = dismissal
	}
	cooldown = { days = 1 }
	
	immediate = {
		show_as_tooltip = {
			scope:hostage = { # Reason not shown in tooltip
				death = { death_reason = death_fight }
			}
		}
	}
	
	option = {
		name = {
			text = bp2_hostage_system.0301.a.killer
			trigger = {
				scope:hostage.killer ?= scope:hostage_warden
				NOT = {
					scope:hostage_warden = {
						any_secret = {
							type = secret_murder
							secret_target = scope:hostage
						}
					}
				}
			}
		}
		name = {
			text = bp2_hostage_system.0301.a.violent
			trigger = {
				scope:hostage = { had_gruesome_death_trigger = yes }
			}
		}
		name = {
			text = bp2_hostage_system.0301.a
			trigger = {
				NOR = {
					scope:hostage = { had_gruesome_death_trigger = yes }
					scope:hostage.killer ?= scope:hostage_warden
				}
			}
		}
	}
}

###
### INVALIDATION
###

scripted_trigger hostage_adopted_invalidation_trigger = {
	scope:hostage.house = scope:warden.house
	scope:hostage.house != scope:home_court.house
}

# Hostage no longer valid - warden
bp2_hostage_system.0400 = {
	type = character_event
	title = bp2_hostage_system.0400.t
	desc = {
		# HOSTAGE INVALID
		first_valid = {
			triggered_desc = { # Hostage inherited land
				trigger = {
					scope:reason ?= flag:ruler
					scope:hostage = { is_landed = yes }
				}
				desc = bp2_hostage_system.0400.landed_hostage
			}
			triggered_desc = { # Hostage inherited domicile
				trigger = { scope:reason ?= flag:ruler }
				desc = bp2_hostage_system.0400.ruler_hostage
			}
			triggered_desc = { # Hostage imprisoned by me
				trigger = {
					scope:reason ?= flag:imprisoner
					root = scope:imprisoner
				}
				desc = bp2_hostage_system.0400.imprisoned_hostage_self
			}
			triggered_desc = { # Hostage imprisoned
				trigger = { scope:reason ?= flag:imprisoner }
				desc = bp2_hostage_system.0400.imprisoned_hostage
			}
			triggered_desc = { # Hostage escaped imprisonment
				trigger = { exists = scope:imprison_failure }
				desc = bp2_hostage_system.0400.imprisoned_hostage_fail
			}
			triggered_desc = { # Adopted
				trigger = { hostage_adopted_invalidation_trigger = yes }
				desc = bp2_hostage_system.0400.adopted
			}
			triggered_desc = { # Home court no longer considers hostage important
				trigger = { scope:reason ?= flag:invalid }
				desc = bp2_hostage_system.0400.unrelated_hostage
			}
			# HOME COURT INVALID
			triggered_desc = {
				trigger = { scope:reason ?= flag:home_court }
				desc = {
					first_valid = {
						triggered_desc = { # Home court lost lands
							trigger = {
								scope:home_court = { is_alive = yes }
								exists = scope:lost_title
							}
							desc = bp2_hostage_system.0400.unlanded_home_court_title
						}
						triggered_desc = { # Home court lost lands
							trigger = {
								scope:home_court = { is_alive = yes }
							}
							desc = bp2_hostage_system.0400.unlanded_home_court
						}
						desc = bp2_hostage_system.0400.dead_home_court
					}
				}
			}
			# WARDEN INVALID
			triggered_desc = {
				trigger = { scope:reason ?= flag:warden }
				desc = {
					first_valid = {
						triggered_desc = { # Home court lost lands
							trigger = {
								scope:warden = { is_alive = yes }
								exists = scope:lost_title
							}
							desc = bp2_hostage_system.0400.unlanded_warden_title
						}
						desc = bp2_hostage_system.0400.unlanded_warden
					}
				}
			}
		}
		# RETURN FLAVOR
		first_valid = {
			triggered_desc = { # Hostage imprisoned by me
				trigger = {
					OR = {
						exists = scope:imprison_failure
						AND = {
							scope:reason ?= flag:imprisoner
							root = scope:imprisoner
						}
					}
				}
				desc = bp2_hostage_system.0400.imprisoned_self
			}
			triggered_desc = { # Hostage imprisoned
				trigger = { scope:reason ?= flag:imprisoner }
				desc = bp2_hostage_system.0400.imprisoned
			}
			triggered_desc = { # Hostage inherited
				trigger = { scope:reason ?= flag:ruler }
				desc = bp2_hostage_system.0400.ruler
			}
			triggered_desc = { # No heirs of warden to take over
				trigger = { hostage_adopted_invalidation_trigger = yes }
				desc = bp2_hostage_system.0400.adopted_stay
			}
			triggered_desc = { # Hostage family exists
				trigger = {
					scope:home_court = { is_alive = yes }
				}
				desc = bp2_hostage_system.0400.family
			}
			desc = bp2_hostage_system.0400.no_family
		}
		triggered_desc = {
			trigger = { exists = scope:my_hostage }
			desc = bp2_hostage_system.0400.my_hostage
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
		triggered_animation = {
			trigger = {
				scope:hostage.house = scope:warden.house
				scope:hostage.house != scope:home_court.house
			}
			animation = admiration
		}
	}
	right_portrait = {
		character = scope:hostage
		triggered_animation = {
			trigger = { scope:reason ?= flag:imprisoner }
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = { scope:reason ?= flag:ruler }
			animation = war_over_win
		}
		animation = happiness
	}
	lower_right_portrait = scope:home_court
	lower_center_portrait = scope:imprisoner
	lower_left_portrait = scope:my_hostage
	
	immediate = {
		scope:home_court = {
			random_in_list = {
				variable = invalidated_warden_hostages
				limit = { var:recently_invalidated_hostage ?= root }
				save_scope_as = my_hostage
			}
		}
		show_as_tooltip = {
			scope:hostage = { # Reason not shown in tooltip
				return_hostage = yes
			}
			scope:my_hostage ?= {
				return_hostage = yes
			}
		}
		if = {
			limit = { scope:reason ?= flag:ruler }
			scope:hostage.primary_title.previous_holder = { save_scope_as = previous_holder }
		}
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:home_court }
				save_scope_as = my_hostage
			}
		}
		if = {
			limit = {
				hostage_adopted_invalidation_trigger = yes
			}
			hidden_effect = {
				scope:hostage = { # Reason not shown in tooltip
					return_hostage = yes
				}
			}
			scope:warden = { add_courtier = scope:hostage }
		}
	}

	option = { # Go
		name = bp2_hostage_system.0400.a
		trigger = { hostage_adopted_invalidation_trigger = no }
	}

	option = { # Stay
		name = bp2_hostage_system.0400.b
		trigger = { hostage_adopted_invalidation_trigger = yes }
	}

	after = {
		scope:home_court = { trigger_event = bp2_hostage_system.0401 }
	}
}

# Hostage no longer valid - home court
bp2_hostage_system.0401 = {
	type = character_event
	title = bp2_hostage_system.0400.t
	desc = {
		# HOSTAGE INVALID
		first_valid = {
			triggered_desc = { # Hostage inherited
				trigger = {
					scope:reason = flag:ruler
					scope:hostage = { is_landed = yes }
				}
				desc = bp2_hostage_system.0401.landed_hostage
			}
			triggered_desc = { # Hostage inherited
				trigger = { scope:reason = flag:ruler }
				desc = bp2_hostage_system.0401.landed_hostage
			}
			triggered_desc = { # Hostage imprisoned by warden
				trigger = {
					scope:reason = flag:imprisoner
					scope:warden = scope:imprisoner
				}
				desc = bp2_hostage_system.0401.imprisoned_hostage_self
			}
			triggered_desc = { # Hostage imprisoned
				trigger = { scope:reason = flag:imprisoner }
				desc = bp2_hostage_system.0401.imprisoned_hostage
			}
			triggered_desc = { # Hostage escaped imprisonment by warden
				trigger = { exists = scope:imprison_failure }
				desc = bp2_hostage_system.0401.imprisoned_hostage_fail
			}
			triggered_desc = { # Adopted
				trigger = { hostage_adopted_invalidation_trigger = yes }
				desc = bp2_hostage_system.0401.adopted
			}
			triggered_desc = { # Home court no longer considers hostage important
				trigger = { scope:reason = flag:invalid }
				desc = bp2_hostage_system.0401.unrelated_hostage
			}
			# HOME COURT INVALID
			triggered_desc = {
				trigger = { scope:reason ?= flag:home_court }
				desc = {
					first_valid = {
						triggered_desc = { # Home court lost lands
							trigger = {
								scope:home_court = { is_alive = yes }
								exists = scope:lost_title
							}
							desc = bp2_hostage_system.0401.unlanded_home_court_title
						}
						desc = bp2_hostage_system.0401.unlanded_home_court
					}
				}
			}
			# WARDEN INVALID
			triggered_desc = {
				trigger = { scope:reason ?= flag:warden }
				desc = {
					first_valid = {
						triggered_desc = { # Home court lost lands
							trigger = {
								scope:warden = { is_alive = yes }
								exists = scope:lost_title
							}
							desc = bp2_hostage_system.0401.unlanded_warden_title
						}
						desc = bp2_hostage_system.0401.unlanded_warden
					}
				}
			}
		}
		# RETURN FLAVOR
		first_valid = {
			triggered_desc = { # Hostage imprisoned
				trigger = { scope:reason = flag:imprisoner }
				desc = bp2_hostage_system.0401.imprisoned
			}
			triggered_desc = { # Hostage imprisoned
				trigger = { exists = scope:imprison_failure }
				desc = bp2_hostage_system.0401.imprisoned_fail
			}
			triggered_desc = { # Hostage inherited
				trigger = { scope:reason = flag:ruler }
				desc = bp2_hostage_system.0400.ruler
			}
			triggered_desc = { # No heirs of warden to take over
				trigger = { hostage_adopted_invalidation_trigger = yes }
				desc = bp2_hostage_system.0401.adopted_stay
			}
			triggered_desc = { # Hostage family exists
				trigger = {
					scope:home_court = { is_alive = yes }
				}
				desc = bp2_hostage_system.0400.family
			}
			desc = bp2_hostage_system.0400.no_family
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = scope:warden
		animation = worry
		triggered_animation = {
			trigger = {
				scope:hostage.house = scope:warden.house
				scope:hostage.house != scope:home_court.house
			}
			animation = admiration
		}
	}
	right_portrait = {
		character = scope:hostage
		triggered_animation = {
			trigger = { scope:reason = flag:imprisoner }
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = { scope:reason = flag:ruler }
			animation = war_over_win
		}
		animation = happiness
	}
	lower_center_portrait = scope:imprisoner
	lower_left_portrait = scope:my_hostage
	
	trigger = {
		NOT = { exists = scope:my_hostage }
	}

	immediate = {
		show_as_tooltip = {
			scope:hostage = { # Reason not shown in tooltip
				return_hostage = yes
			}
		}
		scope:home_court = { save_scope_as = bg_override_char }
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:home_court }
				save_scope_as = my_hostage
			}
		}
		if = {
			limit = {
				hostage_adopted_invalidation_trigger = yes
			}
			show_as_tooltip = {
				scope:warden = { add_courtier = scope:hostage }
			}
		}
	}

	option = { # Go
		name = bp2_hostage_system.0401.a
		trigger = { hostage_adopted_invalidation_trigger = no }
	}

	option = { # Stay
		name = bp2_hostage_system.0401.b
		trigger = { hostage_adopted_invalidation_trigger = yes }
	}
}

# Hostage no longer valid - hostage
bp2_hostage_system.0402 = {
	type = character_event
	title = bp2_hostage_system.0400.t
	orphan = yes
	desc = {
		# HOSTAGE INVALID
		desc = bp2_hostage_system.0402.inherited
		# RETURN FLAVOR
		first_valid = {
			triggered_desc = { # Hostage family exists
				trigger = {
					scope:home_court = { is_alive = no }
				}
				desc = bp2_hostage_system.0402.dead
			}
		}
	}
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = scope:hostage
		animation = worry
	}
	right_portrait = {
		character = scope:warden
		animation = dismissal
	}
	lower_center_portrait = scope:home_court
	
	immediate = {
		show_as_tooltip = {
			scope:hostage = { # Reason not shown in tooltip
				return_hostage = yes
			}
		}
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:home_court }
				save_scope_as = my_hostage
			}
		}
	}

	option = {
		name = bp2_hostage_system.0401.a
	}
}

# Hostage home court changes - warden
bp2_hostage_system.0410 = {
	type = character_event
	title = bp2_hostage_system.0410.t
	desc = bp2_hostage_system.0410.desc
	theme = hostage
	override_background = { reference = relaxing_room }
	left_portrait = {
		character = root
		animation = worry
	}
	right_portrait = {
		character = scope:hostage
		animation = pain
	}
	lower_right_portrait = scope:home_court
	lower_left_portrait = scope:my_hostage
	
	trigger = {
		is_landed_or_landless_administrative = yes
	}
	
	immediate = {
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:home_court }
				save_scope_as = my_hostage
			}
		}
	}

	option = {
		name = bp2_hostage_system.0410.a
		trigger = { exists = scope:my_hostage }
		save_scope_as = both_returned
		scope:home_court = {
			trigger_event = { id = bp2_hostage_system.0411 days = 1 }
		}
		show_as_tooltip = {
			scope:my_hostage = { return_hostage = yes }
			scope:hostage = { return_hostage = yes }
		}
	}

	option = {
		name = bp2_hostage_system.0410.b
		trigger = { exists = scope:my_hostage }
		save_scope_as = my_hostage_returned
		scope:home_court = {
			trigger_event = { id = bp2_hostage_system.0411 days = 1 }
		}
		show_as_tooltip = {
			scope:my_hostage = { return_hostage = yes }
		}
	}

	option = {
		name = bp2_hostage_system.0410.c
		save_scope_as = hostage_returned
		scope:home_court = {
			trigger_event = { id = bp2_hostage_system.0411 days = 1 }
		}
		show_as_tooltip = {
			scope:hostage = { return_hostage = yes }
		}
	}

	option = {
		name = bp2_hostage_system.0410.d
	}
}

# Hostage home court changes - home court
bp2_hostage_system.0411 = {
	type = letter_event
	opening = { desc = bp2_hostage_system.0411.opening }
	desc = {
		desc = bp2_hostage_system.0411.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:my_hostage_returned }
				desc = bp2_hostage_system.0411.my_hostage
			}
			triggered_desc = {
				trigger = { exists = scope:both_returned }
				desc = bp2_hostage_system.0411.both
			}
			desc = bp2_hostage_system.0411.hostage
		}
	}
	sender = scope:warden

	immediate = {
		if = {
			limit = { exists = scope:my_hostage_returned }
			bp2_return_hostage_effect = { HOSTAGE = scope:my_hostage }
		}
		else_if = {
			limit = { exists = scope:both_returned }
			bp2_return_hostage_effect = { HOSTAGE = scope:my_hostage }
			bp2_return_hostage_effect = { HOSTAGE = scope:hostage }
		}
		else = {
			bp2_return_hostage_effect = { HOSTAGE = scope:hostage }
		}
	}

	option = {
		name = bp2_hostage_system.0411.a
	}
}

###
### TRAVEL
###

# Hostage arrives at warden's court - warden
bp2_hostage_system.0500 = {
	type = character_event
	title = bp2_hostage_system.0500.t
	desc = {
		desc =  bp2_hostage_system.0500.desc
		triggered_desc = {
			trigger = { scope:hostage.age >= 6 }
			desc = bp2_hostage_system.0500.anxious
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					location = root.capital_province
					scope:hostage.age >= 6
				}
				desc = bp2_hostage_system.0500.home
			}
			desc = bp2_hostage_system.0500.away
		}
	}
	theme = hostage
	override_background = { reference = courtyard }
	left_portrait = {
		character = root
		animation = war_over_tie
		trigger =  { location = root.capital_province }
	}
	right_portrait = {
		character = scope:hostage
	}
	lower_right_portrait = scope:hostage_home_court
	lower_left_portrait = scope:my_hostage
	
	immediate = {
		if = {
			limit = {
				any_home_court_hostage = { warden ?= scope:hostage_home_court }
			}
			random_home_court_hostage = {
				limit = { warden ?= scope:hostage_home_court }
				save_scope_as = my_hostage
			}
		}
		show_as_tooltip = {
			scope:hostage_warden = { take_hostage = scope:hostage }
		}
		scope:hostage_home_court = {
			if = { # Hostage's letter
				limit = { scope:hostage.age >= 10 }
				trigger_event = { id = bp2_hostage_system.0501 }
			}
			else = { # Warden's letter
				trigger_event = { id = bp2_hostage_system.0502 }
			}
		}
	}

	option = {
		name = {
			trigger = {
				location = root.capital_province
				scope:hostage.age >= 6
			}
			text = bp2_hostage_system.0500.a.home
		}
		name = {
			trigger = {
				OR = {
					location != root.capital_province
					scope:hostage.age < 6
				}
			}
			text = bp2_hostage_system.0500.a
		}
	}
}

# Hostage arrives at warden's court - home_court
bp2_hostage_system.0501 = {
	type = letter_event
	opening = bp2_hostage_system.0501.opening
	desc = {
		desc = bp2_hostage_system.0501.desc
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:alone }
				desc = bp2_hostage_system.0501.child_alone
			}
			triggered_desc = {
				trigger = {
					scope:hostage = { is_adult = no }
				}
				desc = bp2_hostage_system.0501.child
			}
			desc = bp2_hostage_system.0501.adult
		}
	}
	sender = scope:hostage
	
	immediate = {
		scope:hostage_warden = { take_hostage = scope:hostage }
		if = {
			limit = {
				scope:hostage = { is_adult = no }
				scope:hostage_warden = {
					any_courtier_or_guest = {
						count = 0
						this != scope:hostage
						is_adult = no
					}
				}
			}
			save_scope_as = alone
		}
	}

	option = {
		name = {
			trigger = { exists = scope:alone }
			text = bp2_hostage_system.0501.a.child_alone
		}
		name = {
			trigger = {
				scope:hostage = { is_adult = no }
			}
			text = bp2_hostage_system.0501.a.child
		}
		name = {
			trigger = {
				scope:hostage = { is_adult = yes }
			}
			text = bp2_hostage_system.0501.a
		}
	}
}

# Hostage arrives at warden's court - home_court
bp2_hostage_system.0502 = {
	type = letter_event
	opening = bp2_hostage_system.0502.opening
	desc = bp2_hostage_system.0502.desc
	sender = scope:hostage_warden
	
	immediate = {
		scope:hostage_warden = { take_hostage = scope:hostage }
	}

	option = {
		name = bp2_hostage_system.0502.a
	}
}

# Hostage arrives home - home court
bp2_hostage_system.0510 = {
	type = character_event
	title = bp2_hostage_system.0203.t
	desc = {
		desc = bp2_hostage_system.0510.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:hostage.var:short_hostage_duration }
				desc = bp2_hostage_system.0510.duration_short
			}
			triggered_desc = {
				trigger = { exists = scope:hostage.var:long_hostage_duration }
				desc = bp2_hostage_system.0510.duration_long
			}
			desc = bp2_hostage_system.0510.duration
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					location = root.capital_province
					scope:hostage.age >= 3
				}
				desc = bp2_hostage_system.0510.home
			}
			desc = bp2_hostage_system.0510.away
		}
	}
	theme = hostage
	override_background = { reference = courtyard }
	left_portrait = {
		character = root
		animation = admiration
		trigger =  { location = root.capital_province }
	}
	right_portrait = {
		character = scope:hostage
		animation = war_over_win
	}
	lower_right_portrait = scope:hostage_warden
	lower_left_portrait = scope:my_hostage
	
	trigger = {
		OR = {
			exists = scope:hostage_warden
			exists = scope:warden
		}
	}
	
	immediate = {
		if = {
			limit = {
				exists = scope:warden
			}
			scope:warden = { save_scope_as = hostage_warden }
		}
		if = {
			limit = {
				any_warden_hostage = { home_court ?= scope:hostage_warden }
			}
			random_warden_hostage = {
				limit = { home_court ?= scope:hostage_warden }
				save_scope_as = my_hostage
			}
		}
		show_as_tooltip = { bp2_return_hostage_effect = { HOSTAGE = scope:hostage } }
	}

	option = {
		name = bp2_hostage_system.0201.a
	}

	after = {
		scope:hostage = {
			remove_variable = short_hostage_duration
			remove_variable = long_hostage_duration
			remove_variable = hostage_duration
		}
	}
}

