

###TRIGGER LIST

# councillor_loyalty_trigger

#Spouse councillor:
#


#TRIGGERS

can_be_councillor_basics_trigger = {
	is_available_quick = {
		adult = yes
		incapable = no
		imprisoned = no
	}
	is_at_war_with_liege = no
	trigger_if = {
		limit = { has_variable = block_hire_councillor }
		NOT = { var:block_hire_councillor = liege }
	}
}

can_be_chancellor_trigger = {
	can_be_councillor_basics_trigger = yes
	$COURT_OWNER$ ?= {
		NOT = { government_has_flag = government_is_nomadic }
	}
	NAND = {
		has_council_position = councillor_court_chaplain
		faith = { has_doctrine_parameter = clerical_appointment_fixed }
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = liege.diarch
			liege = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	OR = {
		is_ruler = yes
		AND = {
			is_female = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = male_dominated_council } }
		}
		AND = {
			is_male = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = female_dominated_council } }
		}
	}
}

can_be_steward_trigger = {
	can_be_councillor_basics_trigger = yes
	$COURT_OWNER$ ?= {
		NOT = { government_has_flag = government_is_nomadic }
	}
	NAND = {
		has_council_position = councillor_court_chaplain
		faith = { has_doctrine_parameter = clerical_appointment_fixed }
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = liege.diarch
			liege = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	OR = {
		is_ruler = yes
		AND = {
			is_female = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = male_dominated_council } }
		}
		AND = {
			is_male = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = female_dominated_council } }
		}
	}
}

can_be_marshal_trigger = {
	can_be_councillor_basics_trigger = yes
	$COURT_OWNER$ ?= {
		NOT = { government_has_flag = government_is_nomadic }
	}
	is_hostage = no
	NAND = {
		has_council_position = councillor_court_chaplain
		faith = { has_doctrine_parameter = clerical_appointment_fixed }
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = liege.diarch
			liege = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	OR = {
		is_ruler = yes
		AND = {
			is_female = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = male_dominated_council } }
		}
		AND = {
			is_male = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = female_dominated_council } }
		}
		AND = {
			has_trait = shieldmaiden
			$COURT_OWNER$.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
		}
	}
}

can_be_spymaster_trigger = {
	can_be_councillor_basics_trigger = yes
	NAND = {
		has_council_position = councillor_court_chaplain
		faith = { has_doctrine_parameter = clerical_appointment_fixed }
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = liege.diarch
			liege = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	exists = $COURT_OWNER$ #so we can have the argument but get no errors
}

can_be_court_chaplain_trigger = {
	save_temporary_scope_as = court_chaplain_check
	can_be_councillor_basics_trigger = yes
	$COURT_OWNER$ ?= {
		NOT = { government_has_flag = government_is_nomadic }
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = liege.diarch
			liege = { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	$COURT_OWNER$.faith = { has_allowed_gender_for_clergy = scope:court_chaplain_check }
	faith = $COURT_OWNER$.faith
	trigger_if = {
		limit = {
			faith = { has_doctrine = doctrine_theocracy_temporal }
		}
		OR = {
			is_ruler = no
			government_has_flag = government_is_theocracy
		}
	}
	trigger_if = {
		limit = {
			exists = var:escaped_imprisonment_from
		}
		NOT = { var:escaped_imprisonment_from = $COURT_OWNER$ }
	}
	trigger_if = { # An excommunicated ruler tolerate excommunicated bishops
		limit = {
			$COURT_OWNER$ ?= { NOT = { has_trait = excommunicated } }
		}
		NOT = { has_trait = excommunicated }
	}
}

can_be_spouse_councillor_trigger = {
	save_temporary_scope_as = spouse_councillor_check
	can_be_councillor_basics_trigger = yes
	#NOT = { # We allow spouses to both be regents and do their spouse job
	#	this = liege.diarch
	#}
	trigger_if = {
		limit = { is_ruler = yes }
		liege ?= $COUNCIL_OWNER$
		$COUNCIL_OWNER$ = { primary_spouse = scope:spouse_councillor_check }
	}
	trigger_else = {
		$COUNCIL_OWNER$ ?= { primary_spouse = scope:spouse_councillor_check }
	}
}

can_be_kurultai_trigger = {
	can_be_councillor_basics_trigger = yes
	exists = $COURT_OWNER$
	NOT = { government_has_flag = government_is_herder }
	NOR = {
		has_council_position = councillor_spouse
		has_court_position = court_astrologer_court_position
		AND = {
			this = $COURT_OWNER$.diarch
			$COURT_OWNER$ ?= { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	NOR = {
		has_council_position = $CP1$
		has_council_position = $CP2$
		has_council_position = $CP3$
	}
	OR = {
		is_landed = yes
		is_knight_of = $COURT_OWNER$
		is_courtier_of = $COURT_OWNER$
		is_ruler = yes
		is_powerful_vassal = yes
	}
	OR = {
		is_ruler = yes
		AND = {
			is_female = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = male_dominated_council } }
		}
		AND = {
			is_male = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = female_dominated_council } }
		}
		AND = {
			has_trait = shieldmaiden
			$COURT_OWNER$.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
		}
	}
}

can_be_any_kurultai_trigger = {
	can_be_councillor_basics_trigger = yes
	$COURT_OWNER$ ?= {
		OR = {
			has_council_position = councillor_kurultai_1
			has_council_position = councillor_kurultai_2
			has_council_position = councillor_kurultai_3
			has_council_position = councillor_kurultai_4
		}
	}
	NOR = {
		has_council_position = councillor_spouse
		AND = {
			this = $COURT_OWNER$.diarch
			$COURT_OWNER$ ?= { has_diarchy_active_parameter = diarchy_is_vizierate }
		}
	}
	NOR = {
		has_council_position = councillor_kurultai_1
		has_council_position = councillor_kurultai_2
		has_council_position = councillor_kurultai_3
		has_council_position = councillor_kurultai_4
	}
	OR = {
		is_landed = yes
		is_knight_of = $COURT_OWNER$
		is_courtier_of = $COURT_OWNER$
		is_ruler = yes
		is_powerful_vassal = yes
	}
	OR = {
		is_ruler = yes
		AND = {
			is_female = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = male_dominated_council } }
		}
		AND = {
			is_male = yes
			$COURT_OWNER$.faith = { NOT = { has_doctrine_parameter = female_dominated_council } }
		}
		AND = {
			has_trait = shieldmaiden
			$COURT_OWNER$.culture = { has_cultural_parameter = has_access_to_shieldmaidens }
		}
	}
}

is_kurultai_trigger = {
	OR = {
		has_council_position = councillor_kurultai_1
		has_council_position = councillor_kurultai_2
		has_council_position = councillor_kurultai_3
		has_council_position = councillor_kurultai_4
	}
}

has_any_kurultai_trigger = {
	OR = {
		exists = cp:councillor_kurultai_1
		exists = cp:councillor_kurultai_2
		exists = cp:councillor_kurultai_3
		exists = cp:councillor_kurultai_4
	}
}

councillor_loyalty_trigger = {
	weighted_calc_true_if = {
		amount >= 50
		20 = {
			NOT = { has_trait = ambitious }
		}
		20 = {
			opinion = {
				target = liege
				value > 0
			}
		}
		20 = {
			opinion = {
				target = liege
				value > 20
			}
		}
		20 = {
			opinion = {
				target = liege
				value > 40
			}
		}
		20 = {
			opinion = {
				target = liege
				value > 60
			}
		}
	}
}

############################
#SPOUSE COUNCILLOR TRIGGERS#
############################

valid_spouse_councillor_trigger = {
	scope:councillor = { is_available = yes }
	cp:councillor_spouse ?= scope:councillor
}

is_blocked_from_being_fired_from_council_trigger = {
	custom_description = {
		text = "is_blocked_from_being_fired_from_council"
		subject = this
		object = $COURT_OWNER$

		OR = {
			# Check in code if the court owner is prevented from firing the councilor
			# can_fire_position must take a council task as input, but checks the councilor behind the task.
			AND = {
				exists = this.council_task
				this.council_task = { can_fire_position = no }
			}
			# Check for variable preventing the firing of a councilor set by script
			AND = {
				has_variable = block_fire_councillor
				var:block_fire_councillor = $COURT_OWNER$
			}
		}
	}
}


can_be_fired_from_council_trigger = {
	NOT = {
		is_blocked_from_being_fired_from_council_trigger = { COURT_OWNER = $COURT_OWNER$ }
	}
	trigger_if = {
		limit = {
			has_council_position = councillor_court_chaplain
		}
		faith = {
			OR = {
				has_doctrine = doctrine_clerical_succession_temporal_appointment
				has_doctrine = doctrine_clerical_succession_spiritual_appointment
			}
		}
	}
}


#Faith/culture triggers
same_faith_or_culture_as_councillor_trigger = {
	OR = {
		culture = scope:councillor.culture
		faith = scope:councillor.faith
	}
}

different_faith_and_or_culture_from_councillor_trigger = {
	OR = {
		culture != scope:councillor.culture
		faith != scope:councillor.faith
	}
}

character_same_faith_as_councillor_but_different_from_root_trigger = {
	faith = scope:councillor.faith
	faith != root.faith
}

character_same_culture_as_councillor_but_different_from_root_trigger = {
	culture = scope:councillor.culture
	culture != root.culture
}


character_same_faith_or_culture_as_councillor_but_different_from_root_trigger = {
	OR = {
		character_same_faith_as_councillor_but_different_from_root_trigger = yes
		character_same_culture_as_councillor_but_different_from_root_trigger = yes
	}
}

character_different_culture_than_councillor_and_root_trigger = {
	NOR = {
		culture = scope:councillor.culture
		culture = root.culture
	}
}

character_different_faith_than_councillor_and_root_trigger = {
	NOR = {
		faith = scope:councillor.faith
		faith = root.faith
	}
}

character_different_faith_or_culture_than_councillor_and_root_trigger = {
	OR = {
		character_different_culture_than_councillor_and_root_trigger = yes
		character_different_faith_than_councillor_and_root_trigger = yes
	}
}

province_same_faith_or_culture_as_councillor_but_different_from_root_trigger = {
	OR = {
		AND = {
			culture = scope:councillor.culture
			culture != root.culture
		}
		AND = {
			faith = scope:councillor.faith
			faith != root.faith
		}
	}
}
#End of faith/culture triggers


#Councillor Spouse threshold triggers

#Intrigue
spouse_intrigue_tier_1_trigger = {
	scope:councillor = {
		OR = {
			has_character_modifier = councillor_spouse_intrigue_2_modifier
			has_character_modifier = councillor_spouse_intrigue_1_modifier
			has_trait = schemer
			intrigue >= spouse_skill_rating_1
			is_performing_council_task = task_court_intrigue
		}
	}
}

spouse_intrigue_tier_2_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 30
		}
		OR = {
			has_character_modifier = councillor_spouse_intrigue_2_modifier
			has_trait = schemer
			intrigue >= spouse_skill_rating_3
			AND = {
				is_performing_council_task = task_court_intrigue
				OR = {
					intrigue >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_intrigue_2_modifier
					has_character_modifier = councillor_spouse_intrigue_1_modifier
					has_trait = schemer
				}
			}
		}
	}
}

spouse_intrigue_tier_3_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 50
		}
		OR = {
			has_trait = schemer
			intrigue >= spouse_skill_rating_4
			AND = {
				is_performing_council_task = task_court_intrigue
				OR = {
					intrigue >= high_skill_rating
					has_character_modifier = councillor_spouse_intrigue_2_modifier
					has_trait = schemer
				}
			}
		}
	}
}

#Diplomacy
spouse_diplomacy_tier_1_trigger = {
	scope:councillor = {
		OR = {
			has_character_modifier = councillor_spouse_diplomacy_2_modifier
			has_character_modifier = councillor_spouse_diplomacy_1_modifier
			has_trait = diplomat
			diplomacy >= spouse_skill_rating_1
			is_performing_council_task = task_court_politics
		}
	}
}

spouse_diplomacy_tier_2_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 30
		}
		OR = {
			has_character_modifier = councillor_spouse_diplomacy_2_modifier
			has_trait = diplomat
			diplomacy >= spouse_skill_rating_3
			AND = {
				is_performing_council_task = task_court_politics
				OR = {
					diplomacy >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_diplomacy_2_modifier
					has_character_modifier = councillor_spouse_diplomacy_1_modifier
					has_trait = diplomat
				}
			}
		}
	}
}

spouse_diplomacy_tier_3_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 50
		}
		OR = {
			has_trait = diplomat
			diplomacy >= spouse_skill_rating_4
			AND = {
				is_performing_council_task = task_court_politics
				OR = {
					diplomacy >= spouse_skill_rating_2
					has_trait = diplomat
					has_character_modifier = councillor_spouse_diplomacy_2_modifier
				}
			}
		}
	}
}


#Martial
spouse_martial_tier_1_trigger = {
	scope:councillor = {
		OR = {
			has_character_modifier = councillor_spouse_martial_2_modifier
			has_character_modifier = councillor_spouse_martial_1_modifier
			has_trait = strategist
			martial >= spouse_skill_rating_1
			is_performing_council_task = task_chivalry
		}
	}
}

spouse_martial_tier_2_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 30
		}
		OR = {
			has_character_modifier = councillor_spouse_martial_2_modifier
			has_trait = strategist
			martial >= spouse_skill_rating_3
			AND = {
				is_performing_council_task = task_chivalry
				OR = {
					martial >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_martial_2_modifier
					has_character_modifier = councillor_spouse_martial_1_modifier
					has_trait = strategist
				}
			}
		}
	}
}

spouse_martial_tier_3_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 50
		}
		OR = {
			has_trait = strategist
			martial >= spouse_skill_rating_4
			AND = {
				is_performing_council_task = task_chivalry
				OR = {
					martial >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_martial_2_modifier
					has_trait = strategist
				}
			}
		}
	}
}



#Stewardship
spouse_stewardship_tier_1_trigger = {
	scope:councillor = {
		OR = {
			has_character_modifier = councillor_spouse_stewardship_2_modifier
			has_character_modifier = councillor_spouse_stewardship_1_modifier
			has_trait = architect
			stewardship >= spouse_skill_rating_1
			is_performing_council_task = task_manage_domain
		}
	}
}

spouse_stewardship_tier_2_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 30
		}
		OR = {
			has_character_modifier = councillor_spouse_stewardship_2_modifier
			has_trait = architect
			stewardship >= spouse_skill_rating_3
			AND = {
				is_performing_council_task = task_manage_domain
				OR = {
					stewardship >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_stewardship_2_modifier
					has_character_modifier = councillor_spouse_stewardship_1_modifier
					has_trait = architect
				}
			}
		}
	}
}

spouse_stewardship_tier_3_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 50
		}
		OR = {
			has_trait = architect
			stewardship >= spouse_skill_rating_4
			AND = {
				is_performing_council_task = task_manage_domain
				OR = {
					stewardship >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_stewardship_2_modifier
					has_trait = architect
				}
			}
		}
	}
}




#Learning
spouse_learning_tier_1_trigger = {
	scope:councillor = {
		OR = {
			has_character_modifier = councillor_spouse_learning_2_modifier
			has_character_modifier = councillor_spouse_learning_1_modifier
			has_trait = scholar
			learning >= spouse_skill_rating_1
			is_performing_council_task = task_patronage
		}
	}
}

spouse_learning_tier_2_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 30
		}
		OR = {
			has_character_modifier = councillor_spouse_learning_2_modifier
			has_trait = scholar
			learning >= spouse_skill_rating_3
			AND = {
				is_performing_council_task = task_patronage
				OR = {
					learning >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_learning_2_modifier
					has_character_modifier = councillor_spouse_learning_1_modifier
					has_trait = scholar
				}
			}
		}
	}
}

spouse_learning_tier_3_trigger = {
	scope:councillor = {
		opinion = {
			target = liege
			value > 50
		}
		OR = {
			has_trait = scholar
			learning >= spouse_skill_rating_4
			AND = {
				is_performing_council_task = task_patronage
				OR = {
					learning >= spouse_skill_rating_2
					has_character_modifier = councillor_spouse_learning_2_modifier
					has_trait = scholar
				}
			}
		}
	}
}

# Court Espionage task triggers
spymaster_task_find_secrets_interesting_secret_type_trigger = {
	save_temporary_scope_as = suitable_secret
	trigger_if = {
		limit = {
			secret_type = secret_disputed_heritage
			exists = secret_target
		}
		NOT = { secret_target = { has_trait = legitimized_bastard } }
	}
	OR = {
		secret_is_always_interesting_trigger = yes
		is_blackmailable_secret_trigger = { BLACKMAILER = scope:councillor_liege PARTICIPANT = scope:suitable_secret.secret_owner }
	}
}

spymaster_task_find_secrets_block_spymaster_self_reveal_trigger = {
	# Spymaster should not reveal secrets targeting themselves unless it is a murder attempt
	trigger_if = {
		limit = {
			exists = secret_target
			NOT = { secret_type = secret_murder_attempt }
		}
		secret_target != scope:councillor
	}
	# If the spymaster is the father of a secret bastard, don't reveal that
	trigger_if = {
		limit = {
			OR = {
				secret_type = secret_disputed_heritage
				secret_type = secret_unmarried_illegitimate_child
			}
			exists = secret_target.real_father
		}
		secret_target.real_father != scope:councillor
	}
}

spymaster_task_find_secrets_suitable_minor_secret_trigger = {
	OR = {
		is_shunned_for = secret_owner
		AND = {
			NOT = {
				is_blackmailable_secret_trigger = {
					PARTICIPANT = secret_owner
					BLACKMAILER = scope:councillor_liege
				}
			}
			secret_is_always_interesting_trigger = yes
		}
	}
	NOT = { is_known_by = scope:councillor_liege }
	spymaster_task_find_secrets_block_spymaster_self_reveal_trigger = yes
	NOT = {
		any_secret_participant = {
			OR = {
				this = scope:councillor
				this = scope:councillor_liege
			}
		}
	}
	spymaster_task_find_secrets_interesting_secret_type_trigger = yes
}

spymaster_task_find_secrets_suitable_major_secret_trigger = {
	is_criminal_for = secret_owner
	NOT = { is_known_by = scope:councillor_liege }
	spymaster_task_find_secrets_block_spymaster_self_reveal_trigger = yes
	NOT = {
		any_secret_participant = {
			OR = {
				this = scope:councillor
				this = scope:councillor_liege
			}
		}
	}
	spymaster_task_find_secrets_interesting_secret_type_trigger = yes
}

spymaster_task_find_secrets_court_has_minor_secrets_trigger = {
	OR = {
		AND = {
			has_any_secrets = yes
			any_secret = {
				spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
			}
		}
		any_vassal = {
			has_any_secrets = yes
			this != scope:councillor_liege
			this != scope:councillor
			any_secret = {
				spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
			}
		}
		any_courtier_or_guest = {
			has_any_secrets = yes
			this != scope:councillor_liege
			this != scope:councillor
			any_secret = {
				spymaster_task_find_secrets_suitable_minor_secret_trigger = yes
			}
		}
	}
}

spymaster_task_find_secrets_court_has_major_secrets_trigger = {
	OR = {
		AND = {
			has_any_secrets = yes
			any_secret = {
				spymaster_task_find_secrets_suitable_major_secret_trigger = yes
			}
		}
		any_vassal = {
			has_any_secrets = yes
			this != scope:councillor_liege
			this != scope:councillor
			any_secret = {
				spymaster_task_find_secrets_suitable_major_secret_trigger = yes
			}
		}
		any_courtier_or_guest = {
			has_any_secrets = yes
			this != scope:councillor_liege
			this != scope:councillor
			any_secret = {
				spymaster_task_find_secrets_suitable_major_secret_trigger = yes
			}
		}
	}
}

spymaster_find_secrets_secret_holder_is_interesting_to_me_trigger = {
	scope:councillor_liege = {
		save_temporary_scope_as = me
	}
	scope:secret_holder ?= {
		OR = {
			is_ruler = yes
			is_close_or_extended_family_of = scope:me
			is_courtier_of = scope:me
			has_relation_rival = scope:me
			has_relation_lover = scope:me
			is_player_heir_of = scope:me
		}
	}
}

spymaster_find_secrets_secret_target_is_interesting_to_me_trigger = {
	scope:councillor_liege = {
		save_temporary_scope_as = me
	}
	trigger_if = {
		limit = {
			exists = secret_target
		}
		secret_target = {
			OR = {
				is_close_or_extended_family_of = scope:me
				is_courtier_of = scope:me
				has_relation_rival = scope:me
				has_relation_lover = scope:me
				is_player_heir_of = scope:me
			}
		}
	}
	trigger_else = {
		always = no
	}
}


# Event triggers
# Defined here because they need to be used in event + council task desc

marshal_task_1101_county_trigger = {
	holder = root
	NOT = {
		has_county_modifier = marshal_task_organized_service_modifier
	}
}

marshal_task_1102_county_trigger = {
	NOT = {
		has_county_modifier = marshal_task_military_presence_modifier
	}
}

marshal_task_1003_county_trigger = {
	is_valid_for_county_corruption_trigger = yes
	OR = {
		NOT = { has_county_modifier = county_corruption_unsafe_highways_modifier }
		NOT = { has_county_modifier = county_corruption_thieves_guild_modifier }
		NOT = { has_county_modifier = county_corruption_bandits_rampant_modifier }
	}
}

steward_task_county_corruption_county_trigger = {
	holder = {
		OR = {
			is_ai = yes
			this = root
		}
	}
}

councillor_spouse_learning_2603_valid_councillor_trigger = {
	is_available_ai_adult = yes
	this != scope:councillor
}


councillor_liege_has_erudition_legacy_5_perk = {
	scope:councillor_liege.dynasty ?= { has_dynasty_perk = erudition_legacy_5 }
}


councillor_liege_has_customs_legacy_perk = {
	scope:councillor_liege.dynasty ?= { has_dynasty_perk = ep1_culture_legacy_2 }
}

councillor_liege_has_family_business_bonus = {
	scope:councillor_liege.culture ?= { has_cultural_parameter = close_family_better_councillors }
	scope:councillor ?= {
		is_close_family_of = scope:councillor_liege
	}
}

councillor_liege_has_consulted_house_bonus = {
	scope:councillor_liege ?= { has_character_flag = fp3_consulted_house }
	scope:councillor.house ?= scope:councillor_liege.house
}

councillor_is_unskilled_trigger = {
	trigger_if = {
		limit = { $EMPLOYER$.cp:councillor_chancellor ?= this }
		diplomacy < mediocre_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_steward ?= this }
		stewardship < mediocre_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_marshal ?= this }
		martial < mediocre_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_spymaster ?= this }
		intrigue < mediocre_skill_rating
	}
	trigger_else = { learning < mediocre_skill_rating }
}

councillor_is_skilled_trigger = {
	trigger_if = {
		limit = { $EMPLOYER$.cp:councillor_chancellor ?= this }
		diplomacy > decent_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_steward ?= this }
		stewardship > decent_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_marshal ?= this }
		martial > decent_skill_rating
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_spymaster ?= this }
		intrigue > decent_skill_rating
	}
	trigger_else = { learning > decent_skill_rating }
}

kurultai_is_skilled_trigger = {
	trigger_if = {
		limit = { $EMPLOYER$.cp:councillor_kurultai_1 ?= this }
		OR = {
			average_skill_rating >= sum_of_all_skills_threshold_average
			has_any_high_skill_rating = yes
		}
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_kurultai_2 ?= this }
		OR = {
			average_skill_rating >= sum_of_all_skills_threshold_average
			has_any_high_skill_rating = yes
		}
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_kurultai_3 ?= this }
		OR = {
			average_skill_rating >= sum_of_all_skills_threshold_average
			has_any_high_skill_rating = yes
		}
	}
	trigger_else_if = {
		limit = { $EMPLOYER$.cp:councillor_kurultai_4 ?= this }
		OR = {
			average_skill_rating >= sum_of_all_skills_threshold_average
			has_any_high_skill_rating = yes
		}
	}
	trigger_else = { intrigue > decent_skill_rating } # Spymaster
}

#FP3 Legacy Track:
councillor_liege_has_khvarenah_legacy_perk = {
	exists = scope:councillor_liege.dynasty
	scope:councillor_liege.dynasty = { has_dynasty_perk = fp3_khvarenah_legacy_4 }
}

can_be_knight_now_light_trigger = {
	is_available_quick = {
		ai = yes # Players can't be knights
		imprisoned = no
		adult = yes
		alive = yes
	}
}

can_be_trained_as_knight_now_light_trigger = {
	can_be_knight_now_light_trigger = yes
	is_in_army = no
	has_contagious_deadly_disease_trigger = no
	NOT = { has_trait = incapable }
	custom_description = {
		text = ALREADY_IN_ACTIVITY
		NOR = {
			exists = involved_activity
			has_variable = homage_liege_scope
			has_character_flag = meditation_character_flag
			has_character_flag = local_shrine_rite
			has_character_flag = petition_liege_character_flag
			has_character_flag = holding_court_character_flag
			is_being_visited_on_tour_strict = yes
		}
	}
	custom_description = {
		text = ALREADY_PLANNING_ACTIVITY
		NOT = { has_character_flag = planning_an_activity }
	}
	# Variable set within the adventure inspiration events
	NOT = { has_variable = gone_adventuring }
}

teacher_has_trait_that_student_does_not_trigger = {
	OR = {
		AND = {
			$TEACHER$ = { has_trait = logistician }
			$STUDENT$ = { NOT = { has_trait = logistician } }
		}
		AND = {
			$TEACHER$ = { has_trait = military_engineer }
			$STUDENT$ = { NOT = { has_trait = military_engineer } }
		}
		AND = {
			$TEACHER$ = { has_trait = aggressive_attacker }
			$STUDENT$ = { NOT = { has_trait = aggressive_attacker } }
		}
		AND = {
			$TEACHER$ = { has_trait = unyielding_defender }
			$STUDENT$ = { NOT = { has_trait = unyielding_defender } }
		}
		AND = {
			$TEACHER$ = { has_trait = forder }
			$STUDENT$ = { NOT = { has_trait = forder } }
		}
		AND = {
			$TEACHER$ = { has_trait = flexible_leader }
			$STUDENT$ = { NOT = { has_trait = flexible_leader } }
		}
		AND = {
			$TEACHER$ = { has_trait = desert_warrior }
			$STUDENT$ = { NOT = { has_trait = desert_warrior } }
		}
		AND = {
			$TEACHER$ = { has_trait = jungle_stalker }
			$STUDENT$ = { NOT = { has_trait = jungle_stalker } }
		}
		AND = {
			$TEACHER$ = { has_trait = winter_soldier }
			$STUDENT$ = { NOT = { has_trait = winter_soldier } }
		}
		AND = {
			$TEACHER$ = { has_trait = reaver }
			$STUDENT$ = { NOT = { has_trait = reaver } }
		}
		AND = {
			$TEACHER$ = { has_trait = reckless }
			$STUDENT$ = { NOT = { has_trait = reckless } }
		}
		AND = {
			$TEACHER$ = { has_trait = holy_warrior }
			$STUDENT$ = { NOT = { has_trait = holy_warrior } }
		}
		AND = {
			$TEACHER$ = { has_trait = open_terrain_expert }
			$STUDENT$ = { NOT = { has_trait = open_terrain_expert } }
		}
		AND = {
			$TEACHER$ = { has_trait = rough_terrain_expert }
			$STUDENT$ = { NOT = { has_trait = rough_terrain_expert } }
		}
		AND = {
			$TEACHER$ = { has_trait = forest_fighter }
			$STUDENT$ = { NOT = { has_trait = forest_fighter } }
		}
		AND = {
			$TEACHER$ = { has_trait = cautious_leader }
			$STUDENT$ = { NOT = { has_trait = cautious_leader } }
		}
		AND = {
			$TEACHER$ = { has_trait = organizer }
			$STUDENT$ = { NOT = { has_trait = organizer } }
		}
	}
}
