﻿activity_chariot_race = {
	is_shown = {
		highest_held_title_tier >= tier_empire
		is_landed = yes
		culture = { has_cultural_parameter = hosts_chariot_races }
		has_dlc_feature = roads_to_power
		#Every other activity must be blocked until an uncrowned AI crowns themselves
		trigger_if = {
			limit = {
				is_ai = yes
			}
			NOT = {
				has_realm_law = uncrowned
			}
		}
	}

	can_start_showing_failures_only = {
		NOT = { is_activity_type_on_cooldown = activity_chariot_race }
		is_available_adult = yes
	}

	is_valid = {
		scope:host = {
			is_physically_able = yes
			is_landed = yes
		}
		trigger_if = {
			limit = {
				is_current_phase_active = yes
			}
			has_attending_activity_guests = yes
		}
	}

	on_invalidated = {
		# Host becomes unlanded
		if = {
			limit = {
				scope:host = { is_landed = no }
			}
			scope:activity = {
				activity_type = { save_scope_as = activity_type }
			}
			every_attending_character = {
				trigger_event = activity_system.0320
			}
		}
		if = { # No one shows up
			limit = {
				has_attending_activity_guests = no
			}
			scope:activity = {
				activity_type = { save_scope_as = activity_type }
				activity_location = { save_scope_as = location }
			}
			scope:host = { trigger_event = activity_system.0100 }
		}
		chariot_race_remove_variables_effect = yes
	}

	on_host_death = {
		# Make the title heir the new host
		if = {
			limit = { exists = scope:host.primary_title.current_heir }
			scope:host.primary_title.current_heir = { save_scope_as = new_host }
		}
		# Otherwise pass to primary heir
		else = {
			scope:host.primary_heir = { save_scope_as = new_host }
		}

		# If we have a new host, set them
		if = {
			limit = { exists = scope:new_host }
			set_activity_host = scope:new_host
			scope:new_host = {
				trigger_event = { id = activity_system.0080 days = 1 }
			}
		}
	}

	# desc is only shown in debug AI watch window
	ai_will_do = {
		value = 0
		
		# Base
		add = {
			value = 100
			desc = "base"
		}
		
		# Personality
		if = { # Avoids responsibilities
			limit = { has_trait = lazy }
			add = {
				value = -20
				desc = lazy
			}
		}
		if = { # Likes showing off
			limit = { has_trait = arrogant }
			add = {
				value = 20
				desc = arrogant
			}
		}
		else_if = { #
			limit = { has_trait = humble }
			add = {
				value = -10
				desc = humble
			}
		}
		if = { # In it to win it
			limit = { has_trait = ambitious }
			add = {
				value = 20
				desc = ambitious
			}
		}
		if = { # Likes to socialize
			limit = { has_trait = gregarious }
			add = {
				value = 20
				desc = gregarious
			}
		}
		else_if = {
			limit = { has_trait = shy }
			add = {
				value = -15
				desc = shy
			}
		}
		if = {
			limit = { has_trait = reclusive }
			add = {
				value = -25
				desc = reclusive
			}
		}
	}

	ai_check_interval = 60

	max_province_icons = 3

	province_description = {
		triggered_desc = {
			trigger = { this = scope:host.capital_province }
			desc = activity_chariot_race_province_capital
		}
		triggered_desc = {
			trigger = { this = province:496 }
			desc = activity_chariot_race_province_constantinople
		}
	}

	###################
	# PARAMETERS
	###################

	is_single_location = yes

	wait_time_before_start = {
		months = 4
	}

	max_guests = 300

	max_guest_arrival_delay_time = {
		months = 4
	}

	cooldown = {
		years = 10
	}

	province_filter = capital
	ai_province_filter = capital
	ai_will_select_province = 100

	cost = {
		gold = {
			add = {
				add = {
					value = chariot_race_base_cost_value
					desc = chariot_race_base_cost_desc
				}
				if = {
					limit = { employs_court_position = bookmaker_court_position }
					subtract = {
						value = chariot_race_base_cost_value
						multiply = {
							value = 0.1 # Reduces cost by 10% (of the base cost) per level of aptitude
							multiply = court_position:bookmaker_court_position.aptitude:bookmaker_court_position
							add = 0.1 # Since aptitude starts at 0
						}
						desc = bookmaker_court_position
					}
				}
				add = {
					value = chariot_race_base_cost_value
					multiply = activity_cost_scale_by_era
					subtract = chariot_race_base_cost_value
					desc = activity_cost_scale_by_era_desc
				}
				# ep3_emperor_yearly.2060
				if = {
					limit = {
						has_character_flag = constantinople_birthday_flag
					}
					multiply = {
						value = 0.5
						desc = constantinople_birthday_flag_desc
					}
				}
				# roman_restoration.1200
				if = {
					limit = { has_character_flag = half_price_chariot_race_flag }
					multiply = {
						value = 0.5
						desc = half_price_chariot_race_flag_desc
					}
				}
			}
		}
	}

	ui_predicted_cost = {
		gold = {
			# Base Cost
			add = {
				value = chariot_race_base_cost_value
				desc = chariot_race_base_cost_desc
			}
			if = {
				limit = { employs_court_position = bookmaker_court_position }
				subtract = {
					value = chariot_race_base_cost_value
					divide = 10
					desc = bookmaker_court_position
				}
			}
			# Scale by Era
			multiply = {
				value = activity_cost_scale_by_era
				desc = activity_cost_scale_by_era_desc
			}
			# ep3_emperor_yearly.2060
			if = {
				limit = {
					has_character_flag = constantinople_birthday_flag
				}
				multiply = {
					value = 0.5
					desc = constantinople_birthday_flag_desc
				}
			}
		}
	}

	# Guests bring knights & close family
	travel_entourage_selection = {
		weight = {
			value = standard_travel_entourage_additions
			if = {
				limit = {
					OR = {
						has_court_position = charioteer_court_position
						has_any_charioteer_trait = yes
					}
					bannable_serving_diarch_trigger = no
				}
				add = 500
			}
			if = {
				limit = {
					bannable_serving_diarch_trigger = no
					is_landed = no
					OR = {
						is_spouse_of = scope:owner
						is_close_family_of = scope:owner
					}
					is_available = yes
				}
				add = 50
			}
		}

		max = 15
		ai_max = 3
		invite_rule_order = 1
   	}

   	###################
	# OPTIONS
	###################

	options = {
		chariot_option_entertainment = {
			
			chariot_entertainment_bad = {
			
			# desc is only shown in debug AI watch window
				ai_will_do = {
					value = 10
					# Financial preference.
					add = activity_option_likes_cheap_expense_value
				}
				cost = {
					gold = {
						add = {
							desc = chariot_entertainment_bad
							add = {
								value = 20
								desc = chariot_entertainment_bad
							}
							add = {
								value = 20
								multiply = activity_cost_scale_by_era
								subtract = 20
								desc = activity_cost_scale_by_era_desc 
							}
						}
					}
				}
			}
			chariot_entertainment_normal = {
				default = yes
				# desc is only shown in debug AI watch window
				ai_will_do = {
					value = 10
					# Financial preference.
					add = activity_option_likes_middling_expense_value
				}
				cost = {
					gold = {
						add = {
							desc = chariot_entertainment_normal
							add = {
								value = 50
								desc = chariot_entertainment_normal
							}
							add = {
								value = 20
								multiply = activity_cost_scale_by_era
								subtract = 20
								desc = activity_cost_scale_by_era_desc 
							}
						}
					}
				}
			}
			chariot_entertainment_good = {
				# desc is only shown in debug AI watch window
				ai_will_do = {
					value = 10
					# Financial preference.
					add = activity_option_likes_heavy_expense_value
					add = {
						value = ai_greed
						multiply = -0.5
					}
				}
				cost = {
					gold = {
						add = {
							desc = chariot_entertainment_good
							add = {
								value = 100
								desc = chariot_entertainment_good
							}
							add = {
								value = 20
								multiply = activity_cost_scale_by_era
								subtract = 20
								desc = activity_cost_scale_by_era_desc 
							}
						}
					}
				}
			}
		}
	}

   	###################
	# PHASES
	###################
	phases = {
		# Gambling Phase
		chariot_race_gambling = {
			is_predefined = yes
			order = 1

			on_phase_active = {
				if = {
					limit = {
						this = scope:host
					}
					# Add all the charioteers and spectators to guest subsets so we can keep track of them
					gather_charioteers_effect = yes
					scope:activity = {
						every_attending_character = {
							# Pay your entrance fee if you have the money
							if = {
								limit = {
									OR = {
										short_term_gold >= chariot_race_entrance_fee
										is_ai = no
									}
									this != scope:host
								}
								remove_short_term_gold = chariot_race_entrance_fee
							}
							# we add some money to the pot either way to offset the gains in case a bunch of people make good bets
							scope:activity = {
								change_variable = {
									name = chariot_race_pot
									add = prev.chariot_race_entrance_fee
								}
							}
						}
					}
					# Calculate the odds and payout rates for all the competitors 
					calculate_chariot_race_odds_effect = yes
					calculate_chariot_payout_effect = yes

					# Progress the activity
					scope:activity = { progress_activity_phase_after = { months = 1 } }

					# Grab the Bookmaker Court Position or create a character to serve that function
					if = {
						limit = {
							employs_court_position = bookmaker_court_position
						}
						random_court_position_holder = {
							type = bookmaker_court_position
							save_scope_as = bookmaker
						}
					}
					else_if = { # try to pull a pool character
						limit = {
							any_pool_character = {
								province = scope:activity.activity_location
								is_available_ai_adult = yes
								stewardship >= 8
							}
						}
						random_pool_character = {
							province = scope:activity.activity_location
							limit = {
								is_available_ai_adult = yes
								stewardship >= 8
							}
							save_scope_as = bookmaker
						}
					}
					else = { # or just make a character
						create_character = {
							location = scope:activity.activity_location
							template = generic_bookmaker_character
							faith = scope:activity.activity_location.faith
							culture = scope:activity.activity_location.culture
							save_scope_as = bookmaker
						}
					}

					scope:activity = {
						# Send the gambling event to all the spectators
						every_guest_subset = {
							name = spectators
							if = { # Players get the event after a few days, so we know how the AI has bet and can show some basic numbers in the event options
								limit = { is_ai = no }
								trigger_event = {
									id = chariot_race.0100
									days = 1
								}
							}
							else = {
								trigger_event = chariot_race.0100
							}
						}
					}
				}
			}

			on_weekly_pulse = {
				if = {
					limit = {
						this = scope:host
					}
					scope:activity = {
						every_guest_subset = {
							name = spectators
							trigger_event = { on_action = chariot_race_betting_events }
						}
					}
				}
			}
		}
		# Competition Phase
		chariot_race_phase = {
			is_predefined = yes 
			order = 2

			on_enter_phase = {
				if = {
					limit = {
						this = scope:host
					}
					# Choose your speech topic
					trigger_event = chariot_race.0200
					# Progress the activity
					scope:activity = { progress_activity_phase_after = { weeks = 1 } }		
				}
			}

			on_phase_active = {
				# Initialize victory score of the charioteers
				if = {
					limit = { this = scope:host }
					# Race begins, order the candidates based on odds of winning to begin with
					scope:activity = {
						every_guest_subset = {
							name = charioteers
							set_variable = {
								name = chariot_race_victory_score
								value = {
									add = var:odds_win_a
									# add some variance to begin with 
									add = { 1 10 }
								}
							}
						}
						set_variable = {
							name = chariot_race_phase_week
							value = 0
						}
						update_chariot_race_standings_effect = yes
						progress_activity_phase_after = { months = 1 }
					}
				}
				# Fire opening event for everyone letting them know the race has begun
				trigger_event = chariot_race.0250
			}

			on_weekly_pulse = {
				if = {
					limit = { this = scope:host }
					# This on action handles everything occurs on the race track and then fires informative events to spectators who care about the charioteers affected
					# After all that is sorted, it fires chariot_spectator_on_action for spectators that have not yet received an event
					trigger_event = { on_action = chariot_race_on_action }
				}
			}

			on_end = {
				if = {
					limit = {
						this = scope:host
					}
					chariot_race_payout_effect = yes
				}
				trigger_event = chariot_race.0600
			}
		}
		# Conclusion
		chariot_race_phase_ceremony = {
			is_predefined = yes
			order = 3

			on_enter_phase = {
				if = {
					limit = { this = scope:host }
					# No passive state for the ceremony, just jump right into it
					scope:activity = {
						progress_activity_phase_after = { days = 1 }
					}
				}
			}

			on_phase_active = {
				if = {
					limit = { this = scope:host }
					scope:activity = {
						progress_activity_phase_after = { weeks = 1 }
					}
				}
				# Trigger prize event for everyone
				trigger_event = {
					id = chariot_race.0400
					days = 1
				}
			}

			on_end = {
				# Hand out rewards
				if = {
					limit = {
						this = scope:host
					}
					disburse_chariot_race_activity_host_rewards = yes
					# Notification event for host
					trigger_event = chariot_race.0500
					scope:activity = {
						every_guest_subset = {
							name = spectators
							limit = { this != scope:host }
							disburse_chariot_race_activity_spectator_rewards = yes
							# Notification event for spectators
							trigger_event = chariot_race.0501
						}
						every_guest_subset = {
							name = charioteers
							disburse_chariot_race_activity_charioteer_rewards = yes
							# Players can't be charioteers, so we don't need a notification event
						}
					}
				}
			}
		}
	}

	###################
	# GUEST HANDLING
	###################
	guest_invite_rules = {

		defaults = {
			1 = activity_invite_rule_vassals_and_below
			1 = activity_invite_rule_confederates
			1 = activity_invite_rule_tributaries
			1 = activity_invite_rule_charioteers
			2 = activity_invite_rule_friends
			2 = activity_invite_rule_potential_friends
			2 = activity_invite_rule_lovers
			2 = activity_invite_rule_potential_lovers
			2 = activity_invite_rule_close_family
			2 = activity_invite_rule_extended_family
			2 = activity_invite_rule_guests
			1 = activity_invite_rule_landless_adventurers
		}

		rules = {
			# MP 
			3 = activity_invite_mp
		}
	}

	guest_subsets = {
		charioteers
		spectators
	}

	can_be_activity_guest = {
		is_available_adult = yes
		in_diplomatic_range = scope:host
	}

	host_intents = {
		intents = {
			reduce_stress_intent
			increase_influence_intent
			appease_populace_intent
			murder_attendee_intent
			woo_attendee_intent
			befriend_attendee_intent
			spread_legend_intent
			legitimacy_intent
		}
		default = reduce_stress_intent
	}

	guest_intents = {
		intents = { 
			reduce_stress_intent
			increase_influence_intent
			sow_discord_intent
			murder_attendee_intent
			woo_attendee_intent
			befriend_attendee_intent
			spread_legend_intent
		}
		default = reduce_stress_intent
	}

	special_guests = {
		chariot_race_honorary_guest = {
			is_required = no

			can_pick = {
				this != scope:host
				is_healthy = yes
				is_adult = yes
				NOT = { is_spouse_of = scope:host }
				trigger_if = {
					limit = {
						scope:host = { is_ai = yes }
					}
					OR = {
						is_vassal_of = scope:host
						target_is_vassal_or_below = scope:host
						has_relation_friend = scope:host
						has_relation_lover = scope:host
					}
				}
			}
			
			ai_will_do = {
				value = 10
			}
		}
	}

	guest_join_chance = {
		base = 10
		base_activity_modifier = yes

		# Scripted Modifiers
		activity_guest_shared_ai_accept_modifier = yes 
		activity_guest_chariot_race_ai_accept_modifier = yes
	}

	###################
	# ACTIVITY-SPECIFIC PULSES
	###################

	pulse_actions = {
		entries = {
			# Chariot Specific
			apa_cheering_on_competitors
			apa_thunderous_applause
			apa_celebrating_unexpected_overtake
			apa_exchanging_race_commentary
			apa_forging_alliances
			apa_donates_to_the_poor
			
			# Generic
			guest_friendship
			guest_insulted
			host_gains_diplo_xp
			host_gains_steward_xp
			host_gains_intrigue_xp
			contact_network
		}
		chance_of_no_event = 2
	}

	on_start = {
		# Inititalizine the pot
		set_variable = {
			name = chariot_race_pot
			value = 0
		}
		# Opening event/invalidation if not enough people are present
		scope:host = {
			if = {
				limit = { has_character_flag = half_price_chariot_race_flag }
				remove_character_flag = half_price_chariot_race_flag
			}
			trigger_event = {
				on_action = chariot_race_opening_on_action
				days = 1
			}
		}
	}

	on_enter_passive_state = {
		trigger_event = chariot_race.0001
	}

	on_enter_active_state = {
		surveyor_no_stone_unturned_perk_effect = yes
	}

	on_complete = {
		# Distribute prizes
		if = {
			limit = {
				this = scope:host
			}

			save_scope_as = host
			show_as_tooltip = { disburse_chariot_race_activity_host_rewards = yes }

			scope:activity = {
				activity_location = { save_scope_as = hippodrome }
				# variable deletion
				chariot_race_remove_variables_effect = yes
			}

			if = {
				limit = {
					employs_court_position = bookmaker_court_position
					court_position:bookmaker_court_position = { has_character_flag = bookmaker_cooking_the_books }
					NOT = { has_character_flag = cook_the_books_cooldown_flag }
				}
				add_character_flag = {
					flag = cook_the_books_cooldown_flag
					years = 9 # one less year than the cooldown to host the activity
				}
			}
		}
		else = {
			show_as_tooltip = { disburse_chariot_race_activity_spectator_rewards = yes }
		}
	}

	###################
	# GRAPHICS
	###################

	### Plugin widgets
	activity_window_widgets = {
		chariot_race_progress_to_victory_widget = "window_activity_contestants_right_bar_container"
		chariot_race_pivotal_moment_widget = "widget_activity_pivotal_moment_event_window"
	}

	### Backgrounds

	# Travel
	background = { # Bridge
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				is_riverside_province = yes
				geographical_region = world_europe
				OR = {
					terrain = farmlands
					terrain = plains
					terrain = mountains
					terrain = hills
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_bridge.dds"
		environment = "environment_travel_bridge"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #Rice Fields - If we have Paddy fields AND/or terraced hills
	#This goes before other terrain since it can override in many different terrains if built
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				OR = {
					terrain = terraced_hills
					has_building_or_higher = paddy_fields_01
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/tgp_rice_fields.dds"
		environment = "environment_tgp_rice_fields"
		ambience = "event:/DLC/EP4/SFX/Events/Event_Backgrounds/tgp_rice_fields"
	}

	background = { #Farmlands - East Asia
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				culture = { has_graphical_east_asia_culture_group_trigger = yes }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/tgp_farm_asia.dds"
		environment = "environment_tgp_farm_asia"
		ambience = "event:/DLC/EP4/SFX/Events/Event_Backgrounds/tgp_farm_asia"
	}
	
	background = { # Farmland, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_farm.dds"
		environment = "environment_travel_farmlands"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { # Farmland, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/farms.dds"
		environment = "environment_event_farms"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #Desert, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_desert.dds"
		environment = "environment_travel_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}
	background = { #Desert, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/desert.dds"
		environment = "environment_event_bp1_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #forest snowy
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location ?= { hunt_snowy_forest_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_hunt_snowy_forest.dds"
		environment = "environment_hunt_snowy_forest"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #forest_pine
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_forest_pine_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest_pine.dds"
		environment = "environment_event_forest_pine"
		ambience = "event:/SFX/Events/Backgrounds/coniferous_forest_day"
	}

	background = { #forest
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_forest_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest.dds"
		environment = "environment_event_forest"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #mountains, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
		environment = "environment_travel_mountain_settlement"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}
	background = { #mountains, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/mountains.dds"
		environment = "environment_event_mountains"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #steppe, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_steppe.dds"
		environment = "environment_travel_steppe_settlement"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}
	background = { #steppe, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/steppe.dds"
		environment = "environment_event_steppe"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}

	background = { #drylands (formerly desert)
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_drylands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/drylands.dds"
		environment = "environment_event_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #wetlands
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_wetlands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_wetlands.dds"
		environment = "environment_event_bp1_wetlands" 
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #jungle
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_jungle_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_jungle.dds"
		environment = "environment_event_bp1_jungle"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #plains, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_plains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #plains, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_plains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_plains.dds"
		environment = "environment_event_bp1_plains"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #hills, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_hills_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #hills, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_hills_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_hills.dds"
		environment = "environment_event_bp1_hills"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #sea
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				is_sea_province = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/fp1_ocean.dds"
		environment = "environment_event_fp1_ocean"
		ambience = "event:/DLC/FP1/SFX/Events/event_ocean_longship"
	}
	# End Travel
	background = {
		texture = "gfx/interface/illustrations/event_scenes/ep3_hippodrome_chariot_race.dds"
		environment = "environment_ep3_chariot_race"
		ambience = "event:/DLC/FP2/SFX/Events/courtyard"
	}

	window_characters = {
		
		guest = {
			camera = camera_event_center
			
			effect = {
				if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 2
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 2
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 2
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 2
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character = { has_character_flag = successful_bet } }
					animation = { dancing }
				}
				triggered_animation = {
					trigger = {
						scope:character = { has_trait = shy }
					}
					animation = { stress }
				}
				triggered_animation = {
					trigger = {
						always = yes
					}
					animation = { laugh storyteller flirtation_left throne_room_conversation_2 betting }
				}
				animation = personality_compassionate
			}
		}

		guest = {
			#camera = camera_event_right
			camera = camera_event_center

			effect = {
				if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						exists = scope:player
						scope:player = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
						}
					}
					scope:player ?= { add_to_list = characters }
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						exists = scope:host.intent_target
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							this = scope:host.intent_target
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							this = scope:host.intent_target
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							OR = {
								has_relation_lover = scope:host
								has_relation_friend = scope:host
							}
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							OR = {
								has_relation_lover = scope:host
								has_relation_friend = scope:host
							}
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_consort_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_consort_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character = { has_character_flag = successful_bet } }
					animation = { dancing }
				}
				triggered_animation = {
					trigger = {
						exists = scope:host.intent_target
						scope:host = {
							has_activity_intent = woo_attendee_intent
						}
						scope:character = scope:host.intent_target
					}
					animation = { love flirtation }
				}
				triggered_animation = {
					trigger = {
						exists = scope:host.intent_target
						scope:host = {
							has_activity_intent = murder_attendee_intent
						}
						scope:character = scope:host.intent_target
					}
					animation = { dismissal worry paranoia }
				}
				triggered_animation = {
					trigger = {
						scope:host = { has_activity_intent = increase_influence_intent }
					}
					animation = { happiness throne_room_conversation_3 throne_room_conversation_1 debating }
				}
				#Fallback
				animation = personality_honorable
			}
		}
		
		host = {
			camera = camera_event_center
			
			effect = {
				if = {
					limit = {
						OR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					scope:host = {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character.location = { is_sea_province = yes }
					}
					animation = survey
				}
				triggered_animation = {
					trigger = { scope:character = { has_character_flag = successful_bet } }
					animation = { throne_room_applaud_1 }
				}
				triggered_animation = {
					trigger = {
						exists = scope:activity.special_guest:chariot_race_honorary_guest.location
						NOT = {
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
					}
					animation = { boredom }
				}
				triggered_animation = {
					trigger = {
						exists = scope:host.intent_target
						scope:host = {
							is_male = yes
							has_activity_intent = befriend_attendee_intent
						}
						scope:host.intent_target.location = scope:activity.activity_location
					}
					animation = { personality_forgiving personality_compassionate }
				}
				triggered_animation = {
					trigger = {
						exists = scope:host.intent_target
						scope:host = {
							is_male = yes
							has_activity_intent = woo_attendee_intent
						}
						scope:host.intent_target.location = scope:activity.activity_location
					}
					animation = { wedding_groom_right }
				}
				triggered_animation = {
					trigger = {
						exists = scope:host.intent_target
						scope:host = {
							is_female = yes
							has_activity_intent = woo_attendee_intent
						}
						scope:host.intent_target.location = scope:activity.activity_location
					}
					animation = { reception_bride_right }
				}
				triggered_animation = {
					trigger = {
						scope:host = {
							has_activity_intent = increase_influence_intent
							OR = {
								religion = religion:eastern_orthodox_religion
								religion = religion:catholic_religion
								religion = religion:protestant_religion
							}
						}
					}
					animation = { acknowledging scepter } # anims use crucifix scepter
				}
				triggered_animation = {
					trigger = {
						scope:host = { has_activity_intent = increase_influence_intent }
					}
					animation = { toast_goblet personality_honorable happiness }
				}
				#Fallback
				animation = personality_honorable
			}
		}
		
		travel_host = {
			camera = camera_event_horse_left
			
			effect = {
				if = {
					limit = {
						NOR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					scope:host = {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character.location = { is_sea_province = yes }
					}
					animation = { idle }
				}
				triggered_animation = {
					trigger = { scope:character = { has_trait = impatient } }
					animation = { jockey_gallop }
				}
				animation = jockey_walk
			}
		}

		chariot_race_honorary_guest_traveling = {
			camera = camera_event_horse_left
			
			effect = {
				if = {
					limit = {
						scope:activity.special_guest:chariot_race_honorary_guest.involved_activity ?= scope:activity
						NOR = {
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= { is_sea_province = yes }
						}
					}
					special_guest:chariot_race_honorary_guest ?= {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character = { has_trait = impatient } }
					animation = { jockey_gallop }
				}
				animation = jockey_walk
			}
		}

		chariot_race_honorary_guest = {
			camera = camera_event_right
			
			effect = {
				if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= { is_sea_province = yes }
						}
					}
					special_guest:chariot_race_honorary_guest ?= {
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character.location = { is_sea_province = yes } }
					animation = { idle }
				}
				triggered_animation = {
					trigger = { scope:character = { has_character_flag = successful_bet } }
					animation = { throne_room_applaud_1 }
				}
				triggered_animation = {
					trigger = {
						always = yes
					}
					animation = { ecstasy wedding_priest chaplain personality_bold wedding_drunk }
				}
			}
		}
		
		guest = {
			camera = camera_event_right
			
			effect = {
				if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 3
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_councillor_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 3
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_duchy
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 3
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							highest_held_title_tier >= tier_county
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
						any_attending_character = {
							count >= 3
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
							is_close_or_extended_family_of = scope:host
						}
						add_to_list = characters
					}
				}
				else_if = {
					limit = {
						scope:host.location = scope:activity.activity_location
						OR = {
							NOT = { exists = scope:activity.special_guest:chariot_race_honorary_guest }
							scope:activity.special_guest:chariot_race_honorary_guest.location ?= scope:activity.activity_location
						}
					}
					every_attending_character = {
						limit = {
							location = scope:activity.activity_location
							NOR = {
								this = scope:host
								scope:activity.special_guest:chariot_race_honorary_guest ?= this
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character = { has_character_flag = successful_bet } }
					animation = { dancing }
				}
				triggered_animation = {
					trigger = {
						scope:character = { has_trait = shy }
					}
					animation = paranoia
				}
				triggered_animation = {
					trigger = { always = yes }
					animation = { drink eavesdrop drink_goblet }
				}
				animation = personality_bold
			}
		}
	}
}
