﻿
#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

#progress_towards_friend_effect		- Sets potential friend + opinion or upgrades potential friend to full friend
#progress_towards_rival_effect 		- Sets potential rival + opinion or upgrades potential rival to full rival
#progress_towards_lover_effect 		- Sets potential lover + opinion or upgrades potential lover to full lover

#get_characters_of_major_interest_effect
#get_characters_of_minor_interest_effect
#get_characters_of_interest_effect

#get_potential_enemies_effect
#get_random_potential_enemy_effect

#progress_towards_friend_ai_effect		- Progresses to friend if the target is an AI
#progress_towards_rival_ai_effect 		- Progresses to rival if the target is an AI
#progress_towards_lover_ai_effect 		- Progresses to lover if the target is an AI

#####################################################################
# EFFECTS
#####################################################################

### RELATION PROGRESS EFFECTS ###

# Needs CHARACTER and OPINION value, use 0 for no opinion change and default_<relation>_opinion script value for the normal amount

#Sets potential friend + opinion or upgrades potential friend to full friend
progress_towards_friend_effect = {
	#If potential friend, set friend!
	if = {
		limit = {
			has_relation_potential_friend = $CHARACTER$
			can_set_relation_friend_trigger = { CHARACTER = $CHARACTER$ }
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
				exists = scope:relationship_reason_province
			}
			set_relation_friend = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
				province = scope:relationship_reason_province 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_friend_log
						tags = { good }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_province
			}
			set_relation_friend = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				province = scope:relationship_reason_province 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_friend_log
						tags = { good }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_friend = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_friend_log
						tags = { good }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else = {
			set_relation_friend = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_friend_log
						tags = { good }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		# Complete activity intent if relevant
		if = {
			limit = {
				exists = involved_activity
				has_activity_intent = befriend_attendee_intent
				intent_target ?= $CHARACTER$
				intent_target.involved_activity ?= this.involved_activity
			}	
			save_scope_as = intent_completer
			send_interface_toast = {
				title = activity_intent_complete_toast
				left_icon = $CHARACTER$ 
				complete_activity_intent = yes
			}
		}
	}
	# If not...
	else = {
		# ... set potential relation if we're not already friends!
		if = {
			limit = {
				can_set_relation_potential_friend_trigger = { CHARACTER = $CHARACTER$ }
				trigger_if = {
					limit = {
						is_ai = yes
						$CHARACTER$ = { is_ai = yes }
					}
					$CHARACTER$ = {
						opinion = {
							target = prev
							value >= -25
						}
					}
				}
				trigger_else = {
					always = yes
				}
			}
			set_relation_potential_friend = $CHARACTER$
		}

		# ... add opinion if we should!
		save_temporary_scope_value_as = {
			name = friend_opinion
			value = $OPINION$
		}
		if = {
			limit = { NOT = { scope:friend_opinion = 0 } }
			reverse_add_opinion = {
				target = $CHARACTER$
				modifier = friendliness_opinion
				opinion = scope:friend_opinion
			}
			hidden_effect = {
				add_opinion = {
					target = $CHARACTER$
					modifier = friendliness_opinion
					opinion = scope:friend_opinion
				}
			}
		}
	}
}

#Sets potential rival + opinion or upgrades potential rival to full rival
progress_towards_rival_effect = {
	# Do we merit an actual rivalry?
	if = {
		limit = {
			# We don't care between low-tier chars.
			NOT = {
				$CHARACTER$ = { highest_held_title_tier <= tier_barony }
			}
			# Are they low-tier themselves?
			highest_held_title_tier <= tier_barony
			# If they are then they must...
			NOR = {
				# ... be related to the target...
				is_close_or_extended_family_of = $CHARACTER$
				is_consort_of = $CHARACTER$
				# ... or be heir to someone within social spitting distance of the target.
				any_heir_title = {
					tier >= {
						value = $CHARACTER$.highest_held_title_tier
						# So if they're feuding with an emperor, then they must be heir to at least a duchy.
						subtract = 2
					}
				}
			}
		}
		# Now, set grudge if we could already set it.
		if = {
			limit = {
				NOT = { has_relation_grudge = $CHARACTER$ }
			}
			if = {
				limit = {
					exists = scope:relationship_reason_involved_character
					exists = scope:relationship_reason_province
				}
				set_relation_grudge = {
					reason = $REASON$
					target = $CHARACTER$
					involved_character = scope:relationship_reason_involved_character
					province = scope:relationship_reason_province
				}
			}
			else_if = {
				limit = {
					exists = scope:relationship_reason_province
				}
				set_relation_grudge = {
					reason = $REASON$
					target = $CHARACTER$
					province = scope:relationship_reason_province
				}
			}
			else_if = {
				limit = {
					exists = scope:relationship_reason_involved_character
				}
				set_relation_grudge = {
					reason = $REASON$
					target = $CHARACTER$
					involved_character = scope:relationship_reason_involved_character
				}
			}
			else = {
				set_relation_grudge = {
					reason = $REASON$
					target = $CHARACTER$
				}
			}
		}
		# Otherwise, increment raw opinion.
		else = {
			add_opinion = {
				target = $CHARACTER$
				modifier = grudge_opinion
				opinion = -20
			}
		}
	}
	#If potential rival, set rival!
	else_if = {
		limit = {
			has_relation_potential_rival = $CHARACTER$
			can_set_relation_rival_trigger = { CHARACTER = $CHARACTER$ }
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
				exists = scope:relationship_reason_province
			}
			set_relation_rival = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
				province = scope:relationship_reason_province 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_rival_log
						tags = { bad }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_province
			}
			set_relation_rival = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				province = scope:relationship_reason_province 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_rival_log
						tags = { bad }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_rival = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_rival_log
						tags = { bad }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
		else = {
			set_relation_rival = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
			}
			if = {
				limit = {
					this.involved_activity ?= {
						has_activity_type = activity_playdate
					}
				}
				this.involved_activity ?= {
					add_activity_log_entry = {
						key = activity_generic_rival_log
						tags = { bad }
						score = 10
						character = prev
						target = $CHARACTER$
					}
				}
			}
		}
	}
	# If not...
	else = {
		# ... set potential relation if we're not already rivals!
		if = {
			limit = { can_set_relation_potential_rival_trigger = { CHARACTER = $CHARACTER$ } }
			set_relation_potential_rival = $CHARACTER$
		}
		
		# ... add opinion if we should!
		save_temporary_scope_value_as = {
			name = rival_opinion
			value = $OPINION$
		}
		if = {
			limit = { NOT = { scope:rival_opinion = 0 } }
			if = {
				limit = {
					$CHARACTER$ = { is_ai = yes }
				}
				reverse_add_opinion = {
					target = $CHARACTER$
					modifier = hate_opinion
					opinion = scope:rival_opinion
				}
			}
			add_opinion = {
				target = $CHARACTER$
				modifier = hate_opinion
				opinion = scope:rival_opinion
			}
		}
	}
}
# Please use this one with care: players should never auto-upgrade to nemesis if we can help it, this is mostly for the AI.
progress_towards_nemesis_effect = {
	if = {
		limit = {
			has_relation_rival = $CHARACTER$
			can_set_relation_nemesis_trigger = { CHARACTER = $CHARACTER$ }
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
				exists = scope:relationship_reason_province
			}
			set_relation_nemesis = {
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
				province = scope:relationship_reason_province 
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_province
			}
			set_relation_nemesis = {
				reason = $REASON$ 
				target = $CHARACTER$ 
				province = scope:relationship_reason_province 
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_nemesis = {
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
			}
		}
		else = {
			set_relation_nemesis = {
				reason = $REASON$ 
				target = $CHARACTER$ 
			}
		}
	}
	else = {
		progress_towards_rival_effect = {
			CHARACTER = $CHARACTER$
			REASON = $REASON$
			OPINION = $OPINION$
		}
	}
}

#Sets potential lover + opinion or upgrades potential lover to full lover
progress_towards_lover_effect = {
	#If potential lover, set lover!
	if = {
		limit = {
			has_relation_potential_lover = $CHARACTER$
			can_set_relation_lover_trigger = { CHARACTER = $CHARACTER$ }
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
				exists = scope:relationship_reason_province
			}
			set_relation_lover = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
				province = scope:relationship_reason_province 
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_province
			}
			set_relation_lover = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				province = scope:relationship_reason_province 
			}
		}
		else_if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_lover = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
				involved_character = scope:relationship_reason_involved_character 
			}
		}
		else = {
			set_relation_lover = { 
				reason = $REASON$ 
				target = $CHARACTER$ 
			}
		}
		# Complete activity intent if relevant
		if = {
			limit = {
				exists = involved_activity
				has_activity_intent = woo_attendee_intent
				intent_target ?= $CHARACTER$
				intent_target.involved_activity ?= this.involved_activity
			}
			save_scope_as = intent_completer
			send_interface_toast = {
				title = activity_intent_complete_toast
				left_icon = $CHARACTER$ 
				complete_activity_intent = yes
			}
		}
	}
	# If not...
	else = {
		# ... set potential relation if we're not already rivals!
		if = {
			limit = { can_set_relation_potential_lover_trigger = { CHARACTER = $CHARACTER$ } }
			set_relation_potential_lover = $CHARACTER$
		}

		# ... add opinion if we should!
		save_temporary_scope_value_as = {
			name = lover_opinion
			value = $OPINION$
		}
		if = {
			limit = { NOT = { scope:lover_opinion = 0 } }
			reverse_add_opinion = {
				target = $CHARACTER$
				modifier = romance_opinion
				opinion = scope:lover_opinion
			}
			hidden_effect = {
				add_opinion = {
					target = $CHARACTER$
					modifier = romance_opinion
					opinion = scope:lover_opinion
				}
			}
		}
	}
}

### CHARACTERS OF INTEREST EFFECTS ###

#Makes a list of every character of major interest
	#Parameters:
	# LISTNAME - the name of the list

get_characters_of_major_interest_effect = {
	save_temporary_scope_as = major_root
	# 1 - Player heir
	if = {
		limit = {
			major_interest_player_heir_trigger = { LISTNAME = $LISTNAME$ }
		}
		player_heir = { add_to_temporary_list = $LISTNAME$ }
	}
	# 2 - Liege
	if = {
		limit = {
			major_interest_liege_trigger = { LISTNAME = $LISTNAME$ }
		}
		liege = { add_to_temporary_list = $LISTNAME$ }
	}
	# 3 - Realm Priest
	if = {
		limit = {
			major_interest_realm_priest_trigger = { LISTNAME = $LISTNAME$ }
		}
		cp:councillor_court_chaplain = { add_to_temporary_list = $LISTNAME$ }
	}
	# 4 - Primary Spouse
	if = {
		limit = {
			major_interest_primary_spouse_trigger = { LISTNAME = $LISTNAME$ }
		}
		primary_spouse = { add_to_temporary_list = $LISTNAME$ }
	}
	# 5 - Spymaster & # 11 - Other councillors
	every_normal_councillor = {
		limit = {
			NOT = { is_in_list = $LISTNAME$ }
		}
		add_to_temporary_list = $LISTNAME$
	}
	# 6 - Powerful vassals
	every_powerful_vassal = {
		limit = {
			NOT = { is_in_list = $LISTNAME$ }
		}
		add_to_temporary_list = $LISTNAME$
	}
	# 7 - Religious head (Excluded because they're highly context-specific)
	# 8 - Potential heirs (Player only)
	if = {
		limit = { is_ai = no }
		if = {
			limit = { exists = dynasty }
			dynasty = {
				every_dynasty_member = {
					limit = {
						major_interest_potential_heirs_trigger = { LISTNAME = $LISTNAME$ CHARACTER = scope:major_root }
					}
					add_to_temporary_list = $LISTNAME$
				}
			}
		}
	# 9 - Allies (Player only, Enemies are only relevant for content about wars)
		every_ally = {
			limit = {
				NOT = { is_in_list = $LISTNAME$ }
			}
			add_to_temporary_list = $LISTNAME$
		}
	}
	# 10 - Neighboring rulers (not included in this list, hard to gauge relevance)
}

#Makes a list of every character of minor interest
	#Parameters:
	# CHARACTER - the character who the list will be for
	# LISTNAME - the name of the list
get_characters_of_minor_interest_effect = {
	save_temporary_scope_as = minor_root
	# 1 - Concubines & secondary spouses
	every_consort = {
		limit = { minor_interest_concubines_secondary_spouses_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ } }
		add_to_temporary_list = $LISTNAME$
	}	
	# 2 - Direct vassals of high tier
	every_vassal = {
		limit = { minor_interest_high_tier_vassal_trigger = { LISTNAME = $LISTNAME$ } }
		add_to_temporary_list = $LISTNAME$
	}
	# 3 - Betrothed
	if = {
		limit = { minor_interest_betrothed_trigger = { LISTNAME = $LISTNAME$ } }
		betrothed = { add_to_temporary_list = $LISTNAME$ }
	}
	# 4 - Lovers
	every_relation = {
		type = lover
		limit = { NOT = { is_in_list = $LISTNAME$ } }
		add_to_temporary_list = $LISTNAME$
	}
	# 5 - Rivals (excluded as they're typically only used in specific contexts)
	# 6 - Close relatives
	every_close_or_extended_family_member = {
		limit = { minor_interest_close_relatives_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ } }
		add_to_temporary_list = $LISTNAME$
	}
	if = { #Below is just for players
		limit = { is_ai = no }
	# 7 - Guardian
		every_relation = {
			type = guardian
			limit = { NOT = { is_in_list = $LISTNAME$ } }
			add_to_temporary_list = $LISTNAME$
		}
	# 8 - Ward
		every_relation = {
			type = ward
			limit = { NOT = { is_in_list = $LISTNAME$ } }
			add_to_temporary_list = $LISTNAME$
		}
	# 9 - Friends
		every_relation = {
			type = friend
			limit = { NOT = { is_in_list = $LISTNAME$ } }
			add_to_temporary_list = $LISTNAME$
		}
	# 10 - Knights
		every_knight = {
			limit = { NOT = { is_in_list = $LISTNAME$ } }
			add_to_temporary_list = $LISTNAME$
		}
	# 11 - Highly skilled courtiers (players only)
		if = {
			limit = { is_ai = no }
			every_courtier = {
				limit = { minor_interest_skilled_courtiers_trigger = { LISTNAME = $LISTNAME$ } }
				add_to_temporary_list = $LISTNAME$
			}
		}
		every_liege_or_above = {
			limit = { minor_interest_liege_or_above_trigger = { CHARACTER = scope:minor_root LISTNAME = $LISTNAME$ } }
			add_to_temporary_list = $LISTNAME$
		}
	}
}



#Makes a list of all characters of interest
	#Parameters:
	# LISTNAME - the name of the list
get_characters_of_interest_effect = {
	get_characters_of_major_interest_effect = {
		LISTNAME = $LISTNAME$
	}
	get_characters_of_minor_interest_effect = {
		LISTNAME = $LISTNAME$
	}
}





#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$ = {
		every_vassal = {
			limit = {
				is_powerful = yes
				opinion = {
					target = $CHARACTER$
					value <= 0
				}
				NOT = { is_in_list = $LISTNAME$ }
			}
			add_to_list = $LISTNAME$
		}
		every_relation = {
			type = rival
			limit = {
				NOT = { is_in_list = $LISTNAME$ }
			}
			add_to_list = $LISTNAME$
		}
		if = {
			limit = {
				top_liege != this
				liege = {
					opinion = {
						target = $CHARACTER$
						value <= 0
					}
					NOT = {
						is_in_list = $LISTNAME$
					}
				}
			}
			liege = {
				add_to_list = $LISTNAME$
			}
		}
		if = {
			limit = {
				top_liege = this
			}
			every_neighboring_top_liege_realm_owner = {
				limit = {
					NOT = { is_allied_to = $CHARACTER$ }
					OR = {
						opinion = {
							target = $CHARACTER$
							value <= 20
						}
						AND = {
							opinion = {
								target = $CHARACTER$
								value <= 50
							}
							has_any_cb_on = $CHARACTER$
						}
					}
					NOT = { is_in_list = $LISTNAME$ }
				}
				add_to_list = $LISTNAME$
			}
		}
		#Potential Heirs that do not like you
	}
}

set_as_oaf_effect = {
	if = {
		limit = {
			NOT = { has_relation_oaf = $CHARACTER$ }
		}
		set_relation_oaf = $CHARACTER$
	}
}

remove_friend_or_downgrade_friendship_effect = {
	 if = {
        limit = { has_relation_best_friend = $SCOPE$ }
        hidden_effect = { remove_relation_best_friend = $SCOPE$ }
		set_relation_friend = { reason = friend_downgrade_best_friends target = $SCOPE$ }
    }
    else = { remove_relation_friend = $SCOPE$ }
}

remove_lover_or_downgrade_relationship_effect = {
	 if = {
        limit = { has_relation_soulmate = $SCOPE$ }
        hidden_effect = { remove_relation_soulmate = $SCOPE$ }
		set_relation_lover = $SCOPE$
    }
    else = { remove_relation_lover = $SCOPE$ }
}

# Immediately upgrade the relationship
upgrade_to_friend_effect = {
	#If nemesis, change to rival
	if = {
		limit = { has_relation_nemesis = $CHARACTER$ }
		remove_relation_nemesis = $CHARACTER$
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_rival = {
				target = $CHARACTER$
				reason = $REASON$
				involved_character = scope:relationship_reason_involved_character
			}
		}
		else = {
			set_relation_rival = {
				target = $CHARACTER$
				reason = $REASON$
			}
		}
	}
	#If rival, end rivalry.
	else_if = {
		limit = { has_relation_rival = $CHARACTER$ }
		remove_relation_rival = $CHARACTER$
	}
	# If not, look at upgrading from friend to best friend
	else_if = {
		limit = {
			has_relation_friend = $CHARACTER$
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_best_friend = {
				target = $CHARACTER$
				reason = $REASON$
				copy_reason = friend
				involved_character = scope:relationship_reason_involved_character
			}
		}
		else = {
			set_relation_best_friend = {
				target = $CHARACTER$
				copy_reason = friend
				reason = $REASON$
			}
		}
	}
	# If not, look at upgrading from nothing to friend
	else_if = {
		limit = {
			NOT = { has_relation_friend = $CHARACTER$ }
		}
		if = {
			limit = {
				exists = scope:relationship_reason_involved_character
			}
			set_relation_friend = {
				target = $CHARACTER$
				reason = $REASON$
				involved_character = scope:relationship_reason_involved_character
			}
		}
		else = {
			set_relation_friend = {
				target = $CHARACTER$
				reason = $REASON$
			}
		}
	}
}

# Immediately downgrade the relationship
# DO NOT USE AFTER BP1 - hard to implement with relationship reasons
downgrade_to_rival_effect = {
	#If best friend, change to friend
	if = {
		limit = {
			has_relation_best_friend = $CHARACTER$
		}
		remove_relation_best_friend = $CHARACTER$
		set_relation_friend = { reason = friend_downgrade_best_friends target = $CHARACTER$ }
	}
	#If friend, end friendship.
	else_if = {
		limit = {
			has_relation_friend = $CHARACTER$
		}
		remove_relation_friend = $CHARACTER$
	}
	# If not, look at upgrading from rival to nemesis
	else_if = {
		limit = {
			has_relation_rival = $CHARACTER$
			NOT = { has_relation_nemesis = $CHARACTER$ }
		}
		set_relation_nemesis = {
			target = $CHARACTER$
			copy_reason = rival
			reason = nemesis_downgrade_from_rival
		}
	}
	# If not, look at upgrading from nothing to rival
	else_if = {
		limit = {
			NOT = { has_relation_nemesis = $CHARACTER$ }
		}
		set_relation_rival = {
			target = $CHARACTER$
			reason = $REASON$
		}
	}
}

set_random_friendship_reason = { # Use for adults, primarily
	show_as_tooltip = {
		set_relation_friend = $TARGET$
	}
	hidden_effect = {
		random_list = {
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_friend = { reason = friend_random_1 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_friend = { reason = friend_random_2 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_friend = { reason = friend_random_3 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_friend = { reason = friend_random_4 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_friend = { reason = friend_random_5 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_friend = { reason = friend_random_6 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_friend = { reason = friend_random_7 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_friend = { reason = friend_random_8 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege.capital_province
				}
				set_relation_friend = { reason = friend_random_9 target = $TARGET$ involved_character = liege province = liege.capital_province }
			}
			10 = {
				trigger = {
					exists = liege.capital_province
				}
				set_relation_friend = { reason = friend_random_10 target = $TARGET$ involved_character = liege province = liege.capital_province }
			}
			10 = {
				trigger = {
					NOR ={
						exists = location
						exists = liege
					}
				}
				set_relation_friend = { reason = friend_random_fallback target = $TARGET$ }
			}
		}
	}
}

set_random_rivalry_reason = { # Use for adults, primarily
	show_as_tooltip = {
		set_relation_$RELATION$ = $TARGET$
	}
	hidden_effect = {
		random_list = {
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_$RELATION$ = { reason = rival_random_1 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_$RELATION$ = { reason = rival_random_2 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_$RELATION$ = { reason = rival_random_3 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_$RELATION$ = { reason = rival_random_4 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = location
					NOT = { exists = liege }
				}
				set_relation_$RELATION$ = { reason = rival_random_5 target = $TARGET$ province = location }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_$RELATION$ = { reason = rival_random_6 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_$RELATION$ = { reason = rival_random_7 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_$RELATION$ = { reason = rival_random_8 target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					exists = liege.capital_province
				}
				set_relation_$RELATION$ = { reason = rival_random_9 target = $TARGET$ involved_character = liege province = liege.capital_province }
			}
			10 = {
				trigger = {
					exists = liege.capital_province
				}
				set_relation_$RELATION$ = { reason = rival_random_10 target = $TARGET$ involved_character = liege province = liege.capital_province }
			}
			10 = {
				trigger = {
					exists = liege
				}
				set_relation_$RELATION$ = { reason = rivalry_at_court target = $TARGET$ involved_character = liege }
			}
			10 = {
				trigger = {
					NOR ={
						exists = location
						exists = liege
					}
				}
				set_relation_$RELATION$ = { reason = rival_random_fallback target = $TARGET$ }
			}
		}
	}
}

set_random_lover_reason = {
	show_as_tooltip = {
		set_relation_lover = $TARGET$
	}
	hidden_effect = {
		random_list = {
			10 = {
				trigger = {
					$TARGET$ = {
						is_female = yes
					}
				}
				set_relation_lover = { reason = lover_random_1 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_2 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_3 target = $TARGET$ }
			}
			10 = {
				trigger = {
					$TARGET$ = {
						is_male = yes
					}
				}
				set_relation_lover = { reason = lover_random_4 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_5 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_6 target = $TARGET$ }
			}
			10 = {
				trigger = {
					$TARGET$ = {
						is_male = yes
					}
				}
				set_relation_lover = { reason = lover_random_7 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_8 target = $TARGET$ }
			}
			10 = {
				trigger = {
					$TARGET$ = {
						is_female = yes
					}
				}
				set_relation_lover = { reason = lover_random_9 target = $TARGET$ }
			}
			10 = {
				set_relation_lover = { reason = lover_random_10 target = $TARGET$ }
			}
		}
	}
}

# OWNER = character
# TARGET = character
# RELATION = relation_key
send_set_relation_toast_effect = {
	$OWNER$ = {
		save_temporary_scope_as = relation_owner
	}
	$TARGET$ = {
		save_temporary_scope_as = relation_target
	}
	scope:relation_owner = {
		send_interface_toast = {
			type = msg_set_relation_$RELATION$
			left_icon = this
			right_icon = scope:relation_target
		}
	}
	scope:relation_target = {
		send_interface_toast = {
			type = msg_set_relation_$RELATION$
			left_icon = this
			right_icon = scope:relation_owner
		}
	}
}

#Sets favor relation, then gives hook
progress_towards_hook_effect = {
	#If has potential favor, give hook!
	if = {
		limit = {
			NOT = {
				has_hook = $CHARACTER$
			}
			has_relation_potential_hook = $CHARACTER$
		}
		add_hook = {
			type = $HOOK_TYPE$
			target = $CHARACTER$
		}
	}
	# If not...
	else = {
		if = {
			limit = {
				NOT = { has_hook = $CHARACTER$ }
			}
			set_relation_potential_hook = $CHARACTER$
		}
		else = {
			reverse_add_opinion = {
				target = $CHARACTER$
				modifier = favor_opinion
				opinion = 25
			}
		}
	}
}

progress_towards_friend_ai_effect = {
	if = {
		limit = {
			$CHARACTER$ = { is_ai = yes }
		}
		progress_towards_friend_effect = {
			CHARACTER = $CHARACTER$
			OPINION = $OPINION$
			REASON = $REASON$
		}
	}
}

progress_towards_lover_ai_effect = {
	if = {
		limit = {
			$CHARACTER$ = { is_ai = yes }
		}
		progress_towards_lover_effect = {
			CHARACTER = $CHARACTER$
			OPINION = $OPINION$
			REASON = $REASON$
		}
	}
}

progress_towards_rival_ai_effect = {
	if = {
		limit = {
			$CHARACTER$ = { is_ai = yes }
		}
		progress_towards_rival_effect = {
			CHARACTER = $CHARACTER$
			OPINION = $OPINION$
			REASON = $REASON$
		}
	}
}

progress_towards_intent_effect = {
	if = {
		limit = {
			intent_target ?= $CHARACTER$
			has_activity_intent = woo_attendee_intent
		}
		progress_towards_lover_effect = {
			REASON = $REASON$
			CHARACTER = $CHARACTER$
			OPINION = default_lover_opinion
		}
	}
	else_if = {
		limit = {
			OR = {
				AND = {
					intent_target ?= $CHARACTER$
					has_activity_intent = befriend_attendee_intent
				}
				$FRIEND_FALLBACK$ = yes
			}
		}
		progress_towards_friend_effect = {
			REASON = $REASON$
			CHARACTER = $CHARACTER$
			OPINION = default_friend_opinion
		}
	}
	else = {
		reverse_add_opinion = {
			modifier = kindness_opinion
			target = $CHARACTER$
			opinion = default_friend_opinion
		}
	}
}

clear_grudges_effect = {
	$CHAR_1$ = {
		if = {
			limit = { has_relation_grudge = $CHAR_2$ }
			remove_relation_grudge = $CHAR_2$
		}
	}
	$CHAR_2$ = {
		if = {
			limit = { has_relation_grudge = $CHAR_1$ }
			remove_relation_grudge = $CHAR_1$
		}
	}
}
