﻿is_unemployed_able_adult = {
	is_physically_able_adult = yes
	court_position_does_not_already_have_a_job_trigger = yes
	cpa_does_not_already_have_a_job_trigger = yes
}

cpa_does_not_already_have_a_job_trigger = {
	#Not all jobs listed in court_position_does_not_already_have_a_job_trigger
	NOR = {
		# has_court_position = court_physician_court_position
		# has_court_position = cultural_emissary_court_position
		# has_court_position = keeper_of_swans_court_position
		# has_court_position = chief_qadi_court_position
		# has_court_position = garuda_court_position
		# has_court_position = master_of_horse_court_position
		# has_court_position = master_of_hunt_court_position
		# has_court_position = royal_architect_court_position
		# has_court_position = high_almoner_court_position
		# has_court_position = chief_eunuch_court_position
		# has_court_position = champion_court_position
		# has_court_position = court_cave_hermit_position
		# has_court_position = court_artificer_court_position
		# has_court_position = chronicler_court_position
		has_any_court_position = yes
		is_councillor = yes
		has_trait = kingsguard
		has_trait = nightswatch
		has_trait = silent_sister
		has_trait = maester
		#Shouldn't snoop dragonriders just because they're unemployed. Snooping is bad!
		AND = {
			exists = liege
			any_relation = {
				type = agot_dragon
			}
		}
		
		trigger_if ={ #exclude primary heirs and spouses
			limit = {
				exists = liege
				NOT = {
					liege ?= root
				}
			}
			OR = {
				is_primary_heir_of = liege
				is_primary_heir_of = father
				is_primary_heir_of = mother
				is_spouse_of = liege
				AND = {
					is_parent_of = liege
					#liege.age < 16
				}
			}
		}
	}
}

cpa_is_not_a_candidate = {
	is_adult = yes	#Another check, but I don't know if it will return true if all trigger_if's fail
	trigger_if = {
		limit = {
			exists = scope:close_nepo_candidate
		}
		NOT = {
			this = scope:close_nepo_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:nepo_candidate
		}
		NOT = {
			this = scope:nepo_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:spose_nepo_candidate
		}
		NOT = {
			this = scope:spose_nepo_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:vassal_nepo_candidate
		}
		NOT = {
			this = scope:vassal_nepo_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:friend_candidate
		}
		NOT = {
			this = scope:friend_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:courtier_candidate
		}
		NOT = {
			this = scope:courtier_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:prisoner_candidate
		}
		NOT = {
			this = scope:prisoner_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:stranger_candidate
		}
		NOT = {
			this = scope:stranger_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:vassal_candidate
		}
		NOT = {
			this = scope:vassal_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:rival_candidate
		}
		NOT = {
			this = scope:rival_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:nepo_mutulated_candidate
		}
		NOT = {
			this = scope:nepo_mutulated_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:vassal_mutulated_candidate
		}
		NOT = {
			this = scope:vassal_mutulated_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:courtier_mutulated_candidate
		}
		NOT = {
			this = scope:courtier_mutulated_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:mutulated_prisoner_candidate
		}
		NOT = {
			this = scope:mutulated_prisoner_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:stranger_mutulated_candidate
		}
		NOT = {
			this = scope:stranger_mutulated_candidate
		}
	}
	trigger_if = {
		limit = {
			exists = scope:vassal
			NOT = {
				exists = scope:vassal_nepo_candidate
			}
		}
		NOT = {
			this = scope:vassal
		}
	}
	trigger_if = {
		limit = {
			exists = scope:candidate_1
		}
		NOT = {
			this = scope:candidate_1
		}
	}
	trigger_if = {
		limit = {
			exists = scope:candidate_2
		}
		NOT = {
			this = scope:candidate_2
		}
	}
	trigger_if = {
		limit = {
			exists = scope:fallback_candidate_1
		}
		NOT = {
			this = scope:fallback_candidate_1
		}
	}
	trigger_if = {
		limit = {
			exists = scope:fallback_candidate_2
		}
		NOT = {
			this = scope:fallback_candidate_2
		}
	}
	trigger_if = {
		limit = {
			exists = scope:fallback_candidate_3
		}
		NOT = {
			this = scope:fallback_candidate_3
		}
	}
	trigger_if = {
		limit = {
			exists = scope:fallback_candidate_4
		}
		NOT = {
			this = scope:fallback_candidate_4
		}
	}
	trigger_if = {
		limit = {
			exists = scope:fallback_candidate_5
		}
		NOT = {
			this = scope:fallback_candidate_5
		}
	}
}

cpa_can_be_captured = {
	OR = {
		target_is_liege_or_above = root
		is_foreign_court_or_pool_guest_of = root
		is_pool_character = yes
	}
}

cpa_is_unemployed_adult = {
	court_position_does_not_already_have_a_job_trigger = yes
	cpa_does_not_already_have_a_job_trigger = yes
}

cpa_eligible_for_position = {
	switch = {
		trigger = scope:court_position_type
		# AGOT CROWNLANDS
		court_position_type:goldcloaks_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:sea_watch_commander_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:justiciar_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		# AGOT
		court_position_type:maester_court_position = {
			OR = {
				has_trait_xp = {
					trait = maester
					value = 100
				}
				has_trait = disgraced_maester
				has_character_flag = former_acolyte
			}
		}
		court_position_type:household_guard_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:admiral_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:septon_court_position = {
			has_trait = septon
			is_male = yes
		}
		court_position_type:septa_court_position = {
			has_trait = septon
			is_female = yes
		}
		court_position_type:first_sword_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:grey_cloaks_commander_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:crimson_cloaks_commander_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:white_knife_court_position = {
			OR = {
				has_title = title:k_the_white_knife
				has_title = title:d_white_harbor
				has_title = title:d_keystone
			}
		}
		court_position_type:stone_way_court_position = {
			OR = {
				has_title = title:k_yronwood
				has_title = title:d_the_stoneway
				has_title = title:d_greenbelt
			}
		}
		court_position_type:princes_pass_court_position = {
			OR = {
				has_title = title:k_the_red_mountains
				has_title = title:d_the_princes_pass
				has_title = title:d_redmarch
			}
		}
		court_position_type:lorath_harvest_prince_court_position = {
			has_title = title:d_harvest_principality
		}
		court_position_type:lorath_fisher_prince_court_position = {
			has_title = title:d_fisher_principality
		}
		court_position_type:lorath_prince_of_streets_court_position = {
			has_title = title:d_principality_of_the_streets
		}
		# VANILLA
		court_position_type:wet_nurse_court_position = {
			is_female = yes
			effective_age < 46
			NOT = { is_close_family_of = scope:liege }
			has_no_particular_noble_roots_trigger = yes
		}
		court_position_type:charioteer_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
			has_no_particular_noble_roots_trigger = yes
		}
		court_position_type:bookmaker_court_position = {
			has_no_particular_noble_roots_trigger = yes
		}
		court_position_type:akolouthos_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:chief_eunuch_court_position = {
			is_eunuch_trigger = yes
		}
		court_position_type:master_assassin_court_position = {
			has_no_particular_noble_roots_trigger = yes
		}
		court_position_type:cultural_emissary_court_position = {
			# I hate how long I had to look for it
			diplomacy >= 8
		}
		court_position_type:cave_hermit_court_position = {
			has_trait = lifestyle_mystic
			has_trait_xp = {
				trait = lifestyle_mystic
				value >= 50
			}
		}
		court_position_type:court_gardener_court_position = {
			stewardship >= 12
		}
		court_position_type:chronicler_court_position = {
			diplomacy >= 12
		}
		court_position_type:champion_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:court_brewmaster_court_position = {
			drinks_alcohol_trigger = yes
			OR = {
				learning >= 12
				has_trait = lifestyle_reveler
				has_trait = diligent
				has_trait = patient
			}
		}
		court_position_type:lady_in_waiting_court_position = {
			is_female = yes
		}
		court_position_type:bodyguard_court_position = {
			can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:liege }
		}
		court_position_type:court_artificer_court_position = {
			OR = {
				has_completed_inspiration = yes
				exists = inspiration
			}
		}
		# Rest of positions with no special requirements
		fallback = {
			always = yes
		}
	}
}