
###TRIGGER LIST

#################################
# RELATIONSHIP SETTING TRIGGERS #
#################################

### FRIEND ###
can_set_relation_potential_friend_trigger = {
	NOT = { has_relation_potential_friend = $CHARACTER$ }
	can_set_relation_friend_trigger = { CHARACTER = $CHARACTER$ }
}

can_set_relation_friend_trigger = {
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
}

can_set_relation_best_friend_trigger = {
	NOR = {
		this = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
	num_of_relation_best_friend = 0
	$CHARACTER$ = { num_of_relation_best_friend = 0 }
}

### LOVER ###
can_set_relation_potential_lover_trigger = {
	NOT = { has_relation_potential_lover = $CHARACTER$ }
	can_set_relation_lover_trigger = { CHARACTER = $CHARACTER$ }
}

can_set_relation_lover_trigger = {
	is_adult = yes
	NOR = {
		this = $CHARACTER$
		has_relation_lover = $CHARACTER$
	}
	is_attracted_to_gender_of = $CHARACTER$
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
	}
}

can_set_relation_soulmate_trigger = {
	is_adult = yes
	#Some asexuality handling
	trigger_if = {
		limit = { has_sexuality = asexual }
		trigger_if = {
			limit = { is_ai = yes }
			always = no
		}
		trigger_else = {
			$CHARACTER$ = { is_consort_of = prev }
		}
	}
	trigger_else = { is_attracted_to_gender_of = $CHARACTER$ }
	
	NOR = {
		this = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
	$CHARACTER$ = {
		is_adult = yes
		is_attracted_to_gender_of = prev
		num_of_relation_soulmate = 0
	}
	num_of_relation_soulmate = 0
}

### RIVAL ###
can_set_relation_potential_rival_trigger = {
	can_set_relation_rival_if_adult_trigger = { CHARACTER = $CHARACTER$ }
	NOT = { has_relation_potential_rival = $CHARACTER$ }
}

can_set_relation_rival_if_adult_trigger = {
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
}

can_set_relation_rival_trigger = {
	is_adult = yes
	$CHARACTER$ = { is_adult = yes }
	can_set_relation_rival_if_adult_trigger = { CHARACTER = $CHARACTER$ }
}

can_set_relation_nemesis_trigger = {
	is_adult = yes
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
	}
	num_of_relation_nemesis = 0
	$CHARACTER$ = {
		is_adult = yes
		num_of_relation_nemesis = 0
	}
}

can_set_relation_bully_trigger = {
	is_adult = no
	$CHARACTER$ = { is_adult = no }
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_bully = $CHARACTER$
		has_relation_victim = $CHARACTER$
	}
}

can_set_relation_victim_trigger = {
	is_adult = no
	$CHARACTER$ = { is_adult = no }
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_bully = $CHARACTER$
		has_relation_victim = $CHARACTER$
	}
}

can_set_relation_rival_even_if_teen_trigger = {
	OR = {
		is_adult = yes
		child_is_teen_trigger = yes
	}
	$CHARACTER$ = {
		OR = {
			is_adult = yes
			child_is_teen_trigger = yes
		}
	}
	can_set_relation_rival_if_adult_trigger = { CHARACTER = $CHARACTER$ }
}

can_set_relation_nemesis_even_if_teen_trigger = {
	OR = {
		is_adult = yes
		child_is_teen_trigger = yes
	}
	$CHARACTER$ = {
		OR = {
			is_adult = yes
			child_is_teen_trigger = yes
		}
	}
	NOR = {
		this = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
	}
	num_of_relation_nemesis = 0
	$CHARACTER$ = { num_of_relation_nemesis = 0 }
}

### GRUDGE
can_set_relation_grudge_trigger = {
	can_set_relation_grudge_if_adult_trigger = { CHARACTER = $CHARACTER$ }
	NOT = { has_relation_grudge = $CHARACTER$ }
}

can_set_relation_grudge_if_adult_trigger = {
	NOT = { this = $CHARACTER$ }
	NOR = {
		has_relation_friend = $CHARACTER$
		has_relation_best_friend = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
}

### BLOOD BROTHER
can_set_relation_blood_brother_trigger = {
	NOT = { this = $CHARACTER$ }
	NOR = {
		has_relation_blood_brother = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_nemesis = $CHARACTER$
	}
	num_of_relation_blood_brother = 0
	$CHARACTER$ = { num_of_relation_blood_brother = 0 }
}

has_blood_brother = {
	num_of_relation_blood_brother >= 1
}

####################
# RELATION UPGRADE #
####################

# These are not hard blockers for upgrading relations, but are used in relation_upgrade events

### FRIEND
upgrade_ready_potential_friend_to_friend_trigger = {
	can_set_relation_friend_trigger = { CHARACTER = $CHARACTER$ }
}


### BEST FRIEND
upgrade_ready_friend_to_best_friend_trigger = {
	can_set_relation_best_friend_trigger = { CHARACTER = $CHARACTER$ }
}


### LOVER
upgrade_ready_potential_lover_to_lover_support_trigger = {
	OR = {
		is_ai = no #Players chose if they are ready
		trigger_if = {
			limit = { has_trait = chaste }
			opinion = {
				target = $CHARACTER$
				value >= high_positive_opinion
			}
		}
		trigger_else_if = {
			limit = {
				OR = {
					has_trait = lustful
					has_trait = seducer
					$CHARACTER$.attraction >= medium_positive_attraction
				}
			}
			opinion = {
				target = $CHARACTER$
				value >= 0
			}
		}
		trigger_else = {
			opinion = {
				target = $CHARACTER$
				value >= low_positive_opinion
			}
		}
	}
}

upgrade_ready_potential_lover_to_lover_trigger = {
	can_set_relation_lover_trigger = { CHARACTER = $CHARACTER$ }
	upgrade_ready_potential_lover_to_lover_support_trigger = { CHARACTER = $CHARACTER$ }
	save_temporary_scope_as = potential_lover_root
	$CHARACTER$ = { upgrade_ready_potential_lover_to_lover_support_trigger = { CHARACTER = scope:potential_lover_root } }
}

### SOULMATE
upgrade_ready_lover_to_soulmate_trigger = {
	can_set_relation_soulmate_trigger = { CHARACTER = $CHARACTER$ }
}


### RIVAL
upgrade_ready_potential_rival_to_rival_trigger = {
	can_set_relation_rival_trigger = { CHARACTER = $CHARACTER$ }
}

### NEMESIS
upgrade_ready_rival_to_nemesis_trigger = {
	can_set_relation_nemesis_trigger = { CHARACTER = $CHARACTER$ }
}





########################
# AI RELATIONSHIP CAPS #
########################

# Soft caps, mostly for schemes

is_below_ai_friend_soft_cap_trigger = {
	trigger_if = {
		limit = { is_ai = yes }

		trigger_if = {
			limit = {
				OR = {
					highest_held_title_tier >= tier_kingdom
					has_trait = gregarious
				}
			}
			num_of_relation_friend < 3
		}
		trigger_else = {
			num_of_relation_friend < 1
		}
	}
	trigger_else = {
		always = yes
	}
}

is_below_ai_lover_soft_cap_trigger = {
	trigger_if = {
		limit = { is_ai = yes }

		trigger_if = {
			limit = {
				has_trait = lustful
				has_trait = seducer
				has_focus = intrigue_temptation_focus
			}
			num_of_relation_lover < 3
		}
		trigger_else = {
			num_of_relation_lover < 1
		}
	}
	trigger_else = {
		always = yes
	}
}


###############################
# Character priority triggers #
###############################

has_important_relationship_with_character_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_friend = $CHARACTER$
	}
}

has_friendly_relationship_with_character_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
	}
}

has_any_mild_good_relationship_with_character_trigger = {
	OR = {
		has_relation_potential_lover = $CHARACTER$
		has_relation_crush = $CHARACTER$
		has_relation_potential_friend = $CHARACTER$
		has_relation_guardian = $CHARACTER$
		has_relation_ward = $CHARACTER$
		has_relation_elder = $CHARACTER$
		has_relation_disciple = $CHARACTER$
	}
}

has_any_moderate_good_relationship_with_character_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
	}
}

has_any_only_moderate_good_relationship_with_character_trigger = {
	has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
	# Exclude the max-tier positive relationships if we're being this specific.
	NOT = {
		has_any_best_good_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
	}
}

has_any_fertility_relationship_with_character_trigger = {
	OR = {
		has_relation_wedding_very_bad_fertility = $CHARACTER$
		has_relation_wedding_bad_fertility = $CHARACTER$
		has_relation_wedding_good_fertility = $CHARACTER$
		has_relation_wedding_very_good_fertility = $CHARACTER$
	}
}

has_any_fertility_relationship_with_root_trigger = {
	has_any_fertility_relationship_with_character_trigger = { CHARACTER = root }
}

has_any_best_good_relationship_with_character_trigger = {
	OR = {
		has_relation_best_friend = $CHARACTER$
		has_relation_soulmate = $CHARACTER$
	}
}

likes_character_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_crush = $CHARACTER$
		has_relation_potential_friend = $CHARACTER$
		has_relation_elder = $CHARACTER$
		has_relation_disciple = $CHARACTER$
		AND = {
			has_trait = loyal
			OR = {
				liege ?= $CHARACTER$
				is_consort_of = $CHARACTER$
				is_close_or_extended_family_of = $CHARACTER$
			}
		}
		opinion = {
			target = $CHARACTER$
			value >= 25
		}
	}
	NOR = {
		has_relation_victim = $CHARACTER$
		has_relation_bully = $CHARACTER$
		has_relation_rival = $CHARACTER$
		is_at_war_with = $CHARACTER$
		is_imprisoned_by = $CHARACTER$
	}
}

dislikes_character_trigger = {
	OR = {
		opinion = {
			target = $CHARACTER$
			value <= 25
		}
		has_relation_grudge = $CHARACTER$
		has_relation_victim = $CHARACTER$
		has_relation_bully = $CHARACTER$
		has_relation_rival = $CHARACTER$

		AND = {
			has_relation_potential_rival = $CHARACTER$
			opinion = {
				target = $CHARACTER$
				value <= 0
			}
		}
		AND = {
			has_trait = disloyal
			OR = {
				liege ?= $CHARACTER$
				is_consort_of = $CHARACTER$
				is_close_or_extended_family_of = $CHARACTER$
			}
		}
	}
	NOR = {
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_crush = $CHARACTER$
	}
}

has_any_good_relationship_with_character_trigger = {
	OR = {
		has_any_mild_good_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
		has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
	}
}

has_any_mild_bad_relationship_with_character_trigger = {
	OR = {
		has_relation_potential_rival = $CHARACTER$
		has_relation_victim = $CHARACTER$
		has_relation_bully = $CHARACTER$
	}
}

has_any_moderate_bad_relationship_with_character_trigger = {
	has_relation_rival = $CHARACTER$
}

has_any_only_moderate_bad_relationship_with_character_trigger = {
	has_relation_rival = $CHARACTER$
	NOT = {
		has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
	}
}

has_any_worst_bad_relationship_with_character_trigger = {
	has_relation_nemesis = $CHARACTER$
}

has_any_bad_relationship_with_character_trigger = {
	OR = {
		has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
		has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = $CHARACTER$ }
	}
}

has_important_relationship_with_root_trigger = {
	has_important_relationship_with_character_trigger = { CHARACTER = root }
}

has_friendly_relationship_with_root_trigger = {
	has_friendly_relationship_with_character_trigger = { CHARACTER = root }
}

has_any_good_relationship_with_root_trigger = {
	has_any_good_relationship_with_character_trigger = { CHARACTER = root }
}

has_any_bad_relationship_with_root_trigger = {
	has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
}

lover_is_secret_trigger = {
	any_secret = {
		type = secret_lover
		secret_target = $CHARACTER$
	}
}



###############################################
# Triggers that take an argument and NOT root
##############################################

# List of all localizable relations (e.g, My vassal Alex, My courtier Lisa, My liege Frank, My cousin Teddy, etc.)
has_any_relation_trigger = {
	NOT = { this = $CHARACTER$ }
	OR = {
		# They are our liege
		AND = {
			exists = $CHARACTER$.liege
			this = $CHARACTER$.liege
		}
		# We are their liege
		is_vassal_of = $CHARACTER$
		is_courtier_of = $CHARACTER$
		is_councillor_of = $CHARACTER$

		# They are our heir/spouse/familyetc.
		is_heir_of = $CHARACTER$
		is_consort_of = $CHARACTER$
		is_close_or_extended_family_of = $CHARACTER$

		#They are the head of our faith
		AND = {
			exists = $CHARACTER$.faith.religious_head
			this = $CHARACTER$.faith.religious_head
		}

		# Other relations
		has_relation_lover = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_guardian = $CHARACTER$
		has_relation_ward = $CHARACTER$
		has_relation_elder = $CHARACTER$
		has_relation_disciple = $CHARACTER$

		AND = {
			has_employed_any_court_position = yes
			any_court_position_holder = {
				this = $CHARACTER$
			}
		}
	}
}

is_of_major_interest_trigger = {
	NOT = { this = $CHARACTER$ }
	OR = {
		is_heir_of = $CHARACTER$
		is_diarch_of_target = $CHARACTER$
		AND = {
			exists = $CHARACTER$.liege
			this = $CHARACTER$.liege
		}
		is_consort_of = $CHARACTER$
		is_councillor_of = $CHARACTER$
		
		#They are the head of our faith
		AND = {
			exists = $CHARACTER$.faith.religious_head
			this = $CHARACTER$.faith.religious_head
		}

		trigger_if = {
			limit = {
				exists = liege
				exists = $CHARACTER$.liege
			}
			is_powerful_vassal = yes
			liege = $CHARACTER$.liege
		}
		trigger_if = {
			limit = {
				top_liege = this
			}
			any_neighboring_top_liege_realm_owner = {
				this = $CHARACTER$
			}
		}
		#House Head
		trigger_if = {
			limit = {
				exists = $CHARACTER$.house.house_head
			}
			this = $CHARACTER$.house.house_head
		}
		is_child_of = $CHARACTER$
		# Activity Intents
		trigger_if = {
			limit = {
				exists = involved_activity
				exists = intent_target
			}
			intent_target = $CHARACTER$
		}
	}
}

is_of_minor_interest_trigger = {
	NOT = { this = $CHARACTER$ }
	OR = {
		betrothed ?= $CHARACTER$
		has_relation_lover = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_guardian = $CHARACTER$
		has_relation_ward = $CHARACTER$
		has_relation_elder = $CHARACTER$
		has_relation_disciple = $CHARACTER$
		AND = {
			$CHARACTER$ = { target_is_liege_or_above = prev }
			NOT = { this = $CHARACTER$.liege }
		}
		is_close_or_extended_family_of = $CHARACTER$
	}
}

is_of_major_or_minor_interest_trigger = {
	OR = {
		is_of_major_interest_trigger = { CHARACTER = $CHARACTER$ }
		is_of_minor_interest_trigger = { CHARACTER = $CHARACTER$ }
	}
}
has_important_relationship_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_friend = $CHARACTER$
	}
}

has_friendly_relationship_trigger = {
	OR = {
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
	}
}

has_no_real_status_trigger = {
	OR = {
		is_lowborn = yes
		AND = {
			dynasty ?= {
				any_dynasty_member = {
					count <= 2
				}
			}
		}
		highest_held_title_tier <= tier_barony
	}
	NOR = {
		any_close_or_extended_family_member = {
			highest_held_title_tier > tier_barony
		}
		dynasty.dynasty_prestige_level >= 2
	}
	is_clergy = no
	is_theocratic_lessee = no
	is_claimant = no
}

has_no_particular_noble_roots_trigger = {
	custom_tooltip = {
		text = has_no_particular_noble_roots_trigger
		OR = {
			is_lowborn = yes
			dynasty ?= {
				any_dynasty_member = {
					count <= 2
				}
			}
			highest_held_title_tier <= tier_barony
			government_has_flag = government_is_herder
		}
		NOR = {
			AND = {
				highest_held_title_tier > tier_barony
				NOT = { government_has_flag = government_is_herder }
			}
			any_close_or_extended_family_member = {
				highest_held_title_tier > tier_barony
				NOT = { government_has_flag = government_is_herder }
			}
			AND = {
				exists = dynasty
				dynasty.dynasty_prestige_level >= 2
			}
		}
	}
}



###################################
# Root argument versions
###################################

is_of_major_interest_to_root_trigger = {
	is_of_major_interest_trigger = {
		CHARACTER = root
	}
}

is_of_minor_interest_to_root_trigger = {
	is_of_minor_interest_trigger = {
		CHARACTER = root
	}
}


###############
# Character Lists
###############

#Support trigger
major_interest_player_heir_trigger = {
	exists = player_heir
	NOT = { player_heir = { is_in_list = $LISTNAME$ } }
}

#Support trigger
major_interest_liege_trigger = {
	exists = liege
	NOR = {
		this = this.liege
		liege = { is_in_list = $LISTNAME$ }
	}
}

#Support trigger
major_interest_realm_priest_trigger = {
	faith = { has_doctrine = doctrine_theocracy_temporal }
	exists = cp:councillor_court_chaplain
	NOT = {
		cp:councillor_court_chaplain = { is_in_list = $LISTNAME$ }
	}
}

#Support trigger
major_interest_primary_spouse_trigger = {
	exists = primary_spouse
	NOT = { primary_spouse = { is_in_list = $LISTNAME$ } }
}


#Support trigger
major_interest_potential_heirs_trigger = {
	player_heir_position = {
		target = $CHARACTER$
		value <= 5
	}
	NOT = { is_in_list = $LISTNAME$ }
}

#Makes a list of every character of major interest
	#Parameters:
	# CHARACTER - the character who the list will be for
	# LISTNAME - the name of the list
get_characters_of_major_interest_trigger = {
	save_temporary_scope_as = major_root
	# 1 - Player heir
	trigger_if = {
		limit = {
			major_interest_player_heir_trigger = { LISTNAME = $LISTNAME$ }
		}
		player_heir = { add_to_temporary_list = $LISTNAME$ }
	}
	# 2 - Liege
	trigger_if = {
		limit = {
			major_interest_liege_trigger = { LISTNAME = $LISTNAME$ }
		}
		liege = { add_to_temporary_list = $LISTNAME$ }
	}
	# 3 - Realm Priest
	trigger_if = {
		limit = {
			major_interest_realm_priest_trigger = { LISTNAME = $LISTNAME$ }
		}
		cp:councillor_court_chaplain = { add_to_temporary_list = $LISTNAME$ }
	}
	# 4 - Primary Spouse
	trigger_if = {
		limit = {
			major_interest_primary_spouse_trigger = { LISTNAME = $LISTNAME$ }
		}
		primary_spouse = { add_to_temporary_list = $LISTNAME$ }
	}
	# 5 - Spymaster & # 11 - Other councillors
	any_normal_councillor = {
		NOT = { is_in_list = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}
	# 6 - Powerful vassals
	any_powerful_vassal = {
		NOT = { is_in_list = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}
	# 7 - Religious head (Excluded because they're highly context-specific)
	# 8 - Potential heirs (Player only)
	trigger_if = {
		limit = { is_ai = no }
		trigger_if = {
			limit = { exists = dynasty }
			dynasty = {
				any_dynasty_member = {
					major_interest_potential_heirs_trigger = { LISTNAME = $LISTNAME$ CHARACTER = scope:major_root }
					count = all
					add_to_temporary_list = $LISTNAME$
				}
			}
		}
	# 9 - Allies (Player only, Enemies are only relevant for content about wars)
		any_ally = {
			NOT = { is_in_list = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	}
	# 10 - Neighboring rulers (not included in this list, hard to gauge relevance)
}

#Support trigger
minor_interest_concubines_secondary_spouses_trigger = {
	trigger_if = {
		limit = { exists = $CHARACTER$.primary_spouse }
		NOT = { this = $CHARACTER$.primary_spouse  }
	}
	NOT = { is_in_list = $LISTNAME$ }
}

#Support trigger
minor_interest_high_tier_vassal_trigger = {
	is_powerful_vassal = no #Already included in major
#	highest_held_title_tier >= {
#		value = liege.highest_held_title_tier
#		subtract = 2
#		min = 2 #Must be at least a count
#	}
	NOT = { is_in_list = $LISTNAME$ }
}

minor_interest_close_relatives_trigger = {
	NOR = {
		#Blocking the most common overlap with high prio
		AND = {
			is_cousin_of = $CHARACTER$
			NOT = { is_close_family_of = $CHARACTER$ } #Because... incest. Sigh.
		}
		major_interest_potential_heirs_trigger = { CHARACTER = $CHARACTER$ LISTNAME = $LISTNAME$ }
		trigger_if = {
			limit = { exists = $CHARACTER$.player_heir }
			this = $CHARACTER$.player_heir
		}
		is_in_list = $LISTNAME$
	}
}

#Support trigger
minor_interest_betrothed_trigger = {
	betrothed ?= { NOT = { is_in_list = $LISTNAME$ }  }
}

#Support trigger
minor_interest_skilled_courtiers_trigger = {
	OR = {
		diplomacy > high_skill_rating
		martial > high_skill_rating
		stewardship > high_skill_rating
		intrigue > high_skill_rating
		learning > high_skill_rating
		prowess > high_skill_rating
	}
	average_skill_rating >= average_of_all_skills_and_prowess
	NOT = { is_in_list = $LISTNAME$ }
}

#Support trigger
minor_interest_liege_or_above_trigger = {
	NOR = {
		this = $CHARACTER$.liege
		is_in_list = $LISTNAME$
	}
}

#Makes a list of every character of minor interest
	#Parameters:
	# LISTNAME - the name of the list
get_characters_of_minor_interest_trigger = {
	save_temporary_scope_as = minor_root
	# 1 - Concubines & secondary spouses
	any_consort = {
		minor_interest_concubines_secondary_spouses_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}	
	# 2 - Direct vassals of high tier
	any_vassal = {
		minor_interest_high_tier_vassal_trigger = { LISTNAME = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}
	# 3 - Betrothed
	trigger_if = {
		limit = { minor_interest_betrothed_trigger = { LISTNAME = $LISTNAME$ } }
		betrothed = { add_to_temporary_list = $LISTNAME$ }
	}
	# 4 - Lovers
	any_relation = {
		type = lover
		NOT = { is_in_list = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}
	# 5 - Rivals (excluded as they're typically only used in specific contexts)
	# 6 - Close relatives
	any_close_or_extended_family_member = {
		minor_interest_close_relatives_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ }
		count = all
		add_to_temporary_list = $LISTNAME$
	}
	trigger_if = { #Below is just for players
		limit = { is_ai = no }
	# 7 - Guardian
		any_relation = {
			type = guardian
			NOT = { is_in_list = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	# 8 - Ward
		any_relation = {
			type = ward
			NOT = { is_in_list = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	# 9 - Friends
		any_relation = {
			type = friend
			NOT = { is_in_list = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	# 10 - Knights
		any_knight = {
			NOT = { is_in_list = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	# 11 - Highly skilled courtiers (players only)
		trigger_if = {
			limit = { is_ai = no }
			any_courtier = {
				minor_interest_skilled_courtiers_trigger = { LISTNAME = $LISTNAME$ }
				count = all
				add_to_temporary_list = $LISTNAME$
			}
		}
		any_liege_or_above = {
			minor_interest_liege_or_above_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ }
			count = all
			add_to_temporary_list = $LISTNAME$
		}
	}
}



#Makes a list of all characters of interest
	#Parameters:
	# CHARACTER - the character the list is for
	# LISTNAME - the name of the list
get_characters_of_interest_trigger = {
	get_characters_of_major_interest_trigger = {
		LISTNAME = $LISTNAME$
	}
	get_characters_of_minor_interest_trigger = {
		LISTNAME = $LISTNAME$
	}
}



################
# Potential Enemies
################

#Makes a list of characters who are classified as potential enemies
	#Parameters
	# CHARACTER - The character whose enemies are being found
	# LISTNAME - The name of the list
get_potential_enemies_effect = {
	$CHARACTER$ = {
		trigger_if = {
			limit = {
				any_vassal = {
					always = yes
				}
			}
			any_vassal = {
				count = all
				add_to_temporary_list = temp_$LISTNAME$
			}
		}
		trigger_if = {
			limit = {
				any_relation = {
					type = rival
					always = yes
				}
			}
			any_relation = {
				type = rival
				count = all
				add_to_temporary_list = temp_$LISTNAME$
			}
		}
		trigger_if = {
			limit = {
				top_liege != this
			}
			liege = {
				add_to_temporary_list = temp_$LISTNAME$
			}
		}
		trigger_if = {
			limit = {
				top_liege = this
				any_neighboring_top_liege_realm_owner = {
					always = yes
				}
			}
			any_neighboring_top_liege_realm_owner = {
				count = all
				add_to_temporary_list = temp_$LISTNAME$
			}
		}
		#Potential Heirs that do not like you
		#A Religious Head that dislikes you and you are powerful enough

		any_in_list = {
			count = all
			trigger_if = {
				limit = {
					NOT = { is_in_list = $LISTNAME$ }
					OR = {
						#Vassal enemies
						AND = {
							is_vassal_of = $CHARACTER$
							is_powerful = yes
							opinion = {
								target = $CHARACTER$
								value <= 0
							}
						}
						#Rivals
						has_relation_rival = $CHARACTER$
						#Lieges
						AND = {
							$CHARACTER$ = { top_liege != this }
							this = $CHARACTER$.liege
							opinion = {
								target = $CHARACTER$
								value <= 0
							}
						}
						#Neighboring independent rulers
						AND = {
							any_neighboring_top_liege_realm_owner = {
								this = $CHARACTER$
							}
							NOT = { is_allied_to = $CHARACTER$ }
							OR = {
								opinion = {
									target = $CHARACTER$
									value <= 20
								}
								AND = {
									opinion = {
										target = $CHARACTER$
										value <= 50
									}
									has_any_cb_on = $CHARACTER$
								}
							}
						}
					}
				}
				add_to_temporary_list = $LISTNAME$
			}
		}
	}
}

has_RelationToMe_relation = {
	save_temporary_scope_as = relation_check
	NOT = { this = $CHARACTER$ } # Don't print our relation to ourselves!
	OR = {
		is_close_or_extended_family_of = $CHARACTER$
		any_spouse = {
			even_if_dead = yes
			this = $CHARACTER$
		}
		any_spouse = {
			even_if_dead = yes
			this = $CHARACTER$
			is_concubine = yes
		}
		$CHARACTER$ = {
			player_heir ?= scope:relation_check
		}
		is_heir_of = $CHARACTER$
		has_relation_rival = $CHARACTER$
		has_relation_lover = $CHARACTER$
		has_relation_friend = $CHARACTER$
		has_relation_bully = $CHARACTER$
		has_relation_victim = $CHARACTER$
		is_councillor_of = $CHARACTER$
		any_spouse = { any_child = { this = $CHARACTER$ } }
		any_parent = { any_spouse = { this = $CHARACTER$ } }
		any_parent = { any_spouse = { any_child = { this = $CHARACTER$ } } }
		liege ?= $CHARACTER$
		this = { is_tributary_of = $CHARACTER$ }
		any_courtier = { this = $CHARACTER$ }
		any_vassal_or_below = { this = $CHARACTER$ }
		AND = {
			top_liege != this
			$CHARACTER$ = { top_liege != this }
			liege = $CHARACTER$.liege
		}
		has_relation_crush = $CHARACTER$
		has_relation_ward = $CHARACTER$
		has_relation_guardian = $CHARACTER$
		has_relation_mentor = $CHARACTER$
		has_relation_student = $CHARACTER$
		has_relation_elder = $CHARACTER$
		has_relation_disciple = $CHARACTER$
		AND = {
			has_employed_any_court_position = yes
			any_court_position_holder = {
				this = $CHARACTER$
			}
		}
		$CHARACTER$ = { is_sibling_in_law_of_root_trigger = yes }
		AND = {
			exists = dynasty
			$CHARACTER$ = { exists = dynasty }
			dynasty = $CHARACTER$.dynasty
		}
		$CHARACTER$ = {
			any_owned_story = {
				type = story_peasant_affair
				var:peasant_character = {
					this = root
				}
			}
		}
		$CHARACTER$ = {
			is_courtier_of = scope:relation_check
			OR = {
				AND = {
					inspiration ?= {
						inspiration_sponsor = { this = scope:relation_check }
					}
				}
				AND = {
					exists = var:created_artifact_for
					var:created_artifact_for = scope:relation_check
				}
			}
		}
		$CHARACTER$ = {
			any_scheme = {
				scheme_is_character_agent = root
			}
		}
		is_imprisoned_by = $CHARACTER$
		$CHARACTER$ = { is_imprisoned_by = scope:relation_check }
		host ?= $CHARACTER$
		$CHARACTER$ = {
			host ?= scope:relation_check
		}
		is_knight_of = $CHARACTER$
		AND = {
			is_female = yes
			any_spouse = {
				is_child_of = root
			}
		}
		AND = {
			is_male = yes
			any_spouse = {
				is_child_of = root
			}
		}
	}
}
