﻿#############
# Diarchy Scripted Effects
#############

##################################################
# Debug Effects

log_diarch_send_interaction_as_variable_effect = {
	if = {
		limit = { always = no }
		# Did a landless diarch send this?
		if = {
			limit = {
				scope:actor = { is_ruler = no }
			}
			if = {
				limit = {
					NOT = { exists = global_var:landless_diarch_tried_$INTERACTION$ }
				}
				set_global_variable = {
					name = landless_diarch_tried_$INTERACTION$
					value = 1
				}
			}
			else = {
				change_global_variable = {
					name = landless_diarch_tried_$INTERACTION$
					add = 1
				}
			}
		}
	}
}

# These two effects exist to allow quantitative tracking of how many characters in the world are actually using diarch interactions & in what numbers mid-game — left in case Design needs to do more frequency checking & doesn't want to re-script everything.
diarch_interaction_set_or_update_global_variable_effect = {
	if = {
		limit = { always = no }
		if = {
			limit = {
				NOT = { exists = global_var:$VARIABLE$ }
			}
			set_global_variable = {
				name = $VARIABLE$
				value = 1
			}
		}
		else = {
			change_global_variable = {
				name = $VARIABLE$
				add = 1
			}
		}
	}
}
diarch_interaction_add_to_global_list_effect = {
	if = {
		limit = { always = no }
		add_to_global_variable_list = {
			name = $VARIABLE_LIST$
			target = this
		}
	}
}

##################################################
# Historical Effects

remove_generated_diarch_consequences_effect = {
	$NEW_DIARCH$ = {
		remove_opinion = {
			target = $LIEGE$
			modifier = designated_me_regent_opinion
		}
	}
	$LIEGE$ = {
		every_diarchy_succession_character = {
			remove_opinion = {
				target = $LIEGE$
				modifier = passed_me_over_for_regent_opinion
			}
		}
		every_vassal = {
			vassal_stance = courtly
			remove_opinion = {
				target = $LIEGE$
				modifier = designated_bad_regent_opinion
			}
		}
	}
}

##################################################
# Decision Effects

ai_diarch_check_to_see_if_should_launch_coup_effect = {
	scope:actor = {
		if = {
			limit = {
				# Robots only, please.
				is_ai = yes
				# Check that this is the diarch.
				is_diarch_of_target = scope:recipient
				# Plus a few checks for scope:recipient.
				scope:recipient = {
					# Then, we look to see if we've hit that magic number.
					has_diarchy_active_parameter = regents_can_try_to_overthrow_present_lieges
					# Finally, make sure that scope:recipient doesn't have a sensibility cooldown on 'em.
					NOT = { has_character_flag = immune_ai_coups }
				}
				# Only disloyal diarchs will even consider this. It's really not for casuals.
				diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold
			}
			# Right, lets try for some treason, then!
			trigger_event = diarchy.9031
		}
	}
}

diarch_finalise_conspirators_for_overthrow_list_effect = {
	# The list we know we have.
	every_in_list = {
		variable = coup_pv_supporters_list
		limit = {
			diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = prev.liege }
		}
		add_to_list = coup_pv_supporters_final_list
	}
	# & the lists we only might have.
	## Hooks.
	if = {
		limit = { has_variable_list = coup_promise_list_weak_hook }
		every_in_list = {
			variable = coup_promise_list_weak_hook
			limit = {
				diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = prev.liege }
			}
			add_to_list = coup_promise_list_weak_hook_final
		}
	}
	## Strong hooks.
	if = {
		limit = { has_variable_list = coup_promise_list_strong_hook }
		every_in_list = {
			variable = coup_promise_list_strong_hook
			limit = {
				diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = prev.liege }
			}
			add_to_list = coup_promise_list_strong_hook_final
		}
	}
	## Gold.
	if = {
		limit = { has_variable_list = coup_promise_list_gold }
		every_in_list = {
			variable = coup_promise_list_gold
			limit = {
				diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = prev.liege }
			}
			add_to_list = coup_promise_list_gold_final
		}
	}
	## Big gold.
	if = {
		limit = { has_variable_list = coup_promise_list_big_gold }
		every_in_list = {
			variable = coup_promise_list_big_gold
			limit = {
				diarch_coup_valid_conspiracy_culmination_vassals_trigger = { LIEGE = prev.liege }
			}
			add_to_list = coup_promise_list_big_gold_final
		}
	}
}

diarch_clean_up_conspiracy_variables_effect = {
	if = {
		limit = { is_alive = yes }
		remove_variable = coup_pv_supporters_list
		remove_variable = coup_promise_list_weak_hook
		remove_variable = coup_promise_list_strong_hook
		remove_variable = coup_promise_list_gold
		remove_variable = coup_promise_list_big_gold
	}
}

diarch_coup_preamble_effects_effect = {
	# Note that we don't want a list when it comes to the coup event.
	save_scope_value_as = {
		name = disable_display_rightful_imprisonment_tooltip
		value = yes
	}
	# If there's an alliance, it's pretty decisively broken.
	if = {
		limit = { is_allied_to = scope:liege }
		break_alliance_due_to_attack_effect = { TARGET = scope:liege }
	}
	# And don't forget stress!
	stress_impact = {
		base = major_stress_impact_gain
		disloyal = medium_stress_impact_loss
		ambitious = minor_stress_impact_loss
		arrogant = minor_stress_impact_loss
		callous = miniscule_stress_impact_loss
		arbitrary = miniscule_stress_impact_loss
		just = minor_stress_impact_gain
		humble = medium_stress_impact_gain
		content = medium_stress_impact_gain
		loyal = major_stress_impact_gain
	}
	# Register that the AI shouldn't try to coup liege again for a *while*.
	scope:liege = {
		add_character_flag = {
			flag = immune_ai_coups
			years = 50
		}
	}
}

##################################################
# Activities

remove_strife_per_invited_powerful_vassal_effect = {
	scope:activity = {
		if = {
			limit = {
				# Does scope:host have any strife to take care of?
				scope:host = {
					exists = liege
					strife_opinion >= 1
				}
				any_attending_character = {
					this != scope:host
					is_powerful_vassal_of = scope:host.liege
				}
			}
			# Save a variable for the loc key so that we don't need to parse a million scopes _into_ the key.
			## We do it this way because the custom_tooltip otherwise gets real finnicky about having 
			scope:host = {
				set_variable = {
					name = strife_loss_total
					value = {
						value = scope:activity.diarch_reduced_strife_for_inviting_powerful_covassals_value
						# Invert it for UX purposes.
						multiply = -1
					}
				}
			}
			custom_tooltip = remove_strife_per_invited_powerful_vassal_effect.tt
			## Don't forget to remove the variable!
			# Now, change the actual strife.
			hidden_effect = {
				scope:host = { change_strife_opinion = scope:activity.diarch_reduced_strife_for_inviting_powerful_covassals_value }
			}
		}
	}
}

##################################################
# Character Interactions

diarch_changed_own_contract_effect = {
	if = {
		limit = { always = scope:diarch }
		scope:recipient = {
			custom_tooltip = liege_modify_vassal_contract_interaction.tt.diarch_powers_used
			# Co-rulers lose a fair bit less & can change multiple times.
			if = {
				limit = {
					diarch ?= scope:actor
					has_diarchy_active_parameter = diarchy_is_co_rulership
				}
				add_opinion = {
					target = scope:actor
					modifier = abused_position_of_trust_opinion
					opinion = -10
				}
			}
			# Everyone else loses much more.
			else = {
				add_to_variable_list = {
					name = diarch_contract_rights_used_list
					target = scope:actor
				}
				add_opinion = {
					target = scope:actor
					modifier = abused_position_of_trust_opinion
					opinion = -40
				}
			}
		}
	}
}

diarch_revoke_title_interaction_intermediary_fail_opinions_effect = {
	# Scope:actor dislikes scope:intermediary.
	scope:actor = {
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}
	# Scope:recipient has mixed feelings.
	scope:recipient = {
		# Specifically, they're now happy with scope:intermediary...
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = protected_me_opinion
				opinion = 20
			}
			# ... but upset with scope:actor.
			add_opinion = {
				target = scope:actor
				modifier = revoked_title
			}
		}
	}
}

diarch_retract_vassal_interaction_intermediary_fail_opinions_effect = {
	# Scope:actor dislikes scope:intermediary.
	scope:actor = {
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}
	# Scope:recipient has mixed feelings.
	scope:recipient = {
		# Specifically, they're now happy with scope:intermediary...
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = protected_me_opinion
				opinion = 20
			}
			# ... but upset with scope:actor.
			add_opinion = {
				target = scope:actor
				modifier = retracted_vassal
			}
		}
	}
}

diarch_imprison_interaction_intermediary_fail_opinions_effect = {
	# Scope:actor dislikes scope:intermediary.
	scope:actor = {
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = disappointed_opinion
				opinion = -20
			}
		}
	}
	# Scope:recipient has mixed feelings.
	scope:recipient = {
		# Specifically, they're now happy with scope:intermediary...
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = scope:intermediary
				modifier = protected_me_opinion
				opinion = 20
			}
			# ... but upset with scope:actor.
			add_opinion = {
				target = scope:actor
				modifier = imprisoned_me_past
			}
		}
	}
}

diarch_legal_meddling_interaction_success_effect = {
	scope:actor = {
		# Nab the claim.
		add_unpressed_claim = scope:target
		# We nest this so that scope:recipient doesn't have to see their own opinion effects.
		if = {
			limit = {
				this != scope:recipient
			}
			# Add some opinion loss.
			## Counties are worrying.
			if = {
				limit = { scope:target.tier = tier_county }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = annoyed_opinion
					opinion = -20
				}
				change_strife_opinion = minor_strife_gain
			}
			## Duchies are troublesome.
			else_if = {
				limit = { scope:target.tier = tier_duchy }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = angry_opinion
					opinion = -40
				}
				change_strife_opinion = medium_strife_gain
			}
			## Kingdoms are hateful.
			else_if = {
				limit = { scope:target.tier = tier_kingdom }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = hate_opinion
					opinion = -60
				}
				change_strife_opinion = major_strife_gain
			}
		}
	}
	# Object explorer logging.
	scope:actor = {
		diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_legmed_success }
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_legmed_success_actor_list }
	}
	scope:recipient = {
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_legmed_success_recipient_list }
	}
}

diarch_legal_meddling_interaction_fail_effect = {
	scope:actor = {
		# Gain some stress.
		add_stress = minor_stress_gain
		# We nest this so that scope:recipient doesn't have to see their own opinion effects.
		if = {
			limit = {
				this != scope:recipient
			}
			# Add some opinion loss.
			## Counties are worrying.
			if = {
				limit = { scope:target.tier = tier_county }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = respect_opinion
					opinion = -10
				}
			}
			## Duchies are troublesome.
			else_if = {
				limit = { scope:target.tier = tier_duchy }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = annoyed_opinion
					opinion = -20
				}
			}
			## Kingdoms are hateful.
			else_if = {
				limit = { scope:target.tier = tier_kingdom }
				reverse_add_opinion = {
					target = scope:recipient
					modifier = angry_opinion
					opinion = -30
				}
			}
		}
	}
	# Object explorer logging.
	scope:actor = {
		diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_legmed_failure }
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_legmed_failure_actor_list }
	}
	scope:recipient = {
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_legmed_failure_recipient_list }
	}
}

diarch_legal_meddling_interaction_apply_success_effect = {
	# Notify other parties.
	hidden_effect = {
		# Inform the liege.
		scope:actor.liege = {
			send_interface_message = {
				type = msg_diarch_acting_effect
				title = diarch_using_powers.t
				right_icon = scope:recipient
				left_icon = scope:actor
				show_as_tooltip = { diarch_legal_meddling_interaction_success_effect = yes }
			}
		}
		# Inform scope:recipient.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = diarch_legal_meddling_interaction.tt.success
				left_icon = scope:actor
				show_as_tooltip = { diarch_legal_meddling_interaction_success_effect = yes }
			}
		}
	}
	# Finally, fire off the actual effect.
	send_interface_toast = {
		type = event_toast_effect_good
		title = diarch_legal_meddling_interaction.tt.success
		left_icon = scope:recipient
		# Prestige costs.
		## Point out the lack of cost.
		if = {
			limit = { scope:diarch_legal_meddling_interaction_duel_learning = yes }
			custom_tooltip = diarch_interaction_pay_prestige_none
		}
		## Point out the discount.
		else_if = {
			limit = { scope:diarch_legal_meddling_interaction_pay_prestige_partial = yes }
			add_prestige = legal_meddling_interaction_title_discounted_cost_value
		}
		## Soz mate, yerr payin' full price.
		else = { add_prestige = legal_meddling_interaction_title_cost_value }
		# Gib claim & opinion loss.
		diarch_legal_meddling_interaction_success_effect = yes
	}
}

diarch_legal_meddling_interaction_apply_fail_effect = {
	# Notify other parties.
	hidden_effect = {
		# Inform scope:secondary_recipient.
		scope:secondary_recipient = {
			send_interface_message = {
				type = msg_diarch_acting_text_and_effect
				title = diarch_using_powers.t
				desc = diarch_legal_meddling_interaction.tt.failure.liege
				right_icon = scope:recipient
				left_icon = scope:actor
				show_as_tooltip = { diarch_legal_meddling_interaction_fail_effect = yes }
			}
		}
		# Inform scope:recipient.
		scope:recipient = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = diarch_legal_meddling_interaction.tt.failure
				left_icon = scope:actor
				show_as_tooltip = { diarch_legal_meddling_interaction_fail_effect = yes }
			}
		}
	}
	# Finally, fire off the actual effect.
	send_interface_toast = {
		type = event_toast_effect_bad
		title = diarch_legal_meddling_interaction.tt.failure
		left_icon = scope:recipient
		diarch_legal_meddling_interaction_fail_effect = yes
	}
}

diarch_syphon_treasury_interaction_syphon_development_growth_effect = {
	# First, configure the development growth loss to be divided.
	save_scope_value_as = {
		name = county_attribute_loss
		value = $LOSS$
	}
	if = {
		limit = { scope:county_attribute_loss = massive_development_progress_loss }
		custom_tooltip = diarch_syphon_treasury_interaction_syphon_development_growth_massive_tt
	}
	else_if = {
		limit = { scope:county_attribute_loss = major_development_progress_loss }
		custom_tooltip = diarch_syphon_treasury_interaction_syphon_development_growth_major_tt
	}
	else_if = {
		limit = { scope:county_attribute_loss = medium_development_progress_loss }
		custom_tooltip = diarch_syphon_treasury_interaction_syphon_development_growth_medium_tt
	}
	else = { custom_tooltip = diarch_syphon_treasury_interaction_syphon_development_growth_minor_tt }
	# Now, execute our general effects.
	hidden_effect = {
		while = {
			count = syphon_treasury_recipient_county_tally
			random_held_county = {
				limit = {
					NOT = {
						save_temporary_scope_as = current_county
						any_in_list = {
							list = syphon_treasury_affected_counties
							this = scope:current_county
						}
					}
				}
				change_development_progress = syphon_treasury_county_attribute_loss_fraction
				add_to_list = syphon_treasury_affected_counties
			}
		}
	}
}

diarch_syphon_treasury_interaction_syphon_control_effect = {
	# First, configure the control loss to be divided.
	save_scope_value_as = {
		name = county_attribute_loss
		value = $LOSS$
	}
	# Now, execute our general effects.
	while = {
		count = syphon_treasury_recipient_county_tally
		random_held_county = {
			limit = {
				NOT = {
					save_temporary_scope_as = current_county
					any_in_list = {
						list = syphon_treasury_affected_counties
						this = scope:current_county
					}
				}
			}
			change_county_control = syphon_treasury_county_attribute_loss_fraction
			add_to_list = syphon_treasury_affected_counties
		}
	}
}

diarch_syphon_treasury_interaction_caught_embezzling_effect = {
	scope:actor = {
		# Variable results depending on embezzlement level.
		## Very high.
		if = {
			limit = { always = scope:diarch_syphon_treasury_sum_huge }
			# Apply strife.
			change_strife_opinion = monumental_strife_gain
			# Negative opinion.
			scope:recipient = {
				# Greedy characters will not forgive this slight if they can help it.
				if = {
					limit = {
						has_trait = greedy
						can_set_relation_nemesis_trigger = { CHARACTER = scope:actor }
					}
					set_relation_nemesis = {
						target = scope:actor
						reason = rival_tried_to_embezzle
					}
				}
				# Forgiving characters lose a little less.
				else_if = {
					limit = { has_trait = forgiving }
					add_opinion = {
						target = scope:actor
						modifier = disappointed_opinion
						opinion = -10
					}
				}
				# Otherwise, folks do be mad.
				else = {
					add_opinion = {
						target = scope:actor
						modifier = trust_opinion
						opinion = -45
					}
				}
			}
		}
		## High.
		else_if = {
			limit = { always = scope:diarch_syphon_treasury_sum_large }
			# Apply strife.
			change_strife_opinion = massive_strife_gain
			# Negative opinion.
			scope:recipient = {
				# Greedy characters will not forgive this slight if they can help it.
				if = {
					limit = {
						has_trait = greedy
						can_set_relation_rival_trigger = { CHARACTER = scope:actor }
					}
					set_relation_rival = {
						target = scope:actor
						reason = rival_tried_to_embezzle
					}
				}
				# Forgiving characters lose a little less.
				else_if = {
					limit = { has_trait = forgiving }
					add_opinion = {
						target = scope:actor
						modifier = disappointed_opinion
						opinion = -5
					}
				}
				# Otherwise, folks are still somewhat mad.
				else = {
					add_opinion = {
						target = scope:actor
						modifier = trust_opinion
						opinion = -20
					}
				}
			}
		}
		## Medium.
		else_if = {
			limit = { always = scope:diarch_syphon_treasury_sum_medium }
			# Apply strife.
			change_strife_opinion = major_strife_gain
			# Negative opinion.
			## Covered by embezzlement.
			## Greedy characters do still have a bit more room for hate.
			scope:recipient = {
				if = {
					limit = {
						scope:recipient = { has_trait = greedy }
					}
					progress_towards_rival_effect = {
						REASON = rival_tried_to_embezzle
						CHARACTER = scope:actor
						OPINION = 0
					}
				}
			}
		}
		## Low.
		else_if = {
			limit = { always = scope:diarch_syphon_treasury_sum_small }
			# Apply strife.
			change_strife_opinion = medium_strife_gain
			# Negative opinion.
			## Covered by embezzlement.
			## Greedy characters do still have a bit more room for hate.
			scope:recipient = {
				if = {
					limit = {
						scope:recipient = { has_trait = greedy }
					}
					progress_towards_rival_effect = {
						REASON = rival_tried_to_embezzle
						CHARACTER = scope:actor
						OPINION = 0
					}
				}
			}
		}
		# Crime opinion.
		reverse_add_opinion = {
			target = scope:recipient
			modifier = embezzled_opinion
		}
	}
}

diarch_shift_privileges_interaction_success_apply_modifiers_vague_effect = {
	scope:recipient = {
		# We obfuscate at this stage for neater UX.
		custom_tooltip = diarch_shift_privileges_interaction.tt.success.random_negative_effect
	}
}

diarch_shift_privileges_interaction_success_apply_modifiers_actual_effect = {
	# Add a randomised negative modifier.
	random_list = {
		# Target cash.
		100 = {
			ordered_held_title = {
				title_tier = county
				limit = {
					diarch_shift_privileges_valid_target_title_trigger = yes
				}
				order_by = {
					value = title_province.monthly_income
					# Weight down the capital to be the last selected, if we can.
					if = {
						limit = { this = scope:recipient.capital_county }
						add = -1000
					}
				}
				add_county_modifier = {
					modifier = shift_privileges_monopolies_sold_modifier
					years = shift_privileges_modifier_duration_value
				}
				change_county_control = medium_county_control_loss
			}
		}
		# Target levies.
		100 = {
			ordered_held_title = {
				title_tier = county
				limit = {
					diarch_shift_privileges_valid_target_title_trigger = yes
				}
				order_by = {
					value = building_levies
					# Weight down the capital to be the last selected, if we can.
					if = {
						limit = { this = scope:recipient.capital_county }
						add = -1000
					}
				}
				add_county_modifier = {
					modifier = shift_privileges_scutage_exemptions_modifier
					years = shift_privileges_modifier_duration_value
				}
				change_county_control = medium_county_control_loss
			}
		}
		# Target development growth.
		100 = {
			ordered_held_title = {
				title_tier = county
				limit = {
					diarch_shift_privileges_valid_target_title_trigger = yes
				}
				order_by = {
					value = development_rate
					# Weight down the capital to be the last selected, if we can.
					if = {
						limit = { this = scope:recipient.capital_county }
						add = -1000
					}
				}
				add_county_modifier = {
					modifier = shift_privileges_conflicting_deeds_modifier
					years = shift_privileges_modifier_duration_value
				}
				change_county_control = medium_county_control_loss
			}
		}
	}
	# Object explorer logging.
	scope:actor = {
		diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_shiftpriv_success }
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_shiftpriv_success_actor_list }
	}
	scope:recipient = {
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_shiftpriv_success_recipient_list }
	}
}

diarch_shift_privileges_interaction_success_apply_opinion_effect = {
	scope:actor = {
		# Plus opinion loss.
		reverse_add_opinion = {
			target = scope:recipient
			modifier = hate_opinion
			opinion = -30
		}
		# And some strife.
		change_strife_opinion = minor_strife_gain
	}
}

diarch_shift_privileges_interaction_success_apply_other_effect = {
	scope:actor = {
		# Now we dole out some cash.
		add_gold = major_gold_value
	}
}

diarch_shift_privileges_interaction_fail_effect = {
	scope:actor = {
		# Gain some stress, proportional to the size of the realm you're harassing.
		## Counties are a bit of stress.
		if = {
			limit = { scope:recipient.highest_held_title_tier >= tier_county }
			add_stress = minor_stress_gain
		}
		## Duchies are troublesome.
		else_if = {
			limit = { scope:recipient.highest_held_title_tier >= tier_duchy }
			add_stress = medium_stress_gain
		}
		## Kingdoms are a big deal.
		else_if = {
			limit = { scope:recipient.highest_held_title_tier >= tier_kingdom }
			add_stress = major_stress_gain
		}
		# We nest this so that scope:recipient doesn't have to see their own opinion effects.
		if = {
			limit = {
				this != scope:recipient
			}
			# Add some opinion loss.
			reverse_add_opinion = {
				target = scope:recipient
				modifier = angry_opinion
				opinion = -20
			}
		}
	}
	# Object explorer logging.
	scope:actor = {
		diarch_interaction_set_or_update_global_variable_effect = { VARIABLE = di_track_shiftpriv_failure }
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_shiftpriv_failure_actor_list }
	}
	scope:recipient = {
		diarch_interaction_add_to_global_list_effect = { VARIABLE_LIST = di_track_shiftpriv_failure_recipient_list }
	}
}

diarch_shift_privileges_interaction_apply_success_effect = {
	# Notify other parties.
	hidden_effect = {
		# Inform the liege.
		scope:actor.liege = {
			send_interface_message = {
				type = msg_diarch_acting_effect
				title = diarch_using_powers.t
				right_icon = scope:recipient
				left_icon = scope:actor
				show_as_tooltip = {
					diarch_shift_privileges_interaction_success_apply_modifiers_vague_effect = yes
					diarch_shift_privileges_interaction_success_apply_other_effect = yes
				}
			}
		}
		# Inform scope:recipient.
		scope:recipient = {
			send_interface_toast = {
				title = diarch_shift_privileges_interaction.tt.success
				left_icon = scope:actor
				# We apply the actual modifier here, so that scope:recipient can see it.
				diarch_shift_privileges_interaction_success_apply_modifiers_actual_effect = yes
				show_as_tooltip = { diarch_shift_privileges_interaction_success_apply_other_effect = yes }
			}
		}
	}
	# Finally, fire off the actual effect.
	send_interface_toast = {
		title = diarch_shift_privileges_interaction.tt.success
		left_icon = scope:recipient
		# Gib actual gold here.
		diarch_shift_privileges_interaction_success_apply_other_effect = yes
		# Plus talk about a county modifier.
		diarch_shift_privileges_interaction_success_apply_modifiers_vague_effect = yes
	}
	# Finally, apply opinion loss.
	diarch_shift_privileges_interaction_success_apply_opinion_effect = yes
}

diarch_shift_privileges_interaction_apply_fail_effect = {
	# Notify other parties.
	hidden_effect = {
		# Inform scope:secondary_recipient.
		scope:secondary_recipient = {
			send_interface_message = {
				type = msg_diarch_acting_text_and_effect
				title = diarch_using_powers.t
				desc = diarch_shift_privileges_interaction.tt.failure.liege
				right_icon = scope:recipient
				left_icon = scope:actor
				show_as_tooltip = { diarch_shift_privileges_interaction_fail_effect = yes }
			}
		}
		# Inform scope:recipient.
		scope:recipient = {
			send_interface_toast = {
				title = diarch_shift_privileges_interaction.tt.failure
				left_icon = scope:actor
				show_as_tooltip = { diarch_shift_privileges_interaction_fail_effect = yes }
			}
		}
	}
	# Finally, fire off the actual effect.
	send_interface_toast = {
		title = diarch_shift_privileges_interaction.tt.failure
		left_icon = scope:recipient
		diarch_shift_privileges_interaction_fail_effect = yes
	}
}

diarch_swing_scales_guts_effect = {
	# Influence.
	switch = {
		trigger = yes
		scope:swing_influence = {
			show_as_tooltip = {
				change_influence = {
					value = swing_scales_influence_cost_value
					# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
					multiply = legitimacy_regent_swing_scale_multipler_value
					multiply = -1
					round = yes
				}
			}
		}
		# Movement Power.
		scope:swing_movement_power = {
			custom_tooltip = {
				text = swing_scales_decrease_movement_power
				if = {
					limit = {
						exists = var:movement_power_decreased_diarchy
					}
					set_variable = {
					    name = movement_power_decreased_diarchy
					    value = {
					    	value = var:movement_power_decreased_diarchy
					    	add = {
					    		value = movement_power_decreased_diarchy_value
								multiply = legitimacy_regent_swing_scale_multipler_value
							}
					    }
					}
				}
				else = {
					set_variable = {
					    name = movement_power_decreased_diarchy
				    	value = {
				    		value = movement_power_decreased_diarchy_value
							multiply = legitimacy_regent_swing_scale_multipler_value
						}
					}
				}
				#force the update of variables to immediately show changes
				update_character_movement_power_effect = yes
				top_participant_group:dynastic_cycle ?= {
					update_movement_power_effect = yes
				}
			}
		}
		# Prestige.
		scope:swing_prestige = {
			show_as_tooltip = {
				add_prestige = {
					value = swing_scales_prestige_cost_value
					# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
					multiply = legitimacy_regent_swing_scale_multipler_value
					multiply = -1
					round = yes
				}
			}
		}
		# Piety.
		scope:swing_piety = {
			show_as_tooltip = {
				add_piety = {
					value = swing_scales_piety_cost_value
					# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
					multiply = legitimacy_regent_swing_scale_multipler_value
					multiply = -1
					round = yes
				}
			}
		}
		# Cash.
		scope:swing_gold = {
			save_scope_value_as = {
				name = swing_gold_value
				value = {
					value = swing_scales_cash_cost_value
					# LEGITIMACY OF RULER AFFECTS COSTS FOR REGENTS
					multiply = legitimacy_regent_swing_scale_multipler_value
					round = yes
				}
			}
			show_as_tooltip = {
				pay_short_term_gold = {
					target = scope:recipient
					gold = scope:swing_gold_value
				}
			}
			# Scope:actor actually loses their gold when paying the admission price for the interaction, so we silently give scope:recipient gold from nowhere instead.
			hidden_effect = {
				scope:recipient = { add_gold = scope:swing_gold_value }
			}
		}
		# Hook.
		scope:swing_hook = {
			use_hook = scope:recipient
		}
		# HoF.
		scope:swing_hof = {
			show_as_tooltip = {
				add_piety = {
					value = swing_scales_piety_cost_value
					multiply = -1
				}
				pay_short_term_gold = {
					target = scope:actor.faith.religious_head
					gold = swing_scales_cash_cost_value
				}
			}
			# The HoF doesn't need *another* source of cash unless they're fairly minor, so we only actually pay this if they're already very low on cash.
			hidden_effect = {
				scope:actor.faith.religious_head = {
					if = {
						limit = { gold <= 1000 }
						add_gold = scope:actor.swing_scales_cash_cost_value
					}
				}
			}
		}
	}
	if = {
		limit = {
			scope:actor = { is_diarch_of_target = scope:recipient }
			OR = {
				scope:swing_influence = yes
				scope:swing_prestige = yes
				scope:swing_piety = yes
				scope:swing_gold = yes
			}
		}
		if = {
			limit = { scope:recipient.legitimacy_level <= 2 }
			custom_tooltip = legitimacy_swing_scales_cheaper_tt
		}
		else = { custom_tooltip = legitimacy_swing_scales_dearer_tt }
	}
}

overthrow_regent_scheme_interaction_actor_stress_effect = {
	# Loyal stress.
	## Gain stress if current diarch is loyal.
	if = {
		limit = {
			scope:recipient = { diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold }
		}
		stress_impact = {
			honest = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
			loyal = major_stress_impact_gain
		}
		if = {
			limit = { has_trait = loyal }
			custom_tooltip = overthrow_regent_scheme_interaction_actor_stress_effect.tt.loyal.remove_loyal
		}
	}
	## Lose stress if current diarch is disloyal.
	else_if = {
		limit = {
			scope:recipient = { diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold }
		}
		stress_impact = {
			loyal = major_stress_impact_loss
			honest = medium_stress_impact_loss
			compassionate = major_stress_impact_loss
			just = major_stress_impact_loss
		}
		if = {
			limit = { has_trait = loyal }
			custom_tooltip = overthrow_regent_scheme_interaction_actor_stress_effect.tt.loyal.remove_disloyal
		}
	}
	# Disloyal stress.
	## Disloyals don't care if they unseat another disloyal character enough to stress about it, even if they're a bit less likely to do it.
	## Lose stress if current diarch is loyal.
	else_if = {
		limit = {
			scope:recipient = { diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold }
		}
		stress_impact = {
			disloyal = major_stress_impact_loss
			honest = medium_stress_impact_loss
			compassionate = major_stress_impact_loss
			just = major_stress_impact_loss
		}
		if = {
			limit = { has_trait = disloyal }
			custom_tooltip = overthrow_regent_scheme_interaction_actor_stress_effect.tt.disloyal.remove_loyal
		}
	}
	# Else, standard.
	else = {
		stress_impact = {
			honest = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
			just = major_stress_impact_gain
		}
	}
}

invalidate_diarch_grand_wedding_effect = {
	# Invalidate grand weddings
	diarch = {
		if = {
			limit = {
				# scope:diarch is currently an active Diarch
				exists = liege
				is_diarch = yes
				liege = {
					diarch = scope:diarch
					has_active_diarchy = yes
				}
				# scope:diarch was promised a Grand Wedding
				has_variable = promised_grand_wedding_by
			}
			betrothed = { save_scope_as = betrothed }
			# Save scopes of spouses, and organizers from variables
			scope:diarch = {
				add_to_list = informee
				var:promised_grand_wedding_by ?= {
					add_to_list = informee
					var:promised_grand_wedding_to ?= { add_to_list = informee }
				}
			}
			scope:betrothed = {
				add_to_list = informee
				var:promised_grand_wedding_by ?= {
					add_to_list = informee
					var:promised_grand_wedding_to ?= { add_to_list = informee }
				}
			}
			# Clean up variables and inform relevant characters of invalidation
			every_in_list = {
				list = informee
				if = {
					limit = { exists = var:promised_grand_wedding_marriage_countdown }
					remove_variable = promised_grand_wedding_marriage_countdown
				}
				if = {
					limit = { exists = var:promised_grand_wedding_by }
					remove_variable = promised_grand_wedding_by
				}
				if = {
					limit = { exists = var:promised_grand_wedding_to }
					remove_variable = promised_grand_wedding_to
				}
				send_interface_message = {
					type = msg_betrothal_invalidated
					title = grand_wedding_cancelled_by_regency_title
					left_icon = scope:diarch
					right_icon = scope:betrothed
					desc = grand_wedding_cancelled_by_regency_desc
				}
			}
		}
	}
}

sort_vizier_candidates_to_list_effect = {
	scope:actor = {
		every_courtier = {
			limit = { is_valid_basic_candidate_for_vizier_trigger = yes }
			add_to_list = characters_pre_filter
		}
		every_vassal = {
			limit = {
				is_valid_basic_candidate_for_vizier_trigger = yes
				highest_held_title_tier <= tier_barony
			}
			add_to_list = characters_pre_filter
		}
	}
	hidden_effect = {
		while = {
			count = 6
			ordered_in_list = {
				list = characters_pre_filter
				order_by = diarchy_vizier_succession_score_value
				limit = {
					NOT = { is_in_list = characters }
				}
				add_to_list = characters
			}
		}
	}
}

mulct_vizier_for_cash_effect = {
	$VIZIER$ = {
		# How much cash are we getting?
		## Miniscule
		if = {
			limit = { scope:mulct_vizier_interaction_minimal = yes }
			if = {
				limit = {
					NOT = { exists = scope:free_mulct }
				}
				update_diarchy_swing_with_perspective_effect = {
					SWING = vizier_mulct_swing_gain_miniscule_value
					LIEGE = $VIZIER$.liege
				}
			}
			hidden_effect = { add_short_term_gold = liege.minor_gold_value }
			pay_short_term_gold = {
				target = $VIZIER$.liege
				gold = liege.minor_gold_value
			}
		}
		## Minor
		else_if = {
			limit = { scope:mulct_vizier_interaction_minor = yes }
			if = {
				limit = {
					NOT = { exists = scope:free_mulct }
				}
				update_diarchy_swing_with_perspective_effect = {
					SWING = vizier_mulct_swing_gain_minor_value
					LIEGE = $VIZIER$.liege
				}
			}
			hidden_effect = { add_short_term_gold = liege.medium_gold_value }
			pay_short_term_gold = {
				target = $VIZIER$.liege
				gold = liege.medium_gold_value
			}
		}
		## Medium
		else_if = {
			limit = { scope:mulct_vizier_interaction_medium = yes }
			if = {
				limit = {
					NOT = { exists = scope:free_mulct }
				}
				update_diarchy_swing_with_perspective_effect = {
					SWING = vizier_mulct_swing_gain_medium_value
					LIEGE = $VIZIER$.liege
				}
			}
			hidden_effect = { add_short_term_gold = liege.major_gold_value }
			pay_short_term_gold = {
				target = $VIZIER$.liege
				gold = liege.major_gold_value
			}
		}
		## Major
		else_if = {
			limit = { scope:mulct_vizier_interaction_major = yes }
			if = {
				limit = {
					NOT = { exists = scope:free_mulct }
				}
				update_diarchy_swing_with_perspective_effect = {
					SWING = vizier_mulct_swing_gain_major_value
					LIEGE = $VIZIER$.liege
				}
			}
			hidden_effect = { add_short_term_gold = liege.massive_gold_value }
			pay_short_term_gold = {
				target = $VIZIER$.liege
				gold = liege.massive_gold_value
			}
		}
		## Massive
		else_if = {
			limit = { scope:mulct_vizier_interaction_massive = yes }
			if = {
				limit = {
					NOT = { exists = scope:free_mulct }
				}
				update_diarchy_swing_with_perspective_effect = {
					SWING = vizier_mulct_swing_gain_massive_value
					LIEGE = $VIZIER$.liege
				}
			}
			hidden_effect = { add_short_term_gold = liege.monumental_gold_value }
			pay_short_term_gold = {
				target = $VIZIER$.liege
				gold = liege.monumental_gold_value
			}
		}
		# Now we pawn everything they have at the relevant level.
		## T1
		if = {
			limit = {
				NOT = { exists = scope:free_mulct }
				scope:mulct_vizier_interaction_minor = yes 
			}
			custom_tooltip = mulct_vizier_interaction.vizier_loses_extravagance_t1_modifiers
			hidden_effect = {
				remove_character_modifier = vizier_extravagance_t1_treasure_modifier
				remove_character_modifier = vizier_extravagance_t1_activities_modifier
				remove_character_modifier = vizier_extravagance_t1_property_modifier
				remove_character_modifier = vizier_extravagance_t1_charity_modifier
			}
		}
		## T2
		else_if = {
			limit = {
				NOT = { exists = scope:free_mulct }
				scope:mulct_vizier_interaction_medium = yes 
			}
			custom_tooltip = mulct_vizier_interaction.vizier_loses_extravagance_t2_modifiers
			hidden_effect = {
				remove_character_modifier = vizier_extravagance_t2_treasure_modifier
				remove_character_modifier = vizier_extravagance_t2_activities_modifier
				remove_character_modifier = vizier_extravagance_t2_property_modifier
				remove_character_modifier = vizier_extravagance_t2_charity_modifier
			}
		}
		## T3
		else_if = {
			limit = {
				NOT = { exists = scope:free_mulct }
				scope:mulct_vizier_interaction_major = yes 
			}
			custom_tooltip = mulct_vizier_interaction.vizier_loses_extravagance_t3_modifiers
			hidden_effect = {
				remove_character_modifier = vizier_extravagance_t3_treasure_modifier
				remove_character_modifier = vizier_extravagance_t3_activities_modifier
				remove_character_modifier = vizier_extravagance_t3_property_modifier
				remove_character_modifier = vizier_extravagance_t3_charity_modifier
			}
		}
		## T4
		else_if = {
			limit = {
				NOT = { exists = scope:free_mulct }
				scope:mulct_vizier_interaction_massive = yes 
			}
			custom_tooltip = mulct_vizier_interaction.vizier_loses_extravagance_t4_modifiers
			# But first: do we need to flag an achievement?
			if = {
				limit = {
					liege = { is_ai = no }
					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
				}
				liege = { add_character_flag = fp3_mulct_them_dry_achievement_flag }
			}
			hidden_effect = {
				remove_character_modifier = vizier_extravagance_t4_treasure_modifier
				remove_character_modifier = vizier_extravagance_t4_activities_modifier
				remove_character_modifier = vizier_extravagance_t4_property_modifier
				remove_character_modifier = vizier_extravagance_t4_charity_modifier
			}
		}
	}
}

mulct_vizier_for_cash_opinion_reaction_effect = {
	# Greedy viziers hate this.
	if = {
		limit = { has_trait = greedy }
		save_scope_value_as = {
			name = opinion_val
			value = {
				value = -15
				multiply = $MULT$
			}
		}
		add_opinion = {
			modifier = goldlust_opinion
			target = scope:actor
			opinion = scope:opinion_val
		}
	}
	# Generous & most profligate viziers are sorta _eh_ about it.
	else_if = {
		limit = {
			OR = {
				has_trait = generous
				has_trait = profligate
			}
		}
		save_scope_value_as = {
			name = opinion_val
			value = {
				value = -5
				multiply = $MULT$
			}
		}
		add_opinion = {
			modifier = resigned_opinion
			target = scope:actor
			opinion = scope:opinion_val
		}
	}
	# Loyal viziers consider it their duty & forgiving viziers accept it.
	else_if = {
		limit = {
			OR = {
				has_trait = loyal
				has_trait = forgiving
			}
		}
		save_scope_value_as = {
			name = opinion_val
			value = {
				value = -7
				multiply = $MULT$
			}
		}
		add_opinion = {
			modifier = resigned_opinion
			target = scope:actor
			opinion = scope:opinion_val
		}
	}
	# Disloyal viziers think your duty can go stuff itself & vengeful viziers are irate.
	else_if = {
		limit = {
			OR = {
				has_trait = disloyal
				has_trait = vengeful
			}
		}
		save_scope_value_as = {
			name = opinion_val
			value = {
				value = -12
				multiply = $MULT$
			}
		}
		add_opinion = {
			modifier = took_my_coin_opinion
			target = scope:actor
			opinion = scope:opinion_val
		}
	}
	# Everyone else is annoyed.
	else = {
		save_scope_value_as = {
			name = opinion_val
			value = {
				value = -10
				multiply = $MULT$
			}
		}
		add_opinion = {
			modifier = took_my_coin_opinion
			target = scope:actor
			opinion = scope:opinion_val
		}
	}
}

diarch_request_imperial_expedition_accepted_effect = {
	# Explain what's up.
	custom_tooltip = diarch_request_imperial_expedition_interaction.tt.access_to_cb
	custom_tooltip = diarch_request_imperial_expedition_interaction.tt.governors_as_allies
	custom_tooltip = diarch_request_imperial_expedition_interaction.tt.target_behaviour_explanation
	custom_tooltip = diarch_request_imperial_expedition_interaction.tt.post_war
	# Give us our charge so we can actually use the CB.
	set_variable = {
		name = imperial_expedition_charged
		value = yes
	}
	# If you used a hook, calc some extra stuff.
	if = {
		limit = {
			scope:hook = yes
			has_usable_hook = scope:recipient
		}
		# Use the hook up.
		use_hook = scope:recipient
		# Plus scope:recipient is concerned.
		reverse_add_opinion = {
			target = scope:recipient
			modifier = suspicion_opinion
			opinion = -20
		}
	}
	# Otherwise you didn't, so you should be happy.
	else_if = {
		limit = {	
			scope:recipient = { is_ai = yes }
		}
		reverse_add_opinion = {
			target = scope:recipient
			modifier = trust_opinion
			opinion = 20
		}
	}
}

diarch_request_imperial_expedition_rejected_effect = {
	scope:recipient = {
		# We have to put up the same amount of influence they do to veto them.
		if = {
			limit = {
				# Prevent weird +0 influence tooltip.
				scope:hook = no
			}
			change_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
				}
				multiply = -1
			}
		}
		# Plus they get annoyed with us.
		add_opinion = {
			target = scope:actor
			modifier = angry_opinion
			opinion = -40
		}
	}
}

diarch_promoted_as_administrative_candidate_get_best_tooltip_effect = {
	if = {
		limit = {
			scope:actor.top_liege = { has_diarchy_active_parameter = diarch_more_efficient_administrative_emperor_promotion_candidate_massive }
		}
		custom_tooltip = diarch_more_efficient_administrative_emperor_promotion_candidate_massive.tt.interaction_explanation
	}
	else_if = {
		limit = {
			scope:actor.top_liege = { has_diarchy_active_parameter = diarch_more_efficient_administrative_emperor_promotion_candidate_major }
		}
		custom_tooltip = diarch_more_efficient_administrative_emperor_promotion_candidate_major.tt.interaction_explanation
	}
	else_if = {
		limit = {
			scope:actor.top_liege = { has_diarchy_active_parameter = diarch_more_efficient_administrative_emperor_promotion_candidate_medium }
		}
		custom_tooltip = diarch_more_efficient_administrative_emperor_promotion_candidate_medium.tt.interaction_explanation
	}
	else_if = {
		limit = {
			scope:actor.top_liege = { has_diarchy_active_parameter = diarch_more_efficient_administrative_emperor_promotion_candidate_mild }
		}
		custom_tooltip = diarch_more_efficient_administrative_emperor_promotion_candidate_mild.tt.interaction_explanation
	}
}

maiming_destroy_diarchy_effect = {
	if = {
		limit = { exists = scope:destroy_diarchy }
		# Liege maims co-emperor.
		if = {
			limit = { scope:actor.diarch = scope:recipient }
			scope:actor = {
				clear_designated_heir = yes
				end_diarchy = yes
			}
			every_player = {
				limit = {
					NOR = {
						this = scope:actor
						this = scope:recipient
					}
					top_liege = scope:actor.top_liege
				}
				trigger_event = diarchy.8022
			}
		}
		# Co-emperor maims liege.
		else = {
			# We do this in two batches so that we don't produce an error when the emperor is usurped by their old co-emperor.
			## First the empire.
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change
			}
			scope:recipient = {
				every_held_title = {
					limit = {
						OR = {
							this = scope:recipient.capital_county
							this = scope:recipient.capital_county.duchy
							AND = {
								tier = tier_county
								this.duchy = scope:recipient.capital_county.duchy
							}
							tier >= scope:recipient.highest_held_title_tier
						}
					}
					change_title_holder = {
						holder = scope:actor
						change = scope:change
					}
				}
				every_vassal = {
					custom = custom.recipient_every_vassal
					change_liege = {
						LIEGE = scope:actor
						CHANGE = scope:change
					}
				}
			}
			resolve_title_and_vassal_change = scope:change
			## Then the former emperor.
			create_title_and_vassal_change = {
				type = usurped
				save_scope_as = change2
			}
			scope:recipient = {
				change_liege = {
					LIEGE = scope:actor
					CHANGE = scope:change2
				}
			}
			resolve_title_and_vassal_change = scope:change2
			# Plus, end the diarchy.
			hidden_effect = {
				scope:recipient = { end_diarchy = yes }
			}
			every_player = {
				limit = {
					NOR = {
						this = scope:actor
						this = scope:recipient
					}
					top_liege = scope:actor.top_liege
				}
				trigger_event = diarchy.8023
			}
		}
	}
}

diarch_demand_despotate_interaction_accepted_effect = {
	create_title_and_vassal_change = {
		type = granted
		save_scope_as = change
	}
	scope:target = {
		# First, we try to give them lands we hold.
		every_in_de_jure_hierarchy = {
			limit = {
				holder = scope:recipient
				tier >= tier_county
			}
			change_title_holder = {
				holder = scope:actor
				change = scope:change
			}
		}
		# If they're not now landed, try to give them a random county — we do this so that we can keep them administrative.
		if = {
			limit = {
				scope:actor = { is_landed = no }
			}
			scope:target = {
				ordered_de_jure_county = {
					limit = {
						holder = {
							is_ai = yes
							any_liege_or_above = { this = scope:recipient }
						}
					}
					limit = {
						holder = {
							any_liege_or_above = { this = scope:recipient }
						}
					}
					order_by = development_level
					change_title_holder = {
						holder = scope:actor
						change = scope:change
					}
				}
			}
		}
		# If we haven't managed that, pick a random county not owned by a player and give them that.
		change_title_holder = {
			holder = scope:actor
			change = scope:change
		}
		every_dejure_vassal_title_holder = {
			limit = {
				liege = scope:recipient
				NOR = {
					this = scope:actor
					this = scope:recipient
				}
			}
			custom = custom.every_target_de_jure_vassal
			change_liege = {
				liege = scope:actor
				change = scope:change
			}
		}
	}
	resolve_title_and_vassal_change = scope:change
	if = {
		limit = {
			NOT = {
				scope:actor = { is_vassal_of = scope:recipient }
			}
		}
		hidden_effect = {
			create_title_and_vassal_change = {
				type = swear_fealty
				save_scope_as = change
			}
			scope:actor = {
				change_liege = {
					liege = scope:recipient
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
	}
	# If you used a hook, calc some extra stuff.
	if = {
		limit = {
			scope:hook = yes
			has_usable_hook = scope:recipient
		}
		# Use the hook up.
		use_hook = scope:recipient
		# Plus scope:recipient is concerned.
		reverse_add_opinion = {
			target = scope:recipient
			modifier = frustrated_opinion
			opinion = -40
		}
	}
	# Otherwise you didn't, so you should be happy.
	else_if = {
		limit = { is_ai = yes }
		add_opinion = {
			target = scope:recipient
			modifier = grateful_opinion
			opinion = 40
		}
	}
}

diarch_demand_despotate_interaction_rejected_effect = {
	scope:recipient = {
		# We have to put up the same amount of influence they do to veto them.
		if = {
			limit = {
				# Prevent weird +0 influence tooltip.
				scope:hook = no
			}
			change_influence = {
				if = {
					limit = { scope:influence_major = yes }
					add = diarch_demand_despotate_interaction_stake_to_raise_major_value
				}
				else_if = {
					limit = { scope:influence_medium = yes }
					add = diarch_demand_despotate_interaction_stake_to_raise_medium_value
				}
				else_if = {
					limit = { scope:influence_minor = yes }
					add = diarch_demand_despotate_interaction_stake_to_raise_minor_value
				}
			}
			custom_tooltip = diarch_demand_despotate_interaction.tt.double_stake
		}
		# Plus they get annoyed with us.
		add_opinion = {
			target = scope:actor
			modifier = angry_opinion
			opinion = -40
		}
	}
}

scapegoat_counterpart_interaction_process_results_effect = {
	if = {
		limit = { scope:diplomacy_small = yes }
		scope:actor = {
			save_scope_value_as = {
				name = multiplied_diff
				value = {
					value = diplomacy
					subtract = scope:recipient.diplomacy
					multiply = 20
					max = 400
				}
			}
			change_influence = scope:multiplied_diff
			$REALM_OPINION_ACTOR$ = {
				value = scope:multiplied_diff
				divide = 40
				min = 3
			}
		}
		scope:recipient = {
			$REALM_OPINION_RECIPIENT$ = {
				value = scope:multiplied_diff
				divide = 30
				min = 5
			}
		}
	}
	else_if = {
		limit = { scope:diplomacy_large = yes }
		scope:actor = {
			save_scope_value_as = {
				name = multiplied_diff
				value = {
					value = diplomacy
					subtract = scope:recipient.diplomacy
					multiply = 40
					max = 800
				}
			}
			change_influence = scope:multiplied_diff
			$REALM_OPINION_ACTOR$ = {
				value = scope:multiplied_diff
				divide = 40
				min = 5
			}
		}
		scope:recipient = {
			$REALM_OPINION_RECIPIENT$ = {
				value = scope:multiplied_diff
				divide = 30
				min = 10
			}
		}
	}
	else_if = {
		limit = { scope:intrigue_small = yes }
		scope:actor = {
			save_scope_value_as = {
				name = multiplied_diff
				value = {
					value = intrigue
					subtract = scope:recipient.intrigue
					multiply = 20
					max = 400
				}
			}
			change_influence = scope:multiplied_diff
			$REALM_OPINION_ACTOR$ = {
				value = scope:multiplied_diff
				divide = 40
				min = 3
			}
		}
		scope:recipient = {
			$REALM_OPINION_RECIPIENT$ = {
				value = scope:multiplied_diff
				divide = 30
				min = 5
			}
		}
	}
	else_if = {
		limit = { scope:intrigue_large = yes }
		scope:actor = {
			save_scope_value_as = {
				name = multiplied_diff
				value = {
					value = intrigue
					subtract = scope:recipient.intrigue
					multiply = 40
					max = 800
				}
			}
			change_influence = scope:multiplied_diff
			$REALM_OPINION_ACTOR$ = {
				value = scope:multiplied_diff
				divide = 40
				min = 5
			}
		}
		scope:recipient = {
			$REALM_OPINION_RECIPIENT$ = {
				value = scope:multiplied_diff
				divide = 30
				min = 10
			}
		}
	}
}

##################################################
# Events

# Fire a tooltip saying what effect this'll have on regent opinion.
## We don't need to use this _every_where, as otherwise it'd have to supplant the opinion effect entirely, but it's cool to use it in any specific regency events where flat opinion might be a nicer gain than usual.
raise_diarch_opinion_with_loyalty_update_effect = {
	# Check the current opinion.
	diarch = {
		save_opinion_value_as = {
			name = diarch_old_opinion
			target = prev
		}
	}
	# Plus, save $OPINION_AMOUNT$ so that we can use it in subsequent script values.
	save_scope_value_as = {
		name = opinion_amount
		value = $OPINION_AMOUNT$
	}
	# Process the loyalty update tooltip.
	diarch = {
		# Self-interested.
		## Hates you too much to be able to tell.
		if = {
			limit = {
				diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold
				scope:diarch_old_opinion <= -100
				scope:opinion_amount >= 1
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.self_interested.overflow_edgecase }
		}
		### Since save_opinion_value_as doesn't account for overspill past -100, and as we've got some special conditions that make the move from -100 to -99 very dramatic under certain circumstances, we need to have this vague option to cover up systemic inaccuracies.
		## Self-interested remains static.
		else_if = {
			limit = {
				diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold
				raise_diarch_opinion_with_loyalty_update_value <= diarch_loyalty_visibly_disloyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.self_interested.remains_static }
		}
		## Self-interested to selfless.
		else_if = {
			limit = {
				diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold
				raise_diarch_opinion_with_loyalty_update_value >= diarch_loyalty_visibly_loyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.self_interested.to_selfless }
		}
		## Self-interested to situational.
		else_if = {
			limit = { diarch_loyalty <= diarch_loyalty_visibly_disloyal_threshold }
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.self_interested.to_situational }
		}
		# Situational.
		## Situational to selfless.
		else_if = {
			limit = {
				diarch_has_situational_loyalty_trigger = yes
				raise_diarch_opinion_with_loyalty_update_value >= diarch_loyalty_visibly_loyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.situational.to_selfless }
		}
		## Situational to self-interested.
		else_if = {
			limit = {
				diarch_has_situational_loyalty_trigger = yes
				raise_diarch_opinion_with_loyalty_update_value <= diarch_loyalty_visibly_disloyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.situational.to_self_interested }
		}
		## Situational remains static.
		else_if = {
			limit = { diarch_has_situational_loyalty_trigger = yes }
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.situational.remains_static }
		}
		# Selfless.
		## Is too loyal to be able to tell.
		else_if = {
			limit = {
				diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold
				scope:diarch_old_opinion >= 100
				scope:opinion_amount <= -1
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.selfless.overflow_edgecase }
		}
		### As above, we need this vague option to account for overspill.
		## Selfless remains static.
		else_if = {
			limit = {
				diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold
				raise_diarch_opinion_with_loyalty_update_value >= diarch_loyalty_visibly_loyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.selfless.remains_static }
		}
		## Selfless to self-interested.
		else_if = {
			limit = {
				diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold
				raise_diarch_opinion_with_loyalty_update_value <= diarch_loyalty_visibly_disloyal_threshold
			}
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.selfless.to_self_interested }
		}
		## Selfless to situational.
		else_if = {
			limit = { diarch_loyalty >= diarch_loyalty_visibly_loyal_threshold }
			liege = { custom_tooltip = raise_diarch_opinion_with_loyalty_update_effect.tt.selfless.to_situational }
		}
	}
	# Now, add the new opinion.
	reverse_add_opinion = {
		target = diarch
		modifier = $OPINION_TYPE$
		opinion = scope:opinion_amount
	}
}

# Diarchy swing can be good or bad for you depending on whether you're the liege, the diarch, or neutral, so we need different tooltips accordingly.
## Please note: for technical reasons this'll break if you don't use the pre-set script values or update it to include whatever new value you want to use.
update_diarchy_swing_with_perspective_effect = {
	$LIEGE$ = {
		# Sort the effect.
		hidden_effect = { change_diarchy_swing = $SWING$ }
		# Grab $LIEGE$'s scope for loc.
		## We save a weirdy scope name so we don't accidentally overwrite common scopes.
		save_scope_as = liege_loc
	}
	# Right, now flick out the correct tooltips.
	## We can't easily access a number that doesn't yet exist as a variable within a custom tooltip, so this is gon' get _real_ gross and I'm sorry you have to watch it happen.
	## We also don't contain this in the above $LIEGE$ block because otherwise unusual (but valid) uses of the effect cause asserts.
	## Is the diarch gaining?
	if = {
		limit = { $SWING$ >= 1 }
		## Miniscule swing.
		if = {
			limit = { $SWING$ = miniscule_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.miniscule_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.miniscule_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.miniscule_sop_swing_diarch_gain.tt }
			}
		}
		## Minor swing.
		else_if = {
			limit = { $SWING$ = minor_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.minor_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.minor_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.minor_sop_swing_diarch_gain.tt }
			}
		}
		## Medium swing.
		else_if = {
			limit = { $SWING$ = medium_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.medium_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.medium_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.medium_sop_swing_diarch_gain.tt }
			}
		}
		## Major swing.
		else_if = {
			limit = { $SWING$ = major_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.major_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.major_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.major_sop_swing_diarch_gain.tt }
			}
		}
		## Massive swing.
		else_if = {
			limit = { $SWING$ = massive_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.massive_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.massive_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.massive_sop_swing_diarch_gain.tt }
			}
		}
		## Monumental swing.
		else_if = {
			limit = { $SWING$ = monumental_sop_swing_diarch_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.monumental_sop_swing_diarch_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.monumental_sop_swing_diarch_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.monumental_sop_swing_diarch_gain.tt }
			}
		}
	}
	## Is the liege gaining?
	else_if = {
		limit = { $SWING$ <= -1 }
		## Miniscule swing.
		if = {
			limit = { $SWING$ = miniscule_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.miniscule_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.miniscule_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.miniscule_sop_swing_liege_gain.tt }
			}
		}
		## Minor swing.
		else_if = {
			limit = { $SWING$ = minor_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.minor_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.minor_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.minor_sop_swing_liege_gain.tt }
			}
		}
		## Medium swing.
		else_if = {
			limit = { $SWING$ = medium_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.medium_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.medium_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.medium_sop_swing_liege_gain.tt }
			}
		}
		## Major swing.
		else_if = {
			limit = { $SWING$ = major_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.major_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.major_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.major_sop_swing_liege_gain.tt }
			}
		}
		## Massive swing.
		else_if = {
			limit = { $SWING$ = massive_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.massive_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.massive_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.massive_sop_swing_liege_gain.tt }
			}
		}
		## Monumental swing.
		else_if = {
			limit = { $SWING$ = monumental_sop_swing_liege_gain }
			# For the liege.
			if = {
				limit = { this = $LIEGE$ }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.liege_perspective.monumental_sop_swing_liege_gain.tt }
			}
			# For the diarch.
			else_if = {
				limit = { this = $LIEGE$.diarch }
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.diarch_perspective.monumental_sop_swing_liege_gain.tt }
			}
			# For everyone else.
			else = {
				$LIEGE$ = { custom_tooltip = update_diarchy_swing_with_perspective_effect.neutral_perspective.monumental_sop_swing_liege_gain.tt }
			}
		}
	}
	## No gain not accounted for: you should never be swinging by 0.
}

##################################################
# Primeministerships

vizierate_remove_extravagance_modifiers_effect = {
	remove_character_modifier = vizier_extravagance_t1_treasure_modifier
	remove_character_modifier = vizier_extravagance_t1_activities_modifier
	remove_character_modifier = vizier_extravagance_t1_property_modifier
	remove_character_modifier = vizier_extravagance_t1_charity_modifier
	remove_character_modifier = vizier_extravagance_t2_treasure_modifier
	remove_character_modifier = vizier_extravagance_t2_activities_modifier
	remove_character_modifier = vizier_extravagance_t2_property_modifier
	remove_character_modifier = vizier_extravagance_t2_charity_modifier
	remove_character_modifier = vizier_extravagance_t3_treasure_modifier
	remove_character_modifier = vizier_extravagance_t3_activities_modifier
	remove_character_modifier = vizier_extravagance_t3_property_modifier
	remove_character_modifier = vizier_extravagance_t3_charity_modifier
	remove_character_modifier = vizier_extravagance_t4_treasure_modifier
	remove_character_modifier = vizier_extravagance_t4_activities_modifier
	remove_character_modifier = vizier_extravagance_t4_property_modifier
	remove_character_modifier = vizier_extravagance_t4_charity_modifier
}

##################################################
# Co-Rulerships

sort_junior_emperor_candidates_to_list_effect = {
	scope:actor = {
		every_close_or_extended_family_member = {
			limit = { valid_junior_emperor_candidate_trigger = { LIEGE = scope:actor } }
			add_to_list = characters
		}
	}
}

sort_co_emperor_candidates_to_list_effect = {
	scope:actor = {
		every_close_or_extended_family_member = {
			limit = {
				valid_co_emperor_candidate_trigger = { LIEGE = scope:actor }
			}
			add_to_list = characters
		}
		every_vassal = {
			limit = {
				valid_co_emperor_candidate_trigger = { LIEGE = scope:actor }
			}
			add_to_list = characters
		}
	}
}

sort_co_monarch_candidates_to_list_effect = {
	scope:actor = {
		every_child = { 
			limit = {
				valid_co_monarch_candidate_trigger = { LIEGE = scope:actor }
			}
			add_to_list = characters 
		}
	}
}

grateful_for_appointment_as_co_emperor_effect = {
	if = {
		limit = { exists = scope:ai_recipient }
		scope:ai_recipient = {
			set_variable = {
				name = co_emp_appointer
				value = scope:actor
			}
			add_opinion = {
				target = scope:actor
				modifier = made_co_ruler_opinion
				opinion = 50
			}
		}
	}
	else = {
		scope:secondary_recipient ?= {
			set_variable = {
				name = co_emp_appointer
				value = scope:actor
			}
			add_opinion = {
				target = scope:actor
				modifier = made_co_ruler_opinion
				opinion = 50
			}
		}
	}
}

diarch_overwrites_old_designated_heir_apply_opinions_effect = {
	scope:old_heir ?= {
		# Humble or content characters accept this for what it is.
		if = {
			limit = {
				OR = {
					AND = {
						has_trait = humble
						# ... cancelled out by...
						NOT = { has_trait = ambitious }
					}
					AND = {
						has_trait = content
						# ... cancelled out by...
						NOT = { has_trait = arrogant }
					}
				}
			}
			# Annoyance with you.
			add_opinion = {
				target = $LIEGE$
				modifier = disappointed_opinion
				opinion = -20
			}
			# Annoyance with the new co-ruler.
			## Vs. player.
			if = {
				limit = {
					# Rationale for this heinous crime at the top of this block.
					NOT = { exists = scope:ai_recipient }
				}
				add_opinion = {
					target = $CO_RULER$
					modifier = insult_opinion
					opinion = -30
				}
			}
			## Vs. AI.
			else = {
				add_opinion = {
					target = scope:ai_recipient
					modifier = insult_opinion
					opinion = -30
				}
			}
		}
		# Everyone else is outraged.
		else = {
			# Annoyance with you.
			add_opinion = {
				target = $LIEGE$
				modifier = betrayal_opinion
				opinion = -50
			}
			# Annoyance with the new co-ruler.
			## Vs. player.
			if = {
				limit = {
					# Rationale for this heinous crime at the top of this block.
					NOT = { exists = scope:ai_recipient }
				}
				add_opinion = {
					target = $CO_RULER$
					modifier = hate_opinion
					opinion = -75
				}
			}
			## Vs. AI.
			else = {
				add_opinion = {
					target = scope:ai_recipient
					modifier = hate_opinion
					opinion = -75
				}
			}
		}
	}
}

designated_diarch_overwridden_by_co_ruler_effect = {
	$LIEGE$.designated_diarch ?= {
		if = {
			limit = {
				NOT = { this = $CO_RULER$ }
			}
			# Humble or content characters accept this for what it is.
			if = {
				limit = {
					OR = {
						AND = {
							has_trait = humble
							# ... cancelled out by...
							NOT = { has_trait = ambitious }
						}
						AND = {
							has_trait = content
							# ... cancelled out by...
							NOT = { has_trait = arrogant }
						}
					}
				}
				# Annoyance with you.
				add_opinion = {
					target = $LIEGE$
					modifier = disappointed_opinion
					opinion = -10
				}
				# Annoyance with the new co-ruler.
				## Vs. player.
				if = {
					limit = {
						# Rationale for this heinous crime at the top of this block.
						NOT = { exists = scope:ai_recipient }
					}
					add_opinion = {
						target = $CO_RULER$
						modifier = insult_opinion
						opinion = -15
					}
				}
				## Vs. AI.
				else = {
					add_opinion = {
						target = scope:ai_recipient
						modifier = insult_opinion
						opinion = -15
					}
				}
			}
			# Everyone else is outraged.
			else = {
				# Annoyance with you.
				add_opinion = {
					target = $LIEGE$
					modifier = appointed_co_ruler_over_designated_regent_opinion
					opinion = -30
				}
				# Annoyance with the new co-ruler.
				## Vs. player.
				if = {
					limit = {
						# Rationale for this heinous crime at the top of this block.
						NOT = { exists = scope:ai_recipient }
					}
					add_opinion = {
						target = $CO_RULER$
						modifier = appointed_co_ruler_over_designated_regent_opinion
						opinion = -50
					}
				}
				## Vs. AI.
				else = {
					add_opinion = {
						target = scope:ai_recipient
						modifier = appointed_co_ruler_over_designated_regent_opinion
						opinion = -50
					}
				}
			}
		}
	}
}
