﻿
###################
# Generic effects that are used for basic opinion gain etc.
###################

#Basic effect for gaining a court position
basic_gained_court_position_effect = {
	scope:employee = {
		if = {
			limit = {
				has_opinion_modifier = {
					modifier = revoked_court_position_opinion
					target = scope:liege
				}
			}
			remove_opinion = {
				modifier = revoked_court_position_opinion
				target = scope:liege
			}
		}
		if = {
			limit = {
				is_ruler = yes
				has_vassal_stance = courtly
			}
			add_opinion = {
				target = scope:liege
				modifier = courtly_court_position_opinion
			}
		}
		if = {
			limit = {
				scope:liege = { is_ai = no }
			}
			set_variable = {
				name = court_8311_cooldown
				years = 2
			}
		}

		# Unity impact
		#add_clan_unity_interaction_effect = {
		#	CHARACTER = scope:liege
		#	TARGET = this
		#	VALUE = 0 #minor_unity_gain
		#	DESC = clan_unity_assigned_to_court_position.desc
		#	REVERSE_NON_HOUSE_TARGET = yes
		#}
	}
}

#Basic effect for losing a court position
basic_revoked_court_position_effect = {
	scope:employee = {
		if = {
			limit = {
				has_opinion_modifier = {
					modifier = courtly_court_position_opinion
					target = scope:liege
				}
			}
			remove_opinion = {
				modifier = courtly_court_position_opinion
				target = scope:liege
			}
		}
		if = {
			limit = {
				has_opinion_modifier = {
					modifier = hired_me_opinion
					target = scope:liege
				}
			}
			remove_opinion = {
				modifier = hired_me_opinion
				target = scope:liege
			}
		}
		if = {	
			limit = {
				NOT = { has_character_flag = no_revoke_opinion_loss }
			}
		add_opinion = {
			modifier = revoked_court_position_opinion
			target = scope:liege
			opinion = -30
		}
		}

		# Unity impact
		#add_clan_unity_interaction_effect = {
		#	CHARACTER = scope:liege
		#	TARGET = this
		#	VALUE = 0 #minor_unity_loss
		#	DESC = clan_unity_assigned_to_court_position.desc
		#	REVERSE_NON_HOUSE_TARGET = no
		#}
	}
	employed_booner_invalidation_effect = { EMPLOYEE = scope:employee LIEGE = scope:liege }
}

#Basic effect for a court position invalidating
basic_invalidated_court_position_effect = {
	employed_booner_invalidation_effect = { EMPLOYEE = scope:employee LIEGE = scope:liege }
}


################
# EFFECTS FOR SPECIFIC COURT POSITIONS
################

# COURT PHYSICIAN
court_physician_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_physician_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_physician_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT EUNUCH
chief_eunuch_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
chief_eunuch_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
chief_eunuch_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# KEEPER OF SWANS
keeper_of_swans_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
keeper_of_swans_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
keeper_of_swans_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# MASTER OF THE HORSE
master_of_horse_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
master_of_horse_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
master_of_horse_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT JESTER
court_jester_title_accepted_effect = {

}
court_jester_title_revoked_effect = {
	scope:employee = {
		if = { #Only lowborn/unlanded are insulted if it's revoked
			limit = {
				OR = {
					is_lowborn = yes
					is_playable_character = no
				}
			}
			add_opinion = {
				modifier = insult_opinion
				target = liege
				opinion = -15
			}
		}
	}
}
court_jester_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# MASTER OF THE HUNT
master_of_hunt_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
master_of_hunt_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
master_of_hunt_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# HIGH ALMONER
high_almoner_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
high_almoner_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
high_almoner_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# CUPBEARER
cupbearer_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
cupbearer_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
cupbearer_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# SENESCHAL
seneschal_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
seneschal_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
seneschal_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# ANTIQUARIAN
antiquarian_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
antiquarian_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
antiquarian_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT TUTOR
court_tutor_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_tutor_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_tutor_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# ROYAL ARCHITECT
royal_architect_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
royal_architect_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
royal_architect_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT POET
court_poet_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_poet_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_poet_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# BODYGUARD
bodyguard_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
bodyguard_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
bodyguard_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# CHAMPION
champion_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
champion_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
champion_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT MUSICIAN
court_musician_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_musician_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_musician_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# FOOD TASTER
food_taster_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
food_taster_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
food_taster_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# LADY-IN-WAITING
lady_in_waiting_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
lady_in_waiting_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
lady_in_waiting_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# EXECUTIONER
executioner_title_accepted_effect = {
	scope:liege = {
		consume_imprisonment_reasons = scope:employee
	}
	scope:employee = {
		if = {
			limit = { is_imprisoned = yes }
			release_from_prison = yes
		}
	}
	basic_gained_court_position_effect = yes
}
executioner_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
executioner_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# GARUDA
garuda_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
garuda_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
garuda_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT GARDENER
court_gardener_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_gardener_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_gardener_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# CARAVAN MASTER
court_travel_leader_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_travel_leader_title_revoked_effect = {
	basic_revoked_court_position_effect = yes 
}
court_travel_leader_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# WET NURSE
wet_nurse_title_accepted_effect = {
	basic_gained_court_position_effect = yes
	scope:liege = { #set wet_nurse and nursed_child relation with liege's children, siblings, hostages and liege if they are not adult
		every_courtier = {
			limit = {
				is_adult = no
				is_playable_character = no
				OR = {
					is_child_of = scope:liege
					is_sibling_of = scope:liege
					is_hostage_of = scope:liege
				}
				NOT = { has_relation_wet_nurse = scope:employee }
			}
			set_relation_wet_nurse = scope:employee
		}
		if = {
			limit = {
				scope:liege = { is_adult = no }
				NOT = { has_relation_wet_nurse = scope:employee }
			}
			set_relation_wet_nurse = scope:employee
		}
	}
}

wet_nurse_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
	#if any child has positive realtion with the fired nurse trigger an event about them complaining
	if = {
		limit = {
			scope:employee = {
				any_relation = {
					type = nursed_child
					is_alive = yes
					age >= 3
					is_adult = no
					OR = {
						opinion = {
							target = prev
							value >= medium_positive_opinion
						}
						has_relation_friend = prev
						has_relation_best_friend = prev
					}
				}
			}
		}
		scope:employee = {
			random_relation = {
				type = nursed_child
				limit = {
					is_alive = yes
					age >= 3
					OR = {
						opinion = {
							target = prev
							value >= medium_positive_opinion
						}
						has_relation_friend = prev
						has_relation_best_friend = prev
					}
				}
				save_scope_as = nursed_child
			}
			save_scope_as = former_wet_nurse
		}
		scope:liege = {
			trigger_event = {
				id = bp2_yearly.7012
				days = { 5 10 }
			}
		}
	}
}

wet_nurse_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# AKOLOUTHOS
akolouthos_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
akolouthos_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
akolouthos_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# COURT BREWMASTER
court_brewmaster_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
court_brewmaster_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
court_brewmaster_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# GRAND PRECEPTOR

grand_preceptor_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
grand_preceptor_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
grand_preceptor_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# GRAND GUARDIAN

grand_guardian_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
grand_guardian_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
grand_guardian_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# GRAND MENTOR

grand_mentor_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
grand_mentor_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
grand_mentor_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# FIRE DRAGON ENGINEER

fire_dragon_engineer_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
fire_dragon_engineer_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
fire_dragon_engineer_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

# KEEPER OF THE HAREM

keeper_of_the_harem_title_accepted_effect = {
	basic_gained_court_position_effect = yes
}
keeper_of_the_harem_title_revoked_effect = {
	basic_revoked_court_position_effect = yes
}
keeper_of_the_harem_title_invalidated_effect = {
	basic_invalidated_court_position_effect = yes
}

court_position_old_holder_effect = { # Save existing holder if relevant
	$EMPLOYER$ = {
		if = {
			limit = { employs_court_position = $POS$_court_position }
			random_court_position_holder = {
				type = $POS$_court_position
				save_scope_as = old_holder
			}
		}
	}
}

camp_officer_old_holder_effect = { # Save existing holder if relevant
	$EMPLOYER$ = {
		if = {
			limit = { employs_court_position = $POS$_camp_officer }
			random_court_position_holder = {
				type = $POS$_camp_officer
				save_scope_as = old_holder
			}
		}
	}
}

court_position_grant_effect = { # Give position, and revoke old holder's if they exist
	if = { #Bodyguards - we replace the worst one
		limit = {
			$EMPLOYER$ = {
				any_court_position_holder = {
					type = $POS$_court_position
					count >= 2
				}
			}
		}
		$EMPLOYER$ = {
			ordered_court_position_holder = {
				type = $POS$_court_position
				order_by = {
					value = aptitude:$POS$_court_position
					multiply = -1
				}
				save_scope_as = old_holder #Should be the one with worst aptitude
			}
		}
	}
	else_if = {
		limit = {
			$EMPLOYER$.court_position:$POS$_court_position ?= { has_court_position = $POS$_court_position }
		}
		$EMPLOYER$.court_position:$POS$_court_position = { save_scope_as = old_holder }
	}
	$CANDIDATE$ = {
		save_scope_as = candidate
		if = {
			limit = {
				NOR = { 
					is_vassal_of = $EMPLOYER$
					is_courtier_of = $EMPLOYER$
					employer = $EMPLOYER$
				}
			}
			hidden_effect = { set_employer = $EMPLOYER$ }
		}
	}
	$EMPLOYER$ = {
		if = {
			limit = { 
				scope:old_holder ?= { has_court_position = bodyguard_court_position }
				any_court_position_holder = {
					type = bodyguard_court_position
					has_court_position = bodyguard_court_position
					count > 1
				}
			}
			send_interface_toast = {
				title = move_and_grant_court_position_effect_tooltip
				left_icon = $CANDIDATE$
				right_icon = scope:old_holder
				replace_court_position = {
					recipient = $CANDIDATE$
					holder = scope:old_holder
					court_position = $POS$_court_position
				}
			}
		}
		else = {
			send_interface_toast = {
				title = move_and_grant_court_position_effect_tooltip
				left_icon = $CANDIDATE$
				appoint_court_position = {
					recipient = $CANDIDATE$
					court_position = $POS$_court_position
				}
			}
		}
	}
	$CANDIDATE$ = {
		$EMPLOYER$ = {
			save_scope_as = liege
			if = {
				limit = { exists = scope:old_holder }
				custom_tooltip = $POS$_old_holder_aptitude_tooltip
			}
			else = { custom_tooltip = $POS$_aptitude_tooltip }
		}
	}
	#LAAMPs don't pay salaries
	if = {
		limit = { 
			$EMPLOYER$ = { is_landless_adventurer = no }
		}
		custom_tooltip = $POS$_salary_tooltip
	}
}

camp_officer_grant_effect = { # Give position, and revoke old holder's if they exist
	if = {
		limit = {
			$EMPLOYER$.court_position:$POS$_camp_officer ?= { has_court_position = $POS$_camp_officer }
		}
		$EMPLOYER$.court_position:$POS$_camp_officer = { save_scope_as = old_holder }
	}
	$CANDIDATE$ = {
		save_scope_as = candidate
		if = {
			limit = {
				NOR = { 
					is_vassal_of = $EMPLOYER$
					is_courtier_of = $EMPLOYER$
					employer = $EMPLOYER$
				}
			}
			hidden_effect = { set_employer = $EMPLOYER$ }
		}
	}
	$EMPLOYER$ = {
		if = {
			limit = { exists = scope:old_holder }
			send_interface_toast = {
				title = move_and_grant_court_position_effect_tooltip
				left_icon = $CANDIDATE$
				right_icon = scope:old_holder
				replace_court_position = {
					recipient = $CANDIDATE$
					holder = scope:old_holder
					court_position = $POS$_camp_officer
				}
			}
		}
		else = {
			send_interface_toast = {
				title = move_and_grant_court_position_effect_tooltip
				left_icon = $CANDIDATE$
				appoint_court_position = {
					recipient = $CANDIDATE$
					court_position = $POS$_camp_officer
				}
			}
		}
	}
	$CANDIDATE$ = {
		$EMPLOYER$ = {
			save_scope_as = liege
			if = {
				limit = { exists = scope:old_holder }
				custom_tooltip = $POS$_old_holder_aptitude_tooltip
			}
			else = { custom_tooltip = $POS$_aptitude_tooltip }
		}
	}
	#LAAMPs don't pay salaries
	if = {
		limit = { 
			$EMPLOYER$ = { is_landless_adventurer = no }
		}
		custom_tooltip = $POS$_salary_tooltip
	}
}

court_position_generator_variable_effect = {
	set_variable = {
		name = $VAR$_court_position
		value = flag:$POS$
		years = 1
	}
	court_position_old_holder_effect = { POS = $POS$ EMPLOYER = $EMPLOYER$ }
}

camp_officer_generator_variable_effect = {
	set_variable = {
		name = $VAR$_camp_officer
		value = flag:$POS$
		years = 1
	}
	camp_officer_old_holder_effect = { POS = $POS$ EMPLOYER = $EMPLOYER$ }
}

# Sets variable of court position suitable to a character's skills
# Actual job is set with court_position_generator_assignment_effect after using this effect
# VAR - can be used to allow multiple event options: 'target', 'second', 'backup'
# EMPLOYER - should be the char hiring the position
# ROOT - should be the char taking the position
# Saves scope:old_holder as existing holder if they exist
# NOTE: candidates must be courtiers of the employer for this to work
court_position_generator_effect = {
	save_scope_as = candidate
	$EMPLOYER$ = { save_scope_as = liege }
	save_scope_value_as = {
		name = only_empty
		value = flag:$ONLY_EMPTY$
	}
	# Randomly select a fitting role and save it to a variable
	random_list = {
		2 = { # ARCHITECT
			trigger = {
				court_position_generator_pickable_trigger = { POS = royal_architect EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = royal_architect
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = royal_architect
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # SENESCHAL
			trigger = {
				court_position_generator_pickable_trigger = { POS = seneschal EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = seneschal
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = seneschal
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # TUTOR
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_tutor EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_tutor
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_tutor
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # HIGH ALMONER
			trigger = {
				court_position_generator_pickable_trigger = { POS = high_almoner EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = high_almoner
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = high_almoner
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # COURT PHYSICIAN
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_physician EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_physician
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_physician
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # ANTIQUARIAN
			trigger = {
				court_position_generator_pickable_trigger = { POS = antiquarian EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = antiquarian
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = antiquarian
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # HORSE MASTER
			trigger = {
				court_position_generator_pickable_trigger = { POS = master_of_horse EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = master_of_horse
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = master_of_horse
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # BODYGUARD
			trigger = {
				court_position_generator_pickable_trigger = { POS = bodyguard EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = bodyguard
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = bodyguard
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # HUNT MASTER
			trigger = {
				court_position_generator_pickable_trigger = { POS = master_of_hunt EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = master_of_hunt
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = master_of_hunt
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CHAMPION
			trigger = {
				court_position_generator_pickable_trigger = { POS = champion EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = champion
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = champion
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # POET
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_poet EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_poet
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_poet
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # MUSICIAN
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_musician EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_musician
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_musician
				EMPLOYER = $EMPLOYER$
			}
		}
		1 = { # COURT JESTER
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_jester EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_jester
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_jester
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # EXECUTIONER
			trigger = {
				court_position_generator_pickable_trigger = { POS = executioner EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = executioner
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = executioner
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # FOOD TASTER
			trigger = {
				court_position_generator_pickable_trigger = { POS = food_taster EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = food_taster
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = food_taster
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CUPBEARER
			trigger = {
				court_position_generator_pickable_trigger = { POS = cupbearer EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = cupbearer
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = cupbearer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # LADY-IN-WAITING
			trigger = {
				court_position_generator_pickable_trigger = { POS = lady_in_waiting EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = lady_in_waiting
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = lady_in_waiting
				EMPLOYER = $EMPLOYER$
			}
		}
		4 = { # EUNUCH
			trigger = {
				court_position_generator_pickable_trigger = { POS = chief_eunuch EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = chief_eunuch
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = chief_eunuch
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # GARDENER
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_gardener EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_gardener
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_gardener
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # ARTIFICER
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_artificer EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_artificer
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_artificer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CULTURAL EMISSARY
			trigger = {
				court_position_generator_pickable_trigger = { POS = cultural_emissary EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = cultural_emissary
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = cultural_emissary
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CHIEF QADI
			trigger = {
				court_position_generator_pickable_trigger = { POS = chief_qadi EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = chief_qadi
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = chief_qadi
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # GARUDA
			trigger = {
				court_position_generator_pickable_trigger = { POS = garuda EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = garuda
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = garuda
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # KEEPER OF SWANS
			trigger = {
				court_position_generator_pickable_trigger = { POS = keeper_of_swans EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = keeper_of_swans
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = keeper_of_swans
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CARAVAN MASTER
			trigger = {
				court_position_generator_pickable_trigger = { POS = travel_leader EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = travel_leader
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = travel_leader
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # WET NURSE
			trigger = {
				court_position_generator_pickable_trigger = { POS = wet_nurse EMPLOYER = $EMPLOYER$ }
			}
			modifier = {
				add = 5
				has_trait = loyal
			}
			modifier = {
				add = 10
				has_relation_friend = $EMPLOYER$
			}
			modifier = {
				add = 20
				has_relation_best_friend = $EMPLOYER$
			}
			modifier = {
				add = 30
				has_relation_lover = $EMPLOYER$
			}
			modifier = {
				add = 40
				has_relation_soulmate = $EMPLOYER$
			}
			court_position_generator_shared_modifier = {
				POS = wet_nurse
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = wet_nurse
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CAVE HERMIT
			trigger = {
				court_position_generator_pickable_trigger = { POS = cave_hermit EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = cave_hermit
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = cave_hermit
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # MASTER ASSASSIN
			trigger = {
				court_position_generator_pickable_trigger = { POS = master_assassin EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = master_assassin
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = master_assassin
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # COURT SCHOLAR
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_scholar EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_scholar
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_scholar
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CHRONICLER
			trigger = {
				court_position_generator_pickable_trigger = { POS = chronicler EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = chronicler
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = chronicler
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # AKOLOUTHOS
			trigger = {
				court_position_generator_pickable_trigger = { POS = akolouthos EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = akolouthos
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = akolouthos
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # COURT ASTROLOGER
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_astrologer EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_astrologer
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_astrologer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # GRAND PRECEPTOR
			trigger = {
				court_position_generator_pickable_trigger = { POS = grand_preceptor EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = grand_preceptor
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = grand_preceptor
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # GRAND GUARDIAN
			trigger = {
				court_position_generator_pickable_trigger = { POS = grand_guardian EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = grand_guardian
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = grand_guardian
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # GRAND MENTOR
			trigger = {
				court_position_generator_pickable_trigger = { POS = grand_mentor EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = grand_mentor
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = grand_mentor
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # FIRE DRAGON ENGINEER
			trigger = {
				court_position_generator_pickable_trigger = { POS = fire_dragon_engineer EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = fire_dragon_engineer
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = fire_dragon_engineer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # KEEPER OF THE HAREM
			trigger = {
				court_position_generator_pickable_trigger = { POS = keeper_of_the_harem EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = keeper_of_the_harem
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = keeper_of_the_harem
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # BOYAN
			trigger = {
				court_position_generator_pickable_trigger = { POS = boyan EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = boyan
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = boyan
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # SIEGE ENGINEER
			trigger = {
				court_position_generator_pickable_trigger = { POS = siege_engineer EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = siege_engineer
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = siege_engineer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # YURTCHI
			trigger = {
				court_position_generator_pickable_trigger = { POS = yurtchi EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = yurtchi
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = yurtchi
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # CHERBI
			trigger = {
				court_position_generator_pickable_trigger = { POS = cherbi EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = cherbi
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = cherbi
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # YEKE JARQUCHI
			trigger = {
				court_position_generator_pickable_trigger = { POS = yeke_jarquchi EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = yeke_jarquchi
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = yeke_jarquchi
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # FOREIGN EMISSARY
			trigger = {
				court_position_generator_pickable_trigger = { POS = foreign_emissary EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = foreign_emissary
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = foreign_emissary
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # KEEPER OF THE HORSES
			trigger = {
				court_position_generator_pickable_trigger = { POS = keeper_of_the_horses EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = keeper_of_the_horses
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = keeper_of_the_horses
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # Court Guru
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_guru EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_guru
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_guru
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # Court Brahmin
			trigger = {
				court_position_generator_pickable_trigger = { POS = court_brahmin EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = court_brahmin
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = court_brahmin
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # Khlon Glan
			trigger = {
				court_position_generator_pickable_trigger = { POS = khlon_glan EMPLOYER = $EMPLOYER$ }
			}
			court_position_generator_shared_modifier = {
				POS = khlon_glan
				EMPLOYER = $EMPLOYER$
			}
			court_position_generator_variable_effect = {
				VAR = $VAR$
				POS = khlon_glan
				EMPLOYER = $EMPLOYER$
			}
		}
	}
	clear_saved_scope = only_empty
}

# Gives job of court position suitable to a character's skills
# Job is picked in court_position_generator_effect
# VAR - valid parameters: 'target', 'second', 'backup'
# EMPLOYER - should be the char hiring the position
# CANDIDATE - should be the char taking the position
court_position_generator_assignment_effect = {
	switch = {
		trigger = $CANDIDATE$.var:$VAR$_court_position
		# Architect
		flag:royal_architect = {
			court_position_grant_effect = { POS = royal_architect CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Seneschal
		flag:seneschal = {
			court_position_grant_effect = { POS = seneschal CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Tutor
		flag:court_tutor = {
			court_position_grant_effect = { POS = court_tutor CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# High Almoner
		flag:high_almoner = {
			court_position_grant_effect = { POS = high_almoner CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Physician
		flag:court_physician = {
			court_position_grant_effect = { POS = court_physician CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Antiquarian
		flag:antiquarian = {
			court_position_grant_effect = { POS = antiquarian CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Master of the Horse
		flag:master_of_horse = {
			court_position_grant_effect = { POS = master_of_horse CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		} 
		# Bodyguard
		flag:bodyguard = {
			court_position_grant_effect = { POS = bodyguard CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Champion
		flag:champion = {
			court_position_grant_effect = { POS = champion CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Master of the Hunt
		flag:master_of_hunt = {
			court_position_grant_effect = { POS = master_of_hunt CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Poet
		flag:court_poet = {
			court_position_grant_effect = { POS = court_poet CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Musician
		flag:court_musician = {
			court_position_grant_effect = { POS = court_musician CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Jester
		flag:court_jester = {
			court_position_grant_effect = { POS = court_jester CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Executioner
		flag:executioner = {
			court_position_grant_effect = { POS = executioner CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Food Taster
		flag:food_taster = {
			court_position_grant_effect = { POS = food_taster CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Cupbearer
		flag:cupbearer = {
			court_position_grant_effect = { POS = cupbearer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Lady-in-waiting
		flag:lady_in_waiting = {
			court_position_grant_effect = { POS = lady_in_waiting CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		} 
		# Eunuch
		flag:chief_eunuch = {
			court_position_grant_effect = { POS = chief_eunuch CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Gardener
		flag:court_gardener = {
			court_position_grant_effect = { POS = court_gardener CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Artificer
		flag:court_artificer = {
			court_position_grant_effect = { POS = court_artificer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Cultural Emissary
		flag:cultural_emissary = {
			court_position_grant_effect = { POS = cultural_emissary CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Chief Qadi
		flag:chief_qadi = {
			court_position_grant_effect = { POS = chief_qadi CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Garuda
		flag:garuda = {
			court_position_grant_effect = { POS = garuda CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Keeper of the Swans
		flag:keeper_of_swans = {
			court_position_grant_effect = { POS = keeper_of_swans CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Caravan Master
		flag:travel_leader = {
			court_position_grant_effect = { POS = travel_leader CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Wet Nurse
		flag:wet_nurse = {
			court_position_grant_effect = { POS = wet_nurse CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Cave Hermit
		flag:cave_hermit = {
			court_position_grant_effect = { POS = cave_hermit CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Master Assassin
		flag:master_assassin = {
			court_position_grant_effect = { POS = master_assassin CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Scholar
		flag:court_scholar = {
			court_position_grant_effect = { POS = court_scholar CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Chronciler
		flag:chronicler = {
			court_position_grant_effect = { POS = chronicler CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Akolouthos
		flag:akolouthos = {
			court_position_grant_effect = { POS = akolouthos CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Astrologer
		flag:court_astrologer = {
			court_position_grant_effect = { POS = court_astrologer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Grand Preceptor
		flag:grand_preceptor = {
			court_position_grant_effect = { POS = grand_preceptor CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Grand Guardian
		flag:grand_guardian = {
			court_position_grant_effect = { POS = grand_guardian CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Grand Mentor
		flag:grand_mentor = {
			court_position_grant_effect = { POS = grand_mentor CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Fire Dragon Engineer
		flag:fire_dragon_engineer = {
			court_position_grant_effect = { POS = fire_dragon_engineer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Keeper of the Harem
		flag:keeper_of_the_harem = {
			court_position_grant_effect = { POS = keeper_of_the_harem CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Boyan
		flag:boyan = {
			court_position_grant_effect = { POS = boyan CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Siege Engineer
		flag:siege_engineer = {
			court_position_grant_effect = { POS = siege_engineer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Yurtchi
		flag:yurtchi = {
			court_position_grant_effect = { POS = yurtchi CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Cherbi
		flag:cherbi = {
			court_position_grant_effect = { POS = cherbi CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Yeke Jarquchi
		flag:yeke_jarquchi = {
			court_position_grant_effect = { POS = yeke_jarquchi CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Foreign Emissary
		flag:foreign_emissary = {
			court_position_grant_effect = { POS = foreign_emissary CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Keeper of the Horses
		flag:keeper_of_the_horses = {
			court_position_grant_effect = { POS = keeper_of_the_horses CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Guru
		flag:court_guru = {
			court_position_grant_effect = { POS = court_guru CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Court Brahmin
		flag:court_brahmin = {
			court_position_grant_effect = { POS = court_brahmin CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# Khlon Glan
		flag:khlon_glan = {
			court_position_grant_effect = { POS = khlon_glan CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
	}
}

# Sets variable of court position suitable to a character's skills
# Actual job is set with camp_officer_generator_assignment_effect after using this effect
# VAR - can be used to allow multiple event options: 'target', 'second', 'backup'
# EMPLOYER - should be the char hiring the position
# ROOT - should be the char taking the position
# Saves scope:old_holder as existing holder if they exist
camp_officer_generator_effect = {
	save_scope_as = candidate
	$EMPLOYER$ = { save_scope_as = liege }
	# Randomly select a fitting role and save it to a variable
	random_list = {
		2 = { # second
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = second EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = second
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = second
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # quartermaster
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = quartermaster EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = quartermaster
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = quartermaster
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # armorer
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = armorer EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = armorer
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = armorer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # chief_forager
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = chief_forager EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = chief_forager
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = chief_forager
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # master_thief
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = master_thief EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = master_thief
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = master_thief
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # head_porter
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = head_porter EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = head_porter
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = head_porter
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # head_groom
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = head_groom EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = head_groom
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = head_groom
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # huntperson
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = huntperson EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = huntperson
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = huntperson
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # kennelperson
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = kennelperson EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = kennelperson
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = kennelperson
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # chief_engineer
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = chief_engineer EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = chief_engineer
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = chief_engineer
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # witness
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = witness EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = witness
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = witness
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # person_haggler
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = person_haggler EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = person_haggler
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = person_haggler
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # camp_cook
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = camp_cook EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = camp_cook
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = camp_cook
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # master_bard
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = master_bard EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = master_bard
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = master_bard
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # stooge
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = stooge EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = stooge
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = stooge
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # master_of_arms
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = master_of_arms EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = master_of_arms
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = master_of_arms
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # light_cavalry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = light_cavalry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = light_cavalry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = light_cavalry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # camelry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = camelry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = camelry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = camelry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # elephantry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = elephantry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = elephantry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = elephantry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # heavy_cavalry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = heavy_cavalry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = heavy_cavalry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = heavy_cavalry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # horse_archer_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = horse_archer_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = horse_archer_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = horse_archer_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # archer_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = archer_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = archer_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = archer_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # heavy_infantry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = heavy_infantry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = heavy_infantry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = heavy_infantry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # light_infantry_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = light_infantry_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = light_infantry_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = light_infantry_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # pike_captain
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = pike_captain EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = pike_captain
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = pike_captain
				EMPLOYER = $EMPLOYER$
			}
		}
		2 = { # master_of_spoils
			trigger = {
				camp_officer_generator_pickable_trigger = { POS = master_of_spoils EMPLOYER = $EMPLOYER$ }
			}
			camp_officer_generator_shared_modifier = {
				POS = master_of_spoils
				EMPLOYER = $EMPLOYER$
			}
			camp_officer_generator_variable_effect = {
				VAR = $VAR$
				POS = master_of_spoils
				EMPLOYER = $EMPLOYER$
			}
		}
	}
}

# Gives job of court position suitable to a character's skills
# Job is picked in camp_officer_generator_effect
# VAR - valid parameters: 'target', 'second', 'backup'
# EMPLOYER - should be the char hiring the position
# CANDIDATE - should be the char taking the position
camp_officer_generator_assignment_effect = {
	switch = {
		trigger = $CANDIDATE$.var:$VAR$_camp_officer
		# second
		flag:second = {
			camp_officer_grant_effect = { POS = second CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# quartermaster
		flag:quartermaster = {
			camp_officer_grant_effect = { POS = quartermaster CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# armorer
		flag:armorer = {
			camp_officer_grant_effect = { POS = armorer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# chief_forager
		flag:chief_forager = {
			camp_officer_grant_effect = { POS = chief_forager CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# master_thief
		flag:master_thief = {
			camp_officer_grant_effect = { POS = master_thief CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# head_porter
		flag:head_porter = {
			camp_officer_grant_effect = { POS = head_porter CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# head_groom
		flag:head_groom = {
			camp_officer_grant_effect = { POS = head_groom CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# huntperson
		flag:huntperson = {
			camp_officer_grant_effect = { POS = huntperson CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# kennelperson
		flag:kennelperson = {
			camp_officer_grant_effect = { POS = kennelperson CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# chief_engineer
		flag:chief_engineer = {
			camp_officer_grant_effect = { POS = chief_engineer CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# witness
		flag:witness = {
			camp_officer_grant_effect = { POS = witness CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# person_haggler
		flag:person_haggler = {
			camp_officer_grant_effect = { POS = person_haggler CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# camp_cook
		flag:camp_cook = {
			camp_officer_grant_effect = { POS = camp_cook CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# master_bard
		flag:master_bard = {
			camp_officer_grant_effect = { POS = master_bard CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# stooge
		flag:stooge = {
			camp_officer_grant_effect = { POS = stooge CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# master_of_arms
		flag:master_of_arms = {
			camp_officer_grant_effect = { POS = master_of_arms CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# light_cavalry_captain
		flag:light_cavalry_captain = {
			camp_officer_grant_effect = { POS = light_cavalry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# camelry_captain
		flag:camelry_captain = {
			camp_officer_grant_effect = { POS = camelry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# elephantry_captain
		flag:elephantry_captain = {
			camp_officer_grant_effect = { POS = elephantry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# heavy_cavalry_captain
		flag:heavy_cavalry_captain = {
			camp_officer_grant_effect = { POS = heavy_cavalry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# horse_archer_captain
		flag:horse_archer_captain = {
			camp_officer_grant_effect = { POS = horse_archer_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# archer_captain
		flag:archer_captain = {
			camp_officer_grant_effect = { POS = archer_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# heavy_infantry_captain
		flag:heavy_infantry_captain = {
			camp_officer_grant_effect = { POS = heavy_infantry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# light_infantry_captain
		flag:light_infantry_captain = {
			camp_officer_grant_effect = { POS = light_infantry_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# pike_captain
		flag:pike_captain = {
			camp_officer_grant_effect = { POS = pike_captain CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
		# master_of_spoils
		flag:master_of_spoils = {
			camp_officer_grant_effect = { POS = master_of_spoils CANDIDATE = $CANDIDATE$ EMPLOYER = $EMPLOYER$ }
		}
	}
}

# Giving out generic court positions
decide_court_position_to_give_effect = {
	$EMPLOYER$ = {
		if = {
			limit = { exists = $CANDIDATE$ }
			if = {
				limit = {
					$CANDIDATE$ = {
						OR = {
							has_trait = education_learning
							learning >= high_skill_rating
						}
					}
				}
				random_list = {
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_physician_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = physician_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_tutor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_guru_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag } # reusing same flag as tutor for simplicity later on
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = high_almoner_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = almoner_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = antiquarian_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = antiquarian_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = chief_qadi_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = qadi_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = fire_dragon_engineer_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = fire_dragon_engineer_flag }
					}
				}
			}
			else_if = {
				limit = {
					$CANDIDATE$ = {
						OR = {
							has_trait = education_intrigue
							intrigue >= high_skill_rating
						}
					}
				}
				random_list = {
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = food_taster_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = taster_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = executioner_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = executioner_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$ 
								COURT_POS = court_tutor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$ 
								COURT_POS = court_guru_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag } # reusing flag as tutor for simplicity later on
					}
				}
			}
			else_if = {
				limit = {
					$CANDIDATE$ = {
						OR = {
							has_trait = education_diplomacy
							diplomacy >= high_skill_rating
						}
					}
				}
				random_list = {
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = cupbearer_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = cupbearer_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = lady_in_waiting_court_position
							}
							$CANDIDATE$ = { is_female = yes }
						}
						$CANDIDATE$ = { add_character_flag = lady_in_waiting_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_tutor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_guru_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag } # reusing same flag as tutor for simplicity later on
					}
					20 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_jester_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = jester_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_poet_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = poet_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_musician_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = musician_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = wet_nurse_court_position
							}
							$CANDIDATE$ = { is_female = yes }
						}
						$CANDIDATE$ = { add_character_flag = wet_nurse_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = grand_preceptor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = grand_preceptor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = grand_guardian_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = grand_guardian_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = grand_mentor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = grand_mentor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = keeper_of_the_harem_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = keeper_of_the_harem_flag }
					}
				}
			}
			else_if = {
				limit = {
					$CANDIDATE$ = {
						OR = {
							has_trait = education_stewardship
							stewardship >= high_skill_rating
						}
					}
				}
				random_list = {
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_gardener_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = gardener_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = royal_architect_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = architect_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_tutor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_guru_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag } # reusing same flag as tutor for simplicity later on
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = keeper_of_swans_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = swan_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = seneschal_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = seneschal_flag }
					}
				}
			}
			else_if = {
				limit = {
					$CANDIDATE$ = {
						OR = {
							has_trait = education_martial
							martial >= high_skill_rating
						}
					}
				}
				random_list = {
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = master_of_horse_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = horse_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = garuda_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = garuda_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_tutor_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_guru_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = tutor_flag } # reusing tutor flag for simplicity later on
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = master_of_hunt_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = hunt_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = bodyguard_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = bodyguard_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = champion_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = champion_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = akolouthos_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = akolouthos_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = court_astrologer_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = court_astrologer_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = boyan_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = boyan_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = siege_engineer_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = siege_engineer_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = yurtchi_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = yurtchi_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = yeke_jarquchi_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = yeke_jarquchi_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = foreign_emissary_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = foreign_emissary_flag }
					}
					10 = {
						trigger = {
							can_appoint_char_to_court_position = {
								CHAR = $CANDIDATE$
								COURT_POS = keeper_of_the_horses_court_position
							}
						}
						$CANDIDATE$ = { add_character_flag = keeper_of_the_horses_flag }
					}
				}
			}
		}
	}
}

### This effect does NOT care if you are already employing someone in that position
assign_appropriate_court_position_effect = {
	if = {
		limit = {
			$CANDIDATE$ = {
				OR = {
					has_trait = education_learning
					learning >= high_skill_rating
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					can_employ_court_position_type = court_physician_court_position
				}
				$CANDIDATE$ = { add_character_flag = physician_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = high_almoner_court_position
				}
				$CANDIDATE$ = { add_character_flag = almoner_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = antiquarian_court_position
				}
				$CANDIDATE$ = { add_character_flag = antiquarian_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = chief_qadi_court_position
				}
				$CANDIDATE$ = { add_character_flag = qadi_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = siege_engineer_court_position
				}
				$CANDIDATE$ = { add_character_flag = siege_engineer_flag }
			}
		}
	}
	else_if = {
		limit = {
			$CANDIDATE$ = {
				OR = {
					has_trait = education_intrigue
					intrigue >= high_skill_rating
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					can_employ_court_position_type = food_taster_court_position
				}
				$CANDIDATE$ = { add_character_flag = taster_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = executioner_court_position
				}
				$CANDIDATE$ = { add_character_flag = executioner_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = court_astrologer_court_position
				}
				$CANDIDATE$ = { add_character_flag = court_astrologer_flag }
			}
		}
	}
	else_if = {
		limit = {
			$CANDIDATE$ = {
				OR = {
					has_trait = education_diplomacy
					diplomacy >= high_skill_rating
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					can_employ_court_position_type = cupbearer_court_position
				}
				$CANDIDATE$ = { add_character_flag = cupbearer_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = lady_in_waiting_court_position
					$CANDIDATE$ = { is_female = yes }
				}
				$CANDIDATE$ = { add_character_flag = lady_in_waiting_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = court_tutor_court_position
				}
				$CANDIDATE$ = { add_character_flag = tutor_flag }
			}
			20 = {
				trigger = {
					can_employ_court_position_type = court_jester_court_position
				}
				$CANDIDATE$ = { add_character_flag = jester_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = court_poet_court_position
				}
				$CANDIDATE$ = { add_character_flag = poet_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = court_musician_court_position
				}
				$CANDIDATE$ = { add_character_flag = musician_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = wet_nurse_court_position
					$CANDIDATE$ = { is_female = yes }
				}
				$CANDIDATE$ = { add_character_flag = wet_nurse_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = foreign_emissary_court_position
				}
				$CANDIDATE$ = { add_character_flag = foreign_emissary_flag }
			}
		}
	}
	else_if = {
		limit = {
			$CANDIDATE$ = {
				OR = {
					has_trait = education_stewardship
					stewardship >= high_skill_rating
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					can_employ_court_position_type = travel_leader_court_position
				}
				$CANDIDATE$ = { add_character_flag = travel_leader_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = court_gardener_court_position
				}
				$CANDIDATE$ = { add_character_flag = gardener_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = royal_architect_court_position
				}
				$CANDIDATE$ = { add_character_flag = architect_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = keeper_of_swans_court_position
				}
				$CANDIDATE$ = { add_character_flag = swan_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = seneschal_court_position
				}
				$CANDIDATE$ = { add_character_flag = seneschal_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = yurtchi_court_position
				}
				$CANDIDATE$ = { add_character_flag = yurtchi_flag }
			}
		}
	}
	else_if = {
		limit = {
			$CANDIDATE$ = {
				OR = {
					has_trait = education_martial
					martial >= high_skill_rating
				}
			}
		}
		random_list = {
			10 = {
				trigger = {
					can_employ_court_position_type = master_of_horse_court_position
				}
				$CANDIDATE$ = { add_character_flag = horse_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = garuda_court_position
				}
				$CANDIDATE$ = { add_character_flag = garuda_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = master_of_hunt_court_position
				}
				$CANDIDATE$ = { add_character_flag = hunt_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = bodyguard_court_position
				}
				$CANDIDATE$ = { add_character_flag = bodyguard_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = champion_court_position
				}
				$CANDIDATE$ = { add_character_flag = champion_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = akolouthos_court_position
				}
				$CANDIDATE$ = { add_character_flag = akolouthos_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = boyan_court_position
				}
				$CANDIDATE$ = { add_character_flag = boyan_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = yeke_jarquchi_court_position
				}
				$CANDIDATE$ = { add_character_flag = yeke_jarquchi_flag }
			}
			10 = {
				trigger = {
					can_employ_court_position_type = keeper_of_the_horses_court_position
				}
				$CANDIDATE$ = { add_character_flag = keeper_of_the_horses_flag }
			}
		}
	}
}

distribute_determined_court_position_effect = {
	$EMPLOYER$ = {
		if = {
			limit = { $CANDIDATE$ = { has_character_flag = physician_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_physician_court_position
			}
		}
		else_if = {
			limit = { 
				$CANDIDATE$ = { has_character_flag = tutor_flag } 
				NOT = { government_has_flag = government_is_mandala }
			}
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_tutor_court_position
			}
		}
		else_if = {
			limit = { 
				$CANDIDATE$ = { has_character_flag = tutor_flag } 
				government_has_flag = government_is_mandala
			}
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_guru_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = almoner_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = high_almoner_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = antiquarian_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = antiquarian_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = qadi_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = chief_qadi_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = taster_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = food_taster_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = executioner_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = executioner_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = cupbearer_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = cupbearer_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = lady_in_waiting_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = lady_in_waiting_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = jester_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_jester_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = poet_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_poet_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = musician_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_musician_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = gardener_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_gardener_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = architect_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = royal_architect_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = swan_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = keeper_of_swans_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = seneschal_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = seneschal_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = horse_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = master_of_horse_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = garuda_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = garuda_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = hunt_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = master_of_hunt_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = bodyguard_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = bodyguard_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = champion_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = champion_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = travel_leader_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = travel_leader_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = wet_nurse_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = wet_nurse_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = akolouthos_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = akolouthos_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = court_astrologer_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = court_astrologer_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = grand_preceptor_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = grand_preceptor_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = grand_guardian_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = grand_guardian_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = grand_mentor_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = grand_mentor_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = fire_dragon_engineer_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = fire_dragon_engineer_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = keeper_of_the_harem_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = keeper_of_the_harem_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = boyan_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = boyan_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = siege_engineer_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = siege_engineer_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = yurtchi_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = yurtchi_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = yeke_jarquchi_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = yeke_jarquchi_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = foreign_emissary_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = foreign_emissary_court_position
			}
		}
		else_if = {
			limit = { $CANDIDATE$ = { has_character_flag = keeper_of_the_horses_flag } }
			appoint_court_position = {
				recipient = $CANDIDATE$
				court_position = keeper_of_the_horses_court_position
			}
		}
	}
}

give_relevant_valid_court_position = {
	decide_court_position_to_give_effect = {
		EMPLOYER = $EMPLOYER$
		CANDIDATE = $CANDIDATE$
	}
	distribute_determined_court_position_effect = {
		EMPLOYER = $EMPLOYER$
		CANDIDATE = $CANDIDATE$
	}
}

### Court Tutor Task Effects ###
court_tutor_improve_others_skill_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = court_tutor_improve_others_title
		desc = court_tutor_improve_others_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = { add_$SKILL$_skill = 1 }
	}
}

court_tutor_improve_others_trait_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = court_tutor_improve_others_title
		desc = court_tutor_improve_others_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = { add_trait = $TRAIT$ }
	}
}

court_tutor_improve_others_trait_xp_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = court_tutor_improve_others_title
		desc = court_tutor_improve_others_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = {
			add_trait_xp = {
				trait = $TRAIT$
				value = 5
			}
		}
	}
}

court_tutor_improve_others_trait_track_xp_effect = {
	send_interface_toast = {
		type = event_royal_court_good_with_text
		title = court_tutor_improve_others_title
		desc = court_tutor_improve_others_notification_desc
		left_icon = root
		right_icon = scope:target_character

		scope:target_character = {
			add_trait_xp = {
				trait = $TRAIT$
				track = $TRACK$
				value = 5
			}
		}
	}
}

wet_nurse_instill_virtue_effect = {
	scope:notification_character = {
		send_interface_toast = {
			type = event_royal_court_good_with_text
			title = wet_nurse_instill_virtue
			desc = wet_nurse_instill_virtue_notification_desc
			left_icon = root
			right_icon = scope:child_character

			scope:child_character = {
				add_trait = $TRAIT$
			}
		}
	}
}

# Need a 'notification_character' scope for it to work properly
instill_virtue_trait_effect = {
	save_scope_as = child_character
	# Find fitting trait
	random_list = {
		1 = { # Lustful
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = lustful }
				NOT = { has_trait = chaste }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = lustful }
		}
		1 = { # Chaste
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = chaste }
				NOT = { has_trait = lustful }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = chaste }
		}
		1 = { # Gluttonous
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = gluttonous }
				NOT = { has_trait = temperate }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = gluttonous }
		}
		1 = { # Temperate
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = temperate }
				NOT = { has_trait = gluttonous }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = temperate }
		}
		1 = { # Greedy
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = greedy }
				NOT = { has_trait = generous }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = greedy }
		}
		1 = { # Generous
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = generous }
				NOT = { has_trait = greedy }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = generous }
		}
		1 = { # Lazy
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = lazy }
				NOT = { has_trait = diligent }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = lazy }
		}
		1 = { # Diligent
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = diligent }
				NOT = { has_trait = lazy }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = diligent }
		}
		1 = { # Wrathful
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = wrathful }
				NOT = { has_trait = calm }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = wrathful }
		}
		1 = { # Calm
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = calm }
				NOT = { has_trait = wrathful }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = calm }
		}
		1 = { # Patient
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = patient }
				NOT = { has_trait = impatient }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = patient }
		}
		1 = { # Impatient
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = impatient }
				NOT = { has_trait = patient }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = impatient }
		}
		1 = { # Arrogant
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = arrogant }
				NOT = { has_trait = humble }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = arrogant }
		}
		1 = { # Humble
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = humble }
				NOT = { has_trait = arrogant }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = humble }
		}
		1 = { # Deceitful
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = deceitful }
				NOT = { has_trait = honest }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = deceitful }
		}
		1 = { # Honest
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = honest }
				NOT = { has_trait = deceitful }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = honest }
		}
		1 = { # Craven
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = craven }
				NOT = { has_trait = brave }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = craven }
		}
		1 = { # Brave
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = brave }
				NOT = { has_trait = craven }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = brave }
		}
		1 = { # Shy
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = shy }
				NOT = { has_trait = gregarious }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = shy }
		}
		1 = { # Gregarious
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = gregarious }
				NOT = { has_trait = shy }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = gregarious }
		}
		1 = { # Ambitious
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = ambitious }
				NOT = { has_trait = content }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = ambitious }
		}
		1 = { # Content
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = content }
				NOT = { has_trait = ambitious }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = content }
		}
		1 = { # Arbitrary
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = arbitrary }
				NOT = { has_trait = just }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = arbitrary }
		}
		1 = { # Just
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = just }
				NOT = { has_trait = arbitrary }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = just }
		}
		1 = { # Cynical
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = cynical }
				NOT = { has_trait = zealous }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = cynical }
		}
		1 = { # Zealous
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = zealous }
				NOT = { has_trait = cynical }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = zealous }
		}
		1 = { # Paranoid
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = paranoid }
				NOT = { has_trait = trusting }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = paranoid }
		}
		1 = { # Trusting
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = trusting }
				NOT = { has_trait = paranoid }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = trusting }
		}
		1 = { # Compassionate
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = compassionate }
				NOR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = compassionate }
		}
		1 = { # Callous
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = callous }
				NOR = {
					has_trait = compassionate
					has_trait = sadistic
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = callous }
		}
		1 = { # Sadistic
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = sadistic }
				NOR = {
					has_trait = compassionate
					has_trait = callous
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = sadistic }
		}
		1 = { # Stubborn
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = stubborn }
				NOR = {
					has_trait = fickle
					has_trait = eccentric
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = stubborn }
		}
		1 = { # Fickle
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = fickle }
				NOR = {
					has_trait = stubborn
					has_trait = eccentric
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = fickle }
		}
		1 = { # Eccentric
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = eccentric }
				NOR = {
					has_trait = stubborn
					has_trait = fickle
				}
			}
			wet_nurse_instill_virtue_effect = { TRAIT = eccentric }
		}
		1 = { # Vengeful
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = vengeful }
				NOT = { has_trait = forgiving }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = vengeful }
		}
		1 = { # Forgiving
			trigger = {
				wet_nurse_instill_virtue_trigger = { TRAIT = forgiving }
				NOT = { has_trait = vengeful }
			}
			wet_nurse_instill_virtue_effect = { TRAIT = forgiving }
		}
	}
}

promote_relationships_remove_relation_effect = {
	random_relation = {
		type = $RELATION$
		save_scope_as = relation
	}
	remove_relation_bully = scope:relation
}

court_position_vacated_event_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {

						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {

						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {

					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {

					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {

						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			#Release a prisoner
			every_prisoner = {
				limit = {
					is_ruler = no
					is_adult = yes
					is_incapable = no
					is_alive = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_temporary_list = prisoner_candidates
			}
			ordered_in_list = {
				list = prisoner_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = prisoner_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_fg_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			#Release a prisoner
			every_prisoner = {
				limit = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					is_ruler = no
					is_adult = yes
					is_incapable = no
					is_alive = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_temporary_list = prisoner_candidates
			}
			ordered_in_list = {
				list = prisoner_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = prisoner_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_wn_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					NOT = {
						is_close_family_of = root
					}
					age <= 45
					is_female = yes
					has_no_particular_noble_roots_trigger = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					NOT = {
						is_close_family_of = root
					}
					age <= 45
					is_female = yes
					has_no_particular_noble_roots_trigger = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						NOT = {
							is_close_family_of = root
						}
						age <= 45
						is_female = yes
						has_no_particular_noble_roots_trigger = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			if = {
				limit = {
					NOT = {exists = scope:stranger_candidate}
				}
				create_character = { #create a good candidate with a child
					template = bp2_wet_nurse_template
					location = root.location
					save_scope_as = stranger_candidate
				}
				create_character = {
					template = peasant_child_character
					age = { 0 5 }
					culture = root.culture
					faith = root.faith
					location = root.location
					save_scope_as = stranger_candidate_child
				}
				scope:stranger_candidate_child = {
					set_mother = scope:stranger_candidate
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_lin_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {
						is_female = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {
						is_female = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								is_female = yes
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								is_female = yes
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					is_female = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					is_female = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						is_female = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			#Release a prisoner
			every_prisoner = {
				limit = {
					is_female = yes
					is_ruler = no
					is_adult = yes
					is_incapable = no
					is_alive = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_temporary_list = prisoner_candidates
			}
			ordered_in_list = {
				list = prisoner_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = prisoner_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_eun_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {
						has_trait = eunuch
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {
						has_trait = eunuch
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								has_trait = eunuch
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								has_trait = eunuch
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					has_trait = eunuch
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					has_trait = eunuch
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						has_trait = eunuch
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			#Release a prisoner
			every_prisoner = {
				limit = {
					has_trait = eunuch
					is_ruler = no
					is_adult = yes
					is_incapable = no
					is_alive = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_temporary_list = prisoner_candidates
			}
			ordered_in_list = {
				list = prisoner_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = prisoner_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_art_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {
						has_completed_inspiration = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {
						has_completed_inspiration = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								has_completed_inspiration = yes
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								has_completed_inspiration = yes
								is_unemployed_able_adult = yes
								is_ruler = no
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					has_completed_inspiration = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					has_completed_inspiration = yes
					is_unemployed_able_adult = yes
					is_ruler = no
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						has_completed_inspiration = yes
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			#Release a prisoner
			every_prisoner = {
				limit = {
					has_completed_inspiration = yes
					is_ruler = no
					is_adult = yes
					is_incapable = no
					is_alive = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_temporary_list = prisoner_candidates
			}
			ordered_in_list = {
				list = prisoner_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = prisoner_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}

court_position_vacated_event_epa_effect = {
	scope:liege = {
		if = {
			limit = {
				is_ai = no
				NOT = { has_player_court_position_automation_none = court_position_type:$COURT_POSITION_TYPE$ }
			}

			court_position_type:$COURT_POSITION_TYPE$ = {
				save_scope_as = court_position_type
			}
			#Candidates 1 & 2 - best of already present vassals & court members, used in automode
			ordered_court_position_candidate = { 
				court_position_type = scope:court_position_type
				order_by = aptitude_score:$COURT_POSITION_TYPE$

				# Previous holder might still be in the court/alive - lets not include them
				limit = { NOT = { this = scope:employee } }
				max = 2
				check_range_bounds = no

				if = {
					limit = { NOT = { exists = scope:candidate_1 } }
					save_scope_as = candidate_1
				}
				else_if = {
					limit = { NOT = { exists = scope:candidate_2 } }
					save_scope_as = candidate_2
				}
			}
			#Close Family Nepo
			every_close_family_member = {
				if = {
					limit = {
						OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
							is_landed = no
							custom_tooltip = {
								text = eparch_distance_trigger_desc
								capital_province ?= {
									squared_distance = {
										target = scope:liege.capital_province
										value < 50000
									}
								}
								government_allows = administrative
							}
						}
						# Eunuchs were historically not allowed to have this position
						NOT = { has_trait = eunuch }
						is_unemployed_able_adult = yes
						cpa_is_not_a_candidate = yes
					}
					add_to_list = close_nepo_candidates
				}
			}
			ordered_in_list = {
				list = close_nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = close_nepo_candidate
			}
			#Any Family Nepo
			every_close_or_extended_family_member = {
				if = {
					limit = {
						OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
							is_landed = no
							custom_tooltip = {
								text = eparch_distance_trigger_desc
								capital_province ?= {
									squared_distance = {
										target = scope:liege.capital_province
										value < 50000
									}
								}
								government_allows = administrative
							}
						}
						# Eunuchs were historically not allowed to have this position
						NOT = { has_trait = eunuch }
						is_unemployed_able_adult = yes
						cpa_is_not_a_candidate = yes
					}
					add_to_list = nepo_candidates
				}
			}
			ordered_in_list = {
				list = nepo_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = nepo_candidate
			}
			#Spouse Nepo
			if = {
				limit = {
					exists = root.primary_spouse
				}
				root.primary_spouse = {
					save_scope_as = spouse
				}
				scope:spouse = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
									is_landed = no
									custom_tooltip = {
										text = eparch_distance_trigger_desc
										capital_province ?= {
											squared_distance = {
												target = scope:liege.capital_province
												value < 50000
											}
										}
										government_allows = administrative
									}
								}
								# Eunuchs were historically not allowed to have this position
								NOT = { has_trait = eunuch }
								is_unemployed_able_adult = yes
								cpa_is_not_a_candidate = yes
								NOT = {
									is_close_or_extended_family_of = root
								}
							}
							add_to_list = spouse_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = spouse_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = spouse_nepo_candidate
				}
			}
			#Vassal Nepo
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					opinion = {
						target = root
						value < 80
					}
					is_in_civil_war = no
					OR = {
						is_a_faction_leader = yes
						is_a_faction_member = yes
					}
				}
				save_scope_as = vassal
			}
			if = {
				limit = {
					NOT = {
						exists = scope:vassal
					}
				}
				ordered_vassal = {
					order_by = max_military_strength
					limit = {
						opinion = {
							target = root
							value < 80
						}
						is_in_civil_war = no
					}
					save_scope_as = vassal
				}
			}
			if = {
				limit = {
					exists = scope:vassal
				}
				scope:vassal = {
					every_close_or_extended_family_member = {
						if = {
							limit = {
								OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
									is_landed = no
									custom_tooltip = {
										text = eparch_distance_trigger_desc
										capital_province ?= {
											squared_distance = {
												target = scope:liege.capital_province
												value < 50000
											}
										}
										government_allows = administrative
									}
								}
								# Eunuchs were historically not allowed to have this position
								NOT = { has_trait = eunuch }
								is_unemployed_able_adult = yes
								cpa_is_not_a_candidate = yes
							}
							add_to_list = vassal_nepo_candidates
						}
					}
				}
				ordered_in_list = {
					list = vassal_nepo_candidates
					order_by = aptitude_score:$COURT_POSITION_TYPE$
					save_scope_as = vassal_nepo_candidate
				}
			}
			#Hire your friend
			every_relation = {
				type = friend
				limit = {
					OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
						is_landed = no
						custom_tooltip = {
							text = eparch_distance_trigger_desc
							capital_province ?= {
								squared_distance = {
									target = scope:liege.capital_province
									value < 50000
								}
							}
							government_allows = administrative
						}
					}
					# Eunuchs were historically not allowed to have this position
					NOT = { has_trait = eunuch }
					is_unemployed_able_adult = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_list = friend_candidates
			}
			ordered_in_list = {
				list = friend_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = friend_candidate
			}
			#Hire your lover
			every_relation = {
				type = lover
				limit = {
					OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
					is_landed = no
					custom_tooltip = {
						text = eparch_distance_trigger_desc
						capital_province ?= {
							squared_distance = {
								target = scope:liege.capital_province
								value < 50000
							}
						}
						government_allows = administrative
					}
				}
				# Eunuchs were historically not allowed to have this position
				NOT = { has_trait = eunuch }
					is_unemployed_able_adult = yes
					cpa_is_not_a_candidate = yes
				}
				add_to_list = lover_candidates
			}
			ordered_in_list = {
				list = lover_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = lover_candidate
			}
			#Hire a skilled stranger
			every_realm_province = {
				if = {
					limit = {
						save_temporary_scope_as = potential_province
						NOT = {
							any_in_list = {
								list = pool_provinces
								county.duchy = scope:potential_province.county.duchy
							}
						}
					}
					add_to_temporary_list = pool_provinces
				}
			}
			every_in_list = {
				list = pool_provinces
				save_temporary_scope_as = pool_province
				every_pool_character = {
					province = scope:pool_province
					limit = {
						OR = { # Is either unlanded (a courtier or landless family head) or a governor of a nearby theme
						is_landed = no
						custom_tooltip = {
							text = eparch_distance_trigger_desc
							capital_province ?= {
								squared_distance = {
									target = scope:liege.capital_province
									value < 50000
								}
							}
							government_allows = administrative
						}
					}
					# Eunuchs were historically not allowed to have this position
					NOT = { has_trait = eunuch }
						is_unemployed_able_adult = yes
						is_ruler = no
						cpa_is_not_a_candidate = yes
					}
					add_to_temporary_list = stranger_candidates
				}
			}
			ordered_in_list = {
				list = stranger_candidates
				order_by = aptitude_score:$COURT_POSITION_TYPE$
				save_scope_as = stranger_candidate
			}
			if = {
				limit = {
					OR = {
						has_player_court_position_automation_assign_best = scope:court_position_type
						has_player_court_position_automation_assign_best_or_event = scope:court_position_type
					}
					exists = scope:candidate_1
				}

				appoint_court_position = {
					recipient = scope:candidate_1
					court_position = scope:court_position_type
				}
			}
			else_if = {
				limit = {
					has_player_court_position_automation_assign_best = scope:court_position_type
				}
				# Do nothing, the player does not want an event
			}
			else_if = {
				limit = { is_landless_adventurer = yes }
				trigger_event = court_position_management_event.0002
			}
			else = {
				trigger_event = court_position_management_event.0001
			}
		}
	}
}
court_astrologer_task_remove_seasonal_modifiers_effect = {
	hidden_effect = {
		remove_character_modifier = court_astrologer_abundant_grazing_modifier
		remove_character_modifier = court_astrologer_warm_nights_modifier
		remove_character_modifier = court_astrologer_sky_blessing_modifier
		remove_character_modifier = court_astrologer_white_zud_modifier
		remove_character_modifier = court_astrologer_cold_zud_modifier
		remove_character_modifier = court_astrologer_severe_drought_modifier
		remove_character_modifier = court_astrologer_havsarsan_zud_modifier
	}
}

court_astrologer_task_add_seasonal_modifiers_effect = {
	hidden_effect = {
		save_scope_as = current_character
		capital_province.county = {
			random_county_situation_sub_region = {
				limit = {
					OR = {
						sub_region_current_phase = situation_steppe_abundant_grazing_season
						sub_region_current_phase = situation_steppe_warm_nights_season
						sub_region_current_phase = situation_steppe_sky_blessing_season
						sub_region_current_phase = situation_steppe_white_zud_season
						sub_region_current_phase = situation_steppe_cold_zud_season
						sub_region_current_phase = situation_steppe_severe_drought_season
						sub_region_current_phase = situation_steppe_havsarsan_zud_season
					}
				}
				switch = {
					trigger = sub_region_current_phase
					situation_steppe_abundant_grazing_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_abundant_grazing_modifier
						}
					}
					situation_steppe_warm_nights_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_warm_nights_modifier
						}
					}
					situation_steppe_sky_blessing_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_sky_blessing_modifier
						}
					}
					situation_steppe_white_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_white_zud_modifier
						}
					}
					situation_steppe_cold_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_cold_zud_modifier
						}
					}
					situation_steppe_severe_drought_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_severe_drought_modifier
						}
					}
					situation_steppe_havsarsan_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_havsarsan_zud_modifier
						}
					}
				}
			}
		}
	}
}

court_astrologer_task_remove_seasonal_modifiers_effect = {
	hidden_effect = {
		remove_character_modifier = court_astrologer_abundant_grazing_modifier
		remove_character_modifier = court_astrologer_warm_nights_modifier
		remove_character_modifier = court_astrologer_sky_blessing_modifier
		remove_character_modifier = court_astrologer_white_zud_modifier
		remove_character_modifier = court_astrologer_cold_zud_modifier
		remove_character_modifier = court_astrologer_severe_drought_modifier
		remove_character_modifier = court_astrologer_havsarsan_zud_modifier
	}
}

court_astrologer_task_add_seasonal_modifiers_effect = {
	hidden_effect = {
		save_scope_as = current_character
		capital_province.county = {
			random_county_situation_sub_region = {
				limit = {
					OR = {
						sub_region_current_phase = situation_steppe_abundant_grazing_season
						sub_region_current_phase = situation_steppe_warm_nights_season
						sub_region_current_phase = situation_steppe_sky_blessing_season
						sub_region_current_phase = situation_steppe_white_zud_season
						sub_region_current_phase = situation_steppe_cold_zud_season
						sub_region_current_phase = situation_steppe_severe_drought_season
						sub_region_current_phase = situation_steppe_havsarsan_zud_season
					}
				}
				switch = {
					trigger = sub_region_current_phase
					situation_steppe_abundant_grazing_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_abundant_grazing_modifier
						}
					}
					situation_steppe_warm_nights_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_warm_nights_modifier
						}
					}
					situation_steppe_sky_blessing_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_sky_blessing_modifier
						}
					}
					situation_steppe_white_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_white_zud_modifier
						}
					}
					situation_steppe_cold_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_cold_zud_modifier
						}
					}
					situation_steppe_severe_drought_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_severe_drought_modifier
						}
					}
					situation_steppe_havsarsan_zud_season = {
						scope:current_character = {
							add_character_modifier = court_astrologer_havsarsan_zud_modifier
						}
					}
				}
			}
		}
	}
}

# Revoke any court position effect
## Please note that free_revoke_cost flag needs to be set.
## Save employer of person revoked as liege.
## REVOKED_CHARACTER also needs to be filled out.

revoke_specific_court_position_effect = {
	$LIEGE$ = {
		revoke_court_position = {
			recipient = $REVOKED_CHARACTER$
			court_position = $POS$_court_position
		}
		remove_character_flag = free_revoke_cost
	}
}

## Find POS in revoke_specific_court_position_effect
fire_specific_court_position_effect = {
	switch = {
		trigger = has_court_position
		court_physician_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_physician 
			}
		}
		cultural_emissary_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = cultural_emissary
			}
		}
		keeper_of_swans_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = keeper_of_swans
			}
		}
		chief_qadi_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = chief_qadi
			}
		}
		garuda_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = garuda
			}
		}
		court_gardener_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_gardener
			}
		}
		lady_in_waiting_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = lady_in_waiting
			}
		}
		antiquarian_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = antiquarian
			}
		}
		travel_leader_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = travel_leader
			}
		}
		wet_nurse_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = wet_nurse
			}
		}
		court_tutor_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_tutor
			}
		}
		food_taster_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = food_taster
			}
		}
		master_of_horse_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = master_of_horse
			}
		}
		master_of_hunt_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = master_of_hunt
			}
		}
		royal_architect_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = royal_architect
			}
		}
		high_almoner_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = high_almoner
			}
		}
		seneschal_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = seneschal
			}
		}
		cupbearer_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = cupbearer
			}
		}
		chief_eunuch_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = chief_eunuch
			}
		}
		court_jester_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_jester
			}
		}
		court_poet_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_poet
			}
		}
		court_musician_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_musician
			}
		}
		bodyguard_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = bodyguard
			}
		}
		champion_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = champion
			}
		}
		executioner_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = executioner
			}
		}
		court_artificer_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_artificer
			}
		}
		master_assassin_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = master_assassin
			}
		}
		cave_hermit_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = cave_hermit
			}
		}
		chronicler_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = chronicler
			}
		}
		court_scholar_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_scholar
			}
		}
		charioteer_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = charioteer
			}
		}
		bookmaker_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = bookmaker
			}
		}
		akolouthos_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = akolouthos
			}
		}
		court_brewmaster_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = court_brewmaster
			}
		}
		grand_preceptor_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = grand_preceptor
			}
		}
		grand_mentor_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = grand_mentor
			}
		}
		grand_guardian_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = grand_guardian
			}
		}
		fire_dragon_engineer_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = fire_dragon_engineer
			}
		}
		keeper_of_the_harem_court_position = {
			revoke_specific_court_position_effect = {
				REVOKED_CHARACTER = $CHARACTER$
				LIEGE = $LIEGE$
				POS = keeper_of_the_harem
			}
		}
	}
}
