﻿namespace = chariot_race_ongoing_jp

scripted_trigger chariot_race_interested_trigger = {
	OR = {
		exists = var:wager_target # Interested in bet outcome
		exists = var:wager_team # Interested in bet outcome
		employs_court_position = charioteer_court_position
		ai_sociability > medium_positive_ai_value
		ai_energy < low_positive_ai_value
	}
}

scripted_trigger chariot_race_bored_trigger = {
	OR = {
		ai_sociability < low_positive_ai_value
		ai_energy >= medium_positive_ai_value
	}
}

# Try to bond with your intent_target
# by Joe Parkin
chariot_race_ongoing_jp.0100 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0100.t
	desc = {
		desc = chariot_race_ongoing_jp.0100.desc.intro
		first_valid = {
			# Emperor
			triggered_desc = {
				trigger = { scope:intent_target = scope:activity.activity_host }
				desc = chariot_race_ongoing_jp.0100.desc.liege
			}
			# Important courtier, in your booth
			triggered_desc = {
				trigger = {
					this = scope:activity.activity_host
					scope:intent_target = {
						OR = {
							is_close_family_of = root.top_liege
							is_spouse_of = root.top_liege
						}
					}
				}
				desc = chariot_race_ongoing_jp.0100.desc.important_liege
			}
			# Important courtier, in emperor's booth
			triggered_desc = {
				trigger = {
					scope:intent_target = {
						OR = {
							is_close_family_of = root.top_liege
							is_spouse_of = root.top_liege
						}
					}
				}
				desc = chariot_race_ongoing_jp.0100.desc.important
			}
			# King
			triggered_desc = {
				trigger = {
					scope:intent_target = {
						is_landed = yes
						highest_held_title_tier >= tier_kingdom
					}
				}
				desc = chariot_race_ongoing_jp.0100.desc.king
			}
			# Duke
			triggered_desc = {
				trigger = {
					scope:intent_target = {
						is_landed = yes
						highest_held_title_tier >= tier_duchy
					}
				}
				desc = chariot_race_ongoing_jp.0100.desc.duke
			}
			# Count
			triggered_desc = {
				trigger = {
					scope:intent_target = {
						is_landed = yes
						highest_held_title_tier >= tier_county
					}
				}
				desc = chariot_race_ongoing_jp.0100.desc.count
			}
			# Unimportant
			desc = chariot_race_ongoing_jp.0100.desc.courtier
		}
		first_valid = {
			# Especially interested.
			triggered_desc = {
				trigger = {
					scope:intent_target = { chariot_race_interested_trigger = yes }
				}
				desc = {
					desc = chariot_race_ongoing_jp.0100.desc.target_personality.fan
					triggered_desc = {
						trigger = { exists = scope:intent_target.var:wager_target }
						desc = chariot_race_ongoing_jp.0100.desc.target_personality.wager
					}
				}
			}
			# Not interested.
			triggered_desc = {
				trigger = {
					scope:intent_target = { chariot_race_bored_trigger = yes }
				}
				desc = chariot_race_ongoing_jp.0100.desc.target_personality.bored
			}
			# Fallback
			desc = chariot_race_ongoing_jp.0100.desc.target_personality.fallback
		}
		desc = chariot_race_ongoing_jp.0100.desc
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:intent_target
		triggered_animation = {
			trigger = { chariot_race_interested_trigger = yes }
			animation = stress
		}
		triggered_animation = {
			trigger = { chariot_race_bored_trigger = yes }
			animation = boredom
		}
		animation = happiness
	}

	cooldown = { years = 1 }

	trigger = {
		has_activity_intent = befriend_attendee_intent
		intent_target ?= {
			is_alive = yes
			NOR = {
				has_relation_friend = root
				this = root
			}
			scope:activity = {
				any_guest_subset = {
					name = spectators
					this = root.intent_target
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		intent_target = { save_scope_as = intent_target }
	}
	
	option = { # Try to bond
		name = {
			trigger = {
				exists = var:wager_target
				exists = scope:intent_target.var:wager_target
				exists = scope:intent_target.var:wager_team
			}
			text = chariot_race_ongoing_jp.0100.b.wager
		}
		name = {
			trigger = {
				scope:intent_target = {
					chariot_race_interested_trigger = yes
					NOT = { exists = var:wager_target }
				}
			}
			text = chariot_race_ongoing_jp.0100.b.fan
		}
		name = {
			trigger = {
				scope:intent_target = { chariot_race_bored_trigger = yes }
			}
			text = chariot_race_ongoing_jp.0100.b.bored
		}
		name = {
			trigger = {
				scope:intent_target = {
					chariot_race_interested_trigger = no
					chariot_race_bored_trigger = no
				}
			}
			text = chariot_race_ongoing_jp.0100.b
		}
		duel = {
			skill = diplomacy
			target = scope:intent_target
			15 = { # They are convinced
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					AND = {
						chariot_race_interested_trigger = yes
						scope:intent_target = { chariot_race_interested_trigger = yes }
					}
					add = 10
				}
				modifier = {
					exists = scope:intent_target.var:wager_team
					var:wager_team ?= scope:intent_target.var:wager_team
					add = 10
				}
				modifier = {
					AND = {
						chariot_race_bored_trigger = yes
						scope:intent_target = { chariot_race_bored_trigger = yes }
					}
					add = 10
				}
				min = 5
				desc = chariot_race_ongoing_jp.0100.b.tt.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.b.tt.success
					left_icon = scope:intent_target
					progress_towards_friend_effect = {
						REASON = friend_chariot_convincing_display
						CHARACTER = scope:intent_target
						OPINION = default_friend_opinion
					}
				}
			}
			50 = { # They are indifferent
				desc = chariot_race_ongoing_jp.0100.b.tt.neutral
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.b.tt.neutral
					left_icon = scope:intent_target
				}
			}
			5 = { # They are repelled
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					AND = {
						chariot_race_interested_trigger = yes
						scope:intent_target = { chariot_race_bored_trigger = yes }
					}
					add = 5
				}
				modifier = {
					AND = {
						chariot_race_bored_trigger = yes
						scope:intent_target = { chariot_race_interested_trigger = yes }
					}
					add = 5
				}
				min = 5
				desc = chariot_race_ongoing_jp.0100.b.tt.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.b.tt.failure
					left_icon = scope:intent_target
					reverse_add_opinion = {
						target = scope:intent_target
						modifier = contempt_opinion
						opinion = -10
					}
				}
			}
		}
		if = {
			limit = {
				OR = {
					AND = {
						chariot_race_interested_trigger = yes
						scope:intent_target = { chariot_race_bored_trigger = yes }
					}
					AND = {
						chariot_race_bored_trigger = yes
						scope:intent_target = { chariot_race_interested_trigger = yes }
					}
				}
			}
			stress_impact = {
				honest = minor_stress_impact_gain
				shy = minor_stress_impact_gain
				gregarious = miniscule_stress_impact_loss
			}
		}
		else = {
			stress_impact = {
				shy = miniscule_stress_impact_gain
				gregarious = miniscule_stress_impact_loss
			}
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_boldness = 0.5
				ai_vengefulness = 0.25
				ai_sociability = -0.25
			}
		}
	}
	
	option = { # Invite into your booth/stand
		name = chariot_race_ongoing_jp.0100.d
		flavor = {
			triggered_desc = {
				trigger = { this = scope:activity.activity_host }
				desc = chariot_race_ongoing_jp.0100.d.host_flavor
			}
		}
		trigger = {
			scope:intent_target = {
				# Kathisma is already the best seat
				custom_tooltip = {
					text = chariot_race_ongoing_jp.0100.d.best.tt
					NOR = {
						this = scope:activity.activity_host
						is_close_family_of = scope:activity.activity_host
						is_spouse_of = scope:activity.activity_host
					}
				}
				# Your seat must be better than theirs
				custom_tooltip = {
					text = chariot_race_ongoing_jp.0100.d.better.tt
					highest_held_title_tier < root.highest_held_title_tier
				}
			}
		}
		show_as_unavailable = { always = yes }
		# You lose influence with rest of court, they gain influence from the optics
		if = {
			limit = { this = scope:activity.activity_host }
			change_influence = minor_influence_loss
			scope:intent_target = { change_influence = minor_influence_gain }
		}
		else = {
			change_influence = miniscule_influence_loss
			scope:intent_target = { change_influence = miniscule_influence_gain }
		}
		random_list = {
			25 = {
				trigger = { this = scope:activity.activity_host }
				modifier = {
					scope:intent_target = { has_trait = ambitious }
					add = 5
				}
				modifier = {
					scope:intent_target = { has_trait = arrogant }
					add = 5
				}
				min = 5
				desc = chariot_race_ongoing_jp.0100.d.tt.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.d.tt.success
					left_icon = scope:intent_target
					set_relation_friend = {
						target = scope:intent_target
						reason = friend_chariot_invited_to_join
						province = scope:activity.activity_location
					}
				}
			}
			25 = {
				desc = chariot_race_ongoing_jp.0100.d.tt.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.d.tt.partial_success
					left_icon = scope:intent_target
					progress_towards_friend_effect = {
						REASON = friend_chariot_invited_to_join
						CHARACTER = scope:intent_target
						OPINION = default_friend_opinion
					}
				}
			}
			10 = {
				modifier = {
					scope:intent_target = { has_trait = humble }
					add = 5
				}
				modifier = {
					scope:intent_target = { has_trait = shy }
					add = 10
				}
				min = 1
				desc = chariot_race_ongoing_jp.0100.d.tt.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.d.tt.failure
					left_icon = scope:intent_target
					reverse_add_opinion = {
						target = scope:intent_target
						modifier = friendliness_opinion
						opinion = 10
					}
				}
			}
			5 = {
				trigger = {
					reverse_opinion = {
						target = scope:intent_target
						value < 5
					}
				}
				desc = chariot_race_ongoing_jp.0100.d.tt.critical_failure
				min = 1
				opinion_modifier = {
					who = scope:intent_target
					opinion_target = root
					multiplier = -0.1
				}
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0100.d.tt.critical_failure
					left_icon = scope:intent_target
					reverse_add_opinion = {
						target = scope:intent_target
						modifier = unfriendly_opinion
						opinion = -10
					}
				}
			}
		}

		stress_impact = {
			humble = miniscule_stress_impact_loss
			compassionate = miniscule_stress_impact_loss
			shy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 1
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -1
			}
		}
	}
	
	option = { # Nod
		name = {
			trigger = { this != scope:activity.activity_host }
			text = chariot_race_ongoing_jp.0100.e
		}
		name = {
			trigger = { this = scope:activity.activity_host }
			text = chariot_race_ongoing_jp.0100.e.host
		}
		if = {
			limit = {
				tier_difference = { target = scope:intent_target value <= 1 }
			}
			reverse_add_opinion = {
				target = scope:intent_target
				modifier = flattered_opinion
				opinion = 3
			}
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:intent_target value = 2 }
			}
			reverse_add_opinion = {
				target = scope:intent_target
				modifier = flattered_opinion
				opinion = 6
			}
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:intent_target value = 3 }
			}
			reverse_add_opinion = {
				target = scope:intent_target
				modifier = flattered_opinion
				opinion = 9
			}
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:intent_target value = 4 }
			}
			reverse_add_opinion = {
				target = scope:intent_target
				modifier = flattered_opinion
				opinion = 12
			}
		}
		else_if = {
			limit = {
				OR = {
					tier_difference = { target = scope:intent_target value = 5 }
					root = scope:activity.activity_host
				}
			}
			reverse_add_opinion = {
				target = scope:intent_target
				modifier = flattered_opinion
				opinion = 15
			}
		}
		ai_chance = {
			base = 0.5
			ai_value_modifier = {
				ai_boldness = -0.5
			}
		}
	}
}

scripted_trigger chariot_kathisma_mingle_trigger = { # People who be sitting in the imperial box
	OR = {
		scope:activity.activity_host ?= this
		scope:activity.special_guest:chariot_race_honorary_guest ?= this
		is_close_family_of = scope:activity.activity_host
		is_spouse_of = scope:activity.activity_host
		has_character_flag = kathisma_access
	}
}

scripted_trigger chariot_tier_mingle_trigger = {
	OR = {
		is_landed = yes
		is_courtier = yes
	}
	OR = {
		tier_difference = {
			target = root
			value <= 1
		}
		tier_difference = {
			target = root
			value >= -1
		}
	}
}

scripted_trigger chariot_already_known_mingle_trigger = {
	OR = {
		has_any_scripted_relation = root
		any_child = { this = root }
		any_parent = { this = root }
		is_spouse_of = root
		is_vassal_or_below_of = root
		is_courtier_of = root
	}
}

scripted_trigger chariot_tradeable_secret_trigger = {
	NOR = {
		secret_owner = $OTHER$
		secret_target ?= $OTHER$
	}
	OR = {
		secret_owner.top_liege = $OTHER$.top_liege
		secret_target.top_liege ?= $OTHER$.top_liege
	}
}

# Mingle with other attendees outside the kathisma
# by Joe Parkin
chariot_race_ongoing_jp.0200 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0200.t
	desc = {
		desc = chariot_race_ongoing_jp.0200.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					is_landed = yes
					scope:other = { is_landed = yes }
					tier_difference = { target = scope:other value = 0 }
				}
				desc = chariot_race_ongoing_jp.0200.desc.same_rank_ruler
			}
			triggered_desc = {
				trigger = {
					is_landed = no
					scope:other = { is_landed = no }
				}
				desc = chariot_race_ongoing_jp.0200.desc.same_rank_courtier
			}
			triggered_desc = {
				trigger = {
					scope:other = { is_landed = yes }
					tier_difference = { target = scope:other value >= 1 }
				}
				desc = chariot_race_ongoing_jp.0200.desc.higher_rank
			}
			triggered_desc = {
				trigger = {
					scope:other = { is_landed = yes }
					tier_difference = { target = scope:other value <= -1 }
				}
				desc = chariot_race_ongoing_jp.0200.desc.lower_rank
			}
			desc = chariot_race_ongoing_jp.0200.desc.lower_rank_courtier
		}
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:other
		animation = happiness
	}

	cooldown = { years = 1 }

	trigger = {
		chariot_kathisma_mingle_trigger = no
		scope:activity = {
			any_guest_subset = {
				name = spectators
				this != root
				chariot_kathisma_mingle_trigger = no
				chariot_tier_mingle_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = spectators
				limit = { # Prefer intent, same tier and non-known
					this != root
					AND = {
						root = {
							OR = {
								has_activity_intent = befriend_attendee_intent
								has_activity_intent = woo_attendee_intent
							}
							this = root.intent_target
						}
					}
					NOT = { has_relation_friend = root }
					chariot_kathisma_mingle_trigger = no
					chariot_already_known_mingle_trigger = no
					tier_difference = {
						target = root
						value = 0
					}
				}
				alternative_limit = { # Prefer same tier and non-known
					this != root
					chariot_kathisma_mingle_trigger = no
					chariot_already_known_mingle_trigger = no
					tier_difference = {
						target = root
						value = 0
					}
				}
				alternative_limit = { # Prefer intent and non-known
					this != root
					AND = {
						root = {
							OR = {
								has_activity_intent = befriend_attendee_intent
								has_activity_intent = woo_attendee_intent
							}
							this = root.intent_target
						}
					}
					NOT = { has_relation_friend = root }
					chariot_kathisma_mingle_trigger = no
					chariot_already_known_mingle_trigger = no
					chariot_tier_mingle_trigger = yes
				}
				alternative_limit = { # Prefer non-known
					this != root
					chariot_kathisma_mingle_trigger = no
					chariot_already_known_mingle_trigger = no
					chariot_tier_mingle_trigger = yes
				}
				alternative_limit = { # Prefer non-known
					this != root
					chariot_kathisma_mingle_trigger = no
					chariot_tier_mingle_trigger = yes
				}
				weight = {
					base = 1
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				}
				save_scope_as = other
			}
		}
		if = { # Only trade secrets if you can't recruit
			limit = {
				NAND = {
					is_landed = yes
					scope:other = {
						is_landed = no
						is_ruler = no
					}
					NOT = { intent_target ?= scope:other }
				}
			}
			random_known_secret = {
				limit = {
					NOT = { is_known_by = scope:other }
					chariot_tradeable_secret_trigger = { OTHER = scope:other }
				}
				alternative_limit = {
					chariot_tradeable_secret_trigger = { OTHER = root }
				}
				weight = {
					base = 1
					modifier = {
						add = 25
						secret_owner = {
							is_of_minor_interest_trigger = { CHARACTER = root }
						}
					}
					modifier = {
						add = 50
						secret_owner = {
							is_of_major_interest_trigger = { CHARACTER = root }
						}
					}
				}
				save_scope_as = given_secret
			}
			scope:other = {
				random_known_secret = {
					limit = {
						NOT = { is_known_by = scope:other }
						chariot_tradeable_secret_trigger = { OTHER = scope:other }
					}
					alternative_limit = {
						chariot_tradeable_secret_trigger = { OTHER = root }
					}
					weight = {
						base = 1
						modifier = {
							add = 25
							secret_owner = {
								is_of_minor_interest_trigger = { CHARACTER = root }
							}
						}
						modifier = {
							add = 50
							secret_owner = {
								is_of_major_interest_trigger = { CHARACTER = root }
							}
						}
					}
					save_scope_as = received_secret
				}
			}
		}
	}
	
	option = { # Mingle
		name = chariot_race_ongoing_jp.0200.a
		if = {
			limit = {
				tier_difference = { target = scope:other value >= 1 }
			}
			change_influence = miniscule_influence_gain
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:other value <= -1 }
			}
			change_influence = medium_influence_gain
		}
		else = { change_influence = 15 }
		scope:other = {
			if = {
				limit = {
					tier_difference = { target = root value >= 1 }
				}
				change_influence = miniscule_influence_gain
			}
			else_if = {
				limit = {
					tier_difference = { target = root value <= -1 }
				}
				change_influence = medium_influence_gain
			}
			else = { change_influence = 15 }
		}
		reverse_add_opinion = {
			target = scope:other
			modifier = friendliness_opinion
			opinion = 10
		}
		stress_impact = {
			shy = miniscule_stress_impact_gain
			reclusive = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
		}
	}

	option = { # Befriend
		name = chariot_race_ongoing_jp.0200.b
		trigger = {
			has_activity_intent = befriend_attendee_intent
			intent_target ?= scope:other
			NOT = { has_relation_friend = scope:other }
		}
		custom_tooltip = available_because_intent_tt
		add_internal_flag = special
		change_influence = minor_influence_loss
		duel = {
			target = scope:other
			skill = diplomacy
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value >= 1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.b.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.success
					left_icon = scope:other
					progress_towards_friend_effect = {
						REASON = friend_chariot_mingling
						CHARACTER = scope:other
						OPINION = 30
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = chariot_race_ongoing_jp.0200.b.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.partial_success
					left_icon = scope:other
					reverse_add_opinion = {
						target = scope:other
						modifier = friendliness_opinion
						opinion = 15
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value <= -1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.b.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.failure
					left_icon = scope:other
				}
			}
		}
		stress_impact = {
			arrogant = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Compliment
		name = chariot_race_ongoing_jp.0200.c
		trigger = {
			has_activity_intent = woo_attendee_intent
			intent_target ?= scope:other
		}
		custom_tooltip = available_because_intent_tt
		add_internal_flag = special
		change_influence = minor_influence_loss
		duel = {
			target = scope:other
			skill = intrigue
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value >= 1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.c.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.success
					left_icon = scope:other
					progress_towards_lover_effect = {
						REASON = lover_chariot_mingling
						CHARACTER = scope:other
						OPINION = 30
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = chariot_race_ongoing_jp.0200.c.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.partial_success
					left_icon = scope:other
					reverse_add_opinion = {
						target = scope:other
						modifier = friendliness_opinion
						opinion = 15
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value <= -1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.c.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.failure
					left_icon = scope:other
				}
			}
		}
		stress_impact = {
			chaste = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Offer small loan
		name = chariot_race_ongoing_jp.0200.d
		trigger = {
			custom_tooltip = {
				text = chariot_race_ongoing_jp.0200.d.tt
				tier_difference = { target = scope:other value >= 0 }
			}
		}
		show_as_unavailable = {
			NOT = {
				tier_difference = { target = scope:other value <= -1 }
			}
		}
		pay_short_term_gold = {
			target = scope:other
			gold = minor_gold_value
		}
		if = {
			limit = {
				tier_difference = { target = scope:other value >= 1 }
			}
			change_influence = miniscule_influence_gain
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:other value <= -1 }
			}
			change_influence = medium_influence_gain
		}
		else = { change_influence = 15 }
		stress_impact = {
			greedy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}

	option = { # Request small loan
		name = chariot_race_ongoing_jp.0200.e
		trigger = {
			tier_difference = { target = scope:other value <= -1 }
		}
		scope:other = {
			pay_short_term_gold = {
				target = root
				gold = scope:other.minor_gold_value
			}
			change_influence = minor_influence_gain
		}
		stress_impact = {
			arrogant = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Trade secrets
		name = chariot_race_ongoing_jp.0200.f
		trigger = { exists = scope:given_secret }
		custom_tooltip = chariot_race_ongoing_jp.0200.f.available_tt
		scope:given_secret = { reveal_to = scope:other }
		custom_tooltip = chariot_race_ongoing_jp.0200.f.tt
		hidden_effect = {
			duel = {
				target = scope:other
				skill = intrigue
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					modifier = {
						NOT = { exists = scope:received_secret }
						factor = 0
					}
					send_interface_toast = {
						title = chariot_race_ongoing_jp.0200.f.success
						left_icon = scope:other
						scope:received_secret ?= { reveal_to = root }
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					send_interface_toast = {
						title = chariot_race_ongoing_jp.0200.f.failure
						left_icon = scope:other
					}
				}
			}
		}
		stress_impact = {
			honest = miniscule_stress_impact_gain
			confider = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { # Recruit
		name = chariot_race_ongoing_jp.0200.g
		trigger = {
			is_landed = yes
			scope:other = {
				is_landed = no
				is_ruler = no
			}
			NOR = {
				intent_target ?= scope:other
				has_relation_rival = scope:other
			}
		}
		pay_short_term_gold = {
			target = scope:other
			gold = medium_gold_value
		}
		add_courtier = scope:other
		scope:other = { change_influence = minor_influence_gain }
		stress_impact = {
			greedy = miniscule_stress_impact_gain
			callous = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
			modifier = {
				factor = 0
				scope:other.employer = { is_ai = no }
			}
		}
	}

	option = { # Snub
		name = chariot_race_ongoing_jp.0200.h
		if = {
			limit = {
				tier_difference = { target = scope:other value >= 1 }
			}
			add_prestige = miniscule_prestige_gain
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:other value <= -1 }
			}
			add_prestige = medium_prestige_gain
		}
		else = { add_prestige = minor_prestige_gain }
		reverse_add_opinion = {
			target = scope:other
			modifier = unfriendly_opinion
			opinion = -10
		}
		stress_impact = {
			gregarious = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 15
			ai_value_modifier = { 
				ai_sociability = -0.5
			}
		}
	}
}

# Mingle with other attendees inside the kathisma
# by Joe Parkin
chariot_race_ongoing_jp.0201 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0201.t
	desc = {
		desc = chariot_race_ongoing_jp.0201.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { this = scope:activity.activity_host }
				desc = chariot_race_ongoing_jp.0201.desc.emperor
			}
			triggered_desc = {
				trigger = { this = scope:activity.activity_host }
				desc = chariot_race_ongoing_jp.0201.desc.other_emperor
			}
			desc = chariot_race_ongoing_jp.0201.desc.other
		}
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:other
		animation = happiness
	}

	cooldown = { years = 1 }

	trigger = {
		chariot_kathisma_mingle_trigger = yes
		scope:activity = {
			any_guest_subset = {
				name = spectators
				this != root
				chariot_kathisma_mingle_trigger = yes
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:activity = {
			random_guest_subset = {
				name = spectators
				limit = { # Prefer landed & non-known
					is_landed = yes
					this != root
					chariot_already_known_mingle_trigger = no
					chariot_kathisma_mingle_trigger = yes
				}
				alternative_limit = { # Prefer non-known
					this != root
					chariot_already_known_mingle_trigger = no
					chariot_kathisma_mingle_trigger = yes
				}
				alternative_limit = { # Fallback
					this != root
					chariot_kathisma_mingle_trigger = yes
				}
				weight = {
					base = 1
					is_of_major_interest_to_weight_up_modifier = { CHARACTER = root }
					is_of_minor_interest_to_weight_up_modifier = { CHARACTER = root }
				}
				save_scope_as = other
			}
		}
		random_known_secret = {
			limit = {
				NOT = { is_known_by = scope:other }
				chariot_tradeable_secret_trigger = { OTHER = scope:other }
			}
			alternative_limit = {
				chariot_tradeable_secret_trigger = { OTHER = root }
			}
			save_scope_as = given_secret
		}
		scope:other = {
			random_known_secret = {
				limit = {
					NOT = { is_known_by = scope:other }
					chariot_tradeable_secret_trigger = { OTHER = scope:other }
				}
				alternative_limit = {
					chariot_tradeable_secret_trigger = { OTHER = root }
				}
				save_scope_as = received_secret
			}
		}
	}
	
	option = { # Chatter
		name = chariot_race_ongoing_jp.0201.a
		if = {
			limit = {
				tier_difference = { target = scope:other value >= 1 }
			}
			change_influence = miniscule_influence_gain
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:other value <= -1 }
			}
			change_influence = medium_influence_gain
		}
		else = { change_influence = 15 }
		scope:other = {
			if = {
				limit = {
					tier_difference = { target = root value >= 1 }
				}
				change_influence = miniscule_influence_gain
			}
			else_if = {
				limit = {
					tier_difference = { target = root value <= -1 }
				}
				change_influence = medium_influence_gain
			}
		}
		reverse_add_opinion = {
			target = scope:other
			modifier = friendliness_opinion
			opinion = 10
		}
		stress_impact = {
			shy = miniscule_stress_impact_gain
			reclusive = miniscule_stress_impact_gain
		}
	}

	option = { # Super Befriend
		name = chariot_race_ongoing_jp.0201.b
		trigger = { this = scope:activity.activity_host }
		custom_tooltip = chariot_race_ongoing_jp.0201.b.tt
		add_internal_flag = special
		change_influence = minor_influence_loss
		primary_title = {
			change_appointment_investment = {
				target = scope:other
				value = appointment_score_minor_value
			}
		}
		scope:other = { change_influence = major_influence_gain }
		duel = {
			target = scope:other
			skill = diplomacy
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				min = 1
				desc = chariot_race_ongoing_jp.0200.b.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.success
					left_icon = scope:other
					if = {
						limit = {
							has_activity_intent = woo_attendee_intent
							intent_target = scope:other
						}
						progress_towards_lover_effect = {
							REASON = lover_chariot_mingling
							CHARACTER = scope:other
							OPINION = 30
						}
					}
					else = {
						progress_towards_friend_effect = {
							REASON = friend_chariot_mingling
							CHARACTER = scope:other
							OPINION = 30
						}
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 1
				desc = chariot_race_ongoing_jp.0200.b.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.partial_success
					left_icon = scope:other
					reverse_add_opinion = {
						target = scope:other
						modifier = friendliness_opinion
						opinion = 15
					}
				}
			}
		}
		stress_impact = {
			arrogant = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Befriend
		name = chariot_race_ongoing_jp.0201.f
		trigger = {
			this != scope:activity.activity_host
			has_activity_intent = befriend_attendee_intent
			intent_target ?= scope:other
			NOT = { has_relation_friend = scope:other }
		}
		custom_tooltip = available_because_intent_tt
		add_internal_flag = special
		change_influence = minor_influence_loss
		duel = {
			target = scope:other
			skill = diplomacy
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value >= 1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.b.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.success
					left_icon = scope:other
					progress_towards_friend_effect = {
						REASON = friend_chariot_mingling
						CHARACTER = scope:other
						OPINION = 30
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = chariot_race_ongoing_jp.0200.b.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.partial_success
					left_icon = scope:other
					reverse_add_opinion = {
						target = scope:other
						modifier = friendliness_opinion
						opinion = 15
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value <= -1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.b.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.b.failure
					left_icon = scope:other
				}
			}
		}
		stress_impact = {
			arrogant = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Compliment
		name = chariot_race_ongoing_jp.0200.h
		trigger = {
			this != scope:activity.activity_host
			has_activity_intent = woo_attendee_intent
			intent_target ?= scope:other
			scope:other != top_liege
		}
		custom_tooltip = available_because_intent_tt
		add_internal_flag = special
		change_influence = minor_influence_loss
		duel = {
			target = scope:other
			skill = intrigue
			5 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 1.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value >= 1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.c.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.success
					left_icon = scope:other
					progress_towards_lover_effect = {
						REASON = lover_chariot_mingling
						CHARACTER = scope:other
						OPINION = 30
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = chariot_race_ongoing_jp.0200.c.partial_success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.partial_success
					left_icon = scope:other
					reverse_add_opinion = {
						target = scope:other
						modifier = friendliness_opinion
						opinion = 15
					}
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					tier_difference = { target = root value <= -1 }
					add = 10
				}
				desc = chariot_race_ongoing_jp.0200.c.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0200.c.failure
					left_icon = scope:other
				}
			}
		}
		stress_impact = {
			chaste = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Trade secret
		name = chariot_race_ongoing_jp.0201.c
		trigger = { exists = scope:given_secret }
		custom_tooltip = chariot_race_ongoing_jp.0200.f.available_tt
		scope:given_secret = { reveal_to = scope:other }
		custom_tooltip = chariot_race_ongoing_jp.0200.f.tt
		hidden_effect = {
			duel = {
				target = scope:other
				skill = intrigue
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 3.5
						min = -49
					}
					modifier = {
						factor = 0
						NOT = { exists = scope:received_secret }
					}
					send_interface_toast = {
						title = chariot_race_ongoing_jp.0200.f.success
						left_icon = scope:other
						scope:received_secret ?= { reveal_to = root }
					}
				}
				10 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -3.5
						min = -49
					}
					send_interface_toast = {
						title = chariot_race_ongoing_jp.0200.f.failure
						left_icon = scope:other
					}
				}
			}
		}
		stress_impact = {
			honest = miniscule_stress_impact_gain
			confider = minor_stress_impact_loss
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}

	option = { # Blow cold
		name = chariot_race_ongoing_jp.0201.e
		if = {
			limit = {
				tier_difference = { target = scope:other value >= 1 }
			}
			add_prestige = miniscule_prestige_gain
		}
		else_if = {
			limit = {
				tier_difference = { target = scope:other value <= -1 }
			}
			add_prestige = minor_prestige_gain
		}
		else = { add_prestige = medium_prestige_gain }
		reverse_add_opinion = {
			target = scope:other
			modifier = unfriendly_opinion
			opinion = -10
		}
		stress_impact = {
			base = minor_stress_impact_loss
			gregarious = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 15
			ai_value_modifier = {
				ai_sociability = -0.5
			}
		}
	}
}

scripted_trigger chariot_easy_kathisma_access_trigger = {
	is_powerful_vassal = yes
	any_held_title = { is_noble_family_title = yes }
}

# Try to get into the kathisma
# by Joe Parkin
chariot_race_ongoing_jp.0300 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0300.t
	desc = {
		desc = chariot_race_ongoing_jp.0300.desc.intro
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:other
		animation = happiness
	}

	cooldown = { years = 1 }

	trigger = {
		is_ai = no
		chariot_kathisma_mingle_trigger = no
	}

	weight_multiplier = {
		base = 1
		modifier = {
			has_activity_intent = increase_influence_intent
			factor = 2
		}
		modifier = {
			has_activity_intent = befriend_attendee_intent
			intent_target ?= { chariot_kathisma_mingle_trigger = yes }
			factor = 2
		}
	}

	immediate = {
		scope:activity.activity_host = { save_scope_as = host }
	}
	
	option = { # Beg
		name = chariot_race_ongoing_jp.0300.a
		duel = {
			skill = diplomacy
			value = chariot_kathisma_access_difficulty_value
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 2.5
					min = -49
				}
				opinion_modifier = {
					who = scope:host
					opinion_target = root
					multiplier = 0.1
				}
				min = 3
				desc = chariot_race_ongoing_jp.0300.a.success
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0300.a.success
					left_icon = scope:host
					add_character_flag = {
						flag = kathisma_access
						months = 3
					}
					custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
					if = {
						limit = { chariot_easy_kathisma_access_trigger = yes }
						change_influence = minor_influence_value
					}
					else = { change_influence = medium_influence_value }
				}
			}
			10 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -2.5
					min = -49
				}
				opinion_modifier = {
					who = scope:host
					opinion_target = root
					multiplier = -0.1
				}
				min = 3
				desc = chariot_race_ongoing_jp.0300.a.failure
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0300.a.failure
					left_icon = scope:host
					if = {
						limit = { chariot_easy_kathisma_access_trigger = yes }
						add_prestige = medium_prestige_loss
					}
					else = { add_prestige = minor_prestige_loss }
				}
			}
		}
		stress_impact = {
			shy = miniscule_stress_impact_gain
			humble = miniscule_stress_impact_gain
			content = miniscule_stress_impact_gain
			reclusive = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
		}
	}

	option = { # Buy
		name = chariot_race_ongoing_jp.0300.b
		trigger = { gold >= scope:host.minor_gold_value }
		show_as_unavailable = { always = yes }
		random_list = {
			10 = {
				ai_value_modifier = {
					ai_greed = -0.5
					ai_boldness = 0.25
				}
				modifier = {
					add = {
						value = scope:host.ai_greed
						divide = 4
					}
				}
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0300.b.success
					left_icon = scope:host
					pay_short_term_gold = {
						target = scope:host
						gold = scope:host.minor_gold_value
					}
					custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
					add_character_flag = {
						flag = kathisma_access
						months = 3
					}
					if = {
						limit = { chariot_easy_kathisma_access_trigger = yes }
						change_influence = minor_influence_value
					}
					else = { change_influence = medium_influence_value }
				}
			}
			10 = {
				send_interface_toast = {
					title = chariot_race_ongoing_jp.0300.b.failure
					left_icon = scope:host
					if = {
						limit = { chariot_easy_kathisma_access_trigger = yes }
						add_prestige = medium_prestige_loss
					}
					else = { add_prestige = minor_prestige_loss }
				}
			}
		}
		stress_impact = {
			greedy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Bully
		name = chariot_race_ongoing_jp.0300.c
		trigger = { has_hook = scope:host }
		show_as_unavailable = { always = yes }
		add_internal_flag = special
		custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
		if = {
			limit = { chariot_easy_kathisma_access_trigger = yes }
			change_influence = minor_influence_value
		}
		else = { change_influence = medium_influence_value }
		stress_impact = {
			chaste = miniscule_stress_impact_gain
			shy = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Give up
		name = chariot_race_ongoing_jp.0300.d
		stress_impact = {
			ambitious = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = -0.5
			}
		}
	}
}

# Dude trying to get into the kathisma
# by Joe Parkin
chariot_race_ongoing_jp.0301 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0301.t
	desc = {
		desc = chariot_race_ongoing_jp.0301.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:weasel_hook }
				desc = chariot_race_ongoing_jp.0301.desc.hook
			}
			desc = chariot_race_ongoing_jp.0301.desc.ask
		}
		triggered_desc = {
			trigger = { exists = scope:weasel_gold }
			desc = chariot_race_ongoing_jp.0301.desc.gold
		}
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		character = scope:weasel
		animation = obsequious_bow
	}

	cooldown = { years = 1 }

	trigger = {
		scope:activity = {
			root = activity_host
			any_guest_subset = {
				name = spectators
				is_ai = yes
				NOR = {
					this = root
					has_relation_rival = root
				}
				chariot_kathisma_mingle_trigger = no
			}
		}
	}

	weight_multiplier = {
		base = 1
		modifier = {
			scope:activity = {
				any_guest_subset = {
					name = spectators
					is_ai = yes
					NOR = {
						this = root
						has_relation_rival = root
					}
					chariot_kathisma_mingle_trigger = no
					has_activity_intent = increase_influence_intent
					chariot_easy_kathisma_access_trigger = yes
				}
			}
			factor = 2
		}
	}

	immediate = {
		scope:activity = {
			activity_host = { save_scope_as = host }
			random_guest_subset = {
				name = spectators
				limit = {
					is_ai = yes
					NOR = {
						this = root
						has_relation_rival = root
					}
					chariot_kathisma_mingle_trigger = no
				}
				weight = {
					base = 1
					modifier = { # Weasel is befriending
						has_activity_intent = befriend_attendee_intent
						intent_target ?= { chariot_kathisma_mingle_trigger = yes }
						add = 25
					}
					modifier = { # Emperor is befriending
						root = { has_activity_intent = befriend_attendee_intent }
						root.intent_target ?= this
						factor = 2
					}
					modifier = { # Weasel is seeking influence
						has_activity_intent = increase_influence_intent
						factor = 2
					}
					modifier = { # Weasel is important
						chariot_easy_kathisma_access_trigger = yes
						factor = 2
					}
					modifier = { # Deprio unimportant weasels
						is_landed = no
						factor = 0.1
					}
					modifier = { factor = highest_held_title_tier } # Prio important weasels
					modifier = { # Prio bold
						add = {
							value = ai_boldness
							divide = 4
						}
					}
					modifier = { # Prio social
						add = {
							value = ai_sociability
							divide = 4
						}
					}
				}
				save_scope_as = weasel
				if = {
					limit = { has_hook = root }
					save_scope_as = weasel_hook
				}
				else_if = {
					limit = { gold >= root.medium_gold_value } # Should be more than what is required, for AI
					save_scope_as = weasel_gold
				}
			}
		}
	}
	
	option = { # Accept
		name = chariot_race_ongoing_jp.0301.a
		trigger = {
			NOT = { exists = scope:weasel_hook }
		}
		add_prestige = miniscule_prestige_loss
		scope:weasel = {
			custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
			if = {
				limit = {
					OR = {
						is_powerful_vassal = yes
						any_held_title = { is_noble_family_title = yes }
					}
				}
				change_influence = minor_influence_value
			}
			else = { change_influence = medium_influence_value }
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 15
			}
			add_character_flag = {
				flag = kathisma_access
				months = 3
			}
		}
		ai_chance = {
			base = 10
			opinion_modifier = {
				who = root
				opinion_target = scope:weasel
				multiplier = 0.1
			}
			ai_value_modifier = {
				ai_compassion = 0.25
				ai_sociability = 0.25
			}
		}
	}

	option = { # Buy
		name = chariot_race_ongoing_jp.0301.b
		trigger = {
			custom_tooltip = {
				text = chariot_race_ongoing_jp.0301.b.tt
				exists = scope:weasel_gold
			}
		}
		scope:weasel = {
			random_list = {
				1 = {
					ai_value_modifier = {
						ai_greed = -0.5
						ai_boldness = 0.25
					}
					modifier = {
						has_activity_intent = increase_influence_intent
						factor = 2
					}
					modifier = {
						has_trait = profligate
						add = 0.5
					}
					modifier = {
						add = {
							value = gold
							divide = 1000
						}
					}
					desc = chariot_race_ongoing_jp.0301.b.success
					root = {
						send_interface_toast = {
							title = chariot_race_ongoing_jp.0301.b.success
							left_icon = scope:weasel
							scope:weasel = {
								pay_short_term_gold = {
									target = scope:host
									gold = scope:host.minor_gold_value
								}
								custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
								add_character_flag = {
									flag = kathisma_access
									months = 3
								}
								if = {
									limit = {
										OR = {
											is_powerful_vassal = yes
											any_held_title = { is_noble_family_title = yes }
										}
									}
									change_influence = minor_influence_value
								}
								else = { change_influence = medium_influence_value }
							}
						}
					}
				}
				1 = {
					ai_value_modifier = {
						ai_rationality = 0.5
						ai_greed = 0.25
					}
					modifier = {
						ai_has_builder_or_pious_builder_personality = yes
						factor = 0.5
					}
					desc = chariot_race_ongoing_jp.0301.b.failure
					send_interface_toast = {
						title = chariot_race_ongoing_jp.0301.b.failure
						left_icon = scope:weasel
						reverse_add_opinion = {
							target = scope:weasel
							modifier = disappointed_opinion
							opinion = -10
						}
					}
				}
			}
		}
		ai_chance = {
			base = 10
			ai_value_modifier = {
				ai_greed = 0.5
			}
		}
	}

	option = { # Hook
		name = chariot_race_ongoing_jp.0301.c
		trigger = { exists = scope:weasel_hook }
		scope:weasel = {
			custom_tooltip = chariot_race_ongoing_jp.0300.a.tt
			if = {
				limit = {
					OR = {
						is_powerful_vassal = yes
						any_held_title = { is_noble_family_title = yes }
					}
				}
				change_influence = minor_influence_value
			}
			else = { change_influence = medium_influence_value }
		}
	}

	option = { # Refuse
		name = chariot_race_ongoing_jp.0301.d
		trigger = {
			NOT = { exists = scope:weasel_hook }
		}
		scope:weasel = {
			if = {
				limit = { chariot_easy_kathisma_access_trigger = yes }
				add_prestige = medium_prestige_loss
			}
			else = { add_prestige = minor_prestige_loss }
			add_opinion = {
				target = root
				modifier = insulted_opinion
				opinion = -10
			}
		}
		ai_chance = {
			base = 10
			opinion_modifier = {
				who = root
				opinion_target = scope:weasel
				multiplier = -0.1
			}
		}
	}
}

# Generic lap update
# by Joe Parkin
chariot_race_ongoing_jp.0400 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0400.t
	desc = {
		desc = chariot_race_ongoing_jp.0400.intro
		random_valid = {
			desc = chariot_race_ongoing_jp.0400.intro_flavor1
			desc = chariot_race_ongoing_jp.0400.intro_flavor2
			desc = chariot_race_ongoing_jp.0400.intro_flavor3
			desc = chariot_race_ongoing_jp.0400.intro_flavor4
			desc = chariot_race_ongoing_jp.0400.intro_flavor5
		}
		random_valid = {
			desc = chariot_race_ongoing_jp.0400.second1
			desc = chariot_race_ongoing_jp.0400.second2
			desc = chariot_race_ongoing_jp.0400.second3
			desc = chariot_race_ongoing_jp.0400.second4
			desc = chariot_race_ongoing_jp.0400.second5
		}
		random_valid = {
			desc = chariot_race_ongoing_jp.0400.third1
			desc = chariot_race_ongoing_jp.0400.third2
			desc = chariot_race_ongoing_jp.0400.third3
			desc = chariot_race_ongoing_jp.0400.third4
			desc = chariot_race_ongoing_jp.0400.third5
		}
		first_valid = {
			triggered_desc = {
				trigger = { stands_to_win_chariot_wager_trigger = yes }
				desc = chariot_race_ongoing_jp.0400.winning_place
			}
			triggered_desc = {
				trigger = {
					scope:wager_target ?= { chariot_racer_valid_trigger = no }
				}
				desc = chariot_race_ongoing_jp.0400.out
			}
			triggered_desc = {
				trigger = {
					exists = scope:wager_target
					stands_to_win_chariot_wager_trigger = no
				}
				desc = chariot_race_ongoing_jp.0400.losing_place
			}
		}
	}
	theme = chariot_race
	
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					scope:wager_target ?= scope:first_place_charioteer
					scope:wager_target ?= scope:second_place_charioteer
					scope:wager_target ?= scope:third_place_charioteer
				}
			}
			animation = throne_room_cheer_1
		}
		triggered_animation = {
			trigger = {
				scope:wager_target ?= {
					OR = {
						is_alive = no
						scope:activity = {
							NOT = {
								any_guest_subset = {
									name = charioteers
									this = scope:wager_target
								}
							}
						}
					}
				}
			}
			animation = eyeroll
		}
		animation = admiration
	}
	lower_left_portrait = scope:first_place_charioteer
	lower_center_portrait = scope:second_place_charioteer
	lower_right_portrait = scope:third_place_charioteer
	
	trigger = {
		scope:activity.var:chariot_race_phase_week >= 2
		# This event doesn't much work for characters who've bet on the team as a whole
		trigger_if = {
			limit = { exists = var:wager_target }
			NOT = { var:wager_target ?= root }
		}
	}

	immediate = {
		ordered_in_list = {
			list = temp_charioteers_list
			limit = { is_alive = yes }
			order_by = {
				value = 0
				subtract = var:current_place_in_race
			}
			save_scope_as = first_place_charioteer
		}
		ordered_in_list = {
			list = temp_charioteers_list
			limit = {
				is_alive = yes
				this != scope:first_place_charioteer
			}
			order_by = {
				value = 0
				subtract = var:current_place_in_race
			}
			save_scope_as = second_place_charioteer
		}
		ordered_in_list = {
			list = temp_charioteers_list
			limit = {
				is_alive = yes
				NOR = {
					this = scope:first_place_charioteer
					this = scope:second_place_charioteer
				}
			}
			order_by = {
				value = 0
				subtract = var:current_place_in_race
			}
			save_scope_as = third_place_charioteer
		}
		var:wager_target ?= { save_scope_as = wager_target }
	}

	option = { 
		name = chariot_race_ongoing_jp.0400.a
		trigger = { stands_to_win_chariot_wager_trigger = yes }
	}

	option = {
		name = chariot_race_ongoing_jp.0400.b
		trigger = {
			scope:wager_target ?= { chariot_racer_valid_trigger = no }
		}
	}
	
	option = {
		name = chariot_race_ongoing_jp.0400.c
		trigger = {
			NOT = { exists = scope:wager_target }
		}
	}

	option = {
		name = chariot_race_ongoing_jp.0400.d
		trigger = {
			exists = scope:wager_target
			stands_to_win_chariot_wager_trigger = no
			scope:wager_target ?= { chariot_racer_valid_trigger = yes }
		}
	}
}

# Gnarly chariot tricks
# by Joe Parkin
chariot_race_ongoing_jp.0500 = { # Evil Knievel is Alive
	type = activity_event
	title = chariot_race_ongoing_jp.0500.t
	desc = {
		desc = chariot_race_ongoing_jp.0500.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:evil_knievel = scope:first_place_charioteer }
				desc = chariot_race_ongoing_jp.0500.first
			}
			triggered_desc = {
				trigger = { scope:evil_knievel = scope:last_place_charioteer }
				desc = chariot_race_ongoing_jp.0500.last
			}
			triggered_desc = {
				trigger = {
					scope:evil_knievel_place > 1
					scope:evil_knievel_place <= 3
				}
				desc = chariot_race_ongoing_jp.0500.high
			}
			triggered_desc = {
				trigger = {
					scope:evil_knievel_place > 3
					scope:evil_knievel_place <= 6
				}
				desc = chariot_race_ongoing_jp.0500.middle
			}
			desc = chariot_race_ongoing_jp.0500.low
		}
		random_valid = {
			desc = chariot_race_ongoing_jp.0500.trick_flavor1
			desc = chariot_race_ongoing_jp.0500.trick_flavor2
			desc = chariot_race_ongoing_jp.0500.trick_flavor3
		}
		desc = chariot_race_ongoing_jp.0500.filler
		first_valid = { # Overtaking flavor
			triggered_desc = { 
				trigger = { exists = scope:overtaking_charioteer }
				desc = chariot_race_ongoing_jp.0500.overtake
			}
			triggered_desc = { 
				trigger = {
					scope:evil_knievel != scope:last_place_charioteer
				}
				desc = chariot_race_ongoing_jp.0500.maintained
			}
			desc = chariot_race_ongoing_jp.0500.maintained_last
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:overtaking_charioteer
				}
				desc = chariot_race_ongoing_jp.0500.alive_overtaken
			}
			desc = chariot_race_ongoing_jp.0500.alive
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:overtaking_charioteer
					var:wager_target ?= scope:evil_knievel
				}
				desc = chariot_race_ongoing_jp.0500.loss
			}
			triggered_desc = {
				trigger = {
					exists = scope:overtaking_charioteer
					var:wager_target ?= scope:overtaking_charioteer
				}
				desc = chariot_race_ongoing_jp.0500.gain
			}
		}
	}
	theme = chariot_race
	override_background = { reference = ep3_hippodrome_track }
	
	left_portrait = {
		trigger = { exists = scope:overtaking_charioteer }
		character = scope:overtaking_charioteer
		animation = chariot_w_horses_happy
		camera = camera_event_chariot_very_left_hippodrome
	}
	center_portrait = {
		trigger = { NOT = { exists = scope:overtaking_charioteer } }
		character = scope:evil_knievel
		animation = chariot_neutral
		camera = camera_event_chariot_center_hippodrome
	}
	right_portrait = {
		trigger = { exists = scope:overtaking_charioteer }
		character = scope:evil_knievel
		animation = chariot_shocked
		camera = camera_event_chariot_very_right_hippodrome
	}

	immediate = {
		scope:evil_knievel = {
			if = {
				limit = { is_alive = yes }
				if = {
					limit = { exists = scope:overtaking_charioteer }
					add_prestige = major_prestige_gain
				}
				else = { add_prestige = massive_prestige_gain }
				distribute_charioteer_trait_xp_effect = { VALUE = 5 }
			}
			else = {
				show_as_tooltip = {
					death = { death_reason = death_chariot_race_trick }
				}
			}
		}
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.a
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.c
		trigger = {
			exists = scope:overtaking_charioteer
			var:wager_target ?= scope:overtaking_charioteer
		}
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.d
		trigger = {
			exists = scope:overtaking_charioteer
			var:wager_target ?= scope:evil_knievel
		}
	}
}

chariot_race_ongoing_jp.0501 = { # Evil Knievel is Dead
	type = activity_event
	title = chariot_race_ongoing_jp.0500.t
	desc = {
		desc = chariot_race_ongoing_jp.0500.intro
		first_valid = {
			triggered_desc = {
				trigger = { scope:evil_knievel = scope:first_place_charioteer }
				desc = chariot_race_ongoing_jp.0500.first
			}
			triggered_desc = {
				trigger = { scope:evil_knievel = scope:last_place_charioteer }
				desc = chariot_race_ongoing_jp.0500.last
			}
			triggered_desc = {
				trigger = {
					scope:evil_knievel_place > 1
					scope:evil_knievel_place <= 3
				}
				desc = chariot_race_ongoing_jp.0500.high
			}
			triggered_desc = {
				trigger = {
					scope:evil_knievel_place > 3
					scope:evil_knievel_place <= 6
				}
				desc = chariot_race_ongoing_jp.0500.middle
			}
			desc = chariot_race_ongoing_jp.0500.low
		}
		random_valid = {
			desc = chariot_race_ongoing_jp.0500.trick_flavor1
			desc = chariot_race_ongoing_jp.0500.trick_flavor2
			desc = chariot_race_ongoing_jp.0500.trick_flavor3
		}
		desc = chariot_race_ongoing_jp.0500.filler
		first_valid = { # Overtaking flavor
			triggered_desc = { 
				trigger = { exists = scope:overtaking_charioteer }
				desc = chariot_race_ongoing_jp.0500.overtake
			}
			triggered_desc = { 
				trigger = {
					scope:evil_knievel != scope:last_place_charioteer
				}
				desc = chariot_race_ongoing_jp.0500.maintained
			}
			desc = chariot_race_ongoing_jp.0500.maintained_last
		}
		desc = chariot_race_ongoing_jp.0500.dead
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:overtaking_charioteer
					var:wager_target ?= scope:evil_knievel
				}
				desc = chariot_race_ongoing_jp.0500.loss_dead
			}
			triggered_desc = {
				trigger = {
					exists = scope:overtaking_charioteer
					var:wager_target ?= scope:overtaking_charioteer
				}
				desc = chariot_race_ongoing_jp.0500.gain
			}
		}
	}
	theme = chariot_race
	override_background = { reference = ep3_hippodrome_track }
	
	left_portrait = {
		trigger = { exists = scope:overtaking_charioteer }
		character = scope:overtaking_charioteer
		triggered_animation = {
			trigger = {
				var:wager_target ?= scope:overtaking_charioteer
			}
			animation = throne_room_cheer_1
		}
		triggered_animation = {
			trigger = {
				var:wager_target ?= scope:evil_knievel
			}
			animation = anger
		}
		animation = throne_room_applaud_1
	}
	center_portrait = {
		trigger = { NOT = { exists = scope:overtaking_charioteer } }
		character = scope:evil_knievel
		animation = dead
		animate_if_dead = yes
	}
	right_portrait = {
		trigger = { exists = scope:overtaking_charioteer }
		character = scope:evil_knievel
		animation = dead
		animate_if_dead = yes
	}

	immediate = {
		scope:evil_knievel = {
			show_as_tooltip = {
				death = { death_reason = death_chariot_race_trick }
			}
		}
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.b
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.c
		trigger = {
			exists = scope:overtaking_charioteer
			var:wager_target ?= scope:overtaking_charioteer
		}
	}

	option = { 
		name = chariot_race_ongoing_jp.0500.d
		trigger = {
			exists = scope:overtaking_charioteer
			var:wager_target ?= scope:evil_knievel
		}
	}
}

# Gambling criticized
# by Joe Parkin

scripted_trigger chariot_race_gambling_castigator_trigger = {
	is_adult = yes
	is_participant_in_activity = root.involved_activity
	NOR = {
		scope:bookmaker ?= this
		has_trait = profligate
		has_trait = incapable
		is_in_guest_subset = { name = charioteers }
	}
	# Kathisma access
	trigger_if = {
		limit = {
			root = { chariot_tier_mingle_trigger = yes }
		}
		chariot_tier_mingle_trigger = yes
	}
	trigger_else = { chariot_tier_mingle_trigger = no }
}

scripted_effect cancel_wager_effect = {
	custom_tooltip = cancel_wager_effect_tt
	show_as_tooltip = {
		scope:bookmaker = {
			pay_short_term_gold = {
				target = root
				gold = root.var:wager_value
			}
		}
	}
	hidden_effect = { add_short_term_gold = root.var:wager_value }
	scope:activity = {
		change_variable = {
			name = chariot_race_pot
			add = {
				value = root.var:wager_value
				multiply = -1
			}
		}
	}
	remove_variable = wager_team
	remove_variable = wager_value
	remove_variable = wager_target
	remove_variable = wager_type
}

scripted_effect halve_wager_effect = {
	custom_tooltip = halve_wager_effect_tt
	show_as_tooltip = {
		scope:bookmaker = {
			pay_short_term_gold = {
				target = root
				gold = {
					value = root.var:wager_value
					divide = 2
				}
			}
		}
	}
	hidden_effect = {
		add_short_term_gold = {
			value = root.var:wager_value
			divide = 2
		}
	}
	scope:activity = {
		change_variable = {
			name = chariot_race_pot
			add = {
				value = root.var:wager_value
				divide = 2
				multiply = -1
			}
		}
	}
	set_variable = {
		name = wager_value
		value = {
			value = root.var:wager_value
			divide = 2
		}
	}
}

chariot_race_ongoing_jp.0600 = {
	type = activity_event
	title = chariot_race_ongoing_jp.0600.t
	desc = {
		desc = chariot_race_ongoing_jp.0600.intro
		first_valid = {
			triggered_desc = {
				trigger = { chariot_tier_mingle_trigger = yes }
				desc = chariot_race_ongoing_jp.0600.kathisma
			}
			desc = chariot_race_ongoing_jp.0600.stands
		}
		desc = chariot_race_ongoing_jp.0600.desc
	}
	theme = chariot_race
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:castigator
		animation = anger
	}
	lower_center_portrait = scope:bookmaker
	cooldown = { years = 5 }

	trigger = {
		gold < tiny_gold_value
		OR = {
			any_spouse = { chariot_race_gambling_castigator_trigger = yes }
			any_close_family_member = { chariot_race_gambling_castigator_trigger = yes }
			any_relation = {
				type = friend
				chariot_race_gambling_castigator_trigger = yes
			}
		}
	}

	immediate = {
		every_spouse = {
			limit = { chariot_race_gambling_castigator_trigger = yes }
			add_to_list = castigators
		}
		every_close_family_member = {
			limit = { chariot_race_gambling_castigator_trigger = yes }
			add_to_list = castigators
		}
		every_relation = {
			type = friend
			limit = { chariot_race_gambling_castigator_trigger = yes }
			add_to_list = castigators
		}
		random_in_list = {
			list = castigators
			weight = {
				base = 50
				modifier = {
					root.primary_spouse ?= this
					factor = 2
				}
				modifier = {
					is_parent_of = root
					factor = 2
				}
				modifier = {
					has_trait = wrathful
					factor = 2
				}
				modifier = {
					has_trait = calm
					factor = 0.5
				}
				modifier = { add = ai_greed }
				modifier = { add = ai_rationality } # Sorry gamblers
				modifier = { add = ai_energy }
			}
			save_scope_as = castigator
			get_quirk_character_effect = yes
		}
	}

	option = { # Dismiss
		name = chariot_race_ongoing_jp.0600.a
		add_prestige = minor_prestige_gain
		reverse_add_opinion = {
			target = scope:castigator
			modifier = angry_opinion
			opinion = -20
		}
		stress_impact = {
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = -0.5
				ai_rationality = -0.5
				ai_boldness = 0.5
			}
		}
	}

	option = { # Halve bet
		name = chariot_race_ongoing_jp.0600.b
		halve_wager_effect = yes
		reverse_add_opinion = {
			target = scope:castigator
			modifier = respect_opinion
			opinion = 10
		}
		scope:bookmaker = {
			add_opinion = {
				target = scope:castigator
				modifier = annoyed_opinion
				opinion = -10
			}
		}
		stress_impact = {
			stubborn = minor_stress_impact_gain
			profligate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = 0.5
				ai_boldness = -0.5
			}
		}
	}

	option = { # Cancel bet
		name = chariot_race_ongoing_jp.0600.c
		add_prestige = minor_prestige_loss
		cancel_wager_effect = yes
		reverse_add_opinion = {
			target = scope:castigator
			modifier = respect_opinion
			opinion = 20
		}
		scope:bookmaker = {
			add_opinion = {
				target = scope:castigator
				modifier = angry_opinion
				opinion = -20
			}
		}
		stress_impact = {
			stubborn = medium_stress_impact_gain
			profligate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_greed = 1
				ai_rationality = 1
				ai_boldness = -1
			}
		}
	}
}

