@ai_skill_diff_upper_threshold = 8
@ai_skill_diff_lower_threshold = 2
@ai_prestige_bank_threshold = 2

@ai_core_loop_base_value = 4000
@ai_threshold_for_revoke_cyle = 3
@ai_secondary_powers_base_value = 500

###############################################
# #Setup & Misc
#
# CORE DIARCH POWERS
# diarch_revoke_title_interaction		- diarch (actor) takes a title from a vassal of their liege (recipient) with an optional veto for the liege (third_party).
# diarch_retract_vassal_interaction		- diarch (actor) takes a vassal from a vassal of their liege (recipient) with an optional veto for the liege (third_party).
# diarch_imprison_interaction			- diarch (actor) tries to move a character (recipient) within the sub-realm of their liege (third) to their dungeon, with an optional veto for the liege.
# diarch_entrench_regency_interaction	- diarch (actor) shifts the diarchy from temporary to entrenched, making it more difficult for their liege (recipient) to get rid of them.
#
# ANCILLARY DIARCH POWERS
# diarch_legal_meddling_interaction		- diarch (actor) either tests learning or spends prestige to gain an unpressed claim on a title held by a vassal of their liege (recipient).
# diarch_syphon_treasury_interaction	- diarch (actor) either tests stewardship or spends prestige to gain gold at the expense of negative modifiers delivered to the liege (recipient).
# diarch_shift_privileges_interaction	- diarch (actor) either tests diplomacy or spends prestige to give negative modifiers to the lands of a vassal of their liege (secondary recipient), who can't resist.
##################################################










##################################################
# CORE DIARCH POWERS

# Diarch (actor) takes a title from a vassal (recipient) of their liege with an optional veto for the liege (third_party).
diarch_revoke_title_interaction = {
	category = interaction_category_diarch
	common_interaction = no
	interface_priority = 35
	diarch_interaction = yes
	highlighted_reason = HIGHLIGHTED_CAN_DIARCH_REVOKE
	notification_text = DIARCH_REVOKE_TITLE_PROPOSAL
	intermediary_notification_text = diarch_interaction_requesting_sign_off.tt
	intermediary_breakdown_yes = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_YES
	intermediary_breakdown_no = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_NO
	intermediary_breakdown_maybe = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_MAYBE
	intermediary_answer_accept_key = REPLY_ANSWER_ALLOW
	intermediary_answer_reject_key = REPLY_ANSWER_VETO
	pre_answer_yes_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_YES
	pre_answer_no_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_NO
	pre_answer_maybe_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_MAYBE
	icon = revoke_title
	redirect = {
		scope:actor.liege ?= { save_scope_as = intermediary }
	}

	desc = diarch_revoke_title_interaction_desc
	send_name = diarch_revoke_title_interaction.send_name

	special_interaction = diarch_revoke_title
	interface = revoke_title
	target_type = title
	target_filter = recipient_domain_titles
	ai_maybe = yes
	ai_intermediary_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	on_decline_summary = diarch_rebel_or_crime_summary
	prompt = RETRACT_VASSAL_SELECT_VASSAL_TO_RETRACT

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = {
				has_diarchy_parameter = unlock_diarch_revoke_title_interaction
			}
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			# We only target vassals of the liege...
			liege = scope:actor.liege
			this != scope:actor.liege
			# ... who are appropriately landed.
			is_landed_or_landless_administrative = yes
			scope:recipient.highest_held_title_tier >= tier_county
		}
	}

	is_valid = {
		# Here to correct for some dodgy inheritance situations.
		scope:actor != scope:intermediary
	}
	is_valid_showing_failures_only = {
		# Standard validity checks.
		title_revocation_standard_valid_showing_failures_only_trigger = yes
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Plus make sure there's a legal right to revoke.
		scope:actor.liege = {
			trigger_if = {
				limit = { government_has_flag = government_is_tribal }
				custom_description = {
					text = "liege_has_law_allowing_title_revocation_tribal"
					has_realm_law_flag = title_revocation_allowed
				}
			}
			trigger_else_if = {
				limit = { government_has_flag = government_is_administrative }
				custom_description = {
					text = "cannot_diarch_revoke_administrative_titles"
					always = no
				}
			}
			trigger_else = {
				custom_description = {
					text = "liege_has_law_allowing_title_revocation_crown"
					has_realm_law_flag = title_revocation_allowed
				}
			}
		}
		trigger_if = {
			limit = {
				scope:recipient = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
			}
			custom_description = {
				text = liege_vassal_contract_forbids_revocation
				object = scope:recipient
				scope:recipient = {
					NOT = { vassal_contract_has_flag = vassal_contract_cannot_revoke_titles }
				}
			}
		}
		# Diarch revocations require a claim.
		diarch_revocation_has_claim_check_trigger = yes
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_an_entrenched_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege ?= { has_diarchy_active_parameter = unlock_diarch_revoke_title_interaction }
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 3 }

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	is_highlighted = {
		# Diarch revocations require a claim - this is uncommon, so we always highlight it.
		diarch_revocation_has_claim_check_trigger = yes
	}

	can_be_picked_title = {
		scope:target = {
			title_revocation_standard_can_pick_title_trigger = yes
			# Plus, must have scope:actor as a claimant.
			custom_description = {
				text = "you_must_have_a_claim_on_the_title"
				scope:actor = { has_claim_on = scope:target }
			}
		}
	}

	# Hooks can be used to force this through.
	## We don't force-force this on/for the player (so no pain but less benefits), but AI regard weak hooks as compulsory from/for other AI.
	send_options_exclusive = no
	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"

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
		# Did a landless diarch send this?
		log_diarch_send_interaction_as_variable_effect = { INTERACTION = revoke }
	}

	on_auto_accept = {
		scope:recipient = { trigger_event = char_interaction.0261 }
	}

	on_accept = {
		# Since this is a confusing interaction, we want to clarify what you're nicking.
		scope:actor = { custom_tooltip = diarch_revoke_title_interaction.tt.gain_title }
		# To keep some other arcane script working.
		save_scope_value_as = {
			name = revoke_title_interaction
			value = yes
		}
		scope:actor = {
			# Tell them that the revocation went through fine.
			trigger_event = char_interaction.0262
		}
		# Otherwise, follow the standard flow for revocation.
		save_scope_value_as = {
			name = use_strife_not_tyranny
			value = yes
		}
		revoke_title_interaction_effect = yes
		scope:actor = {
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# To avoid unlanded regents becoming vassals of the liege's direct vassals, make sure the current liege remains the liege
		hidden_effect = {
			scope:actor = {
				if = {
					limit = {
						is_landed_or_landless_administrative = no
						scope:intermediary != scope:recipient
					}
					# This has a delay of 1 day (if no delay then the liege change doesn't stick) which really isn't ideal and should be looked into/fixed so that it happens when the action goes into effect
					trigger_event = { id = diarchy.0141 days = 1 }
				}
			}
		}

		# Debug logging.
		debug_log = debug_log.diarch_revoke_title.accepted
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_revoke_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_accept_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_accept_intermediary_list }
		}
	}

	on_intermediary_decline = {
		# Scope:intermediary eats a prestige cost for their veto.
		scope:intermediary = { add_prestige = liege_diarchy_veto_prestige_cost_high }
		scope:actor = {
			# Inform scope:actor that their liege has vetoed them.
			## First, we log which interaction this is for the event's effects.
			save_scope_value_as = {
				name = diarch_interaction
				value = flag:title_revoke
			}
			## Then, fire the event.
			trigger_event = char_interaction.0291
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Inform scope:recipient that scope:intermediary has their back.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_action_vetoed.tt
				left_icon = scope:actor
				right_icon = scope:intermediary
				custom_tooltip = diarch_revoke_title_interaction.tt.inform_recipient
			}
		}
		# Flick out some opinions.
		diarch_revoke_title_interaction_intermediary_fail_opinions_effect = yes

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_revoke_veto }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_veto_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_veto_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_veto_intermediary_list }
		}
	}

	on_decline = {
		scope:actor = {
			# Tell them that the revocation ran into issues.
			trigger_event = char_interaction.0263
			# And give a crime reason for both them and the liege.
			show_as_tooltip = {
				random_list = {
					50 = {
						show_chance = no
						desc = char_interaction.0263.result.criminal
						diarch_declare_recipient_criminal_effect = yes
					}
					50 = {
						show_chance = no
						desc = char_interaction.0263.result.war
						diarch_declare_claim_war_effect = yes
					}
				}
			}
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Flick out some opinions.
		## Scope:recipient is annoyed with scope:actor.
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = revoked_title
			}
		}

		# Debug logging.
		debug_log = debug_log.diarch_revoke_title.rejected
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_revoke_reject }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_reject_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_reject_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_revoke_reject_intermediary_list }
		}
	}

	auto_accept = {
		scope:recipient = {
			calc_true_if = {
				amount >= 2
				custom_description = {
					text = "prisoner_revocation"
					is_imprisoned_by = scope:actor
				}
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:recipient
					scope:hook = yes
					OR = {
						# Strong hooks generally.
						scope:actor = { has_strong_hook = scope:recipient }
						# Weak hooks in inter-AI interactions count as strong hooks.
						AND = {
							scope:actor = { is_ai = yes }
							scope:recipient = { is_ai = yes }
						}
					}
				}
				custom_description = {
					text = "foreign_prison_revocation"
					subject = scope:actor
					object = scope:recipient
					scope:recipient = {
						is_imprisoned = yes
						NOT = { is_imprisoned_by = scope:actor }
					}
				}
			}
		}
	}

	ai_intermediary_accept = {
		# The AI should be inclined to trust their regent, at least a little.
		base = 0
		modifier = { add = liege_trust_diarch_trilateral_interaction_default_value }

		# Standard modifiers.
		intermediary_liege_will_accept_standard_modifiers = {
			CURRENCY = prestige
			COST = liege_diarchy_veto_prestige_cost_high
		}
		# Misc important reasons.
		## Revoking own capital.
		modifier = {
			add = 50
			desc = AI_TITLE_IS_REALM_CAPITAL
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:landed_title = scope:actor.primary_title.title_capital_county
				scope:landed_title = scope:actor.primary_title.title_capital_county.de_jure_liege
			}
		}
	}
	ai_accept = {
		# Try to make it 0 for most interactions
		base = 0

		# Weak Hook
		modifier = {
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook = yes
		}
		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.8
			desc = AI_OPINION_REASON
		}
		# Refusal is Treason
		## It's always treason, but worth pointing it out.
		modifier = {
			add = 20
			desc = AI_REFUSAL_IS_TREASON
		}
		# Revoking own capital.
		modifier = {
			add = 50
			desc = AI_TITLE_IS_REALM_CAPITAL
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:landed_title = scope:actor.primary_title.title_capital_county
				scope:landed_title = scope:actor.primary_title.title_capital_county.de_jure_liege
			}
		}
		# We don't buff claimants because you *have* to be a claimant for a diarch revoke.
		## Compensated for by refusal _always_ being treason.
		# I am a King!
		modifier = {
			add = -20
			desc = offer_vassalization_interaction_aibehavior_hightier_tt
			scope:recipient = { highest_held_title_tier = tier_kingdom }
		}
		# Title is part of vassal's primary title de-jure.
		modifier = {
			add = -25
			desc = AI_REFUSAL_IS_DE_JURE_UNDER
			OR = {
				scope:recipient.primary_title = { is_de_jure_liege_or_above_target = scope:landed_title }
				scope:recipient.primary_title = scope:landed_title
			}
		}
		# Dread
		## Intimidation
		modifier = {
			add = intimidated_halved_reason_value
			desc = INTIMIDATED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
		}
		## Cowing
		modifier = {
			add = cowed_halved_reason_value
			desc = COWED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
		}
		# Comparative military strength.
		modifier = {
			add = {
				value = 1
					subtract = {
						value = scope:recipient.max_military_strength
						divide = { value = scope:actor.max_military_strength min = 1 }
					}
				multiply = 50
				max = 20
			}
			desc = offer_vassalization_interaction_aibehavior_power_tt
			scope:actor = { is_landed_or_landless_administrative = yes }
		}
		# Legalistic tradition
		modifier = {
			add = legalistic_vassal_punishment_acceptance
			desc = tradition_legalistic_name
			scope:actor = {
				has_revoke_title_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
		}
		# Factor for personality.
		ai_value_modifier = {
			who = scope:recipient
			# Greed is always a factor.
			ai_greed = {
				if = {
					limit = {
						scope:recipient = {
							NOT = { ai_greed = 0 }
						}
					}
					value = -0.75
				}
			}
			# If AI is honourable and the law compels them to obey the liege, AI will be more likely to obey.
			ai_honor = {
				if = {
					limit = {
						scope:recipient = { ai_honor > 0 }
					}
					value = 0.5
				}
			}
		}
		# Bump up landless diarchs if we could survive the transition.
		modifier = {
			add = 100
			scope:actor = { is_ruler = no }
			scope:recipient = {
				any_held_county = { count >= 2 }
			}
		}
	}

	# AI
	ai_targets = { ai_recipients = peer_vassals }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_potential = {
		is_diarch = yes
		liege = { has_realm_law_flag = title_revocation_allowed }
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_core_loop_base_value

		# Additions.
		## Opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = 0.25
		}
		## Personality.
		ai_value_modifier = {
			ai_boldness = 0.75
			ai_honor = -0.5
		}
		## Traits.
		### +++ Ambitious.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = ambitious
		}
		### +++ Greedy.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = greedy
		}
		### +++ Vengeful (under certain criteria).
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = vengeful
			has_opinion_modifier = {
				modifier = revoked_title
				target = scope:recipient
			}
		}
		### ++ Arbitrary.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = arbitrary
		}
		### - Generous.
		modifier = {
			add = diarch_ai_desire_minus_1_value
			has_trait = generous
		}
		### -- Just.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = just
		}
		### --- Content.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			has_trait = content
		}
		## Landless characters want land, but also want to focus on taking from those who might give it up.
		### So we prioritise hooked AI counts.
		modifier = {
			add = 100
			is_landed = no
			has_hook = scope:recipient
			scope:recipient = {
				highest_held_title_tier = tier_county
				is_ai = yes
			}
		}
		### Then just hooked AI.
		modifier = {
			add = 50
			is_landed = no
			has_hook = scope:recipient
			scope:recipient = { is_ai = yes }
		}
		## Always revoke preferred capital and capital duchy.
		modifier = {
			add = 1000
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:landed_title = scope:actor.primary_title.title_capital_county
				scope:landed_title = scope:actor.primary_title.title_capital_county.de_jure_liege
			}
		}
		## Slight preference for higher-tier titles.
		modifier = {
			add = {
				value = scope:landed_title.tier
				multiply = 10
			}
		}
		## We avoid wars here too, but only in the resulting event.
		# Factors.
		## Relationships.
		### + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on players unless they're of at least a decent size.
		modifier = {
			factor = 0
			scope:recipient = {
				is_ai = no
				any_held_county = { count <= 3 }
			}
		}
		### x0 Don't go into prestige debt!
		modifier = {
			factor = 0
			prestige <= 0
		}
	}
}

# Diarch (actor) takes a vassal from a vassal (recipient) of their liege with an optional veto for the liege (third_party).
diarch_retract_vassal_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	interface_priority = 10
	highlighted_reason = HIGHLIGHTED_CAN_DIARCH_RETRACT
	notification_text = RETRACT_VASSAL_PROPOSAL
	intermediary_notification_text = diarch_interaction_requesting_sign_off.tt
	intermediary_breakdown_yes = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_YES
	intermediary_breakdown_no = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_NO
	intermediary_breakdown_maybe = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_MAYBE
	intermediary_answer_accept_key = REPLY_ANSWER_ALLOW
	intermediary_answer_reject_key = REPLY_ANSWER_VETO
	pre_answer_yes_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_YES
	pre_answer_no_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_NO
	pre_answer_maybe_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_MAYBE
	icon = icon_liege
	redirect = {
		scope:actor.liege ?= { save_scope_as = intermediary }
	}

	desc = diarch_retract_vassal_interaction_desc
	send_name = diarch_retract_vassal_interaction.send_name

	special_interaction = retract_vassal_interaction
	interface = transfer_vassal
	ai_maybe = yes
	ai_intermediary_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	on_decline_summary = diarch_rebel_or_crime_summary.retract

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = { has_diarchy_parameter = unlock_diarch_retract_vassal_interaction }
			# Plus you need to be landed for this.
			is_landed_or_landless_administrative = yes
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			# We only target vassals of the liege...
			liege = scope:actor.liege
			this != scope:actor.liege
			# ... who are appropriately landed.
			is_landed_or_landless_administrative = yes
			scope:recipient.highest_held_title_tier >= tier_duchy
		}
	}

	is_valid = {
		# Here to correct for some dodgy inheritance situations.
		scope:actor != scope:intermediary
	}
	is_valid_showing_failures_only = {
		# Standard validity checks.
		vassal_retraction_standard_valid_showing_failures_only_trigger = yes
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Scope:recipient must hold at least one of scope:actor's de jure vassals.
		scope:actor = {
			custom_description = {
				text = "you_must_have_a_de_jure_vassal_to_retract"
				object = scope:recipient
				any_held_title = {
					title_tier >= duchy
					any_direct_de_jure_vassal_title = {
						exists = holder
						holder.liege = scope:recipient
					}
				}
			}
		}
		# Plus make sure there's a legal right to retract.
		scope:actor.liege = {
			trigger_if = {
				limit = { government_has_flag = government_is_tribal }
				custom_description = {
					text = "liege_has_law_allowing_vassal_retraction_tribal"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
			trigger_if = {
				limit = {
					NOT = { government_has_flag = government_is_tribal }
				}
				custom_description = {
					text = "liege_has_law_allowing_vassal_retraction_crown"
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
		}
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_an_entrenched_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege = { has_diarchy_active_parameter = unlock_diarch_retract_vassal_interaction }
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 3 }

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	is_highlighted = {
		# Diarch retractions require a de jure claim - this is uncommon, so we always highlight it.
		diarch_retraction_is_de_jure_liege_trigger = yes
	}

	populate_recipient_list = {
		scope:actor = {
			every_held_title = {
				title_tier >= duchy
				every_direct_de_jure_vassal_title = {
					limit = { exists = holder }
					holder = {
						if = {
							limit = { liege = scope:recipient }
							add_to_list = characters
						}
					}
				}
			}
		}
	}

	# Hooks can be used to force this through.
	## We don't force-force this on/for the player (so no pain but less benefits), but AI regard weak hooks as compulsory from/for other AI.
	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

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_auto_accept = {
		scope:recipient = { trigger_event = char_interaction.0271 }
	}

	on_accept = {
		# Follow the standard flow for retraction.
		save_scope_value_as = {
			name = use_strife_not_tyranny
			value = yes
		}
		retract_vassal_interaction_effect = yes
		scope:actor = {
			# Tell them that the retraction went through fine.
			trigger_event = char_interaction.0272
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}

		# Debug logging.
		debug_log = debug_log.diarch_retract_vassal.accepted
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_retract_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_accept_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_accept_intermediary_list }
		}
	}

	on_intermediary_decline = {
		# Scope:intermediary eats a prestige cost for their veto.
		scope:intermediary = { add_prestige = liege_diarchy_veto_prestige_cost_high }
		scope:actor = {
			# Inform scope:actor that their liege has vetoed them.
			## First, we log which interaction this is for the event's effects.
			save_scope_value_as = {
				name = diarch_interaction
				value = flag:vassal_retract
			}
			## Then, fire the event.
			trigger_event = char_interaction.0291
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Inform scope:recipient that scope:intermediary has their back.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_action_vetoed.tt
				left_icon = scope:actor
				right_icon = scope:intermediary
				custom_tooltip = diarch_retract_vassal_interaction.tt.inform_recipient
			}
		}
		# Flick out some opinions.
		diarch_retract_vassal_interaction_intermediary_fail_opinions_effect = yes

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_retract_veto }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_veto_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_veto_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_veto_intermediary_list }
		}
	}

	on_decline = {
		scope:actor = {
			# Tell them that the retraction ran into issues.
			trigger_event = char_interaction.0273
			# And give a crime reason for both them and their liege.
			show_as_tooltip = {
				random_list = {
					50 = {
						show_chance = no
						desc = char_interaction.0273.result.criminal
						diarch_declare_recipient_criminal_effect = yes
					}
					50 = {
						show_chance = no
						desc = char_interaction.0273.result.war
						diarch_declare_vassalisation_war_effect = yes
					}
				}
			}
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Flick out some opinions.
		## Scope:recipient is annoyed with scope:actor.
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = retracted_vassal
			}
		}

		# Debug logging.
		debug_log = debug_log.diarch_retract_vassal.rejected
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_retract_decline }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_decline_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_decline_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_retract_decline_intermediary_list }
		}
	}

	auto_accept = {
		OR = {
			scope:recipient = {
				is_imprisoned_by = scope:actor
			}
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
				scope:actor = { has_strong_hook = scope:recipient }
			}
		}
	}

	ai_intermediary_accept = {
		# The AI should be inclined to trust their regent, at least a little.
		base = 0
		modifier = { add = liege_trust_diarch_trilateral_interaction_default_value }

		# Standard modifiers.
		intermediary_liege_will_accept_standard_modifiers = {
			CURRENCY = prestige
			COST = liege_diarchy_veto_prestige_cost_high
		}
		# Misc important reasons.
		## Retracting vassal with own capital.
		modifier = {
			add = 50
			desc = AI_VASSAL_HOLDS_REALM_CAPITAL
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				OR = {
					any_sub_realm_county = {
						this = scope:actor.primary_title.title_capital_county
					}
					any_sub_realm_duchy = {
						this = scope:actor.primary_title.title_capital_county.de_jure_liege
					}
				}
			}
		}
	}
	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		# Hook used
		modifier = {
			add = 40
			desc = SCHEME_WEAK_HOOK_USED
			scope:hook = yes
		}
		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}
		#
		modifier = {
			add = 25
			desc = AI_REFUSAL_IS_TREASON
			scope:actor = { has_realm_law_flag = vassal_refusal_is_treason }
		}

		ai_value_modifier = {
			who = scope:recipient
			ai_greed = {
				if = {
					limit = {
						scope:recipient = { NOT = { ai_greed = 0 } }
					}
					value = -0.25
				}
			}
			ai_honor = {
				if = {
					limit = {
						scope:recipient = { #If AI is honorable and the law compels to obey the liege, AI will be more likely to obey.
							ai_honor > 0
						}
						scope:actor = {
							has_realm_law_flag = vassal_refusal_is_treason
						}
					}
					value = 0.75
				}
			}
		}
		modifier = {
			add = 50
			desc = AI_VASSAL_HOLDS_REALM_CAPITAL
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				OR = {
					any_sub_realm_county = {
						this = scope:actor.primary_title.title_capital_county
					}
					any_sub_realm_duchy = {
						this = scope:actor.primary_title.title_capital_county.de_jure_liege
					}
				}
			}
		}

		modifier = { #Sub-Vassal is NOT De jure of current Vassal.
			add = 25
			desc = AI_REFUSAL_IS_NOT_DE_JURE_LIEGE
			NOT = {
				scope:recipient = {
					any_held_title = {
						is_de_jure_liege_or_above_target = scope:secondary_recipient.primary_title
					}
				}
			}
		}
		modifier = { #Sub-Vassal is De jure of liege title.
			add = 15
			desc = AI_REFUSAL_IS_DE_JURE_LIEGE
			scope:actor = {
				any_held_title = {
					this = scope:secondary_recipient.primary_title.de_jure_liege
				}
			}
		}
		modifier = {
			add = intimidated_halved_reason_value
			desc = INTIMIDATED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
		}
		modifier = {
			add = cowed_halved_reason_value
			desc = COWED_REASON
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
		}
		modifier = { #Comparative military strength.
			add = {
				value = 1
					subtract = {
					value = scope:recipient.max_military_strength
					divide = { value = scope:actor.max_military_strength min = 1 }
					}
				multiply = 100
			}
			desc = offer_vassalization_interaction_aibehavior_power_tt
		}
		modifier = { #Different faith, no pluralism.
			add = {
				value = -25
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_hostile_level
							}
						}
					}
					add = -10
				}
				if = {
					limit = {
						scope:actor.faith = {
							faith_hostility_level = {
								target = scope:recipient.faith
								value >= faith_evil_level
							}
						}
					}
					add = -25
				}
			}
			desc = AI_REFUSAL_SPLITTING_SAME_FAITH_VASSALS
			scope:actor.faith = scope:secondary_recipient.faith #Will not care as much if the vassal being retracted is of a different faith.
			scope:actor = {
				NOR = { #Of two different faiths AND the potential vassal's faith is not pluralistic.
					faith = scope:recipient.faith
					faith = { has_doctrine = doctrine_pluralism_pluralistic }
				}
			}
		}
	}

	# AI
	ai_targets = { ai_recipients = peer_vassals }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_potential = {
		is_diarch = yes
		has_realm_law_flag = title_revocation_allowed
		primary_title.tier > tier_county
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_secondary_powers_base_value

		# Additions.
		## Opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = 0.25
		}
		## Personality.
		ai_value_modifier = {
			ai_boldness = 0.75
			ai_honor = -0.5
		}
		## Traits.
		### +++ Ambitious.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = ambitious
		}
		### +++ Greedy.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = greedy
		}
		### +++ Vengeful (under certain criteria).
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = vengeful
			has_opinion_modifier = {
				modifier = revoked_title
				target = scope:recipient
			}
		}
		### ++ Arbitrary.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = arbitrary
		}
		### - Generous.
		modifier = {
			add = diarch_ai_desire_minus_1_value
			has_trait = generous
		}
		### -- Just.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = just
		}
		### --- Content.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			has_trait = content
		}
		## Always revoke preferred capital and capital duchy
		modifier = {
			add = 1000
			exists = scope:actor.primary_title.title_capital_county
			OR = {
				scope:actor = {
					any_held_title = { this = scope:actor.primary_title.title_capital_county.de_jure_liege }
				}
				scope:actor.primary_title.title_capital_county.de_jure_liege = { is_title_created = no }
			}
			scope:secondary_recipient = {
				any_sub_realm_county = { this = scope:actor.primary_title.title_capital_county }
			}
		}
		# Always retract preferred capital duchy
		modifier = {
			add = 1000
			exists = scope:actor.primary_title.title_capital_county
			scope:secondary_recipient = {
				any_sub_realm_duchy = { this = scope:actor.primary_title.title_capital_county.de_jure_liege }
			}
		}
		## Slight preference for higher-tier titles
		modifier = {
			add = {
				value = scope:secondary_recipient.highest_held_title_tier
				multiply = 10
			}
		}
		## We avoid wars here too, but only in the resulting event.
		# Factors.
		## Relationships.
		### + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on players unless they're of at least a decent size.
		modifier = {
			factor = 0
			scope:recipient = {
				is_ai = no
				any_held_county = { count <= 3 }
			}
		}
		### x0 Exempt the party baron.
		modifier = {
			factor = 0
			scope:recipient = { has_character_flag = is_party_baron }
		}
	}
}

# Diarch (actor) imprisons a character (recipient) who's a sub-realm character of their liege, with an optional veto for the liege (third_party).
diarch_imprison_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	interface_priority = 16
	notification_text = DIARCH_IMPRISON_PROPOSAL
	intermediary_notification_text = diarch_interaction_requesting_sign_off.tt
	intermediary_breakdown_yes = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_YES
	intermediary_breakdown_no = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_NO
	intermediary_breakdown_maybe = ANSWER_TRILATERAL_INTERMEDIARY_LIEGE_MAYBE
	intermediary_answer_accept_key = REPLY_ANSWER_ALLOW
	intermediary_answer_reject_key = REPLY_ANSWER_VETO
	pre_answer_yes_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_YES
	pre_answer_no_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_NO
	pre_answer_maybe_breakdown_key = ANSWER_TRILATERAL_RECIPIENT_MAYBE
	icon = prison
	redirect = {
		scope:actor.liege ?= { save_scope_as = intermediary }
	}

	desc = diarch_imprison_interaction_desc
	send_name = diarch_imprison_interaction.send_name

	ai_maybe = yes
	ai_intermediary_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	ai_min_reply_days = 4
	ai_max_reply_days = 9

	on_decline_summary = diarch_rebel_or_crime_summary.crominal

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = { has_diarchy_parameter = unlock_diarch_imprison_interaction }
			# The prisoner goes to your dungeon, so we want you to actually have one.
			is_landed_or_landless_administrative = yes
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = { is_imprisoned = no }
		# Scope:recipient can't be visiting elsewhere.
		trigger_if = {
			limit = {
				scope:recipient = { is_courtier = yes }
			}
			NOT = {
				scope:recipient.host = {
					any_foreign_court_guest = { this = scope:recipient }
				}
			}
		}
		# Finally, make sure this isn't someone scope:actor could use the conventional interaction on.
		scope:actor = {
			liege = {
				basic_allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
			}
			NOT = {
				basic_allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
			}
		}
	}

	is_valid = {
		# Here to correct for some dodgy inheritance situations.
		scope:actor != scope:intermediary
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			advanced_allowed_to_imprison_character_trigger = { CHARACTER = scope:recipient }
		}
		imprison_neutral_is_valid_showing_failures_only_triggers_trigger = yes
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_a_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege = { has_diarchy_active_parameter = unlock_diarch_imprison_interaction }
			scope:actor.liege = {
				trigger_if = {
					limit = { has_realm_law_flag = imprisonment_toggle_enable } #Present on all tribal authority to disable imprisonment
					has_realm_law_flag = imprisonment_toggle_on #Present from tribal authority level 1 to re-enable imprisonment
				}
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 3 }

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	is_highlighted = {
		scope:recipient = { is_imprisoned = no }
		scope:actor = { has_imprisonment_reason = scope:recipient }
	}

	#Use hook
	send_option = {
		is_valid = {
			exists = scope:recipient
			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

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_auto_accept = {
		scope:actor = { trigger_event = char_interaction.0281 }
		diarch_imprison_general_accept_effect = yes
	}

	on_accept = {
		if = {
			limit = { scope:hook = yes }
			scope:actor = { use_hook = scope:recipient }
		}
		# Tell them that the imprisonment went through fine.
		scope:actor = { trigger_event = char_interaction.0282 }
		save_scope_value_as = {
			name = use_strife_not_tyranny
			value = yes
		}
		diarch_imprison_general_accept_effect = yes

		# Debug logging.
		debug_log = debug_log.diarch_imprison.accepted
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_imprison_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_accept_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_accept_intermediary_list }
		}
	}

	on_intermediary_decline = {
		# Scope:intermediary eats a prestige cost for their veto.
		scope:intermediary = { add_prestige = liege_diarchy_veto_prestige_cost_medium }
		scope:actor = {
			# Inform scope:actor that their liege has vetoed them.
			## First, we log which interaction this is for the event's effects.
			save_scope_value_as = {
				name = diarch_interaction
				value = flag:imprison
			}
			## Then, fire the event.
			trigger_event = char_interaction.0291
			# Scope:actor can be hostile again.
			clear_hostile_actions_lock_flag_effect = yes
		}
		# Inform scope:recipient that scope:intermediary has their back.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_action_vetoed.tt
				left_icon = scope:actor
				right_icon = scope:intermediary
				custom_tooltip = diarch_imprison_interaction.tt.inform_recipient
			}
		}
		# Flick out some opinions.
		diarch_imprison_interaction_intermediary_fail_opinions_effect = yes

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_imprison_veto }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_veto_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_veto_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_veto_intermediary_list }
		}
	}

	on_decline = {
		scope:actor = {
			save_scope_as = use_strife_not_tyranny
			imprison_HoF_consequences_effect = yes
			imprison_tyranny_effect = yes
		}
		# Do we want a war or an escape?
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = attempted_imprisonment_opinion
			}
			# If target is count or higher, we want the option to start a war.
			if = {
				limit = {
					is_landed_or_landless_administrative = yes
					highest_held_title_tier >= tier_county
				}
				# Send the choosing event.
				scope:actor = { trigger_event = char_interaction.0283 }
				# Display the choices in advance.
				show_as_tooltip = {
					random_list = {
						50 = {
							show_chance = no
							desc = char_interaction.0263.result.criminal
							diarch_declare_recipient_criminal_effect = yes
						}
						50 = {
							trigger = {
								scope:actor = {
									is_landed = yes  # consistent with char_interaction.0283
								}
							}
							show_chance = no
							desc = char_interaction.0263.result.war
							scope:recipient = {
								start_war = {
									casus_belli = remove_regent_cb
									target = scope:actor
								}
							}
						}
					}
				}
			}
			#If target is a baron or unlanded, have them escape.
			else = {
				if = { #To block them from being instantly rehired
					limit = {
						is_councillor_of = scope:actor
						can_be_fired_from_council_trigger = { COURT_OWNER = scope:actor }
					}
					set_variable = {
						name = escaped_imprisonment_from
						value = scope:actor
						years = 20
					}
				}
				if = {
					limit = { is_landed_or_landless_administrative = yes }
					depose_effect = { DEPOSER = scope:actor }
				}
				if = {
					limit = {
						is_playable_character = no
						trigger_if = {
							limit = { is_councillor = yes }
							can_be_fired_from_council_trigger = { COURT_OWNER = scope:recipient.liege }
						}
						trigger_if = {
							limit = { exists = scope:actor.faith.religious_head }
							scope:actor.faith.religious_head != scope:recipient
						}
					}
					custom_tooltip = deposed_and_become_wanderer
					select_and_move_to_pool_effect = yes
				}
				add_opinion = {
					target = scope:actor
					modifier = attempted_imprisonment_opinion
				}
			}
		}

		#Remove them as guardian/ward for any courtier (feedback given in char_interaction.0230)
		scope:actor = {
			if = {
				limit = {
					any_courtier = { has_relation_guardian = scope:recipient }
				}
				every_courtier = {
					limit = { has_relation_guardian = scope:recipient }
					save_scope_as = ward
					remove_guardian_effect = {
						GUARDIAN = scope:recipient
						WARD = scope:ward
						RETURN_WARD = yes
						HIDE_OPINION = no
					}
					add_to_list = ward_children
				}
			}
			if = {
				limit = {
					any_courtier = { has_relation_ward = scope:recipient }
				}
				random_courtier = {
					limit = { has_relation_ward = scope:recipient }
					save_scope_as = guardian
					show_as_tooltip = {
						remove_guardian_effect = {
							GUARDIAN = scope:guardian
							WARD = scope:recipient
							RETURN_WARD = yes
							HIDE_OPINION = no
						}
					}
					add_to_list = guardian_list
				}
				hidden_effect = {
					scope:guardian = {
						send_interface_message = {
							type = event_childhood_neutral
							title = remove_guardian_interaction_notification
							left_icon = scope:recipient
							right_icon = scope:guardian
							remove_guardian_effect = {
								GUARDIAN = scope:guardian
								WARD = scope:recipient
								RETURN_WARD = yes
								HIDE_OPINION = no
							}
						}
					}
				}
			}
		}
		# Misc clean-up stuff.
		scope:actor = {
			if = {
				limit = {
					scope:recipient = {
						OR = {
							is_playable_character = no
							AND = {
								is_landed_or_landless_administrative = yes
								primary_title.tier = tier_barony
							}
						}
					}
				}
				trigger_event = char_interaction.0230
			}
		}
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}

		# Debug logging.
		debug_log = debug_log.diarch_imprison.rejected
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_imprison_decline }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_decline_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_decline_recipient_list }
		}
		scope:intermediary = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_imprison_decline_intermediary_list }
		}
	}

	auto_accept = no

	ai_intermediary_accept = {
		# The AI should be inclined to trust their regent, at least a little.
		base = 0
		modifier = { add = liege_trust_diarch_trilateral_interaction_default_value }

		# Standard modifiers.
		intermediary_liege_will_accept_standard_modifiers = {
			CURRENCY = prestige
			COST = liege_diarchy_veto_prestige_cost_medium
		}
	}
	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		modifier = {
			add = {
				value = scope:actor.intrigue
				multiply = 1
			}
			desc = IMPRISON_INTRIGUE_ACTOR
		}
		modifier = {
			add = {
				value = scope:recipient.intrigue
				multiply = -2
			}
			desc = IMPRISON_INTRIGUE_RECIPIENT
		}

		modifier = {
			add = 30
			desc = SCHEME_HOOK_USED
			scope:hook = yes
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		ai_value_modifier = {
			who = scope:recipient
			ai_boldness = {
				if = {
					limit = {
						scope:recipient = { NOT = { ai_boldness = 0 } }
					}
					value = -0.5
				}
			}
		}
		modifier = {
			add = 20
			desc = AI_REFUSAL_IS_TREASON
			scope:actor = {
				any_vassal_or_below = { this = scope:recipient }
				has_realm_law_flag = vassal_refusal_is_treason
			}
		}
		modifier = {
			add = 50
			desc = AI_PRISON_FEUDAL_COMPLEX_PERK
			scope:actor = {
				has_perk = prison_feudal_complex_perk
			}
		}
		modifier = { #I am a King!
			add = -40
			desc = offer_vassalization_interaction_aibehavior_hightier_tt
			scope:recipient = { highest_held_title_tier = tier_kingdom }
		}
		modifier = { #Courtiers.
			add = 50
			desc = AI_REFUSAL_COURTIER
			scope:recipient = { is_ruler = no }
		}
		modifier = { # Your young children can't really stop you
			add = 200
			desc = AI_REFUSAL_YOUNG_CHILD
			scope:recipient = {
				is_child_of = scope:actor
				is_courtier_of = scope:actor
				is_adult = no
			}
		}
		modifier = { #They're a claimant against you
			add = -70
			desc = AI_CLAIMANT_PENALTY
			scope:actor = {
				OR = {
					any_targeting_faction = {
						faction_type = claimant_faction
						faction_is_at_war = yes
						special_character ?= scope:recipient
					}
					AND = {
						exists = var:claimant_faction_sent_demand
						var:claimant_faction_sent_demand = scope:recipient
					}
				}
			}
		}
		modifier = { #Rank difference.
			add = {
				value = -15
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 2
							}
						}
					}
					add = 5
				}
				if = {
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 3
							}
						}
					}
					add = 5
				}
				if = { #King asking Baron, modifier becomes positive.
					limit = {
						scope:actor = {
							tier_difference = {
								target = scope:recipient
								value >= 4
							}
						}
					}
					add = 10
				}
			}
			desc = AI_REFUSAL_RANK_DIFFERENCE
			scope:recipient = {
				is_ruler = yes
				highest_held_title_tier < tier_kingdom
			}
		}
		modifier = {
			add = intimidated_external_reason_value
			desc = INTIMIDATED_REASON
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
		}
		modifier = {
			add = cowed_external_reason_value
			desc = COWED_REASON
			scope:recipient = {
				NOT = { target_is_liege_or_above = scope:actor }
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
		}
		modifier = { #Comparative military strength.
			add = {
				value = 1
					subtract = {
					value = scope:recipient.max_military_strength
					divide = { value = scope:actor.max_military_strength min = 1 }
					}
				multiply = 100
				min = -1000
				# This max needs to match the loc in offer_vassalization_interaction_aibehavior_power_tt
				max = 20
			}
			desc = offer_vassalization_interaction_aibehavior_power_tt
			scope:actor = { is_ruler = yes }
			scope:recipient = { is_ruler = yes }
		}
		modifier = { #Rivalry modifier.
			add = -50
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
		}
		modifier = { #Nemesis modifier.
			add = -100
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			scope:recipient = {
				has_relation_nemesis = scope:actor
			}
		}
		modifier = {
			add = 10
			desc = GRANDEUR_REASON
			scope:recipient = { has_royal_court = no }
			scope:actor = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_grandeur_current_level >= 7
				court_grandeur_current_level < 9
			}
		}
		modifier = {
			add = 20
			desc = GRANDEUR_REASON
			scope:recipient = { has_royal_court = no }
			scope:actor = {
				has_royal_court = yes
				has_dlc_feature = royal_court
				court_grandeur_current_level >= 9
			}
		}
		modifier = { # Legalistic tradition
			add = legalistic_vassal_punishment_acceptance
			desc = tradition_legalistic_name
			scope:actor = {
				has_imprisonment_reason = scope:recipient
				culture = { has_cultural_parameter = vassals_more_likely_accept_punishments }
			}
		}
	}

	# AI
	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = scripted_relations
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		# You should have a _reason_ to try to imprison someone.
		base = 0

		# Additions.
		## Opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = 0.5
		}
		## Personality.
		ai_value_modifier = {
			ai_vengefulness = 1
			ai_boldness = 0.5
		}
		## Flag Management.
		### Make sure the AI uses hooks for this as it's % based
		modifier = {
			add = 1
			scope:hook = yes
		}
		## Traits.
		### +++ Sadistic.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = greedy
		}
		### +++ Vengeful.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = vengeful
		}
		### ++ Just (under certain circumstances).
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = just
			has_imprisonment_reason = scope:recipient
		}
		### -- Compassionate.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = compassionate
		}
		### --- Forgiving.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			has_trait = forgiving
		}
		## We avoid wars here too, but only in the resulting event.
		## Agenda impact
		modifier = {
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_important }
							has_character_flag = agenda_towards_escalation
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_important }
						}
					}
					add = -100
				}
			}
			any_character_struggle = { involvement = involved }
		}
		modifier = {
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_detractor }
							has_trait = fp3_struggle_supporter
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_detractor }
						}
					}
					add = -100
				}
			}
			any_character_struggle = { involvement = involved }
		}
		modifier = {
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_supporter }
							has_trait = fp3_struggle_detractor
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = { phase_has_catalyst = catalyst_imprison_supporter }
						}
					}
					add = -100
				}
			}
			any_character_struggle = { involvement = involved }
		}
		# Factors.
		## Relationships.
		### + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		### x0 Don't pick on people without due reason unless we really hate them.
		#### Doesn't quite double up with the above factor increase for folks we hate - we want to prioritise them, but we also want to enable them for arbitrary punishment.
		modifier = {
			factor = 0
			NOR = {
				has_imprisonment_reason = scope:recipient
				has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				# Sadists wants to torture folks.
				has_trait = sadistic
				# Agents get a time-out.
				any_targeting_scheme = {
					hostile_scheme_trigger = yes
					is_scheme_agent_exposed = scope:recipient
				}
				# Prior crimes annoy people.
				has_any_major_revenge_opinion_against_character_trigger = { CHARACTER = scope:recipient }
				# Vengeful characters can be a pain over even minor matters.
				AND = {
					OR = {
						has_trait = vengeful
						ai_vengefulness >= very_high_positive_ai_value
					}
					has_any_petty_revenge_opinion_against_character_trigger = { CHARACTER = scope:recipient }
				}
			}
		}
	}
}

# Diarch (actor) offers to boost the CA/TA/IB of liege (recipient), taking on the costs and negatives themselves so that they can use their diarch powers.
diarch_subsidise_crown_authority_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	notification_text = DIARCH_SUBSIDISE_AUTHORITY_PROPOSAL
	icon = icon_contract_modification_single

	desc = diarch_subsidise_crown_authority_interaction_desc

	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			liege_has_co_emperorship_trigger = no
			liege = { has_diarchy_parameter = diarch_can_subsidise_liege_authority }
		}
		# Same sub-realm only.
		OR = {
			scope:actor.liege = scope:recipient
			scope:recipient = {
				any_liege_or_above = { this = scope:actor.liege }
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = diarch_can_subsidise_liege_authority }
		# Can't subisidise past the point needed.
		custom_tooltip = {
			text = diarch_subsidise_crown_authority_interaction.tt.cannot_subsidise_past_necessary
			scope:recipient = {
				NOT = { has_realm_law_flag = diarchs_want_to_subsidise_without_this_flag }
			}
		}
		# And the liege can't have the max level of authority.
		custom_tooltip = {
			text = diarch_subsidise_crown_authority_interaction.tt.liege_cannot_have_max_authority
			scope:recipient = {
				NOT = { has_realm_law_flag = max_authority_level }
			}
		}
		# Aaaand, if you're not tribal/administrative, we need to check some innovations.
		scope:recipient = {
			# CA0 -> CA1.
			trigger_if = {
				limit = { has_realm_law = crown_authority_0 }
				can_pass_law_ca1_trigger = yes
			}
			# CA1 -> CA2.
			trigger_if = {
				limit = { has_realm_law = crown_authority_1 }
				can_pass_law_ca2_trigger = yes
			}
			# CA2 -> CA3.
			trigger_if = {
				limit = { has_realm_law = crown_authority_2 }
				can_pass_law_ca3_trigger = yes
			}

			# If the liege is administrative, they have to be independent.
			trigger_if = {
				limit = { government_allows = administrative }
				is_independent_ruler = yes
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	# Why the hell not? If your liege dies several times in quick succession, sure, centralise all the power you like. That'll go well.
	cooldown_against_recipient = { years = 10 }

	cost = {
		prestige = {
			value = scope:recipient.increase_crown_authority_prestige_cost
			multiply = subsidised_liege_authority_discount_value
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_subsidise_crown_authority_interaction.tt.accepted
				left_icon = scope:recipient
				scope:recipient = {
					# Try to change authority.
					increase_crown_authority_effect = yes
					increase_tribal_authority_effect = yes
					increase_imperial_bureaucracy_effect = yes
					# No one blames the liege for this.
					add_character_modifier = {
						modifier = liege_authority_boost_has_scapegoat_modifier
						years = 10
					}
				}
				# Aaaaand everyone knows what you did.
				change_strife_opinion = massive_strife_gain
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = diarch_subsidise_crown_authority_interaction.tt.declined
				left_icon = scope:recipient
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -20
				}
			}
		}
	}

	ai_accept = {
		base = 0

		# You want to do _what_? For free?
		modifier = {
			add = 100
			desc = diarch_subsidise_crown_authority_interaction.tt.absolutely_yes_please
			always = yes
		}
	}

	auto_accept = {
		custom_description = {
			text = auto_accept_interaction_ai
			object = scope:recipient
			scope:recipient = {
				is_ai = yes
			}
		}
	}

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}
	ai_potential = {
		is_diarch = yes
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
		# You also need prestige left over afterwards to use other interactions, so make sure the AI doesn't bankrupt itself on this.
		prestige >= {
			value = liege.increase_crown_authority_prestige_cost
			multiply = subsidised_liege_authority_discount_value
			add = major_prestige_value
		}
	}

	ai_will_do = {
		base = 0

		# Government situation.
		## Does your liege's gubermint allow you to bully people and take their stuff? No? Then you want to take this interaction; anyone who wouldn't has been pre-filtered.
		modifier = {
			add = 1000
			liege = {
				NOR = {
					has_realm_law_flag = title_revocation_allowed
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
		}
	}
}

# Diarch (actor) requests an adjustment of liege's (recipient's) IB, taking on the costs and negatives themselves _or_ reducing their strife, depending on whether they boost centralisation or decrease it.
diarch_adjust_bureaucracy_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	interface_priority = 9
	notification_text = {
		first_valid = {
			# Decentralise.
			triggered_desc = {
				trigger = { scope:decrease_centralisation = yes }
				desc = DIARCH_ADJUST_BUREAUCRACY_PROPOSAL.DECENTRALISE
			}
			# Centralise.
			desc = DIARCH_ADJUST_BUREAUCRACY_PROPOSAL.CENTRALISE
		}
	}
	icon = icon_contract_modification_single

	desc = diarch_adjust_bureaucracy_interaction_desc

	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			liege_has_co_emperorship_trigger = yes
			liege = { has_diarchy_parameter = unlock_adjust_imperial_bureaucracy_interaction }
		}
		# Same sub-realm only.
		OR = {
			scope:actor.liege = scope:recipient
			scope:recipient = {
				any_liege_or_above = { this = scope:actor.liege }
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = unlock_adjust_imperial_bureaucracy_interaction }
		# And the liege can't have the max level of authority.
		custom_tooltip = {
			text = diarch_subsidise_crown_authority_interaction.tt.liege_cannot_have_max_authority
			scope:recipient = {
				NOT = { has_realm_law_flag = max_authority_level }
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	# Co-emperors can't keep doing this in quick succession.
	cooldown = { years = 10 }

	cost = {
		prestige = {
			value = scope:recipient.increase_crown_authority_prestige_cost
			if = {
				limit = { scope:increase_centralisation = yes }
				multiply = subsidised_liege_authority_discount_value
			}
			else = { multiply = lowered_liege_authority_discount_value }
		}
	}

	# Increase IB
	send_option = {
		flag = increase_centralisation
		is_valid = {
			scope:recipient = {
				NOT = { has_realm_law = imperial_bureaucracy_3 }
			}
		}
		localization = increase_centralisation_name
		current_description = increase_centralisation
		starts_enabled = { always = yes }
	}
	# Decrease IB
	## The AI doesn't use this.
	send_option = {
		flag = decrease_centralisation
		is_valid = {
			scope:recipient = {
				NOT = { has_realm_law = imperial_bureaucracy_0 }
			}
		}
		localization = decrease_centralisation_name
		current_description = decrease_centralisation
	}

	on_send = {
		# Tell the AI to set their only send option.
		if = {
			limit = {
				scope:actor = { is_ai = yes }
			}
			save_scope_value_as = {
				name = increase_centralisation
				value = yes
			}
		}
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_subsidise_crown_authority_interaction.tt.accepted
				left_icon = scope:recipient
				scope:recipient = {
					# Try to change authority.
					if = {
						limit = { scope:increase_centralisation = yes }
						increase_imperial_bureaucracy_effect = yes
						# No one blames the liege for this.
						add_character_modifier = {
							modifier = liege_authority_boost_has_scapegoat_modifier
							years = 10
						}
					}
					else = { decrease_imperial_bureaucracy_effect = yes }
				}
				# Aaaaand everyone knows what you did.
				## For good.
				if = {
					limit = { scope:increase_centralisation = yes }
					change_strife_opinion = massive_strife_gain
				}
				## Or for ill.
				else = { change_strife_opinion = massive_strife_loss }
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = diarch_subsidise_crown_authority_interaction.tt.declined
				left_icon = scope:recipient
				add_opinion = {
					target = scope:recipient
					modifier = refusal_opinion
					opinion = -20
				}
			}
		}
	}

	ai_accept = {
		base = -25

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		# Your level of influence.
		## Impotent
		modifier = {
			add = -10
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPOTENT
			scope:actor.influence_level = 0
		}
		## Influential
		### Would be zero, so it wouldn't appear.
		## Persuasive
		modifier = {
			add = 10
			desc = AI_OPINION_INFLUENCE_LEVEL_PERSUASIVE
			scope:actor.influence_level = 2
		}
		## Controlling
		modifier = {
			add = 20
			desc = AI_OPINION_INFLUENCE_LEVEL_CONTROLLING
			scope:actor.influence_level = 3
		}
		## Authoritative
		modifier = {
			add = 30
			desc = AI_OPINION_INFLUENCE_LEVEL_AUTHORITATIVE
			scope:actor.influence_level = 4
		}
		## Imperious
		modifier = {
			add = 40
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPERIOUS
			scope:actor.influence_level = 5
		}
		# Traits.
		## --- Arrogant
		modifier = {
			add = -30
			desc = ai_acceptance_trait_arrogant
			scope:recipient = { has_trait = arrogant }
		}
		## --- Ambitious
		modifier = {
			add = -30
			desc = ai_acceptance_trait_ambitious
			scope:recipient = { has_trait = ambitious }
		}
		## --- Stubborn
		modifier = {
			add = -30
			desc = ai_acceptance_trait_stubborn
			scope:recipient = { has_trait = stubborn }
		}
		## -- Paranoid
		modifier = {
			add = -20
			desc = ai_acceptance_trait_paranoid
			scope:recipient = { has_trait = paranoid }
		}
		## + Craven
		modifier = {
			add = 10
			desc = ai_acceptance_trait_craven
			scope:recipient = { has_trait = craven }
		}
		## ++ Trusting
		modifier = {
			add = 20
			desc = ai_acceptance_trait_trusting
			scope:recipient = { has_trait = trusting }
		}
		## ++ Fickle
		modifier = {
			add = 20
			desc = ai_acceptance_trait_fickle
			scope:recipient = { has_trait = fickle }
		}
		## +++ Content
		modifier = {
			add = 30
			desc = ai_acceptance_trait_content
			scope:recipient = { has_trait = content }
		}
		## +++ Humble
		modifier = {
			add = 30
			desc = ai_acceptance_trait_humble
			scope:recipient = { has_trait = humble }
		}
		# Factor for personality.
		ai_value_modifier = {
			who = scope:recipient
			# The meeker they are, the more they'll go along with your wishes.
			ai_boldness = {
				if = {
					limit = {
						scope:recipient = {
							NOT = { ai_boldness = 0 }
						}
					}
					value = -1
				}
			}
			# And the lazier.
			ai_energy = {
				if = {
					limit = {
						scope:recipient = { ai_energy > 0 }
					}
					value = 0.5
				}
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = auto_accept_interaction_ai
			object = scope:recipient
			scope:recipient = {
				is_ai = yes
				scope:increase_centralisation = yes
			}
		}
	}

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 24
		hegemony = 24
	}
	ai_potential = {
		is_diarch = yes
		liege_has_co_emperorship_trigger = yes
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
		# You also need prestige left over afterwards to use other interactions, so make sure the AI doesn't bankrupt itself on this.
		prestige >= {
			value = liege.increase_crown_authority_prestige_cost
			multiply = subsidised_liege_authority_discount_value
			add = major_prestige_value
		}
	}

	ai_will_do = {
		base = 0

		# Government situation.
		## Does your liege's gubermint allow you to bully people and take their stuff? No? Then you want to take this interaction; anyone who wouldn't has been pre-filtered.
		modifier = {
			add = 1000
			liege = {
				NOR = {
					has_realm_law_flag = title_revocation_allowed
					has_realm_law_flag = vassal_retraction_allowed
				}
			}
		}
		# Otherwise, there's just a slight constant chance based on energy.
		ai_value_modifier = {
			ai_energy = 2
			# Assuming you're the heir, as otherwise...
			trigger = { liege.player_heir ?= root }
		}
	}
}











##################################################
# ANCILLARY DIARCH POWERS

# Diarch (actor) either tests learning or spends prestige to gain an unpressed claim on a title held by a vassal of their liege (recipient).
diarch_legal_meddling_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	interface_priority = 165
	diarch_interaction = yes
	icon = vassal_claim_liege_title_interaction

	desc = diarch_legal_meddling_interaction_desc

	ai_intermediary_maybe = yes
	target_type = title
	target_filter = recipient_domain_titles
	popup_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = { has_diarchy_parameter = unlock_legal_meddling_interaction }
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			# We only target vassals of the liege...
			liege = scope:actor.liege
			this != scope:actor.liege
			# ... who are appropriately landed.
			is_landed_or_landless_administrative = yes
			scope:recipient.highest_held_title_tier >= tier_county
		}
	}

	is_valid_showing_failures_only = {
		# You can't claim a title from someone if you already have claims on all their titles.
		custom_tooltip = {
			text = diarch_legal_meddling_interaction.tt.they_must_have_at_least_one_unclaimed_title
			scope:recipient = {
				any_held_title = {
					diarch_legal_meddling_claimable_title_trigger = { ACTOR = scope:actor }
				}
			}
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_a_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege = { has_diarchy_active_parameter = unlock_legal_meddling_interaction }
		}
		# Must select something.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:diarch_legal_meddling_interaction_duel_learning = yes
					scope:diarch_legal_meddling_interaction_pay_prestige_partial = yes
					scope:diarch_legal_meddling_interaction_pay_prestige_full = yes
				}
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cooldown = { months = 6 }
	cooldown_against_recipient = { years = 3 }

	can_be_picked_title = {
		scope:target = {
			# Really anything you don't already have a claim on and which isn't special.
			diarch_legal_meddling_claimable_title_trigger = { ACTOR = scope:actor }
		}
	}

	# Attempt Methods
	send_options_exclusive = yes
	## Duel for it.
	send_option = {
		# You can always try to duel for it.
		flag = diarch_legal_meddling_interaction_duel_learning
	}
	## Pay partial prestige.
	send_option = {
		is_valid = {
			scope:actor = {
				prestige >= {
					value = legal_meddling_interaction_title_discounted_cost_value
					multiply = -1
				}
			}
		}
		flag = diarch_legal_meddling_interaction_pay_prestige_partial
	}
	## Pay full prestige.
	send_option = {
		is_valid = {
			scope:actor = {
				prestige >= {
					value = legal_meddling_interaction_title_cost_value
					multiply = -1
				}
			}
		}
		flag = diarch_legal_meddling_interaction_pay_prestige_full
	}

	on_send = {
		# Did a landless diarch send this?
		log_diarch_send_interaction_as_variable_effect = { INTERACTION = forge_claim }
	}

	on_accept = {
		scope:actor = {
			# Resolution method.
			## If we're duelling, then we duel.
			if = {
				limit = { scope:diarch_legal_meddling_interaction_duel_learning = yes }
				# Now: FIGHT! WITH WORDS!
				duel = {
					skill = learning
					target = scope:recipient
					# Victory! A claim for you.
					50 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = 3.5
							min = -49
						}
						desc = diarch_legal_meddling_interaction.tt.success
						diarch_legal_meddling_interaction_apply_success_effect = yes
					}
					# Defeat! Into the loser's bin you go.
					50 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = -3.5
							min = -49
						}
						desc = diarch_legal_meddling_interaction.tt.failure
						diarch_legal_meddling_interaction_apply_fail_effect = yes
					}
				}
			}
			## Otherwise we can take an uneven gamble against a reduced prestige cost..
			else_if = {
				limit = { scope:diarch_legal_meddling_interaction_pay_prestige_partial = yes }
				random_list = {
					# Victory! A claim for you.
					100 = {
						desc = diarch_legal_meddling_interaction.tt.success
						diarch_legal_meddling_interaction_apply_success_effect = yes
					}
					# Defeat! Into the loser's bin you go.
					100 = {
						desc = diarch_legal_meddling_interaction.tt.failure
						diarch_legal_meddling_interaction_apply_fail_effect = yes
					}
				}
			}
			## Or pay the full price.
			else = {
				custom_tooltip = diarch_legal_meddling_interaction.tt.success
				diarch_legal_meddling_interaction_apply_success_effect = yes
			}
		}

		# Debug logging.
		debug_log = debug_log.legal_meddling.attempt_made
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = peer_vassals }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_potential = {
		is_diarch = yes
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_core_loop_base_value

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_boldness = 0.25
			ai_greed = 0.5
			ai_honor = 0.5
		}
		## Flag Management.
		### Duel for it if we're massively superior.
		modifier = {
			add = 100
			scope:diarch_legal_meddling_interaction_duel_learning = yes
			learning_diff = {
				target = scope:recipient
				value >= @ai_skill_diff_upper_threshold
			}
		}
		### Else  we'll try to pay full prestige, if we've got lots to spare.
		modifier = {
			add = 50
			scope:diarch_legal_meddling_interaction_pay_prestige_full = yes
			prestige >= {
				value = shift_privileges_interaction_target_cost_value
				multiply = @ai_prestige_bank_threshold
			}
		}
		### Or else we'll to chance it, if we can afford that + some slack.
		modifier = {
			add = 25
			scope:diarch_legal_meddling_interaction_pay_prestige_partial = yes
			prestige < {
				value = shift_privileges_interaction_target_cost_value
				multiply = @ai_prestige_bank_threshold
			}
			prestige >= {
				value = shift_privileges_interaction_target_discounted_cost_value
				multiply = @ai_prestige_bank_threshold
			}
		}
		### Otherwise we'll risk a regular duel.
		## Weight up for bordering or de jure areas.
		modifier = {
			add = 50
			is_landed_or_landless_administrative = yes
			any_sub_realm_county = {
				any_neighboring_county = {
					holder = {
						OR = {
							this = scope:recipient
							any_liege_or_above = { this = scope:recipient }
						}
					}
				}
			}
		}
		modifier = {
			add = 50
			is_landed_or_landless_administrative = yes
			scope:actor = {
				any_held_title = {
					any_direct_de_jure_vassal_title = {
						holder ?= {
							OR = {
								this = scope:recipient
								this = {
									any_liege_or_above = { this = scope:recipient }
								}
							}
						}
					}
				}
			}
		}
		## Weight down for folks outside of our de jure kingdom.
		modifier = {
			add = -100
			is_landed_or_landless_administrative = yes
			scope:recipient.primary_title.de_jure_liege ?= {
				this != scope:actor.primary_title.de_jure_liege
			}
		}
		## Landless characters want land, but also want to focus on taking from those who might give it up.
		### So we prioritise hooked AI counts.
		modifier = {
			add = 100
			is_landed = no
			has_hook = scope:recipient
			scope:recipient = {
				highest_held_title_tier = tier_county
				is_ai = yes
			}
		}
		### Then just hooked AI.
		modifier = {
			add = 50
			is_landed = no
			has_hook = scope:recipient
			scope:recipient = { is_ai = yes }
		}
		# Factors.
		## + Weight up if we're lacking valid claims
		modifier = {
			factor = 1.5
			NOR = {
				is_claimant = yes
				any_claim = {
					exists = holder
					exists = holder.liege
					holder.liege = scope:actor.liege
				}
			}
		}
		## + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## + If we're landless, turbo charge this when we lack suitable claims.
		modifier = {
			factor = 3
			scope:actor = {
				is_ruler = no
				any_claim = {
					count < @ai_threshold_for_revoke_cyle
					diarch_legal_meddling_claimable_title_trigger = { ACTOR = scope:actor }
				}
			}
		}
		## + If we're landless, try to prioritise anyone we've got a hook on.
		modifier = {
			factor = 2
			scope:actor = {
				is_ruler = no
				has_usable_hook = scope:recipient
			}
		}
		## - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## x0 Don't pick on players unless they're of at least a decent size.
		modifier = {
			factor = 0
			scope:recipient = {
				is_ai = no
				any_held_county = { count <= 3 }
			}
		}
		## x0 If we're landless, don't claim more titles if we've already got enough we can try to action.
		modifier = {
			factor = 0
			scope:actor = {
				is_ruler = no
				any_claim = {
					count >= @ai_threshold_for_revoke_cyle
					diarch_legal_meddling_claimable_title_trigger = { ACTOR = scope:actor }
				}
			}
		}
		## x0 If we're landless, don't pick on people who won't give their lands up.
		modifier = {
			factor = 0
			scope:actor = { is_ruler = no }
			scope:recipient = {
				any_held_county = { count <= 1 }
			}
		}
		### x0 Don't go into prestige debt!
		modifier = {
			factor = 0
			prestige < 0
		}
	}
}

# Diarch (actor) either tests stewardship or spends prestige to gain gold at the expense of negative modifiers delivered to the liege (recipient).
diarch_syphon_treasury_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	icon = icon_gold
	common_interaction = yes

	desc = diarch_syphon_treasury_interaction_desc


	interface_priority = 60

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = { has_diarchy_parameter = unlock_syphon_treasury_interaction }
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			OR = {
				# We only target the liege...
				this = scope:actor.liege
				# ... but we want to see it for peer-vassals and such.
				any_liege_or_above = { this = scope:actor.liege }
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# If scope:actor's stewardship is too crap, then we need to make sure they haven't somehow managed to riddle scope:recipient's lands with negative modifiers already.
		trigger_if = {
			limit = { scope:actor.stewardship < syphon_treasury_stewardship_medium }
			custom_tooltip = {
				text = diarch_syphon_treasury_interaction.tt.not_enough_marks_or_stewardship
				scope:recipient = {
					any_held_county = { diarch_syphon_treasury_embezzlement_modifiers_trigger = no }
				}
			}
		}
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_a_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege = { has_diarchy_active_parameter = unlock_syphon_treasury_interaction }
		}
		# Must have selected an amount to embezzle.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
				custom_tooltip = {
				text = diarch_interactions.tt.must_embezzle_something
				OR = {
					scope:diarch_syphon_treasury_sum_small = yes
					scope:diarch_syphon_treasury_sum_medium = yes
					scope:diarch_syphon_treasury_sum_large = yes
					scope:diarch_syphon_treasury_sum_huge = yes
				}
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cooldown = { years = 3 }

	# Attempt Methods
	send_options_exclusive = yes
	## Steal a small sum.
	### Bonus to scope:actor.
	send_option = {
		flag = diarch_syphon_treasury_sum_small
		# We're doing gross overrides here so that we don't need to relocalise some perfectly good stuff.
		localization = diarch_syphon_treasury_sum_small_name
		current_description = diarch_syphon_treasury_sum_small
	}
	## Steal a moderate sum.
	### No bonus, no malus.
	send_option = {
		flag = diarch_syphon_treasury_sum_medium
		# We're doing gross overrides here so that we don't need to relocalise some perfectly good stuff.
		localization = diarch_syphon_treasury_sum_medium_name
		current_description = diarch_syphon_treasury_sum_medium
		starts_enabled = { always = yes }
	}
	## Steal a large sum.
	### Malus to scope:actor
	send_option = {
		flag = diarch_syphon_treasury_sum_large
		# We're doing gross overrides here so that we don't need to relocalise some perfectly good stuff.
		localization = diarch_syphon_treasury_sum_large_name
		current_description = diarch_syphon_treasury_sum_large
	}
	## Steal a _huge_sum.
	### _Huge_ malus to scope:actor.
	send_option = {
		flag = diarch_syphon_treasury_sum_huge
		# We're doing gross overrides here so that we don't need to relocalise some perfectly good stuff.
		localization = diarch_syphon_treasury_sum_huge_name
		current_description = diarch_syphon_treasury_sum_huge
	}

	on_send = {
		# Did a landless diarch send this?
		log_diarch_send_interaction_as_variable_effect = { INTERACTION = embezzle }
	}

	on_accept = {
		# Time for a skill duel!
		scope:actor = {
			duel = {
				skill = stewardship
				value = syphon_treasury_duel_target_value
				# Victory! Gold for scope:actor, maluses for the liege.
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					# Bonus for smaller amounts.
					modifier = {
						add = 25
						always = scope:diarch_syphon_treasury_sum_small
					}
					# You always have some kind of a chance.
					min = 10
					desc = diarch_syphon_treasury_interaction.tt.success
					# Inform scope:actor what type of embezzlement they'll be pursuing.
					## Very high stewardship characters syphon development growth from a few counties.
					if = {
						limit = {
							stewardship >= syphon_treasury_stewardship_very_high
							NOT = { government_has_flag = government_is_nomadic }
						}
						custom_tooltip = diarch_syphon_treasury_interaction.tt.success.syphon_development_growth
					}
					## Alternatively, herd for nomadic rulers
					else_if = {
						limit = {
							stewardship >= syphon_treasury_stewardship_very_high
							government_has_flag = government_is_nomadic
						}
						custom_tooltip = diarch_syphon_treasury_interaction.tt.success.syphon_herd
					}
					## High stewardship characters syphon some control from various counties.
					else_if = {
						limit = { stewardship >= syphon_treasury_stewardship_high }
						custom_tooltip = diarch_syphon_treasury_interaction.tt.success.syphon_control_several_counties
					}
					## Medium stewardship characters syphon lots of control from one county.
					else_if = {
						limit = { stewardship >= syphon_treasury_stewardship_medium }
						custom_tooltip = diarch_syphon_treasury_interaction.tt.success.syphon_control_county
					}
					## Low stewardship characters apply county modifiers.
					else = { custom_tooltip = diarch_syphon_treasury_interaction.tt.success.apply_county_modifier }
					# Now we sort the actual effects.
					## A nice toast to tell us about our new gold.
					send_interface_toast = {
						type = event_toast_effect_good
						title = diarch_syphon_treasury_interaction.tt.success
						left_icon = scope:recipient
						# Transfer gold.
						## Small amount.
						if = {
							limit = { always = scope:diarch_syphon_treasury_sum_small }
							give_or_update_embezzler_secret_effect = {
								TARGET = scope:recipient
								STAKE = syphon_treasury_gold_gain_low
							}
							add_gold = syphon_treasury_gold_gain_low
						}
						## Medium amount.
						else_if = {
							limit = { always = scope:diarch_syphon_treasury_sum_medium }
							give_or_update_embezzler_secret_effect = {
								TARGET = scope:recipient
								STAKE = syphon_treasury_gold_gain_medium
							}
							add_gold = syphon_treasury_gold_gain_medium
						}
						## Large amount.
						else_if = {
							limit = { always = scope:diarch_syphon_treasury_sum_large }
							give_or_update_embezzler_secret_effect = {
								TARGET = scope:recipient
								STAKE = syphon_treasury_gold_gain_high
							}
							add_gold = syphon_treasury_gold_gain_high
						}
						## Huge amount.
						else_if = {
							limit = { always = scope:diarch_syphon_treasury_sum_huge }
							give_or_update_embezzler_secret_effect = {
								TARGET = scope:recipient
								STAKE = syphon_treasury_gold_gain_very_high
							}
							add_gold = syphon_treasury_gold_gain_very_high
						}
					}
					## Plus the maluses for the liege.
					scope:recipient = {
						# Very high stewardship characters syphon development growth from a few counties.
						if = {
							limit = { scope:actor.stewardship >= syphon_treasury_stewardship_very_high }
							# Gold transfer was...
							## Very high.
							if = {
								limit = { always = scope:diarch_syphon_treasury_sum_huge }
								diarch_syphon_treasury_interaction_syphon_development_growth_effect = { LOSS = massive_development_progress_loss }
							}
							## High.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_large }
								diarch_syphon_treasury_interaction_syphon_development_growth_effect = { LOSS = major_development_progress_loss }
							}
							## Medium.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_medium }
								diarch_syphon_treasury_interaction_syphon_development_growth_effect = { LOSS = medium_development_progress_loss }
							}
							## Low.
							else = {
								diarch_syphon_treasury_interaction_syphon_development_growth_effect = { LOSS = minor_development_progress_loss }
							}
						}
						# Alternatively, for nomadic rulers, we steal some herd
						else_if = {
							limit = { scope:actor.stewardship >= syphon_treasury_stewardship_very_high government_has_flag = government_is_nomadic }
							# Gold transfer was...
							## Very high.
							if = {
								limit = { always = scope:diarch_syphon_treasury_sum_huge }
								scope:recipient = {
									domicile ?= { change_herd = monumental_herd_loss }
								}
							}
							## High.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_large }
								scope:recipient = {
									domicile ?= { change_herd = massive_herd_loss }
								}
							}
							## Medium.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_medium }
								scope:recipient = {
									domicile ?= { change_herd = major_herd_loss }
								}
							}
							## Low.
							else = {
								scope:recipient = {
									domicile ?= { change_herd = medium_herd_loss }
								}
							}
						}
						# High stewardship characters syphon some control from various counties.
						else_if = {
							limit = { scope:actor.stewardship >= syphon_treasury_stewardship_high }
							# Gold transfer was...
							## Very high.
							if = {
								limit = { always = scope:diarch_syphon_treasury_sum_huge }
								diarch_syphon_treasury_interaction_syphon_control_effect = { LOSS = monumental_county_control_loss }
							}
							## High.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_large }
								diarch_syphon_treasury_interaction_syphon_control_effect = { LOSS = extreme_county_control_loss }
							}
							## Medium.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_medium }
								diarch_syphon_treasury_interaction_syphon_control_effect = { LOSS = major_county_control_loss }
							}
							## Low.
							else = {
								diarch_syphon_treasury_interaction_syphon_control_effect = { LOSS = medium_county_control_loss }
							}
						}
						# Medium stewardship characters syphon lots of control from one county.
						else_if = {
							limit = { scope:actor.stewardship >= syphon_treasury_stewardship_medium }
							# Gold transfer was...
							## Very high.
							if = {
								limit = { always = scope:diarch_syphon_treasury_sum_huge }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = {
										this != scope:recipient.capital_county
									}
									alternative_limit = { always = yes }
									change_county_control = monumental_county_control_loss
								}
							}
							## High.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_large }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = {
										this != scope:recipient.capital_county
									}
									alternative_limit = { always = yes }
									change_county_control = extreme_county_control_loss
								}
							}
							## Medium.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_medium }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = {
										this != scope:recipient.capital_county
									}
									alternative_limit = { always = yes }
									change_county_control = major_county_control_loss
								}
							}
							## Low.
							else = {
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = {
										this != scope:recipient.capital_county
									}
									alternative_limit = { always = yes }
									change_county_control = medium_county_control_loss
								}
							}
						}
						# Low stewardship characters apply county modifiers.
						else = {
							# Gold transfer was...
							## Very high.
							if = {
								limit = { always = scope:diarch_syphon_treasury_sum_huge }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = { diarch_syphon_treasury_embezzlement_modifiers_trigger = no }
									add_county_modifier = {
										modifier = syphon_treasury_massive_sum_modifier
										years = 5
									}
								}
							}
							## High.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_large }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = { diarch_syphon_treasury_embezzlement_modifiers_trigger = no }
									add_county_modifier = {
										modifier = syphon_treasury_large_sum_modifier
										years = 5
									}
								}
							}
							## Medium.
							else_if = {
								limit = { always = scope:diarch_syphon_treasury_sum_medium }
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = { diarch_syphon_treasury_embezzlement_modifiers_trigger = no }
									add_county_modifier = {
										modifier = syphon_treasury_medium_sum_modifier
										years = 5
									}
								}
							}
							## Low.
							else = {
								random_held_county = {
									# Try to prefer against the capital, as that's more noticeable.
									limit = { diarch_syphon_treasury_embezzlement_modifiers_trigger = no }
									add_county_modifier = {
										modifier = syphon_treasury_small_sum_modifier
										years = 5
									}
								}
							}
						}
					}
				}
				# Defeat! No gold, just strife & a crime opinion.
				50 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					# Malus for higher amounts.
					modifier = {
						add = 25
						always = scope:diarch_syphon_treasury_sum_large
					}
					# Chungus malus for chungus higher amounts.
					modifier = {
						add = 100
						always = scope:diarch_syphon_treasury_sum_huge
					}
					# You can always fail.
					min = 20
					desc = diarch_syphon_treasury_interaction.tt.failure.actor
					send_interface_toast = {
						type = event_toast_effect_bad
						title = diarch_syphon_treasury_interaction.tt.failure.actor
						left_icon = scope:recipient
						show_as_tooltip = { diarch_syphon_treasury_interaction_caught_embezzling_effect = yes }
					}
					hidden_effect = {
						scope:recipient = {
							send_interface_toast = {
								type = event_toast_effect_neutral
								title = diarch_syphon_treasury_interaction.tt.failure.recipient
								left_icon = scope:actor
								diarch_syphon_treasury_interaction_caught_embezzling_effect = yes
							}
						}
					}
				}
			}
		}

		# Debug logging.
		debug_log = debug_log.syphon_treasury.attempt_made
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		is_diarch = yes
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
		# Honest and generous characters never embezzle.
		NOR = {
			has_trait = honest
			has_trait = generous
		}
	}

	ai_will_do = {
		# Embezzlement is serious, so you need actual reasons for it.
		base = 0

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_boldness = 0.25
			ai_greed = 1
			ai_honor = -0.5
		}
		## Flag Management.
		### The AI never goes for a huge sum, that's just there to tempt the player.
		### We prefer a large sum if we've got a massive skill disparity.
		modifier = {
			add = 100
			scope:diarch_syphon_treasury_sum_large = yes
			stewardship_diff = {
				target = scope:recipient
				value >= @ai_skill_diff_upper_threshold
			}
		}
		### But a moderate sum does well if we're more evenly matched.
		modifier = {
			add = 50
			scope:diarch_syphon_treasury_sum_medium = yes
			stewardship_diff = {
				target = scope:recipient
				value < @ai_skill_diff_upper_threshold
			}
			stewardship_diff = {
				target = scope:recipient
				value >= @ai_skill_diff_lower_threshold
			}
		}
		### Aaaand otherwise we'll accept a small amount.
		modifier = {
			add = 25
			scope:diarch_syphon_treasury_sum_small = yes
			stewardship_diff = {
				target = scope:recipient
				value < @ai_skill_diff_lower_threshold
			}
		}
		## Less likely in tribal societies with less bookwork to hide theft in.
		modifier = {
			add = -50
			scope:recipient = { government_has_flag = government_is_tribal }
		}
		## Debt is a great motivator for theft.
		### Is slightly in debt.
		modifier = {
			add = 10
			debt_level = 1
		}
		### Is one year in debt.
		modifier = {
			add = 25
			debt_level = 2
		}
		### Is two years in debt.
		modifier = {
			add = 40
			debt_level = 3
		}
		### Is three years in debt.
		modifier = {
			add = 60
			debt_level = 4
		}
		### Is four years in debt.
		modifier = {
			add = 100
			debt_level = 5
		}
		### Is over five years in debt.
		modifier = {
			add = 200
			debt_level >= 6
		}
		## Certain traits can affect likelihood directly.
		### It's intentional that these don't sync up value-wise with their opposite traits.
		### Honest/generous excluded because they're hard locked out of the interaction for the AI.
		### +++ Greedy.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = greedy
		}
		### ++ Deceitful.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = deceitful
		}
		### + Arbitrary.
		modifier = {
			add = diarch_ai_desire_plus_1_value
			has_trait = arbitrary
		}
		### -- Just.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = just
		}
		## Skill considerations.
		### Very low negative comparative stewardship.
		modifier = {
			add = -50
			stewardship_diff = {
				target = scope:recipient
				value <= 10
			}
			# Filter out arrogant characters, who can't believe they suck.
			NOT = { has_trait = arrogant }
		}
		### Low negative comparative stewardship.
		modifier = {
			add = -25
			stewardship_diff = {
				target = scope:recipient
				value <= 5
			}
			# Filter out arrogant characters, who can't believe they suck.
			NOT = { has_trait = arrogant }
		}
		### High positive comparative stewardship.
		modifier = {
			add = 25
			stewardship_diff = {
				target = scope:recipient
				value >= 5
			}
			# Filter out humble characters, who give their liege too much credit.
			NOT = { has_trait = humble }
		}
		### Very high positive comparative stewardship.
		modifier = {
			add = 50
			stewardship_diff = {
				target = scope:recipient
				value >= 10
			}
			# Filter out humble characters, who give their liege too much credit.
			NOT = { has_trait = humble }
		}
		# Factors.
		## + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## We're happy to bully players here, since we're not taking their land.
	}
}

# Diarch (actor) either tests diplomacy or spends prestige to give negative modifiers to the lands of a vassal of their liege (secondary recipient), who can't resist.
diarch_shift_privileges_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	icon = icon_shift_privileges
	common_interaction = yes

	ai_intermediary_maybe = yes
	desc = diarch_shift_privileges_interaction_desc

	popup_on_receive = yes

	interface_priority = 285

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
			liege = { has_diarchy_parameter = unlock_shift_privileges_interaction }
		}
		# Make sure scope:recipient is suitable.
		scope:recipient = {
			# We only target vassals of the liege...
			liege = scope:actor.liege
			this != scope:actor.liege
			# ... who are appropriately landed.
			is_landed_or_landless_administrative = yes
			scope:recipient.highest_held_title_tier >= tier_county
		}
	}

	is_valid_showing_failures_only = {
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Diarch revocations require a claim.
		custom_tooltip = {
			text = diarch_shift_privileges_interaction.tt.no_affectable_counties
			scope:recipient = {
				any_held_county = { diarch_shift_privileges_valid_target_title_trigger = yes }
			}
		}
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_an_entrenched_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege = { has_diarchy_active_parameter = unlock_shift_privileges_interaction }
		}
		# Must select something.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:diarch_shift_privileges_interaction_duel_diplomacy = yes
					scope:diarch_shift_privileges_interaction_pay_prestige_partial = yes
					scope:diarch_shift_privileges_interaction_pay_prestige_full = yes
				}
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	cooldown = { months = 6 }
	cooldown_against_recipient = { years = 3 }

	# Attempt Methods
	send_options_exclusive = yes
	## Duel for it.
	send_option = {
		# You can always try to duel for it.
		flag = diarch_shift_privileges_interaction_duel_diplomacy
	}
	## Pay partial prestige.
	send_option = {
		is_valid = {
			scope:actor = {
				prestige >= {
					value = shift_privileges_interaction_target_discounted_cost_value
					multiply = -1
				}
			}
		}
		flag = diarch_shift_privileges_interaction_pay_prestige_partial
	}
	## Pay full prestige.
	send_option = {
		is_valid = {
			scope:actor = {
				prestige >= {
					value = shift_privileges_interaction_target_cost_value
					multiply = -1
				}
			}
		}
		flag = diarch_shift_privileges_interaction_pay_prestige_full
	}

	on_send = {
		# Did a landless diarch send this?
		log_diarch_send_interaction_as_variable_effect = { INTERACTION = shift_privileges }
	}

	on_accept = {
		scope:actor = {
			# Resolution method.
			## If we're duelling, then we duel.
			if = {
				limit = { scope:diarch_shift_privileges_interaction_duel_diplomacy = yes }
				# Now: FIGHT! WITH WORDS!
				duel = {
					skill = diplomacy
					target = scope:recipient
					# Victory! Cash for you, negative modifier for your opponent.
					50 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = 3.5
							min = -49
						}
						desc = diarch_shift_privileges_interaction.tt.success
						diarch_shift_privileges_interaction_apply_success_effect = yes
					}
					# Defeat! Into the loser's bin you go.
					50 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = -3.5
							min = -49
						}
						desc = diarch_shift_privileges_interaction.tt.failure
						diarch_shift_privileges_interaction_apply_fail_effect = yes
					}
				}
			}
			## Otherwise we can take an even gamble against a reduced prestige cost..
			else_if = {
				limit = { scope:diarch_shift_privileges_interaction_pay_prestige_partial = yes }
				random_list = {
					# Victory! A claim for you.
					100 = {
						desc = diarch_shift_privileges_interaction.tt.success
						diarch_shift_privileges_interaction_apply_success_effect = yes
					}
					# Defeat! Into the loser's bin you go.
					100 = {
						desc = diarch_shift_privileges_interaction.tt.failure
						diarch_shift_privileges_interaction_apply_fail_effect = yes
					}
				}
			}
			## Or pay the full price.
			else = {
				custom_tooltip = diarch_shift_privileges_interaction.tt.success
				diarch_shift_privileges_interaction_apply_success_effect = yes
			}
			# Prestige costs.
			## Point out the lack of cost.
			if = {
				limit = { scope:diarch_shift_privileges_interaction_duel_diplomacy = yes }
				custom_tooltip = diarch_interaction_pay_prestige_none
			}
			## Point out the discount.
			else_if = {
				limit = { scope:diarch_shift_privileges_interaction_pay_prestige_partial = yes }
				add_prestige = shift_privileges_interaction_target_discounted_cost_value
			}
			## Soz mate, yerr payin' full price.
			else = { add_prestige = shift_privileges_interaction_target_cost_value }
			tgp_activate_catalyst_against_hegemon_effect = {
				HEGEMON = scope:actor.top_liege
				CATALYST = catalyst_diarch_mandate
			}
		}

		# Debug logging.
		debug_log = debug_log.shift_privileges.attempt_made
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = peer_vassals }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_potential = {
		is_diarch = yes
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_secondary_powers_base_value

		# Additions.
		## Weight for opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		## Weight for personality.
		ai_value_modifier = {
			ai_boldness = 0.25
			ai_greed = 0.5
			ai_honor = 0.5
		}
		## Flag Management.
		### Duel for it if we're massively superior.
		modifier = {
			add = 100
			scope:diarch_shift_privileges_interaction_duel_diplomacy = yes
			diplomacy_diff = {
				target = scope:recipient
				value >= @ai_skill_diff_upper_threshold
			}
		}
		### Else we'll try to pay full prestige, if we've got lots to spare.
		modifier = {
			add = 50
			scope:diarch_shift_privileges_interaction_pay_prestige_full = yes
			prestige >= {
				value = shift_privileges_interaction_target_cost_value
				multiply = @ai_prestige_bank_threshold
			}
		}
		### Or else we'll chance it, if we can afford that + some slack.
		modifier = {
			add = 25
			scope:diarch_shift_privileges_interaction_pay_prestige_partial = yes
			prestige < {
				value = shift_privileges_interaction_target_cost_value
				multiply = @ai_prestige_bank_threshold
			}
			prestige >= {
				value = shift_privileges_interaction_target_discounted_cost_value
				multiply = @ai_prestige_bank_threshold
			}
		}
		### Otherwise we'll risk a regular duel.
		## Landless AI want to do this more.
		modifier = {
			add = 25
			is_ruler = no
		}
		## AI who are in debt seek ways out of it.
		modifier = {
			add = 100
			debt_level >= 0
		}
		## Certain traits make it either very likely or very unlikely.
		### +++ Arbitrary.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = arbitrary
		}
		### --- Just.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			has_trait = just
		}
		# Factors.
		## + Do pick on people we hate.
		modifier = {
			factor = 1.5
			should_prioritise_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## - Try not to pick on allies of our liege.
		modifier = {
			factor = 0.25
			should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## x0 Don't pick on our friends or allies.
		modifier = {
			factor = 0
			should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
		## x0 Don't pick on players unless they're of at least a decent size.
		modifier = {
			factor = 0
			scope:recipient = {
				is_ai = no
				any_held_county = { count <= 3 }
			}
		}
		### x0 Don't go into prestige debt!
		modifier = {
			factor = 0
			prestige < 0
		}
	}
}

# Diarch (actor) requests use of a special CB from liege (recipient), allowing them to powerfully expand the empire's borders and harvest influence.
diarch_request_imperial_expedition_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	notification_text = DIARCH_REQUESTS_IMPERIAL_EXPEDITION
	icon = invasion
	interface_priority = 5

	desc = diarch_request_imperial_expedition_interaction_desc

	ai_maybe = yes
	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			liege = { has_diarchy_parameter = unlock_diarch_requests_military_expedition_interaction }
		}
		# Same sub-realm only.
		OR = {
			scope:actor.liege = scope:recipient
			scope:recipient = {
				any_liege_or_above = { this = scope:actor.liege }
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = unlock_diarch_requests_military_expedition_interaction }
		# And you have to have _some_ troops of your own.
		custom_tooltip = {
			text = diarch_request_imperial_expedition_interaction.tt.minimum_troop_count
			scope:actor.max_military_strength >= request_imperial_expedition_minimum_troop_count_value
		}
		# _And_ you don't already have a charge.
		custom_tooltip = {
			text = diarch_request_imperial_expedition_interaction.tt.actor_already_has_charge
			scope:actor = {
				NOT = { has_variable = imperial_expedition_charged }
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	# Hefty cooldown on this guy, as you shouldn't be able to do these often.
	cooldown_against_recipient = { years = 25 }

	cost = {
		influence = {
			if = {
				limit = { scope:influence_major = yes }
				add = request_imperial_expedition_influence_stake_major_value
			}
			else_if = {
				limit = { scope:influence_medium = yes }
				add = request_imperial_expedition_influence_stake_medium_value
			}
			else_if = {
				limit = { scope:influence_minor = yes }
				add = request_imperial_expedition_influence_stake_minor_value
			}
		}
	}

	# How much influence do we want to outlay on this?
	## A cheapy amount.
	send_option = {
		# Always valid.
		flag = influence_minor
		localization = diarch_request_imperial_expedition_interaction.tt.influence_minor_name
	}
	## A medium amount.
	send_option = {
		is_valid = { scope:actor.influence >= request_imperial_expedition_influence_stake_medium_value }
		flag = influence_medium
		localization = diarch_request_imperial_expedition_interaction.tt.influence_medium_name
	}
	## A large amount.
	send_option = {
		is_valid = { scope:actor.influence >= request_imperial_expedition_influence_stake_major_value }
		flag = influence_major
		localization = diarch_request_imperial_expedition_interaction.tt.influence_major_name
	}
	## Use a hook instead.
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_auto_accept = {
		# Fire the notification event telling scope:recipient what's been done.
		scope:recipient = { trigger_event = diarchy.8003 }
	}

	on_accept = {
		scope:actor = {
			# Display effects in the interaction.
			show_as_tooltip = { diarch_request_imperial_expedition_accepted_effect = yes }
			# Fire the notification event.
			trigger_event = diarchy.8001
		}
	}

	on_decline = {
		scope:actor = {
			# Display effects in the interaction.
			show_as_tooltip = { diarch_request_imperial_expedition_rejected_effect = yes }
			# Fire the notification event.
			trigger_event = diarchy.8002
		}
	}

	auto_accept = {
		scope:recipient = {
			trigger_if = {
				limit = { scope:hook = yes }
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:recipient
					scope:hook = yes
				}
			}
			trigger_else_if = {
				limit = { scope:influence_major = yes }
				influence < request_imperial_expedition_influence_stake_major_value
			}
			trigger_else_if = {
				limit = { scope:influence_medium = yes }
				influence < request_imperial_expedition_influence_stake_medium_value
			}
			trigger_else_if = {
				limit = { scope:influence_minor = yes }
				influence < request_imperial_expedition_influence_stake_minor_value
			}
			trigger_else = { always = no }
		}
	}

	ai_accept = {
		base = -25

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		# Your level of influence.
		## Impotent
		modifier = {
			add = -10
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPOTENT
			scope:actor.influence_level = 0
		}
		## Influential
		### Would be zero, so it wouldn't appear.
		## Persuasive
		modifier = {
			add = 10
			desc = AI_OPINION_INFLUENCE_LEVEL_PERSUASIVE
			scope:actor.influence_level = 2
		}
		## Controlling
		modifier = {
			add = 20
			desc = AI_OPINION_INFLUENCE_LEVEL_CONTROLLING
			scope:actor.influence_level = 3
		}
		## Authoritative
		modifier = {
			add = 30
			desc = AI_OPINION_INFLUENCE_LEVEL_AUTHORITATIVE
			scope:actor.influence_level = 4
		}
		## Imperious
		modifier = {
			add = 40
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPERIOUS
			scope:actor.influence_level = 5
		}
		# Traits.
		## ---- Paranoid
		modifier = {
			add = -50
			desc = ai_acceptance_trait_paranoid
			scope:recipient = { has_trait = paranoid }
		}
		## --- Stubborn
		modifier = {
			add = -30
			desc = ai_acceptance_trait_stubborn
			scope:recipient = { has_trait = stubborn }
		}
		## --- Content
		modifier = {
			add = -30
			desc = ai_acceptance_trait_content
			scope:recipient = { has_trait = content }
		}
		## - Humble
		modifier = {
			add = -10
			desc = ai_acceptance_trait_humble
			scope:recipient = { has_trait = humble }
		}
		## + Arrogant
		modifier = {
			add = 10
			desc = ai_acceptance_trait_arrogant
			scope:recipient = { has_trait = arrogant }
		}
		## + Ambitious
		modifier = {
			add = 10
			desc = ai_acceptance_trait_ambitious
			scope:recipient = { has_trait = ambitious }
		}
		## ++ Trusting
		modifier = {
			add = 20
			desc = ai_acceptance_trait_trusting
			scope:recipient = { has_trait = trusting }
		}
		## ++ Fickle
		modifier = {
			add = 20
			desc = ai_acceptance_trait_fickle
			scope:recipient = { has_trait = fickle }
		}
		## ++ Lazy
		modifier = {
			add = 20
			desc = ai_acceptance_trait_lazy
			scope:recipient = { has_trait = lazy }
		}
		## +++ Craven
		modifier = {
			add = 30
			desc = ai_acceptance_trait_craven
			scope:recipient = { has_trait = craven }
		}
		# Factor for personality.
		ai_value_modifier = {
			who = scope:recipient
			# The meeker they are, the more they'll go along with your wishes.
			ai_boldness = {
				if = {
					limit = {
						scope:recipient = {
							NOT = { ai_boldness = 0 }
						}
					}
					value = -1
				}
			}
			# And the lazier.
			ai_energy = {
				if = {
					limit = {
						scope:recipient = { ai_energy > 0 }
					}
					value = 0.5
				}
			}
		}
	}

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}
	ai_potential = {
		is_diarch = yes
		liege = { has_diarchy_active_parameter = unlock_diarch_requests_military_expedition_interaction }
		NOR = {
			has_trait = craven
			has_trait = lazy
			has_trait = content
		}
	}

	ai_will_do = {
		base = -50

		# Personality.
		ai_value_modifier = {
			ai_energy = 2
			ai_boldness = 1
			ai_greed = 1
		}
		# Traits.
		## Brave
		modifier = {
			add = 25
			has_trait = brave
		}
		## Ambitious
		modifier = {
			add = 50
			has_trait = ambitious
		}
		## Arrogant
		modifier = {
			add = 25
			has_trait = arrogant
		}
		## Loyal & Disloyal (same result, different motivations)
		modifier = {
			add = 25
			OR = {
				has_trait = loyal
				has_trait = disloyal
			}
		}
		## Diligent
		modifier = {
			add = 25
			has_trait = diligent
		}
		## We've already filtered out craven, lazy, & content by this point.
		# Military.
		## For every thousand troops we can put in ourselves, make us more likely to ask.
		modifier = {
			add = {
				value = scope:actor.max_military_strength
				divide = 100
				floor = yes
			}
			always = yes
		}
		# Flag Management.
		## Make sure the AI uses hooks for this as it's % based
		modifier = {
			add = 1
			scope:hook = yes
		}
		## Otherwise, try to spend the most influence possible whenever we can.
		modifier = {
			add = 3
			scope:influence_minor = yes
		}
		modifier = {
			add = 2
			scope:influence_medium = yes
		}
		modifier = {
			add = 1
			scope:influence_major = yes
		}
	}
}

# Diarch (actor) requests a kingdom governor title from liege (recipient).
diarch_demand_despotate_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	notification_text = DIARCH_DEMANDS_DESPOTATE
	icon = icon_found_despotate
	interface_priority = 15

	desc = diarch_demand_despotate_interaction_desc

	target_type = title
	target_filter = secondary_recipient_de_jure_titles
	can_be_picked_title = {
		scope:target = { valid_kingdom_for_diarch_to_demand_as_despotate_trigger = yes }
	}
	has_valid_target_showing_failures_only = {
		# Only show kingdoms.
		scope:target.tier = tier_kingdom
		# Don't show the empire's capital kingdom.
		NOT = {
			scope:recipient.capital_county = { target_is_de_jure_liege_or_above = scope:target }
		}
	}
	# We do this via redirects because recipient_de_jure_titles did not turn up for work today.
	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
	}
	ai_maybe = yes
	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			liege = { has_diarchy_parameter = unlock_diarch_demand_kingdom_interaction }
		}
		# Same sub-realm only.
		OR = {
			scope:actor.liege = scope:recipient
			scope:recipient = {
				any_liege_or_above = { this = scope:actor.liege }
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = unlock_diarch_demand_kingdom_interaction }
		# You do not already have a kingdom tier title
		custom_tooltip = {
			text = diarch_demand_despotate_interaction.tt.already_have_high_titles
			scope:actor.highest_held_title_tier < tier_kingdom
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	# Hefty cooldown on this guy, as you shouldn't be able to pester about this often.
	cooldown_against_recipient = { years = 25 }

	cost = {
		influence = {
			if = {
				limit = { scope:influence_major = yes }
				add = diarch_demand_despotate_interaction_stake_major_value
			}
			else_if = {
				limit = { scope:influence_medium = yes }
				add = diarch_demand_despotate_interaction_stake_medium_value
			}
			else_if = {
				limit = { scope:influence_minor = yes }
				add = diarch_demand_despotate_interaction_stake_minor_value
			}
		}
	}

	# How much influence do we want to outlay on this?
	## A cheapy amount.
	send_option = {
		# Always valid.
		flag = influence_minor
		localization = diarch_demand_despotate_interaction.tt.influence_minor_name
	}
	## A medium amount.
	send_option = {
		is_valid = { scope:actor.influence >= diarch_demand_despotate_interaction_stake_medium_value }
		flag = influence_medium
		localization = diarch_demand_despotate_interaction.tt.influence_medium_name
	}
	## A large amount.
	send_option = {
		is_valid = { scope:actor.influence >= diarch_demand_despotate_interaction_stake_major_value }
		flag = influence_major
		localization = diarch_demand_despotate_interaction.tt.influence_major_name
	}
	## Use a hook instead.
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = hook
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_auto_accept = {
		# Fire the notification event telling scope:recipient what's been done.
		scope:recipient = { trigger_event = diarchy.8033 }
	}

	on_accept = {
		# Notify the player of how to force their liege's hand.
		if = {
			limit = {
				scope:influence_major = yes
				scope:recipient.influence >= diarch_demand_despotate_interaction_stake_to_raise_major_inverted_value
			}
			custom_tooltip = diarch_demand_despotate_interaction_stake_to_raise_major_value.tt.liege_can_refuse
		}
		else_if = {
			limit = {
				scope:influence_medium = yes
				scope:recipient.influence >= diarch_demand_despotate_interaction_stake_to_raise_medium_inverted_value
			}
			custom_tooltip = diarch_demand_despotate_interaction_stake_to_raise_medium_value.tt.liege_can_refuse
		}
		else_if = {
			limit = {
				scope:influence_minor = yes
				scope:recipient.influence >= diarch_demand_despotate_interaction_stake_to_raise_minor_inverted_value
			}
			custom_tooltip = diarch_demand_despotate_interaction_stake_to_raise_minor_value.tt.liege_can_refuse
		}
		scope:actor = {
			# Display effects in the interaction.
			show_as_tooltip = { diarch_demand_despotate_interaction_accepted_effect = yes }
			# Fire the notification event.
			trigger_event = diarchy.8031
		}
	}

	on_decline = {
		scope:actor = {
			# Display effects in the interaction.
			show_as_tooltip = { diarch_demand_despotate_interaction_rejected_effect = yes }
			# Fire the notification event.
			trigger_event = diarchy.8032
		}
	}

	auto_accept = {
		scope:recipient = {
			trigger_if = {
				limit = { scope:hook = yes }
				custom_description = {
					text = "spending_hook"
					subject = scope:actor
					object = scope:recipient
					scope:hook = yes
				}
			}
			trigger_else_if = {
				limit = { scope:influence_major = yes }
				influence < diarch_demand_despotate_interaction_stake_to_raise_major_inverted_value
			}
			trigger_else_if = {
				limit = { scope:influence_medium = yes }
				influence < diarch_demand_despotate_interaction_stake_to_raise_medium_inverted_value
			}
			trigger_else_if = {
				limit = { scope:influence_minor = yes }
				influence < diarch_demand_despotate_interaction_stake_to_raise_minor_inverted_value
			}
			trigger_else = { always = no }
		}
	}

	ai_accept = {
		base = -50

		# Opinion Factor
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		# Your level of influence.
		## Impotent
		modifier = {
			add = -10
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPOTENT
			scope:actor.influence_level = 0
		}
		## Influential
		### Would be zero, so it wouldn't appear.
		## Persuasive
		modifier = {
			add = 10
			desc = AI_OPINION_INFLUENCE_LEVEL_PERSUASIVE
			scope:actor.influence_level = 2
		}
		## Controlling
		modifier = {
			add = 20
			desc = AI_OPINION_INFLUENCE_LEVEL_CONTROLLING
			scope:actor.influence_level = 3
		}
		## Authoritative
		modifier = {
			add = 30
			desc = AI_OPINION_INFLUENCE_LEVEL_AUTHORITATIVE
			scope:actor.influence_level = 4
		}
		## Imperious
		modifier = {
			add = 40
			desc = AI_OPINION_INFLUENCE_LEVEL_IMPERIOUS
			scope:actor.influence_level = 5
		}
		# Traits.
		## ---- Paranoid
		modifier = {
			add = -50
			desc = ai_acceptance_trait_paranoid
			scope:recipient = { has_trait = paranoid }
		}
		## --- Stubborn
		modifier = {
			add = -30
			desc = ai_acceptance_trait_stubborn
			scope:recipient = { has_trait = stubborn }
		}
		## --- Greedy
		modifier = {
			add = -30
			desc = ai_acceptance_trait_greedy
			scope:recipient = { has_trait = greedy }
		}
		## -- Arrogant
		modifier = {
			add = -20
			desc = ai_acceptance_trait_arrogant
			scope:recipient = { has_trait = arrogant }
		}
		## ++ Humble
		modifier = {
			add = 20
			desc = ai_acceptance_trait_humble
			scope:recipient = { has_trait = humble }
		}
		## ++ Trusting
		modifier = {
			add = 20
			desc = ai_acceptance_trait_trusting
			scope:recipient = { has_trait = trusting }
		}
		## ++ Fickle
		modifier = {
			add = 20
			desc = ai_acceptance_trait_fickle
			scope:recipient = { has_trait = fickle }
		}
		## ++ Lazy
		modifier = {
			add = 20
			desc = ai_acceptance_trait_lazy
			scope:recipient = { has_trait = lazy }
		}
		## ++ Generous
		modifier = {
			add = 20
			desc = ai_acceptance_trait_generous
			scope:recipient = { has_trait = generous }
		}
		# Factor for personality.
		ai_value_modifier = {
			who = scope:recipient
			# The meeker they are, the more they'll go along with your wishes.
			ai_boldness = {
				if = {
					limit = {
						scope:recipient = {
							NOT = { ai_boldness = 0 }
						}
					}
					value = -1
				}
			}
			# And the lazier.
			ai_energy = {
				if = {
					limit = {
						scope:recipient = { ai_energy > 0 }
					}
					value = 0.5
				}
			}
		}
	}

	# AI
	ai_set_target = {
		scope:recipient = {
			# Grab our empires.
			every_held_title = {
				title_tier >= empire
				add_to_list = empires_list
			}
			# Then from that, formulate our kingdoms.
			every_in_list = {
				list = empires_list
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_kingdom
						valid_kingdom_for_diarch_to_demand_as_despotate_trigger = yes
					}
					continue = { tier >= tier_kingdom }
					add_to_list = kingdoms_list
				}
			}
			# Now pick our best shot.
			ordered_in_list = {
				list = kingdoms_list
				order_by = {
					# Tell the AI to grab its own kingdom first of all.
					if = {
						limit = { this = scope:actor.capital_county.kingdom }
						add = 1000
					}
					# Otherwise, go for the biggest within the empire.
					else = {
						every_de_jure_county_holder = {
							limit = { top_liege = scope:recipient }
							add = 1
						}
					}
				}
				save_scope_as = target
			}
		}
	}
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 24
		hegemony = 24
	}
	ai_potential = {
		is_diarch = yes
		liege = { has_diarchy_active_parameter = unlock_diarch_demand_kingdom_interaction }
		NOR = {
			has_trait = humble
			has_trait = content
		}
		# Loyal diarchs don't ask for what their liege could give freely.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		base = 25

		# Personality.
		ai_value_modifier = {
			ai_greed = 1
			ai_boldness = 1
			ai_energy = 0.25
		}
		# Opinion.
		## The more we like our emperor, the less likely we are to want to interfere in their planned setup.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -0.25
		}
		# Traits.
		## +++ Ambitious.
		modifier = {
			add = 50
			has_trait = ambitious
		}
		## +++ Arrogant.
		modifier = {
			add = 50
			has_trait = arrogant
		}
		## ++ Greedy.
		modifier = {
			add = 25
			has_trait = greedy
		}
		## ++ Diligent.
		modifier = {
			add = 25
			has_trait = diligent
		}
		## -- Generous.
		modifier = {
			add = -25
			has_trait = generous
		}
		## --- Lazy.
		modifier = {
			add = -50
			has_trait = lazy
		}
		## Humble & Content have both been pre-filtered out.
		# Flag Management.
		## Make sure the AI uses hooks for this as it's % based
		modifier = {
			add = 4
			scope:hook = yes
		}
		## Otherwise, try to spend the most influence possible whenever we can.
		modifier = {
			add = 3
			scope:influence_minor = yes
		}
		modifier = {
			add = 2
			scope:influence_medium = yes
		}
		modifier = {
			add = 1
			scope:influence_major = yes
		}
	}
}










##################################################
# DIARCH COUP LIEGE INTERACTIONS

diarch_coup_liege_interaction = {
	category = interaction_category_diarch
	diarch_interaction = yes
	icon = icon_scheme_claim_throne
	interface_priority = 50
	pre_answer_no_breakdown_key = diarch_coup_liege_interaction_pre_answer_no_breakdown_key
	pre_answer_yes_breakdown_key = diarch_coup_liege_interaction_pre_answer_yes_breakdown_key

	desc = diarch_coup_liege_interaction_desc

	# First, grab every other powerful vassal of your liege & plonk them in a list.
	populate_recipient_list = {
		scope:actor.liege = {
			every_powerful_vassal = {
				limit = {
					this != scope:actor
				}
				add_to_list = characters
			}
			every_powerful_family = {
				limit = {
					NOR = {
						house_head = scope:actor
						house_head = scope:recipient
					}
				}
				house_head = { add_to_list = characters }
			}
		}
	}
	redirect = {
		# Turn the old scope:recipient into the target.
		if = {
			limit = {
				NOR = {
					scope:recipient = scope:actor
					scope:recipient = scope:actor.liege
				}
			}
			scope:recipient = {
				save_scope_as = secondary_recipient
			}
		}
		# Always make sure we're targeting your liege as the recipient for UX consistency.
		scope:actor.liege = {
			save_scope_as = recipient
		}
	}

	is_shown = {
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			OR = {
				AND = {
					exists = liege
					is_diarch_of_target = liege
				}
				is_designated_diarch = yes
			}
		}
		# secondary_recipient is always saved whenever you use it on anyone who isn't yourself or your liege, so we use this fact to validate it after the redirect, otherwise it will show up on every other ruler in the game
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient.liege ?= scope:actor.liege
		}
	}

	is_valid_showing_failures_only = {
		# Diarch must be able to act.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		# Loyalty hooks, per the name, will tend to block this.
		custom_tooltip = {
			text = diarch_coup_liege_interaction.tt.action_blocked_by_loyalty_hook
			NOT = {
				diarch_loyalty_due_to_hook_trigger = {
					LIEGE = scope:recipient
					DIARCH = scope:actor
				}
			}
		}
		# They can't already be in the list.
		custom_tooltip = {
			text = diarch_coup_liege_interaction.tt.secondary_recipient_is_already_in_list
			NOT = {
				scope:actor = {
					any_in_list = {
						variable = coup_pv_supporters_list
						this = scope:secondary_recipient
					}
				}
			}
		}
		# Must be in an actual diarchy — we show most interactions greyed out for designated diarchs.
		custom_tooltip = {
			text = diarch_interactions.tt.you_must_be_in_an_entrenched_regency_to_access
			scope:actor = { is_diarch = yes }
		}
		# And, relatedly, there's some checks that we don't show you unless you *are* already in a diarchy.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch = yes }
			}
			# Diarchs must have unlocked the appropriate power.
			scope:actor.liege ?= { has_diarchy_active_parameter = regents_can_try_to_overthrow_present_lieges }
		}
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			# Must be available.
			## So no kids.
			scope:secondary_recipient = { is_adult = yes }
			## & no one in prison.
			scope:secondary_recipient = { is_imprisoned = no }
			# Plus, currently, humans can't be part of these plots.
			scope:secondary_recipient = { is_ai = yes }
		}
		# Must select something — tooltips'll knacker otherwise + just for consistency.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:promise_nothing = yes
					scope:promise_hook_weak = yes
					scope:promise_hook_strong = yes
					scope:promise_gold_medium = yes
					scope:promise_gold_large = yes
				}
			}
		}
		# Cannot be at war with your liege.
		NOT = {
			scope:actor = { is_at_war_with = scope:actor.liege }
		}
	}

	can_send = {
		# We check this here to make the interaction generally findable, so you can get at the list easily, but prevent you from inviting randos to the coup.
		## It's actually technically harmless - they won't help but don't get their payout if they're not powerful when the coup hits.
		trigger_if = {
			limit = {
				scope:recipient = { government_has_flag = government_has_powerful_families }
			}
			scope:secondary_recipient.house = { is_powerful_family = yes }
		}
		trigger_else = {
			scope:secondary_recipient = { is_powerful_vassal = yes }
		}
	}

	# Promise bugger all.
	send_option = {
		flag = promise_nothing
		localization = PROMISE_NOTHING
	}
	# Promise hook.
	send_option = {
		is_valid = {
			# Can't offer a hook if they've already got any type of hook on you.
			NOT = {
				scope:secondary_recipient ?= { has_hook = scope:actor }
			}
		}
		flag = promise_hook_weak
		localization = PROMISE_HOOK_WEAK
	}
	# Promise strong hook.
	send_option = {
		is_valid = {
			# Can't offer a strong hook if they've already got a strong hook on you.
			NOT = {
				scope:secondary_recipient ?= { has_strong_hook = scope:actor }
			}
		}
		flag = promise_hook_strong
		localization = PROMISE_HOOK_STRONG
	}
	# Promise gold.
	send_option = {
		flag = promise_gold_medium
		localization = PROMISE_GOLD_MEDIUM
	}
	# Promise piles of gold.
	send_option = {
		flag = promise_gold_large
		localization = PROMISE_GOLD_LARGE
	}

	on_accept = {
		if = {
			limit = { exists = scope:secondary_recipient }
			scope:actor = {
				# Scope:secondary_recipient joins your conspiracy.
				custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.joins_conspiracy
				## Send a notification just for a bit of extra feedback.
				send_interface_toast = {
					type = event_toast_effect_good
					title = diarch_coup_liege_interaction.tt.secondary_recipient.joins_conspiracy
					left_icon = scope:secondary_recipient
				}
				# HerHis reward is collected if you succeed.
				if = {
					limit = { scope:promise_nothing = no }
					custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.reward
				}
				# Certain scope:secondary_recipients may betray their liege in the throne room itself.
				## Chancellors in diplo coups.
				if = {
					limit = { scope:secondary_recipient ?= scope:recipient.cp:councillor_chancellor }
					custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.chancellor_sabotage
				}
				## Spymasters in intrigue coups.
				if = {
					limit = { scope:secondary_recipient ?= scope:recipient.cp:councillor_spymaster }
					custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.spymaster_sabotage
				}
				## Personal Champions in prowess coups.
				if = {
					limit = {
						scope:secondary_recipient = { has_court_position = champion_court_position }
					}
					custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.champion_sabotage
					# Yes, there are other candidates, but we're not tooltipping every conceivable case. Rulers are gonna have supporters.
					custom_tooltip = diarch_coup_liege_interaction.tt.secondary_recipient.champion_sabotage.others
				}
				# Right, actually record them.
				## Including in the variable.
				add_to_variable_list = {
					name = coup_pv_supporters_list
					target = scope:secondary_recipient
				}
				## And their promised payment, if anything.
				### Weak hooks.
				if = {
					limit = { scope:promise_hook_weak = yes }
					add_to_variable_list = {
						name = coup_promise_list_weak_hook
						target = scope:secondary_recipient
					}
				}
				### Strong hooks.
				else_if = {
					limit = { scope:promise_hook_strong = yes }
					add_to_variable_list = {
						name = coup_promise_list_strong_hook
						target = scope:secondary_recipient
					}
				}
				### Cash.
				else_if = {
					limit = { scope:promise_gold_medium = yes }
					add_to_variable_list = {
						name = coup_promise_list_gold
						target = scope:secondary_recipient
					}
				}
				### Big Cash.
				else_if = {
					limit = { scope:promise_gold_large = yes }
					add_to_variable_list = {
						name = coup_promise_list_big_gold
						target = scope:secondary_recipient
					}
				}
				tgp_activate_catalyst_against_hegemon_effect = {
					HEGEMON = scope:actor.top_liege
					CATALYST = catalyst_diarch_mandate
				}
			}
		}
	}

	# Disguise the interaction from players.
	ai_min_reply_days = 0
	ai_max_reply_days = 0

	ai_accept = {
		# Base reluctance to commit to a risky, treasonous plan.
		base = -50

		# Opinion.
		## Of scope:actor.
		opinion_modifier = {
			trigger = {
				exists = scope:secondary_recipient # because the secondary_recipient hasn't been chosen when the interaction is initialized
			}
			who = scope:secondary_recipient
			opinion_target = scope:actor
			multiplier = 1
		}
		## Of scope:recipient.
		opinion_modifier = {
			trigger = {
				exists = scope:secondary_recipient
			}
			who = scope:secondary_recipient
			opinion_target = scope:recipient
			multiplier = -0.5
		}
		# Personality.
		## Values.
		ai_value_modifier = {
			trigger = {
				exists = scope:secondary_recipient
			}
			who = scope:secondary_recipient
			ai_honor = -1
			ai_boldness = 0.25
		}
		## Traits.
		### +++ Disloyal.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.disloyal
			scope:secondary_recipient ?= { has_trait = disloyal }
		}
		### +++ Ambitious.
		modifier = {
			add = diarch_ai_desire_plus_3_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.ambitious
			scope:secondary_recipient ?= { has_trait = ambitious }
		}
		### ++ Arbitrary.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.arbitrary
			scope:secondary_recipient ?= { has_trait = arbitrary }
		}
		### + Fickle.
		modifier = {
			add = diarch_ai_desire_plus_1_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.fickle
			scope:secondary_recipient ?= { has_trait = fickle }
		}
		### - Stubborn.
		modifier = {
			add = diarch_ai_desire_minus_1_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.stubborn
			scope:secondary_recipient ?= { has_trait = stubborn }
		}
		### -- Just.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.just
			scope:secondary_recipient ?= { has_trait = just }
		}
		### --- Content.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.content
			scope:secondary_recipient ?= { has_trait = content }
		}
		### --- Loyal.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook.tt.has_trait.loyal
			scope:secondary_recipient ?= { has_trait = loyal }
		}
		# Hooks.
		## Weak hooks are happy to have you in power.
		modifier = {
			add = 25
			scope:secondary_recipient ?= { has_weak_hook = scope:actor }
		}
		## Strong hooks are *very* happy to have you in power.
		modifier = {
			add = 75
			scope:secondary_recipient ?= { has_strong_hook = scope:actor }
		}
		## And conversely, don't want you to coup scope:recipient if they've already got a strong hook on them.
		modifier = {
			add = -100
			scope:secondary_recipient ?= { has_strong_hook = scope:recipient }
		}
		## Loyalty hooks stop the AI signing up.
		modifier = {
			exists = scope:secondary_recipient
			add = -1000
			desc = diarch_coup_liege_interaction.tt.liege_has_loyalty_hook
			diarch_loyalty_due_to_hook_trigger = {
				LIEGE = scope:recipient
				DIARCH = scope:secondary_recipient
			}
		}
		# Various.
		## Scope:secondary_recipient generally doesn't want to betray an ally.
		modifier = {
			add = {
				value = -100
				# Reduce the malus a little if also allied to scope:actor.
				if = {
					limit = {
						scope:secondary_recipient ?= { is_allied_to = scope:actor }
					}
					add = 50
				}
			}
			scope:secondary_recipient ?= { is_allied_to = scope:recipient }
		}
		## Heirs don't generally want to betray scope:recipient, as they'll lose out.
		modifier = {
			add = -100
			desc = diarch_coup_liege_interaction.tt.heir_will_not_side_against_benefactor
			scope:recipient = {
				any_heir = { this = scope:secondary_recipient }
			}
		}
		# Promises.
		## Weak hook.
		modifier = {
			add = {
				value = 25
				# Multiply this...
				## ... down for folks who wouldn't care...
				if = {
					limit = { has_trait = honest }
					multiply = 0.5
				}
				## ... & and up for those who would.
				if = {
					limit = { has_trait = deceitful }
					multiply = 2
				}
			}
			desc = diarch_coup_liege_interaction.tt.wants_hook
			scope:promise_hook_weak = yes
		}
		## Strong hook.
		modifier = {
			add = {
				value = 50
				# Multiply this...
				## ... down for folks who wouldn't care...
				if = {
					limit = { has_trait = honest }
					multiply = 0.5
				}
				## ... & and up for those who would.
				if = {
					limit = { has_trait = deceitful }
					multiply = 2
				}
			}
			desc = diarch_coup_liege_interaction.tt.wants_strong_hook
			scope:promise_hook_strong = yes
		}
		## Gold.
		modifier = {
			add = {
				value = 25
				# Multiply this...
				## ... down for folks who wouldn't care...
				if = {
					limit = { has_trait = generous }
					multiply = 0.5
				}
				## ... & and up for those who would.
				if = {
					limit = { has_trait = greedy }
					multiply = 2
				}
			}
			desc = diarch_coup_liege_interaction.tt.wants_gold
			scope:promise_gold_medium = yes
		}
		## Lotsa gold.
		modifier = {
			add = {
				value = 50
				# Multiply this...
				## ... down for folks who wouldn't care...
				if = {
					limit = { has_trait = generous }
					multiply = 0.5
				}
				## ... & and up for those who would.
				if = {
					limit = { has_trait = greedy }
					multiply = 2
				}
			}
			desc = diarch_coup_liege_interaction.tt.wants_strong_gold
			scope:promise_gold_large = yes
		}
	}

	# AI
	## The AI doesn't use this interaction automatically - they try it manually upon hitting the required threshold.
}









##################################################
# LIEGE ON DIARCH POWERS

# Liege (actor) transfers vizier's (recipient's) extravagance modifiers into their own gold.
mulct_vizier_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	icon = icon_gold

	desc = mulct_vizier_interaction_desc

	is_shown = {
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			diarch ?= scope:recipient
			# Plus only on viziers.
			has_diarchy_active_parameter = unlock_mulct_vizier_interaction
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			# Some basic checks.
			is_available_adult = yes
			# Shouldn't happen, but just in case.
			NOT = { is_at_war_with = scope:recipient }
		}
		# Must select something.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:mulct_vizier_interaction_minimal = yes
					scope:mulct_vizier_interaction_minor = yes
					scope:mulct_vizier_interaction_medium = yes
					scope:mulct_vizier_interaction_major = yes
					scope:mulct_vizier_interaction_massive = yes
				}
			}
		}
	}

	# Don't squeeze them too often.
	cooldown = { years = 10 }

	# Attempt Methods
	send_options_exclusive = yes
	## Minimal.
	### Always show this'un.
	send_option = { flag = mulct_vizier_interaction_minimal }
	## Minor.
	send_option = { flag = mulct_vizier_interaction_minor }
	## Medium.
	send_option = { flag = mulct_vizier_interaction_medium }
	## Major.
	send_option = { flag = mulct_vizier_interaction_major }
	## Massive.
	send_option = { flag = mulct_vizier_interaction_massive }

	can_send = {
		trigger_if = {
			limit = { scope:mulct_vizier_interaction_minor = yes }
			custom_tooltip = {
				text = mulct_vizier_interaction.extravagances_required.t1
				scope:recipient = {
					OR = {
						has_character_modifier = vizier_extravagance_t1_treasure_modifier
						has_character_modifier = vizier_extravagance_t1_activities_modifier
						has_character_modifier = vizier_extravagance_t1_property_modifier
						has_character_modifier = vizier_extravagance_t1_charity_modifier
					}
				}
			}
			custom_tooltip = {
				text = mulct_vizier_interaction.scales_too_swung.tt
				scope:actor.vizier_mulct_swing_check_value >= vizier_mulct_swing_gain_minor_value
			}
		}
		trigger_if = {
			limit = { scope:mulct_vizier_interaction_medium = yes }
			custom_tooltip = {
				text = mulct_vizier_interaction.extravagances_required.t2
				scope:recipient = {
					OR = {
						has_character_modifier = vizier_extravagance_t2_treasure_modifier
						has_character_modifier = vizier_extravagance_t2_activities_modifier
						has_character_modifier = vizier_extravagance_t2_property_modifier
						has_character_modifier = vizier_extravagance_t2_charity_modifier
					}
				}
			}
			custom_tooltip = {
				text = mulct_vizier_interaction.scales_too_swung.tt
				scope:actor.vizier_mulct_swing_check_value >= vizier_mulct_swing_gain_medium_value
			}
		}
		trigger_if = {
			limit = { scope:mulct_vizier_interaction_major = yes }
			custom_tooltip = {
				text = mulct_vizier_interaction.extravagances_required.t3
				scope:recipient = {
					OR = {
						has_character_modifier = vizier_extravagance_t3_treasure_modifier
						has_character_modifier = vizier_extravagance_t3_activities_modifier
						has_character_modifier = vizier_extravagance_t3_property_modifier
						has_character_modifier = vizier_extravagance_t3_charity_modifier
					}
				}
			}
			custom_tooltip = {
				text = mulct_vizier_interaction.scales_too_swung.tt
				scope:actor.vizier_mulct_swing_check_value >= vizier_mulct_swing_gain_major_value
			}
		}
		trigger_if = {
			limit = { scope:mulct_vizier_interaction_massive = yes }
			custom_tooltip = {
				text = mulct_vizier_interaction.extravagances_required.t4
				scope:recipient = {
					OR = {
						has_character_modifier = vizier_extravagance_t4_treasure_modifier
						has_character_modifier = vizier_extravagance_t4_activities_modifier
						has_character_modifier = vizier_extravagance_t4_property_modifier
						has_character_modifier = vizier_extravagance_t4_charity_modifier
					}
				}
			}
			custom_tooltip = {
				text = mulct_vizier_interaction.scales_too_swung.tt
				scope:actor.vizier_mulct_swing_check_value >= vizier_mulct_swing_gain_massive_value
			}
		}
	}

	on_accept = {
		# Sort the gold transfer.
		mulct_vizier_for_cash_effect = { VIZIER = scope:recipient }
		scope:recipient = {
			# How angry is scope:recipient?
			if = {
				limit = { scope:mulct_vizier_interaction_minimal = yes }
				mulct_vizier_for_cash_opinion_reaction_effect = { MULT = 1 }
			}
			if = {
				limit = { scope:mulct_vizier_interaction_minor = yes }
				mulct_vizier_for_cash_opinion_reaction_effect = { MULT = 2 }
			}
			if = {
				limit = { scope:mulct_vizier_interaction_medium = yes }
				mulct_vizier_for_cash_opinion_reaction_effect = { MULT = 3 }
			}
			if = {
				limit = { scope:mulct_vizier_interaction_major = yes }
				mulct_vizier_for_cash_opinion_reaction_effect = { MULT = 4 }
			}
			if = {
				limit = { scope:mulct_vizier_interaction_massive = yes }
				mulct_vizier_for_cash_opinion_reaction_effect = { MULT = 5 }
			}
			# How much stress is this causing them?
			stress_impact = {
				ambitious = major_stress_impact_loss
				arrogant = medium_stress_impact_loss
				generous = minor_stress_impact_loss
				greedy = major_stress_impact_gain
			}
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_vizmulct_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_vizmulct_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_vizmulct_accept_recipient_list }
		}
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = diarch }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 120
		kingdom = 120
		empire = 120
		hegemony = 120
	}
	ai_potential = {
		has_active_diarchy = yes
		has_diarchy_parameter = unlock_mulct_vizier_interaction
	}

	ai_will_do = {
		# You generally want to do this if you can.
		base = 100

		# Circumstances.
		## Are we in debt?
		modifier = {
			add = 100
			gold <= -1
		}
		## Are we at war?
		modifier = {
			add = 100
			is_at_war = yes
		}

		# Vizier Extravagances.
		## Are they in the upper tiers?
		modifier = {
			add = 50
			scope:recipient = {
				OR = {
					has_character_modifier = vizier_extravagance_t3_treasure_modifier
					has_character_modifier = vizier_extravagance_t3_activities_modifier
					has_character_modifier = vizier_extravagance_t3_property_modifier
					has_character_modifier = vizier_extravagance_t3_charity_modifier
				}
			}
		}
		## Are they in the uppermost tier?
		modifier = {
			add = 25
			scope:recipient = {
				OR = {
					has_character_modifier = vizier_extravagance_t4_treasure_modifier
					has_character_modifier = vizier_extravagance_t4_activities_modifier
					has_character_modifier = vizier_extravagance_t4_property_modifier
					has_character_modifier = vizier_extravagance_t4_charity_modifier
				}
			}
		}

		# Traits.
		## Greedy characters'll do it whenever they can.
		modifier = {
			add = 50
			has_trait = greedy
		}
		## Generous characters'll only do it occasionally.
		modifier = {
			add = -50
			has_trait = generous
		}

		# Send Option Usage.
		## These teach the AI how to use the send options.
		## These are linear; basically, prefer the largest number you're valid for (since the can_send'll block whatever you can't mulct).
		modifier = {
			add = 1
			scope:mulct_vizier_interaction_minimal = yes
		}
		modifier = {
			add = 2
			scope:mulct_vizier_interaction_minor = yes
		}
		modifier = {
			add = 3
			scope:mulct_vizier_interaction_medium = yes
		}
		modifier = {
			add = 4
			scope:mulct_vizier_interaction_major = yes
		}
		modifier = {
			add = 5
			scope:mulct_vizier_interaction_massive = yes
		}
	}
}










##################################################
# BOTH-WAYS POWERS

# Diarch or liege target their opposite number and inflict negative realm opinion equivalent to the multiplied difference between intrigue or diplomacy in exchange for influence.
scapegoat_counterpart_interaction = {
	category = interaction_category_diarch
	icon = icon_scheme_slander

	desc = scapegoat_counterpart_interaction_desc

	interface_priority = 25

	is_shown = {
		# You must be one of the partners in a diarchy.
		is_in_scapegoating_diarchy_visibility_trigger = { PARAMETER_TYPE = has_diarchy_parameter }
	}

	is_valid_showing_failures_only = {
		# Free adults only: you can't issue this type of decree from prison, and it wouldn't be fair to stop you from slandering a child but let a child slander you.
		scope:actor = {
			is_imprisoned = no
			is_adult = yes
		}
		# And you can't blame a literal child.
		scope:recipient = { is_adult = yes }
		# Nor can you blame the opposing party if you're a deactivated diarch.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch_of_target = scope:recipient }
			}
			diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
		}
		custom_tooltip = {
			text = scapegoat_counterpart_interaction.tt.skill_requirements
			OR = {
				scope:actor.diplomacy > scope:recipient.diplomacy
				scope:actor.intrigue > scope:recipient.intrigue
			}
		}
		is_in_scapegoating_diarchy_visibility_trigger = { PARAMETER_TYPE = has_diarchy_active_parameter }
		# Cannot be at war with each other.
		NOT = {
			scope:actor = { is_at_war_with = scope:recipient }
		}
	}

	cooldown = { years = 3 }

	cost = {
		# Non-ruler diarchs have all the time to do this the slow way.
		prestige = {
			if = {
				limit = {
					scope:actor = { is_ruler = yes }
				}
				value = medium_prestige_value
			}
		}
	}

	# Diplomacy
	## Small amount
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = scapegoat_counterpart_interaction.diplomacy_small.is_valid
				scope:actor.diplomacy > scope:recipient.diplomacy
			}
		}
		flag = diplomacy_small
		localization = scapegoat_counterpart_interaction.diplomacy_small.t
	}
	## Large amount
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = scapegoat_counterpart_interaction.diplomacy_large.is_valid
				scope:actor.diplomacy > scope:recipient.diplomacy
			}
		}
		flag = diplomacy_large
		localization = scapegoat_counterpart_interaction.diplomacy_large.t
	}
	# Intrigue
	## Small amount
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = scapegoat_counterpart_interaction.intrigue_small.is_valid
				scope:actor.intrigue > scope:recipient.intrigue
			}
		}
		flag = intrigue_small
		localization = scapegoat_counterpart_interaction.intrigue_small.t
	}
	## Large amount
	send_option = {
		is_valid = {
			custom_tooltip = {
				text = scapegoat_counterpart_interaction.intrigue_large.is_valid
				scope:actor.intrigue > scope:recipient.intrigue
			}
		}
		flag = intrigue_large
		localization = scapegoat_counterpart_interaction.intrigue_large.t
	}

	on_accept = {
		scope:recipient = {
			# Send out our effects for the diarch.
			if = {
				limit = { is_diarch_of_target = scope:actor }
				trigger_event = diarchy.8041
				every_player = {
					limit = {
						top_liege = scope:actor.top_liege
						NOR = {
							this = scope:actor
							this = scope:recipient
						}
					}
					trigger_event = diarchy.8041
				}
				scapegoat_counterpart_interaction_process_results_effect = {
					REALM_OPINION_ACTOR = add_tyranny
					REALM_OPINION_RECIPIENT = change_strife_opinion
				}
			}
			# And our effects for the liege.
			else = {
				tgp_activate_catalyst_against_hegemon_effect = {
					HEGEMON = scope:actor.top_liege
					CATALYST = catalyst_diarch_mandate
				}
				trigger_event = diarchy.8042
				every_player = {
					limit = {
						top_liege = scope:actor.top_liege
						NOR = {
							this = scope:actor
							this = scope:recipient
						}
					}
					trigger_event = diarchy.8042
				}
				scapegoat_counterpart_interaction_process_results_effect = {
					REALM_OPINION_ACTOR = change_strife_opinion
					REALM_OPINION_RECIPIENT = add_tyranny
				}
			}
		}
		# Regardless of what happens, scope:recipient is a bit miffed.
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = slandered_me_opinion
				opinion = {
					value = scope:multiplied_diff
					divide = -20
					max = -10
				}
			}
		}
		custom_tooltip = scapegoat_counterpart_interaction.tt.infighting_sullies_the_realm
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = liege }
	ai_targets = { ai_recipients = diarch }
	ai_frequency_by_tier = {
		barony = 0
		county = 36
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_potential = {
		OR = {
			# Either they're a liege.
			AND = {
				has_active_diarchy = yes
				# With suitable skill diffs to give some kind of a gain.
				OR = {
					diplomacy_diff = {
						target = diarch
						value >= 5
					}
					intrigue_diff = {
						target = diarch
						value >= 5
					}
				}
			}
			# Or they're the diarch.
			AND = {
				is_diarch = yes
				# With suitable skill diffs to give some kind of a gain.
				OR = {
					diplomacy_diff = {
						target = liege
						value >= 5
					}
					intrigue_diff = {
						target = liege
						value >= 5
					}
				}
				# Loyal diarchs don't engage in skullduggery.
				diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
			}
		}
		# Filter out some traits that would never do this.
		NOR = {
			has_trait = just
			has_trait = honest
			has_trait = loyal
		}
	}

	ai_will_do = {
		base = -50

		# Opinion.
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -2.5
		}
		## Plus weight up a bit further for bad relationships.
		first_valid = {
			# Nemeses.
			modifier = {
				add = 200
				has_relation_nemesis = scope:recipient
			}
			# Rivals.
			modifier = {
				add = 50
				has_relation_rival = scope:recipient
			}
		}
		# Traits.
		## +++ Deceitful
		modifier = {
			add = 30
			has_trait = deceitful
		}
		## +++ Ambitious
		modifier = {
			add = 30
			has_trait = ambitious
		}
		## ++ Arrogant
		modifier = {
			add = 20
			has_trait = arrogant
		}
		## ++ Arbitrary
		modifier = {
			add = 20
			has_trait = arbitrary
		}
		## ++ Vengeful & doesn't like you
		modifier = {
			add = 20
			has_trait = vengeful
			opinion = {
				target = scope:recipient
				value <= -1
			}
		}
		## + Sadistic
		modifier = {
			add = 10
			has_trait = sadistic
		}
		## + Fickle
		modifier = {
			add = 10
			has_trait = fickle
		}
		## + Eccentric
		modifier = {
			add = 10
			has_trait = eccentric
		}
		## + Greedy
		modifier = {
			add = 10
			has_trait = greedy
		}
		## - Generous
		modifier = {
			add = -10
			has_trait = generous
		}
		## -- Compassionate
		modifier = {
			add = -20
			has_trait = compassionate
		}
		## -- Craven
		modifier = {
			add = -20
			has_trait = craven
		}
		## --- Forgiving
		modifier = {
			add = -30
			has_trait = forgiving
		}
		## --- Humble
		modifier = {
			add = -30
			has_trait = humble
		}
		## ---- Content
		modifier = {
			add = -50
			has_trait = content
		}
		## We've already pre-filtered out Honest & Just.
		# Dread.
		## Intimidated.
		modifier = {
			add = -50
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 1
				}
			}
		}
		## Cowed.
		modifier = {
			add = -100
			scope:actor = {
				has_dread_level_towards = {
					target = scope:recipient
					level = 2
				}
			}
		}
		# Flag Management.
		## Okay, we want to try and pick the larger of either our diplo diff or our intrigue diff.
		### If our diplo diff is higher than our intrigue diff, go for diplo.
		modifier = {
			add = 4
			scope:diplomacy_large = yes
			scapegoat_counterpart_interaction_calc_diplo_diff_treshhold_value >= scapegoat_counterpart_interaction_calc_intrigue_diff_treshhold_value
		}
		### Else, go for intrigue.
		modifier = {
			add = 3
			scope:intrigue_large = yes
		}
		### These two should never trigger, but we've got them here as fallbacks.
		modifier = {
			add = 2
			scope:diplomacy_small = yes
		}
		modifier = {
			add = 1
			scope:intrigue_small = yes
		}
		### And then the AI otherwise doesn't worry about which smaller send option to pick.
		# Influence status.
		## Swimming in influence? Not worth it.
		modifier = {
			factor = 0
			scope:actor.influence >= 500
		}
		## In debt? Weight it up.
		modifier = {
			factor = 2
			scope:actor.influence <= -1
		}
	}
}










##################################################
# MANAGE DIARCHY INTERACTIONS

# Diarch or liege target their opposite number and sink currency to reaffirm their influence in the realm.
swing_scales_currency_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	highlighted_reason = HIGHLIGHTED_CAN_SWING_SCALES
	icon = scroll_scales

	desc = swing_scales_currency_interaction_desc

	interface_priority = 20

	is_shown = {
		# You must be one of the partners in a diarchy.
		OR = {
			scope:actor = { is_diarch_of_target = scope:recipient }
			scope:recipient = { is_diarch_of_target = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		# Forbid when we're at max swing...
		## ... for the regent.
		trigger_if = {
			limit = {
				scope:actor = { is_diarch_of_target = scope:recipient }
			}
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.scales_max_swung
				scope:recipient.diarchy_swing < 100
			}
		}
		## ... and for the liege.
		trigger_if = {
			limit = {
				NOT = {
					scope:actor = { has_diarchy_active_parameter = liege_may_voluntarily_cede_authority }
				}
				scope:recipient = { is_diarch_of_target = scope:actor }
			}
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.scales_max_swung
				scope:actor.diarchy_swing > 0
			}
		}
		# As long as you're able to give something even vaguely like an order to someone who might advocate on your behalf, you're gucci.
		scope:actor = {
			is_imprisoned = no
			age >= 8
		}
		# Must select something.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:swing_influence = yes
					scope:swing_cede_authority = yes
					scope:swing_prestige = yes
					scope:swing_piety = yes
					scope:swing_gold = yes
					scope:swing_hook = yes
					scope:swing_hof = yes
				}
			}
		}
		# And in the _rare_ circumstance that a diarch is a child, they must be at least this tall.
		## Note that we _don't_ do this for the liege, since we want the player to be able to manage their regency — assume that _someone_ is looking out for the child's best interests.
		scope:actor = {
			trigger_if = {
				limit = {
					is_diarch_of_target = scope:recipient
					is_adult = no
				}
				age >= 8
			}
		}
		# Cannot be at war with each other.
		NOT = {
			scope:actor = { is_at_war_with = scope:recipient }
		}
	}

	cooldown = { years = 2 }

	cost = {
		influence = {
			if = {
				limit = { always = scope:swing_influence }
				value = scope:actor.swing_scales_influence_cost_value
				# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
				if = {
					limit = { scope:actor = { is_valid_for_legitimacy_change = yes } }
					multiply = legitimacy_regent_swing_scale_multipler_value
				}
			}
		}
		prestige = {
			if = {
				limit = { always = scope:swing_prestige }
				value = scope:actor.swing_scales_prestige_cost_value
				# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
				if = {
					limit = { scope:actor = { is_valid_for_legitimacy_change = yes } }
					multiply = legitimacy_regent_swing_scale_multipler_value
				}
			}
		}
		piety = {
			if = {
				limit = {
					OR = {
						always = scope:swing_piety
						always = scope:swing_hof
					}
				}
				value = scope:actor.swing_scales_piety_cost_value
				# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
				if = {
					limit = { scope:actor = { is_valid_for_legitimacy_change = yes } }
					multiply = legitimacy_regent_swing_scale_multipler_value
				}
			}
		}
		gold = {
			if = {
				limit = {
					OR = {
						always = scope:swing_gold
						always = scope:swing_hof
					}
				}
				value = scope:actor.swing_scales_cash_cost_value
				# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
				if = {
					limit = { scope:actor = { is_valid_for_legitimacy_change = yes } }
					multiply = legitimacy_regent_swing_scale_multipler_value
				}
			}
		}
	}

	# Influence
	send_option = {
		is_shown = {
			# Make sure influence would be relevant.
			OR = {
				AND = {
					scope:recipient.liege ?= scope:actor
					scope:actor = { government_allows = administrative }
				}
				AND = {
					scope:actor.liege ?= scope:recipient
					scope:recipient = { government_allows = administrative }
				}
			}
		}
		is_valid = {
			scope:actor = { government_allows = administrative }
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		starts_enabled = { scope:actor.influence >= scope:actor.swing_scales_influence_cost_value }
		flag = swing_influence
		localization = SWING_INFLUENCE
		current_description = SWING_INFLUENCE_DESC
	}
	# Movement Power
	send_option = {
		starts_enabled = {
			exists = scope:actor.var:movement_power_individual
			scope:actor.var:movement_power_individual >= decent_movement_power_value
		}
		is_shown = {
			scope:actor = {
				government_has_flag = government_is_celestial
				is_diarch_of_target = scope:recipient
			}
			scope:recipient = { government_has_flag = government_is_celestial }
		}
		is_valid = {
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.scales_min_movement_power
				scope:actor.var:movement_power_individual >= medium_movement_power_value
			}
		}
		flag = swing_movement_power
		localization = SWING_MOVEMENT_POWER
		current_description = SWING_MOVEMENT_POWER_DESC
	}
	# Cede control voluntarily.
	send_option = {
		is_shown = {
			scope:actor = { has_diarchy_active_parameter = liege_may_voluntarily_cede_authority }
			scope:recipient = { is_diarch_of_target = scope:actor }
		}
		is_valid = {
			# Can't be a liege with the scales swung too far in favour of their diarch.
			custom_tooltip = {
				text = mulct_vizier_interaction.scales_too_swung.tt
				scope:actor.diarchy_swing <= 90
			}
		}
		starts_enabled = { scope:actor.influence >= scope:actor.swing_scales_influence_cost_value }
		flag = swing_cede_authority
		localization = SWING_CEDE_AUTHORITY
		current_description = SWING_CEDE_AUTHORITY_DESC
	}
	# Prestige
	send_option = {
		starts_enabled = { scope:actor.prestige >= scope:actor.swing_scales_prestige_cost_value }
		is_valid = {
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		flag = swing_prestige
		localization = SWING_PRESTIGE
		current_description = SWING_PRESTIGE_DESC
	}
	# Piety
	send_option = {
		is_valid = {
			# You must share a HoF to be able to petition one.
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.no_shared_hof
				# We're also secretly just testing if characters are the same faith.
				OR = {
					scope:actor.faith = scope:recipient.faith
					AND = {
						exists = scope:actor.faith.religious_head
						exists = scope:recipient.faith.religious_head
						scope:actor.faith.religious_head = scope:recipient.faith.religious_head
					}
				}
			}
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		starts_enabled = { scope:actor.piety >= scope:actor.swing_scales_piety_cost_value }
		flag = swing_piety
		localization = SWING_PIETY
		current_description = SWING_PIETY_DESC
	}
	# Gold
	send_option = {
		is_shown = {
			# Filter out for the liege in vizierates - they can mulct the vizier, so we don't give them the chance to spend that gold back.
			interaction_actor_is_liege_with_vizierate_trigger = no
		}
		starts_enabled = { scope:actor.gold >= scope:actor.swing_scales_cash_cost_value }
		is_valid = {
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		flag = swing_gold
		localization = SWING_GOLD
		current_description = SWING_GOLD_DESC
	}
	# Hook
	send_option = {
		starts_enabled = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		flag = swing_hook
		localization = SWING_HOOK
		current_description = SWING_HOOK_DESC
	}
	# HoF
	send_option = {
		is_shown = {
			# Filter out for the liege in vizierates - they can mulct the vizier, so we don't give them the chance to spend that gold back.
			interaction_actor_is_liege_with_vizierate_trigger = no
		}
		is_valid = {
			diarch_swing_scales_valid_shared_hof_trigger = yes
			# Can't be a liege with the scales swung completely towards them.
			trigger_if = {
				limit = {
					scope:recipient = { is_diarch_of_target = scope:actor }
				}
				custom_tooltip = {
					text = swing_scales_currency_interaction.tt.scales_max_swung
					scope:actor.diarchy_swing > 0
				}
			}
		}
		# Top of the prio order for enablement.
		starts_enabled = { diarch_swing_scales_valid_shared_hof_trigger = yes }
		flag = swing_hof
		localization = SWING_HOF
		current_description = SWING_HOF_DESC
	}

	on_accept = {
		# Swing the scales in the direction of scope:actor.
		scope:recipient = {
			# Swing the scales up if we're ceding power.
			if = {
				limit = { scope:swing_cede_authority = yes }
				send_interface_message = {
					type = msg_mandate_results_neutral_effect
					title = swing_scales_interaction_by_liege.t
					right_icon = scope:actor
					scope:actor = {
						# Viziers give you more bang for your buck when swinging against 'em.
						# Perk check for Voyager perk
						if = {
							limit = {
								has_diarchy_active_parameter = lieges_swing_more_against_diarchs
								has_perk = power_at_home_perk
								is_travelling = yes
							}
							update_diarchy_swing_with_perspective_effect = {
								SWING = monumental_sop_swing_diarch_gain
								LIEGE = scope:actor
							}
						}
						# Perk or Vizier
						else_if = {
							limit = {
								OR = {
									has_diarchy_active_parameter = lieges_swing_more_against_diarchs
									AND = {
										has_perk = power_at_home_perk
										is_travelling = yes
									}
								}
							}
							update_diarchy_swing_with_perspective_effect = {
								SWING = massive_sop_swing_diarch_gain
								LIEGE = scope:actor
							}
						}
						# Neither
						else = {
							update_diarchy_swing_with_perspective_effect = {
								SWING = major_sop_swing_diarch_gain
								LIEGE = scope:actor
							}
						}
						diarch_swing_scales_guts_effect = yes
						# Plus, everyone benefits.
						change_influence = {
							value = 200
							# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
							multiply = legitimacy_regent_swing_scale_multipler_value
							round = yes
						}
						scope:recipient = {
							change_influence = {
								value = 200
								# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
								multiply = legitimacy_regent_swing_scale_multipler_value
								round = yes
							}
						}
					}
				}
			}
			# Swing the scales down if this is the liege.
			else_if = {
				limit = { is_diarch_of_target = scope:actor }
				send_interface_message = {
					type = msg_mandate_results_bad_effect
					title = swing_scales_interaction_by_liege.t
					right_icon = scope:actor
					scope:actor = {
						# Viziers give you more bang for your buck when swinging against 'em.
						# Perk check for Voyager perk
						if = {
							limit = {
								has_diarchy_active_parameter = lieges_swing_more_against_diarchs
								has_perk = power_at_home_perk
								is_travelling = yes
							}
							update_diarchy_swing_with_perspective_effect = {
								SWING = massive_sop_swing_liege_gain
								LIEGE = scope:actor
							}
						}
						# Perk or Vizier
						else_if = {
							limit = {
								OR = {
									has_diarchy_active_parameter = lieges_swing_more_against_diarchs
									AND = {
										has_perk = power_at_home_perk
										is_travelling = yes
									}
								}
							}
							update_diarchy_swing_with_perspective_effect = {
								SWING = major_sop_swing_liege_gain
								LIEGE = scope:actor
							}
						}
						# Neither
						else = {
							update_diarchy_swing_with_perspective_effect = {
								SWING = medium_sop_swing_liege_gain
								LIEGE = scope:actor
							}
						}
						diarch_swing_scales_guts_effect = yes
					}
				}
			}
			# And up if this is the diarch.
			else = {
				send_interface_message = {
					type = msg_mandate_results_bad_effect
					title = swing_scales_interaction_by_diarch.t
					right_icon = scope:actor
					if = {
						limit = {
							scope:actor = {
								has_perk = power_at_home_perk
								is_travelling = yes
							}
						}
						update_diarchy_swing_with_perspective_effect = {
							SWING = major_sop_swing_diarch_gain
							LIEGE = scope:recipient
						}
					}
					else = {
						update_diarchy_swing_with_perspective_effect = {
							SWING = medium_sop_swing_diarch_gain
							LIEGE = scope:recipient
						}
					}
					scope:actor = { diarch_swing_scales_guts_effect = yes }
				}
			}
		}
		# Unless you gave power to them, scope:recipient is a bit miffed.
		scope:recipient = {
			# We're actually giving them swing, so gain opinion.
			## We lessen the gains from this over time, as they become more and more entitled.
			if = {
				limit = { scope:swing_cede_authority = yes }
				# Actual gains.
				if = {
					limit = {
						OR = {
							NOT = { has_variable = diarch_authority_ceded }
							var:diarch_authority_ceded < diarch_authority_ceded_opinion_value
						}
					}
					# First, check to see how much opinion we should give.
					save_scope_value_as = {
						name = opinion_gain
						value = {
							value = diarch_authority_ceded_opinion_value
							if = {
								limit = { has_variable = diarch_authority_ceded }
								subtract = var:diarch_authority_ceded
							}
						}
					}
					# Then, adjust the opinion.
					add_opinion = {
						target = scope:actor
						modifier = pleased_opinion
						opinion = scope:opinion_gain
					}
					# And decrease our gain next time.
					increment_variable_effect = {
						VAR = diarch_authority_ceded
						VAL = 5
					}
				}
				# Otherwise, a paltry amount.
				## We're deliberately giving you basically nothing here — the 1 is for comedic effect.
				else = {
					add_opinion = {
						target = scope:actor
						modifier = pleased_opinion
						opinion = 1
					}
				}
			}
			# Co-monarchs are more annoyed.
			else_if = {
				limit = {
					OR = {
						AND = {
							scope:actor = { is_diarch_of_target = scope:recipient }
							scope:recipient = { has_diarchy_active_parameter = diarchy_is_co_rulership }
						}
						AND = {
							scope:recipient = { is_diarch_of_target = scope:actor }
							scope:actor = { has_diarchy_active_parameter = diarchy_is_co_rulership }
						}
					}
				}
				add_opinion = {
					target = scope:actor
					modifier = frustrated_opinion
					opinion = -20
				}
			}
			# Take away a normal amount.
			else = {
				add_opinion = {
					target = scope:actor
					modifier = frustrated_opinion
					opinion = -10
				}
			}
		}
		# Some diarchs might be swinging as a prelude to a coup attempt.
		ai_diarch_check_to_see_if_should_launch_coup_effect = yes

		# Debug & object explorer logging.
		## Diarch swung.
		if = {
			limit = {
				exists = scope:recipient.diarch
				scope:actor = scope:recipient.diarch
			}
			debug_log = debug_log.swing_scales.diarch_swung
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_swung_diarch }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_swung_diarch_list }
			}
		}
		## Else liege swung.
		else = {
			debug_log = debug_log.swing_scales.liege_swung
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_swung_liege }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_swung_liege_list }
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = liege
		ai_recipients = diarch
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	ai_potential = {
		OR = {
			# Either they're a liege.
			AND = {
				has_active_diarchy = yes
				# With some kind of valid cause to worry.
				OR = {
					# Lieges don't care unless your regency is entrenched _and_ it's looking to stay that way...
					has_diarchy_active_parameter = regency_cant_be_ended_above_this_point
					# ... unless they could get out of it.
					can_leave_diarchy_trigger = yes
				}
			}
			# Or they're the diarch.
			AND = {
				is_diarch = yes
				# Loyal diarchs don't engage in skullduggery.
				diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
			}
		}
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_secondary_powers_base_value

		# Additions.
		## Flag management.
		### Influence.
		modifier = {
			add = 7
			scope:swing_influence = yes
		}
		modifier = {
			add = 6
			scope:swing_movement_power = yes
		}
		### Cede Authority.
		#### Only do this if you're also humble.
		modifier = {
			add = 10
			scope:swing_cede_authority = yes
			has_trait = humble
		}
		### Prestige.
		modifier = {
			add = 2
			scope:swing_prestige = yes
		}
		### Piety.
		modifier = {
			add = 3
			scope:swing_piety = yes
		}
		### Gold.
		modifier = {
			add = 1
			scope:swing_gold = yes
		}
		### Hook.
		modifier = {
			add = 5
			scope:swing_hook = yes
		}
		### HoF - combined Gold/Piety.
		modifier = {
			add = 4
			scope:swing_hof = yes
		}
		# Factors.
		## x0 Don't go into prestige debt!
		modifier = {
			factor = 0
			scope:swing_prestige = yes
			prestige < 0
		}
		## We otherwise take care of these in the ai_potential block, because otherwise the AI interacts very, very weirdly with them.
	}
}

# For titleless diarchs: anyone playable uses the regular interaction.
diarch_swing_scales_currency_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	diarch_interaction = yes
	highlighted_reason = HIGHLIGHTED_CAN_SWING_SCALES
	icon = scroll_scales

	desc = swing_scales_currency_interaction_desc

	interface_priority = 20

	is_shown = {
		scope:recipient = scope:actor.liege
		# This is for landless diarchs only, and we pre-filter them, so we don't really care about this block.
		## But filter out players anyway for that _seamless_ debug play experience.
		scope:actor = { is_ai = yes }
	}

	is_valid_showing_failures_only = {
		# Forbid when we're at max swing.
		scope:recipient = {
			# Plus also weed out some weird errors where we got confused and looked at ourselves.
			has_active_diarchy = yes
			# Now the actual check.
			trigger_if = {
				limit = { has_active_diarchy = yes }
				diarchy_swing < 100
			}
			trigger_else = { always = no }
		}
		# As long as you're able to give something even vaguely like an order to someone who might advocate on your behalf, you're gucci.
		scope:actor = { is_imprisoned = no }
		# And in the _rare_ circumstance that a diarch is a child, they must be at least this tall.
		## Note that we _don't_ do this for the liege, since we want the player to be able to manage their regency — assume that _someone_ is looking out for the child's best interests.
		scope:actor = {
			trigger_if = {
				limit = {
					is_diarch_of_target = scope:recipient
					is_adult = no
				}
				age >= 8
			}
		}
	}

	cooldown = { years = 2 }

	cost = {
		influence = {
			if = {
				limit = { always = scope:swing_influence }
				# Diarch version.
				if = {
					limit = {
						scope:actor = { is_diarch_of_target = scope:recipient }
					}
					# Costs should always be applied on the diarch.
					add = scope:actor.swing_scales_influence_cost_value
				}
				# Liege version.
				else = {
					# Costs should always be applied on the diarch.
					add = scope:recipient.swing_scales_influence_cost_value
				}
				# Cost scaling mults.
				multiply = scope:actor.swing_scales_discounts_multiplier_value
			}
		}
		prestige = {
			if = {
				limit = { always = scope:swing_prestige }
				# Diarch version.
				if = {
					limit = {
						scope:actor = { is_diarch_of_target = scope:recipient }
					}
					# Costs should always be applied on the diarch.
					add = scope:actor.swing_scales_prestige_cost_value
				}
				# Liege version.
				else = {
					# Costs should always be applied on the diarch.
					add = scope:recipient.swing_scales_prestige_cost_value
				}
				# Cost scaling mults.
				multiply = scope:actor.swing_scales_discounts_multiplier_value
			}
		}
		piety = {
			if = {
				limit = {
					OR = {
						always = scope:swing_piety
						always = scope:swing_hof
					}
				}
				# Diarch version.
				if = {
					limit = {
						scope:actor = { is_diarch_of_target = scope:recipient }
					}
					# Costs should always be applied on the diarch.
					add = scope:actor.swing_scales_piety_cost_value
				}
				# Liege version.
				else = {
					# Costs should always be applied on the diarch.
					add = scope:recipient.swing_scales_piety_cost_value
				}
				# Cost scaling mults.
				multiply = scope:actor.swing_scales_discounts_multiplier_value
			}
		}
		gold = {
			if = {
				limit = {
					OR = {
						always = scope:swing_gold
						always = scope:swing_hof
					}
				}
				# Diarch version.
				if = {
					limit = {
						scope:actor = { is_diarch_of_target = scope:recipient }
					}
					# Costs should always be applied on the diarch.
					add = scope:actor.swing_scales_cash_cost_value
				}
				# Liege version.
				else = {
					# Costs should always be applied on the diarch.
					add = scope:recipient.swing_scales_cash_cost_value
				}
				# Cost scaling mults.
				multiply = scope:actor.swing_scales_discounts_multiplier_value
			}
		}
	}

	# Influence
	send_option = {
		is_shown = {
			# Make sure influence would be relevant.
			OR = {
				AND = {
					scope:recipient.liege ?= scope:actor
					scope:actor = { government_allows = administrative }
				}
				AND = {
					scope:actor.liege ?= scope:recipient
					scope:recipient = { government_allows = administrative }
				}
			}
		}
		is_valid = {
			scope:actor = { government_allows = administrative }
		}
		starts_enabled = { scope:actor.influence >= scope:actor.swing_scales_influence_cost_value }
		flag = swing_influence
		localization = SWING_INFLUENCE
		current_description = SWING_INFLUENCE_DESC
	}
	# Movement Power
	send_option = {
		starts_enabled = {
			exists = scope:actor.var:movement_power_individual
			scope:actor.var:movement_power_individual >= decent_movement_power_value
		}
		is_shown = {
			exists = scope:actor.var:movement_power_individual
			scope:actor = {
				government_has_flag = government_is_celestial
				is_diarch_of_target = scope:recipient
				exists = var:movement_power_individual
			}
			scope:recipient = { government_has_flag = government_is_celestial }
		}
		is_valid = {
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.scales_min_movement_power
				scope:actor.var:movement_power_individual >= medium_movement_power_value
			}
		}
		flag = swing_movement_power
		localization = SWING_MOVEMENT_POWER
		current_description = SWING_MOVEMENT_POWER_DESC
	}
	# Prestige
	send_option = {
		starts_enabled = { scope:actor.prestige >= scope:actor.swing_scales_prestige_cost_value }
		flag = swing_prestige
		localization = SWING_PRESTIGE
	}
	# Piety
	send_option = {
		is_valid = {
			# You must share a HoF to be able to petition one.
			custom_tooltip = {
				text = swing_scales_currency_interaction.tt.no_shared_hof
				# We're also secretly just testing if characters are the same faith.
				OR = {
					scope:actor.faith = scope:recipient.faith
					AND = {
						exists = scope:actor.faith.religious_head
						exists = scope:recipient.faith.religious_head
						scope:actor.faith.religious_head = scope:recipient.faith.religious_head
					}
				}
			}
		}
		starts_enabled = { scope:actor.piety >= scope:actor.swing_scales_piety_cost_value }
		flag = swing_piety
		localization = SWING_PIETY
	}
	# Gold
	send_option = {
		starts_enabled = { scope:actor.gold >= scope:actor.swing_scales_cash_cost_value }
		flag = swing_gold
		localization = SWING_GOLD
	}
	# Hook
	send_option = {
		is_valid = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		starts_enabled = {
			scope:actor = { has_usable_hook = scope:recipient }
		}
		flag = swing_hook
		localization = SWING_HOOK
	}
	# HoF
	send_option = {
		is_valid = { diarch_swing_scales_valid_shared_hof_trigger = yes }
		# Top of the prio order for enablement.
		starts_enabled = { diarch_swing_scales_valid_shared_hof_trigger = yes }
		flag = swing_hof
		localization = SWING_HOF
	}

	on_accept = {
		# Swing the scales down, since scope:actor is always a landless diarch.
		scope:recipient = {
			# Slight chance delays may lead to a diarchy ending before this is received.
			if = {
				limit = { has_active_diarchy = yes }
				send_interface_message = {
					type = msg_mandate_results_bad_effect
					title = swing_scales_interaction_by_diarch.t
					right_icon = scope:actor
					update_diarchy_swing_with_perspective_effect = {
						SWING = medium_sop_swing_diarch_gain
						LIEGE = scope:recipient
					}
					scope:actor = { diarch_swing_scales_guts_effect = yes }
				}
			}
			# Scope:recipient is a bit miffed.
			add_opinion = {
				target = scope:actor
				modifier = frustrated_opinion
				opinion = -10
			}
		}
		# Some diarchs might be swinging as a prelude to a coup attempt.
		ai_diarch_check_to_see_if_should_launch_coup_effect = yes

		# Debug logging.
		debug_log = debug_log.swing_scales.diarch_swung
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_swung_diarch }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_swung_diarch_list }
		}
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = liege }
	# We turn the frequency up higher than the cooldown so that diarchs don't take two years to get into the loop.
	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}

	ai_potential = {
		# Double check due to some irritating errors.
		is_diarch = yes
		liege = { has_active_diarchy = yes }
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# We're generally ruthless here.
		base = @ai_core_loop_base_value

		# Additions.
		## Flag management.
		### Influence.
		modifier = {
			add = 6
			scope:swing_influence = yes
		}
		### Prestige.
		modifier = {
			add = 2
			scope:swing_prestige = yes
		}
		### Piety.
		modifier = {
			add = 3
			scope:swing_piety = yes
		}
		### Gold.
		modifier = {
			add = 1
			scope:swing_gold = yes
		}
		### Hook.
		modifier = {
			add = 5
			scope:swing_hook = yes
		}
		### HoF - combined Gold/Piety.
		modifier = {
			add = 4
			scope:swing_hof = yes
		}
		# Factors.
		## x0 Don't go into prestige debt!
		modifier = {
			factor = 0
			scope:swing_prestige = yes
			prestige < 0
		}
	}
}

# Diarch (actor) shifts from a Temporary Regency to an Entrenched Regency.
diarch_entrench_regency_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	diarch_interaction = yes
	highlighted_reason = HIGHLIGHTED_CAN_DIARCH_ENTRENCH_REGENCY
	icon = icon_entrench_regency

	desc = diarch_entrench_regency_interaction_desc

	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			# With the extra consideration that we only want this to appear for Temporary Regencies.
			liege = { has_diarchy_parameter = unlock_entrench_regency_interaction }
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = unlock_entrench_regency_interaction }
		# You must be able to act as diarch.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
	}

	on_accept = {
		scope:recipient = {
			# Tell scope:recipient what's up.
			send_interface_toast = {
				type = msg_start_diarchy
				title = diarch_entrench_regency_interaction.tt.recipient_notification
				left_icon = scope:actor
				# Change the diarchy type to entrenched.
				set_diarchy_type = regency
				# Set our power level down a bit, but still higher than entrenched regencies that *start* that way would be.
				set_diarchy_swing = 40
			}
			# Plus scope:recipient probably isn't super happy about this.
			add_opinion = {
				target = scope:actor
				modifier = suspicion_opinion
				opinion = -20
			}
		}
		# Bit o'prestige for your hard work.
		scope:actor = { add_prestige = medium_prestige_gain }

		# Debug logging.
		debug_log = debug_log.entrench_regency.attempt_made
		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entrench }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entrench_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entrench_recipient_list }
		}
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 12
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 6
	}
	ai_potential = {
		is_diarch = yes
		# Don't entrench for no reason — we want to have a bit of a delay so that the AI can go off travelling or get locked in prison once in a while.
		liege = { years_in_diarchy >= 2 }
	}

	ai_will_do = {
		# You never _don't_ want to do this.
		base = 1000
	}
}

# Diarch (actor) shifts from an Entrenched Regency to Co-Emperorship.
diarch_regent_appoints_self_co_emperor_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	diarch_interaction = yes
	icon = icon_entrench_regency

	desc = diarch_regent_appoints_self_co_emperor_interaction_desc

	popup_on_receive = yes
	pause_on_receive = yes

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			exists = liege
			is_diarch_of_target = liege
			# With the extra consideration that we only want this to appear for those who can actually _have_ co-emperors.
			liege = {
				has_diarchy_parameter = diarch_can_appoint_self_co_emperor
				may_appoint_co_emperors_trigger = yes
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure scope:recipient is the liege.
		custom_tooltip = {
			text = custom_description.tt.must_target_liege
			scope:recipient = scope:actor.liege
		}
		# Diarchs must have unlocked the appropriate power.
		scope:actor.liege = { has_diarchy_active_parameter = diarch_can_appoint_self_co_emperor }
		# You must be able to act as diarch.
		diarch_cannot_be_disabled_trigger = { DIARCH = scope:actor }
	}

	cost = {
		influence = {
			# Rulers pay influence, non-rulers get a freebie (since they otherwise likely won't accrue the requisite influence).
			if = {
				limit = {
					scope:actor = { is_ruler = yes }
				}
				value = 500
			}
			# If we're doing this vs. someone who could leave a regency, it's significantly costlier.
			if = {
				limit = {
					scope:recipient = { regency_for_personal_reasons_trigger = no }
				}
				add = 1000
			}
		}
	}

	on_accept = {
		scope:recipient = {
			# Tell scope:recipient what's up.
			send_interface_toast = {
				type = msg_start_diarchy
				title = diarch_regent_appoints_self_co_emperor_interaction.tt.recipient_notification
				left_icon = scope:actor
				# Change the diarchy type to a co-emperorship.
				custom_tooltip = {
					text = diarch_regent_appoints_self_co_emperor_interaction.tt.become_co_emperorship
					set_diarchy_type = co_emperorship
				}
				# Set our power level down a bit, we've just got one helluva prize.
				custom_tooltip = {
					text = diarch_regent_appoints_self_co_emperor_interaction.tt.set_swing
					set_diarchy_swing = diarch_regent_appoints_self_co_emperor_interaction_sop_swing_set_value
				}
				add_legitimacy = minor_legitimacy_loss
			}
			# Plus scope:recipient probably isn't super happy about this.
			add_opinion = {
				target = scope:actor
				modifier = suspicion_opinion
				opinion = -50
			}
		}
		# Notify the player about the price spike.
		if = {
			limit = {
				scope:recipient = { regency_for_personal_reasons_trigger = yes }
			}
			custom_tooltip = diarch_regent_appoints_self_co_emperor_interaction.tt.adults_cost_more
		}
		else = { custom_tooltip = diarch_regent_appoints_self_co_emperor_interaction.children_cost_less }
		# Bit o'prestige for your hard work.
		scope:actor = { add_prestige = medium_prestige_gain }
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = liege }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 12
		hegemony = 12
	}
	ai_potential = {
		is_diarch = yes
		# Filter us down nice'n'tight.
		liege = { may_appoint_co_emperors_trigger = yes }
		# Loyal diarchs don't engage in skullduggery.
		diarch_loyalty < diarch_loyalty_visibly_loyal_threshold
	}

	ai_will_do = {
		# You never _don't_ want to do this.
		base = 1000
	}
}

# Liege (actor) ends a Temporary Regency.
liege_dismiss_temporary_regency_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	icon = icon_dismiss_temporary_regency

	desc = liege_dismiss_temporary_regency_interaction_desc


	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			diarch ?= scope:recipient
			# With the extra consideration that we only want this to appear for Temporary Regencies.
			has_diarchy_parameter = can_be_instantly_dismissed
		}
	}

	is_valid_showing_failures_only = {
		# Basic requirements must be fulfilled.
		scope:actor = { can_leave_diarchy_trigger = yes }
	}

	on_accept = {
		scope:actor = {
			# Tell scope:recipient what's up.
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = liege_dismiss_temporary_regency_interaction.tt.recipient_notification
				left_icon = scope:actor
				right_icon = scope:recipient
				# End the diarchy.
				end_diarchy = yes
				scope:recipient = {
					# Bit o'prestige for your hard work.
					if = {
						limit = {
							exists = dynasty
							NOT = {
								exists = scope:actor.dynasty.dynast
								dynasty.dynast = scope:actor.dynasty.dynast
							}
						}
						custom_tooltip = liege_dismiss_temporary_regency_interaction.tt.dynasty_receives_prestige
						hidden_effect = {
							dynasty = { add_dynasty_prestige = liege_dismiss_temporary_regency_interaction_dynasty_prestige_value }
						}
					}
					else = { add_prestige = medium_prestige_gain }
				}
			}
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_dismtemp_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_dismtemp_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_dismtemp_accept_recipient_list }
		}
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = diarch }
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}
	ai_potential = { has_active_diarchy = yes }

	ai_will_do = {
		# You never _don't_ want to do this.
		base = 1000
	}
}

# Liege (actor) moves to end an Entrenched Regency.
liege_dismiss_entrenched_regency_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	notification_text = liege_dismiss_entrenched_regency_interaction_proposal
	icon = icon_dismiss_entrenched_regency

	desc = liege_dismiss_entrenched_regency_interaction_desc

	ai_maybe = yes
	can_send_despite_rejection = yes
	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			diarch ?= scope:recipient
			# With the extra consideration that we only want this to appear for Entrenched Regencies.
			OR = {
				has_diarchy_parameter = dismissal_requires_gift
				AND = {
					has_diarchy_parameter = dismissal_requires_no_ministry
					tgp_has_access_to_ministry_trigger = no
				}
			}
		}
	}

	cooldown = { years = 1 }

	is_valid_showing_failures_only = {
		# Basic requirements must be fulfilled.
		scope:actor = { can_leave_diarchy_trigger = yes }
		# And you mustn't be locked in by your regent's power.
		scope:actor = {
			NOT = { has_diarchy_active_parameter = regency_cant_be_ended_above_this_point }
		}
		# Must select something.
		trigger_if = {
			# AI won't exploit and need this exception, as they don't actually open the windows, so they'll be blocked from taking the interaction otherwise.
			limit = {
				scope:actor = { is_ai = no }
			}
			custom_tooltip = {
				text = interactions_general.tt.must_select_one_option
				OR = {
					scope:diarchy_ending_gift_unnecessary = yes
					scope:diarchy_ending_gift_stiffed = yes
					scope:diarchy_ending_gift_hook = yes
					scope:diarchy_ending_gift_dynasty_prestige = yes
					scope:diarchy_ending_gift_piety = yes
					scope:diarchy_ending_gift_cash = yes
					scope:diarchy_ending_gift_herd = yes
				}
			}
		}
		custom_tooltip = {
			text = government_is_celestial_tt
			scope:actor = {
				tgp_has_access_to_ministry_trigger = no
			}
		}
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
	}

	# Ending gifts.
	send_options_exclusive = yes
	## No gift required.
	send_option = {
		flag = diarchy_ending_gift_unnecessary
		current_description = diarchy_ending_gift_unnecessary_desc
		is_shown = {
			scope:actor = {
				NOT = { has_diarchy_active_parameter = regency_free_end_below_this_point }
			}
		}
	}
	## Stiff scope:recipient for opinion loss.
	send_option = {
		flag = diarchy_ending_gift_stiffed
		current_description = diarchy_ending_gift_stiffed_desc
		is_shown = {
			scope:actor = { has_diarchy_active_parameter = regency_free_end_below_this_point }
		}
	}
	## A hook for scope:recipient on scope:actor.
	send_option = {
		flag = diarchy_ending_gift_hook
		current_description = diarchy_ending_gift_hook_desc
		is_shown = {
			scope:recipient = {
				NOT = { has_hook = scope:actor }
			}
		}
	}
	## Transfer some of your prestige into their dynasty prestige.
	send_option = {
		flag = diarchy_ending_gift_dynasty_prestige
		current_description = diarchy_ending_gift_dynasty_prestige_desc
		is_shown = {
			# Filter out characters with no dynasty.
			exists = scope:recipient.dynasty
			# And make sure that they don't share a dynasty.
			trigger_if = {
				limit = { exists = scope:actor.dynasty }
				scope:actor.dynasty != scope:recipient.dynasty
			}
		}
	}
	## Pray for them to transfer piety.
	### Requires same-HoF.
	send_option = {
		flag = diarchy_ending_gift_piety
		current_description = diarchy_ending_gift_piety_desc
		is_shown = {
			shared_faith_or_hof_trigger = {
				ACTOR = scope:actor
				RECIPIENT = scope:recipient
			}
		}
	}
	## Cash.
	send_option = {
		flag = diarchy_ending_gift_cash
		current_description = diarchy_ending_gift_cash_desc
	}
	## Horse.
	send_option = {
		flag = diarchy_ending_gift_herd
		current_description = diarchy_ending_gift_herd_desc
		is_shown = {
			# Can only pay herd if actor has herd to pay and recipient accepts herd as a currency
			scope:actor = { government_has_flag = government_is_nomadic }
			scope:recipient = { government_has_flag = government_is_nomadic }
		}
	}

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
			# Remove the waiting flag.
			add_character_flag = trying_to_dismiss_regent
		}
	}

	on_accept = {
		# End the diarchy.
		scope:actor = { end_diarchy = yes }
		scope:recipient = {
			# Transfer a gift.
			## ... or don't, 'cause one isn't necessary!
			if = {
				limit = { scope:diarchy_ending_gift_unnecessary = yes }
				custom_tooltip = liege_dismiss_entrenched_regency_interaction.tt.no_gift_necessary
			}
			## Give 'em *nothing*, even though they earnt it.
			if = {
				limit = { scope:diarchy_ending_gift_stiffed = yes }
				custom_tooltip = liege_dismiss_entrenched_regency_interaction.tt.stiff_them
				# Scope:recipient is unhappy about this.
				if = {
					limit = { is_ai = yes }
					# More so if they're arrogant, as they take such a smack in the face even more on the proverbial nose.
					if = {
						limit = { has_trait = arrogant }
						add_opinion = {
							target = scope:actor
							modifier = insult_opinion
							opinion = -50
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = disappointed_opinion
							opinion = -30
						}
					}
				}
			}
			## Give 'em a hook.
			if = {
				limit = { scope:diarchy_ending_gift_hook = yes }
				# Transfer the hook.
				add_hook = {
					type = favor_hook
					target = scope:actor
				}
				# Plus they're happy.
				if = {
					limit = { is_ai = yes }
					# More so if they're deceitful, since they value favours.
					if = {
						limit = { has_trait = deceitful }
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 15
						}
					}
				}
			}
			## Give 'em some dynasty prestige.
			if = {
				limit = { scope:diarchy_ending_gift_dynasty_prestige = yes }
				scope:actor = { add_prestige = minor_prestige_loss }
				# Transfer the prestige.
				custom_tooltip = liege_dismiss_entrenched_regency_interaction.tt.dynasty_receives_prestige
				hidden_effect = {
					dynasty = { add_dynasty_prestige = liege_dismiss_entrenched_regency_interaction_dynasty_prestige_value }
				}
				# Plus they're happy.
				if = {
					limit = { is_ai = yes }
					# More so if they're the dynasty head, as then they can make use of it.
					if = {
						limit = { dynasty.dynast = scope:recipient }
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 15
						}
					}
				}
			}
			## Give 'em some piety.
			if = {
				limit = { scope:diarchy_ending_gift_piety = yes }
				# Transfer the piety.
				scope:actor = { add_piety = medium_piety_loss }
				add_piety = major_piety_value
				# Plus they're happy.
				if = {
					limit = { is_ai = yes }
					# More so if they're zealous, as zealots like piety.
					if = {
						limit = { has_trait = zealous }
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 15
						}
					}
				}
			}
			## Five 'em cold, hard cash.
			if = {
				limit = { scope:diarchy_ending_gift_cash = yes }
				# Transfer the cash.
				scope:actor = {
					pay_short_term_gold = {
						target = scope:recipient
						gold = major_gold_value
					}
				}
				# Plus they're happy.
				if = {
					limit = { is_ai = yes }
					# More so if they're greedy, 'cause greedy likes money.
					if = {
						limit = { has_trait = greedy }
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 15
						}
					}
				}
			}
			# Herd
			if = {
				limit = { scope:diarchy_ending_gift_herd = yes }
				# Transfer the cash.
				scope:actor = {
						#gold = major_gold_value
					pay_herd = {
						target = scope:recipient
						value = domicile.ten_percent_herd_value
					}
				}
				# Plus they're happy.
				if = {
					limit = { is_ai = yes }
					# More so if they're greedy, 'cause greedy likes money i mean horses.
					if = {
						limit = { has_trait = greedy }
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 30
						}
					}
					else = {
						add_opinion = {
							target = scope:actor
							modifier = pleased_opinion
							opinion = 15
						}
					}
				}
			}
		}

		# Object explorer logging.
		if = {
			limit = { always = scope:diarchy_ending_gift_unnecessary }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_unnecessary_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_unnecessary_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_unnecessary_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_stiffed }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_stiffed_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_stiffed_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_stiffed_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_hook }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_hook_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_hook_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_hook_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_dynasty_prestige }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_dynpres_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_dynpres_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_dynpres_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_piety }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_piety_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_piety_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_piety_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_cash }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_cash_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_cash_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_cash_accept_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_herd }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_herd_accept }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_herd_accept_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_herd_accept_recipient_list }
			}
		}
	}

	on_decline = {
		scope:actor = {
			# Attempting to assert authority pushes scope:actor's scales in their favour.
			update_diarchy_swing_with_perspective_effect = {
				SWING = major_sop_swing_liege_gain
				LIEGE = scope:actor
			}
			# Plus AI don't like being told *no*.
			if = {
				limit = { is_ai = no }
				add_opinion = {
					target = scope:recipient
					modifier = trust_opinion
					opinion = -30
				}
			}
		}
		# Clean-up that pesky flag.
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}
		# And add a _new_ pesky flag to stop 'em doubling up whilst also telling them to try to take this interaction again AQAP.
		## This is to stop the AI from failing to tackle this efficiently.
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				add_character_flag = trying_to_dismiss_regent
				trigger_event = {
					id = diarchy.0111
					days = 366
				}
			}
		}

		# Object explorer logging.
		if = {
			limit = { always = scope:diarchy_ending_gift_stiffed }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_stiffed_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_stiffed_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_stiffed_decline_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_hook }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_hook_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_hook_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_hook_decline_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_dynasty_prestige }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_dynpres_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_dynpres_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_dynpres_decline_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_piety }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_piety_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_piety_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_piety_decline_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_cash }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_cash_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_cash_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_cash_decline_recipient_list }
			}
		}
		else_if = {
			limit = { always = scope:diarchy_ending_gift_herd }
			scope:actor = {
				diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_entr_herd_decline }
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_herd_decline_actor_list }
			}
			scope:recipient = {
				diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_entr_herd_decline_recipient_list }
			}
		}
	}

	auto_accept = {
		custom_tooltip = {
			text = liege_dismiss_entrenched_regency_interaction.tt.force_ending
			scope:diarchy_ending_gift_unnecessary = yes
		}
	}

	ai_accept = {
		# Diarchs don't *want* to agree, by default...
		base = 0

		# ... except loyal ones, who really, really do...
		modifier = {
			add = 100
			desc = liege_dismiss_entrenched_regency_interaction.modifier.desc.loyal_diarch
			diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold
		}
		# ... plus inactive ones, who can't really refuse.
		modifier = {
			add = 50
			desc = liege_dismiss_entrenched_regency_interaction.modifier.desc.is_disabled
			scope:recipient = { is_diarch_able_trigger = no }
		}
		# If you could just end the diarchy without any fuss, then they're much more inclined to agree.
		modifier = {
			add = 1000
			desc = liege_dismiss_entrenched_regency_interaction.modifier.desc.could_freely_dismiss_me
			scope:actor = {
				NOT = { has_diarchy_active_parameter = regency_free_end_below_this_point }
			}
		}
		# Factor for diplomacy.
		## Yours.
		modifier = {
			add = {
				value = scope:actor.diplomacy
				multiply = 2
			}
			desc = INTERACTION_DIPLOMACY_ACTOR
		}
		## Theirs.
		modifier = {
			add = {
				value = scope:recipient.diplomacy
				multiply = -2
			}
			desc = INTERACTION_DIPLOMACY_RECIPIENT
		}
		# Factor for opinion.
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			desc = AI_OPINION_REASON
		}
		# Factor for AI personalities.
		ai_value_modifier = {
			ai_honor = 1
			ai_boldness = -0.5
		}
		# Factor for Scales of Power.
		modifier = {
			add = {
				value = scope:actor.diarchy_swing
				# Reduce by 40.
				## 20 is (currently) the node at which things become free, so we want to subtract above this point and invert below it.
				## The extra -20 is so that diarchs are more willing to go in exchange for a gift when their power is ebbing, rather than holding on until they can be discharged without one.
				add = -40
				# Invert it, since scope:actor wants low scales.
				multiply = -1
			}
			desc = INTERACTION_SCALES_OF_POWER
		}
		# Intimidation.
		## Intimidated.
		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		## Cowed.
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		# Factor for low grandeur.
		## 1 level below.
		modifier = {
			add = -20
			desc = GRANDEUR_REASON
			has_royal_court = yes
			has_dlc_feature = royal_court
			court_grandeur_current_level <= 1_levels_below_expected_level
			court_grandeur_current_level > 3_levels_below_expected_level
		}
		## 3 levels below.
		modifier = {
			add = -40
			desc = GRANDEUR_REASON
			has_royal_court = yes
			has_dlc_feature = royal_court
			court_grandeur_current_level <= 3_levels_below_expected_level
			court_grandeur_current_level > 5_levels_below_expected_level
		}
		## 5 levels below.
		modifier = {
			add = -60
			desc = GRANDEUR_REASON
			has_royal_court = yes
			has_dlc_feature = royal_court
			court_grandeur_current_level <= 5_levels_below_expected_level
			court_grandeur_current_level > 7_levels_below_expected_level
		}
		## 7 levels below.
		modifier = {
			add = -80
			desc = GRANDEUR_REASON
			has_royal_court = yes
			has_dlc_feature = royal_court
			court_grandeur_current_level <= 7_levels_below_expected_level
			court_grandeur_current_level > 9_levels_below_expected_level
		}
		## 9 levels below.
		modifier = {
			add = -100
			desc = GRANDEUR_REASON
			has_royal_court = yes
			has_dlc_feature = royal_court
			court_grandeur_current_level <= 9_levels_below_expected_level
		}
		# Negative relationships.
		## Rival.
		modifier = {
			add = -50
			desc = offer_vassalization_interaction_aibehavior_rival_tt
			scope:recipient = {
				has_relation_rival = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
		}
		## Nemesis.
		modifier = {
			add = -100
			desc = offer_vassalization_interaction_aibehavior_nemesis_tt
			scope:recipient = { has_relation_nemesis = scope:actor }
		}
		# Plus for whether you're offering a gift and if it's one they need or not.
		## No gift offered.
		### No base-vs.-trait modifier here, as we want arrogant characters to be dramatic little bastards.
		modifier = {
			add = -30
			desc = AI_OPINION_OFFENDED
			scope:diarchy_ending_gift_stiffed = yes
		}
		## Favour.
		### Deceitful variant.
		modifier = {
			add = 60
			desc = liege_dismiss_entrenched_regency_interaction.tt.deceitful_likes_hook
			scope:diarchy_ending_gift_hook = yes
			has_trait = deceitful
		}
		### Base variant.
		modifier = {
			add = 30
			desc = liege_dismiss_entrenched_regency_interaction.tt.offered_gift
			scope:diarchy_ending_gift_hook = yes
			NOT = { has_trait = deceitful }
		}
		## Dynasty Prestige.
		### Dynasty Head variant.
		modifier = {
			add = 60
			desc = liege_dismiss_entrenched_regency_interaction.tt.dynasty_head_likes_dynasty_prestige
			scope:diarchy_ending_gift_dynasty_prestige = yes
			this = dynasty.dynast
		}
		### Base variant.
		modifier = {
			add = 30
			desc = liege_dismiss_entrenched_regency_interaction.tt.offered_gift
			scope:diarchy_ending_gift_dynasty_prestige = yes
			this != dynasty.dynast
		}
		## Piety.
		### Zealous variant.
		modifier = {
			add = 60
			desc = liege_dismiss_entrenched_regency_interaction.tt.zealous_likes_piety
			scope:diarchy_ending_gift_piety = yes
			has_trait = zealous
		}
		### Base variant.
		modifier = {
			add = 30
			desc = liege_dismiss_entrenched_regency_interaction.tt.offered_gift
			scope:diarchy_ending_gift_piety = yes
			NOT = { has_trait = zealous }
		}
		## Cash.
		### Greedy variant.
		modifier = {
			add = 60
			desc = liege_dismiss_entrenched_regency_interaction.tt.greedy_likes_cash
			scope:diarchy_ending_gift_cash = yes
			has_trait = greedy
		}
		### Base variant.
		modifier = {
			add = 30
			desc = liege_dismiss_entrenched_regency_interaction.tt.offered_gift
			scope:diarchy_ending_gift_cash = yes
			NOT = { has_trait = greedy }
		}
		### Also debters like this.
		modifier = {
			add = 60
			desc = PT_AI_IS_IN_DEBT
			scope:diarchy_ending_gift_cash = yes
			debt_level >= 1
		}
	}

	# AI
	ai_targets = { ai_recipients = diarch }
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}
	ai_potential = {
		# Are we in a diarchy at all?
		has_active_diarchy = yes
		# Can we leave it?
		can_leave_diarchy_trigger = yes
		# Are we locked into a speed-leave cycle?
		NOT = { has_character_flag = trying_to_dismiss_regent }
	}

	ai_will_do = {
		# You never _don't_ want to do this.
		base = 1000

		# Flag management.
		## Auto-dismiss.
		modifier = {
			add = 10
			scope:diarchy_ending_gift_unnecessary = yes
		}
		## Stiff 'em.
		### If we hate the diarch, try to stiff them till we can dismiss 'em.
		modifier = {
			scope:diarchy_ending_gift_stiffed = yes
			add = 9
			diarch_liege_wants_to_stiff_regent_trigger = yes
		}
		### Otherwise, try to down prio this. It'll just make things harder.
		modifier = {
			scope:diarchy_ending_gift_stiffed = yes
			add = 1
			diarch_liege_wants_to_stiff_regent_trigger = no
		}
		## Hook.
		modifier = {
			add = 4
			scope:diarchy_ending_gift_hook = yes
		}
		## Dynasty Prestige.
		modifier = {
			add = 5
			scope:diarchy_ending_gift_dynasty_prestige = yes
		}
		## Piety.
		modifier = {
			add = 2
			scope:diarchy_ending_gift_piety = yes
		}
		## Cash.
		modifier = {
			add = 3
			scope:diarchy_ending_gift_cash = yes
		}
		## Herd.
		modifier = {
			add = 5
			scope:diarchy_ending_gift_herd = yes
		}
	}
}

# Liege (actor) dismisses a Vizierate.
liege_dismiss_vizier_interaction = {
	category = interaction_category_diarch
	common_interaction = yes
	icon = icon_dismiss_temporary_regency

	desc = liege_dismiss_vizier_interaction_desc

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Diarchy checks for scope:actor.
		scope:actor = {
			# If you're not in a diarchy, we don't care.
			diarch ?= scope:recipient
			# With the extra consideration that we only want this to appear for Vizierates.
			has_diarchy_parameter = primeminister_dismissal_will_upset_administration
		}
	}

	is_valid_showing_failures_only = {
		# Basic requirements must be fulfilled.
		scope:actor = { can_leave_diarchy_trigger = yes }
	}

	cooldown = { years = 5 }

	on_accept = {
		scope:actor = {
			# We've dismissed your vizier!
			## Do we need to give a warning tooltip first?
			if = {
				limit = { has_diarchy_active_parameter = primeminister_dismissal_will_upset_administration }
				custom_tooltip = liege_dismiss_vizier_interaction.tt.problematic_dismissal.vizier_too_entrenched
			}
			## Now apply the real effects.
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = liege_dismiss_vizier_interaction.toast.t
				left_icon = scope:actor
				# Will this have ripple effects (actual)?
				if = {
					limit = { has_diarchy_active_parameter = primeminister_dismissal_will_upset_administration }
					# Apply the modifier, scaling to how much we dun goofed.
					add_character_modifier = {
						modifier = civil_service_in_chaos_modifier
						years = 10
					}
				}
				# End the diarchy.
				end_diarchy = yes
			}
		}
		# How badly do they take it?
		scope:recipient = {
			# Vengeful takes it badly.
			if = {
				limit = {
					has_trait = vengeful
					can_set_relation_rival_trigger = { CHARACTER = scope:actor }
				}
				set_relation_rival = {
					target = scope:actor
					reason = rival_dismissed_me_from_vizierate
				}
				add_opinion = {
					target = scope:actor
					modifier = insult_opinion
					opinion = -50
				}
			}
			# Even if they have something stopping them from becoming a rival (e.g., they're already your vizier).
			else_if = {
				limit = { has_trait = vengeful }
				add_opinion = {
					target = scope:actor
					modifier = insult_opinion
					opinion = -50
				}
			}
			# Forgiving isn't mad, they're just disappointed.
			else_if = {
				limit = { has_trait = forgiving }
				add_opinion = {
					target = scope:actor
					modifier = insult_opinion
					opinion = -10
				}
			}
			# Otherwise, a bit of pain is to be expected.
			else = {
				progress_towards_rival_effect = {
					REASON = rival_dismissed_me_from_vizierate
					CHARACTER = scope:actor
					OPINION = 0
				}
				# Throw the opinion manually so we can keep the type unified.
				add_opinion = {
					target = scope:actor
					modifier = insult_opinion
					opinion = -25
				}
			}
			# Plus some stress.
			stress_impact = {
				lazy = major_stress_impact_loss
				humble = medium_stress_impact_loss
				content = medium_stress_impact_loss
				diligent = medium_stress_impact_gain
				ambitious = major_stress_impact_gain
				arrogant = major_stress_impact_gain
			}
			# Extravagance modifiers taken care of in the on_action.
		}
		# Plus, remember to advertise to the player that there are alternatives.
		## We're deliberately doing this outside of scope:actor so we can make it a lil subtitle rather than something lumped in with the effect block.
		## Just give 'em a duchy.
		if = {
			limit = {
				scope:actor = { has_diarchy_active_parameter = primeminister_requires_duchy }
			}
			custom_tooltip = liege_dismiss_vizier_interaction.tt.problematic_dismissal.bribe.duchy
		}
		## Just give 'em a county.
		else_if = {
			limit = {
				scope:actor = { has_diarchy_active_parameter = primeminister_requires_county }
			}
			custom_tooltip = liege_dismiss_vizier_interaction.tt.problematic_dismissal.bribe.county
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_dismviz_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_dismviz_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_dismviz_accept_recipient_list }
		}
	}

	auto_accept = yes

	# AI
	ai_targets = { ai_recipients = diarch }
	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}
	ai_potential = { has_active_diarchy = yes }

	ai_will_do = {
		# You should actively want to get rid of them.
		base = -25

		# If you appointed this vizier, don't remove them unless you get booted down to county or something.
		modifier = {
			add = -500
			var:my_vizier ?= scope:recipient
		}

		# Realm.
		## Weight up heavily for counts; they shouldn't generally get them, but they don't want to keep them if they do.
		modifier = {
			add = 1000
			highest_held_title_tier = tier_county
		}
		## Weight up for dukes.
		modifier = {
			add = 25
			highest_held_title_tier = tier_duchy
		}
		## Weight down for kings.
		modifier = {
			add = -25
			highest_held_title_tier = tier_kingdom
		}
		## Weight down for emperors.
		modifier = {
			add = -50
			highest_held_title_tier >= tier_empire
		}
		## Realm Size.
		### Smaller you are, the more likely you are to do this.
		### Tiny or less.
		modifier = {
			add = 50
			realm_size <= tiny_realm_size
		}
		### Minor.
		modifier = {
			add = 25
			realm_size > tiny_realm_size
			realm_size <= minor_realm_size
		}
		### Major.
		modifier = {
			add = -25
			realm_size >= major_realm_size
			realm_size < massive_realm_size
		}
		### Massive or more.
		modifier = {
			add = -50
			realm_size >= massive_realm_size
		}

		# Traits.
		## +++ Ambitious.
		modifier = {
			add = 25
			has_trait = ambitious
		}
		## +++ Arrogant.
		modifier = {
			add = 25
			has_trait = arrogant
		}
		## ++ Diligent.
		modifier = {
			add = 15
			has_trait = diligent
		}
		## ++ Patient.
		modifier = {
			add = 15
			has_trait = patient
		}
		## + Gregarious.
		modifier = {
			add = 5
			has_trait = gregarious
		}
		## - Shy.
		modifier = {
			add = -5
			has_trait = shy
		}
		## - Content.
		modifier = {
			add = -5
			has_trait = content
		}
		## -- Impatient.
		modifier = {
			add = -15
			has_trait = impatient
		}
		## -- Content.
		modifier = {
			add = -15
			has_trait = content
		}
		## -- Humble.
		modifier = {
			add = -15
			has_trait = humble
		}
		## --- Greedy.
		modifier = {
			add = -25
			has_trait = greedy
		}
		## --- Lazy.
		modifier = {
			add = -25
			has_trait = lazy
		}
	}
}

# A vassal requests their liege designate them as regent, should the need arise.
declare_me_regent_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent
	filter_tags = { admin_liege }

	desc = declare_me_regent_interaction_desc
	notification_text = DECLARE_ME_REGENT_PROPOSAL

	interface_priority = 20
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		# The obvious.
		scope:actor != scope:recipient
		# Only useable on your liege.
		scope:recipient = scope:actor.liege
		# And said-liege can't be in a regency already...
		scope:recipient = {
			trigger_if = {
				limit = {
					NOT = { has_diarchy_type = grand_secretariat }
				}
				has_active_diarchy = no
			}
			trigger_else = {
				scope:actor = {
					OR = {
						has_title = title:e_minister_grand_marshal
						has_title = title:e_minister_chancellor
						has_title = title:e_minister_censor
					}
				}
			}
		}
		# ... or have declared you their regent already!
		scope:actor = {
			is_designated_diarch = no
			NOR = {
				is_diarch_of_target = scope:recipient
				# Can't be used during the Cid story cycle
				has_variable = ongoing_cid_story_cycle
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			# Can't do if you're already expected to be regent.
			is_designated_diarch = no
			# Can't be too young.
			is_adult = yes
			# Or imprisoned.
			is_imprisoned = no
			# Or, for that matter, incapable.
			NOT = { has_trait = incapable }
			is_diarch_valid_trigger = yes
		}
		# Put a general cooldown on this stuff.
		scope:recipient = {
			trigger_if = {
				limit = {
					exists = designated_diarch
				}
				time_after_diarch_designated = { years >= 10 }
			}
		}
	}

	# No general cooldown: if your liege changes, ask away.
	# Long specific cooldown, though. We don't want these going through constantly.
	cooldown_against_recipient = { years = 10 }

	# High cost to reduce spam.
	cost = { prestige = 500 }

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

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = declare_me_regent_interaction.tt.success
				left_icon = scope:recipient
				# Jump the queue to become diarch.
				scope:recipient = {
					if = {
						limit = {
							has_diarchy_type = grand_secretariat
						}
						if = {
							limit = {
								scope:actor = {
									has_title = title:e_minister_grand_marshal
								}
							}
							add_realm_law = grand_marshal_law
						}
						else_if = {
							limit = {
								scope:actor = {
									has_title = title:e_minister_chancellor
								}
							}
							add_realm_law = grand_chancellor_law
						}
						else_if = {
							limit = {
								scope:actor = {
									has_title = title:e_minister_censor
								}
							}
							add_realm_law = grand_censor_law
						}
						scope:actor = {
							set_variable = {
								name = asked_to_be_secretary_director
								value = yes
							}
						}
					}
					else = {
						designate_diarch = scope:actor
					}
				}
				# This prompts some strife.
				change_strife_opinion = major_strife_gain
			}
			# If you used a hook, calc some extra stuff.
			## We move this outside of the toast because we've not got enough room for all this info in there.
			if = {
				limit = {
					scope:hook = yes
					has_usable_hook = scope:recipient
				}
				# Use the hook up.
				use_hook = scope:recipient
				# Plus scope:recipient is _very_ upset.
				reverse_add_opinion = {
					target = scope:recipient
					modifier = suspicion_opinion
					opinion = -20
				}
			}
		}
		scope:recipient = {
			# Some folks may not be happy.
			custom_tooltip = declare_me_regent_interaction.tt.warning.opinions.succession
			custom_tooltip = declare_me_regent_interaction.tt.warning.opinions.courtlies
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_desigme_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_desigme_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_desigme_accept_recipient_list }
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = declare_me_regent_interaction.tt.failure
				left_icon = scope:recipient
				# AI lose opinion of their opposite number.
				if = {
					limit = { is_ai = yes }
					add_opinion = {
						target = scope:recipient
						modifier = insult_opinion
						opinion = -40
					}
				}
				# Even trying produces some strife.
				change_strife_opinion = medium_strife_gain
			}
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_desigme_decline }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_desigme_decline_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_desigme_decline_recipient_list }
		}
	}

	auto_accept = {
		scope:recipient = {
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
			}
		}
	}

	ai_accept = {
		# Try to make it 0 for most interactions
		base = -40

		# Weight for dislike of current regent.
		# Designated regent.
		modifier = {
			add = {
				# Designated diarchs.
				if = {
					limit = {
						designated_diarch ?= {
							save_temporary_scope_as = diarch_successor_temp
							save_temporary_opinion_value_as = {
								name = recipient_opinion_temp
								target = scope:diarch_successor_temp
							}
						}
					}
					add = scope:recipient_opinion_temp
					# Invert to get the true total.
					multiply = -1
				}
				# Expected diarchs.
				else_if = {
					limit = {
						diarchy_successor ?= {
							save_temporary_scope_as = diarch_successor_temp
							scope:actor = {
								save_temporary_opinion_value_as = {
									name = recipient_opinion_temp
									target = scope:diarch_successor_temp
								}
							}
						}
					}
					add = scope:recipient_opinion_temp
					# Invert to get the true total.
					multiply = -1
				}
			}
			desc = declare_me_regent_interaction.tt.opinion_of_current_regent
		}
		# Opinion of scope:actor.
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
		# Personality.
		ai_value_modifier = {
			# Meek characters are more likely to accept this.
			ai_boldness = -0.5
			# Characters with low energy just want to avoid all this planning.
			ai_energy = -0.25
		}
		# Familial closeness.
		## Close family get a decent boost.
		modifier = {
			add = 30
			desc = declare_me_regent_interaction.tt.actor_is.close_family
			is_close_family_of = scope:actor
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				NOT = {
					is_close_family_of = scope:recipient
				}
			}
		}
		## Extended family get a minor boost.
		modifier = {
			add = 20
			desc = declare_me_regent_interaction.tt.actor_is.extended_family
			is_extended_family_of = scope:actor
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				NOT = {
					is_extended_family_of = scope:recipient
				}
			}
		}
		## House members get a slight boost.
		modifier = {
			add = 10
			desc = declare_me_regent_interaction.tt.actor_is.house_member
			house = scope:actor.house
			NOT = {
				is_close_or_extended_family_of = scope:actor
			}
			# Make sure this isn't cancelled out by the incumbent sharing the relation.
			diarchy_successor = {
				house != scope:recipient.house
			}
		}
		# Relationships.
		## Positive.
		modifier = {
			add = 25
			desc = declare_me_regent_interaction.tt.actor_is.positive_relationship
			has_any_good_relationship_with_character_trigger = { CHARACTER = scope:actor }
			# We don't factor for this in the designated/expected diarch 'cause the matrix of overlap'd be hellish.
		}
		## Negative.
		modifier = {
			add = -25
			desc = declare_me_regent_interaction.tt.actor_is.negative_relationship
			has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:actor }
			# We don't factor for this in the designated/expected diarch 'cause the matrix of overlap'd be hellish.
		}
		# Succession score is a direct factor.
		modifier = {
			add = scope:actor.diarchy_regent_succession_score_value
			desc = declare_me_regent_interaction.tt.actor_is.succession_score
			scope:recipient = {
				NOT = { has_diarchy_type = grand_secretariat }
			}
		}

		# Grand Secretariat
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			scope:actor.top_participant_group:dynastic_cycle ?= {
				exists = var:movement_favored
	 		}
	 		desc = diarch_candidate_score.grand_secretariat.favored_value
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			scope:actor = {
				is_any_movement_leader = yes
	 		}
	 		desc = you_are_a_movement_leader_desc_value
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			scope:actor = {
				is_in_pro_hegemon_or_hegemon_movement = yes
	 		}
	 		desc = diarch_candidate_score.grand_secretariat.pro_hegemon_value
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			scope:actor = {
				has_court_position = favored_minister_court_position
			}
			desc = grand_secretariat_aptitude.favored_minister_value
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			desc = actors_merit_level_desc
			add = {
				if = {
					limit = {
						scope:actor.merit_level >= scope:actor.top_liege.diarch.merit_level
						scope:actor.merit >= scope:actor.top_liege.merit
					}
					add = 10
				}
				else = {
					add = -10
				}
			}
		}
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			desc = ACTOR_HIGH_MOVEMENT_POWER
			add = {
				if = {
					limit = {
						exists = scope:actor.top_liege.diarch.var:movement_power
						exists = scope:actor.var:movement_power
				 		scope:actor.var:movement_power >= scope:actor.top_liege.diarch.var:movement_power
					}
					add = 10
				}
				else = {
					add = -40
				}
			}
		}
		# Events
		modifier = {
			add = 25
			desc = tgp_power_undermined_modifier_tt
			has_character_modifier = tgp_power_undermined_modifier
			# We don't factor for this in the designated/expected diarch 'cause the matrix of overlap'd be hellish.
		}
	}

	# AI
	#ai_targets = { ai_recipients = liege }
	#ai_frequency = 0
	#
	#ai_potential = {
	#	# Turning off for the AI for the moment due to not being able to display who you'll offend if you do it.
	#	## Should otherwise work and can be turned back on again if wished.
	#	always = no
	#	# Some traits lock the AI out.
	#	## Calc these first 'cause they're cheaper.
	#	NOR = {
	#		has_trait = lazy
	#		has_trait = humble
	#		has_trait = content
	#	}
	#	OR = {
	#		# Driven by traits or personality.
	#		has_trait = arrogant
	#		has_trait = ambitious
	#		# Family think themselves worthy.
	#		any_close_or_extended_family_member = { this = liege }
	#	}
	#}

	ai_will_do = {
		# Most AI think this is audacious.
		base = 0

		# Weight for personality.
		## Both modifier.
		ai_value_modifier = {
			# Bold, energetic characters fancy the gig.
			ai_boldness = 0.5
			ai_energy = 0.5
		}
		## And traits!
		### These are balanced differently to the other interactions, so it's deliberate that they're not using the @values here.
		### +++ Ambitious.
		modifier = {
			add = 15
			has_trait = ambitious
		}
		### ++ Arrogant.
		modifier = {
			add = 10
			has_trait = arrogant
		}
		### + Diligent.
		modifier = {
			add = 5
			has_trait = diligent
		}
		### + Loyal.
		modifier = {
			add = 5
			has_trait = loyal
		}
		### - Humble.
		modifier = {
			add = -5
			has_trait = humble
		}
		### --- Content.
		modifier = {
			add = -15
			has_trait = content
		}
		### --- Lazy.
		modifier = {
			add = -15
			has_trait = lazy
		}
		# Weight by proximity to the ruler: close family, spouses, etc.
		modifier = {
			add = 25
			OR = {
				any_close_or_extended_family_member = { this = scope:recipient }
				any_spouse = { this = scope:recipient }
			}
		}
		# Councillors have ambitions.
		modifier = {
			add = 25
			is_councillor = yes
		}
		# Weight for opinion of current regent.
		modifier = {
			add = {
				scope:recipient = {
					# Designated diarchs.
					if = {
						limit = {
							designated_diarch ?= {
								save_temporary_scope_as = diarch_successor_temp
								scope:actor = {
									save_temporary_opinion_value_as = {
										name = actor_opinion_temp
										target = scope:diarch_successor_temp
									}
								}
							}
						}
						add = scope:actor_opinion_temp
						# Invert to get the true total.
						multiply = -1
					}
					# Expected diarchs.
					else_if = {
						limit = {
							diarchy_successor ?= {
								save_temporary_scope_as = diarch_successor_temp
								scope:actor = {
									save_temporary_opinion_value_as = {
										name = actor_opinion_temp
										target = scope:diarch_successor_temp
									}
								}
							}
						}
						add = scope:actor_opinion_temp
						# Invert to get the true total.
						multiply = -1
					}
				}
			}
			always = yes
		}
		# The AI will only use a Hook if they couldn't otherwise do this
		modifier = {
			scope:hook = yes
			add = -1
		}
		# Grand Secretariat
		modifier = {
			scope:recipient = {
				has_diarchy_type = grand_secretariat
			}
			add = {
				if = {
	 				limit = {
			 			scope:actor.top_participant_group:dynastic_cycle ?= {
				 			exists = var:movement_favored
		 				}
		 			}
					add = 10
				}
				if = {
					limit = {
						scope:actor = {
							has_court_position = favored_minister_court_position
						}
					}
					add = 20
				}
				if = {
	 				limit = {
	 					scope:actor.merit_level >= scope:actor.top_liege.diarch.merit_level
	 					scope:actor.merit >= scope:actor.top_liege.merit
		 			}
					add = 10
				}
				if = {
					limit = {
						exists = scope:actor.top_liege.diarch.var:movement_power
						exists = scope:actor.var:movement_power
					}
					if = {
		 				limit = {
				 			scope:actor.var:movement_power >= scope:actor.top_liege.diarch.var:movement_power
			 			}
						add = 10
					}
					else = {
						add = -100
					}
				}
			}
		}
	}
}

# Liege (actor) selects a vizier to help them run the realm.
appoint_vizier_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent

	desc = appoint_vizier_interaction_desc
	interface_priority = 20

	is_shown = {
		scope:actor = {
			# Must be able to retain a vizier.
			government_has_flag = may_appoint_viziers
			# Plus obscure the interaction if we've already got one, else it's annoyingly redundant.
			NOT = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
		# We perform this upon ourselves or our (probable) candidates.
		trigger_if = {
			limit = {
				exists = scope:secondary_recipient
			}
			scope:secondary_recipient = {
				is_valid_basic_candidate_for_vizier_trigger = yes
				OR = {
					is_courtier_of = scope:actor
					AND = {
						highest_held_title_tier = tier_barony
						liege = scope:actor
					}
				}
			}
		}
		trigger_else = {
			scope:recipient = {
				this = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		# You can't already be in a diarchy of any kind.
		scope:actor = {
			has_active_diarchy = no
		}
		# Must be of a decent tier.
		custom_tooltip = {
			text = appoint_vizier_interaction.tt.duchy_or_more
			scope:actor.highest_held_title_tier >= tier_duchy
		}
		# Plus the usuals.
		scope:actor = { is_available_at_peace = yes }
		# And can't have put the realm into turmoil over this recently.
		scope:actor = {
			NOT = { has_character_modifier = civil_service_in_chaos_modifier }
		}
	}

	cooldown = { years = 5 }

	populate_recipient_list = { sort_vizier_candidates_to_list_effect = yes }

	redirect = {
		if = {
			limit = { scope:recipient != scope:actor }
			scope:recipient = { save_scope_as = secondary_recipient }
			scope:actor = { save_scope_as = recipient }
		}
	}

	cost = {
		prestige = major_prestige_value
		renown = {
			if = {
				limit = {
					exists = scope:secondary_recipient
					exists = scope:actor.house
					scope:secondary_recipient.house ?= scope:actor.house
				}
				add = scope:actor.dynasty.massive_dynasty_prestige_value
			}
		}
	}

	auto_accept = yes

	pre_auto_accept = {
		# If we're an AI, set the secondary_recipient up for us.
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				# First, we need to calc who _is_ most qualified; we don't have access to the character list any more, so reassemble it.
				sort_vizier_candidates_to_list_effect = yes
				# Now, parse through the list to find the best character.
				ordered_in_list = {
					list = characters
					order_by = diarchy_vizier_succession_score_value
					save_scope_as = ai_recipient
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			# We enter into a vizierate with scope:secondary_recipient.
			custom_tooltip = {
				text = appoint_vizier_interaction.tt.enter_vizierate_with_secondary_recipient
				try_start_diarchy = vizierate
				# The player uses scope:secondary_recipient.
				if = {
					limit = {
						# We use a NOT here  rather than is_ai = no because the AI was occasionally managing to bork its selection process, and the title does _not_ like setting an empty diarch, so we fallback AI who can't behave to a sub-optimal choice.
						NOT = { exists = scope:ai_recipient }
					}
					set_diarch = scope:secondary_recipient
				}
				# Whereas the AI grabs their pre-selected candidate.
				else = {
					set_diarch = scope:ai_recipient
				}
			}
			# Apply opinion.
			## AI.
			if = {
				limit = { exists = scope:ai_recipient }
				scope:ai_recipient = {
					add_opinion = {
						target = scope:actor
						modifier = compliment_opinion
						opinion = 30
					}
					stress_impact = {
						ambitious = minor_stress_impact_loss
						arrogant = minor_stress_impact_loss
						lazy = major_stress_impact_gain
					}
				}
			}
			## Player.
			else = {
				scope:secondary_recipient = {
					add_opinion = {
						target = scope:actor
						modifier = compliment_opinion
						opinion = 30
					}
					stress_impact = {
						ambitious = minor_stress_impact_loss
						arrogant = minor_stress_impact_loss
						lazy = major_stress_impact_gain
					}
				}
			}
			# And get X tax jurisdictions.
			custom_tooltip = appoint_vizier_interaction.tt.secondary_recipient_grants_tax_jurisdictions
			# If scope:secondary_recipient isn't the most qualified candidate, we'll take a scaling negative stewardship modifier.
			## The AI will always pick the highest scoring character, so we only do this for players - lock it off so we're not doing lots of unnecessary calculating.
			if = {
				limit = { is_ai = no }
				# First, we need to calc who _is_ most qualified; we don't have access to the character list any more, so reassemble it.
				sort_vizier_candidates_to_list_effect = yes
				# Now, parse through the list to find the best character.
				ordered_in_list = {
					list = characters
					order_by = diarchy_vizier_succession_score_value
					save_scope_as = best_candidate
				}
				# Is our chap _the_ chap?
				if = {
					limit = {
						scope:secondary_recipient != scope:best_candidate
					}
					# Ok, now display some warnings.
					custom_tooltip = appoint_vizier_interaction.tt.secondary_recipient_is_not_best_candidate
					add_character_modifier = {
						modifier = civil_service_upset_modifier
						years = 10
					}
				}
			}
			# Are they of our house?
			if = {
				limit = {
					exists = scope:secondary_recipient.house
					house ?= scope:secondary_recipient.house
				}
				custom_tooltip = appoint_vizier_interaction.tt.same_house_penalty
			}
			# If we have a designated diarch (and it's not this guy), then they're annoyed.
			designated_diarch ?= {
				if = {
					limit = {
						this != scope:secondary_recipient
					}
					add_opinion = {
						target = scope:actor
						modifier = appointed_vizier_over_designated_regent_opinion
						opinion = -40
					}
				}
			}
			# Set a reminder that we appointed this vizier — the AI'll use this to help with determining whether they should remove them or not.
			set_variable = {
				name = my_vizier
				value = scope:recipient
			}
			# Finally, let's do some stress.
			stress_impact = {
				trusting = massive_stress_impact_loss
				lazy = major_stress_impact_loss
				paranoid = minor_stress_impact_gain
				diligent = minor_stress_impact_gain
			}
		}
		# Notify about council problemos.
		scope:secondary_recipient = {
			if = {
				limit = { is_councillor = yes }
				custom_tooltip = appoint_vizier_interaction.tt.warning.vizier_replace_councillor
			}
		}

		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_appviz_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appviz_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appviz_accept_recipient_list }
		}
	}

	# AI
	ai_targets = { ai_recipients = self }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 240
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	ai_potential = {
		government_has_flag = may_appoint_viziers
	}

	ai_will_do = {
		base = 0

		# Realm.
		## Weight up for kings.
		modifier = {
			add = 50
			highest_held_title_tier = tier_kingdom
		}
		## Weight up for emperors.
		modifier = {
			add = 75
			highest_held_title_tier >= tier_empire
		}
		## Add realm size directly.
		modifier = {
			add = sub_realm_size
			is_landed = yes
		}

		# Traits.
		## +++ Lazy.
		modifier = {
			add = 25
			has_trait = lazy
		}
		## +++ Greedy.
		modifier = {
			add = 25
			has_trait = greedy
		}
		## ++ Humble.
		modifier = {
			add = 15
			has_trait = humble
		}
		## ++ Content.
		modifier = {
			add = 15
			has_trait = content
		}
		## ++ Impatient.
		modifier = {
			add = 15
			has_trait = impatient
		}
		## + Content.
		modifier = {
			add = 5
			has_trait = content
		}
		## + Shy.
		modifier = {
			add = 5
			has_trait = shy
		}
		## - Gregarious.
		modifier = {
			add = -5
			has_trait = gregarious
		}
		## -- Patient.
		modifier = {
			add = -15
			has_trait = patient
		}
		## -- Diligent.
		modifier = {
			add = -15
			has_trait = diligent
		}
		## --- Arrogant.
		modifier = {
			add = -25
			has_trait = arrogant
		}
		## --- Ambitious.
		modifier = {
			add = -25
			has_trait = ambitious
		}
	}
}

# Liege (actor) selects a junior emperor to be their heir.
appoint_junior_emperor_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent
	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		if = {
			limit = { scope:secondary_recipient = scope:actor }
			clear_saved_scope = secondary_recipient
		}
		if = {
			limit = {
				NOT = {
					scope:secondary_recipient ?= { valid_junior_emperor_candidate_trigger = { LIEGE = scope:actor } }
				}
			}
			clear_saved_scope = secondary_recipient
		}
	}

	desc = appoint_junior_emperor_interaction_desc
	interface_priority = 20

	is_shown = {
		# Must be able to retain a co-emperor.
		scope:actor = { may_appoint_co_emperors_trigger = yes }
		# We perform this upon ourselves or our (probable) candidates.
		OR = {
			scope:recipient ?= scope:actor
			scope:secondary_recipient ?= { valid_junior_emperor_candidate_trigger = { LIEGE = scope:actor } }
		}
	}

	is_valid_showing_failures_only = {
		# You can't already be in a diarchy of any kind.
		scope:actor = {
			has_active_diarchy = no
		}
		# Make sure we're targeting the right people, since redirects make this a lil slippery.
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { valid_junior_emperor_candidate_trigger = { LIEGE = scope:actor } }
		}
		# Plus the usuals.
		scope:actor = { is_available_at_peace = yes }
	}

	populate_recipient_list = { sort_junior_emperor_candidates_to_list_effect = yes }

	cost = {
		prestige = designate_heir_admin_prestige_cost
		influence = designate_heir_admin_influence_cost
	}

	auto_accept = yes

	pre_auto_accept = {
		# If we're an AI, set the secondary_recipient up for us.
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				# First, we need to calc who _is_ most qualified; we don't have access to the character list any more, so reassemble it.
				sort_junior_emperor_candidates_to_list_effect = yes
				# Now, parse through the list to find the best character.
				## And by that I mean play literal favourites.
				ordered_in_list = {
					list = characters
					order_by = "reverse_opinion(scope:actor)"
					save_scope_as = ai_recipient
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			# We enter into a junior emperorship with scope:secondary_recipient.
			## The player uses scope:secondary_recipient.
			if = {
				limit = {
					# We use a NOT here  rather than is_ai = no because the AI was occasionally managing to bork its selection process, and the title does _not_ like setting an empty diarch, so we fallback AI who can't behave to a sub-optimal choice.
					NOT = { exists = scope:ai_recipient }
				}
				custom_tooltip = {
					text = appoint_junior_emperor_interaction.tt.enter_junior_emperorship_with_secondary_recipient
					try_start_diarchy = junior_emperorship
					set_diarch = scope:secondary_recipient
				}
				# We set them to be our designated heir.
				## & if we already have an heir, warn that this overwrites it.
				designated_heir ?= {
					if = {
						limit = { this != scope:secondary_recipient }
						custom_tooltip = appoint_junior_emperor_interaction.tt.overwrite_designated_heir
						# Nab them for use further on.
						save_scope_as = old_heir
					}
				}
				## Designate and inform.
				set_designated_heir = scope:secondary_recipient
			}
			## Whereas the AI grabs their pre-selected candidate.
			else = {
				try_start_diarchy = junior_emperorship
				set_diarch = scope:ai_recipient
				# We set them to be our designated heir.
				## First grabbing the old one for opinions.
				designated_heir ?= {
					if = {
						limit = { this != scope:ai_recipient }
						# Nab them for use further on.
						save_scope_as = old_heir
					}
				}
				## Then overwriting.
				set_designated_heir = scope:ai_recipient
			}
		}
		# And remember who appointed them on scope:recipient.
		grateful_for_appointment_as_co_emperor_effect = yes
		# Your designated heir is _very_ pissed.
		diarch_overwrites_old_designated_heir_apply_opinions_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Your designated regent is also unhappy (probably).
		designated_diarch_overwridden_by_co_ruler_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Make sure we have our co-ruler directly with us.
		## Courtiers are given to us immediately.
		if = {
			limit = {
				scope:secondary_recipient = { is_ruler = no }
				scope:secondary_recipient = { NOT = { is_in_the_same_court_as = scope:actor } }
			}
			scope:actor = { add_courtier = scope:secondary_recipient }
		}
		## Vassals are retracted.
		if = {
			limit = { scope:secondary_recipient.liege != scope:actor }
			scope:secondary_recipient.liege = {
				add_opinion = {
					target = scope:actor
					modifier = retracted_vassal
				}
			}
			scope:secondary_recipient.liege = {
				add_opinion = {
					target = scope:actor
					modifier = retracted_vassal
				}
			}
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = change
			}
			scope:secondary_recipient = {
				change_liege = {
					liege = scope:actor
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}




		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_appjunemp_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appjunemp_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appjunemp_accept_recipient_list }
		}
	}

	# AI
	ai_targets = { ai_recipients = children }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 60
		hegemony = 60
	}

	ai_potential = {
		# Filter us down nice'n'tight.
		may_appoint_co_emperors_trigger = yes
		# Plus rule out any diarchies already on the go.
		has_active_diarchy = no
		# Aaaand finally, the AI won't do this unless they're considering their age and they've got no adult kids.
		age >= 50
		any_child = {
			count = all
			is_adult = no
		}
	}

	ai_will_do = {
		# The AI doesn't like doing this without good reason.
		base = -100

		ai_wants_junior_or_co_emperor_modifier = yes
	}
}

# Liege (actor) selects a co-emperor to be their heir/influence farming stooge.
appoint_co_emperor_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent
	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		if = {
			limit = { scope:secondary_recipient ?= scope:actor }
			clear_saved_scope = secondary_recipient
		}
		if = {
			limit = {
				NOT = {
					scope:secondary_recipient ?= {
						valid_co_emperor_candidate_trigger = { LIEGE = scope:actor }
					}
				}
			}
			clear_saved_scope = secondary_recipient
		}
	}

	desc = appoint_co_emperor_interaction_desc
	interface_priority = 280

	is_shown = {
		# Must be able to retain a co-emperor.
		scope:actor = { may_appoint_co_emperors_trigger = yes }
		# We perform this upon ourselves or our (probable) candidates.
		OR = {
			scope:recipient ?= scope:actor
			scope:secondary_recipient ?= {
				valid_co_emperor_candidate_trigger = { LIEGE = scope:actor }
			}
		}
	}

	is_valid_showing_failures_only = {
		# You can't already be in a diarchy of any kind.
		scope:actor = {
			has_active_diarchy = no
		}
		# Make sure we're targeting the right people, since redirects make this a lil slippery.
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = {
				valid_co_emperor_candidate_trigger = { LIEGE = scope:actor }
			}
		}
		# Plus the usuals.
		scope:actor = { is_available_at_peace = yes }
	}

	populate_recipient_list = { sort_co_emperor_candidates_to_list_effect = yes }

	cost = {
		prestige = designate_heir_admin_prestige_cost
		influence = designate_heir_admin_influence_cost
	}

	auto_accept = yes

	pre_auto_accept = {
		# If we're an AI, set the secondary_recipient up for us.
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				# First, we need to calc who _is_ most qualified; we don't have access to the character list any more, so reassemble it.
				sort_co_emperor_candidates_to_list_effect = yes
				# Now, parse through the list to find the best character.
				## And by that I mean play literal favourites.
				ordered_in_list = {
					list = characters
					order_by = {
						value = "reverse_opinion(scope:actor)"
						# Boost up anyone we're related to by blood or marriage.
						if = {
							limit = {
								OR = {
									is_close_or_extended_family_of = scope:actor
									house ?= scope:actor.house
									any_spouse = { is_close_or_extended_family_of = scope:actor }
								}
							}
							# This means we should _generally_ prefer people who are in with the imperial family, but if we hate them then we boot them down the list even further.
							multiply = 10
						}
					}
					save_scope_as = ai_recipient
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			# We enter into a co-emperorship with scope:secondary_recipient.
			## The player uses scope:secondary_recipient.
			if = {
				limit = {
					# We use a NOT here rather than is_ai = no because the AI was occasionally managing to bork its selection process, and the title does _not_ like setting an empty diarch, so we fallback AI who can't behave to a sub-optimal choice.
					NOT = { exists = scope:ai_recipient }
				}
				custom_tooltip = {
					text = appoint_co_emperor_interaction.tt.enter_co_emperorship_with_secondary_recipient
					try_start_diarchy = co_emperorship
					set_diarch = scope:secondary_recipient
				}
				# If appropriate, we set them to be our designated heir.
				if = {
					limit = {
						scope:secondary_recipient = {
							is_close_or_extended_family_of = scope:actor
							house ?= scope:actor.house
						}
					}
					# & if we already have an heir, warn that this overwrites it.
					designated_heir ?= {
						if = {
							limit = { this != scope:secondary_recipient }
							custom_tooltip = appoint_co_emperor_interaction.tt.overwrite_designated_heir
							# Nab them for use further on.
							save_scope_as = old_heir
						}
					}
					# Designate and inform.
					set_designated_heir = scope:secondary_recipient
				}
			}
			## Whereas the AI grabs their pre-selected candidate.
			else = {
				try_start_diarchy = co_emperorship
				set_diarch = scope:ai_recipient
				# If appropriate, we set them to be our designated heir.
				if = {
					limit = {
						scope:secondary_recipient = {
							is_close_or_extended_family_of = scope:actor
							house ?= scope:actor.house
						}
					}
					# First grabbing the old one for opinions.
					designated_heir ?= {
						if = {
							limit = { this != scope:secondary_recipient }
							# Nab them for use further on.
							save_scope_as = old_heir
						}
					}
					# Then overwriting.
					set_designated_heir = scope:ai_recipient
				}
			}
		}
		# And remember who appointed them on scope:recipient.
		grateful_for_appointment_as_co_emperor_effect = yes
		# Your designated heir is _very_ pissed.
		diarch_overwrites_old_designated_heir_apply_opinions_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Your designated regent is also unhappy (probably).
		designated_diarch_overwridden_by_co_ruler_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Make sure we have our co-ruler directly with us.
		## Courtiers are given to us immediately.
		if = {
			limit = {
				scope:secondary_recipient = { is_ruler = no }
			}
			scope:actor = { add_courtier = scope:secondary_recipient }
		}
		## Vassals are retracted.
		if = {
			limit = {
				scope:secondary_recipient.liege != scope:actor
				scope:secondary_recipient = { NOT = { is_in_the_same_court_as = scope:actor } }
			}
			scope:secondary_recipient.liege = {
				add_opinion = {
					target = scope:actor
					modifier = retracted_vassal
				}
			}
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = change
			}
			scope:secondary_recipient = {
				change_liege = {
					liege = scope:actor
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}




		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_appcoemp_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appcoemp_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appcoemp_accept_recipient_list }
		}
	}

	# AI
	ai_targets = { ai_recipients = children }
	ai_targets = { ai_recipients = vassals }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 60
		hegemony = 60
	}

	ai_potential = {
		# Filter us down nice'n'tight.
		may_appoint_co_emperors_trigger = yes
		# Plus rule out any diarchies already on the go.
		has_active_diarchy = no
		# Aaaand finally, the AI won't do this unless they're considering their age and they've got adult kids.
		age >= 50
		any_child = { is_adult = yes }
	}

	ai_will_do = {
		# The AI doesn't like doing this without good reason.
		base = -100

		ai_wants_junior_or_co_emperor_modifier = yes
	}
}

# Liege (actor) selects one of their children to be their heir & diarch.
appoint_co_monarch_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent
	redirect = {
		scope:recipient = { save_scope_as = secondary_recipient }
		if = {
			limit = { scope:secondary_recipient ?= scope:actor }
			clear_saved_scope = secondary_recipient
		}
		if = {
			limit = {
				NOT = {
					scope:secondary_recipient ?= { is_child_of = scope:actor }
				}
			}
			clear_saved_scope = secondary_recipient
		}
	}

	desc = appoint_co_monarch_interaction_desc
	interface_priority = 20

	is_shown = {
		# Must be able to retain a co-emperor.
		scope:actor = { may_appoint_co_monarchs_trigger = yes }
		# We perform this upon ourselves or our (probable) candidates.
		OR = {
			scope:recipient ?= scope:actor
			scope:secondary_recipient ?= { is_child_of = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		# You can't already be in a diarchy of any kind.
		scope:actor = {
			has_active_diarchy = no
		}
		# Make sure we're targeting the right people, since redirects make this a lil slippery.
		trigger_if = {
			limit = { exists = scope:secondary_recipient }
			scope:secondary_recipient = { valid_co_monarch_candidate_trigger = { LIEGE = scope:actor } }
		}
		# Plus the usuals.
		scope:actor = { is_available_at_peace = yes }
	}

	populate_recipient_list = { sort_co_monarch_candidates_to_list_effect = yes }

	cost = {
		prestige = {
			value = designate_heir_cost
			# Discount it because this _is_ worse than the standard path.
			multiply = 0.5
		}
	}

	auto_accept = yes

	pre_auto_accept = {
		# If we're an AI, set the secondary_recipient up for us.
		scope:actor = {
			if = {
				limit = { is_ai = yes }
				# First, we need to calc who _is_ most qualified; we don't have access to the character list any more, so reassemble it.
				sort_co_monarch_candidates_to_list_effect = yes
				# Now, parse through the list to find the best character.
				## And by that I mean play literal favourites.
				ordered_in_list = {
					list = characters
					limit = { valid_co_monarch_candidate_trigger = { LIEGE = scope:actor } }
					order_by = "reverse_opinion(scope:actor)"
					save_scope_as = ai_recipient
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			# We enter into a co-emperorship with scope:secondary_recipient.
			## The player uses scope:secondary_recipient.
			if = {
				limit = {
					# We use a NOT here  rather than is_ai = no because the AI was occasionally managing to bork its selection process, and the title does _not_ like setting an empty diarch, so we fallback AI who can't behave to a sub-optimal choice.
					NOT = { exists = scope:ai_recipient }
				}
				custom_tooltip = {
					text = appoint_co_monarch_interaction.tt.enter_co_monarchy_with_secondary_recipient
					try_start_diarchy = co_monarchy
					set_diarch = scope:secondary_recipient
				}
				# We set them to be our designated heir.
				## & if we already have an heir, warn that this overwrites it.
				designated_heir ?= {
					if = {
						limit = { this != scope:secondary_recipient }
						custom_tooltip = appoint_co_monarch_interaction.tt.overwrite_designated_heir
						# Nab them for use further on.
						save_scope_as = old_heir
					}
				}
				## Designate and inform.
				set_designated_heir = scope:secondary_recipient
			}
			## Whereas the AI grabs their pre-selected candidate.
			else = {
				try_start_diarchy = co_emperorship
				set_diarch = scope:ai_recipient
				# We set them to be our designated heir.
				## First grabbing the old one for opinions.
				designated_heir ?= {
					if = {
						limit = { this != scope:secondary_recipient }
						# Nab them for use further on.
						save_scope_as = old_heir
					}
				}
				## Then overwriting.
				set_designated_heir = scope:ai_recipient
			}
		}
		# And remember who appointed them on scope:recipient.
		grateful_for_appointment_as_co_emperor_effect = yes
		# Your designated heir is _very_ pissed.
		diarch_overwrites_old_designated_heir_apply_opinions_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Your designated regent is also unhappy (probably).
		designated_diarch_overwridden_by_co_ruler_effect = {
			LIEGE = scope:actor
			CO_RULER = scope:secondary_recipient
		}
		# Make sure we have our co-ruler directly with us.
		## Courtiers are given to us immediately.
		if = {
			limit = {
				scope:secondary_recipient = { is_ruler = no }
				scope:secondary_recipient = { NOT = { is_in_the_same_court_as = scope:actor } }
			}
			scope:actor = { add_courtier = scope:secondary_recipient }
		}
		## Vassals are retracted.
		if = {
			limit = { scope:secondary_recipient.liege != scope:actor }
			scope:secondary_recipient.liege = {
				add_opinion = {
					target = scope:actor
					modifier = retracted_vassal
				}
			}
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = change
			}
			scope:secondary_recipient = {
				change_liege = {
					liege = scope:actor
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}




		# Object explorer logging.
		scope:actor = {
			diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_appcomon_accept }
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appcomon_accept_actor_list }
		}
		scope:recipient = {
			diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_appcomon_accept_recipient_list }
		}
	}

	# AI
	ai_targets = { ai_recipients = children }
	ai_frequency_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	ai_potential = {
		# Filter us down nice'n'tight.
		may_appoint_co_monarchs_trigger = yes
		# Plus rule out any diarchies already on the go.
		has_active_diarchy = no
		# Aaaand finally, the AI won't do this unless they're considering their age and they've got adult kids.
		age >= 50
		any_child = { is_adult = yes }
	}

	ai_will_do = {
		# The AI doesn't like doing this without good reason.
		base = -100

		ai_wants_junior_or_co_emperor_modifier = yes
	}
}

# Start a scheme to replace an incumbent regent.
overthrow_regent_scheme_interaction = {
	category = interaction_category_diarch
	icon = icon_declare_me_regent
	ignores_pending_interaction_block = yes

	scheme = overthrow_regent
	desc = overthrow_regent_scheme_interaction_desc

	interface_priority = 20

	is_shown = {
		# Standard setup.
		scope:actor.liege ?= {
			has_active_diarchy = yes
			# You can't overthrow non-regencies. At least not this way.
			has_diarchy_parameter = diarchy_is_regency
		}
		scope:recipient = {
			this != scope:actor
			liege ?= {
				this = scope:actor.liege
				diarch ?= scope:recipient
				this != scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		# Make sure you wouldn't just cop out immediately.
		## Disabling is fine, FWIW. You'll de-disable with time.
		scope:actor = { is_diarch_valid_trigger = yes }
		# Have we been vetoed from succession due to politicking?
		custom_tooltip = {
			text = overthrow_regent_scheme_interaction.tt.filtered_due_to_incumbent_politicking
			NOT = { scope:actor.var:diarch_succession_filtered_due_to_incumbents_politicking ?= scope:recipient }
		}
	}

	# Long specific cooldown. If you give up, you should give it a rest 'less things change.
	cooldown_against_recipient = { years = 10 }

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = overthrow_regent_scheme_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = overthrow_regent_scheme_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = overthrow_regent_scheme_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = overthrow_regent_scheme_interaction.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:actor = {
			# Sort some stress stuff.
			overthrow_regent_scheme_interaction_actor_stress_effect = yes
			# And some feedback for starting.
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = overthrow_regent_scheme_interaction.tt.started_scheme
				left_icon = scope:actor
				right_icon = scope:recipient
				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = overthrow_regent
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_thug
						AGENT_2 = agent_ambusher
						AGENT_3 = agent_muscle
						# Speed.
						AGENT_4 = agent_footpad
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = overthrow_regent
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_footpad
						AGENT_2 = agent_tracker
						AGENT_3 = agent_planner
						# Success.
						AGENT_4 = agent_thug
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = overthrow_regent
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_lookout
						AGENT_2 = agent_lookout
						AGENT_3 = agent_decoy
						# Success.
						AGENT_4 = agent_thug
						# Speed.
						AGENT_5 = agent_footpad
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = overthrow_regent
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_thug
						AGENT_2 = agent_ambusher
						# Speed.
						AGENT_3 = agent_footpad
						AGENT_4 = agent_planner
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
			}
		}
	}

	auto_accept = yes

	# AI
	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = scripted_relations
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_potential = {
		# Some traits lock the AI out.
		## Calc these first 'cause they're cheaper.
		NOR = {
			has_trait = lazy
			has_trait = humble
			has_trait = content
		}
		OR = {
			# Driven by traits or personality.
			has_trait = arrogant
			has_trait = ambitious
			# Family think themselves worthy.
			any_close_or_extended_family_member = { this = liege }
			# If you're rivals with the current regent, that's a good cause.
			any_relation = {
				type = rival
				is_diarch_of_target = root.liege
			}
		}
	}

	ai_will_do = {
		# Most AI think this is audacious.
		base = -50

		# Opinion Factor
		opinion_modifier = {
			opinion_target = scope:recipient
			multiplier = -1
		}
		# Weight for personality.
		## Both modifier.
		ai_value_modifier = {
			# Bold, energetic characters fancy the gig.
			ai_boldness = 0.5
			ai_energy = 0.5
		}
		## And traits!
		### These are balanced differently to the other interactions, so it's deliberate that they're not using the @values here.
		### +++ Loyal (if current regent is disloyal).
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = loyal
			exists = liege
			scope:recipient = { diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold }
			diarch_loyalty_score_type_regency_value >= diarch_loyalty_visibly_loyal_threshold
		}
		### +++ Disloyal (if current regent is loyal).
		modifier = {
			add = diarch_ai_desire_plus_3_value
			has_trait = disloyal
			exists = liege
			scope:recipient = { diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold }
			diarch_loyalty_score_type_regency_value >= diarch_loyalty_visibly_disloyal_threshold
		}
		### ++ Ambitious.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = ambitious
		}
		### ++ Arrogant.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = arrogant
		}
		### ++ Deceitful.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			has_trait = deceitful
		}
		### + Diligent.
		modifier = {
			add = diarch_ai_desire_plus_1_value
			has_trait = diligent
		}
		### - Lazy.
		modifier = {
			add = diarch_ai_desire_minus_1_value
			has_trait = lazy
		}
		### -- Honest.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = honest
		}
		### -- Humble.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = humble
		}
		### -- Content.
		modifier = {
			add = diarch_ai_desire_minus_2_value
			has_trait = content
		}
		### --- Disloyal (if current regent is disloyal).
		modifier = {
			add = diarch_ai_desire_minus_3_value
			has_trait = disloyal
			exists = liege
			scope:recipient = { diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold }
			diarch_loyalty_score_type_regency_value <= diarch_loyalty_visibly_disloyal_threshold
		}
		### --- Loyal (if current regent is loyal).
		#### Also some loyal-adjacent traits that would otherwise cause stress.
		modifier = {
			add = diarch_ai_desire_minus_3_value
			OR = {
				has_trait = loyal
				has_trait = honest
				has_trait = compassionate
				has_trait = just
			}
			exists = liege
			scope:recipient = { diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold }
			diarch_loyalty_score_type_regency_value >= diarch_loyalty_visibly_loyal_threshold
		}
		# Weight by proximity to the ruler: close family, spouses, etc.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			exists = scope:recipient.liege
			OR = {
				any_close_or_extended_family_member = { this = scope:recipient.liege }
				any_spouse = { this = scope:recipient.liege }
			}
		}
		# Councillors have ambitions.
		modifier = {
			add = diarch_ai_desire_plus_2_value
			is_councillor = yes
		}
		# Factors.
		## If relations are near-perfect, we don't want to go plotting, as it'll look weird.
		modifier = {
			factor = 0
			OR = {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				opinion = {
					target = scope:recipient
					value >= very_high_positive_opinion
				}
			}
		}
	}
}
