namespace = ep1_decision

##################################################
#
#	Royal Court Court Grandeur Level & Amenity Decisions Events
#
#	COURT GRANDEUR LEVELS
# 0001 - 0010	Host Fundraiser
# 0011 - 0020	Host Summit
#
#	AMENITIES
# 0101 - 0110	Order Mass Eviction
# 0111 - 0120	Commission Exotic Bedchamber
##################################################










##################################################
# COURT GRANDEUR LEVELS
ep1_decision.0201 = {
	type = character_event
	title = ep1_decision.0201.t
	desc = ep1_decision.0201.desc
	theme = education
	left_portrait = scope:good_linguist
	lower_left_portrait = scope:cheap_linguist
	right_portrait = scope:medium_linguist
	lower_right_portrait = scope:scholarly_linguist
	override_background = { reference = throne_room }

	immediate = {
		### Save cultures and languages
		# Find 1st culture that speaks target language natively
		random_culture_global = {
			limit = {
				exists = culture_head
				scope:target_court_language = { has_court_language_of_culture = prev }
			}
			save_scope_as = ling_cul_1
		}
		# Save liege as example to fetch faiths if relevant
		if = {
			limit = {
				exists = scope:language_scheme_type
				liege = { has_court_language_of_culture = root.liege.culture }
			}
			liege = { save_scope_as = ling_cul_1_ruler }
		}
		# Otherwise find random cul_1 ruler
		else = {
			linguist_random_realm_effect = { CULTURE = ling_cul_1 }
		}
		# Find 2nd culture that speaks target language natively
		if = {
			limit = {
				any_culture_global = {
					exists = culture_head
					scope:target_court_language = { has_court_language_of_culture = prev }
					THIS != scope:ling_cul_1
				}
			}
			random_culture_global = {
				limit = {
					exists = culture_head
					scope:target_court_language = { has_court_language_of_culture = prev }
					THIS != scope:ling_cul_1
				}
				save_scope_as = ling_cul_2
			}
		}
		# If none, duplicate 1st
		else = {
			scope:ling_cul_1 = { save_scope_as = ling_cul_2 }
		}
		# Save random ruler of cul 2 to find faith
		linguist_random_realm_effect = { CULTURE = ling_cul_2 }
		# Save own culture
		culture = { save_scope_as = ling_cul_3 }
		# Bonus languages good linguists may know in addition to root and target
		linguist_bonus_culture_effect = { CULTURE = ling_cul_1 }
		linguist_bonus_culture_effect = { CULTURE = ling_cul_2 }
		linguist_bonus_culture_effect = { CULTURE = ling_cul_3 }
		#### Create Linguists
		hidden_effect = {
			# Poor Linguist
			if = {
				limit = { has_trait = greedy }
				create_character = {
					dynasty = none
					template = court_linguist_cheap_template
					location = root.capital_province
					save_scope_as = cheap_linguist
				}
			}
			# Average Linguist
			create_character = {
				dynasty = none
				template = court_linguist_medium_template
				location = root.capital_province
				save_scope_as = medium_linguist
			}
			# Good Linguist
			create_character = {
				dynasty = none
				template = court_linguist_good_template
				culture = scope:ling_cul_2
				faith = scope:ling_cul_2_ruler.faith
				location = root.capital_province
				save_scope_as = good_linguist
			}
			# Scholarly Linguist
			if = {
				limit = { has_trait = scholar }
				create_character = {
					dynasty = none
					template = court_linguist_good_template
					culture = scope:ling_cul_1
					faith = scope:ling_cul_1_ruler.faith
					location = root.capital_province
					trait = scholar
					save_scope_as = scholarly_linguist
				}
				if = {
					limit = {
						exists = scope:ling_cul_2_bonus
						NOT = {
							scope:scholarly_linguist = { knows_language_of_culture = scope:ling_cul_2_bonus }
						}
					}
					scope:scholarly_linguist = { learn_language_of_culture = scope:ling_cul_2_bonus }
				}
			}
		}
	}

	# Expensive linguist, great teacher
	option = {
		name = ep1_decision.0201.a
		pay_short_term_gold = {
			target = scope:good_linguist
			gold = medium_gold_value
		}
		learn_language_linguist_effect = { LINGUIST = scope:good_linguist }
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				short_term_gold < medium_gold_value
				factor = 0
			}
		}
	}

	# Cheaper linguist; less learning, not a good teacher
	option = {
		name = ep1_decision.0201.b
		pay_short_term_gold = {
			target = scope:medium_linguist
			gold = minor_gold_value
		}
		learn_language_linguist_effect = { LINGUIST = scope:medium_linguist }
		stress_impact = {
			greedy = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				short_term_gold < minor_gold_value_check
				factor = 0
			}
		}
	}

	# I know a good tutor through scholarly circles!
	option = {
		name = ep1_decision.0201.c
		trait = scholar
		trigger = { has_trait = scholar }
		learn_language_linguist_effect = { LINGUIST = scope:scholarly_linguist }
		ai_chance = {
			base = 100
		}
	}

	# I'm cheap, get me anyone who can vaguely speak my language
	option = {
		name = ep1_decision.0201.d
		trait = greedy
		trigger = { has_trait = greedy }
		learn_language_linguist_effect = { LINGUIST = scope:cheap_linguist }
		ai_chance = {
			base = 1000
			modifier = { # Don't do it if you can hire the cool guy
				has_trait = scholar
				factor = 0
			}
		}
	}

	# On seconds thoughts, I won't hire a linguist at all...
	option = {
		name = ep1_decision.0201.e
		ai_chance = {
			base = 0
			modifier = {
				short_term_gold < minor_gold_value_check
				NOR = {
					has_trait = scholar
					has_trait = greedy
				}
				add = 10
			}
		}
	}

	after = {
		every_in_list = {
			list = court_linguist_list
			limit = {
				NOT = { is_courtier_of = root }
			}
			silent_disappearance_effect = yes
		}
	}
}












##################################################
# AMENITIES

##################################################
# Out with the Old
# by Ewan Cowhig Croft
# 0101 - 0110
##################################################

#	Pay a little prestige to boot out all the guests from your palace.
ep1_decision.0101 = {
	type = character_event
	title = ep1_decision.0101.t
	desc = ep1_decision.0101.desc
	theme = court
	left_portrait = {
		character = root
		animation = personality_rational
	}
	override_background = { reference = throne_room }

	immediate = {
		# Grab the capital for easy loc.
		capital_barony = { save_scope_as = capital }
	}

	# Scope:capital is not an inn. Away, leeches!
	option = {
		name = ep1_decision.0101.a

		# Evict your guests.
		order_mass_eviction_decision_guests_only_effect = yes

		stress_impact = {
			shy = minor_stress_impact_loss
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			# AI cannot access this event.
			base = 100
		}
	}

	# Everyone who doesn't have a job or a close blood tie, *out*!
	option = {
		name = ep1_decision.0101.b
		trigger = {
			# If you have no spare rooms at all, you can dismiss useless courtiers for a bit extra.
			amenity_level = {
				target = court_lodging_standards
				value <= low_amenity_level
			}
		}

		# Charge an extra premium.
		add_prestige = {
			value = order_mass_eviction_decision_cost_value
			multiply = -1
		}
		# Evict your guests *&* courtiers.
		order_mass_eviction_decision_courtiers_&_guests_effect = yes

		stress_impact = {
			shy = medium_stress_impact_loss
			gregarious = major_stress_impact_gain
		}
		ai_chance = {
			# AI cannot access this event.
			base = 100
		}
	}

	# On seconds thoughts, this is unbecoming...
	option = {
		name = ep1_decision.0101.c

		# Return invested prestige.
		hidden_effect = { add_prestige_no_experience = order_mass_eviction_decision_cost_value }
		# & reset the cooldown.
		remove_decision_cooldown = order_mass_eviction_decision

		# No stress impact for cancelling out of the decision.
		ai_chance = {
			# AI cannot access this event.
			base = 100
		}
	}
}

##################################################
# Grandiose Decor
# by Ewan Cowhig Croft
# 0111 - 0120
##################################################

# For technical reasons, this trigger can't be the same as exoticise_a_grand_hall_decision_list_builder_guts_trigger, but maintains (almost) technical parity with it.
scripted_trigger ep1_decision_0111_list_builder_guts_trigger = {
	# Is the title presently active?
	is_title_created = yes
	# Filter out anyone already in the list.
	NOT = { is_in_list = royal_courts_list }
	# Check assorted holder things.
	holder = {
		# Filter out anyone who has the right rank but lacks a mechanical royal court.
		has_royal_court = yes
		this != root
		# Can the two communicate?
		in_diplomatic_range = root
	}
}

scripted_effect ep1_decision_0111_apply_hall_effect = {
	# Add mutual opinion for each non-AI involved with the interaction.
	$CHOICE$ = {
		if = {
			limit = { is_ai = yes }
			add_opinion = {
				target = root
				modifier = flattered_opinion
				opinion = 30
			}
		}
	}
	if = {
		limit = { is_ai = yes }
		add_opinion = {
			target = $CHOICE$
			modifier = impressed_opinion
			opinion = 30
		}
	}
	# Gain a fraction of the CGV difference.
	change_current_court_grandeur = $CHOICE$.ep1_decision_0111_proportional_cgv_gain_value
	# Pay prestige proportional to how much CGV is gained.
	add_prestige = $CHOICE$.ep1_decision_0111_proportional_prestige_cost_value
	# Hand over a lil participation prestige for $CHOICE$ so that they know someone thinks their court is rad.
	$CHOICE$ = {
		send_interface_toast = {
			title = ep1_decision.0111.toast.t
			left_icon = root
			# Give a little more for emperors doing this.
			if = {
				limit = { $CHOICE$.primary_title.tier >= tier_empire }
				add_prestige = medium_prestige_gain
			}
			# Otherwise, just a few crumbs of prestige.
			else = { add_prestige = minor_prestige_gain }
		}
	}

	# Stress impact handled in the scripted effect, since it'll always be the same for each char.
	stress_impact = {
		architect = minor_stress_impact_loss
		humble = medium_stress_impact_loss
		arrogant = major_stress_impact_gain
	}
}

#	Arrange for a major room to be remodelled with decor inspired by a more grandiose culture.
ep1_decision.0111 = {
	type = character_event
	title = ep1_decision.0111.t
	desc = ep1_decision.0111.desc
	theme = court
	left_portrait = {
		character = root
		animation = throne_room_conversation_4
	}
	lower_left_portrait = scope:option_1
	lower_center_portrait = scope:option_2
	lower_right_portrait = scope:option_3

	immediate = {
		# Build a list of suitable courts.
		## We add the title rather than the characters to the list for a cleaner debug tooltip in-game.
		every_empire = {
			limit = { ep1_decision_0111_list_builder_guts_trigger = yes }
			# Rack 'em up.
			add_to_list = royal_courts_list
		}
		every_kingdom = {
			limit = { ep1_decision_0111_list_builder_guts_trigger = yes }
			# Rack 'em up.
			add_to_list = royal_courts_list
		}
		# Then, filter through the list and grab appropriate options.
		ordered_in_list = {
			list = royal_courts_list
			max = 4
			check_range_bounds = no
			order_by = {
				# Use CGV as a base.
				add = holder.court_grandeur_current
				# Weight up for neighbouring realms.
				if = {
					limit = {
						holder = {
							OR = {
								any_neighboring_and_across_water_realm_same_rank_owner = { this = root }
								any_neighboring_and_across_water_top_liege_realm_owner = { this = root }
							}
						}
					}
					multiply = 5
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:option_1 }
				}
				holder = { save_scope_as = option_1 }
			}
			else_if = {
				limit = {
					NOT = {
						holder = { this = scope:option_1 }
						exists = scope:option_2
					}
				}
				holder = { save_scope_as = option_2 }
			}
			else_if = {
				limit = {
					NOT = {
						holder = { this = scope:option_1 }
						holder = { this = scope:option_2 }
						exists = scope:option_3
					}
				}
				holder = { save_scope_as = option_3 }
			}
		}
	}

	# Scope:option_1 is a grand, grand place.
	option = {
		name = {
			trigger = { scope:option_1.court_grandeur_current > root.court_grandeur_current }
			text = ep1_decision.0111.a.greater_cgv
		}
		name = {
			trigger = { always = yes }
			text = ep1_decision.0111.a.lesser_cgv
		}
		trigger = { exists = scope:option_1 }

		# Build a hall in the relevant scope's style.
		ep1_decision_0111_apply_hall_effect = { CHOICE = scope:option_1 }

		# Stress_impact block handled in the scripted effect.
		ai_chance = {
			# Generally equal likelihood for each option.
			base = 100
			# Otherwise, people want to model themselves after characters they like.
			#opinion_modifier = { opinion_target = scope:option_1 }
		}
	}

	# I find the architecture of scope:option_2 enthralling!
	option = {
		name = {
			trigger = { scope:option_2.court_grandeur_current > root.court_grandeur_current }
			text = ep1_decision.0111.b.greater_cgv
		}
		name = {
			trigger = { always = yes }
			text = ep1_decision.0111.b.lesser_cgv
		}
		trigger = { exists = scope:option_2 }

		# Build a hall in the relevant scope's style.
		ep1_decision_0111_apply_hall_effect = { CHOICE = scope:option_2 }

		# Stress_impact block handled in the scripted effect.
		ai_chance = {
			# Generally equal likelihood for each option.
			base = 100
			# Otherwise, people want to model themselves after characters they like.
			#opinion_modifier = { opinion_target = scope:option_2 }
		}
	}

	# Perhaps a scope:option_3ikkan lounge?
	option = {
		name = {
			trigger = { scope:option_3.court_grandeur_current > root.court_grandeur_current }
			text = ep1_decision.0111.c.greater_cgv
		}
		name = {
			trigger = { always = yes }
			text = ep1_decision.0111.c.lesser_cgv
		}
		trigger = { exists = scope:option_3 }

		# Build a hall in the relevant scope's style.
		ep1_decision_0111_apply_hall_effect = { CHOICE = scope:option_3 }

		# Stress_impact block handled in the scripted effect.
		ai_chance = {
			# Generally equal likelihood for each option.
			base = 100
			# Otherwise, people want to model themselves after characters they like.
			#opinion_modifier = { opinion_target = scope:option_3 }
		}
	}

	# These all seem quite foreign...
	option = {
		name = ep1_decision.0111.d

		# Refund the gold paid; we mention this in a tooltip so that it's a bit less noticeable.
		hidden_effect = { add_gold = var:exoticise_a_grand_hall_decision_refund_value }
		custom_tooltip = ep1_decision.0111.d.tt
		# Take the decision off cooldown.
		remove_decision_cooldown = exoticise_a_grand_hall_decision

		# No stress impact for cancelling out.
		ai_chance = {
			# If the AI has gotten this far, they should pick an option.
			base = 0
		}
	}

	after = {
		# Whatever else happens, clear the refund value.
		remove_variable = exoticise_a_grand_hall_decision_refund_value
	}
}

