﻿#Interactions relating to hostages

### Offer hostage - unilateral
# actor = offerer
# recipient = receiver
# secondary_actor = hostage
gpt_ai_offer_hostage_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes
	pause_on_receive = yes
	icon = icon_hostage

	populate_actor_list = {
		scope:actor = {
			every_close_family_member = {
				limit = {
					# Unlanded, at sender's court, child/sibling/nibling/grandchild
					bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:actor }
				}
				add_to_list = characters
			}
		}
	}

	desc = offer_hostage_interaction_desc
	
	prompt = OFFER_HOSTAGE_SELECT_HOSTAGE_TO_TRANSFER

	notification_text = OFFER_HOSTAGE_PROPOSAL

	cooldown_against_recipient = { years = 3 }

	is_shown = {
		scope:actor = { is_ai = yes }
		# Cannot exchange hostages with self
		NOT = { scope:recipient = scope:actor }
		# Only significant rulers use hostages
		scope:actor.highest_held_title_tier > 1
		scope:recipient.highest_held_title_tier > 2
		# Laamps can't do anything with hostages but return/recall them.
		NOR = {
			scope:actor = { is_landless_adventurer = yes }
			scope:recipient = { is_landless_adventurer = yes }
		}
	}

	is_valid_showing_failures_only = {
		# Must be available
		scope:recipient = { basic_is_available_ai = yes }
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { basic_is_available_ai = yes }
		}
		NOR = {
			# Must be at peace 
			scope:recipient = { is_at_war_with = scope:actor }
			# Allies don't need hostages
			scope:recipient = { is_allied_to = scope:actor }
			# Only family oriented governments use hostages
			scope:actor = {
				government_has_flag = government_is_theocracy
			}
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
			# 1 hostage per home court
			custom_tooltip = {
				text = "already_has_your_hostage_tt"
				scope:recipient = {
					any_warden_hostage = { home_court ?= scope:actor }
				}
			}
			custom_description = {
				text = hostage_already_travelling_tt
				subject = scope:actor
				object = scope:recipient
				scope:actor = {
					any_close_family_member = {
						exists = var:hostage_travelling_to_warden
						var:hostage_travelling_to_warden = scope:recipient
					}
				}
			}
		}
		scope:actor = {
			OR = {
				is_landless_ruler = no
				is_landless_administrative = yes
			}
		}
		scope:recipient = {
			OR = {
				is_landless_ruler = no
				is_landless_administrative = yes
			}
		}
		# Stop AI spamming hostage offers
		trigger_if = {
			limit = {
				scope:actor = { is_ai = yes }
				exists = scope:secondary_actor
			}
			NOT = {
				scope:secondary_actor = { has_character_flag = ai_should_not_offer_hostage }
			}
			NOT = { scope:secondary_actor = { is_primary_heir_of = scope:actor } }
		}
		# Tooltip for players in case of no valid hostages to offer
		trigger_else = {
			scope:actor = {
				custom_description = {
					text = "basic_valid_hostage_to_offer"
					object = scope:recipient
					any_close_family_member = {
						# Unlanded, at sender's court, child/sibling/nibling/grandchild
						bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:actor }
					}
				}
			}
		}
		# Hostages still valid
		trigger_if = {
			limit = {
				exists = scope:secondary_actor
				exists = scope:actor
			}
			scope:secondary_actor = {
				bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:actor }
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:actor
			TARGET = scope:recipient
		}
	}
	
	can_be_picked = {
		# Unlanded, at sender's court, child/sibling/nibling/grandchild
		bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:actor }
		# Under offer
		custom_tooltip = {
			text = hostage_already_offered_awaiting_response_tt
			NOT = { has_character_flag = under_offer_as_hostage_flag }
		}
		# Already offered
		custom_tooltip = {
			text = hostage_already_offered_awaiting_response_tt
			NOT = { exists = var:hostage_travelling_to_warden }
		}
	}

	can_send = {
		scope:actor = { # AI only offer to more powerful neighbors
			trigger_if = {
				limit = { is_ai = yes }
				bp2_valid_to_offer_hostage_ai_trigger = yes
				# AI should not offer close family of players without their consent
				NOR = {
					scope:secondary_actor = {
						any_close_family_member = {
							is_ai = no
							OR = {
								is_parent_of = scope:secondary_actor
								is_grandparent_of = scope:secondary_actor
							}
							NOT = { this = scope:actor }
						}
					}
					# A hostage died on their watch
					var:hostage_died ?= scope:recipient
				}
			}
		}
		scope:recipient = {
			trigger_if = {
				limit = { is_ai = no }
				NOT = {
					scope:secondary_actor = { has_character_flag = ai_should_not_offer_hostage }
				}
				NOT = { scope:secondary_actor = { is_primary_heir_of = scope:actor } }
			}
		}
		# Adult hostages must be loyal enough to go along with it
		scope:secondary_actor = {
			trigger_if = {
				limit = { is_adult = yes }
				OR = {
					AND = {
						custom_tooltip = {
							text = hostage_opinion_too_low_tt
							opinion = {
								target = scope:actor
								value >= -25
							}
						}
						NOT = { has_trait = disloyal }
					}
					has_trait = loyal
				}
			}
			# Under offer
			custom_tooltip = {
				text = hostage_already_offered_awaiting_response_tt
				NOT = { has_character_flag = under_offer_as_hostage_flag }
			}
		}
	}

	cost = {}

	on_send = {
		scope:secondary_actor = {
			add_character_flag = {
				flag = under_offer_as_hostage_flag
				months = 1
			}
		}
		if = {
			limit = {
				scope:recipient = { is_ai = no }
			}
			hidden_effect = {
				scope:secondary_actor = {
					add_character_flag = {
						flag = ai_should_not_offer_hostage
						years = 3
					}
				}
			}
		}
	}
	
	on_accept = {
		# Save scopes for clarity
		scope:actor = { save_scope_as = hostage_sender }
		scope:secondary_actor = { save_scope_as = hostage }
		scope:recipient = { save_scope_as = hostage_taker }
		custom_description_no_bullet = { text = hostage_pacts_on_arrival_tt }
		custom_description_no_bullet = { text = hostage_execution_warning_tt }
		custom_description_no_bullet = { text = hostage_attack_warning_tt }
		hostage_depart_effect = {
			HOSTAGE = scope:hostage
			WARDEN = scope:hostage_taker
			HOME_COURT = scope:hostage_sender
		}
		scope:actor = { trigger_event = char_interaction.0330 }
		# If we're of the same clan this interaction affects unity
		if = {
			limit = {
				scope:actor = { government_has_flag = government_is_clan }
				scope:actor.house = scope:recipient.house
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = medium_unity_loss
				DESC = clan_unity_hostage.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}

	on_decline = {
		scope:actor = {
			trigger_event = char_interaction.0300
		}
		scope:secondary_actor = { remove_character_flag = under_offer_as_hostage_flag }
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}

	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = { target = scope:actor }
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	# AI
	ai_accept = {
		base = 0 # Try to make it 0 for most interactions
		
		######### PERSONALITY

		bp2_hostage_offer_personality_modifier = yes

		######### OPINION

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}

		######### RELATIONS

		bp2_hostage_relation_modifier = yes
		
		######### DREAD

		bp2_hostage_dread_modifier = yes

		######### HOSTAGE IMPORTANCE
		
		# Hostages
		modifier = {
			exists = scope:secondary_actor
			add = interaction_actor_hostage_value
			desc = HOSTAGE_VALUE_ACTOR_REASON
		}

		######### RELATIVE POWER

		bp2_hostage_tier_neighbor_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_claims_casus_bellis_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_vassals_lieges_modifier = { # Political situation
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_relative_strength_modifier = { # Relative military strength
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}

		######### CULTURAL DIFFERENCES

		bp2_hostage_culture_faith_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}

		######### CULTURAL TRADITIONS

		modifier = {
			scope:recipient.culture = { has_cultural_tradition = tradition_equitable }
			add = 25
			desc = HOSTAGE_EQUITABLE_TRADITION_REASON
		}
		modifier = {
			scope:recipient.culture = { has_cultural_tradition = tradition_esteemed_hospitality }
			add = 25
			desc = HOSTAGE_ESTEEMED_HOSPITALITY_TRADITION_REASON
		}
		modifier = {
			scope:recipient = {
				is_vassal_of = scope:actor
				culture = { has_cultural_tradition = tradition_loyal_soldiers }
			}
			add = 25
			desc = HOSTAGE_LOYAL_SUBJECTS_TRADITION_REASON
		}

		######### OTHER

		modifier = { # Already have a truce
			scope:recipient ?= { has_truce = scope:actor }
			desc = HOSTAGE_RECIPIENT_EXISTING_TRUCE_REASON
			add = -20
		}
		modifier = { # Already fighting a war
			scope:recipient ?= { is_at_war = yes }
			desc = HOSTAGE_AT_WAR_REASON
			add = 15
		}
		modifier = { # Already have their hostage
			scope:actor = {
				any_warden_hostage = { home_court ?= scope:recipient }
			}
			desc = HOSTAGE_ALREADY_DEMANDED_REASON
			add = 50
		}
		modifier = {
			add = -50
			scope:actor = { has_character_modifier = attacked_warden }
			desc = attacked_warden
		}
		modifier = { # Conqueror
			scope:recipient ?= {
				ai_has_conqueror_personality = yes
			}
			desc = NO_FRIVOLOUS_ACTIVITIES_REASON
			add = -1000
		}
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 20
	}

	ai_frequency = 36 #120

	ai_potential = {
		highest_held_title_tier >= tier_county
		ai_has_conqueror_personality = no
	}

	ai_will_do = {
		base = -50
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Opinion Factor
			who = scope:actor
			opinion_target = scope:secondary_actor
			multiplier = -0.1
			desc = AI_OPINION_REASON
		}
		bp2_hostage_tier_neighbor_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_claims_casus_bellis_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_vassals_lieges_modifier = { # Political situation
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_relative_strength_modifier = { # Relative military strength
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_culture_faith_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		modifier = { # Attacked a hostage's home court
			add = -50
			scope:recipient = { has_character_modifier = attacked_home_court }
			desc = attacked_home_court
		}
		modifier = { # Hostage died on their watch
			exists = scope:actor.var:hostage_died
			scope:recipient = {
				NOR = {
					var:let_my_hostage_die ?= scope:actor
					has_opinion_modifier = {
						target = scope:actor
						modifier = killed_hostage_opinion
					}
				}
			}
			desc = HOSTAGE_PREVIOUSLY_DIED_REASON
			add = -25
		}
		modifier = { # MY Hostage died on their watch
			scope:recipient = {
				var:let_my_hostage_die ?= scope:actor
				NOT = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = killed_hostage_opinion
					}
				}
			}
			desc = HOSTAGE_PREVIOUSLY_DIED_HOME_COURT_REASON
			add = -100
		}
		modifier = { # Killed my hostage!!!
			scope:recipient = {
				has_opinion_modifier = {
					target = scope:actor
					modifier = killed_hostage_opinion
				}
			}
			desc = HOSTAGE_KILLED_REASON
			add = -200
		}
		modifier = { # Not neighboring
			NOR = {
				scope:recipient = {
					character_is_land_realm_neighbor = scope:actor
					top_liege = scope:actor.top_liege
				}
			}
			add = -50
		}
		modifier = {
			scope:recipient = { has_character_flag = halved_hostage_prestige_income }
			desc = HOSTAGE_RETAINED_ADULTHOOD_REASON
			add = -25
		}
		# Cultural traditions
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_equitable }
			add = 25
		}
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_esteemed_hospitality }
			add = 25
		}
		modifier = {
			scope:actor = {
				is_vassal_of = scope:recipient
				culture = { has_cultural_tradition = tradition_loyal_soldiers }
			}
			add = 25
			desc = HOSTAGE_CULTURAL_TRADITION_REASON
		}


		modifier = {
			add = 1000
			scope:actor = {
				is_independent_ruler = yes
				ai_boldness < 40
				ai_rationality > -20
				any_neighboring_and_across_water_top_liege_realm_owner = {
					this = scope:recipient
				}
				OR = {
					max_military_strength < scope:recipient.eighty_percent_of_max_military_strength
					AND = {
						ai_boldness < 0
						max_military_strength < scope:recipient.fifty_percent_of_current_military_strength
					}
				}
			}
			scope:recipient = {
				is_independent_ruler = yes
			}
		}

		modifier = {
			add = 1000
			scope:actor = {
				is_independent_ruler = no
				top_liege = scope:recipient.top_liege
				ai_boldness < 40
				ai_rationality > -20
				any_neighboring_realm_same_rank_owner = {
					this = scope:recipient
				}
				OR = {
					max_military_strength < scope:recipient.eighty_percent_of_max_military_strength
					AND = {
						ai_boldness < 0
						max_military_strength < scope:recipient.fifty_percent_of_current_military_strength
					}
				}
			}
			scope:recipient = {
				is_independent_ruler = no
			}
		}
	}
}

### Demand hostage - unilateral
# actor = receiver
# recipient = offerer
# secondary_recipient = hostage
gpt_ai_demand_hostage_interaction = {
	category = interaction_category_diplomacy
	common_interaction = no
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	popup_on_receive = yes
	pause_on_receive = yes
	icon = icon_hostage

	desc = demand_hostage_interaction_desc
	
	prompt = DEMAND_HOSTAGE_SELECT_HOSTAGE_TO_OFFER

	notification_text = DEMAND_HOSTAGE_PROPOSAL

	populate_recipient_list = {
		scope:recipient = {
			every_close_family_member = {
				limit = {
					# Unlanded, at sender's court, child/sibling/nibling/grandchild
					bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:recipient }
				}
				add_to_list = characters
			}
		}
	}

	cooldown_against_recipient = { years = 3 } 

	is_shown = {
		scope:actor = { is_ai = yes }
		# Cannot exchange hostages with self
		NOT = { scope:recipient = scope:actor }
		# Only significant rulers use hostages
		scope:actor.highest_held_title_tier > 2
		OR = {
			scope:recipient.highest_held_title_tier > tier_barony
			scope:recipient.liege ?= {
				highest_held_title_tier > 1
				any_close_family_member = {
					this = scope:recipient
					# Unlanded, at sender's court, child/sibling/nibling/grandchild
					bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:recipient.liege }
				}
			}
		}
		# Laamps can't do anything with hostages but return/recall them.
		NOR = {
			scope:actor = { is_landless_adventurer = yes }
			scope:recipient = { is_landless_adventurer = yes }
		}
	}

	redirect = {
		if = {
			limit = {
				scope:recipient ?= {
					is_playable_character = no
					is_landless_ruler = no
				}
			}
			scope:recipient ?= { save_scope_as = secondary_recipient }
			scope:secondary_recipient.liege ?= { save_scope_as = recipient }
		}
	}

	is_valid_showing_failures_only = {
		# Must be available
		scope:recipient = { basic_is_available_ai = yes }
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { basic_is_available_ai = yes }
		}
		# Must be approachable
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
		}
		scope:actor = {
			OR = {
				is_landless_ruler = no
				is_landless_administrative = yes
			}
		}
		scope:recipient = {
			OR = {
				is_landless_ruler = no
				is_landless_administrative = yes
			}
		}
		NOR = {
			# Must be at peace 
			scope:recipient = { is_at_war_with = scope:actor }
			# Allies don't need hostages
			scope:recipient = { is_allied_to = scope:actor }
			# Only family oriented governments use hostages
			scope:actor = {
				government_has_flag = government_is_theocracy
			}
			scope:recipient = {
				government_has_flag = government_is_theocracy
			}
			# 1 hostage per court
			custom_tooltip = {
				text = "already_have_their_hostage_tt"
				scope:actor = {
					any_warden_hostage = { home_court ?= scope:recipient }
				}
			}
			custom_description = {
				text = "hostage_already_travelling_tt"
				subject = scope:actor
				object = scope:recipient
				scope:actor = {
					any_close_family_member = {
						exists = var:hostage_travelling_to_warden
						var:hostage_travelling_to_warden = scope:recipient
					}
				}
			}
		}
		# Stop AI spamming hostage offers
		trigger_if = {
			limit = {
				scope:recipient = { is_ai = yes }
				exists = scope:secondary_recipient
			}
			NOT = {
				scope:secondary_recipient = { has_character_flag = ai_should_not_demand_hostage }
			}
			NOT = { scope:secondary_recipient = { is_primary_heir_of = scope:recipient } }
		}
		# Tooltip for players in case of no valid hostages to demand
		# Make sure this exactly matches "can_be_picked" section below
		trigger_else = {
			scope:recipient = {
				custom_description = {
					text = "basic_valid_hostage_to_demand"
					subject = scope:actor
					object = scope:recipient
					any_close_family_member = {
						# Unlanded, at sender's court, child/sibling/nibling/grandchild
						bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:recipient }
					}
				}
			}
		}
		# Hostages still valid
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
				exists = scope:recipient
			}
			scope:secondary_recipient = {
				bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:recipient }
			}
		}
		tgp_blocked_action_against_tenno_trigger = {
			ACTOR = scope:actor
			TARGET = scope:recipient
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			trigger_if = { # AI only demand from less powerful neighbors
				limit = { is_ai = yes }
				bp2_valid_to_demand_hostage_ai_trigger = yes
				NOR = {
					scope:secondary_recipient ?= { has_character_flag = ai_should_not_demand_hostage }
					scope:secondary_recipient = { is_primary_heir_of = scope:recipient }
					# AI should not demand close family of players without their consent
					scope:secondary_recipient = {
						any_close_family_member = {
							is_ai = no
							OR = {
								is_parent_of = scope:secondary_recipient
								is_grandparent_of = scope:secondary_recipient
							}
							NOT = { this = scope:recipient }
						}
					}
					# A hostage died on their watch
					var:hostage_died ?= scope:recipient
				}
			}
		}
		# Adult hostages must be loyal enough to go along with it
		scope:secondary_recipient = {
			trigger_if = {
				limit = { is_adult = yes }
				OR = {
					AND = {
						custom_tooltip = {
							text = hostage_opinion_too_low_tt
							opinion = {
								target = scope:recipient
								value >= -25
							}
							NOT = { has_trait = disloyal }
						}
					}
					has_trait = loyal
				}
			}
			custom_tooltip = {
				text = hostage_already_offered_awaiting_response_tt
				NOT = { has_character_flag = under_offer_as_hostage_flag }
			}
		}
	}
	
	can_be_picked = {
		# Unlanded, at sender's court, child/sibling/nibling/grandchild
		bp2_valid_to_offer_as_hostage_trigger = { SENDER = scope:recipient }
		# Already offered
		custom_tooltip = {
			text = hostage_already_offered_awaiting_response_tt
			NOT = { has_character_flag = under_offer_as_hostage_flag }
		}
		# Already offered
		custom_tooltip = {
			text = hostage_already_offered_awaiting_response_tt
			NOT = { exists = var:hostage_travelling_to_warden }
		}
	}

	cost = {}

	on_send = {
		scope:secondary_recipient = {
			add_character_flag = {
				flag = under_offer_as_hostage_flag
				months = 1
			}
		}
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
		if = {
			limit = {
				scope:recipient = { is_ai = no }
			}
			scope:secondary_recipient = {
				add_character_flag = {
					flag = ai_should_not_demand_hostage
					years = 3
				}
			}
		}
	}

	on_accept = {
		# Save scopes for clarity
		scope:actor = { save_scope_as = hostage_taker }
		scope:recipient = { save_scope_as = hostage_sender }
		scope:secondary_recipient = { save_scope_as = hostage }
		custom_description_no_bullet = { text = hostage_pacts_on_arrival_tt }
		custom_description_no_bullet = { text = hostage_execution_warning_tt }
		custom_description_no_bullet = { text = hostage_attack_warning_tt }
		hostage_depart_effect = {
			HOSTAGE = scope:hostage
			WARDEN = scope:hostage_taker
			HOME_COURT = scope:hostage_sender
		}
		show_as_tooltip = {
			if = {
				limit = {
					scope:recipient = { is_vassal_of = scope:actor }
				}
				scope:recipient = {
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							modifier = liege_demanded_hostage_opinion
							target = scope:actor
						}
					}
				}
				scope:actor = {
					# Tyranny for demanding from vassals
					add_tyranny = minor_tyranny_gain
				}
			}
		}
		scope:actor = { trigger_event = char_interaction.0331 }
		# If we're of the same clan this interaction affects unity
		if = {
			limit = {
				scope:actor = { government_has_flag = government_is_clan }
				scope:actor.house = scope:recipient.house
			}
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:actor
				TARGET = scope:recipient
				VALUE = minor_unity_loss
				DESC = clan_unity_hostage.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
		}
	}

	on_decline = {
		show_as_tooltip = {
			if = { # Effects for refusing demand from liege
				limit = {
					scope:recipient = { is_vassal_of = scope:actor }
				}
				scope:recipient = {
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							modifier = liege_demanded_hostage_opinion
							target = scope:actor
						}
					}
				}
				scope:actor = {
					# Tyranny for demanding from vassals
					add_tyranny = minor_tyranny_gain
					if = {
						limit = { is_ai = yes }
						add_opinion = {
							modifier = vassal_refused_hostage_demand_opinion
							target = scope:recipient
						}
					}
				}
			}
		}
		scope:actor = {
			trigger_event = char_interaction.0301
		}
		scope:secondary_recipient = { remove_character_flag = under_offer_as_hostage_flag }
	}

	auto_accept = {
		trigger_if = {
			limit = {
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook ?= yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
		trigger_else = { always = no }
	}
	
	can_be_blocked = {
		custom_description = { #Hook from Recipient can counteract, but only if Actor is not forcing the action via Strong Hook.
			text = "spending_hook"
			subject = scope:recipient
			object = scope:actor
			scope:recipient = { has_hook = scope:actor }
			NAND = {
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	on_blocked_effect = {
		scope:recipient = {
			remove_hook = { target = scope:actor }
		}
	}

	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no
	
	# AI
	ai_accept = {
		base = 0
		
		######### PERSONALITY

		bp2_hostage_demand_personality_modifier = yes

		######### OPINION

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:secondary_recipient
			multiplier = -0.1
			desc = AI_OPINION_REASON
		}

		######### RELATIONS

		bp2_hostage_relation_modifier = yes

		######### DREAD

		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}

		######### HOSTAGE IMPORTANCE
		
		modifier = {
			exists = scope:secondary_recipient
			add = interaction_recipient_hostage_value
			desc = HOSTAGE_VALUE_RECIPIENT_REASON
		}

		######### RELATIVE POWER

		bp2_hostage_tier_neighbor_modifier = { # Realm relative position
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_claims_casus_bellis_modifier = { # Desire for land/war
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_vassals_lieges_modifier = { # Political situation
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_relative_strength_modifier = { # Relative military strength
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		modifier = {
			desc = HOSTAGE_IMMINENT_THREAT_REASON
			scope:actor = { has_any_cb_on = scope:recipient }
			scope:actor.current_strength_with_allies_fifty_percent_value > scope:recipient.current_strength_with_allies_value
			add = 25
		}

		######### CULTURAL DIFFERENCES

		bp2_hostage_culture_faith_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}

		######### CULTURAL TRADITIONS

		modifier = {
			scope:recipient.culture = { has_cultural_tradition = tradition_equitable }
			add = 25
			desc = HOSTAGE_EQUITABLE_TRADITION_REASON
		}
		modifier = {
			scope:recipient.culture = { has_cultural_tradition = tradition_esteemed_hospitality }
			add = 25
			desc = HOSTAGE_ESTEEMED_HOSPITALITY_TRADITION_REASON
		}
		modifier = {
			scope:recipient = {
				is_vassal_of = scope:actor
				culture = { has_cultural_tradition = tradition_loyal_soldiers }
			}
			add = 25
			desc = HOSTAGE_LOYAL_SUBJECTS_TRADITION_REASON
		}

		######### OTHER

		modifier = { # Hostage died on their watch
			exists = scope:actor.var:hostage_died
			scope:recipient = {
				NOR = {
					var:let_my_hostage_die ?= scope:actor
					has_opinion_modifier = {
						target = scope:actor
						modifier = killed_hostage_opinion
					}
				}
			}
			desc = HOSTAGE_PREVIOUSLY_DIED_REASON
			add = -25
		}
		modifier = { # MY Hostage died on their watch
			scope:recipient = {
				var:let_my_hostage_die ?= scope:actor
				NOT = {
					has_opinion_modifier = {
						target = scope:actor
						modifier = killed_hostage_opinion
					}
				}
			}
			desc = HOSTAGE_PREVIOUSLY_DIED_HOME_COURT_REASON
			add = -100
		}
		modifier = { # Killed my hostage!!!
			scope:recipient = {
				has_opinion_modifier = {
					target = scope:actor
					modifier = killed_hostage_opinion
				}
			}
			desc = HOSTAGE_KILLED_REASON
			add = -200
		}
		modifier = { # Already have a truce
			scope:actor ?= { has_truce = scope:recipient }
			desc = HOSTAGE_ACTOR_EXISTING_TRUCE_REASON
			add = -20
		}
		modifier = { # Already fighting a war
			scope:recipient ?= { is_at_war = yes }
			desc = HOSTAGE_AT_WAR_REASON
			add = 15
		}
		modifier = { # Already have your hostage
			scope:recipient = {
				any_warden_hostage = { home_court ?= scope:actor }
			}
			desc = HOSTAGE_ALREADY_OFFERED_REASON
			add = 50
		}
		modifier = { # Attacked a hostage's home court
			add = -50
			scope:actor = { has_character_modifier = attacked_home_court }
			desc = attacked_home_court
		}
		modifier = {
			scope:hook = yes
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
		}
		modifier = {
			scope:secondary_recipient ?= { is_adult = no }
			scope:actor = { has_character_flag = halved_hostage_prestige_income }
			desc = HOSTAGE_RETAINED_ADULTHOOD_REASON
			add = -25
		}
		modifier = { # Conqueror
			scope:recipient ?= {
				ai_has_conqueror_personality = yes
			}
			desc = NO_FRIVOLOUS_ACTIVITIES_REASON
			add = -1000
		}
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 20
	}

	ai_frequency = 36 #120

	ai_potential = {
		highest_held_title_tier >= tier_county
		ai_has_conqueror_personality = no
	}

	ai_will_do = {
		base = -50
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		bp2_hostage_tier_neighbor_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_claims_casus_bellis_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_vassals_lieges_modifier = { # Political situation
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_relative_strength_modifier = { # Relative military strength
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		bp2_hostage_culture_faith_modifier = {
			SENDER = scope:actor
			RECEIVER = scope:recipient
		}
		modifier = {
			add = -50
			scope:recipient = { has_character_modifier = attacked_warden }
			desc = attacked_warden
		}
		modifier = { # The AI will only use a Hook if they couldn't otherwise do this
			scope:hook = yes
			add = -1
		}
		modifier = { # Not neighboring
			NOR = {
				scope:recipient = {
					character_is_land_realm_neighbor = scope:actor
					top_liege = scope:actor.top_liege
				}
			}
			add = -50
		}
		# Cultural traditions
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_equitable }
			add = 25
		}
		modifier = {
			scope:actor.culture = { has_cultural_tradition = tradition_esteemed_hospitality }
			add = 25
		}
		modifier = {
			scope:actor = {
				is_vassal_of = scope:recipient
				culture = { has_cultural_tradition = tradition_loyal_soldiers }
			}
			add = 25
			desc = HOSTAGE_CULTURAL_TRADITION_REASON
		}

		modifier = {
			add = 1000
			scope:actor = {
				is_independent_ruler = yes
				ai_compassion > -20
				ai_boldness < 40
				any_neighboring_and_across_water_top_liege_realm_owner = {
					this = scope:recipient
				}
				current_military_strength > scope:recipient.fifty_percent_more_of_current_military_strength
			}
			scope:recipient = {
				is_independent_ruler = yes
			}
		}

		modifier = {
			add = 1000
			scope:actor = {
				is_independent_ruler = no
				top_liege = scope:recipient.top_liege
				ai_compassion > -20
				ai_boldness < 40
				any_neighboring_realm_same_rank_owner = {
					this = scope:recipient
				}
				current_military_strength > scope:recipient.fifty_percent_more_of_current_military_strength
			}
			scope:recipient = {
				is_independent_ruler = no
			}
		}
	}
}



