﻿namespace = tribal


#Events related to tribal governments
#These events are very generalized to be applicable for a wide variety of characters, and some inaccuracies will inevitable exist.

# Flavor events
# tribal.1001-1999



#################
#				#
#	FLAVOR 		#
#				#
#################


#########################################
# Someone challenges your rule!			#
# by Linnéa Thimrén						#
#########################################

#Can only be triggered through the decision "tribal_challenge_ruler_decision"

scripted_effect tribal_1001_transfer_liege_title_effect = {
	scope:title_being_fought_over.holder = {
		# Only add it to the holder to the list if they don't have another title of the same tier
		if = {
			limit = {
				any_held_title = {
					count = 0
					this != scope:title_being_fought_over
					tier = scope:title_being_fought_over.tier
				}
			}
			add_to_temporary_list = transfered_vassals
		}
		every_vassal = {
			limit = {
				this != scope:challenger
			}
			add_to_temporary_list = transfered_vassals
		}
	}
	create_title_and_vassal_change = {
		type = usurped
		save_scope_as = change
		add_claim_on_loss = no
	}
	scope:title_being_fought_over = {
		change_title_holder = {
			holder = scope:challenger
			change = scope:change
		}
	}
	every_in_list = {
	 	list = transfered_vassals
	 	change_liege = {
	 		LIEGE = scope:challenger
	 		CHANGE = scope:change
	 	}
	}
	resolve_title_and_vassal_change = scope:change
	if = {
		limit = {
			root = scope:challenger
		}
		scope:liege_to_challenge = {
			add_opinion = {
				target = scope:challenger
				modifier = usurped_title
			}
		}
	}
	else = {
		hidden_effect = {
			scope:liege_to_challenge = {
				add_opinion = {
					target = scope:challenger
					modifier = usurped_title
				}
			}
		}
	}
}

scripted_effect tribal_1001_challenger_lost_effect = {
	if = {
		limit = {
			root = scope:liege_to_challenge
		}
		scope:liege_to_challenge = {
			add_prestige = medium_prestige_gain
		}
	}
	else = {
		hidden_effect = {
			scope:liege_to_challenge = {
				add_prestige = medium_prestige_gain
			}
		}
	}
	add_prestige_level = -1
	if = {
		limit = {
			root = scope:challenger
		}
		scope:liege_to_challenge = {
			add_opinion = {
				target = scope:challenger
				modifier = tried_to_usurped_title
			}
		}
	}
	else = {
		hidden_effect = {
			scope:liege_to_challenge = {
				add_opinion = {
					target = scope:challenger
					modifier = tried_to_usurped_title
				}
			}
		}
	}
}


scripted_effect tribal_1001_challenger_backed_out_effect = {
	add_prestige = major_prestige_loss
	if = {
		limit = {
			root = scope:challenger
		}
		scope:liege_to_challenge = {
			add_opinion = {
				target = scope:challenger
				modifier = tried_to_usurped_title
			}
		}
	}
	else = {
		hidden_effect = {
			scope:liege_to_challenge = {
				add_opinion = {
					target = scope:challenger
					modifier = tried_to_usurped_title
				}
			}
		}
	}
}

scripted_effect tribal_1001_start_sce_bout_effect = {
	custom_tooltip = challenge_to_single_combat_interaction.enter_non_lethal_bout.tt
	random_list = {
		100 = {
			show_chance = no
			trigger = { exists = scope:liege_champion }
			desc = tribal.1001.a_champion_success
			scope:challenger = { tribal_1001_challenger_lost_effect = yes }
		}
		100 = {
			show_chance = no
			trigger = { exists = scope:liege_champion }
			desc = tribal.1001.a_champion_failure
			scope:challenger = { tribal_1001_transfer_liege_title_effect = yes }
		}
		100 = {
			show_chance = no
			trigger = {
				NOT = { exists = scope:liege_champion }
				this = scope:liege_to_challenge
			}
			desc = tribal.1001.a_success
			scope:challenger = { tribal_1001_challenger_lost_effect = yes }
		}
		100 = {
			show_chance = no
			trigger = {
				NOT = { exists = scope:liege_champion }
				this = scope:liege_to_challenge
			}
			desc = tribal.1001.a_failure
			scope:challenger = { tribal_1001_transfer_liege_title_effect = yes }
		}
		100 = {
			show_chance = no
			trigger = {
				NOT = { exists = scope:liege_champion }
				this = scope:challenger
			}
			desc = tribal.1001.a_failure
			scope:challenger = { tribal_1001_challenger_lost_effect = yes }
		}
		100 = {
			show_chance = no
			trigger = {
				NOT = { exists = scope:liege_champion }
				this = scope:challenger
			}
			desc = tribal.1001.a_success
			scope:challenger = { tribal_1001_transfer_liege_title_effect = yes }
		}
	}
}

scripted_trigger tribal_1001_champion_check_trigger = {
	this != scope:challenger
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
	is_available = yes
	is_adult = yes
	is_ai = yes
	NOT = { has_relation_rival = root }
	can_start_single_combat_trigger = yes
}

tribal.1001 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					age >= 45
				}
				desc = tribal.1001.desc_old
			}
			triggered_desc = {
				trigger = {
					prowess < scope:challenger.prowess
				}
				desc = tribal.1001.desc_weak
			}
			triggered_desc = {
				trigger = {
					scope:challenger = {
						has_dread_level_towards = {
							target = root
							level = 2
						}
					}
				}
				desc = tribal.1001.desc_meak
			}
			desc = tribal.1001.desc_fallback
		}
		desc = tribal.1001.desc
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = personality_bold
	}

	trigger = {
		scope:challenger = { can_start_single_combat_trigger = yes }
	}

	immediate = {
		play_music_cue = mx_cue_combat_2
		scope:challenger = {
			add_character_flag = { #To block the event and block the decision
				flag = recently_took_the_tribal_challenge_ruler_decision
				years = 10
			}
		}
		#If you cannot fight yourself then find a champion
		if = {
			limit = {
				NAND = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					can_start_single_combat_trigger = yes
				}
			}
			if = {
				limit = {
					any_court_position_holder = {
						type = champion_court_position
						tribal_1001_champion_check_trigger = yes
					}
				}
				every_court_position_holder = {
					type = champion_court_position
					limit = { tribal_1001_champion_check_trigger = yes }
					add_to_list = champion_candidates
				}
			}
			if = {
				limit = {
					any_relation = {
						type = friend
						tribal_1001_champion_check_trigger = yes
					}
				}
				every_relation = {
					type = friend
					limit = { tribal_1001_champion_check_trigger = yes }
					add_to_list = champion_candidates
				}
			}
			if = {
				limit = {
					exists = cp:councillor_marshal
					cp:councillor_marshal = { tribal_1001_champion_check_trigger = yes }
				}
				cp:councillor_marshal = { add_to_list = champion_candidates }
			}
			if = {
				limit = {
					any_knight = { tribal_1001_champion_check_trigger = yes }
				}
				every_knight = {
					limit = { tribal_1001_champion_check_trigger = yes }
					add_to_list = champion_candidates
				}
			}
			#Still empty list?
			if = {
				limit = {
					any_in_list = {
						list = champion_candidates
						count < 1
					}
				}
				if = {
					limit = {
						any_vassal = { tribal_1001_champion_check_trigger = yes }
					}
					every_vassal = {
						limit = { tribal_1001_champion_check_trigger = yes }
						add_to_list = champion_candidates
					}
				}
				if = {
					limit = {
						any_courtier = { tribal_1001_champion_check_trigger = yes }
					}
					every_courtier = {
						limit = { tribal_1001_champion_check_trigger = yes }
						add_to_list = champion_candidates
					}
				}
			}
			#Save champion
			if = {
				limit = {
					any_in_list = {
						list = champion_candidates
						count >= 1
					}
				}
				random_in_list = {
					list = champion_candidates
					limit = { #We prioritize your champions
						has_court_position = champion_court_position
						is_court_position_employer = {
							court_position = champion_court_position
							who = root
						}
					}
					alternative_limit = { prowess > high_skill_rating }
					alternative_limit = { always = yes }
					weight = {
						base = 1
						compare_modifier = {
							value = prowess
							multiplier = 10
						}
						opinion_modifier = {
							opinion_target = root
							multiplier = 1
						}
					}
					save_scope_as = liege_champion
				}
			}
		}
	}

	option = { #Fight!
		name = {
			trigger = { age > scope:challenger.age }
			text = tribal.1001.a_child
		}
		name = {
			trigger = { age <= scope:challenger.age }
			text = tribal.1001.a
		}
		trigger = {
			OR = {
				AND = {
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
					can_start_single_combat_trigger = yes
				}
				exists = scope:liege_champion
			}
		}
		if = {
			limit = { exists = scope:liege_champion }
			custom_tooltip = tribal.1001.a_champion
			show_as_tooltip = {
				scope:liege_champion = { tribal_1001_start_sce_bout_effect = yes }
			}
		}
		else = {
			show_as_tooltip = { tribal_1001_start_sce_bout_effect = yes }
		}
		
		scope:challenger = { trigger_event = tribal.1003 }

		ai_chance = {
			base = 50
			modifier = {
				trigger = { NOT = { exists = scope:liege_champion } }
				add = 30
				prowess > scope:challenger.prowess
			}
			modifier = {
				trigger = { exists = scope:liege_champion }
				add = 30
				scope:liege_champion.prowess > scope:challenger.prowess
			}
			ai_value_modifier = {
				ai_boldness = 0.75
			}
		}
	}

	option = { #Flyting!
		name = tribal.1001.b
		trigger = {
			culture = {
				OR = {
					has_cultural_pillar = heritage_north_germanic
					has_cultural_pillar = heritage_west_germanic
					has_cultural_pillar = heritage_brythonic
					has_cultural_pillar = heritage_goidelic
				}
			}
		}
		show_as_tooltip = {
			duel = {
				skill = learning
				target = scope:challenger
				10 = {
					desc = tribal.1001.b_success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					scope:challenger = {
						tribal_challenger_lost_effect = yes
					}
				}
				10 = {
					desc = tribal.1001.b_failure
					scope:challenger = {
						tribal_transfer_liege_title_effect = yes
					}
				}
			}
		}
		scope:challenger = {
			trigger_event = tribal.1006
		}

		ai_chance = {
			base = 50
			modifier = {
				add = 30
				learning > scope:challenger.learning
			}
		}
	}

	option = { #Ok, take it...
		name = tribal.1001.c
		show_as_tooltip = {
			tribal_transfer_liege_title_effect = yes
		}
		scope:challenger = {
			trigger_event = tribal.1002
		}
		ai_chance = {
			base = 0
			#More likely the more scared I am of the challenger
			modifier = {
				add = 25
				dread_modified_ai_boldness = {
					dreaded_character = scope:challenger
					value <= -45
				}
			}
			modifier = {
				add = 50
				dread_modified_ai_boldness = {
					dreaded_character = scope:challenger
					value <= -75
				}
			}
		}
	}
}

#They just gave it all over without a fight!
tribal.1002 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1003.desc_opening
		desc = tribal.1002.desc
	}
	theme = realm
	left_portrait = {
		character = scope:liege_to_challenge
		animation = fear
	}

	immediate = {
		tribal_transfer_liege_title_effect = yes
	}

	option = {
		name = tribal.1002.a
	}
}


#They will fight you, in a... fight!
tribal.1003 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1003.desc_opening
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						scope:liege_to_challenge.age > root.age
					}
					desc = tribal.1003.desc_old
				}
				desc = tribal.1003.desc_young
			}
			first_valid = {
				triggered_desc = {
				    trigger = {
						exists = scope:liege_champion
				    }
				    desc = tribal.1003.desc_liege_champion
				}
				desc = tribal.1003.desc
			}
		}
	}
	theme = realm
	left_portrait = {
		character = scope:liege_to_challenge
		animation = anger
	}
	right_portrait = {
		trigger = {
			exists = scope:liege_champion
		}
		character = scope:liege_champion
		animation = anger
	}

	immediate = {
		set_signature_weapon_effect = yes
		if = {
			limit = {
				exists = scope:liege_champion
			}
			scope:liege_champion = {
				set_signature_weapon_effect = yes
			}
		}
		else = {
			scope:liege_to_challenge = {
				set_signature_weapon_effect = yes
			}
		}
	}

	option = { #I will fight!
		name = tribal.1003.a
		if = {
			limit = { exists = scope:liege_champion }
			show_as_tooltip = {
				scope:liege_champion = { tribal_1001_start_sce_bout_effect = yes }
			}
			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:challenger
				SC_ATTACKER = scope:challenger
				SC_DEFENDER = scope:liege_champion
				FATALITY = no
				FIXED = no
				LOCALE = throne_room
				OUTPUT_EVENT = tribal.1021
				INVALIDATION_EVENT = tribal.1022
			}
		}
		else = {
			show_as_tooltip = { tribal_1001_start_sce_bout_effect = yes }
			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:challenger
				SC_ATTACKER = scope:challenger
				SC_DEFENDER = scope:liege_to_challenge
				FATALITY = no
				FIXED = no
				LOCALE = throne_room
				OUTPUT_EVENT = tribal.1021
				INVALIDATION_EVENT = tribal.1022
			}
		}
	}

	option = { #Back out
		name = tribal.1003.b
		tribal_1001_challenger_backed_out_effect = yes
		scope:liege_to_challenge = {
			trigger_event = tribal.1010
		}
	}
}

#Challenger won!
tribal.1004 = {
	orphan = yes
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1004.desc_opening
		desc = tribal.1004.desc
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = happiness
	}

	option = {
		name = tribal.1004.a
		scope:challenger = {
			tribal_transfer_liege_title_effect = yes
		}
	}
}

#Challenger lost
tribal.1005 = {
	orphan = yes
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1004.desc_opening
		desc = tribal.1005.desc
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = sadness
	}

	option = {
		name = tribal.1005.a
		show_as_tooltip = {
			scope:challenger = {
				tribal_challenger_lost_effect = yes
			}
		}
	}
}

#Using champion - Challenger won!
tribal.1014 = {
	orphan = yes
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1014.desc_opening
		desc = tribal.1014.desc
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = happiness
	}
	right_portrait = {
		character = scope:liege_champion
		animation = sadness
	}

	option = {
		name = tribal.1014.a
		scope:challenger = {
			tribal_transfer_liege_title_effect = yes
		}
	}
}

#Using champion - Challenger lost
tribal.1015 = {
	orphan = yes
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1014.desc_opening
		desc = tribal.1015.desc
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = sadness
	}
	right_portrait = {
		character = scope:liege_champion
		animation = war_over_win
	}

	option = {
		name = tribal.1015.a
		show_as_tooltip = {
			scope:challenger = {
				tribal_challenger_lost_effect = yes
			}
		}
		scope:liege_champion = {
			add_opinion = {
				target = root
				modifier = respect_opinion
				opinion = 20
			}
		}
	}
}


#They will fight you, time for flyting
tribal.1006 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1003.desc_opening
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						scope:liege_to_challenge.age > root.age
					}
					desc = tribal.1006.desc_old
				}
				desc = tribal.1006.desc_young
			}
		}
		desc = tribal.1006.desc
		desc = {
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_02
				}
			}
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_2_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_2_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_02
				}
			}
		}
	}
	theme = realm
	left_portrait = {
		character = scope:liege_to_challenge
		animation = anger
	}

	immediate = {
		hidden_effect = {
			random_list = {
				1 = {
					save_scope_value_as = {
						name = rhyme_group
						value = flag:a
					}
				}
				1 = {
					save_scope_value_as = {
						name = rhyme_group
						value = flag:b
					}
				}
				1 = {
					save_scope_value_as = {
						name = rhyme_group
						value = flag:c
					}
				}
			}
		}
	}

	option = {
		name = tribal.1006.a
		duel = {
			skill = learning
			target = scope:liege_to_challenge
			10 = {
				desc = tribal.1006.a_success
				send_interface_toast = {
					title = tribal.1006.a_success
					left_icon = scope:liege_to_challenge
					show_as_tooltip = {
						tribal_transfer_liege_title_effect = yes
					}
				}
				scope:liege_to_challenge = {
					trigger_event = tribal.1007
				}
			}
			10 = {
				desc = tribal.1006.a_failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2
				}
				send_interface_toast = {
					title = tribal.1006.a_failure
					left_icon = scope:liege_to_challenge
					tribal_challenger_lost_effect = yes
				}
				scope:liege_to_challenge = {
					trigger_event = tribal.1008
				}
			}
		}
	}

	option = { #Back out
		name = tribal.1006.b
		tribal_1001_challenger_backed_out_effect = yes
		scope:liege_to_challenge = {
			trigger_event = tribal.1010
		}
	}
}

#Challenger won!
tribal.1007 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1008.desc
		desc = {
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_02
				}
			}
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_2_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_2_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_02
				}
			}
		}
		desc = tribal.1007.desc_ending
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = happiness
	}

	immediate = {
		scope:challenger = {
			tribal_transfer_liege_title_effect = yes
		}
	}

	option = {
		name = tribal.1007.a
	}
}

#Challenger lost
tribal.1008 = {
	type = character_event
	title = tribal.1001.t
	desc = {
		desc = tribal.1008.desc
		desc = {
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_1_a_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_1_b_02
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_1_c_02
				}
			}
			random_valid = {
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:a }
					desc = insult_poetry_line_2_a_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:b }
					desc = insult_poetry_line_2_b_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_01
				}
				triggered_desc = {
					trigger = { scope:rhyme_group = flag:c }
					desc = insult_poetry_line_2_c_02
				}
			}
		}
		desc = tribal.1008.desc_ending
	}
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = sadness
	}

	immediate = {
		show_as_tooltip = {
			scope:challenger = {
				tribal_challenger_lost_effect = yes
			}
		}
	}

	option = {
		name = tribal.1008.a
	}
}

#They back out
tribal.1010 = {
	type = character_event
	title = tribal.1001.t
	desc = tribal.1010.desc
	theme = realm
	left_portrait = {
		character = scope:challenger
		animation = fear
	}

	immediate = {
		add_prestige = medium_prestige_gain
		show_as_tooltip = {
			scope:challenger = {
				tribal_1001_challenger_backed_out_effect = yes
			}
		}
	}

	option = {
		name = tribal.1010.a
	}
}

#	Bout has ended, inform affected parties.
tribal.1021 = {
	hidden = yes

	immediate = {
		# Did scope:challenger win?
		if = {
			limit = { scope:sc_victor = scope:challenger }
			# And send out the ending events.
			scope:liege_to_challenge = {
				if = {
					limit = { exists = scope:liege_champion }
					send_interface_toast = {
						title = tribal.1001.a_champion_failure
						left_icon = scope:challenger
						right_icon = scope:liege_champion
						show_as_tooltip = { tribal_1001_transfer_liege_title_effect = yes }
					}
				}
				else = {
					send_interface_toast = {
						title = tribal.1001.a_failure
						left_icon = scope:challenger
						show_as_tooltip = { tribal_1001_transfer_liege_title_effect = yes }
					}
				}
			}
			scope:challenger = {
				send_interface_toast = {
					title = tribal.1001.a_success
					left_icon = scope:liege_to_challenge
					tribal_1001_transfer_liege_title_effect = yes
				}
			}
		}
		# Or did they lose?
		else = {
			# Apply effects; we do this separately so that there's not a weird day's delay.
			tribal_1001_challenger_lost_effect = yes
			# And send out the ending events.
			scope:liege_to_challenge = {
				if = {
					limit = { exists = scope:liege_champion }
					send_interface_toast = {
						title = tribal.1001.a_champion_success
						left_icon = scope:challenger
						right_icon = scope:liege_champion
						show_as_tooltip = { tribal_1001_challenger_lost_effect = yes }
					}
				}
				else = {
					send_interface_toast = {
						title = tribal.1001.a_success
						left_icon = scope:challenger
						show_as_tooltip = { tribal_1001_challenger_lost_effect = yes }
					}
				}
			}
			scope:challenger = {
				send_interface_toast = {
					title = tribal.1001.a_failure
					left_icon = scope:liege_to_challenge
					tribal_1001_challenger_lost_effect = yes
				}
			}
		}
	}
}

tribal.1022 = {
	hidden = yes

	immediate = {
		# Put your shirts back on.
		if = {
			limit = { exists = scope:liege_champion }
			single_combat_clean_shirtlessness_effect = {
				ATTACKER = scope:challenger
				DEFENDER = scope:liege_champion
			}
		}
		else = {
			single_combat_clean_shirtlessness_effect = {
				ATTACKER = scope:challenger
				DEFENDER = scope:liege_to_challenge
			}
		}
		# Inform both parties that the duel has invalidated.
		scope:challenger = {
			send_interface_toast = {	
				title = tribal.1022.trigger_failure.challenger
				left_icon = scope:liege_to_challenge
			}
		}
		scope:liege_to_challenge = {
			send_interface_toast = {	
				title = tribal.1022.trigger_failure.liege_to_challenge
				left_icon = scope:challenger
			}
		}
	}
}

#########################################
# Holmgång with a rival 				#
# by Linnéa Thimrén						#
#########################################

scripted_trigger tribal_1101_victim_trigger = {
	basic_is_available_ai = yes
	is_in_the_same_court_as_or_guest = root
	NOR = {
		this = scope:rival
		has_relation_lover = scope:rival
		has_relation_friend = scope:rival
		has_trait_rank = {
			trait = wounded
			rank >= 2
		}
	}
}

tribal.1101 = {
	type = character_event
	title = tribal.1101.t
	desc = tribal.1101.desc
	theme = rival_relation
	left_portrait = {
		character = scope:rival
		animation = rage
	}
	right_portrait = {
		character = scope:victim
		animation = pain
	}
	lower_right_portrait = {
		character = scope:friend
		animation = anger
	}
	
	trigger = {
		faith = faith:norse_pagan
		government_has_flag = government_is_tribal
		NOT = { has_character_flag = had_event_tribal_1101 }
		any_relation = {
			type = rival
			faith = faith:norse_pagan
			basic_is_available_ai = yes
			save_temporary_scope_as = rival
		}
		OR = {
			any_heir = {
				tribal_1101_victim_trigger = yes
			}
			any_child = {
				tribal_1101_victim_trigger = yes
			}
			any_spouse = {
				tribal_1101_victim_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1

		modifier = {
			add = 1
			any_relation = {
				type = rival
				faith = faith:norse_pagan
				basic_is_available_ai = yes
				is_in_the_same_court_as_or_guest = root
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_tribal_1101
			years = 10
		}
		random_relation = {
			type = rival
			limit = {
				faith = faith:norse_pagan
				is_in_the_same_court_as_or_guest = root
				basic_is_available_ai = yes
			}
			alternative_limit = {
				faith = faith:norse_pagan
				basic_is_available_ai = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					has_relation_nemesis = root
				}
			}
			save_scope_as = rival
		}

		hidden_effect = {
			random_list = {
				10 = {
					trigger = {
						any_heir = {
							tribal_1101_victim_trigger = yes
						}
					}
					random_heir = {
						limit = {
							tribal_1101_victim_trigger = yes
						}
						weight = {
							base = 1
							modifier = {
								add = 10
								is_player_heir_of = root
							}
							modifier = {
								add = 5
								has_friendly_relationship_with_root_trigger = yes
							}
						}
						save_scope_as = victim
					}
				}
				10 = {
					trigger = {
						any_child = {
							tribal_1101_victim_trigger = yes
						}
					}
					random_child = {
						limit = {
							tribal_1101_victim_trigger = yes
						}
						weight = {
							base = 1
							modifier = {
								add = 5
								is_heir_of = root
							}
							modifier = {
								add = 10
								has_friendly_relationship_with_root_trigger = yes
							}
						}
						save_scope_as = victim
					}
				}
				10 = {
					trigger = {
						any_spouse = {
							tribal_1101_victim_trigger = yes
						}
					}
					random_spouse = {
						limit = {
							tribal_1101_victim_trigger = yes
						}
						weight = {
							base = 1
							modifier = {
								add = 10
								has_friendly_relationship_with_root_trigger = yes
							}
						}
						save_scope_as = victim
					}
				}
			}
		}
		scope:victim = {
			increase_wounds_effect = { REASON = fight }
		}

		#Do you have a friend who can help you?
		if = {
			limit = {
				any_relation = {
					type = friend
					basic_is_available_ai = yes
					prowess > root.prowess
				}
			}
			random_relation = {
				type = friend
				limit = {
					basic_is_available_ai = yes
					prowess > root.prowess
				}
				save_scope_as = friend
			}
		}
	}

	option = { #I challenge thee!
		name = tribal.1101.a
		duel = {
			skill = prowess
			target = scope:rival
			20 = {
				desc = tribal.1101.a_success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3
				}
				show_as_tooltip = {
					scope:rival = {
						add_prestige_level = -1
						death = {
							death_reason = death_duel
							killer = root
						}
					}
					add_prestige = medium_prestige_gain
				}
				trigger_event = tribal.1102
			}
			10 = {
				desc = tribal.1101.a_failure
				show_as_tooltip = {
					increase_wounds_effect = { REASON = fight }
					root = { add_prestige = minor_prestige_loss }
				}
				trigger_event = tribal.1104
			}
		}
		show_as_tooltip = {
			scope:rival = {
				add_opinion = {
					target = root
					modifier = hate_opinion
					opinion = -20
				}
			}
		}
	}

	option = { #My friend challenges thee! Easier challenge
		name = tribal.1101.b
		trigger = {
			exists = scope:friend
		}
		scope:friend = {
			duel = {
				skill = prowess
				target = scope:rival
				50 = {
					desc = tribal.1101.b_success
					compare_modifier = {
						value = scope:duel_value
						multiplier = 4
					}
					show_as_tooltip = {
						scope:rival = {
							add_prestige_level = -1
							death = {
								death_reason = death_duel
								killer = scope:friend
							}
						}
						root = { add_prestige = medium_prestige_gain }
					}
					root = {
						trigger_event = tribal.1103
					}
				}
				10 = {
					desc = tribal.1101.b_failure
					show_as_tooltip = {
						increase_wounds_effect = { REASON = fight }
						root = { add_prestige = minor_prestige_loss }
					}
					root = {
						trigger_event = tribal.1105
					}
				}
			}
			show_as_tooltip = {
				scope:rival = {
					add_opinion = {
						target = scope:friend
						modifier = hate_opinion
						opinion = -20
					}
				}
				scope:rival = {
					add_opinion = {
						target = root
						modifier = hate_opinion
						opinion = -20
					}
				}
			}
		}
		save_scope_value_as = {
			name = used_friend
			value = yes
		}
		trigger_event = tribal.1102
	}

	option = { #Do nothing
		name = tribal.1101.c
		scope:victim = {
			add_opinion = {
				target = root
				modifier = weak_opinion
				opinion = -10
			}
		}
		add_prestige = major_prestige_loss
	}
}

#You won!!
tribal.1102 = {
	type = character_event
	title = tribal.1101.t
	desc = {
		desc = tribal.1102.desc_opening
		desc = tribal.1102.desc
	}
	theme = rival_relation
	left_portrait = scope:rival

	immediate = {
		set_signature_weapon_effect = yes
		scope:rival = {
			add_prestige_level = -1
			death = {
				death_reason = death_duel
				killer = root
			}
		}
		add_prestige = medium_prestige_gain
	}

	option = {
		name = tribal.1102.a
	}
}

#You won!! By the help of your friend
tribal.1103 = {
	type = character_event
	title = tribal.1101.t
	desc = {
		desc = tribal.1103.desc_opening
		desc = tribal.1103.desc
	}
	theme = rival_relation
	left_portrait = scope:rival
	right_portrait = {
		character = scope:friend
		animation = personality_bold
	}

	immediate = {
		scope:friend = {
			set_signature_weapon_effect = yes
		}
		scope:rival = {
			add_prestige_level = -1
			death = {
				death_reason = death_duel
				killer = root
			}
		}
		add_prestige = medium_prestige_gain
	}

	option = {
		name = tribal.1102.a
	}
}

#Rival won...
tribal.1104 = {
	type = character_event
	title = tribal.1101.t
	desc = {
		desc = tribal.1102.desc_opening
		desc = tribal.1104.desc
	}
	theme = rival_relation
	left_portrait = {
		character = scope:rival
		animation = personality_bold
	}

	immediate = {
		set_signature_weapon_effect = yes
		scope:rival = {
			set_signature_weapon_effect = yes
		}
		increase_wounds_effect = { REASON = fight }
		add_prestige = minor_prestige_loss
	}

	option = {
		name = tribal.1104.a
	}
}

#Rival won over friend...
tribal.1105 = {
	type = character_event
	title = tribal.1101.t
	desc = {
		desc = tribal.1102.desc_opening
		desc = tribal.1105.desc
	}
	theme = rival_relation
	left_portrait = {
		character = scope:rival
		animation = personality_bold
	}

	immediate = {
		scope:friend = {
			set_signature_weapon_effect = yes
			increase_wounds_effect = { REASON = fight }
		}
		scope:rival = {
			set_signature_weapon_effect = yes
		}
		add_prestige = minor_prestige_loss
	}

	option = {
		name = tribal.1105.a
	}
}


#########################################
# Horse Racing							#
# by Linnéa Thimrén						#
#########################################

tribal.1201 = {
	type = character_event
	title = tribal.1201.t
	desc = {
		desc = tribal.1201.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					any_owned_story = {
						type = story_cycle_martial_lifestyle_warhorse
					}
				}
				desc = tribal.1201.desc_warhorse
			}
			desc = tribal.1201.desc
		}
		desc = tribal.1201.desc_ending
	}
	theme = hunting
	left_portrait = scope:racer
	right_portrait = scope:villain_racer
	
	trigger = {
		is_available_adult = yes
		government_has_flag = government_is_tribal
		capital_province = { geographical_region = world_steppe }
		NOT = { has_character_flag = had_event_tribal_1201 }
		OR = {
			any_vassal = {
				count >= 2
				is_available_ai_adult = yes
			}
			any_courtier = {
				count >= 2
				is_available_ai_adult = yes
			}
			any_neighboring_realm_same_rank_owner = {
				count >= 2
				is_available_ai_adult = yes
				government_has_flag = government_is_tribal
				capital_province = { geographical_region = world_steppe }
			}
		}
	}

	weight_multiplier = {
		base = 1

		modifier = {
			add = 1
			OR = { #More likely if someone that can be involved has a warhorse story going on
				any_owned_story = {
					type = story_cycle_martial_lifestyle_warhorse
				}
				any_vassal = {
					is_available_ai_adult = yes
					any_owned_story = {
						type = story_cycle_martial_lifestyle_warhorse
					}
				}
				any_courtier = {
					is_available_ai_adult = yes
					any_owned_story = {
						type = story_cycle_martial_lifestyle_warhorse
					}
				}
				any_neighboring_realm_same_rank_owner = {
					government_has_flag = government_is_tribal
					capital_province = { geographical_region = world_steppe }
					is_available_ai_adult = yes
					any_owned_story = {
						type = story_cycle_martial_lifestyle_warhorse
					}
				}
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_tribal_1201
			years = 10
		}
		if = {
			limit = {
				any_vassal = {
					is_available_ai_adult = yes
				}
			}
			every_vassal = {
				limit = {
					is_available_ai_adult = yes
				}
				add_to_list = potential_racers
			}
		}
		if = {
			limit = {
				any_neighboring_realm_same_rank_owner = {
					is_available_ai_adult = yes
					government_has_flag = government_is_tribal
					capital_province = { geographical_region = world_steppe }
				}
			}
			every_neighboring_realm_same_rank_owner = {
				limit = {
					is_available_ai_adult = yes
					government_has_flag = government_is_tribal
					capital_province = { geographical_region = world_steppe }
				}
				add_to_list = potential_racers
			}
		}
		if = {
			limit = {
				any_courtier = {
					is_available_ai_adult = yes
				}
			}
			every_courtier = {
				limit = {
					is_available_ai_adult = yes
				}
				add_to_list = potential_racers
			}
		}
		#To save the "good" racer
		random_in_list = {
			list = potential_racers
			limit = {
				any_owned_story = {
					type = story_cycle_martial_lifestyle_warhorse
				}
			}
			alternative_limit = {
				has_court_position = master_of_horse_court_position
			}
			alternative_limit = {
				is_of_major_interest_to_root_trigger = yes
			}
			alternative_limit = {
				always = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					has_any_good_relationship_with_root_trigger = yes
				}
				modifier = {
					add = 5
					is_powerful_vassal_of = root
				}
				opinion_modifier = {
					opinion_target = root
					multiplier = 10
				}
			}
			save_scope_as = racer
		}
		#To save the "bad" racer
		random_in_list = {
			list = potential_racers
			limit = {
				any_owned_story = {
					type = story_cycle_martial_lifestyle_warhorse
				}
				this != scope:racer
			}
			alternative_limit = {
				has_court_position = master_of_horse_court_position
				this != scope:racer
			}
			alternative_limit = {
				is_of_major_interest_to_root_trigger = yes
				this != scope:racer
			}
			alternative_limit = {
				this != scope:racer
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					has_personality_malicious_trigger = yes
				}
				modifier = {
					add = 10
					has_any_bad_relationship_with_root_trigger = yes
				}
				modifier = {
					add = 5
					is_powerful_vassal_of = root
				}
				opinion_modifier = {
					opinion_target = root
					multiplier = -10
				}
			}
			save_scope_as = villain_racer
		}
	}

	option = { #Join!
		name = tribal.1201.a
		custom_tooltip = tribal.1201.a.tt
		trigger_event = {
			id = tribal.1202
			days = { 7 10 }
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { #Just chill
		name = tribal.1201.b
		add_stress = medium_stress_loss
		ai_chance = {
			base = 50
			modifier = {
				add = 30
				stress >= high_medium_stress
			}
		}
	}
}

#Sabotage time
tribal.1202 = {
	type = character_event
	title = tribal.1201.t
	desc = tribal.1202.desc
	theme = hunting
	left_portrait = {
		character = scope:villain_racer
		animation = personality_dishonorable
	}

	immediate = {
	
	}

	option = { #Intervene
		name = tribal.1202.a
		scope:villain_racer = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -20
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = 0.75
			}
		}
	}

	option = { #Do nothing
		name = tribal.1202.b
		flavor = tribal.1202.b.tt
		hidden_effect = {
			random_list = {
				20 = {
					save_scope_value_as = {
						name = sabotaged_you
						value = yes
					}
				}
				80 = {
					save_scope_value_as = {
						name = sabotaged_racer
						value = yes
					}
				}
			}
		}
		ai_chance = {
			base = 60
		}
	}
	
	option = { #Sabotage THEIR horse!
		name = tribal.1202.c
		duel = {
			skill = intrigue
			target = scope:villain_racer
			20 = {
				desc = tribal.1202.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = tribal.1202.c.success
					left_icon = scope:villain_racer
					custom_tooltip = tribal.1202.c.tt
				}
				save_scope_value_as = {
					name = sabotaged_villain
					value = yes
				}
			}
			10 = {
				desc = tribal.1202.c.failure
				send_interface_toast = {
					title = tribal.1202.c.failure
					left_icon = scope:villain_racer
					scope:villain_racer = {
						add_opinion = {
							target = root
							modifier = suspicion_opinion
							opinion = -10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 25
			modifier = {
				add = 50
				intrigue >= high_skill_rating
			}
			ai_value_modifier = {
				ai_vengefulness = 0.25
			}
		}
	}

	after = {
		trigger_event = {
			id = tribal.1203
			days = { 7 10 }
		}
	}
}

#Time to race!
tribal.1203 = {
	type = character_event
	title = tribal.1201.t
	desc = {
		desc = tribal.1203.desc_opening
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:sabotaged_you
				}
				desc = tribal.1203.desc_sabotaged_you
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotaged_racer
				}
				desc = tribal.1203.desc_sabotaged_racer
			}
			triggered_desc = {
				trigger = {
					exists = scope:sabotaged_villain
				}
				desc = tribal.1203.desc_sabotaged_villain
			}
			desc = tribal.1203.desc
		}
	}
	theme = hunting
	left_portrait = {
		character = scope:racer
		triggered_animation = {
			trigger = {
				exists = scope:sabotaged_racer
			}
			animation = pain
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:sabotaged_racer }
			}
			animation = idle
		}
	}
	right_portrait = {
		character = scope:villain_racer
		triggered_animation = {
			trigger = {
				exists = scope:sabotaged_villain
			}
			animation = pain
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:sabotaged_villain }
			}
			animation = idle
		}
	}

	immediate = {
		if = {
			limit = {
				exists = scope:sabotaged_racer
			}
			scope:racer = {
				increase_wounds_effect = { REASON = horse_riding_accident }
			}
		}
		if = {
			limit = {
				exists = scope:sabotaged_villain
			}
			scope:villain_racer = {
				increase_wounds_effect = { REASON = horse_riding_accident }
			}
		}
		if = {
			limit = {
				exists = scope:sabotaged_you
			}
			increase_wounds_effect = { REASON = horse_riding_accident }
		}
	}

	option = { #Stop and help
		name = tribal.1203.a
		trigger = {
			NOT = { exists = scope:sabotaged_you }
			OR = {
				exists = scope:sabotaged_racer
				exists = scope:sabotaged_villain
			}
		}
		if = {
			limit = {
				exists = scope:sabotaged_racer
			}
			progress_towards_friend_effect = {
				CHARACTER = scope:racer
				OPINION = default_friend_opinion
				REASON = friend_helped_during_horse_race
			}
			scope:racer = {
				add_character_modifier = {
					modifier = wounds_quickly_tended_to_modifier
					years = 2
				}
			}
		}
		if = {
			limit = {
				exists = scope:sabotaged_villain
			}
			progress_towards_friend_effect = {
				CHARACTER = scope:villain_racer
				OPINION = default_friend_opinion
				REASON = friend_helped_during_horse_race
			}
			scope:villain_racer = {
				add_character_modifier = {
					modifier = wounds_quickly_tended_to_modifier
					years = 2
				}
			}
		}
		save_scope_value_as = {
			name = stopped_and_helped
			value = yes
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 100
				OR = {
					has_focus = learning_medicine_focus
					learning >= high_skill_rating
				}
			}
			ai_value_modifier = {
				ai_compassion = 0.75
			}
		}
	}

	option = { #Just focus on the race
		name = {
			trigger = {
				NOR = {
					exists = scope:sabotaged_racer
					exists = scope:sabotaged_villain
				}
			}
			text = tribal.1203.b_nothing_sabotaged
		}
		name = {
			trigger = {
				OR = {
					exists = scope:sabotaged_racer
					exists = scope:sabotaged_villain
				}
			}
			text = tribal.1203.b
		}
		trigger = {
			NOT = { exists = scope:sabotaged_you }
		}
		custom_tooltip = tribal.1203.b.tt
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = 0.5
			}
		}
	}

	option = { #You got hurt!
		name = tribal.1203.c
		trigger = {
			exists = scope:sabotaged_you
		}
	}

	option = { #Veer into the villain!
		name = tribal.1203.d
		trigger = {
			OR = {
				NOR = {
					exists = scope:sabotaged_racer
					exists = scope:sabotaged_villain
				}
				exists = scope:sabotaged_racer
			}
		}
		random_list = {
			70 = {
				desc = tribal.1203.d.success
				send_interface_toast = {
					title = tribal.1203.d.success
					left_icon = scope:villain_racer
					scope:villain_racer = {
						increase_wounds_effect = { REASON = horse_riding_accident }
					}
				}
			}
			30 = {
				desc = tribal.1203.d.failure
				send_interface_toast = {
					title = tribal.1203.d.failure
					left_icon = root
					custom_tooltip = tribal.1203.d.failure.tt
				}
				save_scope_value_as = {
					name = rammed_villains_horse
					value = yes
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_vengefulness = 0.5
				ai_compassion = -0.5
			}
		}
	}
	
	option = { #Jump over to the villains horse
		name = tribal.1203.e
		trigger = {
			NOT = { exists = scope:sabotaged_you }
			NOT = { exists = scope:sabotaged_villain }
			prowess >= high_skill_rating
		}
		skill = prowess
		duel = {
			skill = prowess
			target = scope:villain_racer
			20 = {
				desc = tribal.1203.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2
				}
				send_interface_toast = {
					title = tribal.1203.success
					left_icon = scope:villain_racer
					scope:villain_racer = {
						increase_wounds_effect = { REASON = horse_riding_accident }
					}
				}
				save_scope_value_as = {
					name = in_the_lead
					value = yes
				}
			}
			10 = {
				desc = tribal.1203.failure
				send_interface_toast = {
					title = tribal.1203.failure
					left_icon = scope:villain_racer
					increase_wounds_effect = { REASON = horse_riding_accident }
				}
			}
		}
		progress_towards_rival_effect = {
			REASON = rival_jump_to_rivals_horse
			CHARACTER = scope:villain_racer
			OPINION = default_rival_opinion
		}
		save_scope_value_as = {
			name = jumped_horses
			value = yes
		}
		ai_chance = {
			base = 100
			modifier = {
				add = 25
				prowess > scope:villain_racer.prowess
			}
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	after = {
		trigger_event = {
			id = tribal.1204
			days = { 7 10 }
		}
	}
}


#Finish line
tribal.1204 = {
	type = character_event
	title = tribal.1201.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						exists = scope:stopped_and_helped
						exists = scope:sabotaged_you
					}
				}
				desc = tribal.1204.desc_slow
			}
			desc = tribal.1204.desc_fast
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:racer_in_the_lead
				}
				desc = tribal.1204.desc_racer
			}
			triggered_desc = {
				trigger = {
					exists = scope:villain_in_the_lead
				}
				desc = tribal.1204.desc_villain
			}
			desc = {
				first_valid = {
					triggered_desc = {
						trigger = {
							exists = scope:jumped_horses
						}
						desc = tribal.1204.desc_you_jumped_horses
					}
					desc = tribal.1204.desc_you
				}
			}
		}
	}
	theme = hunting
	left_portrait = {
		character = scope:racer
		triggered_animation = {
			trigger = {
				exists = scope:racer_in_the_lead
			}
			animation = happiness
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:racer_in_the_lead }
			}
			animation = sadness
		}
	}
	right_portrait = {
		character = scope:villain_racer
		triggered_animation = {
			trigger = {
				exists = scope:villain_in_the_lead
				OR = {
					exists = scope:sabotaged_you
					exists = scope:sabotaged_racer
				}
			}
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				exists = scope:villain_in_the_lead
				NOR = {
					exists = scope:sabotaged_you
					exists = scope:sabotaged_racer
				}
			}
			animation = happiness
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:villain_in_the_lead }
			}
			animation = sadness
		}
	}

	immediate = {
		hidden_effect = {
			random_list = {
				5 = { #You win!
					trigger = {
						NOT = {
							exists = scope:sabotaged_you
						}
					}
					save_scope_value_as = {
						name = in_the_lead
						value = yes
					}
					modifier = {
						add = root.prowess
					}
					modifier = {
						add = -4
						exists = scope:rammed_villains_horse
					}
				}
				5 = { #Racer wins
					trigger = {
						NOT = {
							exists = scope:sabotaged_racer
						}
					}
					save_scope_value_as = {
						name = racer_in_the_lead
						value = yes
					}
					modifier = {
						add = scope:racer.prowess
					}
				}
				5 = { #Villain wins
					trigger = {
						NOT = {
							exists = scope:sabotaged_villain
						}
					}
					save_scope_value_as = {
						name = villain_in_the_lead
						value = yes
					}
					modifier = {
						add = scope:villain_racer.prowess
					}
				}
			}
		}
	}

	option = { #I won!
		name = tribal.1204.a
		trigger = {
			exists = scope:in_the_lead
		}
		add_prestige = major_prestige_gain
	}

	option = { #Racer won!
		name = tribal.1204.b
		trigger = {
			exists = scope:racer_in_the_lead
		}
		scope:racer = {
			add_prestige = major_prestige_gain
		}
		add_prestige = minor_prestige_loss
	}

	option = { #Villain won!
		name = tribal.1204.b
		trigger = {
			exists = scope:villain_in_the_lead
		}
		scope:villain_racer = {
			add_prestige = major_prestige_gain
		}
		add_prestige = minor_prestige_loss
	}
}



#########################################
# Crocodile Encounter					#
# by Linnéa Thimrén						#
#########################################

#Based on the travel narrative of Abu Abdalla ibn Battuta (he was alive a bit later, but still...!)
tribal.1301 = {
	type = character_event
	title = tribal.1301.t
	desc = tribal.1301.desc
	theme = friendly
	override_background = {
		reference = wilderness
	}
	left_portrait = {
		character = scope:peasant
		animation = dismissal
	}
	
	trigger = {
		is_available_adult = yes
		government_has_flag = government_is_tribal
		capital_province = { geographical_region = world_africa }
		NOT = { has_character_flag = had_event_tribal_1301 }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_tribal_1301
			years = 20
		}
		create_character = {
			template = servant_character
			dynasty = none
			location = root.capital_province
			gender_female_chance = 50
			save_scope_as = peasant
		}
		hidden_effect = {
			scope:peasant = {
				add_trait = brave
			}
		}
		capital_county = {
			save_scope_as = capital
		}
	}

	option = { #Thank you!! Have some gold
		name = tribal.1301.a
		trigger = {
			short_term_gold >= minor_gold_value
		}
		scope:capital = {
			add_county_modifier = {
				modifier = invested_in_province_modifier
				years = 5
			}
		}
		remove_short_term_gold = minor_gold_value
		ai_chance = {
			base = 50
			modifier = {
				add = -100
				has_trait = greedy
			}
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { #Thank you, please come work for me
		name = tribal.1301.b
		add_courtier = scope:peasant
		scope:peasant = {
			add_opinion = {
				target = root
				modifier = loyal_servant
			}
			hidden_effect = {
				set_relation_potential_friend = root
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
		}
	}

	option = { #Well... bye.
		name = tribal.1301.c
		add_character_modifier = {
			modifier = drank_water_modifier
			years = 1
		}
		hidden_effect = {
			random = {
				chance = 100
				trigger_event = tribal.1302
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 25
				has_trait = arrogant
			}
			ai_value_modifier = {
				ai_compassion = -0.5
			}
		}
	}

	option = { #Thanks.
		name = tribal.1301.d
		custom_tooltip = tribal.1301.d.tt
		ai_chance = {
			base = 50
		}
	}
}

#You approached the water
tribal.1302 = {
	type = character_event
	title = tribal.1301.t
	desc = tribal.1302.desc
	theme = unfriendly
	override_background = {
		reference = wilderness
	}
	left_portrait = {
		character = scope:peasant
		animation = fear
	}

	immediate = {
		increase_wounds_effect = { REASON = crocodile }
	}

	option = {
		name = tribal.1302.a
	}
}

#########################################
# Irrigate Oasis						#
# by Linnéa Thimrén						#
#########################################

tribal.1303 = {
	type = character_event
	title = tribal.1303.t
	desc = tribal.1303.desc
	theme = realm
	left_portrait = scope:councillor
	
	trigger = {
		is_available_adult = yes
		government_has_flag = government_is_tribal
		capital_province = { geographical_region = world_africa }
		exists = cp:councillor_steward
		short_term_gold >= medium_gold_value
		NOT = { has_character_flag = had_event_tribal_1301 }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_tribal_1301
			years = 10
		}
		cp:councillor_steward = {
			save_scope_as = councillor
		}
		capital_county = {
			save_scope_as = capital
		}
	}

	option = { #Invest
		name = tribal.1303.a
		scope:capital = {
			add_county_modifier = {
				modifier = irrigated_oasis_modifier
				years = 10
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.75
			}
		}
	}

	option = { #They'll pay to get access!
		name = tribal.1303.b
		scope:capital = {
			add_county_modifier = {
				modifier = guarded_irrigated_oasis_modifier
				years = 10
			}
		}
		remove_treasury_or_gold = medium_treasury_or_gold_value
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.75
			}
		}
	}

	option = { #Leave it
		name = tribal.1303.c
		scope:capital = {
			add_county_modifier = {
				modifier = oasis_modifier
				years = 10
			}
		}
	}
}
