﻿#############
# Diarchy Scripted Values
#############

##################################################
# General Values

raise_diarch_opinion_with_loyalty_update_value = {
	value = diarch_loyalty
	add = scope:opinion_amount
}

diarch_wants_more_swing_event_threshold_value = 90

adult_co_ruler_power_balance_scaling_value = {
	value = 50

	# If our liege would have a regency, trend towards max.
	if = {
		limit = {
			liege = { regency_for_personal_reasons_trigger = yes }
		}
		add = 50
	}
	# Likewise, if the co-ruler would be disabled, trend towards min.
	else_if = {
		limit = { is_diarch_able_trigger = no }
		add = -50
	}
}

##################################################
# Diarch Loyalty Values

diarch_loyalty_visibly_loyal_threshold = 75
diarch_loyalty_visibly_disloyal_threshold = 25

diarch_loyalty_score_add_minor_value = 10
diarch_loyalty_score_add_medium_value = 25
diarch_loyalty_score_add_major_value = 50
diarch_loyalty_score_add_massive_value = 100
diarch_loyalty_score_add_omega_value = 1000

diarch_loyalty_score_add_minor_gain = diarch_loyalty_score_add_minor_value
diarch_loyalty_score_add_medium_gain = diarch_loyalty_score_add_medium_value
diarch_loyalty_score_add_major_gain = diarch_loyalty_score_add_major_value
diarch_loyalty_score_add_massive_gain = diarch_loyalty_score_add_massive_value
diarch_loyalty_score_add_omega_gain = diarch_loyalty_score_add_omega_value

diarch_loyalty_score_add_minor_loss = {
	value = diarch_loyalty_score_add_minor_value
	multiply = -1
}
diarch_loyalty_score_add_medium_loss = {
	value = diarch_loyalty_score_add_medium_value
	multiply = -1
}
diarch_loyalty_score_add_major_loss = {
	value = diarch_loyalty_score_add_major_value
	multiply = -1
}
diarch_loyalty_score_add_massive_loss = {
	value = diarch_loyalty_score_add_massive_value
	multiply = -1
}
diarch_loyalty_score_add_omega_loss = {
	value = diarch_loyalty_score_add_omega_value
	multiply = -1
}

diarch_loyalty_score_type_regency_value = {
	### PLEASE NOTE ####
	# It's deliberate design that we don't double up on lots of values between loyalty and succession score (e.g., familial bonuses).
	# If the two values become too synced, then you'll either always be fine or else always be screwed. Neither of these are fun or interesting.
	# The intention is that societal ties govern your succession score whilst loyalty is more about personal relations and outlook (which is why we pepper in some traits and cultural traditions to break the score up a bit).

	if = {
		# For performance reasons, you'll sometimes check this when you don't have a liege, so we need to check beforehand for error purposes.
		limit = { exists = liege }
		# Add raw opinion.
		add = {
			desc = diarch_loyalty_score.regency.opinion_of_you
			value = "opinion(liege)"
		}
		# High-Tier Relationships.
		add = diarch_loyalty_score_standard_values_high_tier_relationships_value
		# Traits.
		add = diarch_loyalty_score_standard_values_general_traits_value
		# Court Positions.
		add = diarch_loyalty_score_standard_values_general_court_positions_value
		# Cultural Traditions.
		add = diarch_loyalty_score_standard_values_general_culture_value
		# Sympathies.
		## General factors.
		add = diarch_loyalty_score_standard_values_general_sympathies_value
		## Dread factors in in temporary regencies.
		if = {
			limit = {
				liege = {
					dread >= 1
					has_diarchy_active_parameter = diarchy_type_is_temporary_regency
				}
				has_dread_level_towards = {
	  				target = liege
	  				level >= 1
	  			}
			}
			add = {
				desc = diarch_loyalty_score.regency.temporary_regency.dread
				value = {
					value = liege.dread
					# Weight up if they're a basic natural coward.
					if = {
						limit = {
							has_dread_level_towards = {
				  				target = liege
				  				level >= 2
				  			}
						}
						multiply = 2
					}
				}
			}
		}
		# Overrides.
		## Loyalty overrides.
		add = diarch_loyalty_score_standard_values_overrides_loyalty_value
		# Voyager Perk
		add = diarch_loyalty_score_value_power_at_home_perk_value
	}
}

diarch_loyalty_score_type_vizierate_value = {
	### PLEASE NOTE ####
	# It's deliberate design that we don't double up on lots of values between loyalty and succession score (e.g., familial bonuses).
	# If the two values become too synced, then you'll either always be fine or else always be screwed. Neither of these are fun or interesting.
	# The intention is that societal ties govern your succession score whilst loyalty is more about personal relations and outlook (which is why we pepper in some traits and cultural traditions to break the score up a bit).

	if = {
		# For performance reasons, you'll sometimes check this when you don't have a liege, so we need to check beforehand for error purposes.
		limit = { exists = liege }
		# Add raw opinion.
		add = {
			desc = diarch_loyalty_score.regency.opinion_of_you
			value = "opinion(liege)"
		}
		# High-Tier Relationships.
		add = diarch_loyalty_score_standard_values_high_tier_relationships_value
		# Traits.
		add = diarch_loyalty_score_standard_values_general_traits_value
		# Court Positions.
		add = diarch_loyalty_score_standard_values_general_court_positions_value
		# Cultural Traditions.
		add = diarch_loyalty_score_standard_values_general_culture_value
		# Sympathies.
		## General factors.
		add = diarch_loyalty_score_standard_values_general_sympathies_value
		# Overrides.
		## Loyalty overrides.
		add = diarch_loyalty_score_standard_values_overrides_loyalty_value
	}
}

diarch_loyalty_score_type_co_emperorship_value = {
	### PLEASE NOTE ####
	# As there's no succession for co-emperors, we can afford to be a bit more direct with the values affecting them vs. other types of diarchy, so here (and specifically here) it's fine to lump w/e in.

	if = {
		# For performance reasons, you'll sometimes check this when you don't have a liege, so we need to check beforehand for error purposes.
		limit = { exists = liege }
		# Add raw opinion.
		add = {
			desc = diarch_loyalty_score.regency.opinion_of_you
			value = "opinion(liege)"
		}
		# How likely are we to be heir?
		## Fancy non-standard values in use.
		add = diarch_loyalty_score_esoteric_values_heirage_situation_value
		# High-Tier Relationships.
		add = diarch_loyalty_score_standard_values_high_tier_relationships_value
		# Traits.
		## Fancy non-standard values in use.
		add = diarch_loyalty_score_esoteric_values_co_rulership_traits_value
		# Court Positions.
		add = diarch_loyalty_score_standard_values_general_court_positions_value
		# Cultural Traditions.
		add = diarch_loyalty_score_standard_values_general_culture_value
		# Sympathies.
		## General factors.
		add = diarch_loyalty_score_standard_values_general_sympathies_value
		## Dread.
		if = {
			limit = {
				liege.dread >= 1
				has_dread_level_towards = {
	  				target = liege
	  				level >= 1
	  			}
			}
			add = {
				desc = diarch_loyalty_score.co_rule.co_emperorship.dread
				value = {
					value = liege.dread
					# Weight up if they're a basic natural coward.
					if = {
						limit = {
							has_dread_level_towards = {
				  				target = liege
				  				level >= 2
				  			}
						}
						multiply = 2
					}
				}
			}
		}
		# Overrides.
		## Loyalty overrides.
		add = diarch_loyalty_score_standard_values_overrides_loyalty_value
	}
}

diarch_loyalty_score_standard_values_general_sympathies_value = {
	# Compassion if liege is helpless.
	if = {
		limit = {
			liege = {
				OR = {
					is_incapable = yes
					is_adult = no
				}
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.compassion_for_helpless
			value = root.ai_compassion
		}
	}
	# Tyranny.
	if = {
		limit = { liege.tyranny >= 1 }
		add = {
			desc = diarch_loyalty_score.regency.tyranny
			value = {
				value = liege.tyranny
				multiply = -1
			}
		}
	}
}

diarch_loyalty_score_standard_values_general_culture_value = {
	culture = {
		# +++ Malleable Subjects.
		if = {
			limit = { has_cultural_tradition = tradition_fp2_malleable_subjects }
			add = {
				desc = diarch_loyalty_score.regency.tradition_fp2_malleable_subjects
				value = diarch_loyalty_score_add_major_gain
			}
		}
		# +++ Recognition of Talent & lowborn.
		if = {
			limit = {
				has_cultural_tradition = tradition_talent_acquisition
				root = { is_lowborn = yes }
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_talent_acquisition
				value = diarch_loyalty_score_add_major_gain
			}
		}
		# ++/-- Astute Diplomats & they like or dislike their liege.
		if = {
			limit = { has_cultural_tradition = tradition_astute_diplomats }
			# If they like you, they work loyally.
			if = {
				limit = {
					root = {
						opinion = {
							target = liege
							value >= 1
						}
					}
				}
				add = {
					desc = diarch_loyalty_score.regency.tradition_astute_diplomats.positive
					value = diarch_loyalty_score_add_medium_gain
				}
			}
			# If they don't, they work against you.
			else_if = {
				limit = {
					root = {
						opinion = {
							target = liege
							value <= -1
						}
					}
				}
				add = {
					desc = diarch_loyalty_score.regency.tradition_astute_diplomats.negative
					value = diarch_loyalty_score_add_medium_loss
				}
			}
			# Else neutral, so they're ambivalent.
		}
		# ++ Ruling Caste & is liege.
		if = {
			limit = {
				root.liege.culture = {
					has_cultural_tradition = tradition_ruling_caste
					# But only apply it to diff-cultured characters.
					NOT = { this = root.culture }
				}
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_ruling_caste
				value = diarch_loyalty_score_add_medium_gain
			}
		}
		# ++ Family Business & extended family.
		if = {
			limit = {
				has_cultural_tradition = tradition_family_entrepreneurship
				root = { is_close_or_extended_family_of = liege }
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_family_entrepreneurship
				value = diarch_loyalty_score_add_medium_gain
			}
		}
		# + Hereditary Hierarchy.
		if = {
			limit = { has_cultural_tradition = tradition_hereditary_hierarchy }
			add = {
				desc = diarch_loyalty_score.regency.tradition_hereditary_hierarchy
				value = diarch_loyalty_score_add_minor_gain
			}
		}
		# + Tribal Unity & same-house.
		if = {
			limit = {
				has_cultural_tradition = tradition_tribe_unity
				exists = root.liege.house
				root.house ?= root.liege.house
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_tribe_unity
				value = diarch_loyalty_score_add_minor_gain
			}
		}
		# + Strong Kinship & same-house.
		if = {
			limit = {
				has_cultural_tradition = tradition_strong_kinship
				exists = root.liege.house
				root.house ?= root.liege.house
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_strong_kinship
				value = diarch_loyalty_score_add_minor_gain
			}
		}
		# +/- Chivalry & variable depending on "honour".
		if = {
			limit = { has_cultural_tradition = tradition_chivalry }
			# If dishonourable...
			if = {
				limit = {
					root.liege = {
						OR = {
							tyranny >= 1
							prestige_level <= 0
							has_any_shunned_or_criminal_trait_in_faith_trigger = {
								CHARACTER = liege
								FAITH = root.faith
							}
							# We avoid the actual ai_honour stat because it's a bit less exposed to the player.
						}
					}
				}
				add = {
					desc = diarch_loyalty_score.regency.tradition_chivalry.loss
					value = diarch_loyalty_score_add_minor_loss
				}
			}
			# Else, honourable enough.
			else = {
				add = {
					desc = diarch_loyalty_score.regency.tradition_chivalry.gain
					value = diarch_loyalty_score_add_minor_gain
				}
			}
		}
		# + Philosopher Culture & learning education.
		if = {
			limit = {
				has_cultural_tradition = tradition_philosopher_culture
				root = { has_trait = education_learning }
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_philosopher_culture
				value = diarch_loyalty_score_add_minor_gain
			}
		}
		# -1 (and only 1) if Vegetarian & liege isn't also vegetarian.
		## This one goes out to our dear D.M. for everything he's ever said at lunch.
		if = {
			limit = {
				has_cultural_tradition = tradition_vegetarianism
				# ^We're deliberately only checking culture rather than faith here — not wanting to mock religious convictions.
				## Just personal ones.
				root.liege = { is_vegetarian_trigger = no }
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_vegetarianism
				value = -1
			}
		}
		# -- Eye for an Eye.
		if = {
			limit = { has_cultural_tradition = tradition_eye_for_an_eye }
			add = {
				desc = diarch_loyalty_score.regency.tradition_eye_for_an_eye
				value = diarch_loyalty_score_add_medium_loss
			}
		}
		# -- Byzantine Traditions.
		if = {
			limit = { has_cultural_tradition = tradition_byzantine_succession }
			add = {
				desc = diarch_loyalty_score.regency.tradition_byzantine_succession
				value = diarch_loyalty_score_add_medium_loss
			}
		}
		# -- EP3 Byzantines
		if = {
			limit = { has_cultural_tradition = tradition_ep3_palace_politics }
			add = {
				desc = diarch_loyalty_score.regency.tradition_ep3_palace_politics
				value = diarch_loyalty_score_add_medium_loss
			}
		}
		# -- Warrior Culture & non-martially educated lieges.
		if = {
			limit = {
				has_cultural_tradition = tradition_warrior_culture
				root.liege = {
					NOR = {
						has_trait = education_martial
						has_focus = education_martial
					}
				}
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_warrior_culture
				value = diarch_loyalty_score_add_medium_loss
			}
		}
		# --- Practiced Pirates.
		if = {
			limit = { has_cultural_tradition = tradition_practiced_pirates }
			add = {
				desc = diarch_loyalty_score.regency.tradition_practiced_pirates
				value = diarch_loyalty_score_add_major_loss
			}
		}
		# --- Bound by Faith & different faiths.
		if = {
			limit = {
				has_cultural_tradition = tradition_faith_bound
				NOT = { root.faith = root.liege.faith }
			}
			add = {
				desc = diarch_loyalty_score.regency.tradition_faith_bound
				value = diarch_loyalty_score_add_major_loss
			}
		}
	}
}

diarch_loyalty_score_standard_values_general_court_positions_value = {
	# Court Positions.
	## ++ Chief Eunuch.
	if = {
		limit = { has_court_position = chief_eunuch_court_position }
		add = {
			desc = diarch_loyalty_score.regency.chief_eunuch
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## ++ Chief Qadi.
	if = {
		limit = { has_court_position = chief_qadi_court_position }
		add = {
			desc = diarch_loyalty_score.regency.chief_qadi
			value = diarch_loyalty_score_add_medium_gain
		}
	}
}

diarch_loyalty_score_standard_values_general_traits_value = {
	# Traits.
	## + Lazy.
	if = {
		limit = { has_trait = lazy }
		add = {
			desc = diarch_loyalty_score.regency.lazy
			value = diarch_loyalty_score_add_minor_gain
		}
	}
	## ++/-- Diligent.
	### ++ If they like you...
	else_if = {
		limit = {
			has_trait = diligent
			opinion = {
				target = liege
				value >= 1
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.diligent.positive
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	### -- If they dislike you...
	else_if = {
		limit = {
			has_trait = diligent
			opinion = {
				target = liege
				value <= -1
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.diligent.negative
			value = diarch_loyalty_score_add_medium_loss
		}
	}
	### ... and perfectly-neutral diligent characters do nothing extra about it. They are ambivalent.
	## ++ Craven.
	if = {
		limit = { has_trait = craven }
		add = {
			desc = diarch_loyalty_score.regency.craven
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## ++ Honest.
	if = {
		limit = { has_trait = honest }
		add = {
			desc = diarch_loyalty_score.regency.honest
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## -- Deceitful.
	else_if = {
		limit = { has_trait = deceitful }
		add = {
			desc = diarch_loyalty_score.regency.deceitful
			value = diarch_loyalty_score_add_medium_loss
		}
	}
	## +++ Content.
	if = {
		limit = { has_trait = content }
		add = {
			desc = diarch_loyalty_score.regency.content
			value = diarch_loyalty_score_add_major_gain
		}
	}
	## --- Ambitious.
	else_if = {
		limit = { has_trait = ambitious }
		add = {
			desc = diarch_loyalty_score.regency.ambitious
			value = diarch_loyalty_score_add_major_loss
		}
	}
	## -- Arbitrary.
	if = {
		limit = { has_trait = arbitrary }
		add = {
			desc = diarch_loyalty_score.regency.arbitrary
			value = diarch_loyalty_score_add_medium_loss
		}
	}
	## ++ Just.
	else_if = {
		limit = { has_trait = just }
		add = {
			desc = diarch_loyalty_score.regency.just
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## --- Disloyal.
	if = {
		limit = { has_trait = disloyal }
		add = {
			desc = diarch_loyalty_score.regency.disloyal
			value = diarch_loyalty_score_add_major_loss
		}
	}
	## +++ Loyal.
	else_if = {
		limit = { has_trait = loyal }
		add = {
			desc = diarch_loyalty_score.regency.loyal
			value = diarch_loyalty_score_add_major_gain
		}
	}
}

diarch_loyalty_score_standard_values_high_tier_relationships_value = {
	# We don't take the basic tier relationships into account because they affect opinion heavily, and we don't want to double dip too much unless it seems important.
	## Good.
	if = {
		limit = {
			has_any_best_good_relationship_with_character_trigger = { CHARACTER = liege }
		}
		add = {
			desc = diarch_loyalty_score_power_at_home_perk
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## Bad.
	if = {
		limit = {
			has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = liege }
		}
		add = {
			desc = diarch_loyalty_score.regency.your_negative_relation
			value = diarch_loyalty_score_add_massive_loss
		}
	}
}

diarch_loyalty_score_standard_values_overrides_loyalty_value = {
	# Everyone has a breaking point, so if they categorically hate you, we reduce it down.
	if = {
		limit = {
			opinion = {
				target = liege
				value <= -100
			}
			OR = {
				has_hook_of_type = {
					target = root
					type = loyalty_hook
				}
				has_hook_of_type = {
					target = root
					type = predecessor_loyalty_hook
				}
				ai_honor >= max_positive_honor
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.override_negated
			value = diarch_loyalty_score_add_major_gain
		}
	}
	# Loyalty hooks of any kind mean the diarch will always be unfailingly loyal in their duties.
	## Standard loyalty.
	else_if = {
		limit = {
			liege = {
				has_hook_of_type = {
					target = root
					type = loyalty_hook
				}
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.loyalty_hook.self
			value = diarch_loyalty_score_add_omega_gain
		}
	}
	## Predecessor loyalty.
	else_if = {
		limit = {
			liege = {
				has_hook_of_type = {
					target = root
					type = predecessor_loyalty_hook
				}
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.loyalty_hook.predecessor
			value = diarch_loyalty_score_add_omega_gain
		}
	}
	# And, per request, if the character is unfailingly honourable then they will also always be loyal.
	else_if = {
		limit = { ai_honor >= max_positive_honor }
		add = {
			desc = diarch_loyalty_score.regency.ai_honour
			value = diarch_loyalty_score_add_omega_gain
		}
	}
}

diarch_loyalty_score_value_power_at_home_perk_value = {
	if = {
		limit = {
			liege ?= {
				has_perk = power_at_home_perk
				is_travelling = yes
			}
		}
		add = {
			desc = diarch_loyalty_score_power_at_home_perk
			value = diarch_loyalty_score_add_medium_gain
		}
	}
}

# Similar to the usual traits value but with _much_ more extreme responses to some traits.
diarch_loyalty_score_esoteric_values_co_rulership_traits_value = {
	# Traits.
	## + Lazy.
	if = {
		limit = { has_trait = lazy }
		add = {
			desc = diarch_loyalty_score.regency.lazy
			value = diarch_loyalty_score_add_minor_gain
		}
	}
	## ++/--- Diligent.
	### ++ If they like you...
	else_if = {
		limit = {
			has_trait = diligent
			opinion = {
				target = liege
				value >= 1
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.diligent.positive
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	### --- If they dislike you...
	else_if = {
		limit = {
			has_trait = diligent
			opinion = {
				target = liege
				value <= -1
			}
		}
		add = {
			desc = diarch_loyalty_score.regency.diligent.negative
			value = diarch_loyalty_score_add_major_loss
		}
	}
	### ... and perfectly-neutral diligent characters do nothing extra about it. They are ambivalent.
	## ++ Craven.
	if = {
		limit = { has_trait = craven }
		add = {
			desc = diarch_loyalty_score.regency.craven
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## ++ Honest.
	if = {
		limit = { has_trait = honest }
		add = {
			desc = diarch_loyalty_score.regency.honest
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## --- Deceitful.
	else_if = {
		limit = { has_trait = deceitful }
		add = {
			desc = diarch_loyalty_score.regency.deceitful
			value = diarch_loyalty_score_add_major_loss
		}
	}
	## +++ Content.
	if = {
		limit = { has_trait = content }
		add = {
			desc = diarch_loyalty_score.regency.content
			value = diarch_loyalty_score_add_major_gain
		}
	}
	## ---- Ambitious.
	else_if = {
		limit = { has_trait = ambitious }
		add = {
			desc = diarch_loyalty_score.regency.ambitious
			value = diarch_loyalty_score_add_massive_loss
		}
	}
	## --- Arbitrary.
	if = {
		limit = { has_trait = arbitrary }
		add = {
			desc = diarch_loyalty_score.regency.arbitrary
			value = diarch_loyalty_score_add_major_loss
		}
	}
	## ++ Just.
	else_if = {
		limit = { has_trait = just }
		add = {
			desc = diarch_loyalty_score.regency.just
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## ---- Disloyal.
	if = {
		limit = { has_trait = disloyal }
		add = {
			desc = diarch_loyalty_score.regency.disloyal
			value = diarch_loyalty_score_add_massive_loss
		}
	}
	## +++ Loyal.
	else_if = {
		limit = { has_trait = loyal }
		add = {
			desc = diarch_loyalty_score.regency.loyal
			value = diarch_loyalty_score_add_major_gain
		}
	}
	## ++ Humble.
	if = {
		limit = { has_trait = humble }
		add = {
			desc = diarch_loyalty_score.regency.humble
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## -- Arrogant.
	else_if = {
		limit = { has_trait = arrogant }
		add = {
			desc = diarch_loyalty_score.regency.arrogant
			value = diarch_loyalty_score_add_medium_loss
		}
	}
	## ++ Patient.
	if = {
		limit = { has_trait = patient }
		add = {
			desc = diarch_loyalty_score.regency.patient
			value = diarch_loyalty_score_add_medium_gain
		}
	}
	## -- Impatient.
	else_if = {
		limit = { has_trait = impatient }
		add = {
			desc = diarch_loyalty_score.regency.impatient
			value = diarch_loyalty_score_add_medium_loss
		}
	}
}

diarch_loyalty_score_esoteric_values_heirage_situation_value = {
	# Designated heirs feel happy for it.
	if = {
		limit = { liege.designated_heir ?= root }
		# Designated heirs are happy for it.
		add = {
			desc = diarch_loyalty_score.co_rulership.designated_heir
			value = 25
		}
	}
	# Unless we have a few specific traits, we get impatient for power over time.
	if = {
		limit = {
			OR = {
				# Something that makes us patient.
				NOR = {
					has_trait = patient
					has_trait = content
					has_trait = humble
					has_trait = loyal
				}
				# Without something that stops us being impatient.
				OR = {
					has_trait = impatient
					has_trait = ambitious
					has_trait = arrogant
					has_trait = disloyal
				}
			}
		}
		# Dedicating this section of the script to Ol' Charlie Boy.
		add = {
			desc = diarch_loyalty_score.co_rulership.years_waiting
			value = {
				value = years_as_diarch
				multiply = -2
			}
		}
		# Bonus if we're much younger than them/malus if older.
		if = {
			limit = { age != liege.age }
			add = {
				desc = diarch_loyalty_score.co_rulership.age_difference
				value = {
					value = liege.age
					subtract = age
				}
			}
		}
		# Same again for health.
		## 85+.
		if = {
			limit = {
				liege.age >= 85
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.just_die_already
				value = -55
			}
		}
		## 80+.
		else_if = {
			limit = {
				liege.age >= 80
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.your_time_is_up
				value = -45
			}
		}
		## 75+.
		else_if = {
			limit = {
				liege.age >= 75
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.you_are_too_fit
				value = -35
			}
		}
		## 70+.
		else_if = {
			limit = {
				liege.age >= 70
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.you_are_too_fit
				value = -25
			}
		}
		## 65+.
		else_if = {
			limit = {
				liege.age >= 65
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.you_are_too_fit
				value = -15
			}
		}
		## 55+.
		else_if = {
			limit = {
				liege.age >= 55
				liege.health >= medium_health
			}
			add = {
				desc = diarch_loyalty_score.co_rulership.showing_no_signs_of_slowing
				value = -5
			}
		}
		# But if we're unhealthy, ignore it — we've got other stuff to worry about.
	}
}

regent_loyal_after_death_hook_duration_years_value = {
	value = 21
	subtract = root.primary_heir.age
}

historic_regent_loyal_after_death_hook_duration_years_char_214_value = {
	value = 21
	subtract = character:214.age
}

##################################################
# Diarchy Succession Candidate Values

# These need to be whole numbers or the UI'll get _weird_.
miniscule_diarch_candidate_value = 1
minor_diarch_candidate_value = 2
medium_diarch_candidate_value = 6
major_diarch_candidate_value = 14
massive_diarch_candidate_value = 22
monumental_diarch_candidate_value = 33

miniscule_diarch_candidate_gain = miniscule_diarch_candidate_value
minor_diarch_candidate_gain = minor_diarch_candidate_value
medium_diarch_candidate_gain = medium_diarch_candidate_value
major_diarch_candidate_gain = major_diarch_candidate_value
massive_diarch_candidate_gain = massive_diarch_candidate_value
monumental_diarch_candidate_gain = monumental_diarch_candidate_value

miniscule_diarch_candidate_loss = {
	value = miniscule_diarch_candidate_value
	multiply = -1
}
minor_diarch_candidate_loss = {
	value = minor_diarch_candidate_value
	multiply = -1
}
medium_diarch_candidate_loss = {
	value = medium_diarch_candidate_value
	multiply = -1
}
major_diarch_candidate_loss = {
	value = major_diarch_candidate_value
	multiply = -1
}
massive_diarch_candidate_loss = {
	value = massive_diarch_candidate_value
	multiply = -1
}
monumental_diarch_candidate_loss = {
	value = monumental_diarch_candidate_value
	multiply = -1
}

hard_disable_diarch_candidate_value = -1000

diarchy_succession_court_type_baseline_value = 10
diarchy_succession_competence_baseline_value = 5

diarchy_regent_succession_score_value = {
	if = {
		# For performance reasons, you'll sometimes check this when you don't have a liege, so we need to check beforehand for error purposes.
		limit = { exists = liege }
		# We increase the importance of family if the liege is underage or an imbecile.
		if = {
			limit = {
				liege = {
					OR = {
						is_adult = no
						is_incapable = yes
					}
				}
				any_close_or_extended_family_member = { this = liege }
			}
			# Ruling characters  get a bit less, as they have other duties.
			if = {
				limit = { is_ruler = yes }
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.diarchy_specific.regency.close_or_extended_family_of_invalid.ruler
				}
			}
			# Whereas non-rulers get a mega-boost, as they can be there all the time
			else = {
				add = {
					value = monumental_diarch_candidate_gain
					desc = diarch_succession_score.diarchy_specific.regency.close_or_extended_family_of_invalid.non_ruler
				}
			}
		}
		# Familial ties.
		## If you engage in hyper-incest and break your own regency succession, don't come crying to the devs. You have done this to yourself.
		add = {
			desc = diarch_succession_score.category.familial_ties
			# ADD SCORE
			## Is parent of
			if = {
				limit = { is_parent_of = liege }
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_parent
				}
			}
			## Is child of
			if = {
				limit = { is_child_of = liege }
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_child
				}
			}
			## Is sibling of
			if = {
				limit = { is_sibling_of = liege }
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_sibling
				}
			}
			## Is grandparent of
			if = {
				limit = { is_grandparent_of = liege }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_grandparent
				}
			}
			## Is grandchild of
			if = {
				limit = { is_grandchild_of = liege }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_grandchild
				}
			}
			## Is uncle/aunt of
			if = {
				limit = { is_uncle_or_aunt_of = liege }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_auntuncle
				}
			}
			## Is nibling of
			if = {
				limit = { is_nibling_of = liege }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_nibling
				}
			}
			## Is cousin of
			if = {
				limit = { is_cousin_of = liege }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_cousin
				}
			}
			## Is great grandparent of
			if = {
				limit = { is_great_grandparent_of = liege }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.your_greatgrandparent
				}
			}
			## Is great grandchild of
			if = {
				limit = { is_great_grandchild_of = liege }
				add = {
					value = miniscule_diarch_candidate_gain
					desc = diarch_succession_score.familial_ties.yourgreat_grandchild
				}
			}
		}
		# Personal ties.
		add = {
			desc = diarch_succession_score.category.personal_ties
			# ADD SCORE
			## Is your heir
			if = {
				limit = {
					exists = liege.primary_heir
					this = liege.primary_heir
				}
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_heir
				}
			}
			## Is spouse of
			if = {
				limit = { is_spouse_of = liege }
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_spouse
				}
			}
			## Is guardian of
			if = {
				limit = { has_relation_ward = liege }
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_ward
				}
			}
			## Has a seat on your council
			if = {
				limit = { is_councillor_of = liege }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_councillor
				}
			}
			## Is powerful vassal of
			if = {
				limit = { is_powerful_vassal = yes }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_powerful_vassal
				}
			}
			### Has positive opinion
			#if = {
			#	limit = {
			#		opinion = {
			#			target = liege
			#			value >= medium_positive_opinion
			#		}
			#	}
			#	add = {
			#		value = miniscule_diarch_candidate_gain
			#		desc = diarch_succession_score.personal_ties.likes_you
			#	}
			#}
			## Has positive relationship
			if = {
				limit = {
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_positive_relation
				}
			}
			# REMOVE SCORE
			## Is your nemesis
			if = {
				limit = {
					has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.personal_ties.your_nemesis
				}
			}
			## Has a moderate bad relationship
			if = {
				limit = {
					has_any_only_moderate_bad_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.personal_ties.your_negative_relation
				}
			}
			### Has negative opinion
			#if = {
			#	limit = {
			#		opinion = {
			#			target = liege
			#			value <= medium_negative_opinion
			#		}
			#	}
			#	add = {
			#		value = miniscule_diarch_candidate_loss
			#		desc = diarch_succession_score.personal_ties.dislikes_you
			#	}
			#}
		}
		# Societal bonds.
		add = {
			desc = diarch_succession_score.category.societal_bonds
			# ADD SCORE
			## Is in your house
			if = {
				limit = {
					exists = house
					house = liege.house
				}
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.societal_bonds.your_house
				}
			}
			## Is in your dynasty
			if = {
				limit = {
					exists = house
					# Filter out same-house chars to avoid double-dipping.
					NOT = { house = liege.house }
					# So we _only_ want same dynasty chars.
					dynasty = liege.dynasty
				}
				add = {
					value = miniscule_diarch_candidate_gain
					desc = diarch_succession_score.societal_bonds.your_dynasty
				}
			}
			## Has same faith
			if = {
				limit = { faith = liege.faith }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.societal_bonds.your_faith
				}
			}
			## Is of same culture
			if = {
				limit = { culture = liege.culture }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.societal_bonds.your_culture
				}
			}
		}
		# Royal court.
		if = {
			limit = {
				liege = { has_royal_court = yes }
				has_dlc_feature = royal_court
			}
			add = {
				desc = diarch_succession_score.category.royal_court
				# ADD SCORE
				## Skill for court type.
				### Diplomacy.
				if = {
					limit = {
						liege = { has_court_type = court_diplomatic }
					}
					add = {
						value = diplomacy
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.diplomacy
					}
				}
				### Martial.
				if = {
					limit = {
						liege = { has_court_type = court_warlike }
					}
					add = {
						value = martial
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.martial
					}
				}
				### Stewardship.
				if = {
					limit = {
						liege = { has_court_type = court_administrative }
					}
					add = {
						value = stewardship
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.stewardship
					}
				}
				### Intrigue.
				if = {
					limit = {
						liege = { has_court_type = court_intrigue }
					}
					add = {
						value = intrigue
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.intrigue
					}
				}
				### Learning.
				if = {
					limit = {
						liege = { has_court_type = court_scholarly }
					}
					add = {
						value = learning
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.learning
					}
				}
				### Prowess.
				if = {
					limit = {
						liege = { has_court_type = court_tribal }
					}
					add = {
						value = prowess
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.prowess
					}
				}
				## Speaks court language.
				if = {
					limit = { knows_court_language_of = liege }
					add = {
						value = major_diarch_candidate_gain
						desc = diarch_succession_score.royal_court.speaks_court_language
					}
				}
			}
		}
		# Traits: Noble Ambitions.
		add = {
			desc = diarch_succession_score.category.traits.noble_ambitions
			# ADD SCORE
			## Ambitious trait
			if = {
				limit = { has_trait = ambitious }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.traits.ambitious
				}
			}
			## Diligent trait
			if = {
				limit = { has_trait = diligent }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.traits.diligent
				}
			}
			# REMOVE SCORE
			## Lazy trait
			if = {
				limit = { has_trait = lazy }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.traits.lazy
				}
			}
			## Humble trait
			if = {
				limit = { has_trait = humble }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.traits.humble
				}
			}
			## Content trait
			if = {
				limit = { has_trait = content }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.traits.content
				}
			}
		}
		# Circumstances.
		add = {
			desc = diarch_succession_score.category.circumstances
			# REMOVE SCORE
			## Has a critical illness
			if = {
				limit = { has_serious_disease_trigger = yes }
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.cripplingly_ill
				}
			}
			## Has severe wounds
			if = {
				limit = { has_trait = wounded_3 }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.badly_wounded
				}
			}
			## Has a criminal reason.
			if = {
				limit = {
					save_temporary_scope_as = char_temp
					liege = {
						OR = {
							has_imprisonment_reason = scope:char_temp
							has_banish_reason = scope:char_temp
							has_execute_reason = scope:char_temp
							has_revoke_title_reason = scope:char_temp
						}
					}
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.known_criminal
				}
			}
			## Under the age of 25
			if = {
				limit = { age <= 25 }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.very_young
				}
			}
			## High-stress characters
			if = {
				limit = { stress_level >= 1 }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.stressed_out
				}
			}
			## Bastard / Child of Concubine
			if = {
				limit = {
					OR = {
						has_trait = bastard
						has_trait = child_of_concubine
					}
				}
				add = {
					value = miniscule_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.illegitimate
				}
			}
			## Has a minor illness
			if = {
				limit = { has_trait = ill }
				add = {
					value = miniscule_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.mildly_ill
				}
			}
			## Has a minor wound
			if = {
				limit = {
					OR = {
						has_trait = wounded_1
						has_trait = wounded_2
					}
				}
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.mildly_wounded
				}
			}
			## Doesn't speak your main language
			### Due to technical constraints, we can currently only check if you speak your liege's culture's language, not if you have any shared languages.
			if = {
				limit = {
					NOR = {
						knows_language_of_culture = liege.culture
						# Exempt family members so that we don't screw wrong-gendered unlanded chars over.
						is_close_or_extended_family_of = liege
					}
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.not_speak_language
				}
			}
		}
		# REMOVE CANDIDATES
		## Must be a vassal or in your court
		if = {
			limit = {
				exists = liege
				NOR = {
					is_ruler = yes
					is_courtier_of = liege
				}
			}
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.neither_vassal_nor_courtier
			}
		}
		## Must be an adult
		if = {
			limit = { is_adult = no }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.child
			}
		}
		## Must not NOT imprisoned
		if = {
			limit = { is_imprisoned = yes }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.imprisoned
			}
		}
		## Is NOT incapable or infirm
		if = {
			limit = {
				OR = {
					is_incapable = yes
					has_trait = infirm
				}
			}
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.incapable_or_infirm
			}
		}
		## Event filter.
		### Current regent's shenanigans.
		if = {
			limit = { var:diarch_succession_filtered_due_to_incumbents_politicking ?= liege }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.event_filters.incumbent_politicking
			}
		}
	}
}

diarchy_vizier_succession_score_value = {
	if = {
		# For performance reasons, you'll sometimes check this when you don't have a liege, so we need to check beforehand for error purposes.
		limit = { exists = liege }
		# Familial ties.
		## We actually weight down here, as you don't generally want family to be your vizier.
		add = {
			desc = diarch_succession_score.category.familial_ties
			# REMOVE SCORE
			## Is close family
			if = {
				limit = { is_close_family_of = liege }
				add = {
					value = monumental_diarch_candidate_loss
					desc = diarch_succession_score.familial_ties.undignified.close_family
				}
			}
			## Is extended family
			else_if = {
				limit = { is_extended_family_of = liege }
				add = {
					value = massive_diarch_candidate_loss
					desc = diarch_succession_score.familial_ties.undignified.extended_family
				}
			}
			## Is same-house
			else_if = {
				limit = {
					exists = liege.house
					house ?= liege.house
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.familial_ties.undignified.house
				}
			}
			## Is same-dynasty
			else_if = {
				limit = {
					exists = liege.dynasty
					dynasty = liege.dynasty
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.familial_ties.undignified.dynasty
				}
			}
		}
		# Personal ties.
		## Since viziers aren't generally part of the ruling family, or indeed any ruling family, we cut down personal ties a smidge compared to usual.
		add = {
			desc = diarch_succession_score.category.personal_ties
			# ADD SCORE
			## Is guardian of
			if = {
				limit = { has_relation_ward = liege }
				add = {
					value = massive_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_ward
				}
			}
			## Nothing for being on your council - they're a council position, so this'd only ever weight up the incumbent.
			### I mean, technically not _but_ the actual mechanical effect is that the vizier council position'll auto-replace whatever other position they held, which'd get annoying_fast_, so we avoid it.
			## Has positive opinion
			if = {
				limit = {
					opinion = {
						target = liege
						value >= medium_positive_opinion
					}
				}
				add = {
					value = miniscule_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.likes_you
				}
			}
			## Has positive relationship
			if = {
				limit = {
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.personal_ties.your_positive_relation
				}
			}
			# REMOVE SCORE
			## Is your nemesis
			if = {
				limit = {
					has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.personal_ties.your_nemesis
				}
			}
			## Has a moderate bad relationship
			if = {
				limit = {
					has_any_only_moderate_bad_relationship_with_character_trigger = { CHARACTER = liege }
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.personal_ties.your_negative_relation
				}
			}
			## Has negative opinion
			if = {
				limit = {
					opinion = {
						target = liege
						value <= medium_negative_opinion
					}
				}
				add = {
					value = miniscule_diarch_candidate_loss
					desc = diarch_succession_score.personal_ties.dislikes_you
				}
			}
		}
		# Suitable servants.
		add = {
			desc = diarch_succession_score.category.suitable_servant
			# ADD SCORE
			## Ruler status.
			### Tax collector.
			if = {
				limit = { is_tax_collector = yes }
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.tax_collector
				}
			}
			### Lowborn.
			if = {
				limit = { is_lowborn = yes }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.lowborn
				}
			}
			### Landless.
			if = {
				limit = { is_landed = no }
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.landless
				}
			}
			## In-Groupness.
			### Same culture.
			if = {
				limit = { culture = liege.culture }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.shares_liege_culture
				}
			}
			### Same faith.
			if = {
				limit = { faith = liege.faith }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.shares_liege_faith
				}
			}
			### Diff-faith same HoF.
			if = {
				limit = {
					NOT = { faith = liege.faith }
					exists = liege.faith.religious_head
					faith.religious_head ?= liege.faith.religious_head
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.shares_liege_hof
				}
			}
			### Diff-faith diff-HoF Righteous.
			else_if = {
				limit = {
					NOT = { faith = liege.faith }
					faith = {
						faith_hostility_level = {
							target = prev.liege.faith
							value = faith_fully_accepted_level
						}
					}
				}
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.diff_faith_considers_liege_righteous
				}
			}
			### Diff-faith diff-HoF Astray.
			else_if = {
				limit = {
					NOT = { faith = liege.faith }
					faith = {
						faith_hostility_level = {
							target = prev.liege.faith
							value = faith_astray_level
						}
					}
				}
				add = {
					value = miniscule_diarch_candidate_gain
					desc = diarch_succession_score.suitable_servant.diff_faith_considers_liege_astray
				}
			}
			# VARIABLE SCORE
			## In-Groupness.
			### Diff-culture acceptance.
			if = {
				limit = {
					NOT = { culture = liege.culture }
				}
				culture = {
					add = {
						value = {
							# Grab the our cultural acceptance value.
							value = "cultural_acceptance(prev.liege.culture)"
							# Now, the actual 0 opinion point is waaaaay up at 100%, so we set a high base to make lacking acceptance more of a problem.
							## But not so high as to screw minorities (who are likely both faith and culture minorities) out of ever getting the position.
							add = -50
							# Finally, reduce the number down - this gives us an axis of -10 to +10.
							multiply = 0.2
							# Cultural Acceptance actually goes to 2 decimal places, so we need to round it out neatly or someone's gonna end up with a score of 25.03.
							round = yes
						}
						desc = diarch_succession_score.suitable_servant.diff_culture_acceptance
					}
				}
			}
			# REMOVE SCORE
			## Ruler status.
			### Punish barons.
			#### Double-dipping, but just to make it clear.
			if = {
				limit = { is_landed = yes }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.suitable_servant.landed
				}
			}
			## In-Groupness.
			### Diff-faith diff-HoF Hostile.
			if = {
				limit = {
					faith = {
						faith_hostility_level = {
							target = prev.liege.faith
							value = faith_hostile_level
						}
					}
				}
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.suitable_servant.diff_faith_considers_liege_hostile
				}
			}
			### Diff-faith diff-HoF Evil.
			else_if = {
				limit = {
					faith = {
						faith_hostility_level = {
							target = prev.liege.faith
							value = faith_evil_level
						}
					}
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.suitable_servant.diff_faith_considers_liege_evil
				}
			}
		}
		# Nepotism.
		add = {
			desc = diarch_succession_score.category.nepotism
			# Liege Partners.
			## Friends with primary spouse.
			if = {
				limit = {
					liege.primary_spouse ?= { has_relation_friend = prev }
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.primary_spouse.friend
				}
			}
			## Friends with consort
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_lesser_consort_trigger = { RELATION = friend }
				}
				add = {
					value = minor_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.consort.friend
				}
			}
			## Best Friends with primary spouse.
			if = {
				limit = {
					liege.primary_spouse ?= { has_relation_best_friend = prev }
				}
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.primary_spouse.best_friend
				}
			}
			## Best Friends with consort
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_lesser_consort_trigger = { RELATION = best_friend }
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.consort.best_friend
				}
			}
			## Rivals with primary spouse.
			if = {
				limit = {
					liege.primary_spouse ?= { has_relation_rival = prev }
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.primary_spouse.rival
				}
			}
			## Rivals with consort
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_lesser_consort_trigger = { RELATION = rival }
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.consort.rival
				}
			}
			## Nemeses with primary spouse.
			if = {
				limit = {
					liege.primary_spouse ?= { has_relation_nemesis = prev }
				}
				add = {
					value = monumental_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.primary_spouse.nemesis
				}
			}
			## Nemeses with consort
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_lesser_consort_trigger = { RELATION = nemesis }
				}
				add = {
					value = massive_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.consort.nemesis
				}
			}
			## Shares culture with minority consort
			if = {
				limit = {
					diarch_candidate_shares_minority_status_with_trigger = {
						TRIGGER_OR_TARGET = any_consort
						QUALITY = culture
					}
				}
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.any_consort.shares_minority_culture
				}
			}
			## Shares faith with minority consort
			if = {
				limit = {
					diarch_candidate_shares_minority_status_with_trigger = {
						TRIGGER_OR_TARGET = any_consort
						QUALITY = faith
					}
				}
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.any_consort.shares_minority_faith
				}
			}
			# Liege Stay-at-Home Children.
			## Friends with SaH child.
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_child_trigger = { RELATION = friend }
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.sah_child.friend
				}
			}
			## Best Friends with SaH child.
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_child_trigger = { RELATION = best_friend }
				}
				add = {
					value = major_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.sah_child.best_friend
				}
			}
			## Rivals with SaH child.
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_child_trigger = { RELATION = rival }
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.sah_child.rival
				}
			}
			## Nemeses with SaH child.
			if = {
				limit = {
					diarch_candidate_shares_relationship_with_child_trigger = { RELATION = nemesis }
				}
				add = {
					value = massive_diarch_candidate_loss
					desc = diarch_succession_score.nepotism.sah_child.nemesis
				}
			}
			## Shares culture with minority SaH child.
			if = {
				limit = {
					diarch_candidate_shares_minority_status_with_trigger = {
						TRIGGER_OR_TARGET = any_child
						QUALITY = culture
					}
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.sah_child.shares_minority_culture
				}
			}
			## Shares faith with minority SaH child.
			if = {
				limit = {
					diarch_candidate_shares_minority_status_with_trigger = {
						TRIGGER_OR_TARGET = any_child
						QUALITY = faith
					}
				}
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.nepotism.sah_child.shares_minority_faith
				}
			}
			# Incumbent Vizier.
			if = {
				limit = { exists = liege.diarch }
				# Close family of incumbent vizier.
				if = {
					limit = {
						NOT = { this = liege.diarch }
						is_close_family_of = liege.diarch
					}
					add = {
						value = massive_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.close_family
					}
				}
				# Extended family of incumbent vizier.
				if = {
					limit = {
						NOT = { this = liege.diarch }
						is_extended_family_of = liege.diarch
					}
					add = {
						value = major_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.extended_family
					}
				}
				# Friends with incumbent vizier.
				if = {
					limit = { has_relation_friend = liege.diarch }
					add = {
						value = medium_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.friend
					}
				}
				# Best Friends with incumbent vizier.
				if = {
					limit = { has_relation_best_friend = liege.diarch }
					add = {
						value = massive_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.best_friend
					}
				}
				# Rivals with incumbent vizier.
				if = {
					limit = { has_relation_rival = liege.diarch }
					add = {
						value = major_diarch_candidate_loss
						desc = diarch_succession_score.nepotism.incumbent_vizier.rival
					}
				}
				# Nemeses with incumbent vizier.
				if = {
					limit = { has_relation_nemesis = liege.diarch }
					add = {
						value = monumental_diarch_candidate_loss
						desc = diarch_succession_score.nepotism.incumbent_vizier.nemesis
					}
				}
				# Shares culture with minority incumbent vizier.
				if = {
					limit = {
						NOT = { this = liege.diarch }
						diarch_candidate_shares_minority_status_with_trigger = {
							TRIGGER_OR_TARGET = diarch
							QUALITY = culture
						}
					}
					add = {
						value = major_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.shares_minority_culture
					}
				}
				# Shares faith with minority incumbent vizier.
				if = {
					limit = {
						NOT = { this = liege.diarch }
						diarch_candidate_shares_minority_status_with_trigger = {
							TRIGGER_OR_TARGET = diarch
							QUALITY = faith
						}
					}
					add = {
						value = major_diarch_candidate_gain
						desc = diarch_succession_score.nepotism.incumbent_vizier.shares_minority_faith
					}
				}
			}
		}
		# Royal court.
		if = {
			limit = {
				liege = { has_royal_court = yes }
				has_dlc_feature = royal_court
			}
			add = {
				desc = diarch_succession_score.category.royal_court
				# ADD SCORE
				## Skill for court type.
				### Diplomacy.
				if = {
					limit = {
						liege = { has_court_type = court_diplomatic }
					}
					add = {
						value = diplomacy
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.diplomacy
					}
				}
				### Martial.
				if = {
					limit = {
						liege = { has_court_type = court_warlike }
					}
					add = {
						value = martial
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.martial
					}
				}
				### Stewardship.
				if = {
					limit = {
						liege = { has_court_type = court_administrative }
					}
					add = {
						value = stewardship
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.stewardship
					}
				}
				### Intrigue.
				if = {
					limit = {
						liege = { has_court_type = court_intrigue }
					}
					add = {
						value = intrigue
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.intrigue
					}
				}
				### Learning.
				if = {
					limit = {
						liege = { has_court_type = court_scholarly }
					}
					add = {
						value = learning
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.learning
					}
				}
				### Prowess.
				if = {
					limit = {
						liege = { has_court_type = court_tribal }
					}
					add = {
						value = prowess
						# Then we subtract the baseline so that your skill has to matter.
						subtract = diarchy_succession_court_type_baseline_value
						desc = diarch_succession_score.royal_court.court_type.prowess
					}
				}
				## Speaks court language.
				if = {
					limit = { knows_court_language_of = liege }
					add = {
						# Value a bit lower than elsewhere; it's not that it's not important, but it's more easily out-balanced by other factors (e.g., competency) so we need to lower it proportionally.
						value = medium_diarch_candidate_gain
						desc = diarch_succession_score.royal_court.speaks_court_language
					}
				}
			}
		}
		# Base skills.
		## Viziers are a very functional job, so they always take account of the most practical courtly skills.
		add = {
			desc = diarch_succession_score.category.competence
			# ADD SCORE
			## Diplomacy.
			add = {
				value = diplomacy
				# Then we subtract the baseline so that your skill has to matter.
				subtract = diarchy_succession_competence_baseline_value
				desc = diarch_succession_score.competence.vizierate.diplomacy
			}
			## Stewardship.
			add = {
				value = stewardship
				# Then we subtract the baseline so that your skill has to matter.
				subtract = diarchy_succession_competence_baseline_value
				desc = diarch_succession_score.competence.vizierate.stewardship
			}
			## Intrigue.
			add = {
				value = intrigue
				# Then we subtract the baseline so that your skill has to matter.
				subtract = diarchy_succession_competence_baseline_value
				desc = diarch_succession_score.competence.vizierate.intrigue
			}
		}
		# Traits: Civil Service.
		## These are a bit more important due to the lack of familial ties, so we boost the score a little.
		add = {
			desc = diarch_succession_score.category.traits.civil_service
			# ADD SCORE
			## Prefer motivated workers.
			### Ambitious trait
			if = {
				limit = { has_trait = ambitious }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.ambitious
				}
			}
			### Diligent trait
			if = {
				limit = { has_trait = diligent }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.diligent
				}
			}
			## But also just things that make you a good civil servant.
			### Humble trait
			if = {
				limit = { has_trait = humble }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.humble
				}
			}
			### Content trait
			if = {
				limit = { has_trait = content }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.content
				}
			}
			### Patient trait
			if = {
				limit = { has_trait = patient }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.patient
				}
			}
			### Just trait
			if = {
				limit = { has_trait = just }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.just
				}
			}
			## Both extremities of the wealth spectrum are appreciated.
			### Greedy
			if = {
				limit = { has_trait = greedy }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.greedy
				}
			}
			### Generous
			if = {
				limit = { has_trait = generous }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.generous
				}
			}
			## Plus some lifestyle cappers.
			### Diplomat
			if = {
				limit = { has_trait = diplomat }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.diplomat
				}
			}
			### Administrator
			if = {
				limit = { has_trait = administrator }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.administrator
				}
			}
			### Avaricious
			if = {
				limit = { has_trait = avaricious }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.avaricious
				}
			}
			### Schemer
			if = {
				limit = { has_trait = schemer }
				add = {
					value = medium_diarch_candidate_gain
					desc = diarch_succession_score.traits.schemer
				}
			}
			# REMOVE SCORE
			## Poor workers.
			### Lazy trait
			if = {
				limit = { has_trait = lazy }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.traits.lazy
				}
			}
			### Arrogant trait
			if = {
				limit = { has_trait = arrogant }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.traits.arrogant
				}
			}
			### Impatient trait
			if = {
				limit = { has_trait = impatient }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.traits.impatient
				}
			}
		}
		# Circumstances.
		add = {
			desc = diarch_succession_score.category.circumstances
			# REMOVE SCORE
			## Has a critical illness
			if = {
				limit = { has_serious_disease_trigger = yes }
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.cripplingly_ill
				}
			}
			## Has severe wounds
			if = {
				limit = { has_trait = wounded_3 }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.badly_wounded
				}
			}
			## Has a criminal reason.
			if = {
				limit = {
					save_temporary_scope_as = char_temp
					liege = {
						OR = {
							has_imprisonment_reason = scope:char_temp
							has_banish_reason = scope:char_temp
							has_execute_reason = scope:char_temp
							has_revoke_title_reason = scope:char_temp
						}
					}
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.known_criminal
				}
			}
			## Under the age of 25
			if = {
				limit = { age <= 25 }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.very_young
				}
			}
			## High-stress characters
			if = {
				limit = { stress_level  >= 1 }
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.stressed_out
				}
			}
			## Has a minor illness
			if = {
				limit = { has_trait = ill }
				add = {
					value = minor_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.mildly_ill
				}
			}
			## Has a minor wound
			if = {
				limit = {
					OR = {
						has_trait = wounded_1
						has_trait = wounded_2
					}
				}
				add = {
					value = medium_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.mildly_wounded
				}
			}
			## Doesn't speak your main language
			### Due to technical constraints, we can currently only check if you speak your liege's culture's language, not if you have any shared languages.
			if = {
				limit = {
					NOR = {
						knows_language_of_culture = liege.culture
						# Exempt family members so that we don't screw wrong-gendered unlanded chars over.
						is_close_or_extended_family_of = liege
					}
				}
				add = {
					value = major_diarch_candidate_loss
					desc = diarch_succession_score.circumstances.not_speak_language
				}
			}
		}
		# REMOVE CANDIDATES
		## Cannot be a big land owner
		if = {
			limit = { highest_held_title_tier > tier_barony }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.count_or_above
			}
		}
		## Must be an adult
		if = {
			limit = { is_adult = no }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.child
			}
		}
		## Must not NOT imprisoned
		if = {
			limit = { is_imprisoned = yes }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.imprisoned
			}
		}
		## Is NOT incapable or infirm
		if = {
			limit = {
				OR = {
					is_incapable = yes
					has_trait = infirm
				}
			}
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.incapable_or_infirm
			}
		}
		## MUST match liege's faith gender requirements
		### We double-check this here (even though it's disallowed for validity) to stop wrong-gendered characters sneakily inheriting the post when the numbers haven't been recalc'd then _immediately_ invalidating.
		if = {
			limit = { diarch_matches_liege_faith_gender_preference_trigger = no }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.right_gendered_for_liege
			}
		}
		## Event filter.
		### Current regent's shenanigans.
		if = {
			limit = { var:diarch_succession_filtered_due_to_incumbents_politicking ?= liege }
			add = {
				value = hard_disable_diarch_candidate_value
				desc = diarch_succession_score.disqualifiers.event_filters.incumbent_politicking
			}
		}
	}
}

courtly_offence_at_succession_threshold_low = 15
courtly_offence_at_succession_threshold_medium = 30
courtly_offence_at_succession_threshold_high = 45

courtly_offence_scandalise_value = -60
courtly_offence_greatly_offend_value = -50
courtly_offence_offend_value = -40
courtly_offence_somewhat_offend_value = -20
courtly_offence_lightly_offend_value = -10

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

diarch_ai_desire_plus_3_value = 50
diarch_ai_desire_plus_2_value = 30
diarch_ai_desire_plus_1_value = 10
diarch_ai_desire_minus_1_value = -10
diarch_ai_desire_minus_2_value = -30
diarch_ai_desire_minus_3_value = -50

liege_trust_diarch_trilateral_interaction_default_value = {
	# Base for players.
	value = 25
	# But if we've got AI on either side of us, who're nicely weighted to be considerate to their liege, be a little more trusting.
	if = {
		limit = {
			scope:actor = { is_ai = yes }
			scope:recipient = { is_ai = yes }
		}
		add = 75
	}
}

liege_diarchy_veto_prestige_cost_high = -250
liege_diarchy_veto_prestige_cost_medium = -150
liege_diarchy_veto_prestige_cost_low = -75

liege_diarchy_veto_influence_cost_high = -150
liege_diarchy_veto_influence_cost_medium = -100
liege_diarchy_veto_influence_cost_low = -50

# Overall control values for keeping some vague level of parity between prestige surcharges for lieges in powerful diarchies.
liege_diarchy_surcharge_interaction_miniscule_value = minor_prestige_value
liege_diarchy_surcharge_interaction_minor_value = medium_prestige_value
liege_diarchy_surcharge_interaction_medium_value = 250
liege_diarchy_surcharge_interaction_major_value = major_prestige_value
liege_diarchy_surcharge_interaction_massive_value = 450

liege_diarchy_surcharge_interaction_revoke_title_interaction_value = {
	# Base value of zero, since this is free by default.
	value = {
		value = 0
		desc = BASE
	}

	# But, inside diarchies, there's a cost attached to various simple political actions.
	scope:actor = {
		if = {
			limit = { has_active_diarchy = yes }
			# Mild costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_mild }
				add = {
					value = liege_diarchy_surcharge_interaction_miniscule_value
					desc = IS_IN_DIARCHY_MILD_COSTS
				}
			}
			# Medium costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_medium }
				add = {
					value = liege_diarchy_surcharge_interaction_minor_value
					desc = IS_IN_DIARCHY_MEDIUM_COSTS
				}
			}
			# Major costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_major }
				add = {
					value = liege_diarchy_surcharge_interaction_medium_value
					desc = IS_IN_DIARCHY_MAJOR_COSTS
				}
			}
			# Massive costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_massive }
				add = {
					value = liege_diarchy_surcharge_interaction_massive_value
					desc = IS_IN_DIARCHY_MASSIVE_COSTS
				}
			}
		}
	}
}

liege_diarchy_surcharge_interaction_retract_vassal_interaction_value = {
	# Base value of zero, since this is free by default.
	value = {
		value = 0
		desc = BASE
	}

	# But, inside diarchies, there's a cost attached to various simple political actions.
	scope:actor = {
		if = {
			limit = { has_active_diarchy = yes }
			# Mild costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_mild }
				add = {
					value = liege_diarchy_surcharge_interaction_miniscule_value
					desc = IS_IN_DIARCHY_MILD_COSTS
				}
			}
			# Medium costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_medium }
				add = {
					value = liege_diarchy_surcharge_interaction_minor_value
					desc = IS_IN_DIARCHY_MEDIUM_COSTS
				}
			}
			# Major costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_major }
				add = {
					value = liege_diarchy_surcharge_interaction_medium_value
					desc = IS_IN_DIARCHY_MAJOR_COSTS
				}
			}
			# Massive costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_massive }
				add = {
					value = liege_diarchy_surcharge_interaction_major_value
					desc = IS_IN_DIARCHY_MASSIVE_COSTS
				}
			}
		}
	}
}

liege_diarchy_surcharge_interaction_imprison_interaction_value = {
	# Base value of zero, since this is free by default.
	value = {
		value = 0
		desc = BASE
	}

	# But, inside diarchies, there's a cost attached to various simple political actions.
	scope:actor = {
		if = {
			limit = { has_active_diarchy = yes }
			# Mild costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_mild }
				add = {
					value = liege_diarchy_surcharge_interaction_miniscule_value
					desc = IS_IN_DIARCHY_MILD_COSTS
				}
			}
			# Medium costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_medium }
				add = {
					value = liege_diarchy_surcharge_interaction_minor_value
					desc = IS_IN_DIARCHY_MEDIUM_COSTS
				}
			}
			# Major costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_major }
				add = {
					value = liege_diarchy_surcharge_interaction_medium_value
					desc = IS_IN_DIARCHY_MAJOR_COSTS
				}
			}
			# Massive costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_massive }
				add = {
					value = liege_diarchy_surcharge_interaction_major_value
					desc = IS_IN_DIARCHY_MASSIVE_COSTS
				}
			}
		}
	}
}

liege_diarchy_surcharge_interaction_execute_prisoner_interaction_value = {
	# Base value of zero, since this is free by default.
	value = {
		value = 0
		desc = BASE
	}

	# But, inside diarchies, there's a cost attached to various simple political actions.
	scope:actor = {
		if = {
			limit = { has_active_diarchy = yes }
			# Mild costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_mild }
				add = {
					value = liege_diarchy_surcharge_interaction_miniscule_value
					desc = IS_IN_DIARCHY_MILD_COSTS
				}
			}
			# Medium costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_medium }
				add = {
					value = liege_diarchy_surcharge_interaction_minor_value
					desc = IS_IN_DIARCHY_MEDIUM_COSTS
				}
			}
			# Major costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_major }
				add = {
					value = liege_diarchy_surcharge_interaction_medium_value
					desc = IS_IN_DIARCHY_MAJOR_COSTS
				}
			}
			# Massive costs.
			if = {
				limit = { has_diarchy_active_parameter = liege_pays_currency_surcharge_for_mundane_interactions_massive }
				add = {
					value = liege_diarchy_surcharge_interaction_major_value
					desc = IS_IN_DIARCHY_MASSIVE_COSTS
				}
			}
		}
	}

	# If our faith believes in HumSac, then this is a religious action and never costs prestige.
	if = {
		limit = {
			scope:actor.faith = { has_doctrine_parameter = human_sacrifice_active }
		}
		multiply = 0
	}
}

subsidised_liege_authority_discount_value = 0.5
lowered_liege_authority_discount_value = 0.25

legal_meddling_interaction_title_cost_value = {
	value = 0

	# Boost the value for duchies.
	if = {
		limit = {
			exists = scope:target
			scope:target.tier = tier_duchy
		}
		add = major_prestige_loss
	}
	# Even more for kingdoms.
	else_if = {
		limit = {
			exists = scope:target
			scope:target.tier = tier_kingdom
		}
		add = massive_prestige_loss
	}
	# Or else default back to counties.
	else = { add = medium_prestige_loss }
}

legal_meddling_interaction_title_discounted_cost_value = {
	value = legal_meddling_interaction_title_cost_value
	multiply = 0.5
	# Now make it neat.
	divide = 10
	round = yes
	multiply = 10
}

syphon_treasury_duel_target_value = {
	# We generally want to duel vs. the liege's stewardship...
	value = liege.stewardship
	# ... but in the interests of fairness, we put a floor on it.
	min = low_skill_rating
}

syphon_treasury_stewardship_very_high = very_high_skill_rating
syphon_treasury_stewardship_high = decent_skill_rating
syphon_treasury_stewardship_medium = mediocre_skill_rating

syphon_treasury_gold_gain_low = {
	value = 0
	add = scope:recipient.minor_gold_value
}
syphon_treasury_gold_gain_medium = {
	value = 0
	add = scope:recipient.medium_gold_value
}
syphon_treasury_gold_gain_high = {
	value = 0
	add = scope:recipient.major_gold_value
}
syphon_treasury_gold_gain_very_high = {
	value = 0
	add = scope:recipient.monumental_gold_value
}

syphon_treasury_recipient_county_tally = {
	value = 0
	# This gets used in a trigger and was being fussy about having effects in it, so we do it the manual way. Le sigh.
	scope:recipient = {
		# If scope:recipient has at least five counties, we add 5.
		if = {
			limit = {
				any_held_county = { count >= 5 }
			}
			add = 5
		}
		# Else 4.
		else_if = {
			limit = {
				any_held_county = { count >= 4 }
			}
			add = 4
		}
		# Else 3.
		else_if = {
			limit = {
				any_held_county = { count >= 3 }
			}
			add = 3
		}
		# Else 2.
		else_if = {
			limit = {
				any_held_county = { count >= 2 }
			}
			add = 2
		}
		# Else 1.
		else = { add = 1 }
	}
}

syphon_treasury_county_attribute_loss_fraction = {
	value = scope:county_attribute_loss
	scope:recipient = {
		# If scope:recipient has at least five counties, we divide by 5.
		if = {
			limit = {
				any_held_county = { count >= 5 }
			}
			multiply = 0.2
		}
		# Else 4.
		else_if = {
			limit = {
				any_held_county = { count >= 4 }
			}
			multiply = 0.25
		}
		# Else 3.
		else_if = {
			limit = {
				any_held_county = { count >= 3 }
			}
			multiply = 0.33
		}
		# Else 2.
		else_if = {
			limit = {
				any_held_county = { count >= 2 }
			}
			multiply = 0.5
		}
		# Else 1, so we do nothing.
	}
}

shift_privileges_interaction_target_cost_value = {
	value = 0

	# It's cheaper to attack higher tiers than lower ones.
	## So kingdoms are cheapest.
	if = {
		limit = { scope:recipient.highest_held_title_tier = tier_kingdom }
		add = medium_prestige_loss
	}
	## Then duchies.
	else_if = {
		limit = { scope:recipient.highest_held_title_tier = tier_duchy }
		add = major_prestige_loss
	}
	## And otherwise we default back to the humble county.
	else = { add = massive_prestige_loss }
}

shift_privileges_interaction_target_discounted_cost_value = {
	value = shift_privileges_interaction_target_cost_value
	multiply = 0.5
	# Now make it neat.
	divide = 10
	round = yes
	multiply = 10
}

shift_privileges_modifier_duration_value = 8

swing_scales_discounts_multiplier_value = {
	# Landless characters pay a fraction.
	if = {
		limit = { is_playable_character = no }
		value = 0.75
	}
	# Otherwise we give the AI mate's rates to encourage them to use the system.
	else_if = {
		limit = { is_ai = yes }
		value = 0.5
	}
	# Otherwise no discounts.
	else = { value = 1 }
}

swing_scales_influence_cost_value = {
	value = 0
	# Gate by liege tier.
	## Count.
	if = {
		limit = { liege.highest_held_title_tier <= tier_county }
		add = minor_influence_value
	}
	## Duke.
	else_if = {
		limit = { liege.highest_held_title_tier <= tier_duchy }
		add = medium_influence_value
	}
	## King or Emperor
	else = { add = major_influence_value }

	# Adjust how much this swing costs due to Legitimacy
	## Should only affect the regent, not the ruler
	if = {
		limit = {
			scope:recipient = { is_liege_or_above_of = scope:actor }
		}
		# 1
		if = {
			limit = { liege.legitimacy_level = 1 }
			add = miniscule_influence_value
		}
		# 2
		else_if = {
			limit = { liege.legitimacy_level = 2 }
			add = minor_influence_value
		}
		# 3
		else_if = {
			limit = { liege.legitimacy_level = 3 }
			add = medium_influence_value
		}
		# 4
		else_if = {
			limit = { liege.legitimacy_level = 4 }
			add = major_influence_value
		}
		# 5
		else_if = {
			limit = { liege.legitimacy_level = 5 }
			add = massive_influence_value
		}
		else = {
			# Deliberately empty
			# Adjustable in the future if necessary
		}
	}
}

swing_scales_prestige_cost_value = {
	value = 0
	# Gate by liege tier.
	## Count.
	if = {
		limit = { liege.highest_held_title_tier <= tier_county }
		add = minor_prestige_value
	}
	## Duke.
	else_if = {
		limit = { liege.highest_held_title_tier <= tier_duchy }
		add = medium_prestige_value
	}
	## King or Emperor
	else = { add = major_prestige_value }

	# Adjust how much this swing costs due to Legitimacy
	## Should only affect the regent, not the ruler
	if = {
		limit = {
			scope:recipient = { is_liege_or_above_of = scope:actor }
		}
		# 1
		if = {
			limit = { liege.legitimacy_level = 1 }
			add = miniscule_prestige_value
		}
		# 2
		else_if = {
			limit = { liege.legitimacy_level = 2 }
			add = minor_prestige_value
		}
		# 3
		else_if = {
			limit = { liege.legitimacy_level = 3 }
			add = medium_prestige_value
		}
		# 4
		else_if = {
			limit = { liege.legitimacy_level = 4 }
			add = major_prestige_value
		}
		# 5
		else_if = {
			limit = { liege.legitimacy_level = 5 }
			add = massive_prestige_value
		}
		else = {
			# Deliberately empty
			# Adjustable in the future if necessary
		}
	}
}

swing_scales_piety_cost_value = {
	# Various ways to be charged piety.
	## Pure route.
	if = {
		limit = {
			OR = {
				always = scope:swing_piety
				# And if we're in the important_action...
				NOT = { exists = scope:swing_piety }
			}
		}
		value = 0
		# Gate by liege tier.
		## Count.
		if = {
			limit = { liege.highest_held_title_tier <= tier_county }
			add = minor_piety_value
		}
		## Duke.
		else_if = {
			limit = { liege.highest_held_title_tier <= tier_duchy }
			add = medium_piety_value
		}
		## King or Emperor
		else = { add = major_piety_value }
	}
	## Hybrid HoF route.
	else_if = {
		limit = { always = scope:swing_hof }
		value = 0
		# Gate by liege tier.
		## Count.
		if = {
			limit = { liege.highest_held_title_tier <= tier_county }
			add = minor_piety_value
		}
		## Duke.
		else_if = {
			limit = { liege.highest_held_title_tier <= tier_duchy }
			add = medium_piety_value
		}
		## King or Emperor
		else = { add = major_piety_value }
	}

	# Adjust how much this swing costs due to Legitimacy
	## Should only affect the regent, not the ruler
	if = {
		limit = {
			scope:recipient = { is_liege_or_above_of = scope:actor }
		}
		# 1
		if = {
			limit = { liege.legitimacy_level = 1 }
			add = miniscule_piety_value
		}
		# 2
		else_if = {
			limit = { liege.legitimacy_level = 2 }
			add = minor_piety_value
		}
		# 3
		else_if = {
			limit = { liege.legitimacy_level = 3 }
			add = medium_piety_value
		}
		# 4
		else_if = {
			limit = { liege.legitimacy_level = 4 }
			add = major_piety_value
		}
		# 5
		else_if = {
			limit = { liege.legitimacy_level = 5 }
			add = massive_piety_value
		}
		else = {
			# Deliberately empty
			# Adjustable in the future if necessary
		}
	}
}

swing_scales_cash_cost_value = {
	## Pure route.
	if = {
		limit = {
			OR = {
				always = scope:swing_gold
				# And if we're in the important action...
				NOT = { exists = scope:swing_gold }
			}
		}
		value = 0
		# Gate by liege tier.
		## Count.
		if = {
			limit = { liege.highest_held_title_tier <= tier_county }
			add = medium_gold_value
		}
		## Duke.
		else_if = {
			limit = { liege.highest_held_title_tier <= tier_duchy }
			add = major_gold_value
		}
		## King or Emperor
		else = { add = massive_gold_value }
	}
	## Hybrid HoF route.
	else_if = {
		limit = { always = scope:swing_hof }
		value = 0
		# Gate by liege tier.
		## Count.
		if = {
			limit = { liege.highest_held_title_tier <= tier_county }
			add = minor_gold_value
		}
		## Duke.
		else_if = {
			limit = { liege.highest_held_title_tier <= tier_duchy }
			add = medium_gold_value
		}
		## King or Emperor
		else = { add = major_gold_value }
	}

	# Adjust how much this swing costs due to Legitimacy
	## Should only affect the regent, not the ruler
	if = {
		limit = {
			scope:recipient = { is_liege_or_above_of = scope:actor }
		}
		# 1
		if = {
			limit = { liege.legitimacy_level = 1 }
			add = tiny_gold_value
		}
		# 2
		else_if = {
			limit = { liege.legitimacy_level = 2 }
			add = minor_gold_value
		}
		# 3
		else_if = {
			limit = { liege.legitimacy_level = 3 }
			add = medium_gold_value
		}
		# 4
		else_if = {
			limit = { liege.legitimacy_level = 4 }
			add = major_gold_value
		}
		# 5
		else_if = {
			limit = { liege.legitimacy_level = 5 }
			add = massive_gold_value
		}
		else = {
			# Deliberately empty
			# Adjustable in the future if necessary
		}
	}
}

swing_scales_hof_actor_opinion_min_value = high_positive_opinion

swing_scales_hof_recipient_opinion_max_value = medium_positive_opinion

liege_dismiss_temporary_regency_interaction_dynasty_prestige_value = { value = medium_dynasty_prestige_gain }

liege_dismiss_entrenched_regency_interaction_dynasty_prestige_value = { value = major_dynasty_prestige_gain }

diarch_should_educate_liege_value = 50

vizier_bonus_tax_jurisdictions_value = {
	add = stewardship
	divide = 7.5
	min = 1
	max = 5
}

vizier_dismissal_penalty_sop_mult_value = 0.1

vizier_extravagance_modifiers_t1_tally = {
	if = {
		limit = { has_character_modifier = vizier_extravagance_t1_treasure_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t1_activities_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t1_property_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t1_charity_modifier }
		add = 1
	}
}

vizier_extravagance_modifiers_t2_tally = {
	if = {
		limit = { has_character_modifier = vizier_extravagance_t2_treasure_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t2_activities_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t2_property_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t2_charity_modifier }
		add = 1
	}
}

vizier_extravagance_modifiers_t3_tally = {
	if = {
		limit = { has_character_modifier = vizier_extravagance_t3_treasure_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t3_activities_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t3_property_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t3_charity_modifier }
		add = 1
	}
}

vizier_extravagance_modifiers_t4_tally = {
	if = {
		limit = { has_character_modifier = vizier_extravagance_t4_treasure_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t4_activities_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t4_property_modifier }
		add = 1
	}
	if = {
		limit = { has_character_modifier = vizier_extravagance_t4_charity_modifier }
		add = 1
	}
}

vizier_mulct_swing_check_value = {
	value = 100
	subtract = diarchy_swing
}
vizier_mulct_swing_gain_miniscule_value = miniscule_sop_swing_diarch_gain
vizier_mulct_swing_gain_minor_value = minor_sop_swing_diarch_gain
vizier_mulct_swing_gain_medium_value = medium_sop_swing_diarch_gain
vizier_mulct_swing_gain_major_value = major_sop_swing_diarch_gain
vizier_mulct_swing_gain_massive_value = massive_sop_swing_diarch_gain

request_imperial_expedition_influence_stake_minor_value = 100
request_imperial_expedition_influence_stake_medium_value = 200
request_imperial_expedition_influence_stake_major_value = 300

request_imperial_expedition_minimum_troop_count_value = 1000

request_imperial_expedition_influence_from_counties_full_value = {
	value = medium_influence_value
	multiply = var:title_tally_all
}
request_imperial_expedition_influence_from_vassals_full_value = {
	value = medium_influence_value
	multiply = var:vassal_tally_all
}

request_imperial_expedition_influence_from_counties_prize_value = {
	value = medium_influence_value
	multiply = var:vassal_tally_prize
}
request_imperial_expedition_influence_from_vassals_prize_value = {
	value = medium_influence_value
	multiply = var:title_tally_prize
}

request_imperial_expedition_influence_from_counties_reduced_value = {
	value = minor_influence_value
	multiply = var:title_tally_all
}
request_imperial_expedition_influence_from_vassals_reduced_value = {
	value = medium_influence_value
	multiply = var:vassal_tally_all
}

diarch_demand_despotate_interaction_stake_major_value = 500
diarch_demand_despotate_interaction_stake_medium_value = 350
diarch_demand_despotate_interaction_stake_minor_value = 200
diarch_demand_despotate_interaction_stake_to_raise_major_value = {
	value = diarch_demand_despotate_interaction_stake_major_value
	multiply = -2
}
diarch_demand_despotate_interaction_stake_to_raise_medium_value = {
	value = diarch_demand_despotate_interaction_stake_medium_value
	multiply = -2
}
diarch_demand_despotate_interaction_stake_to_raise_minor_value = {
	value = diarch_demand_despotate_interaction_stake_minor_value
	multiply = -2
}
# Invert these _again_ for use in loc/some triggers.
## No I am not okay, thank you for asking.
diarch_demand_despotate_interaction_stake_to_raise_major_inverted_value = {
	value = diarch_demand_despotate_interaction_stake_to_raise_major_value
	multiply = -1
}
diarch_demand_despotate_interaction_stake_to_raise_medium_inverted_value = {
	value = diarch_demand_despotate_interaction_stake_to_raise_medium_value
	multiply = -1
}
diarch_demand_despotate_interaction_stake_to_raise_minor_inverted_value = {
	value = diarch_demand_despotate_interaction_stake_to_raise_minor_value
	multiply = -1
}

scapegoat_counterpart_interaction_calc_diplo_diff_treshhold_value = {
	add = scope:actor.diplomacy
	subtract = scope:recipient.diplomacy
}
scapegoat_counterpart_interaction_calc_intrigue_diff_treshhold_value = {
	add = scope:actor.intrigue
	subtract = scope:recipient.intrigue
}

diarch_regent_appoints_self_co_emperor_interaction_sop_swing_set_value = 40

diarch_authority_ceded_opinion_value = 20

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

diarch_reduced_strife_for_inviting_powerful_covassals_value = {
	value = 0
	every_attending_character = {
		limit = {
			NOT = { this = scope:host }
			is_powerful_vassal_of = scope:host.liege
		}
		add = -4
	}
}

##################################################
# Mandate Events

diarchy_1731_minimum_county_opinion_value = high_negative_opinion

##################################################
# Decisions

pv_overthrow_threshold_value = {
	value = 0
	# Grab our sum total of powerful vassals.
	liege = {
		every_powerful_vassal = { add = 1 }
	}
	# Halve it.
	multiply = 0.5
	# Now round down to even us out.
	floor = yes
	# And add +1 to get a simple majority.
	add = 1
	# ... but then subtract one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	if = {
		limit = { is_powerful_vassal = yes }
		add = -1
	}
}

pv_overthrow_tally_value = {
	value = 0
	every_in_list = {
		variable = coup_pv_supporters_list
		limit = {
			is_powerful_vassal_of = root.liege
			is_alive = yes
		}
		add = 1
	}
}

# Display versions of the values: these are one higher to adjust for root potentially being in them.
pv_overthrow_threshold_display_value = {
	value = pv_overthrow_threshold_value
	# ... but then add back the one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	if = {
		limit = { is_powerful_vassal = yes }
		add = 1
	}
}

pv_overthrow_tally_display_value = {
	value = pv_overthrow_tally_value
	# ... and remember to add one if we're a powerful vassal, since we _won't_ be in the list but, naturally, support the coup.
	## We have to separate out the values like this, since the actual list checks powerful vassals and we're not actually in it.
	if = {
		limit = { is_powerful_vassal = yes }
		add = 1
	}
}

##################################################
# Parameters

# We scale the benefits to both parties in a co-emperorship or junior emperorship by how many years they've been in the job, controlled by this.
co_emperor_scale_years_in_job_value = 5

# Controls how much skill gain child diarchs get on transitioning to majority
## T1
diarch_gain_skill_on_majority_t1_primary_value = 2
diarch_gain_skill_on_majority_t1_secondary_value = 1
## T2
diarch_gain_skill_on_majority_t2_primary_value = 3
diarch_gain_skill_on_majority_t2_primary_diff_value = {
	value = diarch_gain_skill_on_majority_t2_primary_value
	subtract = diarch_gain_skill_on_majority_t1_primary_value
}
diarch_gain_skill_on_majority_t2_secondary_value = 2
diarch_gain_skill_on_majority_t2_secondary_diff_value = {
	value = diarch_gain_skill_on_majority_t2_secondary_value
	subtract = diarch_gain_skill_on_majority_t1_secondary_value
}
## T3
diarch_gain_skill_on_majority_t3_primary_value = 4
diarch_gain_skill_on_majority_t3_primary_diff_value = {
	value = diarch_gain_skill_on_majority_t3_primary_value
	subtract = diarch_gain_skill_on_majority_t2_primary_value
}
diarch_gain_skill_on_majority_t3_secondary_value = 3
diarch_gain_skill_on_majority_t3_secondary_diff_value = {
	value = diarch_gain_skill_on_majority_t3_secondary_value
	subtract = diarch_gain_skill_on_majority_t2_secondary_value
}
## T4
diarch_gain_skill_on_majority_t4_primary_value = 5
diarch_gain_skill_on_majority_t4_primary_diff_value = {
	value = diarch_gain_skill_on_majority_t4_primary_value
	subtract = diarch_gain_skill_on_majority_t3_primary_value
}
diarch_gain_skill_on_majority_t4_secondary_value = 4
diarch_gain_skill_on_majority_t4_secondary_diff_value = {
	value = diarch_gain_skill_on_majority_t4_secondary_value
	subtract = diarch_gain_skill_on_majority_t3_secondary_value
}
