﻿namespace = diarchy

# DESIGN NOTE ON MANDATE EVENTS
# Mandate events should be structured in script following a specific option format in order to sync them with the UX presented to the player, and scripted proportionally in a certain fashion for the same reason.
#
# The option format for _every_ mandate event should be:
## Resolve the situation at a cost to yourself for the benefit of your liege
### Option #1 allows this using one of the positive traits associated with that mandate - this replaces the possible skill duel
### Option #2 allows this using a skill duel against one of the skills associated with that mandate
## Resolve the situation and split the benefit between yourself and your liege
### Option #3 is always a straight skill duel, using the same skill as Option #2
## Abandon the situation
### Option #4 allows this using one of the negative traits associated with that mandate - this replaces the regular opt out
### Option #5 is a regular opt out
#
# The ratio is for which skills are used in these events. Every mandate has a primary skill and two secondary skills, and the primary skill should be the one most used in the events. The ratio to aim for is 3:1:1 for primary skill:secondary skill A:secondary skill B.

##################################################
# #Notifications
# 0001 - 0020	Regency Started (various)
# 0021 - 0040	You become Regent
# 0101 - 0140	Maintenance (various)
#
# #Schemes
# 0501 - 0510	Overthrow Diarch Scheme - Maintenance
# 0511 - 0550	Overthrow Diarch Scheme - Failure
# 0551 - 0590	Overthrow Diarch Scheme - Success
#
# #Mandates - Fill Coffers
# 1201 - 1210	Open Hearts, Open Pockets - Levy an extra tax from a wealthy co-vassal.
# 1211 - 1220	Terms & Conditions - Reinforce the fine points of a co-vassal's contract.
# 1221 - 1230	Your New Home - Resettle peasants from a rural county to an urban one.
# 1231 - 1240	In for a Penny - Issue stricter criminal fines.
# 1241 - 1250	A Taxing Subject - Levy exempt institutions (churches in theocratic faiths, privileged burghers and charities in lay ones).
#
# #Mandates - Promote Authority
# 1701 - 1710	The Right to Rule - Boost CA/TA by negotiating with powerful vassals.
# 1711 - 1720	Expiration Date - Exploit wording in a vassal contract to reset a cooldown.
# 1721 - 1730	Settling Grievances - Negotiate a powerful character out of a faction.
# 1731 - 1740	Settling Accounts - Negotiate a group of counties out of a faction.
# 1741 - 1750	Look at it this Way - Boost the opinion council members have of their liege.
#
# #Mandates - Swell Armies
# 2201 - 2210	Bring Out Your Youth - Round up countryside recruits.
# 2211 - 2220	A Rare Talent - Woo Hedge Knight
# 2221 - 2230	Martial Donatives - Entice professional soldiery
# 2231 - 2240	A Better Use for You - Empty the gaols
# 2241 - 2250	Make a WomanMan Out of You - Train baronial troops
#
# #Interactions
# 8001 - 8010	Request Imperial Expedition - Letter notification events
# 8011 - 8020	Request Imperial Expedition - Domain choice events
#
# #Decisions
# 9001 - 9040	Attempt to Overthrow Ruler - throw-down to usurp your liege without a war.
##################################################










##################################################
# NOTIFICATIONS & MAINTENANCE

##################################################
# Regency Started (various)
# by Ewan Cowhig Croft
# 0001 - 0020
##################################################

#	You've just been forced into a regency because you've been imprisoned.
diarchy.0001 = {
	hidden = yes

	trigger = {
		basic_eligible_for_diarchy_trigger = yes
		imprisonment_would_cause_regency_trigger = yes
	}

	immediate = {
		start_diarchy = temporary_regency
	}
}

#	You've just been forced into a regency because you're travelling outside of your sub-realm.
diarchy.0002 = {
	hidden = yes

	trigger = {
		basic_eligible_for_diarchy_trigger = yes
		# Diarchs check your liege so that they can attend business within the realm easily.
		trigger_if = {
			limit = { is_diarch = yes }
			travel_would_cause_regency_trigger = { REALM_HOLDER = root.liege }
		}
		# Otherwise, just grab whoe'er.
		trigger_else = {
			travel_would_cause_regency_trigger = { REALM_HOLDER = root }
		}
	}

	immediate = {
		start_diarchy = temporary_regency
	}
}

#	You've just been forced into a regency for personal reasons (e.g., you're a child).
diarchy.0011 = {
	hidden = yes

	trigger = {
		has_active_diarchy = no
		regency_for_personal_reasons_trigger = yes
		basic_eligible_for_diarchy_trigger = yes
	}

	immediate = {
		start_diarchy = regency
	}
}

#	You've been forced into a regency arbitrarily (e.g., due to history setup).
diarchy.0012 = {
	hidden = yes

	immediate = {
		start_diarchy = regency
		# Historic setup stuff.
		## Fatimids start basically completely screwed.
		if = {
			limit = { this = character:3096 }
			set_diarchy_swing = 100
		}
	}
}

##################################################
# Called to Become Diarch
# by Ewan Cowhig Croft
# 0021 - 0040
##################################################

scripted_trigger diarch_0021_is_liege_travelling_abroad_trigger = {
	is_travelling = yes
	NOT = { top_liege = current_travel_plan.final_destination_province.county.holder.top_liege  }
}

scripted_trigger diarch_0021_is_liege_in_army_trigger = {
	is_at_war_as_attacker = yes
	is_in_army = yes
}

scripted_trigger diarch_0021_event_option_arrogant_trigger = {
	OR = {
		has_trait = arrogant
		has_trait = ambitious
	}
}

#	You are called to support the realm as a diarch.
diarchy.0021 = {
	type = character_event
	title = diarchy.0021.t
	desc = {
		# Nature of the appointment.
		first_valid = {
			# Is a child?
			triggered_desc = {
				trigger = {
					liege = { is_adult = no }
				}
				desc = diarchy.0021.desc.appointment_nature.child
			}
			# Is incapable?
			triggered_desc = {
				trigger = {
					liege = { has_trait = incapable }
				}
				desc = diarchy.0021.desc.appointment_nature.incapable
			}
			# Is imprisoned?
			triggered_desc = {
				trigger = {
					liege = { is_imprisoned = yes }
				}
				desc = diarchy.0021.desc.appointment_nature.imprisoned
			}
			# Is travelling?
			triggered_desc = {
				trigger = {
					liege = { diarch_0021_is_liege_travelling_abroad_trigger = yes }
				}
				desc = diarchy.0021.desc.appointment_nature.travelling
			}
			# Is at war?
			triggered_desc = {
				trigger = {
					liege = { diarch_0021_is_liege_in_army_trigger = yes }
				}
				desc = diarchy.0021.desc.appointment_nature.war
			}
			# Fallback.
			desc = diarchy.0021.desc.appointment_nature.fallback
		}
		# Diarchy type.
		first_valid = {
			# Temporary regency.
			triggered_desc = {
				trigger = {
					liege = { has_diarchy_parameter = diarchy_type_is_temporary_regency }
				}
				desc = diarchy.0021.desc.diarchy_type.regency_temporary
			}
			# Entrenched regency.
			triggered_desc = {
				trigger = {
					liege = { has_diarchy_parameter = diarchy_type_is_entrenched_regency }
				}
				desc = diarchy.0021.desc.diarchy_type.regency_entrenched
			}
			# Fallback.
			desc = diarchy.0021.desc.diarchy_type.fallback
		}
		desc = diarchy.0021.desc.outro
	}
	theme = realm
	left_portrait = {
		character = root
		animation = chancellor
	}
	right_portrait = {
		character = liege
		# Likes you.
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = liege
					value >= medium_positive_opinion
				}
			}
			animation = admiration
		}
		# Dislikes you.
		triggered_animation = {
			trigger = {
				reverse_opinion = {
					target = liege
					value <= medium_negative_opinion
				}
			}
			animation = disgust
		}
		# Neutral about you.
		triggered_animation = {
			trigger = { always = yes }
			animation = personality_bold
		}
	}
	# Default background is fine, but if the liege is off doing other things, then we want to note that.
	## Children live in the relaxing room.
	override_background = {
		trigger = {
			liege = { is_adult = no }
		}
		reference = relaxing_room_scope
	}
	## Incapables live in the bedroom.
	override_background = {
		trigger = {
			liege = { has_trait = incapable }
		}
		reference = bedchamber
	}
	## Prisoners live in the dungeon (even if they're in house arrest - this is more of a visual storytelling thing).
	override_background = {
		trigger = {
			liege = { is_imprisoned = yes }
		}
		reference = dungeon_scope
	}
	## Travellers take their current location.
	override_background = {
		trigger = {
			liege = { diarch_0021_is_liege_travelling_abroad_trigger = yes }
		}
		reference = wilderness_scope
	}
	## Commanding an army? You get a battlefield.
	override_background = {
		trigger = {
			liege = { diarch_0021_is_liege_in_army_trigger = yes }
		}
		reference = battlefield
	}

	trigger = {
		# Don't fire the event if we've had it once this diarchy already.
		NOT = { has_character_flag = has_had_diarch_intro_event_flag }
		exists = liege
		liege = { has_active_diarchy = yes }
	}

	immediate = {
		play_music_cue = "mx_cue_positive_effect"
		# Sort scopes.
		save_scope_as = diarch
		liege ?= {
			# Grab the liege for general ease.
			save_scope_as = liege
			# But also for backgrounds.
			## If liege is a child, we want _their_ relaxing room.
			if = {
				limit = { is_adult = no }
				save_scope_as = background_relaxing_room_scope
			}
			## We want to take the imprisoner's dungeon if necessary.
			if = {
				limit = { exists = imprisoner }
				imprisoner = { save_scope_as = background_dungeon_scope }
			}
			## And if you're travelling, we want to take your location.
			if = {
				limit = { is_travelling = yes }
				location = { save_scope_as = background_wilderness_scope }
			}
		}
		# Landless diarchs get a little bit of extra spending prestige.
		if = {
			limit = { is_ruler = no }
			add_prestige_no_experience = 500
		}
		# Reminder about diarch powers.
		custom_tooltip = diarchy.0021.reminder.diarch_powers
		# Reminder about the Scales of Power.
		custom_tooltip = diarchy.0021.reminder.scales_of_power
		# Mark that this character has had the intro event and we don't want to give it to them again till they leave their role.
		add_character_flag = has_had_diarch_intro_event_flag
	}

	# I shall start my rei-#EMP rule#! at once!
	option = {
		name = diarchy.0021.a
		trigger = { diarch_0021_event_option_arrogant_trigger = yes }
		trait = arrogant
		trait = ambitious
		
		# Swing the scales somewhat in your favour.
		update_diarchy_swing_with_perspective_effect = {
			SWING = minor_sop_swing_diarch_gain
			LIEGE = scope:liege
		}

		stress_impact = {
			ambitious = miniscule_stress_impact_loss
			content = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -0.5
			}
		}
	}
	
	# I already have so many ideas for the realm!
	option = {
		name = diarchy.0021.a.sedate
		trigger = { diarch_0021_event_option_arrogant_trigger = no }
		
		# Swing the scales a bit in your favour.
		update_diarchy_swing_with_perspective_effect = {
			SWING = minor_sop_swing_diarch_gain
			LIEGE = scope:liege
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			lazy = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -0.5
			}
		}
	}
	
	# Ah, recognition.
	option = {
		name = diarchy.0021.b
		
		# Some bonus prestige.
		add_prestige = minor_prestige_gain

		stress_impact = {
			arrogant = minor_stress_impact_loss
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = 0.5
				ai_rationality = 0.25
			}
		}
	}
	
	# Lazy: I am afraid I have too many pressing commitments...
	option = {
		name = diarchy.0021.c
		trigger = {
			is_ai = no
			has_trait = lazy
		}
		trait = lazy
		
		# Lose a bit of prestige.
		add_prestige = medium_prestige_loss
		# Aaaand off you go!
		depose_diarch = yes

		stress_impact = { lazy = massive_stress_impact_loss }
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = 0.5
				ai_rationality = 0.25
			}
		}
	}
}

#	Reset the cooldown on the intro event.
diarchy.0022 = {
	hidden = yes

	# We're just laundering this effect through an event so we can delay it be a day.
	immediate = { remove_character_flag = has_had_diarch_intro_event_flag }
}

#	Co-ruler maintenance.
diarchy.0023 = {
	hidden = yes

	immediate = {
		if = {
			limit = {
				has_diarchy_active_parameter = diarchy_is_co_rulership
				diarch.liege ?= root
			}
			diarch = { set_variable = use_co_ruler_title }
			# Plus, if we're a duumvirate of some kind, flag that too — we need to know for transfer logic..
			if = {
				limit = {
					OR = {
						has_diarchy_active_parameter = diarchy_type_is_junior_emperorship
						has_diarchy_active_parameter = diarchy_type_is_co_emperorship
					}
				}
				diarch = { set_variable = diarchy_transfer_type_duumvirate }
			}
		}
	}
}

#	Co-ruler is transferred via death.
diarchy.0024 = {
	hidden = yes

	immediate = {
		save_scope_as = new_holder
		# Toss our co-ruler to their new court if relevant.
		scope:co_ruler = {
			if = {
				limit = {
					is_courtier = yes
					NOT = { is_courtier_of = scope:new_holder }
				}
				set_employer = scope:new_holder
			}
		}
		switch = {
			trigger = scope:diarchy_type
			flag:junior_emperorship = {
				start_diarchy = junior_emperorship
				set_diarch = scope:co_ruler
				set_diarchy_swing = scope:sop_swing
			}
			flag:co_emperorship = {
				start_diarchy = co_emperorship
				set_diarch = scope:co_ruler
				set_diarchy_swing = scope:sop_swing
			}
			flag:co_monarchy = {
				start_diarchy = co_monarchy
				set_diarch = scope:co_ruler
				set_diarchy_swing = scope:sop_swing
			}
		}
	}
}

#	Co-ruler is transferred via anything except death.
diarchy.0025 = {
	hidden = yes

	trigger = {
		has_variable = co_ruler_to_transfer
		NOT = { var:co_ruler_to_transfer = scope:new_holder }
	}

	immediate = {
		# Toss our co-ruler to their new court if relevant.
		var:co_ruler_to_transfer = {
			if = {
				limit = {
					is_courtier = yes
					NOT = { is_courtier_of = scope:new_holder }
				}
				set_employer = scope:new_holder
			}
		}
		if = {
			limit = {
				var:co_ruler_to_transfer = {
					OR = {
						is_courtier_of = scope:new_holder
						is_vassal_of = scope:new_holder
					}
				}
			}
			if = {
				limit = {
					has_variable = diarchy_transfer_type_duumvirate
					var:co_ruler_to_transfer = { is_adult = no }
				}
				scope:new_holder = {
					start_diarchy = junior_emperorship
					set_diarch = root.var:co_ruler_to_transfer
				}
			}
			else_if = {
				limit = { has_variable = diarchy_transfer_type_duumvirate }
				scope:new_holder = {
					start_diarchy = co_emperorship
					set_diarch = root.var:co_ruler_to_transfer
				}
			}
			else = {
				start_diarchy = co_monarchy
				set_diarch = root.var:co_ruler_to_transfer
			}
		}
	}
}

##################################################
# Various Maintenance
# by Ewan Cowhig Croft
# 0101 - 0140
##################################################

# Mandate management.
diarchy.0101 = {
	hidden = yes

	trigger = {
		has_active_diarchy = yes
		# Because we were apparently occasionally catching gaps in diarch succession.
		exists = diarch
	}

	immediate = {
		# Decide what event pool to draw from.
		if = {
			limit = {
				# Filtering out landless lieges, since they're too much to control for.
				is_landed_or_landless_administrative = yes
				# Aaaand we don't want to give child diarchs mandate events.
				diarch = { is_adult = yes }
				# Or diarchs currently fighting their liege.
				NOT = { is_at_war_with = diarch }
			}
			diarch = {
				random_list = {
					100 = {
						trigger = { has_active_mandate = fill_coffers }
						trigger_event = { on_action = diarchy_mandate_fill_coffers_random }
					}
					100 = {
						trigger = { has_active_mandate = promote_authority }
						trigger_event = { on_action = diarchy_mandate_promote_authority_random }
					}
					100 = {
						trigger = { has_active_mandate = swell_armies }
						trigger_event = { on_action = diarchy_mandate_swell_armies_random }
					}
				}
			}
		}
		# And loop it in a bit.
		## Sometimes fast.
		if = {
			limit = { has_diarchy_active_parameter = mandate_tempo_fast }
			trigger_event = {
				id = diarchy.0101
				days = { 365 730 }
			}
		}
		## Sometimes slow.
		else_if = {
			limit = { has_diarchy_active_parameter = mandate_tempo_fast }
			trigger_event = {
				id = diarchy.0101
				days = { 730 1460 }
			}
		}
		# Give out manipulation hooks to landless diarchs.
		diarch = {
			if = {
				# Assuming they're not children.
				limit = { is_adult = yes }
				trigger_event = diarchy.0121
			}
		}
	}
}

# AI dismiss entrenched regencies.
diarchy.0111 = {
	hidden = yes

	trigger = {
		NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
		exists = diarch
		is_character_interaction_valid = {
			interaction = liege_dismiss_entrenched_regency_interaction
			recipient = diarch
		}
		# TIT-46565
		diarch = { is_ai = yes }
	}

	on_trigger_fail = { remove_character_flag = trying_to_dismiss_regent }

	immediate = {
		run_interaction = {
			interaction = liege_dismiss_entrenched_regency_interaction
			actor = root
			recipient = diarch
			execute_threshold = decline
		}
	}
}

# Everyone dismissing temporary regencies.
diarchy.0112 = {
	hidden = yes

	trigger = {
		exists = diarch
		is_character_interaction_valid = {
			interaction = liege_dismiss_temporary_regency_interaction
			recipient = diarch
		}
	}

	immediate = {
		run_interaction = {
			interaction = liege_dismiss_temporary_regency_interaction
			actor = root
			recipient = diarch
			execute_threshold = decline
		}
	}
}

# AI dismiss inherited entrenched regencies.
diarchy.0113 = {
	hidden = yes

	trigger = {
		is_ai = yes
		NOT = { has_character_flag = had_diarchy_0113 }
	}

	immediate = {
		# Are we in a suitable diarchy?
		if = {
			limit = { has_diarchy_active_parameter = diarchy_type_is_entrenched_regency }
			# Try to end the regency through the usual flow.
			trigger_event = {
				id = diarchy.0111
				months = { 1 3 }
			}
		}
		# Make sure that we don't re-fire the event constantly when inheriting many titles.
		add_character_flag = {
			flag = had_diarchy_0113
			days = 2
		}
	}
}

# Landless diarchs accrue hooks.
diarchy.0121 = {
	hidden = yes

	trigger = {
		liege ?= {
			any_vassal = {
				save_temporary_scope_as = char_temp
				# No players.
				is_ai = yes
				# Avoid anyone we've already got a hook on.
				NOR = {
					has_character_flag = landless_diarch_tried_to_ensnare_for_hook
					root = {
						any_hooked_character = { this = scope:char_temp }
					}
				}
				# Is a landed ruler.
				# Either a duke with at least two counties or a count - don't even consider trying it on with kings.
				is_landed_or_landless_administrative = yes
				OR = {
					AND = {
						highest_held_title_tier <= tier_duchy
						domain_size >= 2
					}
					highest_held_title_tier <= tier_county
				}
				# Plus avoid anyone we wouldn't want to target regardless.
				NOR = {
					should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
						ACTOR = root
						RECIPIENT = scope:char_temp
					}
					should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
						ACTOR = root
						RECIPIENT = scope:char_temp
					}
				}
			}
		}
	}	

	immediate = {
		# We don't want to give a manipulation hook during the first mandate event...
		if = {
			limit = {
				has_character_flag = landless_diarch_gains_manipulation_hooks
				# Do you have the right personality for skullduggery?
				NOR = {
					has_trait = just
					has_trait = content
					has_trait = honest
					ai_honor >= very_high_positive_ai_value
				}
				# Do you already have lots of hooks? If so, you should use those first.
				any_hooked_character = {
					count <= 6
					liege ?= root.liege
				}
			}
			# Right, now we can order some likely vassals.
			liege = {
				every_vassal = {
					limit = {
						# Save a temp scope, 'cause we'll be using it.
						save_temporary_scope_as = char_temp
						# No players.
						is_ai = yes
						# Avoid anyone we've already got a hook on.
						NOR = {
							has_character_flag = landless_diarch_tried_to_ensnare_for_hook
							root = {
								any_hooked_character = { this = scope:char_temp }
							}
						}
						# Is a landed ruler.
						# Either a duke with at least two counties or a count - don't even consider trying it on with kings.
						is_landed_or_landless_administrative = yes
						OR = {
							AND = {
								highest_held_title_tier <= tier_duchy
								domain_size >= 2
							}
							highest_held_title_tier <= tier_county
						}
						# Plus avoid anyone we wouldn't want to target regardless.
						NOR = {
							should_avoid_hostile_action_against_due_to_personal_relations_trigger = {
								ACTOR = root
								RECIPIENT = scope:char_temp
							}
							should_avoid_hostile_action_against_due_to_liege_relations_trigger = {
								ACTOR = root
								RECIPIENT = scope:char_temp
							}
						}
					}
					add_to_list = valid_hookable_vassals_list
				}
			}
			# Now that we have a list, let's select someone appropriate.
			ordered_in_list = {
				list = valid_hookable_vassals_list
				order_by = {
					value = intrigue
					multiply = -1
				}
				save_scope_as = best_candidate
			}
			# Finally, intrigue duel (weighted a bit in favour of the regent) to try and grab that hook.
			if = {
				limit = { exists = scope:best_candidate }
				duel = {
					skill = intrigue
					target = scope:best_candidate
					# Victory! A hook for the diarch.
					65 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = 3.5
							min = -49
						}
						# Gain a manipulation hook on 'em.
						add_hook = {
							type = manipulation_hook
							target = scope:best_candidate
						}
						# And a little strife opinion too.
						change_strife_opinion = minor_strife_gain
						# Plus some lost respect.
						reverse_add_opinion = {
							target = scope:best_candidate
							modifier = respect_opinion
							opinion = -20
						}
					}
					# Defeat! [sad trombone noises]
					35 = {
						compare_modifier = {
							value = scope:duel_value
							multiplier = -3.5
							min = -49
						}
						scope:best_candidate = {
							# Give scope:best_candidate immunity to fabrication for the duration-ish of a manipulation hook.
							add_character_flag = {
								flag = landless_diarch_tried_to_ensnare_for_hook
								years = 10
							}
							# Still lose _some_ respect.
							add_opinion = {
								target = root
								modifier = respect_opinion
								opinion = -10
							}
						}
					}
				}
			}
		}
		# ... so we set a flag that'll be required by the prior section if we don't have it.
		else = {
			add_character_flag = {
				flag = landless_diarch_gains_manipulation_hooks
				# Set the duration to be one more than the maximum length of the mandate event loop.
				days = 731
			}
		}
	}
}

# Dummy event to suppress some errors elsewhere.
diarchy.0131 = {
	hidden = yes
	orphan = yes

	immediate = {
		if = {
			limit = {
				exists = global_var:di_track_entr_stiffed_decline_recipient_list
				exists = global_var:di_track_imprison_veto_recipient_list
				exists = global_var:di_track_entr_piety_accept_actor_list
				exists = global_var:di_track_legmed_failure_recipient_list
				exists = global_var:di_track_entr_cash_accept_actor_list
				exists = global_var:di_track_entr_stiffed_accept_recipient_list
				exists = global_var:di_track_entr_unnecessary_accept_recipient_list
				exists = global_var:di_track_imprison_veto_intermediary_list
				exists = global_var:di_track_entr_dynpres_accept_recipient_list
				exists = global_var:di_track_imprison_accept_intermediary_list
				exists = global_var:di_track_desigme_accept_recipient_list
				exists = global_var:di_track_entr_hook_decline_recipient_list
				exists = global_var:di_track_entr_cash_decline_recipient_list
				exists = global_var:di_track_entrench_recipient_list
				exists = global_var:di_track_revoke_accept_actor_list
				exists = global_var:di_track_entr_piety_decline_actor_list
				exists = global_var:di_track_retract_decline_intermediary_list
				exists = global_var:di_track_revoke_reject_recipient_list
				exists = global_var:di_track_entr_dynpres_accept_actor_list
				exists = global_var:di_track_shiftpriv_failure_actor_list
				exists = global_var:di_track_revoke_veto_recipient_list
				exists = global_var:di_track_entr_hook_decline_actor_list
				exists = global_var:di_track_legmed_success_recipient_list
				exists = global_var:di_track_revoke_veto_intermediary_list
				exists = global_var:di_track_entr_hook_accept_actor_list
				exists = global_var:di_track_revoke_reject_intermediary_list
				exists = global_var:di_track_desigme_decline_recipient_list
				exists = global_var:di_track_retract_accept_recipient_list
				exists = global_var:di_track_imprison_decline_intermediary_list
				exists = global_var:di_track_retract_decline_recipient_list
				exists = global_var:di_track_swung_liege_list
				exists = global_var:di_track_entr_cash_accept_recipient_list
				exists = global_var:di_track_legmed_success_actor_list
				exists = global_var:di_track_revoke_accept_recipient_list
				exists = global_var:di_track_dismtemp_accept_actor_list
				exists = global_var:di_track_revoke_reject_actor_list
				exists = global_var:di_track_shiftpriv_success_actor_list
				exists = global_var:di_track_retract_veto_recipient_list
				exists = global_var:di_track_revoke_accept_intermediary_list
				exists = global_var:di_track_dismtemp_accept_recipient_list
				exists = global_var:di_track_desigme_decline_actor_list
				exists = global_var:di_track_imprison_accept_actor_list
				exists = global_var:di_track_imprison_veto_actor_list
				exists = global_var:di_track_desigme_accept_actor_list
				exists = global_var:di_track_retract_decline_actor_list
				exists = global_var:di_track_retract_accept_intermediary_list
				exists = global_var:di_track_entr_cash_decline_actor_list
				exists = global_var:di_track_imprison_decline_recipient_list
				exists = global_var:di_track_legmed_failure_actor_list
				exists = global_var:di_track_entr_stiffed_decline_actor_list
				exists = global_var:di_track_retract_veto_intermediary_list
				exists = global_var:di_track_shiftpriv_failure_recipient_list
				exists = global_var:di_track_swung_diarch_list
				exists = global_var:di_track_revoke_veto_actor_list
				exists = global_var:di_track_entr_dynpres_decline_actor_list
				exists = global_var:di_track_entr_unnecessary_accept_actor_list
				exists = global_var:di_track_imprison_decline_actor_list
				exists = global_var:di_track_retract_accept_actor_list
				exists = global_var:di_track_entrench_actor_list
				exists = global_var:di_track_entr_dynpres_decline_recipient_list
				exists = global_var:di_track_retract_veto_actor_list
				exists = global_var:di_track_entr_stiffed_accept_actor_list
				exists = global_var:di_track_shiftpriv_success_recipient_list
				exists = global_var:di_track_entr_hook_accept_recipient_list
				exists = global_var:di_track_imprison_accept_recipient_list
				exists = global_var:di_track_entr_piety_accept_recipient_list
				exists = global_var:di_track_entr_piety_decline_recipient_list
				exists = global_var:di_track_entr_stiffed_decline_recipient_list
				exists = global_var:di_track_imprison_veto_recipient_list
				exists = global_var:di_track_entr_piety_accept_actor_list
				exists = global_var:di_track_legmed_failure_recipient_list
				exists = global_var:di_track_entr_cash_accept_actor_list
				exists = global_var:di_track_entr_stiffed_accept_recipient_list
				exists = global_var:di_track_entr_unnecessary_accept_recipient_list
				exists = global_var:di_track_imprison_veto_intermediary_list
				exists = global_var:di_track_entr_dynpres_accept_recipient_list
				exists = global_var:di_track_imprison_accept_intermediary_list
				exists = global_var:di_track_desigme_accept_recipient_list
				exists = global_var:di_track_entr_hook_decline_recipient_list
				exists = global_var:di_track_entr_cash_decline_recipient_list
				exists = global_var:di_track_entrench_recipient_list
				exists = global_var:di_track_revoke_accept_actor_list
				exists = global_var:di_track_entr_piety_decline_actor_list
				exists = global_var:di_track_retract_decline_intermediary_list
				exists = global_var:di_track_revoke_reject_recipient_list
				exists = global_var:di_track_entr_dynpres_accept_actor_list
				exists = global_var:di_track_shiftpriv_failure_actor_list
				exists = global_var:di_track_revoke_veto_recipient_list
				exists = global_var:di_track_entr_hook_decline_actor_list
				exists = global_var:di_track_legmed_success_recipient_list
				exists = global_var:di_track_revoke_veto_intermediary_list
				exists = global_var:di_track_entr_hook_accept_actor_list
				exists = global_var:di_track_revoke_reject_intermediary_list
				exists = global_var:di_track_desigme_decline_recipient_list
				exists = global_var:di_track_retract_accept_recipient_list
				exists = global_var:di_track_imprison_decline_intermediary_list
				exists = global_var:di_track_retract_decline_recipient_list
				exists = global_var:di_track_swung_liege_list
				exists = global_var:di_track_entr_cash_accept_recipient_list
				exists = global_var:di_track_legmed_success_actor_list
				exists = global_var:di_track_revoke_accept_recipient_list
				exists = global_var:di_track_dismtemp_accept_actor_list
				exists = global_var:di_track_revoke_reject_actor_list
				exists = global_var:di_track_shiftpriv_success_actor_list
				exists = global_var:di_track_retract_veto_recipient_list
				exists = global_var:di_track_revoke_accept_intermediary_list
				exists = global_var:di_track_dismtemp_accept_recipient_list
				exists = global_var:di_track_desigme_decline_actor_list
				exists = global_var:di_track_imprison_accept_actor_list
				exists = global_var:di_track_imprison_veto_actor_list
				exists = global_var:di_track_desigme_accept_actor_list
				exists = global_var:di_track_retract_decline_actor_list
				exists = global_var:di_track_retract_accept_intermediary_list
				exists = global_var:di_track_entr_cash_decline_actor_list
				exists = global_var:di_track_imprison_decline_recipient_list
				exists = global_var:di_track_legmed_failure_actor_list
				exists = global_var:di_track_entr_stiffed_decline_actor_list
				exists = global_var:di_track_retract_veto_intermediary_list
				exists = global_var:di_track_shiftpriv_failure_recipient_list
				exists = global_var:di_track_swung_diarch_list
				exists = global_var:di_track_revoke_veto_actor_list
				exists = global_var:di_track_entr_dynpres_decline_actor_list
				exists = global_var:di_track_entr_unnecessary_accept_actor_list
				exists = global_var:di_track_imprison_decline_actor_list
				exists = global_var:di_track_retract_accept_actor_list
				exists = global_var:di_track_entrench_actor_list
				exists = global_var:di_track_entr_dynpres_decline_recipient_list
				exists = global_var:di_track_retract_veto_actor_list
				exists = global_var:di_track_entr_stiffed_accept_actor_list
				exists = global_var:di_track_shiftpriv_success_recipient_list
				exists = global_var:di_track_entr_hook_accept_recipient_list
				exists = global_var:di_track_imprison_accept_recipient_list
				exists = global_var:di_track_entr_piety_accept_recipient_list
				exists = global_var:di_track_entr_piety_decline_recipient_list
				exists = global_var:di_track_appviz_accept
				exists = global_var:di_track_appviz_accept_actor_list
				exists = global_var:di_track_appviz_accept_recipient_list
				exists = global_var:di_track_dismviz_accept
				exists = global_var:di_track_dismviz_accept_actor_list
				exists = global_var:di_track_dismviz_accept_recipient_list
				exists = global_var:di_track_vizmulct_accept
				exists = global_var:di_track_vizmulct_accept_actor_list
				exists = global_var:di_track_vizmulct_accept_recipient_list
				exists = global_var:di_track_appjunemp_accept
				exists = global_var:di_track_appjunemp_accept_actor_list
				exists = global_var:di_track_appjunemp_accept_recipient_list
				exists = global_var:di_track_appcoemp_accept
				exists = global_var:di_track_appcoemp_accept_actor_list
				exists = global_var:di_track_appcoemp_accept_recipient_list
				exists = global_var:di_track_appcomon_accept
				exists = global_var:di_track_appcomon_accept_actor_list
				exists = global_var:di_track_appcomon_accept_recipient_list
				var:struggle_involvement_defender ?= flag:interloper
			}
		}
	}
}

# To avoid unlanded regents becoming vassals of the liege's direct vassals, make sure the current liege remains the liege
diarchy.0141 = {
	hidden = yes

	immediate = {
		hidden_effect = {
			create_title_and_vassal_change = {
				type = revoked
				save_scope_as = title_change
			}
			change_liege = {
				liege = scope:intermediary
				change = scope:title_change
			}
			resolve_title_and_vassal_change = scope:title_change
		}
	}
}










##################################################
# SCHEMES

scripted_effect overthrow_regent_scheme_success_effect = {
	# Finish up the scheme.
	hidden_effect = {
		scope:scheme = { end_scheme = yes }
	}
	# Forcibly become diarch of scope:liege.
	scope:liege = { set_diarch = scope:owner }
	# Now handle the imprisonment.
	scope:owner = {
		# Kidnap scope:target.
		## Mark scope:target as unreleasable.
		scope:target = {
			set_variable = {
				name = imprisoned_by_diarch
				value = scope:owner
			}
		}
		## Landed characters take them directly.
		if = {
			limit = { is_landed_or_landless_administrative = yes }
			hard_imprison_character_effect = {
				TARGET = scope:target
				IMPRISONER = scope:owner
			}
		}
		## Landless characters boot them to their liege's dungeon.
		else = {
			hard_imprison_character_effect = {
				TARGET = scope:target
				IMPRISONER = scope:owner.liege
			}
		}
		# Gain a bunch of strife.
		change_strife_opinion = monumental_strife_gain
		# Both scope:target & scope:liege get criminal opinions on you.
		reverse_add_opinion = {
			target = scope:liege
			modifier = treasonous_usurped_my_diarch
		}
	}
}

scripted_effect overthrow_regent_scheme_failure_effect = {
	# Regardless, next time'll be harder.
	scope:target = {
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}

scripted_effect overthrow_regent_scheme_discovery_effect = {
	# If we know who's behind this, then there's some hurt feelings involved.
	if = {
		limit = { exists = scope:scheme_discovered }
		scope:owner = {
			# If successful, we give out harsher opinions.
			if = {
				limit = { exists = scope:scheme_successful }
				reverse_add_opinion = {
					modifier = treasonous_usurped_my_diarch
					target = scope:liege
				}
			}
			else = {
				# Otherwise, it's mild stuff.
				scope:owner = {
					reverse_add_opinion = {
						modifier = 	plotting_against_diarch_opinion
						target = scope:liege
					}
					reverse_add_opinion = {
						modifier = plotting_against_me_opinion
						target = scope:target
					}
				}
			}
		}
	}
}

##################################################
# Overthrow Diarch Scheme - Maintenance
# by Ewan Cowhig Croft
# 0501 - 0510
##################################################

#	Setup our rolls.
diarchy.0501 = {
	hidden = yes

	immediate = {
		# Start the process.
		add_character_flag = {
			flag = is_in_event_diarchy_0501
			days = 1
		}
		# Nab an extra scope for the liege, just to make loc and such a bit easier.
		scope:owner.liege = { save_scope_as = liege }
		# Roll for outcomes.
		## Success.
		random = {
			chance = scope:scheme.scheme_success_chance
			custom_tooltip = abduct_successful_roll_tt
			save_scope_value_as = {
				name = scheme_successful
				value = yes
			}
		}
		## Secrecy.
		random = {
			chance = {
				value = 100
				subtract = scope:scheme.scheme_secrecy
			}
			custom_tooltip = abduct_become_discovered_roll_tt
			save_scope_value_as = {
				name = scheme_discovered
				value = yes
			}
		}
		# Now, fire off our events.
		## Successful overthrow!
		if = {
			limit = { exists = scope:scheme_successful }
			# Ping out event messages.
			scope:owner = { trigger_event = diarchy.0551 }
			scope:liege = { trigger_event = diarchy.0561 }
			scope:target = { trigger_event = diarchy.0571 }
			# Run the actual effects.
			overthrow_regent_scheme_success_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
		## Unsuccessful overthrow!
		else = {
			# Ping out event messages.
			scope:owner = { trigger_event = diarchy.0511 }
			scope:liege = { trigger_event = diarchy.0521 }
			scope:target = { trigger_event = diarchy.0531 }
			# Run the actual effects.
			overthrow_regent_scheme_failure_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}
}

##################################################
# Overthrow Diarch Scheme - Failure
# by Ewan Cowhig Croft
# 0511 - 0550
##################################################

#	Scope:owner - scheme failed.
diarchy.0511 = {
	type = character_event
	title = diarchy.0511.t
	desc = {
		desc = diarchy.0511.desc.intro
		first_valid = {
			# Discovered.
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = diarchy.0511.desc.discovered
			}
			# Undiscovered.
			desc = diarchy.0511.desc.undiscovered
		}
		desc = diarchy.0511.desc.outro
	}
	theme = crown
	left_portrait = {
		character = scope:owner
		animation = disapproval
	}
	right_portrait = {
		character = scope:target
		animation = rage
	}
	lower_center_portrait = scope:liege
	override_background = { reference = corridor_night }

	immediate = {
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_failure_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}

	# Bah, this is pointless.
	option = {
		name = diarchy.0511.a

		scope:scheme = { end_scheme = yes }

		stress_impact = {
			fickle = miniscule_stress_impact_loss
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_energy = -1
				ai_vengefulness = -1
			}
		}
	}
	
	# Again. We'll get HerHim next time.
	option = {
		name = diarchy.0511.b

		play_music_cue = "mx_cue_stress"
		scope:scheme = { add_scheme_progress = -50 }

		stress_impact = {
			stubborn = miniscule_stress_impact_loss
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_energy = 1
				ai_vengefulness = 1
			}
		}
	}
}

# Scope:owner.liege - scheme failed.
diarchy.0521 = {
	type = letter_event
	opening = diarchy.0521.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = diarchy.0521.desc.discovered
			}
			desc = diarchy.0521.desc.undiscovered
		}
	}
	sender = scope:target

	immediate = {
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_failure_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}

	# I am aghast!
	option = {
		name = diarchy.0521.a
		trigger = { exists = scope:scheme_discovered }
	}

	# Concerning...
	option = {
		name = diarchy.0521.b
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
	}
}

#	Scope:target - scheme failed.
diarchy.0531 = {
	type = character_event
	title = diarchy.0531.t
	desc = {
		desc = diarchy.0531.desc.intro
		first_valid = {
			# Discovered.
			triggered_desc = {
				trigger = { exists = scope:scheme_discovered }
				desc = diarchy.0531.desc.discovered
			}
			# Undiscovered.
			desc = diarchy.0531.desc.undiscovered
		}
		desc = diarchy.0531.desc.outro
	}
	theme = crown
	left_portrait = {
		character = scope:target
		animation = rage
	}
	right_portrait = {
		character = scope:owner_revealed
		animation = disapproval
	}
	lower_center_portrait = scope:liege
	override_background = { reference = corridor_night }

	immediate = {
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_failure_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
		# Has scope:owner been revealed?
		if = {
			limit = { exists = scope:scheme_discovered }
			scope:owner = { save_scope_as = owner_revealed }
		}
	}

	# Missed me ya bastadds.
	option = {
		name = {
			text = {
				first_valid = {
					# Paranoid.
					triggered_desc = {
						trigger = { has_trait = paranoid }
						desc = diarchy.0531.a.paranoid
					}
					# Trusting.
					triggered_desc = {
						trigger = { has_trait = trusting }
						desc = diarchy.0531.a.trusting
					}
					# Scope:owner has been revealed.
					triggered_desc = {
						trigger = { exists = scope:scheme_discovered }
						desc = diarchy.0531.a.scheme_discovered
					}
					# Scope:owner is a secret.
					desc = diarchy.0531.a.scheme_secret
				}
			}
		}

		# Paranoid characters have their world view validated.
		if = {
			limit = { has_trait = paranoid }
			stress_impact = { base = minor_stress_impact_loss }
		}
		# Otherwise, use the regular block.
		else = {
			stress_impact = {
				base = minor_stress_impact_gain
				trusting = minor_stress_impact_gain
			}
		}
		ai_chance = {
			# No ai_chance needed for notification event.
			base = 1
		}
	}
}

##################################################
# Overthrow Diarch Scheme - Success
# by Ewan Cowhig Croft
# 0551 - 0590
##################################################

#	Scope:owner - scheme succeeded.
diarchy.0551 = {
	type = character_event
	title = diarchy.0551.t
	desc = diarchy.0551.desc
	theme = crown
	left_portrait = {
		character = scope:owner
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:target
		animation = fear
	}
	lower_center_portrait = scope:liege
	override_background = { reference = dungeon }

	immediate = {
		play_music_cue = "mx_cue_prison"
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_success_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}

	# Smooth as silk.
	option = {
		name = diarchy.0551.a

		# Yeaaahhh, Just isn't ok with this.
		stress_impact = { just = major_stress_impact_gain }
		ai_chance = {
			# No ai_chance needed for notification event.
			base = 1
		}
	}
}

# Scope:owner.liege - scheme succeeded.
diarchy.0561 = {
	type = letter_event
	opening = diarchy.0561.t
	desc = diarchy.0561.desc
	sender = scope:owner
	
	immediate = {
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_success_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}

	# It is what it is. For the moment.
	option = { name = diarchy.0561.a }
}

#	Scope:target - scheme succeeded.
diarchy.0571 = {
	type = character_event
	title = diarchy.0571.t
	desc = {
		desc = diarchy.0571.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { has_trait = blind }
				desc = diarchy.0571.desc.outro.blind
			}
			desc = diarchy.0571.desc.outro.sighted
		}
	}
	theme = crown
	left_portrait = {
		character = scope:target
		animation = fear
	}
	right_portrait = {
		character = scope:owner
		animation = schadenfreude
	}
	lower_center_portrait = scope:liege
	override_background = { reference = dungeon }

	immediate = {
		play_music_cue = "mx_cue_prison"
		# Actual effects happen further up in the chain.
		show_as_tooltip = {
			overthrow_regent_scheme_success_effect = yes
			overthrow_regent_scheme_discovery_effect = yes
		}
	}

	# Scope:liege will hear of this! GetSheHe'll hear!
	option = {
		name = diarchy.0571.a

		stress_impact = { base = medium_stress_impact_gain }
		ai_chance = {
			# No ai_chance needed for notification event.
			base = 1
		}
	}
}











##################################################
# MANDATES - GENERIC SCRIPTED TRIGGERS & EFFECTS

scripted_effect diarchy_mandates_refresh_liege_diarch_scopes_effect = {
	# First the liege.
	liege = { save_scope_as = liege }
	# Then just root (for tooltips).
	save_scope_as = diarch
}

scripted_effect diarchy_mandates_opt_out_apply_liege_disappointment_effect = {
	reverse_add_opinion = {
		modifier = disappointed_opinion
		target = scope:liege
		opinion = -10
	}
}











##################################################
# MANDATES - FILL COFFERS

##################################################
# Open Hearts, Open Pockets
# by Ewan Cowhig Croft
# 1201 - 1210
##################################################

scripted_trigger diarchy_1201_valid_exploitable_vassal_trigger = {
	# We use gold, and not short term gold, because we're not fussed about the AI's financial planning and to increase valid targets.
	gold >= liege.medium_gold_value
	# Add some general filters.
	is_available_ai_adult = yes
	NOR = {
		# Filter out anyone who's already had this event target them.
		has_character_flag = had_event_diarchy_1201_demand_recently
		# And remove root.
		this = root
	}
}

scripted_effect diarchy_1201_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1201.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_vassal
			# Transfer gold.
			scope:exploitable_vassal = {
				pay_short_term_gold = {
					target = scope:liege
					gold = scope:extra_tax
				}
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
	# Now we add some ancillary opinions.
	reverse_add_opinion = {
		modifier = angry_opinion
		target = scope:exploitable_vassal
		opinion = -30
	}
}

scripted_effect diarchy_1201_swing_resolve_stress_impact_effect = {
	stress_impact = {
		generous = medium_stress_impact_gain
		just = medium_stress_impact_gain
	}
}

#	Levy an extra tax from a wealthy co-vassal.
diarchy.1201 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1201.t
	}
	desc = diarchy.1201.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:diarch
		animation = disapproval
	}
	right_portrait = {
		character = scope:exploitable_vassal
		animation = anger
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Ensure there's a vassal with suitable wealth to tax
		liege = {
			any_vassal = { diarchy_1201_valid_exploitable_vassal_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Next, we nab a suitable vassal to demand gold from.
		scope:liege = {
			ordered_vassal = {
				limit = { diarchy_1201_valid_exploitable_vassal_trigger = yes }
				order_by = gold
				# Grab their scope.
				save_scope_as = exploitable_vassal
				# Filter them out from getting this for a while.
				add_character_flag = {
					flag = had_event_diarchy_1201_demand_recently
					years = 20
				}
			}
		}
		## Now finalise the gold costs.
		save_scope_value_as = {
			name = extra_tax
			value = scope:liege.medium_gold_value
		}
		save_scope_value_as = {
			name = split_tax
			value = {
				value = scope:extra_tax
				multiply = 0.5
			}
		}
	}

	# Resolve with Good Trait: tax them using your full authority.
	option = {
		name = diarchy.1201.a
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Apply success effects.
		diarchy_1201_successful_swing_resolve_effect = yes

		diarchy_1201_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1201_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to hike tax revenues blatantly.
	option = {
		name = diarchy.1201.b
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		duel = {
			skill = intrigue
			target = scope:exploitable_vassal
			# Success: tax for scope:liege!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1201.b.tt.success
				send_interface_toast = {
					title = diarchy.1201.b.tt.success
					left_icon = scope:exploitable_vassal
					# Apply success effects.
					diarchy_1201_successful_swing_resolve_effect = yes
				}
			}
			# Failure: no tax for anyone, just a bill.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1201.b.tt.failure
				send_interface_toast = {
					title = diarchy.1201.b.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1201.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.liege
							}
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = disgusted_opinion
						target = scope:exploitable_vassal
						opinion = -15
					}
				}
			}
		}

		diarchy_1201_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1201_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: agree to lesser taxes on subsidiary vassals in exchange for a kick-back.
	option = {
		name = diarchy.1201.c

		duel = {
			skill = intrigue
			target = scope:exploitable_vassal
			# Success: split the tax bill equally.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1201.c.tt.success
				send_interface_toast = {
					title = diarchy.1201.c.tt.success
					left_icon = scope:exploitable_vassal
					# Stuff that'll go to the liege via feed message.
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1201.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Transfer gold.
							scope:exploitable_vassal = {
								pay_short_term_gold = {
									target = scope:liege
									gold = scope:split_tax
								}
								pay_short_term_gold = {
									target = scope:diarch
									gold = scope:split_tax
								}
							}
							# Swing the scales & apply strife.
							update_diarchy_swing_with_perspective_effect = {
								SWING = minor_sop_swing_diarch_gain
								LIEGE = scope:liege
							}
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:exploitable_vassal
						opinion = -30
					}
					reverse_add_opinion = {
						modifier = disappointed_opinion
						target = scope:liege
						opinion = -5
					}
				}
			}
			# Failure: you get nothing and everyone's annoyed with you.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1201.c.tt.failure
				send_interface_toast = {
					title = diarchy.1201.c.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1201.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.split
							}
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = disgusted_opinion
						target = scope:exploitable_vassal
						opinion = -15
					}
					reverse_add_opinion = {
						modifier = disappointed_opinion
						target = scope:liege
						opinion = -10
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -0.5
			}
		}
	}

	# Opt Out with Bad Trait: refuse to put that strain on another vassal.
	option = {
		name = diarchy.1201.d
		trigger = { has_trait = generous }
		trait = generous

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1201.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:exploitable_vassal
			opinion = 20
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { generous = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: go for a walk in the sun instead.
	option = {
		name = diarchy.1201.e
		trigger = {
			NOT = { has_trait = generous }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1201.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:exploitable_vassal
			opinion = 20
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			base = minor_stress_loss
			generous = miniscule_stress_impact_loss
			just = miniscule_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 0.5
				ai_greed = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Terms & Conditions
# by Ewan Cowhig Croft
# 1211 - 1220
##################################################

scripted_trigger diarchy_1211_valid_exploitable_vassal_trigger = {
	# Does the vassal have a negotiable contract?
	government_has_flag = government_is_feudal
	vassal_contract_has_modifiable_obligations = yes
	# Add some general filters.
	is_available_ai_adult = yes
	NOR = {
		# Filter out anyone who's already had this event target them.
		has_character_flag = had_event_diarchy_1211_demand_recently
		# And remove root.
		this = root
	}
}

scripted_effect diarchy_1211_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1211.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_vassal
			# Boost obligations.
			scope:exploitable_vassal = {
				# If we can increase taxes, we go for them.
				if = {
					limit = { vassal_contract_obligation_level_can_be_increased = feudal_government_taxes }
					vassal_contract_increase_obligation_level = feudal_government_taxes
				}
				# Otherwise, it'll be levies.
				else_if = {
					limit = { vassal_contract_obligation_level_can_be_increased = feudal_government_levies }
					vassal_contract_increase_obligation_level = feudal_government_levies
				}
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = medium_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = major_strife_gain }
		}
	}
	# Now we add some ancillary opinions.
	reverse_add_opinion = {
		modifier = angry_opinion
		target = scope:exploitable_vassal
		opinion = -30
	}
}

scripted_effect diarchy_1211_swing_resolve_stress_impact_effect = {
	stress_impact = {
		arrogant = miniscule_stress_impact_loss
		shy = minor_stress_impact_gain
		just = major_stress_impact_gain
	}
}

#	Reinforce the fine points of a co-vassal's contract.
diarchy.1211 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1211.t
	}
	desc = diarchy.1211.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:diarch
		animation = throne_room_writer
	}
	right_portrait = {
		character = scope:exploitable_vassal
		animation = disgust
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Does the liege have a vassal whose contract they could reset?
		liege = {
			any_vassal = { diarchy_1211_valid_exploitable_vassal_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now find an appropriate vassal to increase the contract of.
		scope:liege = {
			random_vassal = {
				limit = { diarchy_1211_valid_exploitable_vassal_trigger = yes }
				# Grab their scope.
				save_scope_as = exploitable_vassal
				# Filter them out from getting this again in their lifetime.
				add_character_flag = had_event_diarchy_1211_demand_recently
			}
		}
	}

	# Resolve with Good Trait: strategically ignore the fine print that doesn't support your arguments.
	option = {
		name = diarchy.1211.a
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Apply success effects.
		diarchy_1211_successful_swing_resolve_effect = yes

		diarchy_1211_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1211_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: argue the terms of old oaths.
	option = {
		name = diarchy.1211.b
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		duel = {
			skill = learning
			target = scope:exploitable_vassal
			# Success: you squeeze a little extra blood from this stone.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1211.b.tt.success
				send_interface_toast = {
					title = diarchy.1211.b.tt.success
					left_icon = scope:exploitable_vassal
					# Apply success effects.
					diarchy_1211_successful_swing_resolve_effect = yes
				}
			}
			# Failure: SheHe is resolute.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1211.b.tt.failure
				send_interface_toast = {
					title = diarchy.1211.b.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1211.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.affect_contract.liege
							}
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = disgusted_opinion
						target = scope:exploitable_vassal
						opinion = -15
					}
				}
			}
		}

		diarchy_1211_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1211_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: agree to drop the subject in exchange for a meaningless extra homage and a kickback.
	option = {
		name = diarchy.1211.c

		duel = {
			skill = learning
			target = scope:exploitable_vassal
			# Success: SheHe accepts reluctantly.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1211.c.tt.success
				send_interface_toast = {
					title = diarchy.1211.c.tt.success
					left_icon = scope:exploitable_vassal
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1211.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Homage to scope:liege.
							add_prestige = minor_prestige_gain
							# Gold to scope:diarch.
							scope:exploitable_vassal = {
								pay_short_term_gold = {
									target = scope:diarch
									gold = scope:diarch.minor_gold_value
								}
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:exploitable_vassal
						opinion = -10
					}
				}
			}
			# Failure: SheHe is outraged!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1211.c.tt.failure
				send_interface_toast = {
					title = diarchy.1211.c.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1211.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.self
							}
							scope:diarch = { add_prestige = minor_prestige_loss }
						}
					}
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:exploitable_vassal
						opinion = -30
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	# Opt Out with Bad Trait: agree to give them the benefit of the doubt.
	option = {
		name = diarchy.1211.d
		trigger = { has_trait = generous }
		trait = generous

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1211.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:exploitable_vassal
			opinion = 20
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { generous = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: back down and abandon this line of inquiry.
	option = {
		name = diarchy.1211.e
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1211.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:exploitable_vassal
			opinion = 10
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			craven = miniscule_stress_impact_loss
			shy = minor_stress_impact_loss
			stubborn = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 0.75
				ai_honor = 0.5
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Your New Home
# by Ewan Cowhig Croft
# 1221 - 1230
##################################################

scripted_trigger diarchy_1221_valid_drainable_county_trigger = {
	tier = tier_county
	county_control >= medium_county_control
}

scripted_trigger diarchy_1221_valid_beneficiary_county_basics_trigger = {
	# Only counties, please.
	tier = tier_county
	# Filter out the capital.
	NOT = { this = scope:liege.capital_county }
}

scripted_effect diarchy_1221_drain_scope_actor_county_effect = {
	scope:actor_county = {
		change_county_control = major_county_control_loss
		change_development_progress = minimal_development_progress_loss
	}
}

scripted_effect diarchy_1221_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1221.a.t
			left_icon = scope:diarch
			right_icon = scope:recipient_county
			# Lose control and a _teensy_ bit of development progress in scope:actor_county.
			diarchy_1221_drain_scope_actor_county_effect = yes
			# Gain development progress in scope:recipient_county.
			scope:recipient_county = { change_development_progress = medium_development_progress_gain }
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
}

scripted_effect diarchy_1221_swing_resolve_stress_impact_effect = {
	stress_impact = {
		just = minor_stress_impact_gain
		compassionate = major_stress_impact_gain
	}
}

#	Resettle peasants from a rural county to an urban one.
diarchy.1221 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1221.t
	}
	desc = diarchy.1221.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:diarch
		animation = stress
	}
	right_portrait = {
		character = scope:liege
		animation = personality_greedy
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Root must have a suitable county.
		any_held_title = { diarchy_1221_valid_drainable_county_trigger = yes }
		# Liege must have at least two counties, as we want to buff something _other_ than their capital.
		liege = {
			any_held_title = {
				count >= 2
				tier = tier_county
			}
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now, we pick out the appropriate liege county.
		scope:liege = {
			ordered_held_title = {
				order_by = development_level
				# Try to nab a county that's the same culture as scope:liege...
				limit = {
					diarchy_1221_valid_beneficiary_county_basics_trigger = yes
					culture = scope:liege.culture
				}
				# ... but failing that, any will do.
				alternative_limit = { diarchy_1221_valid_beneficiary_county_basics_trigger = yes }
				save_scope_as = recipient_county
			}
		}
		## Finally, sort through the valid drainable counties.
		ordered_held_title = {
			# Find the most rural county we can.
			order_by = {
				value = development_level
				multiply = -1
			}
			# Now we want to try and nab a county that's the same culture as scope:recipient_county.
			limit = {
				diarchy_1221_valid_drainable_county_trigger = yes
				culture = scope:recipient_county.culture
			}
			# ... but we'll still accept any old county, tbh.
			alternative_limit = { diarchy_1221_valid_drainable_county_trigger = yes }
			save_scope_as = actor_county
		}
	}

	# Resolve with Good Trait: be brutal, but efficient, about the transfer.
	option = {
		name = diarchy.1221.a
		trigger = { has_trait = callous }
		trait = callous

		# Apply success effects.
		diarchy_1221_successful_swing_resolve_effect = yes

		diarchy_1221_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1221_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to offer decent endorsements for moving.
	option = {
		name = diarchy.1221.b
		trigger = {
			NOT = { has_trait = callous }
		}

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: financial inducements convince several ambitious families.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1221.b.tt.success
				send_interface_toast = {
					title = diarchy.1221.b.tt.success
					left_icon = scope:actor_county
					right_icon = scope:recipient_county
					# Apply success effects.
					diarchy_1221_successful_swing_resolve_effect = yes
					# Plus lose cash.
					remove_short_term_gold = minor_gold_value
				}
			}
			# Failure: the peasantry have to be forced to move at all.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1221.b.tt.failure
				send_interface_toast = {
					title = diarchy.1221.b.tt.failure
					left_icon = scope:actor_county
					right_icon = scope:recipient_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1221.b.t
							left_icon = scope:diarch
							right_icon = scope:recipient_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.harass_peasants.liege
							}
							# There's still some stress.
							scope:actor_county = { change_county_control = minor_county_control_loss }
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
		}

		diarchy_1221_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1221_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}

	# Resolve and Split Benefit: move some but agree to take bribes from the wealthiest serfs to stay put.
	option = {
		name = diarchy.1221.c

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: you make a tidy profit.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1221.c.tt.success
				send_interface_toast = {
					title = diarchy.1221.c.tt.success
					left_icon = scope:exploitable_vassal
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1221.c.t.success
							left_icon = scope:diarch
							right_icon = scope:recipient_county
							# Some gain...
							scope:recipient_county = { change_development_progress = minor_development_progress_gain }
							scope:diarch = { add_gold = minor_gold_value }
							# ... whilst others lose out.
							diarchy_1221_drain_scope_actor_county_effect = yes
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: your infamy spreads for such an offer.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1221.c.tt.failure
				send_interface_toast = {
					title = diarchy.1221.c.tt.failure
					left_icon = scope:diarch
					right_icon = scope:recipient_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1221.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.self
							}
							# There's still some stress.
							scope:actor_county = { change_county_control = minor_county_control_loss }
							# Plus people think you suck.
							scope:diarch = { add_prestige = medium_prestige_loss }
						}
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -0.5
			}
		}
	}

	# Opt Out with Bad Trait: spend the time counting your own peasantry rather than scope:liege's.
	option = {
		name = diarchy.1221.d
		flavor = diarchy.1221.d.tt
		trigger = { has_trait = greedy }
		trait = greedy

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1221.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { greedy = major_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: sit in the garden instead.
	option = {
		name = diarchy.1221.e
		trigger = {
			NOT = { has_trait = greedy }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1221.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_energy = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# In for a Penny
# by Ewan Cowhig Croft
# 1231 - 1240
##################################################

scripted_trigger diarchy_1231_valid_exploitable_county_trigger = {
	tier = tier_county
	NOR = {
		has_county_modifier = mandate_induced_fines_to_liege_modifier
		has_county_modifier = mandate_induced_fines_split_modifier
		has_county_modifier = mandate_fines_being_ignored_modifier
	}
}

scripted_effect diarchy_1231_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1231.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_county
			# A tithe is paid.
			add_gold = medium_gold_value
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
	# Plus the expected consequences.
	scope:exploitable_county = {
		add_county_modifier = {
			modifier = mandate_induced_fines_to_liege_modifier
			years = 10
		}
	}
}

scripted_effect diarchy_1231_swing_resolve_stress_impact_effect = {
	stress_impact = {
		impatient = miniscule_stress_impact_loss
		compassionate = medium_stress_impact_gain
		generous = major_stress_impact_gain
	}
}

#	Issue stricter criminal fines.
diarchy.1231 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1231.t
	}
	desc = diarchy.1231.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:diarch
		animation = stress
	}
	right_portrait = {
		character = scope:liege
		animation = steward
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		any_held_title = { diarchy_1231_valid_exploitable_county_trigger = yes }
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Nab a county to bully.
		random_held_title = {
			limit = { diarchy_1231_valid_exploitable_county_trigger = yes }
			save_scope_as = exploitable_county
		}
	}

	# Resolve with Good Trait: hike fines across the board recklessly.
	option = {
		name = diarchy.1231.a
		trigger = { has_trait = callous }
		trait = callous

		# Apply success effects.
		diarchy_1231_successful_swing_resolve_effect = yes

		diarchy_1231_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1231_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to hike fines in a way that'll earn extra cash without causing too many problems.
	option = {
		name = diarchy.1231.b
		trigger = {
			NOT = { has_trait = callous }
		}

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: you're able to skirt the worst of the complaints & raise the cash.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1231.b.tt.success
				send_interface_toast = {
					title = diarchy.1231.b.tt.success
					left_icon = scope:exploitable_county
					# Apply success effects.
					diarchy_1231_successful_swing_resolve_effect = yes
				}
			}
			# Failure: you're utterly ignored.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1231.b.tt.failure
				send_interface_toast = {
					title = diarchy.1231.b.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1231.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.liege
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# No one is paying attention to your demands.
					scope:exploitable_county = {
						add_county_modifier = {
							modifier = mandate_fines_being_ignored_modifier
							years = 10
						}
					}
				}
			}
		}

		diarchy_1231_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1231_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: try to take a cut of the extra money.
	option = {
		name = diarchy.1231.c

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: people don't grumble any more than they already were.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1231.c.tt.success
				send_interface_toast = {
					title = diarchy.1231.c.tt.success
					left_icon = scope:exploitable_county
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1231.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Transfer gold & apply county modifier.
							add_gold = minor_gold_value
							scope:exploitable_county = {
								add_county_modifier = {
									modifier = mandate_induced_fines_split_modifier
									years = 10
								}
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: your hypocrisy is called out.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1231.c.tt.failure
				send_interface_toast = {
					title = diarchy.1231.c.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1231.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.split
							}
							# Lose a fair ol' chunk o' prestige.
							scope:diarch = { add_prestige = medium_prestige_loss }
						}
					}
					# No one is paying attention to your demands.
					scope:exploitable_county = {
						add_county_modifier = {
							modifier = mandate_fines_being_ignored_modifier
							years = 10
						}
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_compassion = -1
			}
		}
	}

	# Opt Out with Bad Trait: lower and limit fines for the least fortunate.
	option = {
		name = diarchy.1231.d
		trigger = { has_trait = generous }
		trait = generous

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1231.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
				# Lowering a few fines does make you seem mildly more likeable.
				scope:diarch = { add_prestige = miniscule_prestige_gain }
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { generous = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: declare this outside of your remit.
	option = {
		name = diarchy.1231.e
		trigger = {
			NOT = { has_trait = generous }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1231.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			just = miniscule_stress_impact_loss
			generous = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.25
				ai_energy = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# A Taxing Subject
# by Ewan Cowhig Croft
# 1241 - 1250
##################################################

scripted_effect diarchy_1241_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1241.a.t
			left_icon = scope:diarch
			# The tax arrives.
			add_gold = scope:extra_tax
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = medium_strife_gain }
		}
	}
}

scripted_effect diarchy_1241_swing_resolve_stress_impact_effect = {
	stress_impact = {
		cynical = miniscule_stress_impact_loss
		compassionate = medium_stress_impact_gain
		zealous = major_stress_impact_gain
	}
}

#	Levy exempt institutions (churches in theocratic faiths, privileged burghers and charities in lay ones).
diarchy.1241 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1241.t
	}
	desc = diarchy.1241.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:diarch
		animation = paranoia
	}
	right_portrait = {
		character = scope:liege
		animation = personality_greedy
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now finalise the gold costs.
		save_scope_value_as = {
			name = extra_tax
			value = scope:liege.major_gold_value
		}
		save_scope_value_as = {
			name = split_tax
			value = {
				value = scope:extra_tax
				multiply = 0.5
			}
		}
	}

	# Resolve with Good Trait: ruthlessly tax the untaxed without regard for custom.
	option = {
		name = diarchy.1241.a
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Apply success effects.
		diarchy_1241_successful_swing_resolve_effect = yes

		diarchy_1241_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1241_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to justify these taxes as special exceptions.
	option = {
		name = diarchy.1241.b
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: there's much grumbling, but everything goes through.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1241.b.tt.success
				send_interface_toast = {
					title = diarchy.1241.b.tt.success
					# Apply success effects.
					diarchy_1241_successful_swing_resolve_effect = yes
				}
			}
			# Failure: you cause yourself a scandal.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1241.b.tt.failure
				send_interface_toast = {
					title = diarchy.1241.b.tt.failure
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1241.b.t
							left_icon = scope:diarch
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.liege
							}
							# People agree this was a bad idea.
							scope:diarch = { add_piety = medium_piety_loss }
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
		}

		diarchy_1241_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1241_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: try the same, but take a toll for your hard work.
	option = {
		name = diarchy.1241.c

		duel = {
			skill = stewardship
			value = high_skill_rating
			# Success: you manage to pull it off and make a tidy profit.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1241.c.tt.success
				send_interface_toast = {
					title = diarchy.1241.c.tt.success
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1241.c.t.success
							left_icon = scope:diarch
							# To you.
							add_gold = scope:split_tax
							# To me.
							scope:diarch = { add_gold = scope:split_tax }
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: you cause a _double_ scandal.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1241.c.tt.failure
				send_interface_toast = {
					title = diarchy.1241.c.tt.failure
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1241.c.t.failure
							left_icon = scope:diarch
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.split
							}
							# People criticise your double-abuse of power.
							scope:diarch = {
								add_piety = minor_piety_loss
								add_prestige = minor_prestige_loss
							}
						}
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_zeal = -1
			}
		}
	}

	# Opt Out with Bad Trait: quit the whole affair, knowing that you can't tax your own churches/charities like this.
	option = {
		name = diarchy.1241.d
		trigger = { has_trait = greedy }
		trait = greedy

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1241.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { greedy = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: back out, horrified at the impiety of such a proposition.
	option = {
		name = diarchy.1241.e
		trigger = {
			NOT = { has_trait = greedy }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1241.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			zealous = miniscule_stress_impact_loss
			cynical = minor_stress_impact_gain
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_zeal = 1
				ai_compassion = 1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}










##################################################
# MANDATES - PROMOTE AUTHORITY

##################################################
# The Right to Rule
# by Ewan Cowhig Croft
# 1701 - 1710
##################################################

scripted_trigger diarchy_1701_valid_powerful_councillor_guts_trigger = {
	is_available_ai_adult = yes
	is_powerful_vassal = yes
	NOR = {
		# People who wouldn't be yelling at a council meeting. Probably.
		has_trait = calm
		has_trait = shy
		has_trait = craven
		# Plus filter out root.
		this = root
	}
}

scripted_trigger diarchy_1701_valid_powerful_councillor_trigger = {
	# Basic checks first.
	diarchy_1701_valid_powerful_councillor_guts_trigger = yes
	# Now, for technical reasons it's difficult to pick two characters from the list who specifically hate each other, so instead we just make sure there's no one with any good relationship of another councillor who they might then roll.
	save_temporary_scope_as = char_temp
	root = {
		any_councillor = {
			diarchy_1701_valid_powerful_councillor_guts_trigger = yes
			NOR = {
				has_any_good_relationship_with_character_trigger = { CHARACTER = scope:char_temp }
				is_consort_of = scope:char_temp
			}
		}
	}
}

scripted_effect diarchy_1701_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1701.a.t
			left_icon = scope:councillor_1
			right_icon = scope:councillor_2
			# Tribes increase TA.
			if = {
				limit = { government_has_flag = government_is_tribal }
				increase_tribal_authority_effect = yes
			}
			# Everyone else increases CA.
			else = { increase_crown_authority_effect = yes }
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = medium_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = major_strife_gain }
		}
	}
}

scripted_effect diarchy_1701_swing_resolve_stress_impact_effect = {
	stress_impact = {
		gregarious = miniscule_stress_impact_loss
		shy = minor_stress_impact_gain
		wrathful = medium_stress_impact_gain
	}
}

scripted_effect diarchy_1701_councillors_argue_opinion_consequences_effect = {
	scope:councillor_1 = {
		add_opinion = {
			modifier = respect_opinion
			target = scope:councillor_2
			opinion = -20
		}
	}
	scope:councillor_2 = {
		add_opinion = {
			modifier = respect_opinion
			target = scope:councillor_1
			opinion = -20
		}
	}
}

#	Boost CA/TA by negotiating with powerful vassals.
diarchy.1701 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1701.t
	}
	desc = diarchy.1701.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:councillor_1
		animation = anger
	}
	right_portrait = {
		character = scope:councillor_2
		animation = personality_vengeful
	}
	lower_center_portrait = scope:diarch
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Make sure increasing the law is even possible.
		liege = {
			# Auto-out if they've had this event happen in the last 20 years.
			NOT = { has_character_flag = had_event_diarchy_1701_negotiation_recently }
			# Can they increase their authority?
			## Tribal characters.
			trigger_if = {
				limit = { government_has_flag = government_is_tribal }
				# Can never be done at maximum authority.
				NOT = { has_realm_law = tribal_authority_3 }
			}
			## Everyone else.
			trigger_else = {
				# Can never be done at maximum authority.
				NOT = { has_realm_law = crown_authority_3 }
				# And filter for technology.
				trigger_if = {
					limit = { has_realm_law = crown_authority_1 }
					culture = { has_innovation = innovation_royal_prerogative }
				}
			}
			# Make sure we've got at least a couple of vassals to check this through.
			any_councillor = {
				count >= 2
				diarchy_1701_valid_powerful_councillor_trigger = yes
			}
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Nab two suitable councillors.
		scope:liege = {
			ordered_councillor = {
				limit = { diarchy_1701_valid_powerful_councillor_trigger = yes }
				order_by = {
					value = diplomacy
					# If possible, we want firebrands first, but alternative limits 'cause problems so we just boost them up here.
					if = {
						limit = {
							OR = {
								has_trait = wrathful
								has_trait = gregarious
								has_trait = brave
								has_trait = ambitious
								has_trait = arrogant
								has_trait = impatient
							}
						}
						add = 1000
					}
				}
				max = 2
				check_range_bounds = no
				# First one.
				if = {
					limit = {
						NOT = { exists = scope:councillor_1 }
					}
					save_scope_as = councillor_1
				}
				# Then another.
				else_if = {
					limit = {
						NOT = {
							this = scope:councillor_1
							exists = scope:councillor_2
						}
					}
					save_scope_as = councillor_2
				}
			}
		}
		# Finally, put this event on cooldown for scope:liege for a *while*.
		scope:liege = {
			add_character_flag = {
				flag = had_event_diarchy_1701_negotiation_recently
				years = 20
			}
		}
	}

	# Resolve with Good Trait: keep things bubbling over at a civil pace.
	option = {
		name = diarchy.1701.a
		trigger = { has_trait = calm }
		trait = calm

		# Apply success effects.
		diarchy_1701_successful_swing_resolve_effect = yes

		diarchy_1701_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1701_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to mediate the dispute.
	option = {
		name = diarchy.1701.b
		trigger = {
			NOT = { has_trait = calm }
		}

		duel = {
			skill = diplomacy
			target = scope:councillor_1
			# Success: you make headway on all fronts.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1701.b.tt.success
				send_interface_toast = {
					title = diarchy.1701.b.tt.success
					left_icon = scope:councillor_1
					right_icon = scope:councillor_2
					# Apply success effects.
					diarchy_1701_successful_swing_resolve_effect = yes
				}
			}
			# Failure: the argument continues unabated.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1701.b.tt.failure
				send_interface_toast = {
					title = diarchy.1701.b.tt.failure
					left_icon = scope:councillor_1
					right_icon = scope:councillor_2
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1701.b.t
							left_icon = scope:councillor_1
							right_icon = scope:councillor_2
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.boost_authority.liege
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:councillor_1
						opinion = -10
					}
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:councillor_2
						opinion = -10
					}
				}
			}
		}

		diarchy_1701_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1701_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: side with the winning group.
	option = {
		name = diarchy.1701.c

		duel = {
			skill = diplomacy
			target = scope:councillor_1
			# Success: your contribution is welcomed.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1701.c.tt.success
				send_interface_toast = {
					title = diarchy.1701.c.tt.success
					left_icon = scope:councillor_1
					right_icon = scope:councillor_2
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1701.c.t.success
							left_icon = scope:councillor_1
							right_icon = scope:councillor_2
							# Dole out some prestige for settling the argument, albeit badly.
							add_prestige = minor_prestige_gain
							scope:diarch = { add_prestige = medium_prestige_gain }
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:councillor_2
						opinion = -40
					}
				}
			}
			# Failure: you're clearly a bootlick.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1701.c.tt.failure
				send_interface_toast = {
					title = diarchy.1701.c.tt.failure
					left_icon = scope:councillor_1
					right_icon = scope:councillor_2
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1701.c.t.failure
							left_icon = scope:councillor_1
							right_icon = scope:councillor_2
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.network.self
							}
							scope:diarch = { add_prestige = minor_prestige_loss }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:councillor_1
						opinion = -10
					}
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:councillor_2
						opinion = -10
					}
				}
			}
		}

		stress_impact = { just = minor_stress_impact_gain }
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_sociability = 0.25
			}
		}
	}

	# Opt Out with Bad Trait: fly into a rage.
	option = {
		name = diarchy.1701.d
		trigger = { has_trait = wrathful }
		trait = wrathful

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1701.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_1701_councillors_argue_opinion_consequences_effect = yes
		## Speedily add the councillors to a list so we can neatly give them opinion loss of you condensed down into a shorter tooltip.
		scope:councillor_1 = { add_to_list = affected_councillors_list }
		scope:councillor_2 = { add_to_list = affected_councillors_list }
		every_in_list = {
			list = affected_councillors_list
			custom = diarchy.1701.d.custom.both_councillors
			add_opinion = {
				target = scope:diarch
				modifier = reputation_opinion
				opinion = -20
			}
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { wrathful = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: quietly check out of the meeting whilst they scream at each other.
	option = {
		name = diarchy.1701.e
		trigger = {
			NOT = { has_trait = wrathful }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1701.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_1701_councillors_argue_opinion_consequences_effect = yes
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			shy = medium_stress_impact_loss
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -0.5
				ai_sociability = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Expiration Date
# by Ewan Cowhig Croft
# 1711 - 1720
##################################################

scripted_trigger diarchy_1711_valid_exploitable_vassal_trigger = {
	# First and foremost: have their obligations been changed (and thus could be changed again if we removed the cooldown)?
	vassal_contract_is_blocked_from_modification = yes
	# Plus make sure they're not going to immediately take advantage of this themselves.
	NOT = { has_hook = root.liege }
	# Add some general filters.
	is_available_ai_adult = yes
	NOR = {
		# Filter out anyone who's already had this event target them.
		has_character_flag = had_event_diarchy_1711_demand_recently
		# And remove root.
		this = root
	}
}

scripted_effect diarchy_1711_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1711.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_vassal
			scope:exploitable_vassal = { set_vassal_contract_modification_blocked = no }
			update_diarchy_swing_with_perspective_effect = {
				SWING = major_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = massive_strife_gain }
		}
	}
	# Now we add some ancillary opinions.
	## Mitigate the loss if scope:exploitable_vassal is legalistic by nature.
	scope:exploitable_vassal = {
		if = {
			limit = {
				faith = { has_doctrine_parameter = legalism_modified_law_costs }
			}
			add_opinion = {
				modifier = angry_opinion
				target = scope:diarch
				opinion = -30
			}
		}
		else = {
			add_opinion = {
				modifier = angry_opinion
				target = scope:diarch
				opinion = -60
			}
		}
	}
}

#	Exploit wording in a vassal contract to reset a cooldown.
diarchy.1711 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1711.t
	}
	desc = diarchy.1711.desc
	theme = stewardship_wealth_focus
	left_portrait = {
		character = scope:diarch
		animation = personality_cynical
	}
	right_portrait = {
		character = scope:exploitable_vassal
		animation = worry
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Does the liege have a vassal whose contract could be increased?
		liege = {
			any_vassal = { diarchy_1711_valid_exploitable_vassal_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now find an appropriate vassal to reset the cooldown for.
		scope:liege = {
			random_vassal = {
				# Try to nab vassals whose contracts scope:liege could safely change immediately.
				limit = {
					save_temporary_scope_as = vassal_temp
					scope:liege = { has_hook = scope:vassal_temp }
					diarchy_1711_valid_exploitable_vassal_trigger = yes
				}
				alternative_limit = { diarchy_1711_valid_exploitable_vassal_trigger = yes }
				# Grab their scope.
				save_scope_as = exploitable_vassal
				# Filter them out from getting this again in their lifetime.
				add_character_flag = had_event_diarchy_1711_demand_recently
			}
		}
	}

	# Resolve with Good Trait: fall back on your reputation for legality.
	option = {
		name = diarchy.1711.a
		trigger = { has_trait = just }
		trait = just

		# Apply success effects.
		diarchy_1711_successful_swing_resolve_effect = yes

		stress_impact = { deceitful = minor_stress_impact_gain }
		ai_chance = {
			base = 10
			diarchy_1711_swing_resolve_ai_value_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to win the argument.
	option = {
		name = diarchy.1711.b
		trigger = {
			NOT = { has_trait = just }
		}

		duel = {
			skill = learning
			target = scope:exploitable_vassal
			# Success: your legal theory is indisputable.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1711.b.tt.success
				send_interface_toast = {
					title = diarchy.1711.b.tt.success
					left_icon = scope:exploitable_vassal
					# Apply success effects.
					diarchy_1711_successful_swing_resolve_effect = yes
				}
			}
			# Failure: the gaps in your argument are obvious.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1711.b.tt.failure
				send_interface_toast = {
					title = diarchy.1711.b.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1711.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.affect_contract.liege
							}
							scope:diarch = { change_strife_opinion = medium_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = dismissive_opinion
						target = scope:exploitable_vassal
						opinion = -20
					}
				}
			}
		}

		stress_impact = { honest = minor_stress_impact_gain }
		ai_chance = {
			base = 10
			diarchy_1711_swing_resolve_ai_value_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: agree to drop the offending wording for a kickback.
	option = {
		name = diarchy.1711.c

		duel = {
			skill = learning
			target = scope:exploitable_vassal
			# Success: you obtain the promised bribes!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1711.c.tt.success
				send_interface_toast = {
					title = diarchy.1711.c.tt.success
					left_icon = scope:exploitable_vassal
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1711.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Fork out some gold.
							scope:exploitable_vassal = {
								pay_short_term_gold = {
									target = scope:liege
									gold = minor_gold_value
								}
								pay_short_term_gold = {
									target = scope:diarch
									gold = minor_gold_value
								}
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:exploitable_vassal
						opinion = -20
					}
				}
			}
			# Failure: the realm hears of your dishonesty.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1711.c.tt.failure
				send_interface_toast = {
					title = diarchy.1711.c.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1711.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.self
							}
							# That'll be a bit of lost rep for scope:diarch.
							scope:diarch = { add_prestige = minor_prestige_loss }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:exploitable_vassal
						opinion = -10
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -1
			}
		}
	}

	# Opt Out with Bad Trait: get angry and ignore the contract's contents.
	option = {
		name = diarchy.1711.d
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1711.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = respect_opinion
			target = scope:exploitable_vassal
			opinion = -20
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { arbitrary = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: back down from the discussion.
	option = {
		name = diarchy.1711.e
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1711.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:exploitable_vassal
			opinion = 10
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			shy = miniscule_stress_impact_loss
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = 0.25
				ai_sociability = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Settling Grievances
# by Ewan Cowhig Croft
# 1721 - 1730
##################################################

scripted_trigger diarchy_1721_valid_exploitable_vassal_trigger = {
	# Has to be in a faction...
	OR = {
		is_a_faction_leader = yes
		is_a_faction_member = yes
	}
	# ... _and_ be able to leave that faction.
	is_forced_into_faction = no
	joined_faction = { faction_is_at_war = no }
	# Ensure there's some degree of believability.
	NOR = {
		has_any_bad_relationship_with_character_trigger = { CHARACTER = root.liege }
		opinion = {
			target = root.liege
			value <= high_negative_opinion
		}
		# Event narrative needs us to filter out certain traits.
		has_trait = arbitrary
		has_trait = brave
	}
	# Plus isn't root & hasn't had the event recently-ish.
	NOR = {
		this = root
		has_character_flag = had_event_diarchy_1721_demand_recently
	}
	# Finally, ensure this character can be hooked by scope:diarch.
	save_temporary_scope_as = faction_member_temp
	scope:diarch = {
		can_add_hook = {
			target = scope:faction_member_temp
			type = indebted_hook
		}
	}
}

scripted_effect diarchy_1721_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1721.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_vassal
			# Boot scope:exploitable_vassal from the faction.
			leave_faction_with_cooldown_effect = {
				FACTION = scope:exploitable_vassal.joined_faction
				YEARS = 10
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = major_strife_gain }
		}
	}
}

#	Negotiate a powerful character out of a faction.
diarchy.1721 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1721.t
	}
	desc = diarchy.1721.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:diarch
		animation = admiration
	}
	right_portrait = {
		character = scope:exploitable_vassal
		animation = personality_bold
	}
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# There's gotta be someone in a faction to negotiate with.
		liege = {
			any_vassal = { diarchy_1721_valid_exploitable_vassal_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Pick a vassal to lever out of a faction.
		scope:liege = {
			ordered_vassal = {
				order_by = {
					value = current_military_strength
					# Now we want to weight up or down according to the state of their faction.
					joined_faction = {
						# Modify weighting according to relative power threshold.
						## Minimal: ~25% power.
						if = {
							limit = { faction_power <= faction_power_minimal }
							multiply = 0.2
						}
						## Halfway: ~50% power.
						else_if = {
							limit = { faction_power <= faction_power_halfway_threshold }
							multiply = 0.5
						}
						## Pushing: ~75% power.
						else_if = {
							limit = { faction_power <= faction_power_pushing_threshold }
							multiply = 0.8
						}
						# Weight up massively if that faction could press demands.
						if = {
							limit = { faction_can_press_demands = yes }
							multiply = 5
						}
					}
				}
				limit = { diarchy_1721_valid_exploitable_vassal_trigger = yes }
				# Grab their scope.
				save_scope_as = exploitable_vassal
				# Stop such a negotiation repeating for a while.
				add_character_flag = {
					flag = had_event_diarchy_1721_demand_recently
					years = 10
				}
			}
		}
	}

	# Resolve with Good Trait: remind them of the bonds of duty and honour.
	option = {
		name = diarchy.1721.a
		trigger = { has_trait = just }
		trait = just

		# Apply success effects.
		diarchy_1721_successful_swing_resolve_effect = yes

		stress_impact = { shy = miniscule_stress_impact_gain }
		ai_chance = {
			base = 10
			diarchy_1721_swing_resolve_ai_value_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: point out how things would go for them personally if things turned violent.
	option = {
		name = diarchy.1721.b
		trigger = {
			NOT = { has_trait = just }
		}

		duel = {
			skill = martial
			target = scope:exploitable_vassal
			# Success: you cow them.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1721.b.tt.success
				send_interface_toast = {
					title = diarchy.1721.b.tt.success
					left_icon = scope:exploitable_vassal
					# Apply success effects.
					diarchy_1721_successful_swing_resolve_effect = yes
				}
			}
			# Failure: SheHe stands resolute.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1721.b.tt.failure
				send_interface_toast = {
					title = diarchy.1721.b.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1721.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.affect_faction.liege
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = respect_opinion
						target = scope:exploitable_vassal
						opinion = -20
					}
				}
			}
		}

		stress_impact = { humble = miniscule_stress_impact_gain }
		ai_chance = {
			base = 10
			diarchy_1721_swing_resolve_ai_value_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: agree to look the other way for a favour. Or else.
	option = {
		name = diarchy.1721.c

		duel = {
			skill = martial
			target = scope:exploitable_vassal
			# Success: a binding promise is given.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1721.c.tt.success
				send_interface_toast = {
					title = diarchy.1721.c.tt.success
					left_icon = scope:exploitable_vassal
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1721.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Some prestige for scope:liege.
							add_prestige = minor_prestige_gain
							# And a hook for scope:diarch.
							scope:diarch = {
								add_hook = {
									type = indebted_hook
									target = scope:exploitable_vassal
								}
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:exploitable_vassal
						opinion = -15
					}
				}
			}
			# Failure: they add you to their list.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1721.c.tt.failure
				send_interface_toast = {
					title = diarchy.1721.c.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1721.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.network.self
							}
							# Strife amongst the vassals!
							scope:exploitable_vassal = {
								reverse_add_opinion = {
									modifier = angry_opinion
									target = scope:diarch
									opinion = -30
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			honest = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -0.25
			}
		}
	}

	# Opt Out with Bad Trait: agree with them that might makes right.
	option = {
		name = diarchy.1721.d
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1721.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:exploitable_vassal
			opinion = 20
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { arbitrary = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: feign that this was just a social visit.
	option = {
		name = diarchy.1721.e
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1721.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = pleased_opinion
			target = scope:exploitable_vassal
			opinion = 10
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			honest = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_boldness = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Settling Accounts
# by Ewan Cowhig Croft
# 1731 - 1740
##################################################

scripted_trigger diarchy_1731_valid_exploitable_county_trigger = {
	# First, we filter out factions that can't be negotiated with for obvious reasons.
	faction_is_at_war = no
	# Nab the faction for checking purposes.
	save_temporary_scope_as = faction_temp
	# We need a certain amount of county members, so first we check how many there are total to early-out invalid factions before doing expensive neighbouring checks.
	any_faction_county_member = {
		count >= 3
		# Also try to make sure they don't *ragingly* hate liege.
		county_opinion >= diarchy_1731_minimum_county_opinion_value
	}
	# Now we check whether the three counties border at least one of the other counties, so that we've got a nice lil clump.
	any_faction_county_member = {
		diarchy_1731_core_exploitable_county_trigger = { FACTION = scope:faction_temp }
	}
}

scripted_trigger diarchy_1731_core_exploitable_county_trigger = {
	county_opinion >= diarchy_1731_minimum_county_opinion_value
	# We don't need to check in sequence, since we know that one county will always need to border two for there to be a chain, so we just look for that.
	any_connected_county = {
		count >= 2
		any_title_joined_faction = { this = $FACTION$ }
		county_opinion >= diarchy_1731_minimum_county_opinion_value
	}
}

scripted_effect diarchy_1731_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1731.a.t
			left_icon = scope:diarch
			right_icon = scope:county_1
			# Remove the affected counties from the faction.
			## Obscure things for neater tooltips, since an every_in_list won't work correctly with the title_leave_faction effect.
			hidden_effect =  {
				scope:county_1 = { title_leave_faction = scope:faction }
				scope:county_2 = { title_leave_faction = scope:faction }
				scope:county_3 = { title_leave_faction = scope:faction }
			}
			custom_tooltip = diarchy_1731.tt.affected_counties_removed
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
}

scripted_effect diarchy_1731_swing_resolve_stress_impact_effect = {
	stress_impact = {
		gregarious = miniscule_stress_impact_loss
		humble = miniscule_stress_impact_loss
		shy = minor_stress_impact_gain
		arrogant = major_stress_impact_gain
	}
}

#	Negotiate a group of counties out of a faction.
diarchy.1731 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1731.t
	}
	desc = diarchy.1731.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:diarch
		animation = worry
	}
	right_portrait = {
		character = scope:misc_peasant
		animation = aggressive_sword
		hide_info = yes
	}
	# All-Thing cultures meet at the stones.
	override_background = {
		trigger = {
			culture = { has_innovation = innovation_all_things }
		}
		reference = council_chamber
	}
	# Everyone else in the town square.
	override_background = {
		trigger = {
			NOT = {
				culture = { has_innovation = innovation_all_things }
			}
		}
		reference = market_scope
	}

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# There's gotta be a county to negotiate with.
		liege = {
			any_targeting_faction = { diarchy_1731_valid_exploitable_county_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now we're gotta pick some counties!
		scope:liege = {
			random_targeting_faction = {
				limit = { diarchy_1731_valid_exploitable_county_trigger = yes }
				# Save the faction for checking purposes.
				save_scope_as = faction
				# Ok, now we've got a valid faction, we want to pick three connected counties within it.
				## Nab our ringleader county.
				random_faction_county_member = {
					limit = {
						diarchy_1731_core_exploitable_county_trigger = { FACTION = scope:faction }
					}
					save_scope_as = county_1
				}
				## Then our secondary county.
				scope:county_1 = {
					random_connected_county = {
						limit = {
							county_opinion >= diarchy_1731_minimum_county_opinion_value
							any_title_joined_faction = { this = scope:faction }
						}
						save_scope_as = county_2
					}
				}
				## And our third county.
				scope:county_1 = {
					random_connected_county = {
						limit = {
							county_opinion >= diarchy_1731_minimum_county_opinion_value
							any_title_joined_faction = { this = scope:faction }
							NOT = { this = scope:county_2 }
						}
						save_scope_as = county_3
					}
				}
			}
		}
		## Finally, sort our background scope.
		scope:county_1.title_province = { save_scope_as = background_market_scope }
	}

	# Resolve with Good Trait: listen to their problems one by one.
	option = {
		name = diarchy.1731.a
		trigger = { has_trait = calm }
		trait = calm

		# Apply success effects.
		diarchy_1731_successful_swing_resolve_effect = yes

		diarchy_1731_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1731_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to mediate with the group as a whole.
	option = {
		name = diarchy.1731.b
		trigger = {
			NOT = { has_trait = calm }
		}

		duel = {
			skill = diplomacy
			value = high_skill_rating
			# Success: you soothe their tempers.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1731.b.tt.success
				send_interface_toast = {
					title = diarchy.1731.b.tt.success
					left_icon = scope:county_1
					# Apply success effects.
					diarchy_1731_successful_swing_resolve_effect = yes
				}
			}
			# Failure: you're pelted with rotten produce.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1731.b.tt.failure
				send_interface_toast = {
					title = diarchy.1731.b.tt.failure
					left_icon = scope:county_1
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1731.b.t
							left_icon = scope:diarch
							right_icon = scope:county_1
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.harass_peasants.liege
							}
							# Your standing takes a bit of a hit.
							scope:diarch = { add_prestige = minor_prestige_loss }
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
		}

		diarchy_1731_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1731_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: hear their grievances but try to increase your own standing.
	option = {
		name = diarchy.1731.c

		duel = {
			skill = diplomacy
			value = high_skill_rating
			# Success: clearly you're a champion of the people.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1731.c.tt.success
				send_interface_toast = {
					title = diarchy.1731.c.tt.success
					left_icon = scope:county_1
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1731.c.t.success
							left_icon = scope:diarch
							right_icon = scope:county_1
							# Split some prestige together.
							add_prestige = minor_prestige_gain
							scope:diarch = { add_prestige = medium_prestige_gain }
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: this isn't about *you*.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1731.c.tt.failure
				send_interface_toast = {
					title = diarchy.1731.c.tt.failure
					left_icon = scope:county_1
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1731.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:county_1
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.network.self
							}
							scope:diarch = { add_prestige = medium_prestige_loss }
						}
					}
				}
			}
		}

		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			humble = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_compassion = 0.5
			}
		}
	}

	# Opt Out with Bad Trait: scream at the throng.
	option = {
		name = diarchy.1731.d
		trigger = { has_trait = wrathful }
		trait = wrathful

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1731.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# How embarrassing!
		add_prestige = minor_prestige_loss
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { wrathful = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: make perfunctory promises and leave.
	option = {
		name = diarchy.1731.e
		trigger = {
			NOT = { has_trait = wrathful }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1731.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			shy = miniscule_stress_impact_loss
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = -0.5
				ai_sociability = -0.75
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Look at it this Way
# by Ewan Cowhig Croft
# 1741 - 1750
##################################################

scripted_trigger diarchy_1741_valid_exploitable_councillor_trigger = {
	# Opinion must be low, but not _too_ low.
	opinion = {
		target = liege
		value <= medium_positive_opinion
	}
	opinion = {
		target = liege
		value >= high_negative_opinion
	}
	# Plus some standard checks.
	is_available_ai_adult = yes
	NOT = { this = root }
}

scripted_effect diarchy_1741_give_opinion_from_councillors_effect = {
	$TARGET$ = {
		if = {
			limit = {
				any_in_list = {
					list = affected_councillors_list
					count >= 2
				}
			}
			every_in_list = {
				list = affected_councillors_list
				custom = diarchy.1741.custom.several_councillors
				add_opinion = {
					target = $TARGET$
					modifier = respect_opinion
					opinion = $OPINION$
				}
			}
		}
		else = {
			reverse_add_opinion = {
				target = scope:councillor_1
				modifier = respect_opinion
				opinion = $OPINION$
			}
		}
	}
}

scripted_effect diarchy_1741_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.1741.a.t
			left_icon = scope:diarch
			right_icon = scope:councillor_1
			# Dish out some bonus opinion.
			diarchy_1741_give_opinion_from_councillors_effect = {
				TARGET = scope:liege
				OPINION = 30
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = medium_strife_gain }
		}
	}
}

scripted_effect diarchy_1741_swing_resolve_stress_impact_effect = {
	stress_impact = {
		gregarious = miniscule_stress_impact_loss
		content = minor_stress_impact_loss
		ambitious = minor_stress_impact_gain
	}
}

#	Boost the opinion council members have of their liege.
diarchy.1741 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.1741.t
	}
	desc = diarchy.1741.desc
	theme = diplomacy_foreign_affairs_focus
	left_portrait = {
		character = scope:diarch
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:councillor_1
		animation = personality_rational
	}
	# Fill out either end, starting with the furthest away (since we're being lightly adversasrial), _then_ do the centre.
	lower_left_portrait = scope:councillor_3
	lower_center_portrait = scope:councillor_4
	lower_right_portrait = scope:councillor_2
	override_background = { reference = council_chamber }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# A few councillors must be available to suck up to.
		liege = {
			any_councillor = {
				count >= 2
				diarchy_1741_valid_exploitable_councillor_trigger = yes
			}
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Now we want to try and nab some councillors.
		scope:liege = {
			ordered_councillor = {
				limit = { diarchy_1741_valid_exploitable_councillor_trigger = yes }
				# We want to try and keep this challenging, so order by diplomacy.
				order_by = {
					value = diplomacy
					# But alternative limits throw a fit and we *prefer* someone confrontational, so weight that up.
					if = {
						limit = {
							NOR = {
								has_trait = compassionate
								has_trait = shy
								has_trait = craven
								has_trait = fickle
								opinion = {
									target = scope:diarch
									value >= medium_positive_opinion
								}
							}
						}
						add = 1000
					}
				}
				# We can please up to x4.
				max = 4
				check_range_bounds = no
				## Councillor #1.
				if = {
					limit = {
						NOT = { exists = scope:councillor_1 }
					}
					save_scope_as = councillor_1
					# Keep 'em in a list so we can refer to 'em easily in one of the later options.
					add_to_list = affected_councillors_list
				}
				## Councillor #2.
				else_if = {
					limit = {
						NOT = {
							this = scope:councillor_1
							exists = scope:councillor_2
						}
					}
					save_scope_as = councillor_2
					# Keep 'em in a list so we can refer to 'em easily in one of the later options.
					add_to_list = affected_councillors_list
				}
				## Councillor #3.
				else_if = {
					limit = {
						NOT = {
							this = scope:councillor_1
							this = scope:councillor_2
							exists = scope:councillor_3
						}
					}
					save_scope_as = councillor_3
					# Keep 'em in a list so we can refer to 'em easily in one of the later options.
					add_to_list = affected_councillors_list
				}
				## Councillor #4.
				else_if = {
					limit = {
						NOT = {
							this = scope:councillor_1
							this = scope:councillor_2
							this = scope:councillor_3
							exists = scope:councillor_4
						}
					}
					save_scope_as = councillor_4
					# Keep 'em in a list so we can refer to 'em easily in one of the later options.
					add_to_list = affected_councillors_list
				}
			}
		}
	}

	# Resolve with Good Trait: talk through the many benefits of working *with* scope:liege.
	option = {
		name = diarchy.1741.a
		trigger = { has_trait = calm }
		trait = calm

		# Apply success effects.
		diarchy_1741_successful_swing_resolve_effect = yes

		diarchy_1741_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1741_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to bring them round to your point of view.
	option = {
		name = diarchy.1741.b
		trigger = {
			NOT = { has_trait = calm }
		}

		duel = {
			skill = diplomacy
			target = scope:councillor_1
			# Success: you make decent headway.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1741.b.tt.success
				send_interface_toast = {
					title = diarchy.1741.b.tt.success
					left_icon = scope:councillor_1
					# Apply success effects.
					diarchy_1741_successful_swing_resolve_effect = yes
				}
			}
			# Failure: what a lapdog you are!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1741.b.tt.failure
				send_interface_toast = {
					title = diarchy.1741.b.tt.failure
					left_icon = scope:councillor_1
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1741.b.t
							left_icon = scope:diarch
							right_icon = scope:councillor_1
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.boost_authority.liege
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Now we add some ancillary opinions.
					if = {
						limit = {
							any_in_list = {
								list = affected_councillors_list
								count >= 2
							}
						}
						every_in_list = {
							list = affected_councillors_list
							custom = diarchy.1741.custom.several_councillors
							add_opinion = {
								target = scope:diarch
								modifier = respect_opinion
								opinion = -10
							}
						}
					}
					else = {
						reverse_add_opinion = {
							target = scope:councillor_1
							modifier = respect_opinion
							opinion = -10
						}
					}
				}
			}
		}

		diarchy_1741_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_1741_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: try to curry favour with them personally.
	option = {
		name = diarchy.1741.c

		duel = {
			skill = diplomacy
			target = scope:councillor_1
			# Success: you *are* a charming fellow.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.1741.c.tt.success
				send_interface_toast = {
					title = diarchy.1741.c.tt.success
					left_icon = scope:councillor_1
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1741.c.t.success
							left_icon = scope:diarch
							right_icon = scope:councillor_1
							# Dish out some bonus opinion.
							diarchy_1741_give_opinion_from_councillors_effect = {
								TARGET = scope:liege
								OPINION = 10
							}
							# Dish out some bonus opinion.
							diarchy_1741_give_opinion_from_councillors_effect = {
								TARGET = scope:diarch
								OPINION = 30
							}
						}
					}
				}
			}
			# Failure: how self-serving!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.1741.c.tt.failure
				send_interface_toast = {
					title = diarchy.1741.c.tt.failure
					left_icon = scope:councillor_1
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.1741.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:councillor_1
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.network.self
							}
							# Dish out some bonus opinion.
							diarchy_1741_give_opinion_from_councillors_effect = {
								TARGET = scope:diarch
								OPINION = -20
							}
						}
					}
				}
			}
		}

		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			gregarious = miniscule_stress_impact_loss
			shy = minor_stress_impact_gain
			honest = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_honor = -0.5
			}
		}
	}

	# Opt Out with Bad Trait: get mad at them for impugning the honour of your office.
	option = {
		name = diarchy.1741.d
		trigger = { has_trait = wrathful }
		trait = wrathful

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1741.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		if = {
			limit = {
				any_in_list = {
					list = affected_councillors_list
					count >= 2
				}
			}
			every_in_list = {
				list = affected_councillors_list
				custom = diarchy.1741.custom.several_councillors
				add_opinion = {
					target = scope:diarch
					modifier = respect_opinion
					opinion = -20
				}
			}
		}
		else = {
			reverse_add_opinion = {
				target = scope:councillor_1
				modifier = respect_opinion
				opinion = -20
			}
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { wrathful = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: write this conversation off as wasted.
	option = {
		name = diarchy.1741.e
		trigger = {
			NOT = { has_trait = wrathful }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.1741.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Doesn't look great.
		add_prestige = minor_prestige_loss
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_energy = -0.5
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}










##################################################
# MANDATES - SWELL ARMIES

##################################################
# Bring Out Your Youth
# by Ewan Cowhig Croft
# 2201 - 2210
##################################################

scripted_trigger diarchy_2201_valid_exploitable_county_trigger = {
	# Counties only, please.
	tier = tier_county
	# Must not have a suitable modifier.
	NOR = {
		has_county_modifier = mandate_squeezing_recruiting_sources_modifier
		has_county_modifier = mandate_extra_recruiting_sources_modifier
	}
	# Should be hovering at at least an _arguable_ level of control, or else you're already missing out on plenty of recruiting.
	county_control >= medium_county_control
}

scripted_effect diarchy_2201_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.2201.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_county
			scope:exploitable_county = {
				add_county_modifier = {
					modifier = mandate_squeezing_recruiting_sources_modifier
					years = 10
				}
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
	# Plus scope:diarch sees some backlash.
	add_character_modifier = {
		modifier = mandate_hated_recruiter_modifier
		years = 10
	}
}

scripted_effect diarchy_2201_swing_resolve_stress_impact_effect = {
	stress_impact = {
		diligent = miniscule_stress_impact_loss
		lazy = medium_stress_impact_gain
		compassionate = medium_stress_impact_gain
		just = medium_stress_impact_gain
	}
}

#	Round up countryside recruits.
## Sorta struggled to represent the actual process of levying troops in the copy of this event - it shouldn't be taken to mean that medieval armies were predominantly composed of volunteers, just that volunteers could be raised from areas that had already supplied their levy but had more manpower left in the pool.
diarchy.2201 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.2201.t
	}
	desc = diarchy.2201.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:diarch
		animation = personality_bold
	}
	right_portrait = {
		character = scope:misc_peasant
		animation = worry
		hide_info = yes
	}
	override_background = { reference = wilderness_scope }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# You haven't annoyed everyone too recently.
		NOR = {
			has_character_modifier = mandate_hated_recruiter_modifier
			has_character_modifier = mandate_failed_to_drum_up_rural_recruits_modifier
		}
		# There's gotta be some counties to harass.
		liege = {
			any_held_title = { diarchy_2201_valid_exploitable_county_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Select a county to buff.
		scope:liege = {
			# If scope:liege has many counties, we try to nab their third most levy-producing, for a more rural feel.
			if = {
				limit = {
					any_held_title = {
						count >= 3
						diarchy_2201_valid_exploitable_county_trigger = yes
					}
				}
				ordered_held_title = {
					limit = { diarchy_2201_valid_exploitable_county_trigger = yes }
					order_by = total_county_levies
					position = 2
					# First and second counties aren't relevant, so we skip straight to #3.
					save_scope_as = exploitable_county
				}
			}
			# Otherwise, select one at random.
			else = {
				random_held_title = {
					limit = { diarchy_2201_valid_exploitable_county_trigger = yes }
					save_scope_as = exploitable_county
				}
			}
		}
		## Now, we want to create a peasant from scope:exploitable_county to be shocked.
		create_character = {
			template = generic_peasant_character
			culture = scope:exploitable_county.culture
			faith = scope:exploitable_county.faith
			location = scope:exploitable_county.title_province
			save_scope_as = misc_peasant
		}
		## Finally, sort the background.
		scope:exploitable_county.title_province = { save_scope_as = background_wilderness_scope }
	}

	# Resolve with Good Trait: take everyone of fit age that you can gather, ignoring protests.
	option = {
		name = diarchy.2201.a
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Apply success effects.
		diarchy_2201_successful_swing_resolve_effect = yes

		diarchy_2201_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2201_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: drum up support the old fashion way.
	option = {
		name = diarchy.2201.b
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: you enlist a suitable throng.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2201.b.tt.success
				send_interface_toast = {
					title = diarchy.2201.b.tt.success
					left_icon = scope:exploitable_county
					# Apply success effects.
					diarchy_2201_successful_swing_resolve_effect = yes
				}
			}
			# Failure: the peasantry flee your soldiers.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2201.b.tt.failure
				send_interface_toast = {
					title = diarchy.2201.b.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2201.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.harass_peasants.liege
							}
							# Some PR issues ensue.
							scope:diarch = {
								add_character_modifier = {
									modifier = mandate_failed_to_drum_up_rural_recruits_modifier
									years = 10
								}
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
		}

		diarchy_2201_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2201_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: take bribes from worried families for ignoring their children.
	option = {
		name = diarchy.2201.c

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: a little for me, a little for you.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2201.c.tt.success
				send_interface_toast = {
					title = diarchy.2201.c.tt.success
					left_icon = scope:exploitable_county
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2201.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# A modifier for the liege.
							scope:exploitable_county = {
								add_county_modifier = {
									modifier = mandate_extra_recruiting_sources_modifier
									years = 10
								}
							}
							# And some cash for scope:diarch.
							scope:diarch = { add_gold = minor_gold_value }
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: bitter recriminations follow.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2201.c.tt.failure
				send_interface_toast = {
					title = diarchy.2201.c.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2201.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.obtain_gold.self
							}
							# Some PR issues ensue.
							scope:diarch = {
								add_character_modifier = {
									modifier = mandate_failed_to_drum_up_rural_recruits_modifier
									years = 10
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			callous = miniscule_stress_impact_loss
			generous = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 1
				ai_honor = -0.5
			}
		}
	}

	# Opt Out with Bad Trait: these people have fulfilled their legal obligations already.
	option = {
		name = diarchy.2201.d
		trigger = { has_trait = just }
		trait = just

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2201.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# A hero of the people. Sorta. Given you brought this whole thing up.
		add_prestige = minor_prestige_gain
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { just = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: refuse to force the issue.
	option = {
		name = diarchy.2201.e
		trigger = {
			NOT = { has_trait = just }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2201.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			compassionate = miniscule_stress_impact_loss
			callous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_honor = 0.75
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		# Take care of the misc character.
		hidden_effect = {
			scope:misc_peasant = {
				death = { death_reason = death_vanished }
			}
		}
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# A Rare Talent
# by Ewan Cowhig Croft
# 2211 - 2220
##################################################

scripted_trigger diarchy_2211_valid_pool_character_trigger = {
	# Are they eligible to be a knight at all?
	can_be_knight_trigger = { ARMY_OWNER = scope:liege }
	# Do they some quality that marks them out as a particularly noteworthy knight?
	OR = {
		# Either they're just a solid fighter.
		prowess >= very_high_skill_rating
		# Or they have some useful special trait.
		AND = {
			prowess >= high_skill_rating
			OR = {
				has_trait = berserker
				has_trait = shieldmaiden
				has_trait = varangian
				has_trait = lifestyle_blademaster
				number_of_commander_traits >= 1
			}
		}
	}
}

scripted_effect diarchy_2211_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.2211.a.t
			left_icon = scope:diarch
			right_icon = scope:hedge_knight
			# Free knight!
			add_courtier = scope:hedge_knight
			reverse_add_opinion = {
				target = scope:hedge_knight
				modifier = flattered_opinion
				opinion = 50
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
}

scripted_effect diarchy_2211_scan_for_potential_knights_effect = {
	every_de_jure_county = {
		title_province = {
			save_scope_as = current_prov
			if = {
				limit = {
					any_pool_character = {
						count >= 1
						province = scope:current_prov
					}
				}
				every_pool_character = {
					limit = { diarchy_2211_valid_pool_character_trigger = yes }
					province = scope:current_prov
					add_to_list = potential_hedge_knights_list
				}
			}
		}
	}
}

scripted_effect diarchy_2211_swing_resolve_stress_impact_effect = {
	stress_impact = { shy = minor_stress_impact_gain }
}

#	Woo Hedge Knight.
diarchy.2211 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.2211.t
	}
	desc = diarchy.2211.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:diarch
		animation = admiration
	}
	right_portrait = {
		character = scope:hedge_knight
		animation = marshal
	}
	override_background = { reference = tavern }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Select a suitable hedge knight.
		### First, we try to grab any possible candidates.
		#### Landless diarchs use their liege's capital.
		if = {
			limit = { is_landed_or_landless_administrative = no }
			scope:liege.capital_county = {
				save_scope_as = appropriate_capital
				duchy = { diarchy_2211_scan_for_potential_knights_effect = yes }
			}
		}
		#### Landed diarchs use their own.
		else = {
			capital_county = {
				save_scope_as = appropriate_capital
				duchy = { diarchy_2211_scan_for_potential_knights_effect = yes }
			}
		}
		### Now pick the best one.
		if = {
			limit = {
				any_in_list = {
					list = potential_hedge_knights_list
					count >= 1
				}
			}
			ordered_in_list = {
				list = potential_hedge_knights_list
				order_by = prowess
				save_scope_as = hedge_knight
			}
		}
		### Failing that, we create one.
		else = {
			# Nab scope:liege for the knightly gender check.
			scope:liege = { save_scope_as = value_target }
			# Then make us a knight!
			create_character = {
				template = new_warrior_character
				culture = scope:appropriate_capital.culture
				faith = scope:appropriate_capital.faith
				gender_female_chance = scope_value_target_soldier_female_chance
				location = scope:appropriate_capital.title_province
				save_scope_as = hedge_knight
				# If their prowess has turned out low, we boost it up to a minimum.
				after_creation = {
					# We force a recalc _before_ checking because after_creation seems to not factor traits in to skill checks immediately, which was leading to knights with 30-45 prowess about 60% of the time.
					force_character_skill_recalculation = yes
					# Then we look to see if the base needs boosting.
					if = {
						limit = { prowess < high_skill_rating }
						add_prowess_skill = {
							value = high_skill_rating
							subtract = prowess
						}
						# Update their sheet.
						force_character_skill_recalculation = yes
					}
					if = {
						limit = { diplomacy < medium_skill_rating }
						add_diplomacy_skill = {
							value = medium_skill_rating
							subtract = diplomacy
						}
						# Update their sheet.
						force_character_skill_recalculation = yes
					}
				}
			}
			# Mark that they were added for this event, and thus must be cleaned up after it.
			scope:hedge_knight = {
				save_scope_value_as = {
					name = hedge_knight_created
					value = yes
				}
			}
		}
		## Don't forget scope:hedge_knight's location!
		scope:hedge_knight.location.county = { save_scope_as = hedge_knight_location }
	}

	# Resolve with Good Trait: have your agents doggedly pursue the knight at every opportunity.
	option = {
		name = diarchy.2211.a
		trigger = { has_trait = gregarious }
		trait = gregarious

		# Apply success effects.
		diarchy_2211_successful_swing_resolve_effect = yes

		diarchy_2211_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2211_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to persuade HerHim about the glory of serving scope:liege.
	option = {
		name = diarchy.2211.b
		trigger = {
			NOT = { has_trait = gregarious }
		}

		duel = {
			skill = diplomacy
			target = scope:hedge_knight
			# Success: your words sway scope:hedge_knight.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2211.b.tt.success
				send_interface_toast = {
					title = diarchy.2211.b.tt.success
					left_icon = scope:hedge_knight
					# Apply success effects.
					diarchy_2211_successful_swing_resolve_effect = yes
				}
			}
			# Failure: your pleas fall on deaf ears.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2211.b.tt.failure
				send_interface_toast = {
					title = diarchy.2211.b.tt.failure
					left_icon = scope:hedge_knight
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2211.b.t
							left_icon = scope:diarch
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_character.liege
							}
							# Scope:diarch's reputation takes a hit.
							scope:diarch = { add_prestige = minor_prestige_loss }
							# No strife here - you're not abusing your powers, really, just being a bit pushy.
						}
					}
					reverse_add_opinion = {
						target = scope:hedge_knight
						modifier = annoyed_opinion
						opinion = -30
					}
				}
			}
		}

		diarchy_2211_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2211_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: try to persuade HerHim to serve you instead.
	option = {
		name = diarchy.2211.c

		duel = {
			skill = diplomacy
			target = scope:hedge_knight
			# Success: you entice scope:hedge_knight.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2211.c.tt.success
				send_interface_toast = {
					title = diarchy.2211.c.tt.success
					left_icon = scope:hedge_knight
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2211.c.t.success
							left_icon = scope:diarch
							right_icon = scope:hedge_knight
							# Consolation prestige for scope:liege.
							add_prestige = minor_prestige_gain
							# Free knight! Just... not for scope:liege.
							scope:diarch = {
								# Landed diarchs get the knight.
								if = {
									limit = { is_ruler = yes }
									add_courtier = scope:hedge_knight
								}
								# Landless diarchs get prestige & a favour from scope:hedge_knight (mostly for flavour).
								else = {
									add_prestige = medium_prestige_gain
									if = {
										limit = {
											NOT = { has_hook = scope:hedge_knight }
										}
										add_hook = {
											type = favor_hook
											target = scope:hedge_knight
										}
									}
								}
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
					# Scope:hedge_knight comes around to things.
					reverse_add_opinion = {
						target = scope:hedge_knight
						modifier = flattered_opinion
						opinion = 30
					}
				}
			}
			# Failure: SheHe wants nothing to do with you.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2211.c.tt.failure
				send_interface_toast = {
					title = diarchy.2211.c.tt.failure
					left_icon = scope:hedge_knight
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2211.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:hedge_knight
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_character.self
							}
							# This is more personal, so scope:diarch takes a more public hit.
							scope:diarch = { add_prestige = medium_prestige_loss}
						}
					}
				}
			}
		}

		stress_impact = {
			deceitful = miniscule_stress_impact_loss
			honest = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_honor = -0.5
			}
		}
	}

	# Opt Out with Bad Trait: take the hint, but take it hard.
	option = {
		name = diarchy.2211.d
		trigger = { has_trait = shy }
		trait = shy

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2211.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:hedge_knight
			}
		}
		# Bit of a public fit, that.
		add_prestige = minor_prestige_loss
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { shy = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: take the hint.
	option = {
		name = diarchy.2211.e
		trigger = {
			NOT = { has_trait = shy }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2211.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:hedge_knight
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			shy = miniscule_stress_impact_loss
			stubborn = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_honor = 0.5
				ai_compassion = 0.25
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		# If they were created for this, take care of scope:hedge_knight.
		hidden_effect = {
			if = {
				limit = {
					exists = scope:hedge_knight_created
					exists = scope:hedge_knight
					scope:hedge_knight = { is_courtier = no }
				}
				scope:hedge_knight = {
					death = { death_reason = death_vanished }
				}
			}
		}
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Martial Donatives
# by Ewan Cowhig Croft
# 2221 - 2230
##################################################

scripted_effect diarchy_2221_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.2221.a.t
			left_icon = scope:diarch
			# MaA are discounted for a bit.
			add_character_modifier = {
				modifier = mandate_sellswords_bolster_ranks_modifier
				years = 10
			}
			# ... at some cost to scope:diarch.
			scope:diarch = { remove_short_term_gold = medium_gold_value }
			# Swing the scales.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			# No strife here - you're not abusing your powers.
		}
	}
}

scripted_effect diarchy_2221_swing_resolve_stress_impact_effect = {
	stress_impact = {
		generous = miniscule_stress_impact_loss
		greedy = major_stress_impact_gain
	}
}

#	Entice professional soldiery.
diarchy.2221 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.2221.t
	}
	desc = diarchy.2221.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:diarch
		animation = steward
	}
	right_portrait = {
		character = scope:misc_soldier
		animation = celebrate_axe
		hide_info = yes
	}
	override_background = { reference = market_scope }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		liege = {
			# Liege must have some MaA to improve (as that's the desired modifier, even if they end up with a discount instead due to the split-benefits option).
			number_of_maa_regiments >= 1
			# Plus check they've not acquired either of the MaA modifiers before.
			NOR = {
				has_character_modifier = mandate_sellswords_bolster_ranks_modifier
				has_character_modifier = mandate_sellswords_bolster_recruitment_modifier
			}
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Nab scope:liege's capital for the background.
		scope:liege.capital_county.title_province = { save_scope_as = background_market_scope }
		## Create a random sellsword.
		### First, nab scope:liege for gender_female_chance purposes.
		scope:liege = { save_scope_as = value_target }
		### Then make a warrior.
		create_character = {
			template = new_warrior_character
			culture = scope:liege.capital_county.culture
			faith = scope:liege.capital_county.faith
			gender_female_chance = scope_value_target_soldier_female_chance
			location = scope:liege.capital_county.title_province
			save_scope_as = misc_soldier
		}
	}

	# Resolve with Good Trait: carouse & glorify the life of a sellsword.
	option = {
		name = diarchy.2221.a
		trigger = { has_trait = gregarious }
		trait = gregarious

		# Apply success effects.
		diarchy_2221_successful_swing_resolve_effect = yes

		diarchy_2221_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2221_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to offer only competitive bonuses.
	option = {
		name = diarchy.2221.b
		trigger = {
			NOT = { has_trait = gregarious }
		}

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: money well spent!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2221.b.tt.success
				send_interface_toast = {
					title = diarchy.2221.b.tt.success
					# Apply success effects.
					diarchy_2221_successful_swing_resolve_effect = yes
				}
			}
			# Failure: a poor investment.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2221.b.tt.failure
				send_interface_toast = {
					title = diarchy.2221.b.tt.failure
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2221.b.t
							left_icon = scope:diarch
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_troops.liege
							}
							# Gold is lost, but that's all.
							scope:diarch = { remove_short_term_gold = medium_gold_value }
						}
					}
				}
			}
		}

		diarchy_2221_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2221_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: offer decent bonuses, but offer them the option of serving you too.
	option = {
		name = diarchy.2221.c

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: a fine crop of soldiers.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2221.c.tt.success
				send_interface_toast = {
					title = diarchy.2221.c.tt.success
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2221.c.t.success
							left_icon = scope:diarch
							# MaA cost is discounted for a bit.
							add_character_modifier = {
								modifier = mandate_sellswords_bolster_recruitment_modifier
								years = 10
							}
							scope:diarch = {
								add_character_modifier = {
									modifier = mandate_sellswords_bolster_recruitment_modifier
									years = 10
								}
								# Plus you gotta pay the initial investment.
								remove_short_term_gold = medium_gold_value
							}
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: barely a trickle of troops enlist.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2221.c.tt.failure
				send_interface_toast = {
					title = diarchy.2221.c.tt.failure
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2221.c.t.failure
							left_icon = scope:diarch
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_troops.split
							}
							# Gold is lost, but that's all.
							scope:diarch = { remove_short_term_gold = medium_gold_value }
						}
					}
				}
			}
		}

		stress_impact = {
			generous = miniscule_stress_impact_loss
			honest = medium_stress_impact_gain
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = 1
				ai_boldness = 0.5
			}
		}
	}

	# Opt Out with Bad Trait: freak out and flee.
	option = {
		name = diarchy.2221.d
		trigger = { has_trait = shy }
		trait = shy

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2221.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Not a good look.
		add_prestige = minor_prestige_loss
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { shy = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: back down due to cost.
	option = {
		name = diarchy.2221.e
		trigger = {
			NOT = { has_trait = shy }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2221.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			greedy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
			generous = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = -0.25
				ai_greed = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# A Better Use for You
# by Ewan Cowhig Croft
# 2231 - 2240
##################################################

scripted_trigger diarchy_2231_valid_exploitable_county_trigger = {
	tier = tier_county
	NOT = { has_county_modifier = mandate_emptied_gaols_modifier }
}

scripted_effect diarchy_2231_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.2231.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_county
			# The gaols are emptied.
			scope:exploitable_county = {
				add_county_modifier = {
					modifier = mandate_emptied_gaols_modifier
					years = 10
				}
			}
			# But scope:liege has a goodly source of violent types.
			add_character_modifier = {
				modifier = mandate_hired_thugs_modifier
				years = 10
			}
			# Swing the scales & apply strife.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			scope:diarch = { change_strife_opinion = minor_strife_gain }
		}
	}
}

scripted_effect diarchy_2231_swing_resolve_stress_impact_effect = {
	stress_impact = { just = major_stress_impact_gain }
}

#	Empty the gaols.
diarchy.2231 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.2231.t
	}
	desc = diarchy.2231.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:diarch
		animation = disapproval
	}
	right_portrait = {
		character = scope:misc_peasant
		animation = disbelief
		hide_info = yes
	}
	override_background = { reference = dungeon }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Liege isn't still benefiting from the modifier.
		NOT = {
			liege = { has_character_modifier = mandate_hired_thugs_modifier }
		}
		# Has a suitable county.
		any_held_title = { diarchy_2231_valid_exploitable_county_trigger = yes }
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Grab a random county to affected.
		### We want somewhere that'll sting but which _isn't_ your capital, ideally...
		if = {
			limit = {
				any_held_title = {
					count >= 2
					diarchy_2231_valid_exploitable_county_trigger = yes
				}
			}
			ordered_held_title = {
				limit = {
					diarchy_2231_valid_exploitable_county_trigger = yes
					NOT = { this = scope:diarch.capital_county }
				}
				order_by = development_level
				save_scope_as = exploitable_county
			}
		}
		### ... but in extremis, we'll take your capital too.
		else = {
			random_held_title = {
				limit = { diarchy_2231_valid_exploitable_county_trigger = yes }
				save_scope_as = exploitable_county
			}
		}
		## Create a peasant to be scandalised.
		create_character = {
			template = generic_peasant_character
			culture = scope:exploitable_county.culture
			faith = scope:exploitable_county.faith
			location = scope:exploitable_county.title_province
			save_scope_as = misc_peasant
		}
	}

	# Resolve with Good Trait: ride out the complaints and plough ahead.
	option = {
		name = diarchy.2231.a
		trigger = { has_trait = arbitrary }
		trait = arbitrary

		# Apply success effects.
		diarchy_2231_successful_swing_resolve_effect = yes

		diarchy_2231_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2231_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to weigh up the useful ones against the outrage caused.
	option = {
		name = diarchy.2231.b
		trigger = {
			NOT = { has_trait = arbitrary }
		}

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: you strike something like a balance.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2231.b.tt.success
				send_interface_toast = {
					title = diarchy.2231.b.tt.success
					left_icon = scope:exploitable_county
					# Apply success effects.
					diarchy_2231_successful_swing_resolve_effect = yes
				}
			}
			# Failure: once free, the criminals immediately flee.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2231.b.tt.failure
				send_interface_toast = {
					title = diarchy.2231.b.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2231.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_troops.liege
							}
							# The gaols are emptied regardless.
							scope:exploitable_county = {
								add_county_modifier = {
									modifier = mandate_emptied_gaols_modifier
									years = 10
								}
							}
							# Add some strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
		}

		diarchy_2231_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2231_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: take the choicest candidates for yourself.
	option = {
		name = diarchy.2231.c

		duel = {
			skill = martial
			value = high_skill_rating
			# Success: it's not good work, but it's honest.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2231.c.tt.success
				send_interface_toast = {
					title = diarchy.2231.c.tt.success
					left_icon = scope:exploitable_county
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2231.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# The gaols are emptied.
							scope:exploitable_county = {
								add_county_modifier = {
									modifier = mandate_emptied_gaols_modifier
									years = 10
								}
							}
							# The criminals make no noticeable difference, other than a few stand-out examples.
							add_dread = medium_dread_gain
							scope:diarch = { add_dread = medium_dread_gain }
							# Apply a little strife.
							scope:diarch = { change_strife_opinion = minor_strife_gain }
						}
					}
				}
			}
			# Failure: once free, the criminals immediately flee.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2231.c.tt.failure
				send_interface_toast = {
					title = diarchy.2231.c.tt.failure
					left_icon = scope:exploitable_county
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2231.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_county
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_troops.split
							}
							# The gaols are emptied regardless.
							scope:exploitable_county = {
								add_county_modifier = {
									modifier = mandate_emptied_gaols_modifier
									years = 10
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
			honest = minor_stress_impact_gain
			just = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}

	# Opt Out with Bad Trait: back down, unable to bring yourself to circumvent the law like this.
	option = {
		name = diarchy.2231.d
		trigger = { has_trait = just }
		trait = just

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2231.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_county
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { just = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: back down before the mob.
	option = {
		name = diarchy.2231.e
		trigger = {
			NOT = { has_trait = just }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2231.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_county
			}
		}
		# Now we add some ancillary opinions.
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			craven = miniscule_stress_impact_loss
			brave = medium_stress_impact_gain
			stubborn = medium_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_compassion = 1
				ai_sociability = -0.75
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}

##################################################
# Make a WomanMan Out of You
# by Ewan Cowhig Croft
# 2241 - 2250
##################################################

scripted_trigger diarchy_2241_valid_exploitable_vassal_trigger = {
	# Filter out non-barons.
	highest_held_title_tier = tier_barony
	# Make sure they're around for the event.
	is_available_ai_adult = yes
	# And that they've not had it recently.
	NOR = {
		has_character_modifier = mandate_baronial_troops_trained_modifier
		has_character_modifier = mandate_baronial_troops_half_trained_modifier
	}
	NOT = { is_diarch = yes }
}

scripted_effect diarchy_2241_successful_swing_resolve_effect = {
	# Stuff that'll go to the liege via feed message.
	scope:liege = {
		send_interface_message = {
			type = msg_mandate_results_neutral_effect
			title = diarchy.2241.a.t
			left_icon = scope:diarch
			right_icon = scope:exploitable_vassal
			# Buff the baron.
			scope:exploitable_vassal = {
				add_character_modifier = {
					modifier = mandate_baronial_troops_trained_modifier
					years = 20
				}
			}
			# Swing the scales.
			update_diarchy_swing_with_perspective_effect = {
				SWING = minor_sop_swing_diarch_gain
				LIEGE = scope:liege
			}
			# No strife, since this isn't an abuse of power.
		}
	}
	# Now we add some ancillary opinions.
	reverse_add_opinion = {
		modifier = angry_opinion
		target = scope:exploitable_vassal
		opinion = -30
	}
}

scripted_effect diarchy_2241_swing_resolve_stress_impact_effect = {
	stress_impact = { lazy = major_stress_impact_gain }
}

#	Train baronial troops.
diarchy.2241 = {
	type = character_event
	title = {
		desc = mandate_event_prefix
		desc = diarchy.2241.t
	}
	desc = diarchy.2241.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:diarch
		animation = personality_bold
	}
	right_portrait = {
		character = scope:exploitable_vassal
		animation = stress
	}
	override_background = { reference = courtyard }

	cooldown = { years = 5 }

	trigger = {
		# Standard checks.
		is_available = yes
		is_diarch = yes
		# Will be training troops, so must be eligible to do so.
		can_be_knight_trigger = { ARMY_OWNER = root }
		# And not absolutely terrible.
		prowess >= medium_skill_rating
		# Plus hasn't got one of the relevant modifiers previously.
		NOR = {
			has_character_modifier = mandate_focused_on_own_training_modifier
			has_character_modifier = mandate_strained_self_training_modifier
		}
		# Liege must have at least one baron vassal. Y'know. In case you're the one-county Emperor of Byzantium. I guess.
		liege = {
			any_vassal = { diarchy_2241_valid_exploitable_vassal_trigger = yes }
		}
	}

	immediate = {
		# Block our feed message tooltip.
		add_character_flag = blocked_diarch_feed_message_tooltip
		# We need to save some scopes for loc/general ease.
		## Sort our base scopes.
		diarchy_mandates_refresh_liege_diarch_scopes_effect = yes
		## Grab the best available baron.
		scope:liege = {
			ordered_vassal = {
				limit = { diarchy_2241_valid_exploitable_vassal_trigger = yes }
				order_by = max_military_strength
				save_scope_as = exploitable_vassal
			}
		}
	}

	# Resolve with Good Trait: charm them into following your lead.
	option = {
		name = diarchy.2241.a
		trigger = { has_trait = gregarious }
		trait = gregarious

		# Apply success effects.
		diarchy_2241_successful_swing_resolve_effect = yes

		diarchy_2241_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2241_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve at Self-Cost: try to whip them into shape personally.
	option = {
		name = diarchy.2241.b
		trigger = {
			NOT = { has_trait = gregarious }
		}

		duel = {
			skill = prowess
			value = high_skill_rating
			# Success: at last, real WomenMen!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2241.b.tt.success
				send_interface_toast = {
					title = diarchy.2241.b.tt.success
					left_icon = scope:exploitable_vassal
					# Apply success effects.
					diarchy_2241_successful_swing_resolve_effect = yes
				}
			}
			# Failure: what a sorry lot of louts they prove to be...
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2241.b.tt.failure
				send_interface_toast = {
					title = diarchy.2241.b.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2241.b.t
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.acquire_troops.liege
							}
							# Charge a little prestige.
							scope:diarch = { add_prestige = minor_prestige_loss }
						}
					}
				}
			}
		}

		diarchy_2241_swing_resolve_stress_impact_effect = yes
		ai_chance = {
			base = 10
			diarchy_2241_swing_resolve_ai_value_modifier = yes
			# Characters lacking drive don't generally engage with mandates.
			diarchy_mandate_events_low_diligency_weight_down_modifier = yes
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_up_ai_modifier = yes
		}
	}
	
	# Resolve and Split Benefit: focus more on personal fitness.
	option = {
		name = diarchy.2241.c

		duel = {
			skill = prowess
			value = high_skill_rating
			# Success: a fearsome force!
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.2241.c.tt.success
				send_interface_toast = {
					title = diarchy.2241.c.tt.success
					left_icon = scope:exploitable_vassal
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2241.c.t.success
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Buff the baron a _little_.
							scope:exploitable_vassal = {
								add_character_modifier = {
									modifier = mandate_baronial_troops_half_trained_modifier
									years = 20
								}
							}
							# Buff scope:diarch.
							scope:diarch = {
								add_character_modifier = {
									modifier =  mandate_focused_on_own_training_modifier
									years = 10
								}
							}
							# No strife, since you're not abusing your power.
						}
					}
				}
			}
			# Failure: you hurt yourself in your confusion.
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.2241.c.tt.failure
				send_interface_toast = {
					title = diarchy.2241.c.tt.failure
					left_icon = scope:exploitable_vassal
					remove_character_flag = blocked_diarch_feed_message_tooltip
					scope:liege = {
						send_interface_message = {
							type = msg_mandate_results_neutral_effect
							title = diarchy.2241.c.t.failure
							left_icon = scope:diarch
							right_icon = scope:exploitable_vassal
							# Process feed message tooltip.
							if = {
								limit = {
									scope:diarch = {
										NOT = { has_character_flag = blocked_diarch_feed_message_tooltip }
									}
								}
								custom_tooltip = diarchies.0000.diarch_mandate_fail.tt.train_self.self
							}
							# You sprain something badly.
							scope:diarch = {
								add_character_modifier = {
									modifier =  mandate_strained_self_training_modifier
									years = 10
								}
							}
							# No strife, since you're not abusing your power.
						}
					}
				}
			}
		}

		stress_impact = {
			diligent = miniscule_stress_impact_loss
			athletic = major_stress_impact_loss
			lazy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_energy = 1
				ai_rationality = 0.5
			}
		}
	}

	# Opt Out with Bad Trait: shake your head and leave wordlessly.
	option = {
		name = diarchy.2241.d
		trigger = { has_trait = shy }
		trait = shy

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2241.d.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = insult_opinion
			target = scope:exploitable_vassal
			opinion = -30
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = { shy = medium_stress_impact_loss }
		ai_chance = {
			# The AI should generally go for a trait opt-out whenever one's available.
			base = 1000
			# Though we might weight that down a smidgeon if SheHe's driven.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Opt Out: declare this to be a waste of your time.
	option = {
		name = diarchy.2241.e
		trigger = {
			NOT = { has_trait = shy }
		}

		# Stuff that'll go to the liege via feed message.
		scope:liege = {
			send_interface_message = {
				type = msg_mandate_results_bad_text
				title = diarchy.2241.e.t
				desc = diarchy.0000.tt.diarch_shirked_duties
				left_icon = scope:diarch
				right_icon = scope:exploitable_vassal
			}
		}
		# Now we add some ancillary opinions.
		reverse_add_opinion = {
			modifier = insult_opinion
			target = scope:exploitable_vassal
			opinion = -30
		}
		diarchy_mandates_opt_out_apply_liege_disappointment_effect = yes

		stress_impact = {
			lazy = miniscule_stress_impact_loss
			diligent = minor_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_energy = -1
			}
			# Committed diarchs pursue their mandates.
			diarchy_mandate_events_committed_diarch_serves_weight_down_ai_modifier = yes
			# Also adjusted per some general diligency traits.
			diarchy_mandate_events_high_diligency_weight_down_modifier = yes
		}
	}

	# Run some clean-up stuff.
	after = {
		if = {
			limit = { has_character_flag = blocked_diarch_feed_message_tooltip }
			remove_character_flag = blocked_diarch_feed_message_tooltip
		}
	}
}










##################################################
# INTERACTIONS

##################################################
# Request Imperial Expedition - Letter notification events
# by Ewan Cowhig Croft
# 8001 - 8010
##################################################

scripted_effect send_expedition_information_to_player_governors_effect = {
	save_scope_value_as = {
		name = expedition_info
		value = flag:$RESPONSE$
	}
	every_player = {
		limit = {
			any_liege_or_above = { this = scope:recipient }
			NOR = {
				this = scope:actor
				this = scope:recipient
			}
		}
		trigger_event = diarchy.8004
	}
	# Suppress error from us not using the accepted response.
	if = {
		limit = { scope:expedition_info = flag:accepted }
	}
}

#	Your request to launch an expedition has been granted.
diarchy.8001 = {
	type = letter_event
	opening = diarchy.8001.t
	desc = diarchy.8001.desc
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		diarch_request_imperial_expedition_accepted_effect = yes
		# If it's the AI, force this right away.
		if = {
			limit = { is_ai = yes }
			# And by right away, we mean launder it a day for technical reasons.
			trigger_event = {
				id = diarchy.8007
				days = 1
			}
		}
	}

	# To war!
	option = {
		name = diarchy.8001.a

		# No stress or AI chance needed for a notification event.
	}

	after = {
		# Aaaaand the result for our player governors.
		send_expedition_information_to_player_governors_effect = { RESPONSE = accepted }
	}
}

#	Your request to launch an expedition has been refused.
diarchy.8002 = {
	type = letter_event
	opening = diarchy.8002.t
	desc = diarchy.8002.desc
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		diarch_request_imperial_expedition_rejected_effect = yes
	}

	# Narrow-minded fool.
	option = {
		name = diarchy.8002.a

		# No stress or AI chance needed for a notification event.
	}

	after = {
		# Aaaaand the result for our player governors.
		send_expedition_information_to_player_governors_effect = { RESPONSE = refused }
	}
}

#	You've been forced to agree to an imperial expedition.
diarchy.8003 = {
	type = letter_event
	opening = diarchy.8003.t
	desc = diarchy.8003.desc
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		diarch_request_imperial_expedition_accepted_effect = yes
	}

	# That presumptuous fool!
	option = {
		name = diarchy.8003.a

		# No stress or AI chance needed for a notification event.
	}

	after = {
		# Aaaaand the result for our player governors.
		send_expedition_information_to_player_governors_effect = { RESPONSE = forced }
	}
}

#	Inform the governors what's up.
diarchy.8004 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:expedition_info = flag:refused }
				desc = diarchy.8004.t.vetoed
			}
			desc = diarchy.8004.t.planned
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:expedition_info = flag:refused }
				desc = diarchy.8004.desc.vetoed
			}
			desc = {
				desc = diarchy.8004.desc.planned
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:expedition_info = flag:forced
						}
						desc = diarchy.8004.desc.planned.forced
					}
					desc = diarchy.8004.desc.planned.allowed
				}
			}
		}
	}
	theme = administrative
	left_portrait = {
		character = scope:actor
		triggered_animation = {
			trigger = { scope:expedition_info != flag:refused }
			animation = marshal
		}
		triggered_animation = {
			trigger = { scope:expedition_info = flag:refused }
			animation = anger
		}
	}
	right_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = { scope:expedition_info != flag:refused }
			animation = admiration
		}
		triggered_animation = {
			trigger = { scope:expedition_info = flag:refused }
			animation = dismissal
		}
	}

	immediate = {
		show_as_tooltip = {
			scope:actor = { diarch_request_imperial_expedition_accepted_effect = yes }
		}
	}

	# Fresh lands for the taking...
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:expedition_info = flag:refused }
						desc = diarchy.8004.a.vetoed
					}
					desc = diarchy.8004.a.allowed
				}
			}
		}

		# No stress or AI chance needed for a notification event.
	}
}

#	An expedition is being launched on your border, obliging you to join.
diarchy.8005 = {
	type = letter_event
	opening = diarchy.8005.t
	desc = diarchy.8005.desc
	sender = scope:attacker

	trigger = {
		NOT = { has_character_flag = pinged_to_join_expedition }
	}

	immediate = {
		add_character_flag = {
			flag = pinged_to_join_expedition
			days = 5
		}
		show_as_tooltip = {
			scope:attacker = {
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:defender
				}
			}
		}
	}

	# Once more unto the breach!
	option = {
		name = diarchy.8005.a

		scope:war = { add_attacker = prev }

		stress_impact = {
			brave = major_stress_impact_loss
			just = minor_stress_impact_loss
			arbitrary = minor_stress_impact_gain
			craven = major_stress_impact_gain
		}
		# The AI should always do this.
		ai_chance = { base = 100 }
	}

	# Nope, we ain't doin' that.
	option = {
		name = diarchy.8005.b

		# You shirk your duties.
		change_strife_opinion = 50

		stress_impact = {
			craven = major_stress_impact_loss
			arbitrary = minor_stress_impact_loss
			just = minor_stress_impact_gain
			brave = major_stress_impact_gain
		}
		# The AI should never choose this.
		ai_chance = { base = 0 }
	}
}

#	You run a military governate and an expedition is being launched.
diarchy.8006 = {
	type = letter_event
	opening = diarchy.8006.t
	desc = diarchy.8006.desc
	sender = scope:attacker

	immediate = {
		show_as_tooltip = {
			scope:attacker = {
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:defender
				}
			}
		}
	}

	# Once more unto the breach!
	option = {
		name = diarchy.8006.a

		scope:war = { add_attacker = prev }
		# Since it's optional for you to join, you gain influence.
		change_influence = major_influence_gain

		stress_impact = {
			brave = major_stress_impact_loss
			just = minor_stress_impact_loss
			arbitrary = minor_stress_impact_gain
			craven = major_stress_impact_gain
		}
		# AI choose based on how much they like the co-emperor.
		ai_chance = {
			opinion_modifier = { opinion_target = scope:attacker }
			ai_value_modifier = { ai_boldness = 1 }
		}
	}

	# Nope, we ain't doin' that.
	option = {
		name = diarchy.8006.b

		# You shirk your duties.
		reverse_add_opinion = {
			target = scope:attacker
			modifier = disappointed_opinion
			opinion = -20
		}

		stress_impact = {
			craven = major_stress_impact_loss
			arbitrary = minor_stress_impact_loss
			just = minor_stress_impact_gain
			brave = major_stress_impact_gain
		}
		# AI choose based on how much they like the co-emperor.
		ai_chance = {
			opinion_modifier = {
				opinion_target = scope:attacker
				multiplier = -1
			}
			ai_value_modifier = { ai_boldness = -1 }
		}
	}
}

scripted_effect diarchy_8007_designate_targets_effect = {
	if = {
		limit = {
			NOT = { exists = scope:target_1 }
		}
		save_scope_as = target_1
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_2 }
		}
		save_scope_as = target_2
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_3 }
		}
		save_scope_as = target_3
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_4 }
		}
		save_scope_as = target_4
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_5 }
		}
		save_scope_as = target_5
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_6 }
		}
		save_scope_as = target_6
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_7 }
		}
		save_scope_as = target_7
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_8 }
		}
		save_scope_as = target_8
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_9 }
		}
		save_scope_as = target_9
	}
	else_if = {
		limit = {
			NOT = { exists = scope:target_10 }
		}
		save_scope_as = target_10
	}
}

#	Tell the AI to try to declare its best possible war.
diarchy.8007 = {
	hidden = yes

	immediate = {
		# If statement to allow this to be turned off/on easily.
		if = {
			limit = { always = yes }
			save_scope_as = diarch
			liege = { save_scope_as = liege }
			every_neighboring_top_liege_realm_owner = {
				limit = {
					highest_held_title_tier >= tier_kingdom
					realm_size >= 30
					NOR = {
						is_allied_to = scope:liege
						is_allied_to = scope:diarch
						is_allied_in_war = scope:liege
						is_allied_in_war = scope:diarch
						any_truce_holder = {
							OR = {
								this = scope:liege
								this = scope:diarch
							}
						}
					}
				}
				add_to_list = possible_targets_list
			}
			ordered_in_list = {
				list = possible_targets_list
				order_by = {
					every_sub_realm_duchy = {
						if = {
							limit = {
								any_title_to_title_neighboring_duchy = {
									any_de_jure_county = { holder.top_liege = scope:liege }
								}
							}
							add = 10
						}
						if = {
							limit = {
								any_this_title_or_de_jure_above = { holder ?= scope:liege }
							}
							add = 20
						}
					}
					save_temporary_scope_as = target_temp
					scope:liege = {
						every_sub_realm_duchy = {
							if = {
								limit = {
									any_de_jure_county = { holder.top_liege = scope:target_temp }
								}
								add = 30
							}
						}
					}
				}
				save_scope_as = probable_target
			}
			# We do a set_variable here to work around a code limitation that's not fixed yet.
			set_variable = {
				name = probable_target
				value = scope:probable_target
			}
			ai_start_best_war = {
				recalculate_cb_targets = yes
				is_valid = {
					scope:target_character = var:probable_target
					any_in_list = { list = target_titles }
				}
				cb = { imperial_expedition_cb }
			}
		}
		# Cursed manual targeting VERY BAD THING THAT WE SHOULD NOT DO, per long-standing instruction from Code.
		## Left it in here for future debugging purposes, as it's useful if the above effect breaks.
		if = {
			limit = { always = no }
			save_scope_as = diarch
			liege = { save_scope_as = liege }
			every_neighboring_top_liege_realm_owner = {
				limit = {
					highest_held_title_tier >= tier_kingdom
					realm_size >= 30
					NOR = {
						is_allied_to = scope:liege
						is_allied_to = scope:diarch
						is_allied_in_war = scope:liege
						is_allied_in_war = scope:diarch
					}
				}
				add_to_list = possible_targets_list
			}
			ordered_in_list = {
				list = possible_targets_list
				order_by = {
					every_sub_realm_duchy = {
						if = {
							limit = {
								any_title_to_title_neighboring_duchy = {
									any_de_jure_county = { holder.top_liege = scope:liege }
								}
							}
							add = 10
						}
						if = {
							limit = {
								any_this_title_or_de_jure_above = { holder ?= scope:liege }
							}
							add = 20
						}
					}
					save_temporary_scope_as = target_temp
					scope:liege = {
						every_sub_realm_duchy = {
							if = {
								limit = {
									any_de_jure_county = { holder.top_liege = scope:target_temp }
								}
								add = 30
							}
						}
					}
				}
				save_scope_as = target
				# Now add all their valid titles to a list.
				every_sub_realm_duchy = {
					if = {
						limit = {
							OR = {
								any_this_title_or_de_jure_above = { holder ?= scope:liege }
								# Be a bit more thorough with this check now, as we've less to iterate over.
								save_temporary_scope_as = duchy_temp
								any_title_to_title_neighboring_duchy = {
									any_de_jure_county = {
										holder.top_liege = scope:liege
										any_title_to_title_neighboring_county = { duchy = scope:duchy_temp }
									}
								}
							}
						}
						diarchy_8007_designate_targets_effect = yes
					}
				}
				scope:liege = {
					every_sub_realm_duchy = {
						if = {
							limit = {
								any_de_jure_county = { holder.top_liege = scope:target }
							}
							diarchy_8007_designate_targets_effect = yes
						}
					}
				}
			}
			# Ugly war targeting.
			## 10 targets.
			if = {
				limit = { exists = scope:target_10 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
					target_title = scope:target_9
					target_title = scope:target_10
				}
			}
			## 09 targets.
			else_if = {
				limit = { exists = scope:target_9 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
					target_title = scope:target_9
				}
			}
			## 08 targets.
			else_if = {
				limit = { exists = scope:target_8 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
					target_title = scope:target_8
				}
			}
			## 07 targets.
			else_if = {
				limit = { exists = scope:target_7 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
					target_title = scope:target_7
				}
			}
			## 06 targets.
			else_if = {
				limit = { exists = scope:target_6 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
					target_title = scope:target_6
				}
			}
			## 05 targets.
			else_if = {
				limit = { exists = scope:target_5 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
					target_title = scope:target_5
				}
			}
			## 04 targets.
			else_if = {
				limit = { exists = scope:target_4 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
					target_title = scope:target_4
				}
			}
			## 03 targets.
			else_if = {
				limit = { exists = scope:target_3 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
					target_title = scope:target_3
				}
			}
			## 02 targets.
			else_if = {
				limit = { exists = scope:target_2 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
					target_title = scope:target_2
				}
			}
			## 01 targets.
			else_if = {
				limit = { exists = scope:target_1 }
				start_war = {
					casus_belli = imperial_expedition_cb
					target = scope:target
					target_title = scope:target_1
				}
			}
		}
	}
}

##################################################
# Request Imperial Expedition - Domain choice events
# by Ewan Cowhig Croft
# 8011 - 8020
##################################################

scripted_trigger diarchy_8011_has_titles_to_transfer = {
	OR = {
		list_size = {
			name = vassals_to_transfer_all
			value >= 1
		}
		list_size = {
			name = 	titles_to_transfer_all
			value >= 1
		}
	}
}

scripted_effect diarchy_8011_turn_over_titles = {
	# Sort our inf up here so that we can apply it correctly in the step after next.
	hidden_effect = {
		change_influence = scope:attacker.$INFLUENCE_TOOLTIP_TITLE$
		change_influence = scope:attacker.$INFLUENCE_TOOLTIP_VASSAL$
	}
	# Process actual effects.
	hidden_effect = {
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}
		# Transfer vassals.
		every_in_list = {
			list = $VASSAL_TRANSFER_LIST$
			change_liege = {
				liege = scope:attacker.liege
				change = scope:change
			}
		}
		# Transfer titles.
		every_in_list = {
			list = $TITLE_TRANSFER_LIST$
			change_title_holder = {
				holder = scope:attacker.liege
				change = scope:change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
	# Gain influence per county.
	custom_tooltip = diarchy_8011.turn_over_titles.tt.$TITLE_TRANSFER_LIST$
	# Gain influence per vassal by their size.
	if = {
		limit = { var:$VASSAL_VAR$ >= 1 }
		custom_tooltip = diarchy_8011.turn_over_titles.tt.$VASSAL_TRANSFER_LIST$
	}
}

scripted_effect diarchy_8011_process_niche_titles = {
	# Process actual effects.
	hidden_effect = {
		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
			add_claim_on_loss = yes
		}
		# No vassals: they should be covered by other effects.
		# Transfer titles.
		every_in_list = {
			list = rightful_holder_is_other_vassal_list
			duchy.holder = { save_scope_as = legal_holder }
			change_title_holder = {
				holder = scope:legal_holder
				change = scope:change
				take_baronies = yes
			}
		}
		resolve_title_and_vassal_change = scope:change
	}
	# No influence: it's already been handled elsewhere.
}

#	War won! what do
diarchy.8011 = {
	type = character_event
	title = diarchy.8011.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { diarchy_8011_has_titles_to_transfer = no }
				desc = diarchy.8011.desc.all_titles_legally_yours
			}
			desc = diarchy.8011.desc.fallback
		}
	}
	theme = emperor
	left_portrait = {
		character = scope:attacker
		animation = sword_coup_degrace
	}
	right_portrait = {
		character = scope:defender
		animation = sword_yield_start
	}
	override_background = { reference = throne_room }

	immediate = {
		# Alright, let's figure out where our gains might go.
		## First off, try to pick a prize county.
		ordered_in_list = {
			list = titles_taken
			limit = { tier = tier_county }
			order_by = development_level
			save_scope_as = prize_county
		}
		## Now we work out what titles we'd give over if we transferred them.
		### Create missing duchies.
		hidden_effect = {
			every_in_list = {
				list = titles_taken
				limit = {
					duchy = { is_title_created = no }
				}
				create_title_and_vassal_change = {
					type = created
					save_scope_as = change
					add_claim_on_loss = no
				}
				duchy = {
					# Make the guy.
					change_title_holder = {
						holder = scope:attacker
						change = scope:change
					}
					# Cheekily whack it in the OG list so the logic doesn't break.
					add_to_list = titles_taken
				}
				resolve_title_and_vassal_change = scope:change
			}
		}
		### Vassals.
		every_in_list = {
			list = vassals_taken
			limit = {
				NOT = {
					any_held_title = {
						any_this_title_or_de_jure_above = { is_in_list = attacker_pre_held_titles }
					}
				}
			}
			# Track the transfer of everyone.
			add_to_list = vassals_to_transfer_all
			scope:attacker = {
				increment_variable_effect = {
					VAR = vassal_tally_all
					VAL = prev.sub_realm_size
				}
			}
			# And the transfer of just those that wouldn't stay with your prize county.
			if = {
				limit = {
					exists = scope:prize_county
					NOT = {
						any_held_title = {
							any_this_title_or_de_jure_above = { this = scope:prize_county.duchy }
						}
					}
				}
				add_to_list = vassals_to_transfer_prize
				scope:attacker = {
					increment_variable_effect = {
						VAR = vassal_tally_prize
						VAL = prev.sub_realm_size
					}
				}
			}
		}
		### Counties.
		every_in_list = {
			list = titles_taken
			limit = {
				NOT = {
					any_this_title_or_de_jure_above = { is_in_list = attacker_pre_held_titles }
				}
			}
			# Track the transfer of everything.
			add_to_list = titles_to_transfer_all
			scope:attacker = {
				increment_variable_effect = {
					VAR = title_tally_all
					VAL = 1
				}
			}
			# And the transfer of just those that wouldn't stay with your prize county.
			if = {
				limit = {
					exists = scope:prize_county
					NOR = {
						this = scope:prize_county.duchy
						duchy = scope:prize_county.duchy
					}
				}
				add_to_list = titles_to_transfer_prize
				scope:attacker = {
					increment_variable_effect = {
						VAR = title_tally_prize
						VAL = 1
					}
				}
			}
		}
		### Flag anything that has another rightful holder.
		every_in_list = {
			list = titles_taken
			limit = {
				tier = tier_county
				duchy.holder ?= {
					NOT = { this = scope:attacker }
					any_liege_or_above = { this = scope:attacker.liege }
					save_temporary_scope_as = legal_holder
				}
				# Don't give away our prize.
				trigger_if = {
					limit = { exists = scope:prize_county }
					NOR = {
						this = scope:prize_county.duchy
						duchy = scope:prize_county.duchy
					}
				}
			}
			add_to_list = rightful_holder_is_other_vassal_list
		}
		## We may choose to appoint interrim governors, in which case we want to know who those are.
		## First, let's assemble a rough candidates list.
		every_in_list = {
			list = target_titles
			title_capital_county.title_province = {
				save_scope_as = province_temp
				every_pool_character = {
					province = scope:province_temp
					limit = {
						# Some sensible restrictions.
						is_adult = yes
						has_any_bad_relationship_with_root_trigger = no
						# We want competent governors, civil or military.
						OR = {
							stewardship >= very_high_skill_rating
							martial >= very_high_skill_rating
						}
						# And make sure they're faith-valid.
						faith = { save_temporary_scope_as = faith_temp }
						"root.faith.faith_hostility_level(scope:faith_temp)" <= faith_astray_level
					}
					add_to_list = interim_governors_prefilter_list
				}
			}
		}
		## Set a control for how many times we'll want to iterate over the list.
		save_scope_value_as = {
			name = candidates_required
			value = "list_size(target_titles)"
		}
		## Ok, now we try to process people _within_ that list according to preferance.
		ordered_in_list = {
			list = interim_governors_prefilter_list
			order_by = {
				value = 1
			}
			check_range_bounds = no
			max = scope:candidates_required
			add_to_list = interim_governors_actual_list
		}
		## Finally, we save the relative list sizes for use as a comparator in one of the option triggers.
		### Transfer all title lists size.
		save_scope_value_as = {
			name = transfer_all_size
			value = {
				every_in_list = {
					list = vassals_to_transfer_all
					add = 1
				}
				every_in_list = {
					list = titles_to_transfer_all
					add = 1
				}
			}
		}
		### Reserve prize title lists size.
		save_scope_value_as = {
			name = transfer_prize_size
			value = {
				every_in_list = {
					list = vassals_to_transfer_prize
					add = 1
				}
				every_in_list = {
					list = titles_to_transfer_prize
					add = 1
				}
			}
		}
	}

	# Keep them all.
	option = {
		name = diarchy.8011.a
		trigger = { diarchy_8011_has_titles_to_transfer = yes }

		# You keep _everything_.
		custom_tooltip = diarchy.8011.tt.all_lands_remain_in_your_custody
		# Lose opinion with the emps scaling according to how many titles you were fighting for.
		reverse_add_opinion = {
			target = liege
			modifier = suspicion_opinion
			opinion = {
				value = -10
				multiply = {
					every_in_list = {
						list = target_titles
						add = 1
					}
				}
			}
		}
		# Fire the event for the emperor.
		save_scope_value_as = {
			name = war_result
			value = flag:keeping_all
		}
		scope:attacker.liege = { trigger_event = diarchy.8012 }

		stress_impact = {
			ambitious = major_stress_impact_loss
			arrogant = medium_stress_impact_loss
			greedy = minor_stress_impact_loss
			generous = minor_stress_impact_gain
			humble = medium_stress_impact_gain
			content = major_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -1
			}
		}
	}
	
	# Turn them over.
	option = {
		name = diarchy.8011.b
		trigger = { diarchy_8011_has_titles_to_transfer = yes }

		# Lose anything you shouldn't have legally owned.
		custom_tooltip = diarchy.8011.tt.distribution.lands_given_to_emperor
		# Turn them over to the emperor.
		diarchy_8011_turn_over_titles = {
			VASSAL_TRANSFER_LIST = vassals_to_transfer_all
			TITLE_TRANSFER_LIST = titles_to_transfer_all
			VASSAL_VAR = vassal_tally_all
			INFLUENCE_TOOLTIP_TITLE = request_imperial_expedition_influence_from_counties_full_value
			INFLUENCE_TOOLTIP_VASSAL = request_imperial_expedition_influence_from_vassals_full_value
		}
		# Who is, naturally, quite happy about this.
		reverse_add_opinion = {
			target = liege
			modifier = suspicion_opinion
			opinion = {
				value = 10
				multiply = {
					every_in_list = {
						list = target_titles
						add = 1
					}
				}
			}
		}
		# Handle the dregs.
		diarchy_8011_process_niche_titles = yes
		# Fire the event for the emperor.
		save_scope_value_as = {
			name = war_result
			value = flag:turning_over_all
		}
		scope:attacker.liege = { trigger_event = diarchy.8012 }

		stress_impact = {
			content = major_stress_impact_loss
			humble = medium_stress_impact_loss
			generous = minor_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = medium_stress_impact_gain
			ambitious = major_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_honor = 1
				ai_boldness = -1
			}
		}
	}
	
	# Keep the duchy with the highest development county.
	option = {
		name = diarchy.8011.c
		trigger = {
			exists = scope:prize_county
			scope:transfer_all_size > scope:transfer_prize_size
			diarchy_8011_has_titles_to_transfer = yes
		}

		# We'll keep scope:prize_county & its attached lands.
		custom_tooltip = diarchy.8011.tt.distribution.reserve_prize
		# Turn the rest over to the emperor.
		diarchy_8011_turn_over_titles = {
			VASSAL_TRANSFER_LIST = vassals_to_transfer_prize
			TITLE_TRANSFER_LIST = titles_to_transfer_prize
			VASSAL_VAR = vassal_tally_prize
			INFLUENCE_TOOLTIP_TITLE = request_imperial_expedition_influence_from_counties_prize_value
			INFLUENCE_TOOLTIP_VASSAL = request_imperial_expedition_influence_from_vassals_prize_value
		}
		# Still pretty happy — you can't be begrudged a bit of a share, after all.
		reverse_add_opinion = {
			target = liege
			modifier = pleased_opinion
			opinion = {
				value = 10
				multiply = {
					every_in_list = {
						list = target_titles
						add = 1
					}
				}
				# Subtract the target duchy we kept for ourselves.
				add = -10
				# And make sure we never try to add 0 opinion (i.e., because we had two target duchies).
				min = 10
			}
		}
		# Handle the dregs.
		diarchy_8011_process_niche_titles = yes
		# Fire the event for the emperor.
		save_scope_value_as = {
			name = war_result
			value = flag:turning_over_most
		}
		scope:attacker.liege = { trigger_event = diarchy.8012 }

		stress_impact = {
			ambitious = medium_stress_impact_loss
			arrogant = minor_stress_impact_loss
			greedy = miniscule_stress_impact_loss
			generous = miniscule_stress_impact_gain
			humble = minor_stress_impact_gain
			content = medium_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 1
				ai_rationality = 1
			}
		}
	}
	
	# Appoint interim governors.
	option = {
		name = diarchy.8011.d
		trigger = { diarchy_8011_has_titles_to_transfer = yes }

		# Ok, let's parse out some titles!
		## Your stuff is gonna get handed out to a whole bunch of dudes.
		custom_tooltip = diarchy.8011.tt.distribution.interim_governors
		custom_tooltip = diarchy.8011.tt.distribution.interim_governors.hook_and_opinion
		## Begin handing out actual titles.
		hidden_effect = {
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = yes
			}
			# Transfer vassals.
			every_in_list = {
				list = vassals_to_transfer_all
				change_liege = {
					liege = scope:attacker.liege
					change = scope:change
				}
			}
			# Transfer titles.
			every_in_list = {
				list = titles_to_transfer_all
				limit = { tier >= tier_duchy }
				# Try to find a suitable governor.
				## First grabbing them from the list.
				random_in_list = {
					list = interim_governors_actual_list
					limit = {
						NOT = { is_in_list = governors_used_list }
					}
					save_scope_as = interim_gov_temp
					add_to_list = governors_used_list
				}
				## But if we come back empty-handed, then we can just make someone from the duchy.
				if = {
					limit = {
						NOT = { exists = scope:interim_gov_temp }
					}
					# If we like the local faith enough, take that.
					if = {
						limit = {
							title_capital_county.faith = { save_temporary_scope_as = faith_temp }
							"root.faith.faith_hostility_level(scope:faith_temp)" <= faith_astray_level
						}
						scope:faith_temp = { save_scope_as = new_gov_faith }
					}
					# Else take ours.
					else = {
						scope:attacker.faith = { save_scope_as = new_gov_faith }
					}
					create_character = {
						template = ep3_magistrate_character
						location = root.capital_province
						culture = title_capital_county.culture
						faith = scope:new_gov_faith
						save_scope_as = interim_gov_temp
					}
				}
				# Transfer all the relevant counties.
				every_de_jure_county = {
					limit = { is_in_list = titles_to_transfer_all }
					change_title_holder = {
						holder = scope:interim_gov_temp
						change = scope:change
						take_baronies = yes
					}
				}
				# Then the duchy itself.
				change_title_holder = {
					holder = scope:interim_gov_temp
					change = scope:change
					take_baronies = yes
				}
				# Note whose governments we'll need to adjust — we do this here because we're clearing the scope in a sec + they aren't fully landed till have we resolve.
				scope:interim_gov_temp = { add_to_list = char_govs_to_change_list }
				# Remove the governor we just used so that we can see if we need to create someone.
				clear_saved_scope = interim_gov_temp
			}
			resolve_title_and_vassal_change = scope:change
			every_in_list = {
				list = char_govs_to_change_list
				# Force everyone to be governors.
                if = {
                    limit = {
                        NOT = { government_has_flag = government_is_republic }
                        NOT = { government_has_flag = government_is_theocracy }
                        NOT = { government_has_flag = government_is_administrative }
                    }
				    change_government = administrative_government
                }
				# Also you get a hook + opinion with each new governor.
				## This thing is truculent as all hell and will just error stubbornly simply because we have the temerity to apply effects to a hidden list before we've populated that list (and we do _this_ because we don't know who's in it).
				### It works fine, it just hates me. Ignore its lies.
				save_temporary_scope_as = char_temp
				root = {
					add_favour_hook_if_possible_simple_effect = { TARGET = scope:char_temp }
				}
				## This'll works zero errors though.
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 100
				}
			}
		}
		## Including any dregs.
		diarchy_8011_process_niche_titles = yes
		# Gain influence per county.
		custom_tooltip = {
			text = diarchy_8011.turn_over_titles.tt.interim_governors.county
			change_influence = scope:attacker.request_imperial_expedition_influence_from_counties_reduced_value
		}
		# Gain influence per vassal by their size.
		if = {
			limit = { var:vassal_tally_all >= 1 }
			custom_tooltip = {
				text = diarchy_8011.turn_over_titles.tt.interim_governors.vassal
				change_influence = scope:attacker.request_imperial_expedition_influence_from_vassals_reduced_value
			}
		}
		# Emps is still pretty happy — you're not building too much of a threat.
		reverse_add_opinion = {
			target = liege
			modifier = reputation_opinion
			opinion = {
				value = 5
				multiply = {
					every_in_list = {
						list = target_titles
						add = 1
					}
				}
			}
		}
		# Fire the event for the emperor.
		save_scope_value_as = {
			name = war_result
			value = flag:interim_governors
		}
		scope:attacker.liege = { trigger_event = diarchy.8012 }

		# No stress here, it's the compromise option.
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_rationality = 1
				ai_sociability = 1
			}
		}
	}
	
	# It is perfectly legal.
	option = {
		name = diarchy.8011.e
		trigger = { diarchy_8011_has_titles_to_transfer = no }

		# You cheeky fucker.
		custom_tooltip = diarchy.8011.e.tt.keep_everything_but_legally
		# Fire the event for the emperor.
		save_scope_value_as = {
			name = war_result
			value = flag:legal_shenanigans
		}
		scope:attacker.liege = { trigger_event = diarchy.8012 }

		# No stress here, we're just covering an edge case.
		# Nor do we need AI chance: if you get this option, you got literally no others.
	}

	after = {
		# Clean up our variables.
		remove_variable = vassal_tally_all
		remove_variable = vassal_tally_prize
		remove_variable = title_tally_all
		remove_variable = title_tally_prize
	}
}

#	War result.
diarchy.8012 = {
	type = letter_event
	opening = diarchy.8012.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:war_result = flag:keeping_all }
				desc = diarchy.8012.desc.keeping_all
			}
			triggered_desc = {
				trigger = { scope:war_result = flag:turning_over_all }
				desc = diarchy.8012.desc.turning_over_all
			}
			triggered_desc = {
				trigger = { scope:war_result = flag:turning_over_most }
				desc = diarchy.8012.desc.turning_over_most
			}
			triggered_desc = {
				trigger = { scope:war_result = flag:interim_governors }
				desc = diarchy.8012.desc.interim_governors
			}
			triggered_desc = {
				trigger = { scope:war_result = flag:legal_shenanigans }
				desc = diarchy.8012.desc.legal_shenanigans
			}
		}
	}
	sender = scope:attacker

	immediate = {
		switch = {
			trigger = scope:war_result
			flag:keeping_all = { custom_tooltip = diarchy.8012.tt.keeping_all }
			flag:turning_over_all = { custom_tooltip = diarchy.8012.tt.turning_over_all }
			flag:turning_over_most = { custom_tooltip = diarchy.8012.tt.turning_over_most }
			flag:interim_governors = { custom_tooltip = diarchy.8012.tt.interim_governors }
			flag:legal_shenanigans = { custom_tooltip = diarchy.8012.tt.legal_shenanigans }
		}
	}

	# Acknowledged.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:war_result = flag:keeping_all }
						desc = diarchy.8012.desc.a.keeping_all
					}
					triggered_desc = {
						trigger = { scope:war_result = flag:turning_over_all }
						desc = diarchy.8012.desc.a.turning_over_all
					}
					triggered_desc = {
						trigger = { scope:war_result = flag:turning_over_most }
						desc = diarchy.8012.desc.a.turning_over_most
					}
					triggered_desc = {
						trigger = { scope:war_result = flag:interim_governors }
						desc = diarchy.8012.desc.a.interim_governors
					}
					triggered_desc = {
						trigger = { scope:war_result = flag:legal_shenanigans }
						desc = diarchy.8012.desc.a.legal_shenanigans
					}
				}
			}
		}

		# No stress or AI chance needed for a notification event.
	}
}

##################################################
# Maiming Co-Emperors For Fun & Profit
# by Ewan Cowhig Croft
# 8021 - 8030
##################################################

scripted_trigger administrative_player_is_related_to_maiming_participant_trigger = {
	OR = {
		is_consort_of = $PARTICIPANT$
		is_close_or_extended_family_of = $PARTICIPANT$
		$PARTICIPANT$.house ?= house
	}
}

scripted_effect determine_which_bit_was_chopped_off_recipient_effect = {
	show_as_tooltip = {
		switch = {
			trigger = yes
			scope:maim_castrate = {
				scope:recipient = { add_trait_force_tooltip = eunuch_1 }
			}
			scope:maim_blind = {
				scope:recipient = { add_trait_force_tooltip = blind }
			}
			scope:maim_face = {
				scope:recipient = { add_trait_force_tooltip = disfigured }
			}
			scope:maim_arm = {
				scope:recipient = { apply_maimed_trait_and_modifier_effect = yes }
			}
			scope:maim_leg = {
				scope:recipient = { add_trait_force_tooltip = one_legged }
			}
		}
	}
}

#	Teach the AI to be judicious with their political maimings.
diarchy.8021 = {
	hidden = yes

	# Note that characters who don't fulfil the below may still run the interaction, just not commonly, whereas characters who _do_ will fulfil it near-instantly.
	## We deliberately avoid positive relationship reasons: friends, lovers, and family alike were slaughtered for the throne.
	trigger = {
		scope:imprisoner = {
			OR = {
				AND = {
					is_diarch_of_target = root
					root = { has_diarchy_parameter = diarchy_is_co_rulership }
				}
				AND = {
					diarch ?= root
					has_diarchy_parameter = diarchy_is_co_rulership
				}
			}
			ai_diarch_would_maim_execute_superior_if_got_chance_trigger = { LIEGE = root }
		}
	}

	immediate = {
		# Try to only maim if we can.
		if = {
			limit = {
				scope:imprisoner = {
					is_character_interaction_valid = {
						interaction = systematically_maim_character_interaction
						recipient = root
					}
				}
			}
			run_interaction = {
				interaction = systematically_maim_character_interaction
				actor = scope:imprisoner
				recipient = root
				execute_threshold = accept
			}
		}
		# Otherwise, they're for the more permanent chop.
		else_if = {
			limit = {
				scope:imprisoner = {
					is_character_interaction_valid = {
						interaction = execute_prisoner_interaction
						recipient = root
					}
				}
			}
			run_interaction = {
				interaction = execute_prisoner_interaction
				actor = scope:imprisoner
				recipient = root
				execute_threshold = accept
			}
		}
	}
}

#	Co-emperor maimed & cast aside.
diarchy.8022 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_alive = yes }
				}
				desc = diarchy.8022.t
			}
			desc = diarchy.8022.t.dead
		}
	}
	desc = {
		desc = diarchy.8022.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_alive = no }
				}
				desc = diarchy.8022.desc.dead
			}
			desc = diarchy.8022.desc.maimed
		}
		desc = diarchy.8022.desc.outro
	}
	theme = emperor
	left_portrait = {
		character = scope:actor
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = {
				scope:recipient = { is_alive = yes }
			}
			animation = fear
		}
		triggered_animation = {
			trigger = {
				scope:recipient = { is_alive = no }
			}
			animation = map_fear
		}
	}

	immediate = {
		if = {
			limit = {
				scope:recipient = { is_alive = yes }
			}
			custom_tooltip = diarchy.8022.tt.explanation
			determine_which_bit_was_chopped_off_recipient_effect = yes
		}
	}

	# An outrageous crime!
	option = {
		name = diarchy.8022.a
		trigger = {
			administrative_player_is_related_to_maiming_participant_trigger = { PARTICIPANT = scope:recipient }
		}

		# No stress or AI needed for a notification event.
	}
	
	# This was the best possible outcome.
	option = {
		name = diarchy.8022.b
		trigger = {
			administrative_player_is_related_to_maiming_participant_trigger = { PARTICIPANT = scope:actor }
		}

		# No stress or AI needed for a notification event.
	}
	
	# So it goes in GetCapitalLocation.
	option = {
		name = diarchy.8022.c
		trigger = { always = yes }

		# No stress or AI needed for a notification event.
	}
}

#	Senior emperor maimed and usurped.
diarchy.8023 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_alive = yes }
				}
				desc = diarchy.8023.t
			}
			desc = diarchy.8022.t.dead
		}
	}
	desc = {
		desc = diarchy.8023.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient = { is_alive = no }
				}
				desc = diarchy.8023.desc.dead
			}
			desc = diarchy.8023.desc.maimed
		}
		desc = diarchy.8023.desc.outro
		triggered_desc = {
			trigger = {
				scope:recipient = { is_alive = yes }
			}
			desc = diarchy.8023.desc.outro.alive
		}
	}
	theme = emperor
	left_portrait = {
		character = scope:actor
		animation = schadenfreude
	}
	right_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = {
				scope:recipient = { is_alive = yes }
			}
			animation = fear
		}
		triggered_animation = {
			trigger = {
				scope:recipient = { is_alive = no }
			}
			animation = map_fear
		}
	}

	immediate = {
		custom_tooltip = diarchy.8023.tt.explanation
		if = {
			limit = {
				scope:recipient = { is_alive = yes }
			}
			determine_which_bit_was_chopped_off_recipient_effect = yes
		}
	}

	# The GetHouseNames take their rightful place at last.
	option = {
		name = diarchy.8023.a
		trigger = {
			exists = scope:actor.house
			exists = scope:recipient.house
			scope:recipient.house != scope:actor.house
			administrative_player_is_related_to_maiming_participant_trigger = { PARTICIPANT = scope:actor }
		}

		# No stress or AI needed for a notification event.
	}
	
	# This is usurpation!
	option = {
		name = diarchy.8023.b
		trigger = {
			administrative_player_is_related_to_maiming_participant_trigger = { PARTICIPANT = scope:recipient }
		}

		# No stress or AI needed for a notification event.
	}
	
	# So it goes in GetCapitalLocation.
	option = {
		name = diarchy.8023.c
		trigger = { always = yes }

		# No stress or AI needed for a notification event.
	}
}

##################################################
# Request Despotate
# by Ewan Cowhig Croft
# 8031 - 8040
##################################################

#	Your request for a despotate has been granted.
diarchy.8031 = {
	type = letter_event
	opening = diarchy.8031.t
	desc = diarchy.8031.desc
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		diarch_demand_despotate_interaction_accepted_effect = yes
	}

	# Excellent.
	option = {
		name = diarchy.8031.a

		# No stress or AI chance needed for a notification event.
	}
}

#	Your request for a despotate has been refused.
diarchy.8032 = {
	type = letter_event
	opening = diarchy.8032.t
	desc = diarchy.8032.desc
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		diarch_demand_despotate_interaction_rejected_effect = yes
	}

	# Bah, they're intimidated by me!
	option = {
		name = diarchy.8032.a

		# No stress or AI chance needed for a notification event.
	}
}

#	You've been forced to agree to your co-emperor a despotate.
diarchy.8033 = {
	type = letter_event
	opening = diarchy.8033.t
	desc = {
		desc = diarchy.8033.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:hook = yes }
				desc = diarchy.8033.desc.hook
			}
			desc = diarchy.8033.desc.insufficient_influence
		}
	}
	sender = scope:recipient

	immediate = {
		# Apply interaction effects.
		show_as_tooltip = { diarch_demand_despotate_interaction_accepted_effect = yes }
		# Confirm what happened if it wouldn't have showed otherwise.
		if = {
			limit = { scope:hook = no }
			custom_tooltip = diarchy.8033.tt.influence
		}
	}

	# Sonuva
	option = {
		name = diarchy.8033.a

		# No stress or AI chance needed for a notification event.
	}
}

##################################################
# Scapegoat Co-Emperor
# by Ewan Cowhig Croft
# 8041 - 8050
##################################################

#	Your Senior Emperor is slagging you off.
diarchy.8041 = {
	type = letter_event
	opening = diarchy.8041.t
	desc = diarchy.8041.desc
	sender = scope:actor

	immediate = {
		# Actual effects applied after these events are sent out back in the interaction.
		show_as_tooltip = {
			scapegoat_counterpart_interaction_process_results_effect = {
				REALM_OPINION_ACTOR = add_tyranny
				REALM_OPINION_RECIPIENT = change_strife_opinion
			}
		}
	}

	# Confounded ingrate!
	option = {
		name = diarchy.8041.a
		trigger = { this = scope:recipient }

		# No stress or AI chance needed for a notification event.
	}

	# Mum and dad are fighting again.
	option = {
		name = diarchy.8041.b
		trigger = { this != scope:recipient }

		# No stress or AI chance needed for a notification event.
	}
}

#	Your Co-Emperor is slagging you off.
diarchy.8042 = {
	type = letter_event
	opening = diarchy.8042.t
	desc = diarchy.8042.desc
	sender = scope:actor

	immediate = {
		# Actual effects applied after these events are sent out back in the interaction.
		show_as_tooltip = {
			scapegoat_counterpart_interaction_process_results_effect = {
				REALM_OPINION_ACTOR = change_strife_opinion
				REALM_OPINION_RECIPIENT = add_tyranny
			}
		}
	}

	# Confounded ingrate!
	option = {
		name = diarchy.8042.a
		trigger = { this = scope:recipient }

		# No stress or AI chance needed for a notification event.
	}

	# Mum and dad are fighting again.
	option = {
		name = diarchy.8042.b
		trigger = { this != scope:recipient }

		# No stress or AI chance needed for a notification event.
	}
}










##################################################
# DECISIONS - GENERIC SCRIPTED TRIGGERS & EFFECTS

# Do you have a proxy available who might be a separate actor in the event?
## NOT considering whether they've betrayed scope:liege yet or not.
scripted_trigger diarch_9000_valid_yet_betrayable_proxy_trigger = {
	is_available = yes
	NOT = { this = scope:usurper }
}

# Try to grab scope:liege's highest held title tiers & vassals.
scripted_effect diarch_coup_attempt_take_highest_held_title_tiers_effect = {
	# Save a reference point.
	scope:liege.primary_title = { save_scope_as = liege_primary }
	# Grab the relevant titles'n'vassals.
	scope:liege = {
		# Gather every top-tier title scope:liege has.
		every_held_title = {
			limit = {
				this = scope:liege_primary
				is_head_of_faith = no
			}
			alternative_limit = {
				tier = scope:liege_primary.tier
				is_head_of_faith = no
			}
			add_to_list = top_tier_titles_list
		}
		# Plus all those tasty vassals.
		every_vassal = { add_to_list = direct_vassals_list }
	}
	# Now, let's do some painful transfers.
	create_title_and_vassal_change = {
		type = usurped
		save_scope_as = title_change
	}
	## Swap the titles.
	every_in_list = {
		list = top_tier_titles_list
		change_title_holder = {
			holder = scope:usurper
			change = scope:title_change
		}
	}
	## We don't need to show the vassalage changes, they're implicit.
	hidden_effect = {
		every_in_list = {
			list = direct_vassals_list
			limit = {
				NOT = { this = scope:usurper }
			}
			change_liege = {
				liege = scope:usurper
				change = scope:title_change
			}
		}
		scope:liege = {
			change_liege = {
				liege = scope:usurper
				change = scope:title_change
			}
		}
	}
	resolve_title_and_vassal_change = scope:title_change
}

# Try to take the largest de facto kingdom in scope:liege's realm if they're an empire so that they're not left with a big powerbase.
scripted_effect diarch_coup_attempt_take_largest_de_facto_kingdom_effect = {
	if = {
		limit = {
			diarch_coup_attempt_grabbable_kingdom_trigger = { TARGET = scope:liege }
		}
		# Alright, grab the kingdom title with the most de facto counties within the primary title.
		ordered_held_title = {
			limit = {
				diarch_coup_attempt_grabbable_kingdom_guts_trigger = { TARGET = scope:liege }
			}
			order_by = {
				every_de_jure_county = {
					limit = {
						holder = {
							any_liege_or_above = { this = scope:liege }
						}
					}
					add = 1
				}
			}
			save_scope_as = grabbable_kingdom
		}
		# Now transfer that too.
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = title_change
		}
		scope:grabbable_kingdom = {
			change_title_holder = {
				holder = scope:usurper
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
}

# Try to take scope:liege's de jure capital, plus the duchy and its lands.
## If scope:liege surrendered, leave them with some kinda playable lands.
scripted_effect diarch_coup_attempt_take_de_jure_capital_and_duchy_effect = {
	if = {
		limit = {
			any_held_title = {
				diarch_coup_attempt_grabbable_capital_and_duchies_trigger = { TARGET = scope:liege }
			}
		}
		# Double check - do we need to grab a spare county for scope:liege to inhabit?
		## To process this adequately, we'll need to set up a list, as otherwise non-matching titles will through the count off.
		every_held_title = {
			limit = {
				diarch_coup_attempt_grabbable_capital_and_duchies_trigger = { TARGET = scope:liege }
			}
			add_to_list = grabbable_capital_counties_and_duchy_list
		}
		## Now, check the list to see if there's any spare candidate for scope:liege to fall back to.
		if = {
			limit = {
				AND = {
					exists = scope:liege_action
					scope:liege_action = flag:surrendered
				}
				any_held_title = {
					count = all
					tier = tier_county
					is_in_list = grabbable_capital_counties_and_duchy_list
				}
			}
			# Grab the most loyal vassal we have.
			ordered_vassal_or_below = {
				limit = {
					is_ai = yes
					NOT = {
						any_liege_or_above = { this = scope:usurper }
					}
					any_held_title = {
						tier = tier_county
						count >= 2
					}
				}
				alternative_limit = {
					is_ai = yes
					any_held_title = {
						tier = tier_county
						count >= 2
					}
				}
				alternative_limit = { is_ai = yes }
				alternative_limit = {
					any_held_title = {
						tier = tier_county
						count >= 2
					}
				}
				order_by = {
					# Opinion.
					add = "opinion(liege)"
					# Plus weight up a bit more for higher tier vassals.
					add = highest_held_title_tier
				}
				# Now, pick a suitable county for them to donate.
				ordered_held_title = {
					limit = {
						tier = tier_county
						NOT = { this = prev.capital_county }
					}
					alternative_limit = { tier = tier_county }
					order_by = development_level
					save_scope_as = emergency_refuge
				}
			}
		}
		# Do we have to sort a refuge?
		if = {
			limit = { exists = scope:emergency_refuge }
			# We do a separate transfer because we don't want to include claims.
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = title_change
				add_claim_on_loss = no
			}
			scope:emergency_refuge = {
				change_title_holder = {
					holder = scope:liege
					change = scope:title_change
				}
			}
			resolve_title_and_vassal_change = scope:title_change
		}
		create_title_and_vassal_change = {
			type = usurped
			save_scope_as = title_change
		}
		# Do the main transfer.
		every_in_list = {
			list = grabbable_capital_counties_and_duchy_list
			change_title_holder = {
				holder = scope:usurper
				change = scope:title_change
			}
		}
		resolve_title_and_vassal_change = scope:title_change
	}
}

# Hand out the rewards scope:usurper promised their conspirators.
scripted_effect diarch_coup_attempt_usurper_opinion_effect = {
	# Hooks.
	every_in_list = {
		list = coup_promise_list_weak_hook_final
		add_hook = {
			type = minor_crime_accomplice_hook
			target = scope:usurper
			years = 30
		}
	}
	# Strong hooks.
	every_in_list = {
		list = coup_promise_list_strong_hook_final
		add_hook = {
			type = major_crime_accomplice_hook
			target = scope:usurper
		}
	}
	# Golb.
	every_in_list = {
		list = coup_promise_list_gold_final
		save_temporary_scope_as = char_temp
		scope:usurper = {
			pay_short_term_gold = {
				target = scope:char_temp
				gold = major_gold_value
			}
		}
	}
	# Bog golb.
	every_in_list = {
		list = coup_promise_list_big_gold_final
		save_temporary_scope_as = char_temp
		scope:usurper = {
			pay_short_term_gold = {
				target = scope:char_temp
				gold = massive_gold_value
			}
		}
	}
}

# Process the general mass of effects when scope:usurper succeeds, including some tooltips'n'OoO stuff.
scripted_effect diarch_coup_attempt_standard_suite_effect = {
	scope:liege = {
		# Show in this order for presentation reasons...
		show_as_tooltip = {
			diarch_coup_attempt_take_highest_held_title_tiers_effect = yes
			diarch_coup_attempt_take_largest_de_facto_kingdom_effect = yes
			diarch_coup_attempt_take_de_jure_capital_and_duchy_effect = yes
		}
		# ... even though we have a different actual order for O-o-O reasons.
		hidden_effect = {
			diarch_coup_attempt_take_de_jure_capital_and_duchy_effect = yes
			diarch_coup_attempt_take_largest_de_facto_kingdom_effect = yes
			diarch_coup_attempt_take_highest_held_title_tiers_effect = yes
		}
	}
	# Scope:usurper receives strife.
	scope:usurper = {
		if = {
			limit = { strife_opinion >= 1 }
			# Diplomacy coups reduce strife-tyranny conversion.
			if = {
				limit = { scope:coup_diplomacy = yes }
				add_tyranny = {
					value = strife_opinion
					multiply = 0.25
				}
				custom_tooltip = diarch_coup_attempt_standard_suite_effect.tt.reduced_amount
			}
			# Otherwise, do the standard amount.
			else = {
				add_tyranny = {
					value = strife_opinion
					multiply = 0.5
				}
			}
		}
	}
	# Scope:usurper has debts to pay, but only they need to see 'em.
	if = {
		limit = { this = scope:usurper }
		diarch_coup_attempt_usurper_opinion_effect = yes
	}
	hidden_effect = { diarch_coup_attempt_usurper_opinion_effect = yes }
	# Finally, clean up the variables.
	scope:usurper = { diarch_clean_up_conspiracy_variables_effect = yes }
}

# We imprison the liege after successful intrigue coups.
## Mostly in here in case we want to add anything fancy to imprisonment in future.
scripted_effect diarch_coup_attempt_imprison_liege_effect = {
	hard_imprison_character_effect = {
		TARGET = scope:liege
		IMPRISONER = scope:usurper
	}
}

# Give scope:liege criminal opinions on everyone who betrays them.
scripted_effect diarch_coup_attempt_apply_opinion_effect = {
	# All moot if scope:liege is dead.
	if = {
		limit = {
			scope:liege = { is_alive = no }
		}
		scope:usurper = {
			reverse_add_opinion = {
				modifier = orchestrated_coup_opinion
				target = scope:liege
			}
		}
		# Only scope:liege really needs to see how pissed they get with the lesser conspirators, and the player doesn't much care, so we hide this.
		hidden_effect = {
			every_in_list = {
				list = coup_pv_supporters_final_list
				reverse_add_opinion = {
					modifier = rebellious_vassal_opinion
					target = scope:liege
				}
			}
		}
	}
}

# Try to remove the diarchy, else depose the diarch and reset the SoP.
scripted_effect diarch_coup_attempt_end_diarchy_effect = {
	# Remove the diarchy if we can.
	if = {
		limit = { can_leave_diarchy_trigger = yes }
		end_diarchy = yes
	}
	# Else depose the current diarch.
	else = {
		set_diarchy_swing = 0
		scope:usurper = { depose_diarch = yes }
	}
}

# Try to imprison scope:usurper, if applicable, and either end the diarchy if we can or else set the swing waaaaaaaaay back to 0.
scripted_effect diarch_coup_attempt_imprison_usurper_effect = {
	# Try to end the diarchy.
	diarch_coup_attempt_end_diarchy_effect = yes
	# And to the dungeon you go.
	rightfully_imprison_character_effect = {
		TARGET = scope:usurper
		IMPRISONER = scope:liege
	}
	# Plus grab the lesser conspirators.
	every_in_list = {
		list = coup_pv_supporters_final_list
		save_temporary_scope_as = char_temp
		# If a player has somehow wandered in here, don't inconvenience them.
		limit = { is_ai = yes }
		rightfully_imprison_character_effect = {
			TARGET = scope:char_temp
			IMPRISONER = scope:liege
		}
	}
}

# Put truces in place so scope:liege doesn't get insta-screwed & can't insta-revolt.
scripted_effect diarch_coup_attempt_add_equal_truces_effect = {
	add_truce_both_ways = {
		character = scope:usurper
		years = 10
		name = diarch_coup_equal_truce
	}
}

# Put truces in place so scope:liege doesn't get insta-screwed & can't insta-revolt, but bias them in favour of scope:liege.
scripted_effect diarch_coup_attempt_add_unequal_truces_effect = {
	add_truce_one_way = {
		character = scope:usurper
		years = 5
		name = diarch_coup_unequal_truce_for_liege
	}
	scope:usurper = {
		add_truce_one_way = {
			character = scope:liege
			years = 25
			name = diarch_coup_unequal_truce_for_usurper
		}
	}
}

# Do the set up to determine whether scope:liege has anyone who'll stand in on HerHis behalf, or if the person who might is part of the conspiracy.
scripted_effect diarch_9000_create_proxy_and_check_for_betrayal_effect = {
	save_scope_as = proxy
	set_location = { location = scope:liege.location }
	# Cool, are they in on the conspiracy?
	if = {
		limit = {
			scope:usurper = {
				any_in_list = {
					variable = coup_pv_supporters_list
					this = scope:proxy
				}
			}
		}
		# Ayyup. Bugger.
		scope:liege = { add_character_flag = betrayed_by_proxy }
	}
}

# If you've got a vacant slot, you're probably gonna get a nickname for this.
scripted_effect diarch_9000_generic_nickname_after_effect = {
	hidden_effect = {
		scope:usurper = {
			if = {
				limit = { has_any_nickname = no }
				random_list = {
					# Generic nicknames.
					## Usurper
					### We weight this up so that you've got a 1:3-ish chance of being the Usurper for usurping.
					250 = { give_nickname = nick_the_usurper }
					## Betrayer
					100 = { give_nickname = nick_the_betrayer }
					## Traitor
					100 = { give_nickname = nick_the_traitor }
					## Oathbreaker
					100 = { give_nickname = nick_the_oathbreaker }
					# Diplo-specific nicknames.
					## Ruthless
					100 = {
						trigger = { scope:coup_diplomacy = yes }
						give_nickname = nick_the_ruthless
					}
					## Silver-Tongue
					100 = {
						trigger = { scope:coup_diplomacy = yes }
						give_nickname = nick_the_silver_tongue
					}
					# Intrigue-specific nicknames.
					## Selfish
					100 = {
						trigger = { scope:coup_intrigue = yes }
						give_nickname = nick_the_selfish
					}
					## Brute
					100 = {
						trigger = { scope:coup_intrigue = yes }
						give_nickname = nick_the_brute
					}
					# Prowess-specific nicknames.
					## Black
					100 = {
						trigger = { scope:coup_prowess = yes }
						give_nickname = nick_the_black
					}
					## Oppressor
					100 = {
						trigger = { scope:coup_prowess = yes }
						give_nickname = nick_the_oppressor
					}
				}
			}
		}
	}
}













##################################################
# DECISIONS

##################################################
# A Long Awaited Coup: Diplomacy
# by Ewan Cowhig Croft
# 9001 - 9010
##################################################

scripted_effect diarchy_9001_liege_successful_effect = {
	trigger_event = diarchy.9004
	scope:usurper = { trigger_event = diarchy.9005 }
	# Fire the actual effects instantaneously here.
	diarch_coup_attempt_imprison_usurper_effect = yes
}

scripted_effect diarchy_9001_usurper_successful_effect = {
	trigger_event = diarchy.9002
	scope:usurper = { trigger_event = diarchy.9003 }
	# Fire the actual effects instantaneously here.
	diarch_coup_attempt_standard_suite_effect = yes
}

#	You attempt to bloodlessly coup your liege.
diarchy.9001 = {
	type = character_event
	title = diarchy.9001.t
	desc = {
		desc = diarchy.9001.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:proxy }
				}
				desc = diarchy.9001.desc.proxy.none
			}
			triggered_desc = {
				trigger = { has_character_flag = betrayed_by_proxy }
				desc = diarchy.9001.desc.proxy.betrayed
			}
			desc = diarchy.9001.desc.proxy.loyal
		}
		desc = diarchy.9001.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		animation = marshal
	}
	lower_center_portrait = scope:proxy

	cooldown = { years = 10 }

	immediate = {
		play_music_cue = "mx_cue_murder"
		# Is there a proxy candidate?
		if = {
			limit = {
				# There needs to be someone to begin with and they need to be available locally.
				cp:councillor_chancellor ?= { diarch_9000_valid_yet_betrayable_proxy_trigger = yes }
			}
			# Alright, record them.
			cp:councillor_chancellor = { diarch_9000_create_proxy_and_check_for_betrayal_effect = yes }
		}
	}

	# Meet the challenge personally.
	option = {
		name = diarchy.9001.a
		trigger = { character_is_teen_or_older_trigger = yes }
		show_as_unavailable = { character_is_teen_or_older_trigger = no }
		skill = diplomacy

		save_scope_value_as = {
			name = liege_action
			value = flag:self_fought
		}
		duel = {
			skill = diplomacy
			target = scope:usurper
			# You shatter the conspiracy's unity.
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.9001.a.tt.success
				diarchy_9001_liege_successful_effect = yes
			}
			# It's a fait accomplit.
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.9001.a.tt.failure
				diarchy_9001_usurper_successful_effect = yes
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_equal_truces_effect = yes

		stress_impact = {
			brave = miniscule_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
			humble = minor_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = diplomacy
					subtract = scope:usurper.diplomacy
					multiply = 10
				}
				always = yes
			}
			# Arrogant chars want to act themselves.
			modifier = {
				add = 50
				has_trait = arrogant
			}
		}
	}
	
	# Send in scope:proxy.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { character_is_teen_or_older_trigger = yes }
						desc = diarchy.9001.b.fallback
					}
					desc = diarchy.9001.b.young
				}
			}
		}
		trigger = {
			exists = scope:proxy
			NOT = { has_character_flag = betrayed_by_proxy }
		}
		show_as_unavailable = { has_character_flag = betrayed_by_proxy }
		skill = diplomacy

		save_scope_value_as = {
			name = liege_action
			value = flag:proxy_fought
		}
		scope:proxy = {
			duel = {
				skill = diplomacy
				target = scope:usurper
				# You shatter the conspiracy's unity.
				60 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					desc = diarchy.9001.b.tt.success
					scope:liege = { diarchy_9001_liege_successful_effect = yes }
				}
				# It's a fait accomplit.
				40 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					desc = diarchy.9001.b.tt.failure
					scope:liege = { diarchy_9001_usurper_successful_effect = yes }
				}
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_equal_truces_effect = yes

		stress_impact = {
			craven = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_gain
			brave = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = -1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:usurper.intrigue
					multiply = 10
				}
				always = yes
			}
			## Vs. scope:liege.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:liege.intrigue
					multiply = 10
				}
				always = yes
			}
			# Humble chars want to defer to their skilled advisors.
			modifier = {
				add = 50
				has_trait = humble
			}
		}
	}
	
	# Acquiesce to the ultimatum.
	option = {
		name = diarchy.9001.c

		save_scope_value_as = {
			name = liege_action
			value = flag:surrendered
		}
		diarchy_9001_usurper_successful_effect = yes
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_unequal_truces_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			generous = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
			stubborn = major_stress_impact_gain
			ambitious = massive_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_boldness = -2 }
			# Cravens are a bit more likely to go along with this, but even then.
			modifier = {
				add = 25
				has_trait = craven
			}
		}
	}

	# Guards, GUARDS!
	option = {
		name = diarchy.9001.d
		# Player-only chance at making it through.
		trigger = { is_ai = no }

		random_list = {
			# Loyal guards arrive and arrest scope:usurper.
			20 = {
				desc = diarchy.9001.d.tt.win
				diarchy_9001_liege_successful_effect = yes
			}
			# Your last possible defenders are put down without mercy.
			80 = {
				desc = diarchy.9001.d.tt.loss
				diarchy_9001_usurper_successful_effect = yes
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			# No AI chance needed for player-only option.
			base = 1
		}
	}
}

#	Usurper won, liege-side.
diarchy.9002 = {
	type = character_event
	title = diarchy.9002.t
	desc = {
		desc = diarchy.9002.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9002.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9002.desc.proxy.self_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9002.desc.surrendered
			}
			desc = diarchy.9002.desc.scuffled
		}
		desc = diarchy.9002.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy

	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# How... how could this happen...
	option = {
		name = diarchy.9002.a

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	# My destiny. Undone.
	option = {
		name = diarchy.9002.b
		trigger = {
			exists = dynasty
			dynasty ?= scope:usurper.dynasty
			scope:usurper = { is_ai = yes }
		}

		set_player_character = scope:usurper

		# An uncomfortable transition — we still add it to be fair, but hide it so that we don't muddy the tooltips.
		hidden_effect = {
			stress_impact = { base = major_stress_impact_gain }
		}
		# No stress impact for player-only option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Usurper won, usurper-side.
diarchy.9003 = {
	type = character_event
	title = diarchy.9003.t
	desc = {
		desc = diarchy.9003.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9003.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9003.desc.proxy.self_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9003.desc.surrendered
			}
			desc = diarchy.9003.desc.scuffled
		}
		desc = diarchy.9003.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	right_portrait = {
		character = scope:liege
		animation = fear
	}
	lower_center_portrait = scope:proxy
	
	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
		# Achievements.
		if = {
			limit = {
				exists = global_var:started_your_eternal_reward_achievement
				is_ai = no
			}
			set_global_variable = {
				name = finished_your_eternal_reward_achievement
				value = yes
			}
		}
	}

	# This had to be done.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { exists = scope:liege_action }
						desc = diarchy.9003.a
					}
					desc = diarchy.9003.a.some_blood
				}
			}
		}

		# A prize for your efforts.
		add_prestige = major_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { diarch_9000_generic_nickname_after_effect = yes }
}

#	Liege won, liege-side.
diarchy.9004 = {
	type = character_event
	title = diarchy.9004.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9004.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9004.desc.proxy.self_fought
			}
			desc = diarchy.9004.desc.scuffled
		}
		desc = diarchy.9004.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	right_portrait = {
		character = scope:usurper
		animation = fear
	}
	lower_center_portrait = scope:proxy

	immediate = {
		show_as_tooltip = {
			# Prison changes.
			diarch_coup_attempt_imprison_usurper_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# I am the _GetTitleAsNameNoTooltip_.
	option = {
		name = diarchy.9004.a

		# What a bonanza!
		add_prestige = massive_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Liege won, usurper-side.
diarchy.9005 = {
	type = character_event
	title = diarchy.9005.t
	desc = {
		desc = diarchy.9005.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9005.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9005.desc.proxy.self_fought
			}
			desc = diarchy.9005.desc.scuffled
		}
		desc = diarchy.9005.desc.outro
	}
	theme = diplomacy
	left_portrait = {
		character = scope:usurper
		animation = fear
	}
	right_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy

	immediate = {
		show_as_tooltip = {
			# Prison changes.
			diarch_coup_attempt_imprison_usurper_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# It is over.
	option = {
		name = diarchy.9005.a

		# This doesn't bode well for you.
		add_prestige = massive_prestige_loss

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}
}


##################################################
# A Long Awaited Coup: Intrigue
# by Ewan Cowhig Croft
# 9011 - 9020
##################################################

scripted_effect diarchy_9011_liege_successful_effect = {
	trigger_event = diarchy.9014
	scope:usurper = { trigger_event = diarchy.9015 }
	# Fire the actual effects instantaneously here.
	diarch_coup_attempt_imprison_usurper_effect = yes
}

scripted_effect diarchy_9011_usurper_successful_effect = {
	trigger_event = diarchy.9012
	scope:usurper = { trigger_event = diarchy.9013 }
	# Fire the actual effects instantaneously here.
	diarch_coup_attempt_standard_suite_effect = yes
	# Plus, imprison scope:liege.
	diarch_coup_attempt_imprison_liege_effect = yes
}

#	You attempt to coup your liege with just a little bloodshed, threatened and actual.
diarchy.9011 = {
	type = character_event
	title = diarchy.9011.t
	desc = {
		desc = diarchy.9011.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:proxy }
				}
				desc = diarchy.9011.desc.proxy.none
			}
			triggered_desc = {
				trigger = { has_character_flag = betrayed_by_proxy }
				desc = diarchy.9011.desc.proxy.betrayed
			}
			desc = diarchy.9011.desc.proxy.loyal
		}
		desc = diarchy.9011.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		animation = hunting_knife_start
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	cooldown = { years = 10 }

	immediate = {
		play_music_cue = "mx_cue_murder"
		# Is there a proxy candidate?
		if = {
			limit = {
				# There needs to be someone to begin with and they need to be available locally.
				cp:councillor_spymaster ?= { diarch_9000_valid_yet_betrayable_proxy_trigger = yes }
			}
			# Alright, record them.
			cp:councillor_spymaster = { diarch_9000_create_proxy_and_check_for_betrayal_effect = yes }
		}
	}

	# Meet the challenge personally.
	option = {
		name = diarchy.9011.a
		trigger = { character_is_teen_or_older_trigger = yes }
		show_as_unavailable = { character_is_teen_or_older_trigger = no }
		skill = intrigue

		save_scope_value_as = {
			name = liege_action
			value = flag:self_fought
		}
		duel = {
			skill = intrigue
			target = scope:usurper
			# You shatter the conspiracy's unity.
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = diarchy.9011.a.tt.success
				diarchy_9011_liege_successful_effect = yes
			}
			# It's a fait accomplit.
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = diarchy.9011.a.tt.failure
				diarchy_9011_usurper_successful_effect = yes
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_equal_truces_effect = yes

		stress_impact = {
			brave = miniscule_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
			humble = minor_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = intrigue
					subtract = scope:usurper.intrigue
					multiply = 10
				}
				always = yes
			}
			# Arrogant chars want to act themselves.
			modifier = {
				add = 50
				has_trait = arrogant
			}
		}
	}
	
	# Send in scope:proxy.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { character_is_teen_or_older_trigger = yes }
						desc = diarchy.9011.b.fallback
					}
					desc = diarchy.9011.b.young
				}
			}
		}
		trigger = {
			exists = scope:proxy
			NOT = { has_character_flag = betrayed_by_proxy }
		}
		show_as_unavailable = { has_character_flag = betrayed_by_proxy }
		skill = intrigue

		save_scope_value_as = {
			name = liege_action
			value = flag:proxy_fought
		}
		scope:proxy = {
			duel = {
				skill = intrigue
				target = scope:usurper
				# You shatter the conspiracy's unity.
				60 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					desc = diarchy.9011.b.tt.success
					scope:liege = { diarchy_9011_liege_successful_effect = yes }
				}
				# It's a fait accomplit.
				40 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					desc = diarchy.9011.b.tt.failure
					scope:liege = { diarchy_9011_usurper_successful_effect = yes }
				}
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_equal_truces_effect = yes

		stress_impact = {
			craven = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_gain
			brave = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = -1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:usurper.intrigue
					multiply = 10
				}
				always = yes
			}
			## Vs. scope:liege.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:liege.intrigue
					multiply = 10
				}
				always = yes
			}
			# Humble chars want to defer to their skilled advisors.
			modifier = {
				add = 50
				has_trait = humble
			}
		}
	}
	
	# Acquiesce to the ultimatum.
	option = {
		name = diarchy.9011.c

		save_scope_value_as = {
			name = liege_action
			value = flag:surrendered
		}
		diarchy_9011_usurper_successful_effect = yes
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_unequal_truces_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			generous = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
			stubborn = major_stress_impact_gain
			ambitious = massive_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_boldness = -2 }
			# Cravens are a bit more likely to go along with this, but even then.
			modifier = {
				add = 25
				has_trait = craven
			}
		}
	}

	# Guards, GUARDS!
	option = {
		name = diarchy.9011.d
		# Player-only chance at making it through.
		trigger = { is_ai = no }

		random_list = {
			# Loyal guards arrive and arrest scope:usurper.
			20 = {
				desc = diarchy.9011.d.tt.win
				diarchy_9011_liege_successful_effect = yes
			}
			# Your last possible defenders are put down without mercy.
			80 = {
				desc = diarchy.9011.d.tt.loss
				diarchy_9011_usurper_successful_effect = yes
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			# No AI chance needed for player-only option.
			base = 1
		}
	}
}

#	Usurper won, liege-side.
diarchy.9012 = {
	type = character_event
	title = diarchy.9012.t
	desc = {
		desc = diarchy.9012.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9012.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9012.desc.proxy.self_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9012.desc.surrendered
			}
			desc = diarchy.9012.desc.scuffled
		}
		desc = diarchy.9012.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
			# Imprisonment.
			diarch_coup_attempt_imprison_liege_effect = yes
		}
	}

	# How... how could this happen...
	option = {
		name = diarchy.9012.a

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	# My destiny. Undone.
	option = {
		name = diarchy.9012.b
		trigger = {
			exists = dynasty
			dynasty ?= scope:usurper.dynasty
			scope:usurper = { is_ai = yes }
		}

		set_player_character = scope:usurper

		# An uncomfortable transition — we still add it to be fair, but hide it so that we don't muddy the tooltips.
		hidden_effect = {
			stress_impact = { base = major_stress_impact_gain }
		}
		# No stress impact for player-only option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Usurper won, usurper-side.
diarchy.9013 = {
	type = character_event
	title = diarchy.9013.t
	desc = {
		desc = diarchy.9013.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9013.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9013.desc.proxy.self_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9013.desc.surrendered
			}
			desc = diarchy.9013.desc.scuffled
		}
		desc = diarchy.9013.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	right_portrait = {
		character = scope:liege
		animation = fear
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
			# Imprisonment.
			diarch_coup_attempt_imprison_liege_effect = yes
		}
		# Achievements.
		if = {
			limit = {
				exists = global_var:started_your_eternal_reward_achievement
				is_ai = no
			}
			set_global_variable = {
				name = finished_your_eternal_reward_achievement
				value = yes
			}
		}
	}

	# This had to be done.
	option = {
		name = diarchy.9013.a

		# Might makes right, I suppose.
		add_prestige = major_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { diarch_9000_generic_nickname_after_effect = yes }
}

#	Liege won, liege-side.
diarchy.9014 = {
	type = character_event
	title = diarchy.9014.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9014.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9014.desc.proxy.self_fought
			}
			desc = diarchy.9014.desc.scuffled
		}
		desc = diarchy.9014.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	right_portrait = {
		character = scope:usurper
		animation = fear
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Prison changes.
			diarch_coup_attempt_imprison_usurper_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# I am the _GetTitleAsNameNoTooltip_.
	option = {
		name = diarchy.9014.a

		# Well done, well done.
		add_prestige = massive_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Liege won, usurper-side.
diarchy.9015 = {
	type = character_event
	title = diarchy.9015.t
	desc = {
		desc = diarchy.9015.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9015.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9015.desc.proxy.self_fought
			}
			desc = diarchy.9015.desc.scuffled
		}
		desc = diarchy.9015.desc.outro
	}
	theme = intrigue
	left_portrait = {
		character = scope:usurper
		animation = fear
	}
	right_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Prison changes.
			diarch_coup_attempt_imprison_usurper_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# It is over.
	option = {
		name = diarchy.9015.a

		# This doesn't bode well for you.
		add_prestige = massive_prestige_loss

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}
}

##################################################
# A Long Awaited Coup: Prowess
# by Ewan Cowhig Croft
# 9021 - 9030
##################################################

scripted_effect diarchy_9021_liege_successful_effect = {
	trigger_event = diarchy.9024
	# Big RIP.
	scope:usurper = {
		death = {
			death_reason = death_coup_failed
			killer = scope:liege
		}
	}
	scope:liege = {
		if = {
			limit = {
				exists = dynasty
				dynasty ?= scope:usurper.dynasty
			}
			add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:usurper }
		}
	}
	# Plus grab the lesser conspirators.
	every_in_list = {
		list = coup_pv_supporters_final_list
		limit = { is_alive = yes }
		save_temporary_scope_as = char_temp
		rightfully_imprison_character_effect = {
			TARGET = scope:char_temp
			IMPRISONER = scope:liege
		}
	}
}

scripted_effect diarchy_9021_usurper_successful_effect = {
	trigger_event = diarchy.9022
	scope:usurper = { trigger_event = diarchy.9023 }
	diarch_coup_attempt_standard_suite_effect = yes
	# Big RIP.
	death = {
		death_reason = death_coup_successful
		killer = scope:usurper
	}
	scope:usurper = {
		if = {
			limit = {
				exists = dynasty
				dynasty ?= scope:liege.dynasty
			}
			add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:liege }
		}
	}
}

#	You try to slaughter your way to power.
diarchy.9021 = {
	type = character_event
	title = diarchy.9021.t
	desc = {
		desc = diarchy.9021.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = scope:proxy }
				}
				desc = diarchy.9021.desc.proxy.none
			}
			triggered_desc = {
				trigger = { has_character_flag = betrayed_by_proxy }
				desc = diarchy.9021.desc.proxy.betrayed
			}
			desc = diarchy.9021.desc.proxy.loyal
		}
	}
	theme = martial
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		scripted_animation = duel_wield_weapon
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	cooldown = { years = 10 }

	immediate = {
		play_music_cue = "mx_cue_murder"
		# Is there a proxy candidate?
		## First, we check for a court champion.
		if = {
			limit = {
				any_court_position_holder = {
					has_court_position = champion_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
			}
			random_court_position_holder = {
				limit = {
					has_court_position = champion_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
				diarch_9000_create_proxy_and_check_for_betrayal_effect = yes
			}
		}
		## Then, we go over any bodyguards.
		else_if = {
			limit = {
				any_court_position_holder = {
					has_court_position = bodyguard_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
			}
			ordered_court_position_holder = {
				limit = {
					has_court_position = bodyguard_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
				order_by = prowess
				diarch_9000_create_proxy_and_check_for_betrayal_effect = yes
			}
		}
		else_if = {
			limit = {
				any_court_position_holder = {
					has_court_position = akolouthos_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
			}
			ordered_court_position_holder = {
				limit = {
					has_court_position = akolouthos_court_position
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
				order_by = prowess
				diarch_9000_create_proxy_and_check_for_betrayal_effect = yes
			}
		}
		## Finally, try to grab a knight.
		else_if = {
			limit = {
				any_knight = {
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
			}
			ordered_knight = {
				limit = {
					diarch_9000_valid_yet_betrayable_proxy_trigger = yes
					is_ai = yes
				}
				order_by = prowess
				diarch_9000_create_proxy_and_check_for_betrayal_effect = yes
			}
		}
	}

	# Meet the challenge personally.
	option = {
		name = diarchy.9021.a
		trigger = { can_start_single_combat_trigger = yes }
		show_as_unavailable = { can_start_single_combat_trigger = no }
		skill = prowess

		save_scope_value_as = {
			name = liege_action
			value = flag:self_fought
		}
		# A duel will begin immediately.
		## Inform the player.
		custom_tooltip = diarchy.9021.a.tt.commence_duel.self
		## Now fire it.
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:usurper
			SC_ATTACKER = scope:usurper
			SC_DEFENDER = scope:liege
			FATALITY = always
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = diarchy.9028
			INVALIDATION_EVENT = diarchy.9029
		}
		# Inform the player of the possible outcomes.
		show_as_tooltip = {
			random_list = {
				100 = {
					desc = diarchy.9021.a.tt.success
					show_chance = no
					diarchy_9021_liege_successful_effect = yes
				}
				100 = {
					desc = diarchy.9021.a.tt.failure
					show_chance = no
					diarchy_9021_usurper_successful_effect = yes
				}
			}
		}

		stress_impact = {
			brave = miniscule_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
			humble = minor_stress_impact_gain
			craven = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = intrigue
					subtract = scope:usurper.intrigue
					multiply = 10
				}
				always = yes
			}
			# Arrogant chars want to act themselves.
			modifier = {
				add = 50
				has_trait = arrogant
			}
		}
	}
	
	# Send in scope:proxy.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { character_is_teen_or_older_trigger = yes }
						desc = diarchy.9021.b.fallback
					}
					desc = diarchy.9021.b.young
				}
			}
		}
		trigger = {
			exists = scope:proxy
			NOT = { has_character_flag = betrayed_by_proxy }
		}
		show_as_unavailable = { has_character_flag = betrayed_by_proxy }
		skill = prowess

		save_scope_value_as = {
			name = liege_action
			value = flag:proxy_fought
		}
		# A duel will begin immediately.
		## Inform the player.
		custom_tooltip = diarchy.9021.b.tt.commence_duel.proxy
		## Now fire it.
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:usurper
			SC_ATTACKER = scope:usurper
			SC_DEFENDER = scope:proxy
			FATALITY = always
			FIXED = no
			LOCALE = throne_room
			OUTPUT_EVENT = diarchy.9028
			INVALIDATION_EVENT = diarchy.9029
		}
		# Inform the player of the possible outcomes.
		show_as_tooltip = {
			random_list = {
				100 = {
					desc = diarchy.9021.a.tt.success
					show_chance = no
					diarchy_9021_liege_successful_effect = yes
				}
				100 = {
					desc = diarchy.9021.a.tt.failure
					show_chance = no
					diarchy_9021_usurper_successful_effect = yes
				}
			}
		}

		stress_impact = {
			craven = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_loss
			ambitious = minor_stress_impact_gain
			brave = major_stress_impact_gain
		}
		ai_chance = {
			# Higher than usual default, because you shouldn't generally want to willingly surrender your titles.
			base = 100
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_energy = -1
			}
			# Account for skills.
			## Vs. scope:usurper.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:usurper.intrigue
					multiply = 10
				}
				always = yes
			}
			## Vs. scope:liege.
			modifier = {
				add = {
					value = scope:proxy.intrigue
					subtract = scope:liege.intrigue
					multiply = 10
				}
				always = yes
			}
			# Humble chars want to defer to their skilled advisors.
			modifier = {
				add = 50
				has_trait = humble
			}
		}
	}
	
	# Acquiesce to the ultimatum.
	option = {
		name = diarchy.9021.c

		save_scope_value_as = {
			name = liege_action
			value = flag:surrendered
		}
		trigger_event = diarchy.9022
		scope:usurper = { trigger_event = diarchy.9023 }
		diarch_coup_attempt_standard_suite_effect = yes
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes
		# And apply truces.
		diarch_coup_attempt_add_unequal_truces_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			generous = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
			stubborn = major_stress_impact_gain
			ambitious = massive_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = { ai_boldness = -2 }
			# Cravens are a bit more likely to go along with this, but even then.
			modifier = {
				add = 25
				has_trait = craven
			}
		}
	}

	# Guards, GUARDS!
	option = {
		name = diarchy.9021.d
		# Player-only chance at making it through.
		trigger = { is_ai = no }

		random_list = {
			# Loyal guards arrive and arrest scope:usurper.
			20 = {
				desc = diarchy.9021.d.tt.win
				trigger_event = diarchy.9024
				scope:usurper = { trigger_event = diarchy.9025 }
				# Big RIP.
				scope:usurper = {
					death = {
						death_reason = death_coup_failed
						killer = scope:liege
					}
				}
				scope:liege = {
					if = {
						limit = {
							exists = dynasty
							dynasty ?= scope:usurper.dynasty
						}
						add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:usurper }
					}
				}
			}
			# Your last possible defenders are put down without mercy.
			80 = {
				desc = diarchy.9021.d.tt.loss
				diarchy_9021_usurper_successful_effect = yes
			}
		}
		# Sort some criminal opinions.
		diarch_coup_attempt_apply_opinion_effect = yes

		stress_impact = {
			craven = major_stress_impact_loss
			humble = miniscule_stress_impact_loss
			greedy = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			# No AI chance needed for player-only option.
			base = 1
		}
	}
}

#	Usurper won, liege-side.
diarchy.9022 = {
	type = character_event
	title = diarchy.9022.t
	desc = {
		desc = diarchy.9022.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9022.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9022.desc.proxy.surrendered
			}
			desc = diarchy.9022.desc.scuffled
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9022.desc.outro.surrendered
			}
			desc = diarchy.9022.desc.outro
		}
	}
	theme = martial
	left_portrait = {
		character = scope:liege
		animation = fear
	}
	right_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
	}

	# How... how could this happen...
	option = {
		name = diarchy.9022.a

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	# My destiny. Undone.
	option = {
		name = diarchy.9022.b
		trigger = {
			exists = dynasty
			dynasty ?= scope:usurper.dynasty
			scope:usurper = { is_ai = yes }
		}

		set_player_character = scope:usurper

		# An uncomfortable transition — we still add it to be fair, but hide it so that we don't muddy the tooltips.
		hidden_effect = {
			stress_impact = { base = major_stress_impact_gain }
		}
		# No stress impact for player-only option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Usurper won, usurper-side.
diarchy.9023 = {
	type = character_event
	title = diarchy.9023.t
	desc = {
		desc = diarchy.9023.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:surrendered }
				desc = diarchy.9023.desc.surrendered
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:liege_action = flag:proxy_fought }
						desc = diarchy.9023.desc.proxy.proxy_fought
					}
					triggered_desc = {
						trigger = { scope:liege_action = flag:self_fought }
						desc = diarchy.9023.desc.proxy.self_fought
					}
					desc = diarchy.9023.desc.scuffled
				}
				desc = diarchy.9023.desc.outro
			}
		}
	}
	theme = intrigue
	left_portrait = {
		character = scope:usurper
		animation = war_over_win
	}
	right_portrait = {
		character = scope:liege
		animation = fear
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			# Title changes.
			diarch_coup_attempt_standard_suite_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
		# Achievements.
		if = {
			limit = {
				exists = global_var:started_your_eternal_reward_achievement
				is_ai = no
			}
			set_global_variable = {
				name = finished_your_eternal_reward_achievement
				value = yes
			}
		}
	}

	# This had to be done.
	option = {
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = { scope:liege_action = flag:surrendered }
						desc = diarchy.9023.a.liege_survives
					}
					desc = diarchy.9023.a
				}
			}
		}

		# Might makes right, I suppose.
		add_prestige = major_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { diarch_9000_generic_nickname_after_effect = yes }
}

#	Liege won, liege-side.
diarchy.9024 = {
	type = character_event
	title = diarchy.9024.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:liege_action = flag:proxy_fought }
				desc = diarchy.9024.desc.proxy.proxy_fought
			}
			triggered_desc = {
				trigger = { scope:liege_action = flag:self_fought }
				desc = diarchy.9024.desc.proxy.self_fought
			}
			desc = diarchy.9024.desc.scuffled
		}
		desc = diarchy.9024.desc.outro
	}
	theme = martial
	left_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	right_portrait = {
		character = scope:usurper
		animation = fear
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			diarchy_9021_liege_successful_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
		diarch_coup_attempt_end_diarchy_effect = yes
	}

	# I am the _GetTitleAsNameNoTooltip_.
	option = {
		name = diarchy.9024.a

		# You earnt this.
		add_prestige = massive_prestige_gain

		# No stress gain for descriptive option.
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}

	after = { remove_character_flag = betrayed_by_proxy }
}

#	Liege won, usurper-side.
diarchy.9025 = {
	type = character_event
	title = diarchy.9025.t
	desc = diarchy.9025.desc
	theme = martial
	left_portrait = {
		character = scope:usurper
		animation = fear
	}
	right_portrait = {
		character = scope:liege
		animation = war_over_win
	}
	lower_center_portrait = scope:proxy
	override_background = { reference = throne_room }

	immediate = {
		show_as_tooltip = {
			diarchy_9021_liege_successful_effect = yes
			# Opinion changes.
			diarch_coup_attempt_apply_opinion_effect = yes
		}
		death = {
			death_reason = death_coup_failed
			killer = scope:liege
		}
		scope:usurper = {
			if = {
				limit = {
					exists = dynasty
					dynasty ?= scope:liege.dynasty
				}
				add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:liege }
			}
		}
	}

	# It is over.
	option = {
		name = diarchy.9025.a

		# This doesn't bode well for you.
		add_prestige = massive_prestige_loss

		# An uncomfortable transition.
		stress_impact = { base = major_stress_impact_gain }
		ai_chance = {
			# Descriptive event, doesn't need complex AI logic.
			base = 100
		}
	}
}

#	Post-SCE processing.
diarchy.9028 = {
	hidden = yes

	immediate = {
		# Did scope:usurper win?
		if = {
			limit = { scope:sc_victor = scope:usurper }
			# If scope:liege is alive, give them their event.
			scope:liege = {
				if = {
					limit = { is_alive = yes }
					trigger_event = diarchy.9022
				}
			}
			scope:usurper = {
				trigger_event = diarchy.9023
				# Now trigger the actual effects.
				diarch_coup_attempt_standard_suite_effect = yes
			}
		}
		# Otherwise, scope:liege won.
		else = {
			scope:liege = { trigger_event = diarchy.9024 }
			# Scope:usurper might actually be dead at this point, but only if a player won the scramble toss-up.
		}
	}
}

#	SCE has invalidated.
diarchy.9029 = {
	hidden = yes

	immediate = {
		scope:usurper = { save_scope_as = actor }
		scope:liege = { save_scope_as = liege }
		# Put your shirts back on.
		single_combat_clean_shirtlessness_effect = {
			ATTACKER = scope:actor
			DEFENDER = scope:recipient
		}
		# Inform both parties that the duel has invalidated.
		scope:actor = {
			send_interface_toast = {	
				title = fp1_tbc.0021.trigger_failure.actor
				left_icon = scope:recipient
			}
		}
		scope:recipient = {
			send_interface_toast = {	
				title = fp1_tbc.0021.trigger_failure.recipient
				left_icon = scope:actor
			}
		}
	}
}

##################################################
# AI Coup Controls
# by Ewan Cowhig Croft
# 9031 - 9040
##################################################

#	Gather conspiratial allies.
diarchy.9031 = {
	hidden = yes

	immediate = {
		# Try to grab some suitable co-conspirators.
		liege = {
			every_powerful_vassal = {
				limit = {
					# No players, they add too much complication.
					is_ai = yes
					# Plus the obvious.
					NOT = { this = scope:actor }
					# Block a few things the player might expect to save them.
					NOR = {
						# High opinion.
						opinion = {
							target = scope:recipient
							value >= medium_positive_opinion
						}
						# Loyal.
						has_trait = loyal
						# Content.
						has_trait = content
						# Just.
						has_trait = just
						# Stubborn.
						has_trait = stubborn
						# Finally, loyalty hooks.
						diarch_loyalty_due_to_hook_trigger = {
							LIEGE = scope:recipient
							DIARCH = prev
						}
					}
					# We take into account the same type of thing as the interaction, but we're less strict so that the AI actually has a chance at this.
					## They just need to look like an obvious conspirator to scope:actor.
					calc_true_if = {
						amount >= 2
						# Opinion.
						AND = {
							# They must dislike their current liege.
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
							# And not completely hate your guts.
							opinion = {
								target = scope:actor
								value >= neutral_opinion
							}
						}
						# Personality.
						## Values.
						ai_honor <= dominant_negative_ai_value
						## Traits.
						### Disloyal.
						has_trait = disloyal
						### Ambitious.
						has_trait = ambitious
						### Arbitrary.
						has_trait = arbitrary
						### Fickle.
						has_trait = fickle
						### Diligent + negative opinion.
						AND = {
							has_trait = diligent
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Wrathful + negative opinion.
						AND = {
							has_trait = wrathful
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Impatient + negative opinion.
						AND = {
							has_trait = impatient
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Arrogant + negative opinion.
						AND = {
							has_trait = arrogant
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Deceitful + negative opinion.
						AND = {
							has_trait = deceitful
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Brave + negative opinion.
						AND = {
							has_trait = brave
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Paranoid + negative opinion.
						AND = {
							has_trait = paranoid
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Callous + negative opinion.
						AND = {
							has_trait = callous
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Sadistic + negative opinion.
						AND = {
							has_trait = sadistic
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						### Vengeful + negative opinion.
						AND = {
							has_trait = vengeful
							opinion = {
								target = scope:recipient
								value <= high_negative_opinion
							}
						}
						# Plus factor for lots of different violations.
						has_any_major_negative_opinion_against_character_trigger = { CHARACTER = scope:recipient }
					}
					# Make sure there's nothing that should really rule them out as joining the conspiracy.
					## We do these checks last since they're a bit more expensive, so we want to check easy stuff first.
					NOR = {
						## Generally, we don't want to betray an ally, unless it's for another ally.
						AND = {
							is_allied_to = scope:recipient
							NOT = { is_allied_to = scope:actor }
						}
						## Heirs don't generally want to betray their benefactor, as they'll lose out.
						save_temporary_scope_as = char_temp
						scope:recipient = {
							any_heir = { this = scope:char_temp }
						}
					}
				}
				save_temporary_scope_as = char_temp
				# Right, now add them to various lists.
				scope:actor = {
					# The chief conspirators list.
					add_to_variable_list = {
						name = coup_pv_supporters_list
						target = scope:char_temp
					}
					# By default, try to award strong hooks.
					if = {
						limit = {
							NOT = {
								scope:char_temp = { has_strong_hook = scope:actor }
							}
						}
						add_to_variable_list = {
							name = coup_promise_list_strong_hook
							target = scope:char_temp
						}
					}
					# Already got a strong hook? Fine, promise oodles of gooldles.
					else = {
						add_to_variable_list = {
							name = coup_promise_list_big_gold
							target = scope:char_temp
						}
					}
				}
			}
		}
		# Schedule the coup attempt for the immediate future.
		trigger_event = {
			id = diarchy.9032
			months = { 2 4 }
		}
	}
}

#	Try to execute a coup.
diarchy.9032 = {
	hidden = yes

	trigger = {
		is_ai = yes
		# Do we match the decision's requirements?
		diarch_coup_attempt_is_valid_trigger = { LIEGE = scope:recipient }
		diarch_coup_attempt_is_valid_showing_failure_only_trigger  = { DIARCH = scope:actor }
	}

	on_trigger_fail = {
		# A player hasn't inherited into us, right?
		if = {
			limit = { is_ai = yes }
			# Good, start the clean-up.
			diarch_clean_up_conspiracy_variables_effect = yes
			# Are we still a diarch?
			if = {
				limit = { is_diarch_of_target = scope:recipient }
				# Sweet, we are. Ok, try to run us over from the top again.
				trigger_event = diarchy.9031
			}
		}
	}

	immediate = {
		# Save some scopes for loc.
		scope:actor = { save_scope_as = usurper }
		scope:recipient = { save_scope_as = liege }
		# Fire the misc assorted effects we want here & for the player path.
		diarch_coup_preamble_effects_effect = yes
		# Compile our final conspirator list.
		diarch_finalise_conspirators_for_overthrow_list_effect = yes
		# Pick a coup type at semi-random.
		random_list = {
			# Diplomacy
			1 = {
				save_scope_value_as = {
					name = coup_diplomacy
					value = yes
				}
				save_scope_value_as = {
					name = coup_intrigue
					value = no
				}
				save_scope_value_as = {
					name = coup_prowess
					value = no
				}
				scope:liege = { trigger_event = diarchy.9001 }
				# Weight according to skills
				modifier = {
					add = {
						add = diplomacy
						subtract = scope:liege.diplomacy
					}
					always = yes
				}
				# Plus take education into account, for a bit of extra guessability.
				modifier = {
					add = 5
					has_trait = education_diplomacy
				}
				min = 1
			}
			# Intrigue
			1 = {
				save_scope_value_as = {
					name = coup_diplomacy
					value = no
				}
				save_scope_value_as = {
					name = coup_intrigue
					value = yes
				}
				save_scope_value_as = {
					name = coup_prowess
					value = no
				}
				scope:liege = { trigger_event = diarchy.9011 }
				# Weight according to skills
				modifier = {
					add = {
						add = intrigue
						subtract = scope:liege.intrigue
					}
					always = yes
				}
				# Plus take education into account, for a bit of extra guessability.
				modifier = {
					add = 5
					has_trait = education_intrigue
				}
				min = 1
			}
			# Prowess
			1 = {
				save_scope_value_as = {
					name = coup_diplomacy
					value = no
				}
				save_scope_value_as = {
					name = coup_intrigue
					value = no
				}
				save_scope_value_as = {
					name = coup_prowess
					value = yes
				}
				scope:liege = { trigger_event = diarchy.9021 }
				# Weight according to skills
				modifier = {
					add = {
						add = prowess
						subtract = scope:liege.prowess
					}
					always = yes
				}
				# Plus take education into account, for a bit of extra guessability.
				modifier = {
					add = 5
					# The prowess education isn't standard, so we use martial instead.
					has_trait = education_martial
				}
				min = 1
			}
		}
	}
}
