﻿#Coronation End Effect
# root is the current attending character
# current scope is the host of the activity, also available as scope:activity.host

# Activity Base Effects
coronation_busy_effect = {
	if = {
		limit = {
			is_ai = no
			has_multiple_players = yes
		}
		involved_activity ?= {
			add_to_variable_list = {
				name = coronation_list_busy
				target = root
			}
		}
	}
}

coronation_ready_effect = {
	if = {
		limit = {
			is_ai = no
			has_multiple_players = yes
		}
		involved_activity ?= {
			remove_list_variable = {
				name = coronation_list_busy
				target = root
			}
		}
	}
}

# Realm Laws
coronation_reset_realm_law_effect = {
	trigger_event = ach_maintenance_events.0001
}

coronation_reset_realm_law_variable_effect = {
	if = {
		limit = {
			NOT = { has_realm_law = crowned_emperor }
			has_variable = crowned_emperor_var
		}
		remove_variable = crowned_emperor_var
	}
	else_if = {
		limit = {
			NOT = { has_realm_law = crowned_king }
			has_variable = crowned_king_var
		}
		remove_variable = crowned_king_var
	}
}

coronation_change_law_effect = {
	if = {
		limit = {
			involved_activity = {
				has_activity_option = {
					category = special_type
					option = coronation_type_anointment
				}
			}
		}
		if = {
			limit = {
				NOT = {
					has_game_rule = coronation_laws_off
				}
			}
			add_realm_law = crowned_emperor
		}
		set_variable = crowned_emperor_var
	}
	else = {
		if = {
			limit = {
				NOT = {
					has_game_rule = coronation_laws_off
				}
			}
			add_realm_law = crowned_king
		}
		set_variable = crowned_king_var
	}
}

# Oaths
coronation_set_oath_effect = {
	save_scope_value_as = { 
		name = $OATH$ 
		value = flag:$OATH$ 
	}
	scope:$OATH$ ?= {
		add_to_list = chosen_oaths
	}
}

coronation_set_oath_alternatives_effect = {
	# Find up to 11 fitting oaths the ruler might choose from
	random_list = {
		pick = 11
		unique = yes
		## Diplomacy
		# Alliances
		1 = {
			trigger = {
				is_ai = no
				NOR = { 
					has_variable = diplomacy_oath_1 
					has_character_modifier = oath_of_alliances
				}
				any_ally = {
					count <= 1
				}
			}
			coronation_set_oath_effect = { OATH = diplomacy_oath_1 }
		}
		# Children 
		1 = {
			trigger = {
				NOR = { 
					has_variable = diplomacy_oath_2 
					has_character_modifier = oath_of_children
				}
				fertility >= 0.5
				trigger_if = {
					limit = {
						is_ai = yes
					}
					OR = {
						is_married = no
						any_spouse = {
							fertility >= 0.5
						}
					}
				}
				age <= 30
				any_child = {
					count <= 2
				}
			}
			coronation_set_oath_effect = { OATH = diplomacy_oath_2 }
		}
		## Martial
		# Reconquering Lands in your De Jure
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_conqueror_personality = yes
				}
				NOR = { 
					has_variable = martial_oath_1 
					has_character_modifier = oath_of_reconquest
					government_has_flag = government_is_mandala
				}
				primary_title ?= {
					any_de_jure_county = {
						percent >= 0.35
						holder = {
							NOR = { 
								target_is_liege_or_above = root 
								this = root
							}
						}
					}
				}
			}
			coronation_set_oath_effect = { OATH = martial_oath_1 }
		}
		# General Conquer lands Oath
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_conqueror_personality = yes
					ai_has_warlike_personality = yes
				}
				NOR = { 
					has_variable = martial_oath_2 
					has_character_modifier = oath_of_conquest
					government_has_flag = government_is_mandala
				}
			}
			coronation_set_oath_effect = { OATH = martial_oath_2 }
		}
		## Stewardship
		# Peace Oath
		1 = {
			trigger = {
				NOR = { 
					has_variable = stewardship_oath_1 
					has_character_modifier = oath_of_peace
				}
				days_of_continuous_peace <= 365
			}
			coronation_set_oath_effect = { OATH = stewardship_oath_1 }
		}
		# Building Oath
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_economical_boom_personality = yes
				}
				NOR = { 
					has_variable = stewardship_oath_2 
					has_character_modifier = oath_of_buildings
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_tribal
				}
			}
			coronation_set_oath_effect = { OATH = stewardship_oath_2 }
		}
		## Intrigue
		## Learning
		# University Oath
		50 = {
			trigger = {
				is_ai = no
				NOT = { has_variable = learning_oath_1 }
				any_realm_county = {
					title_province = { has_special_building = no }
					development_level >= 25
				}
			}
			coronation_set_oath_effect = { OATH = learning_oath_1 }
		}
		# Purge Pretenders
		1 = {
			trigger = {
				is_ai = no
				NOR = {
					has_variable = purge_pretenders_oath
					has_character_modifier = oath_of_purge_pretenders
					has_realm_law = single_heir_succession_law
					has_realm_law = clan_harmonious_partition_succession_law
					has_realm_law = single_heir_succession_law_youngest
					has_realm_law = single_heir_dynasty_house
					government_has_flag = government_is_mandala
				}
				trigger_if = {
					limit = {
						culture = {
							has_cultural_era_or_later = culture_era_late_medieval
						}
					}
					primary_title ?= {
						any_claimant = {
							count >= 12
							NOT = {
								is_child_of = root
							}
						}
					}
				}
				trigger_else_if = {
					limit = {
						culture = {
							has_cultural_era_or_later = culture_era_high_medieval
						}
					}
					primary_title ?= {
						any_claimant = {
							count >= 10
							NOT = {
								is_child_of = root
							}
						}
					}
				}
				trigger_else_if = {
					limit = {
						culture = {
							has_cultural_era_or_later = culture_era_early_medieval
						}
					}
					primary_title ?= {
						any_claimant = {
							count >= 8
							NOT = {
								is_child_of = root
							}
						}
					}
				}
				trigger_else = {
					primary_title ?= {
						any_claimant = {
							count >= 6
							NOT = {
								is_child_of = root
							}
						}
					}
				}
			}
			coronation_set_oath_effect = { OATH = purge_pretenders_oath }
		}

		# End the struggle
		100 = {
			trigger = {
				is_ai = no
				NOR = { 
					has_variable = end_the_struggle_oath 
					has_character_modifier = oath_of_end_the_struggle
				}
				OR = {
					exists = struggle:iberian_struggle
					exists = struggle:persian_struggle
				}
				OR = {
					any_character_struggle = { is_struggle_type = iberian_struggle }
					any_character_struggle = { is_struggle_type = persian_struggle }
				}
			}
			coronation_set_oath_effect = { OATH = end_the_struggle_oath }
		}

		## Greatest Hunter
		1 = {
			trigger = {
				is_ai = no
				NOR = {
					has_variable = greatest_hunter_oath
					has_character_modifier = oath_greatest_hunter
					culture ?= { has_cultural_tradition = tradition_vegetarianism }
				}
			}
			coronation_set_oath_effect = { OATH = greatest_hunter_oath }
		}

		## Heir Preparation
		1 = {
			trigger = {
				is_ai = no
				age >= 50
				NOR = {
					has_variable = heir_preparation_oath
					has_character_modifier = oath_heir_preparation
					primary_heir ?= {
						is_child_of = prev
					}
				}
			}
			coronation_set_oath_effect = { OATH = heir_preparation_oath }
		}

		## Install Claimants
		1 = {
			trigger = {
				is_ai = no
				NOR = { 
					has_variable = install_claimants_oath 
					has_character_modifier = oath_install_claimants
					government_has_flag = government_is_mandala
				}
			}
			coronation_set_oath_effect = { OATH = install_claimants_oath }
		}

		## Mend the Fracture
		1 = {
			trigger = {
				always = no
				NOR = { 
					has_variable = mend_the_fracture_oath 
					has_character_modifier = oath_mend_the_fracture
				}
				any_sub_realm_county = {
					percent >= 0.4
					culture != root.culture
					culture = {
						cultural_acceptance = {
							target = root.culture
							value <= 20
						}
						any_culture_county = {
							count >= 6
							holder = {
								target_is_liege_or_above = root
							}
						}
						any_culture_county = {
							percent >= 0.6
							holder = {
								target_is_liege_or_above = root
							}
						}
					}
				}
			}
			coronation_set_oath_effect = { OATH = mend_the_fracture_oath }
		}

		## Provide for Warriors
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_economical_boom_personality = yes
				}
				NOR = { 
					has_variable = provide_for_the_warriors_oath 
					has_character_modifier = oath_provide_for_the_warriors
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_tribal
				}
				any_directly_owned_province = {
					count >= 3
					free_building_slots >= 1
					NOT = {
						has_building_or_higher = oath_warriors_building_01
					}
				}
			}
			coronation_set_oath_effect = { OATH = provide_for_the_warriors_oath }
		}

		## Provide for the Faithful
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_economical_boom_personality = yes
				}
				NOR = { 
					has_variable = provide_for_the_faithful_oath 
					has_character_modifier = oath_provide_for_the_faithful
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_tribal
				}
				any_directly_owned_province = {
					count >= 3
					free_building_slots >= 1
					NOT = {
						has_building_or_higher = oath_faithful_building_01
					}
				}
			}
			coronation_set_oath_effect = { OATH = provide_for_the_faithful_oath }
		}

		## Provide for the Poor
		1 = {
			trigger = {
				OR = {
					is_ai = no
					ai_has_economical_boom_personality = yes
				}
				NOR = { 
					has_variable = provide_for_the_poor_oath 
					has_character_modifier = oath_provide_for_the_poor
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_tribal
				}
				any_directly_owned_province = {
					count >= 3
					free_building_slots >= 1
					NOT = {
						has_building_or_higher = oath_poor_building_01
					}
				}
			}
			coronation_set_oath_effect = { OATH = provide_for_the_poor_oath }
		}

		## Repent
		1 = {
			trigger = {
				is_ai = no
				NOR = { 
					has_variable = repent_oath 
					has_character_modifier = oath_repent
				}
				num_sinful_traits >= 1
			}
			coronation_set_oath_effect = { OATH = repent_oath }
		}
	}
}

coronation_chosen_oath_setup_effect = {
	custom_tooltip = $VAR$_tooltip
	set_variable = {
		name = $VAR$
		value = 0
	}
	set_variable = {
		name = $VAR$_timer
		days = $TIME$
	}
	trigger_event = {
		on_action = coronation_failed_oath_on_action
		days = $TIME$
	}
	scope:activity = {
		set_variable = {
			name = $VAR$
			value = 0
		}
	}
}

coronation_upgrade_oath_value_effect = {
	save_scope_value_as = {
		name = value_of_oath
		value = {
			value = 0
			add = {
				value = scope:activity.var:activity_special_type_progression
				divide = 20
				ceiling = yes
			}
			min = 1
		}
	}
	# Diplomacy
	if = {
		limit = {
			has_variable = diplomacy_oath_1
			var:diplomacy_oath_1 = 0
		}
		set_variable = {
			name = diplomacy_oath_1
			value = scope:value_of_oath
		}
	}
	if = {
		limit = {
			has_variable = diplomacy_oath_2
			var:diplomacy_oath_2 = 0
		}
		set_variable = {
			name = diplomacy_oath_2
			value = scope:value_of_oath
		}
	}
	# Martial
	else_if = {
		limit = {
			has_variable = martial_oath_1
			var:martial_oath_1 = 0
		}
		set_variable = {
			name = martial_oath_1
			value = scope:value_of_oath
		}
	}
	else_if = {
		limit = {
			has_variable = martial_oath_2
			var:martial_oath_2 = 0
		}
		set_variable = {
			name = martial_oath_2
			value = scope:value_of_oath
		}
	}
	# Stewardship
	else_if = {
		limit = {
			has_variable = stewardship_oath_1
			var:stewardship_oath_1 = 0
		}
		set_variable = {
			name = stewardship_oath_1
			value = scope:value_of_oath
		}
	}
	else_if = {
		limit = {
			has_variable = stewardship_oath_2
			var:stewardship_oath_2 = 0
		}
		set_variable = {
			name = stewardship_oath_2
			value = scope:value_of_oath
		}
	}
	# Intrigue
	# Learning
	else_if = {
		limit = {
			has_variable = learning_oath_1
			var:learning_oath_1 = 0
		}
		set_variable = {
			name = learning_oath_1
			value = scope:value_of_oath
		}
	}

	# De Jure rights
	else_if = {
		limit = {
			has_variable = purge_pretenders_oath
			var:purge_pretenders_oath = 0
		}
		set_variable = {
			name = purge_pretenders_oath
			value = scope:value_of_oath
		}
	}

	# End the struggle
	else_if = {
		limit = {
			has_variable = end_the_struggle_oath
			var:end_the_struggle_oath = 0
		}
		set_variable = {
			name = end_the_struggle_oath
			value = scope:value_of_oath
		}
	}

	# Greatest Hunter
	else_if = {
		limit = {
			has_variable = greatest_hunter_oath
			var:greatest_hunter_oath = 0
		}
		set_variable = {
			name = greatest_hunter_oath
			value = scope:value_of_oath
		}
	}

	# Heir Preparation
	else_if = {
		limit = {
			has_variable = heir_preparation_oath
			var:heir_preparation_oath = 0
		}
		set_variable = {
			name = heir_preparation_oath
			value = scope:value_of_oath
		}
	}

	# Install Claimants
	else_if = {
		limit = {
			has_variable = install_claimants_oath
			var:install_claimants_oath = 0
		}
		set_variable = {
			name = install_claimants_oath
			value = scope:value_of_oath
		}
	}

	# Mend the Fracture
	else_if = {
		limit = {
			has_variable = mend_the_fracture_oath
			var:mend_the_fracture_oath = 0
		}
		set_variable = {
			name = mend_the_fracture_oath
			value = scope:value_of_oath
		}
	}

	# Provide for the Warriors
	else_if = {
		limit = {
			has_variable = provide_for_the_warriors_oath
			var:provide_for_the_warriors_oath = 0
		}
		set_variable = {
			name = provide_for_the_warriors_oath
			value = scope:value_of_oath
		}
	}

	# Provide for the Faithful
	else_if = {
		limit = {
			has_variable = provide_for_the_faithful_oath
			var:provide_for_the_faithful_oath = 0
		}
		set_variable = {
			name = provide_for_the_faithful_oath
			value = scope:value_of_oath
		}
	}

	# Provide for the Poor
	else_if = {
		limit = {
			has_variable = provide_for_the_poor_oath
			var:provide_for_the_poor_oath = 0
		}
		set_variable = {
			name = provide_for_the_poor_oath
			value = scope:value_of_oath
		}
	}

	# Repent
	else_if = {
		limit = {
			has_variable = repent_oath
			var:repent_oath = 0
		}
		set_variable = {
			name = repent_oath
			value = scope:value_of_oath
		}
	}
}

coronation_oath_reward_effect = {
	save_scope_value_as = {
		name = oath_base_value
		value = {
			value = 200
			switch = {
				trigger = var:$VARIABLE$
				2 = {
					multiply = {
						value = 1
						add = 0.4
					}
				}
				3 = {
					multiply = {
						value = 1
						add = {
							value = 0.4
							multiply = 2
						}
					}
				}
				4 = {
					multiply = {
						value = 1
						add = {
							value = 0.4
							multiply = 3
						}
					}
				}
				5 = {
					multiply = {
						value = 1
						add = {
							value = 0.4
							multiply = 4
						}
					}
				}
				6 = {
					multiply = {
						value = 1
						add = {
							value = 0.4
							multiply = 5
						}
					}
				}
				7 = {
					multiply = {
						value = 1
						add = {
							value = 0.4
							multiply = 6
						}
					}
				}
			}
		}
	}
	coronation_oath_legitimacy_effect = { VALUE = scope:oath_base_value }
	coronation_oath_prestige_effect = { 
		VALUE = scope:oath_base_value 
		PRESTIGE_MULTIPLIER = 2
	}
	remove_variable = $VARIABLE$
}

coronation_oath_legitimacy_effect = {
	save_scope_value_as = {
		name = base_value
		value = {
			value = $VALUE$
			if = { # With higher legitimacy level, you are less in need of legitimacy, so we reduce the amount. In turn, we increase prestige gains later
				limit = {
					root.legitimacy_level >= 5
				}
				multiply = 0.5
			}
			#Balancing down because wow
			multiply = 0.2
		}
	}
	add_legitimacy = scope:base_value
}

coronation_oath_prestige_effect = {
	save_scope_value_as = {
		name = base_value
		value = {
			value = $VALUE$
			multiply = $PRESTIGE_MULTIPLIER$
			if = { # When Legitimacy gain goes down, Prestige gain goes up
				limit = {
					root.legitimacy_level >= 5
				}
				multiply = 1.5
			}
			#Balancing down because wow
			multiply = 0.5
		}
	}
	add_prestige = scope:base_value
}

coronation_oath_success_effect = {
	save_scope_value_as = {
		name = find_oath
		value = flag:$OATH$
	}
	show_as_tooltip = {
		coronation_oath_reward_effect = { VARIABLE = $OATH$ }
	}

	trigger_event = coronation_events.0175
}

coronation_oath_remove_variable_on_failure_effect = {
	if = {
		limit = {
			has_variable = $VAR$
			NOT = { has_variable = $VAR$_timer }
		}
		save_scope_value_as = {
			name = find_oath
			value = flag:$VAR$
		}
		remove_variable = $VAR$
	}
}

coronation_oath_cleanup_effect = {
	# Diplomacy
	if = {
		limit = {
			NOT = { has_variable = diplomacy_oath_1 }
		}
		remove_variable = diplomacy_oath_1_timer
	}
	if = {
		limit = {
			NOT = { has_variable = diplomacy_oath_2 }
		}
		remove_variable = diplomacy_oath_2_timer
	}
	# Martial
	if = {
		limit = {
			NOT = { has_variable = martial_oath_1 }
		}
		remove_variable = martial_oath_1_timer
		remove_variable = oath_reconquest_title
	}
	if = {
		limit = {
			NOT = { has_variable = martial_oath_2 }
		}
		remove_variable = martial_oath_2_timer
		remove_variable = oath_conquest_size
	}
	# Stewardship
	if = {
		limit = {
			NOT = { has_variable = stewardship_oath_1 }
		}
		remove_variable = stewardship_oath_1_timer
	}
	if = {
		limit = {
			NOT = { has_variable = stewardship_oath_2 }
		}
		remove_variable = stewardship_oath_2_timer
	}
	# Learning
	if = {
		limit = {
			NOT = { has_variable = learning_oath_1 }
		}
		remove_variable = learning_oath_1_timer
		remove_variable = learning_oath_cost
	}
	# De Jure rights
	if = {
		limit = {
			NOT = { has_variable = purge_pretenders_oath }
		}
		remove_variable = purge_pretenders_oath_timer
		remove_variable = purge_pretenders_target_title
	}
	# End the struggle
	if = {
		limit = {
			NOT = { has_variable = end_the_struggle_oath }
		}
		remove_variable = end_the_struggle_oath_timer
		remove_variable = end_the_struggle_oath_type_var
	}
	# Greatest Hunter
	if = {
		limit = {
			NOT = { has_variable = greatest_hunter_oath }
		}
		remove_variable = greatest_hunter_oath_timer
		remove_variable = greatest_hunter_oath_l_counter
		remove_variable = greatest_hunter_oath_r_counter
	}
	# Heir Preparation
	if = {
		limit = {
			NOT = { has_variable = heir_preparation_oath }
		}
		remove_variable = heir_preparation_oath_timer
	}
	# Install Claimants
	if = {
		limit = {
			NOT = { has_variable = install_claimants_oath }
		}
		remove_variable = install_claimants_oath_timer
	}
	# Mend the Fracture
	if = {
		limit = {
			NOT = { has_variable = mend_the_fracture_oath }
		}
		remove_variable = mend_the_fracture_oath_timer
	}
	# Provide for the Warriors
	if = {
		limit = {
			NOT = { has_variable = provide_for_the_warriors_oath }
		}
		remove_variable = provide_for_the_warriors_oath_timer
	}
	# Provide for the Faithful
	if = {
		limit = {
			NOT = { has_variable = provide_for_the_faithful_oath }
		}
		remove_variable = provide_for_the_faithful_oath_timer
	}
	# Provide for the Poor
	if = {
		limit = {
			NOT = { has_variable = provide_for_the_poor_oath }
		}
		remove_variable = provide_for_the_poor_oath_timer
	}
	# Repent
	if = {
		limit = {
			NOT = { has_variable = repent_oath }
		}
		remove_variable = repent_oath_timer
	}
	
}

coronation_hof_visit_effect = {
	involved_activity = {
		add_activity_log_entry = {
			key = activity_hof_arrival_log
			tags = { good }
			score = 20
			character = activity_host
			target = scope:hof
		}
		# Small boost to Magnificence
		activity_special_type_progression_tiny = yes
		custom_tooltip = coronation_tt_positive_tiny
		activity_host = {
			# Hosts get a bit of legitimacy and piety from having the HoF show up
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
			add_piety = minor_piety_gain
		}
		activity_location = {
			show_as_tooltip = {
				add_province_modifier = {
					modifier = ach_hof_visit_modifier
					years = 10
				}
			}
			if = { # Add the Papal visit modifier
				limit = {
					NOT = { has_province_modifier = ach_hof_visit_modifier }
				}
				hidden_effect = {
					add_province_modifier = {
						modifier = ach_hof_visit_modifier
						years = 10
					}

					# Toast the divine trinity of those who care: the host, the local baron and the holy count
					scope:host = {
						send_interface_toast = {
							title = ach_coronation.0001.tt.hof_visit.title
							left_icon = scope:hof
							custom_tooltip = ach_coronation.0001.tt.hof_visit
						}
					}
				}
			}
		}
	}
}

create_proper_coronation_artifact_setup = {
	if = {
		limit = {
			coronation_proper_artifact_crown_trigger = yes
		}
		save_scope_value_as = {
			name = coronation_artifact
			value = flag:smith_type_crown
		}
	}
	else_if = {
		limit = {
			coronation_proper_artifact_regalia_trigger = yes
		}
		save_scope_value_as = {
			name = coronation_artifact
			value = flag:smith_type_regalia
		}
	}
	else = {
		save_scope_value_as = {
			name = coronation_artifact
			value = flag:smith_type_crown
		}
	}

	if = { #first we check for an antiquarian
		limit = {
			employs_court_position = antiquarian_court_position
		}
		random_court_position_holder = {
			type = antiquarian_court_position
			save_scope_as = crownmaker
		}
	}
	else_if = {
		limit = {
			any_pool_character = {
				province = root.capital_province
				has_no_particular_noble_roots_trigger = yes
				is_available_healthy_ai_adult = yes
				NOR = {
					exists = inspiration
					has_trait = peasant_leader
				}
			}
		}
		
		random_pool_character = {
			province = root.capital_province
			limit = {
				has_no_particular_noble_roots_trigger = yes
				is_available_healthy_ai_adult = yes
				NOR = {
					exists = inspiration
					has_trait = peasant_leader
				}
			}
			save_scope_as = crownmaker
		}
		hidden_effect = { root = { add_courtier = scope:crownmaker } }
	}
	else = {
		hidden_effect = {
			create_character = {
				template = local_artisan_template
				location = root.capital_province
				gender_female_chance = root_faith_dominant_gender_adjusted_female_chance
				save_scope_as = crownmaker
			}
			root = { add_courtier = scope:crownmaker }
		}
	}
	
	add_character_flag = waiting_for_a_crown

	scope:crownmaker = {
		set_variable = {
			name = artifact_smith_type
			value = scope:coronation_artifact
		}
		create_inspiration = smith_inspiration
	}
}

create_proper_coronation_artifact_creation = {
	if = {
		limit = { scope:coronation_artifact = flag:smith_type_crown }
		custom_tooltip = court_maintenance.0011.crown_needed.tooltip
	}
	else = {
		custom_tooltip = court_maintenance.0011.regalia_needed.tooltip
	}
	sponsor_inspiration = scope:crownmaker.inspiration
}

create_proper_coronation_artifact = {
	create_proper_coronation_artifact_setup = yes
	hidden_effect = { sponsor_inspiration = scope:crownmaker.inspiration }
}

coronation_ceremony_magnificence_effect = {
	if = {
		limit = {
			coronation_ceremony_magnificence_adjustment_value >= 3
		}
		custom_tooltip = coronation_tt_positive_major
		scope:activity = { activity_special_type_progression_major = yes }
	}
	else_if = {
		limit = {
			coronation_ceremony_magnificence_adjustment_value >= 2
		}
		custom_tooltip = coronation_tt_positive_medium
		scope:activity = { activity_special_type_progression_medium = yes }
	}
	else_if = {
		limit = {
			coronation_ceremony_magnificence_adjustment_value >= 1
		}
		custom_tooltip = coronation_tt_positive_tiny
		scope:activity = { activity_special_type_progression_tiny = yes }
	}
	else_if = {
		limit = {
			coronation_ceremony_magnificence_adjustment_value >= 0
		}
		custom_tooltip = coronation_tt_positive_miniscule
		scope:activity = { activity_special_type_progression_miniscule = yes }
	}
	else_if = {
		limit = {
			coronation_ceremony_magnificence_adjustment_value >= -1
		}
		custom_tooltip = coronation_tt_negative_tiny
		scope:activity = { activity_special_type_progression_negative_tiny = yes }
	}
	else = {
		custom_tooltip = coronation_tt_negative
		scope:activity = { activity_special_type_progression_negative = yes }
	}
	if = {
		limit = {
			has_activity_intent = coronation_impress_attendees
		}
		custom_tooltip = improved_because_intent_tt
	}
	if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = ceremony_size
					option = coronation_large_ceremony
				}
			}
		}
		custom_tooltip = improved_by_coronation_large_ceremony_tt
	}
	if = {
		limit = {
			scope:activity = {
				has_activity_option = {
					category = ceremony_size
					option = coronation_small_ceremony
				}
			}
		}
		custom_tooltip = degraded_by_coronation_small_ceremony_tt
	}
}

#For flavor and adjusting piety in coronation ceremony the clergy's approval event
coronation_ceremony_piety_effect = {
	if = {
		limit = {
			coronation_clergy_approval_value >= 3
		}
		add_piety = {
			value = massive_piety_gain
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = coronation_type_anointment
						}
					}
				}
				multiply = 1.5
			}
		}
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= 2
		}
		add_piety = {
			value = major_piety_gain
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = coronation_type_anointment
						}
					}
				}
				multiply = 1.5
			}
		}
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= 1
		}
		add_piety = {
			value = medium_piety_gain
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = coronation_type_anointment
						}
					}
				}
				multiply = 1.5
			}
		}
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= 0
		}
		add_piety = {
			value = minor_piety_gain
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = coronation_type_anointment
						}
					}
				}
				multiply = 1.5
			}
		}
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= -1
		}
		add_piety = {
			value = miniscule_piety_gain
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = coronation_type_anointment
						}
					}
				}
				multiply = 1.5
			}
		}
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= -2
		}
		add_piety = minor_piety_loss
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= -3
		}
		add_piety = major_piety_loss
	}
	else_if = {
		limit = {
			coronation_clergy_approval_value >= -4
		}
		add_piety = major_piety_loss
	}
	else = {
		add_piety = massive_piety_loss
	}
	#Custom tooltip triggers need to match coronation_clergy_approval_value
	if = {
		limit = {
			OR = {
				scope:activity.special_guest:priest ?= {
					opinion = {
						target = scope:host
						value >= 90
					}
				}
				faith.religious_head ?= {
					opinion = {
						target = scope:host
						value >= 40
					}
				}
			}
		}
		custom_tooltip = coronation_piety_improved_by_clerics
	}
	if = {
		limit = {
			OR = {
				scope:activity.special_guest:priest ?= {
					opinion = {
						target = scope:host
						value <= -90
					}
				}
				faith.religious_head ?= {
					opinion = {
						target = scope:host
						value <= -40
					}
				}
			}
		}
		custom_tooltip = coronation_piety_harmed_by_clerics
	}
	if = {
		limit = {
			OR = {
				num_virtuous_traits >= 1
				has_trait = zealous
				has_trait = saint
				has_trait = saoshyant_descendant
				has_trait = sayyid
				has_trait = divine_blood
				has_trait = consecrated_blood
				has_trait = order_member
				has_trait = faith_warrior
				has_trait = saoshyant
				has_trait = paragon
				has_trait = savior
				has_trait = crusader_king
				has_trait = theologian
			}
		}
		custom_tooltip = coronation_piety_improved_by_virtuous_traits
	}
	if = {
		limit = {
			OR = {
				num_sinful_traits >= 1
				has_trait = cynical
				has_trait = excommunicated
				has_any_shunned_or_criminal_trait_in_faith_trigger = {
					CHARACTER = scope:host
					FAITH = scope:host.faith
				}
				has_trait = despoiler_of_byzantium
				has_trait = bastard
				has_trait = gallowsbait
				has_trait = decadent
				num_sinful_traits >= 2
			}
		}
		custom_tooltip = coronation_piety_harmed_by_sinful_traits
	}
	if = {
		limit = {
			piety_level >= 3
		}
		custom_tooltip = coronation_piety_improved_by_piety_level
	}
	if = {
		limit = {
			piety_level < 1
		}
		custom_tooltip = coronation_piety_harmed_by_piety_level
	}
}

#For flavor and adjusting prestige in coronation ceremony the vassals' approval event
coronation_ceremony_prestige_effect = {
	if = {
		limit = {
			coronation_vassals_approval_value >= 3
		}
		add_prestige = massive_prestige_gain
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= 2
		}
		add_prestige = major_prestige_gain
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= 1
		}
		add_prestige = medium_prestige_gain
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= 0
		}
		add_prestige = minor_prestige_gain
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= -1
		}
		add_prestige = miniscule_prestige_gain
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= -2
		}
		add_prestige = minor_prestige_loss
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= -3
		}
		add_prestige = medium_prestige_loss
	}
	else_if = {
		limit = {
			coronation_vassals_approval_value >= -4
		}
		add_prestige = major_prestige_loss
	}
	else = {
		add_prestige = massive_prestige_loss
	}
	#Custom tooltip triggers need to match coronation_vassals_approval_value
	#Tooltip major reasons why or why not
	if = {
		limit = {
			has_activity_intent = coronation_embrace_supporters
		}
		custom_tooltip = coronation_prestige_embrace_supporters
	}
	if = {
		limit = {
			combined_supporter_vassal_strength > combined_detractor_vassal_strength
		}
		custom_tooltip = coronation_prestige_improved_by_supporters
	}
	if = {
		limit = {
			combined_detractor_vassal_strength > combined_supporter_vassal_strength
		}
		custom_tooltip = coronation_prestige_harmed_by_detractors
	}
	if = {
		limit = {
			OR = {
				any_targeting_faction = {
					faction_power >= scope:host.current_military_strength
					NOT = {
						faction_is_type = peasant_faction
					}
				}
				any_targeting_faction = {
					count >= 2
					NOT = {
						faction_is_type = peasant_faction
					}
				}
			}
		}
		custom_tooltip = coronation_prestige_harmed_by_factions
	}
	if = {
		limit = {
			OR = {
				has_trait = bastard
				has_trait = denounced
				has_trait = wild_oat
				has_trait = legitimized_bastard
				has_trait = gallivanter
				has_trait = disinherited
				has_trait = bastard_founder
				has_trait = disloyal
			}
		}
		custom_tooltip = coronation_prestige_harmed_by_ignoble_traits
	}
	if = {
		limit = {
			OR = {
				AND = {
					tyranny >= high_tyranny
					dread < high_dread
				}
				AND = {
					tyranny >= medium_tyranny
					dread < medium_dread
				}
			}
		}
		custom_tooltip = coronation_prestige_harmed_by_tyranny
	}
	if = {
		limit = {
			OR = {
				has_trait = august
				has_trait = family_first
				has_trait = knight_errant
				AND = {
					has_trait = lifestyle_hunter
					OR = {
						has_trait_xp = {
							trait = lifestyle_hunter
							track = hunter
							value >= 25
						}
						has_trait_xp = {
							trait = lifestyle_hunter
							track = falconer
							value >= 25
						}
					}
				}
				AND = {
					has_trait = governor
					has_trait_xp = {
						trait = governor
						value >= 50
					}
				}
				has_trait = violet_poet
				has_trait = diplomat
				has_trait = extolled
				has_trait = augustus
				has_trait = greatest_of_khans
				has_trait = gallant
			}
		}
		custom_tooltip = coronation_prestige_improved_by_noble_traits
	}
	if = {
		limit = {
			legitimacy_level >= 5
		}
		custom_tooltip = coronation_prestige_improved_by_legitimacy
	}
}

#For flavor and adjusting legitimacy in coronation ceremony the people's approval event
coronation_ceremony_legitimacy_effect = {
	if = {
		limit = {
			has_legitimacy = yes
		}
		if = {
			limit = {
				coronation_popular_approval_value >= 3
			}
			add_legitimacy = major_legitimacy_gain
		}
		else_if = {
			limit = {
				coronation_popular_approval_value >= 2
			}
			add_legitimacy = medium_legitimacy_gain
		}
		else_if = {
			limit = {
				coronation_popular_approval_value >= 1
			}
			add_legitimacy = minor_legitimacy_gain
		}
		else_if = {
			limit = {
				coronation_popular_approval_value >= 0
			}
			add_legitimacy = miniscule_legitimacy_gain
		}
		else_if = {
			limit = {
				coronation_popular_approval_value >= -1
			}
			add_legitimacy = minor_legitimacy_loss
		}
		else_if = {
			limit = {
				coronation_popular_approval_value >= -2
			}
			add_legitimacy = medium_legitimacy_loss
		}
		else = {
			add_legitimacy = major_legitimacy_loss
		}
	}
	#Tooltip major reasons why or why not
	#coronation_popular_approval_value needs to be updated with these
	if = {
		limit = {
			has_activity_intent = coronation_impress_attendees
		}
		custom_tooltip = coronation_legit_impress_attendees
	}
	if = {
		limit = {
			OR = {
				has_trait = peasant_leader
				has_trait = populist_leader
				has_trait = education_republican_knowledge_1
				has_trait = education_republican_knowledge_2
				has_trait = education_republican_knowledge_3
				has_trait = education_republican_knowledge_4	
			}
		}
		custom_tooltip = coronation_legit_improved_by_peasant_leader
	}
	if = {
		limit = {
			location.county = {
				county_opinion >= 25
			}
		}
		custom_tooltip = coronation_legit_improved_by_county_opinion
	}
	if = {
		limit = {
			involved_activity = {
				has_activity_option = {
					category = special_type
					option = coronation_type_anointment
				}
			}
		}
		custom_tooltip = coronation_legit_improved_by_anointment
	}
	if = {
		limit = {
			location.county = {
				county_opinion < 0
				holder = {
					OR = {
						this = root
						any_liege_or_above = {
							this = root
						}
					}
				}
			}
		}
		custom_tooltip = coronation_legit_harmed_by_county_opinion
	}
	if = {
		limit = {
			location.county = {
				county_control < 100
				holder = {
					OR = {
						this = root
						any_liege_or_above = {
							this = root
						}
					}
				}
			}
		}
		custom_tooltip = coronation_legit_harmed_by_county_control
	}
	if = {
		limit = {
			#county is in faction against liege
			location.county = {
				holder = {
					OR = {
						this = scope:host
						any_liege_or_above = {
							this = scope:host
						}
					}
				}
				title_is_a_faction_member = yes
			}
		}
		custom_tooltip = coronation_legit_harmed_by_county_faction
	}
	if = {
		limit = {
			OR = {
				AND = {
					tyranny >= high_tyranny
					dread < high_dread
				}
				AND = {
					tyranny >= medium_tyranny
					dread < medium_dread
				}
			}
		}
		custom_tooltip = coronation_legitimacy_harmed_by_tyranny
	}
	if = {
		limit = {
			location = {
				any_province_epidemic = {
					exists = this
				}
			}
		}
		custom_tooltip = coronation_legit_harmed_by_disease
	}
}

#Increases or reduces attendee opinion based on coronation magnificence
#Used in ceremony phase
coronation_ceremony_opinion_effect = {
	scope:activity = {
		if = {
			limit = {
				scope:activity.var:activity_special_type_progression >= 75
			}
			every_attending_character = {
				custom = custom.every_attending_character
				limit = {
					NOT = {
						this = scope:host
					}
				}
				add_opinion = {
					target = scope:host
					opinion = 10
					modifier = impressed_opinion
				}
			}
			scope:host = {
				custom_tooltip = coronation_ceremony_opinion_effect_tt
			}
		}
		else_if = {
			limit = {
				scope:activity.var:activity_special_type_progression >= 50
			}
			every_attending_character = {
				custom = custom.every_attending_character
				limit = {
					NOT = {
						this = scope:host
					}
				}
				add_opinion = {
					target = scope:host
					opinion = 5
					modifier = impressed_opinion
				}
			}
			scope:host = {
				custom_tooltip = coronation_ceremony_opinion_effect_tt
			}
		}
		else_if = {
			limit = {
				scope:activity.var:activity_special_type_progression < 25
			}
			every_attending_character = {
				custom = custom.every_attending_character
				limit = {
					NOT = {
						this = scope:host
					}
				}
				add_opinion = {
					target = scope:host
					opinion = -10
					modifier = contempt_opinion
				}
			}
			scope:host = {
				custom_tooltip = coronation_ceremony_opinion_effect_tt
			}
		}
	}
}

#Only going to do anything in root's realm, during beginning of coronation ceremony
coronation_ceremony_county_effect = {
	scope:activity = {
		if = {
			limit = {
				activity_location.county.holder = {
					OR = {
						this = scope:host
						any_liege_or_above = {
							this = scope:host
						}
					}
				}
			}
			if = {
				limit = {
					scope:activity.var:activity_special_type_progression >= 75
				}
				activity_location.county = {
					if = {
						limit = {
							county_control < 100
						}
						change_county_control = major_county_control_gain
					}
					if = {
						limit = { uses_county_fertility = yes }
						add_county_modifier = {
							modifier = major_coronation_approval_unsettled_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					else = {
						add_county_modifier = {
							modifier = major_coronation_approval_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					custom_tooltip = county_modifier_excellent_magnificence
					custom_tooltip = coronation_modifier_removed_on_title_transfer_tt
					custom_tooltip = coronation_modifier_negative_on_title_transfer_tt
				}
			}
			else_if = {
				limit = {
					scope:activity.var:activity_special_type_progression >= 50
				}
				activity_location.county = {
					if = {
						limit = {
							county_control < 100
						}
						change_county_control = medium_county_control_gain
					}
					if = {
						limit = { uses_county_fertility = yes }
						add_county_modifier = {
							modifier = medium_coronation_approval_unsettled_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					else = {
						add_county_modifier = {
							modifier = medium_coronation_approval_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					custom_tooltip = county_modifier_good_magnificence
					custom_tooltip = coronation_modifier_removed_on_title_transfer_tt
					custom_tooltip = coronation_modifier_negative_on_title_transfer_tt
				}
			}
			else_if = {
				limit = {
					scope:activity.var:activity_special_type_progression >= 25
				}
				activity_location.county = {
					if = {
						limit = {
							county_control < 100
						}
						change_county_control = minor_county_control_gain
					}
					if = {
						limit = { uses_county_fertility = yes }
						add_county_modifier = {
							modifier = minor_coronation_approval_unsettled_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					else = {
						add_county_modifier = {
							modifier = minor_coronation_approval_modifier
							years = 10
							desc = coronation_modifier_removed_on_title_transfer_desc
						}
					}
					custom_tooltip = county_modifier_decent_magnificence
					custom_tooltip = coronation_modifier_removed_on_title_transfer_tt
					custom_tooltip = coronation_modifier_negative_on_title_transfer_tt
				}
			}
		}
	}
}

coronation_move_towards_supporter_effect = {
	$CHARACTER$ = {
		if = {
			limit = {
				scope:activity = {
					is_target_in_variable_list = {
						name = major_detractor
						target = $CHARACTER$
					}
				}
			}
			scope:activity = {
				remove_list_variable = {
					name = major_detractor
					target = $CHARACTER$
				}
			}
		}
		#Are you a detractor? Stop that
		if = {
			limit = {
				is_in_guest_subset = {
					name = detractor
				}
			}
			if = {
				limit = {
					root = scope:host
				}
				custom_tooltip = buddy_leaves_detractors_tt
			}
			else = {
				custom_tooltip = buddy_leaves_detractors_tt.guest
			}
			scope:activity = {
				remove_from_guest_subset = {
					name = detractor
					target = $CHARACTER$
				}
				add_to_variable_list = {
					name = blocked_from_detractors
					target = $CHARACTER$
				}
				if = {
					limit = {
						has_variable_list = locked_into_detractors
					}
					remove_list_variable = {
						name = locked_into_detractors
						target = $CHARACTER$
					}
				}
			}
			
		}
		#Not a supporter? Make them a supporter
		else_if = {
			limit = {
				NOT = {
					is_in_guest_subset = {
						name = supporter
					}
				}
			}
			if = {
				limit = {
					root = scope:host
				}
				custom_tooltip = buddy_becomes_supporter_tt
			}
			else = {
				custom_tooltip = buddy_becomes_supporter_tt.guest
			}
			scope:activity = {
				add_to_guest_subset = {
					name = supporter
					target = $CHARACTER$
				}
				add_to_variable_list = {
					name = locked_into_supporters
					target = $CHARACTER$
				}
				if = {
					limit = {
						has_variable_list = blocked_from_supporters
					}
					remove_list_variable = {
						name = blocked_from_supporters
						target = $CHARACTER$
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					scope:activity = {
						any_in_list = {
							variable = major_supporter
							count = all
							coronation_supporter_sort_value > $CHARACTER$.coronation_supporter_sort_value
						}
					}
				}
			}
			scope:activity = {
				ordered_in_list = {
					variable = major_supporter
					order_by = {
						value = coronation_supporter_sort_value
						multiply = -1
					}
					scope:activity = {
						remove_list_variable = {
							name = major_supporter
							target = prev
						}
					}
				}
				add_to_variable_list = {
					name = major_supporter
					target = $CHARACTER$
				}
			}
		}
	}
}
coronation_move_towards_detractor_effect = {
	$CHARACTER$ = {
		if = {
			limit = {
				scope:activity = {
					is_target_in_variable_list = {
						name = major_supporter
						target = $CHARACTER$
					}
				}
			}
			scope:activity = {
				remove_list_variable = {
					name = major_supporter
					target = $CHARACTER$
				}
			}
		}
		#re you a detractor? Stop that
		if = {
			limit = {
				is_in_guest_subset = {
					name = supporter
				}
			}
			if = {
				limit = {
					root = scope:host
				}
				custom_tooltip = hater_leaves_supporters_tt
			}
			else = {
				custom_tooltip = hater_leaves_supporters_tt.guest
			}
			scope:activity = {
				remove_from_guest_subset = {
					name = supporter
					target = $CHARACTER$
				}
				add_to_variable_list = {
					name = blocked_from_supporters
					target = $CHARACTER$
				}
				if = {
					limit = {
						has_variable_list = locked_into_detractors
					}
					remove_list_variable = {
						name = locked_into_detractors
						target = $CHARACTER$
					}
				}
			}
		}
		#Not a supporter? Make them a supporter
		else_if = {
			limit = {
				NOT = {
					is_in_guest_subset = {
						name = detractor
					}
				}
			}
			if = {
				limit = {
					root = scope:host
				}
				custom_tooltip = hater_becomes_detractor_tt
			}
			else = {
				custom_tooltip = hater_becomes_detractor_tt.guest
			}
			scope:activity = {
				add_to_guest_subset = {
					name = detractor
					target = $CHARACTER$
				}
				add_to_variable_list = {
					name = locked_into_detractors
					target = $CHARACTER$
				}
				if = {
					limit = {
						has_variable_list = blocked_from_detractors
					}
					remove_list_variable = {
						name = blocked_from_detractors
						target = $CHARACTER$
					}
				}
			}
		}
		if = {
			limit = {
				NOT = {
					scope:activity = {
						any_in_list = {
							variable = major_detractor
							count = all
							coronation_detractor_sort_value > $CHARACTER$.coronation_detractor_sort_value
						}
					}
				}
			}
			scope:activity = {
				ordered_in_list = {
					variable = major_detractor
					order_by = {
						value = coronation_detractor_sort_value
						multiply = -1
					}
					scope:activity = {
						remove_list_variable = {
							name = major_detractor
							target = prev
						}
					}
				}
				add_to_variable_list = {
					name = major_detractor
					target = $CHARACTER$
				}
			}
		}
	}
}

coronation_save_crowning_artifact_effect = {
	if = {
		limit = {
			coronation_proper_artifact_regalia_trigger = no
		}
		ordered_character_artifact = {
			order_by = artifact_rarity
			limit = {
				artifact_slot_type = helmet
				has_variable = artifact_succession_title
				var:artifact_succession_title = {
					this = $HOST$.primary_title
				}
			}
			alternative_limit = {
				artifact_slot_type = helmet
				NOT = { has_variable = artifact_succession_title }
			}
			alternative_limit = {
				artifact_slot_type = helmet
			}
			save_scope_as = crowning_artifact
		}
	}
	else = {
		ordered_character_artifact = {
			order_by = artifact_rarity
			limit = {
				artifact_slot_type = regalia
				has_variable = artifact_succession_title
				var:artifact_succession_title = {
					this = $HOST$.primary_title
				}
			}
			alternative_limit = {
				artifact_slot_type = regalia
				NOT = { has_variable = artifact_succession_title }
			}
			alternative_limit = {
				artifact_slot_type = regalia
			}
			save_scope_as = crowning_artifact
		}
	}
}

coronation_weaken_detractors_opinion_effect = {
	involved_activity = {
		if = {
			limit = {
				any_attending_character = {
					is_vassal_of = root
					has_vassal_stance = belligerent
					NOT = { is_in_guest_subset = { name = detractor } }
				}
			}
			every_attending_character = {
				limit = {
					is_vassal_of = root
					has_vassal_stance = belligerent
					NOT = { is_in_guest_subset = { name = detractor } }
					opinion = {
						target = root
						value < 100
					}
				}
				custom = weaken_detractors_opinion
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 5
				}
			}
		}
	}
}

coronation_exalt_crown_opinion_effect = {
	involved_activity = {
		if = {
			limit = {
				any_attending_character = {
					is_vassal_of = root
					has_vassal_stance = parochial
				}
			}
			every_attending_character = {
				limit = {
					is_vassal_of = root
					has_vassal_stance = parochial
				}
				custom = exalt_crown_opinion
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 5
				}
			}
		}
	}
}

coronation_embrace_supporters_opinion_effect = {
	involved_activity = {
		if = {
			limit = {
				any_attending_character = {
					is_vassal_of = root
					OR = {
						has_vassal_stance = glory_hound
						has_vassal_stance = zealot
					}
					opinion = {
						target = root
						value < 100
					}
				}
			}
			every_attending_character = {
				limit = {
					is_vassal_of = root
					OR = {
						has_vassal_stance = glory_hound
						has_vassal_stance = zealot
					}
					opinion = {
						target = root
						value < 100
					}
				}
				custom = embrace_supporters_opinion
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 5
				}
			}
		}
	}	
}

coronation_impress_attendees_opinion_effect = {
	involved_activity = {
		if = {
			limit = {
				any_attending_character = {
					is_vassal_of = root
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = minority
					}
					opinion = {
						target = root
						value < 100
					}
				}
			}
			every_attending_character = {
				limit = {
					is_vassal_of = root
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = minority
					}
					opinion = {
						target = root
						value < 100
					}
				}
				custom = impress_attendees_opinion
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 5
				}
			}
		}
	}
}
coronation_save_anointer_effect = {
	scope:host = {
		if = {
			limit = {
				coronation_living_officiator_trigger = yes
				NOT = {
					scope:activity.var:officiator = {
						this = scope:host
					}
				}
			}
			scope:activity.var:officiator = {
				save_scope_as = anointer
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:anointer }
					scope:anointer = {
						is_alive = no
					}
					scope:anointer = {
						is_imprisoned = yes
					}
				}
				scope:activity = {
					any_attending_character = {
						this = faith.religious_head
						NOT = {
							this = scope:host
						}
						faith = scope:host.faith
						is_alive = yes	
					}
				}
			}
			faith.religious_head = {
				save_scope_as = anointer
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:anointer }
					scope:anointer = {
						is_alive = no
					}
					scope:anointer = {
						is_imprisoned = yes
					}
				}
				cp:councillor_court_chaplain ?= {
					is_alive = yes
					is_imprisoned = no
					is_incapable = no
					has_contagious_deadly_disease_trigger = no
				}
			}
			cp:councillor_court_chaplain ?= {
				save_scope_as = anointer
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:anointer }
					scope:anointer = {
						is_alive = no
					}
					scope:anointer = {
						is_imprisoned = yes
					}
				}
			}
			ordered_vassal = {
				order_by = max_military_strength
				limit = {
					involved_activity ?= scope:activity
					government_has_flag = government_is_theocracy
					is_alive = yes
				}
				save_scope_as = anointer
			}
		}
		if = {
			limit = {
				OR = {
					NOT = { exists = scope:anointer }
					scope:anointer = {
						is_alive = no
					}
					scope:anointer = {
						is_imprisoned = yes
					}
				}
			}
			create_character = {
				template = priest_character_template
				location = scope:host.location
				culture = scope:host.location.culture
				faith = scope:host.faith
				save_scope_as = anointer
			}
			scope:anointer = {
				add_character_flag = anointer_destroy_me
			}
		}
	}
}

coronation_disburse_rewards_effect = {
	if = { #Highest Magnificence Rewards
		limit = {
			scope:activity = { var:activity_special_type_progression >= 100 }
		}

		#Oath Legitimacy and Prestige upgrade notificiation
		custom_tooltip = coronation_oath_upgrade_100

		custom_tooltip = coronation_reward_100
		save_scope_value_as = {
			name = coronation_reward_mult
			value = 2.5
		}

		ach_coronation_ceremony_intent_modifiers_giveaway_effect = yes
		save_scope_value_as = {
			name = coronation_vassal_opinion_gain
			value = 20
		}
	}
	else_if = { #High Magnificence Rewards
		limit = {
			scope:activity = { var:activity_special_type_progression >= 75 }
		}

		#Intent rewards

		ach_coronation_ceremony_intent_modifiers_giveaway_effect = yes

		#Oath Legitimacy and Prestige upgrade notificiation
		custom_tooltip = coronation_oath_upgrade_75

		custom_tooltip = coronation_reward_75
		save_scope_value_as = {
			name = coronation_reward_mult
			value = 1.75
		}

		save_scope_value_as = {
			name = coronation_vassal_opinion_gain
			value = 15
		}
	}
	else_if = { #Medium Magnificence Rewards
		limit = {
			scope:activity = { var:activity_special_type_progression >= 50 }
		}

		#Oath Legitimacy and Prestige upgrade notificiation
		custom_tooltip = coronation_oath_upgrade_50

		custom_tooltip = coronation_reward_50
		save_scope_value_as = {
			name = coronation_reward_mult
			value = 1.5
		}

		save_scope_value_as = {
			name = coronation_vassal_opinion_gain
			value = 10
		}
	}
	else_if = { #Low Magnificence Rewards
		limit = {
			scope:activity = { var:activity_special_type_progression >= 25 }
		}

		#Oath Legitimacy and Prestige upgrade notificiation
		custom_tooltip = coronation_oath_upgrade_25

		save_scope_value_as = {
			name = coronation_vassal_opinion_gain
			value = 5
		}

		save_scope_value_as = {
			name = coronation_reward_mult
			value = 1.25
		}
	}
	else = {
		save_scope_value_as = {
			name = coronation_reward_mult
			value = 1
		}
	}

	if = {
		limit = { exists = scope:coronation_vassal_opinion_gain root = root.involved_activity.activity_host }
		switch = {
			trigger = has_activity_intent
			coronation_exalt_crown = {
				involved_activity = {
					every_attending_character = {
						limit = {
							is_vassal_of = root
							has_vassal_stance = parochial
						}
						custom = exalt_crown_opinion
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = scope:coronation_vassal_opinion_gain
						}
					}
				}
			}
			coronation_embrace_supporters = {
				involved_activity = {
					every_attending_character = {
						limit = {
							is_vassal_of = root
							OR = {
								has_vassal_stance = glory_hound
								has_vassal_stance = zealot
							}
						}
						custom = embrace_supporters_opinion
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = scope:coronation_vassal_opinion_gain
						}
					}
				}
			}
			coronation_weaken_detractors = {
				involved_activity = {
					every_attending_character = {
						limit = {
							is_vassal_of = root
							has_vassal_stance = belligerent
							NOT = { is_in_guest_subset = { name = detractor } }
						}
						custom = weaken_detractors_opinion
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = scope:coronation_vassal_opinion_gain
						}
					}
				}
			}
			coronation_impress_attendees = {
				involved_activity = {
					every_attending_character = {
						limit = {
							is_vassal_of = root
							OR = {
								has_vassal_stance = courtly
								has_vassal_stance = minority
							}
						}
						custom = impress_attendees_opinion
						add_opinion = {
							target = root
							modifier = impressed_opinion
							opinion = scope:coronation_vassal_opinion_gain
						}
					}
				}
			}	
		}
	}

	
	save_scope_value_as = {
		name = tribal_prestige_mult
		value = 1
	}
	switch = {
		trigger = government_has_flag
		government_is_administrative = {
			change_influence = {
				value = medium_influence_value
				multiply = scope:coronation_reward_mult
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_celestial = {
			change_influence = {
				value = medium_influence_value
				multiply = scope:coronation_reward_mult
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_meritocratic = {
			change_influence = {
				value = medium_influence_value
				multiply = scope:coronation_reward_mult
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_steppe_admin = {
			change_influence = {
				value = medium_influence_value
				multiply = scope:coronation_reward_mult
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_japan_administrative = {
			change_influence = {
				value = medium_influence_value
				multiply = scope:coronation_reward_mult
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_nomadic = {
			save_scope_value_as = {
				name = coronation_herd_value
				value = {
					value = scope:host.domicile.medium_herd_value
					multiply = scope:coronation_reward_mult
				}
			}
			hidden_effect = {
				domicile ?= {
					change_herd = {
						value = scope:coronation_herd_value
					}
				}
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
			custom_tooltip = coronation_nomadic_herd_reward
		}
		government_is_clan = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						house ?= scope:host.house
						is_ai = yes
					}
					switch = {
						trigger = scope:coronation_reward_mult
						1 = {
							save_scope_value_as = {
								name = clan_unity_gain
								value = miniscule_unity_loss
							}
						}
						1.25 = {
							save_scope_value_as = {
								name = clan_unity_gain
								value = miniscule_unity_gain
							}
						}
						1.5 = {
							save_scope_value_as = {
								name = clan_unity_gain
								value = minor_unity_gain
							}
						}
						1.75 = {
							save_scope_value_as = {
								name = clan_unity_gain
								value = medium_unity_gain
							}
						}
						2.5 = {
							save_scope_value_as = {
								name = clan_unity_gain
								value = major_unity_gain
							}
						}
					}
					save_scope_as = unity_character
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:unity_character
						TARGET = scope:host
						VALUE = scope:clan_unity_gain
						DESC = clan_unity_coronation_reward.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
				}
			}
			save_scope_value_as = {
				name = coronation_reward_mult
				value = {
					value = scope:coronation_reward_mult
					multiply = 0.8
				}
			}
		}
		government_is_tribal = {
			save_scope_value_as = {
				name = tribal_prestige_mult
				value = {
					value = scope:coronation_reward_mult
					subtract = 1
					multiply = 0.4
					add = 1
					min = 1
				}	
			}
		}
	}

	# Prestige and Legitimacy Rewards for host after coronation ceremony

	add_prestige = {
		value = 100
		multiply = {
			value = number_of_vassal_supporters
			min = 1
		}
		multiply = scope:coronation_reward_mult
		multiply = scope:tribal_prestige_mult
		min = 100
		max = {
			value = 4000
			multiply = scope:tribal_prestige_mult
		}
	}

	add_legitimacy = {
		value = 25
		multiply = {
			value = number_of_vassal_supporters
			min = 1
		}
		multiply = scope:coronation_reward_mult
		min = 25
		max = 1000
	}
	
	# Renown if you have the Exalt the Crown Intent
	if = {
		limit = { has_activity_intent = coronation_exalt_crown }
		dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
	}
}


ach_coronation_ceremony_intent_modifiers_giveaway_effect = {
	switch = {
		trigger = has_activity_intent
		coronation_exalt_crown = {
			if = {
				limit = {
					government_has_flag = government_is_settled
				}
				add_character_modifier = {
					modifier = bp4_exalted_coronation
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = bp4_exalted_coronation_alt
					years = 20
				}
			}
		}
		coronation_embrace_supporters = {
			if = {
				limit = {
					government_has_flag = government_is_settled
				}
				add_character_modifier = {
					modifier = bp4_supported_coronation
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = bp4_supported_coronation_alt
					years = 20
				}
			}
		}
		coronation_weaken_detractors = {
			if = {
				limit = {
					government_has_flag = government_is_settled
				}
				add_character_modifier = {
					modifier = bp4_asserting_coronation
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = bp4_asserting_coronation_alt
					years = 20
				}
			}
		}
		coronation_impress_attendees = {
			if = {
				limit = {
					government_has_flag = government_is_settled
				}
				add_character_modifier = {
					modifier = bp4_impressive_coronation
					years = 20
				}
			}
			else = {
				add_character_modifier = {
					modifier = bp4_impressive_coronation_alt
					years = 20
				}
			}
		}
	}
}

coronation_completed_log_entry_effect = {
	involved_activity = {
		add_activity_log_entry = {
			key = coronation_completed_log_entry_effect
			tags = { completed }
			score = 100
			show_in_conclusion = yes
			character = scope:activity.activity_host
			#Effects
			show_as_tooltip = {
				scope:activity.activity_host = {
					custom_tooltip = coronation_completed_log_oath_tt
					coronation_change_law_effect = yes
					coronation_disburse_rewards_effect = yes			
				}
			}
		}
	}
}


coronation_create_artifact_game_start_effect = {
	save_scope_as = owner
	if = {
		limit = {
			OR = {
				realm_size >= 60
				highest_held_title_tier >= tier_empire
			}
		}
		set_artifact_rarity_famed = yes
	}
	else = {
		set_artifact_rarity_masterwork = yes
	}

	if = {
		limit = {
			coronation_proper_artifact_crown_trigger = yes
		}
		save_scope_value_as = {
			name = artifact_type
			value = flag:crown
		}
	}
	else_if = {
		limit = {
			coronation_proper_artifact_regalia_trigger = yes
		}
		save_scope_value_as = {
			name = artifact_type
			value = flag:regalia
		}
	}
	else = {
		random_list = {
			1 = {
				save_scope_value_as = {
					name = artifact_type
					value = flag:crown
				}
			}
			1 = {
				save_scope_value_as = {
					name = artifact_type
					value = flag:regalia
				}
			}
		}
	}
	primary_title = {
		save_scope_as = crown_title
		ordered_past_holder = {
			limit = {
				NOT = { this = scope:owner }
				house = scope:owner.house
				time_since_death ={
					years >= 80
				}
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				dynasty = scope:owner.dynasty
				time_since_death ={
					years >= 80
				}
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				culture = scope:owner.culture
				time_since_death ={
					years >= 80
				}
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				faith = scope:owner.faith
				time_since_death ={
					years >= 80
				}
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				dynasty = scope:owner.dynasty
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				culture = scope:owner.culture
			}
			alternative_limit = {
				NOT = { this = scope:owner }
				faith = scope:owner.faith
			}
			alternative_limit = {
				NOT = { this = scope:owner }
			}
			alternative_limit = {
				always = yes
			}
			save_scope_as = title_founder
		}
	}

	if = {
		limit = {
			game_start_date >= 1170.1.1
		}
		coronation_create_artifact_date_effect = {
			DATE_CREATION = 1060.1.1
			DATE_INHERITANCE = 1070.1.1
		}
	}
	else_if = {
		limit = {
			game_start_date >= 1066.1.1
		}
		coronation_create_artifact_date_effect = {
			DATE_CREATION = 940.1.1
			DATE_INHERITANCE = 960.1.1
		}
	}
	else_if = {
		limit = {
			game_start_date < 868.1.1
		}
		coronation_create_artifact_date_effect = {
			DATE_CREATION = 740.1.1
			DATE_INHERITANCE = 760.1.1
		}
	}
}

coronation_create_artifact_date_effect = {
	if = {
		limit = {
			scope:artifact_type = flag:crown
		}
		create_artifact = {
			name = ach_spawned_crown_name
			description = ach_spawned_crown_desc
			type = helmet
			visuals = crown
			template = crown_wearable_template
			wealth = scope:wealth
			quality = scope:quality
			decaying = no
			modifier = artifact_monthly_minor_prestige_2_modifier
			modifier = artifact_legitimacy_gain_mult_4_modifier
			history = {
				type = created
				date = $DATE_CREATION$
				recipient = scope:title_founder
				location = scope:crown_title.title_capital_county.title_province
			}
			save_scope_as = newly_created_artifact
		}
		scope:newly_created_artifact = {	
			add_artifact_title_history = {
				target = scope:crown_title
				date = $DATE_INHERITANCE$
			}
			set_variable = {
				name = artifact_succession_title
				value = scope:crown_title
			}
			add_scaled_artifact_modifier_rulership_effect = yes
		}
	}
	else_if = {
		limit = {
			scope:artifact_type = flag:regalia
		}
		create_artifact = {
			name = ach_spawned_regalia_name
			description = ach_spawned_regalia_desc
			type = regalia
			visuals = regalia
			wealth = scope:wealth
			quality = scope:quality
			template = regalia_template
			decaying = no
			modifier = artifact_monthly_minor_prestige_2_modifier
			modifier = artifact_legitimacy_gain_mult_4_modifier
			history = {
				type = created
				date = $DATE_CREATION$
				recipient = scope:title_founder
				location = scope:crown_title.title_capital_county.title_province
			}
			save_scope_as = newly_created_artifact
		}
		scope:newly_created_artifact = {		
			add_artifact_title_history = {
				target = scope:crown_title
				date = $DATE_INHERITANCE$
			}
			set_variable = {
				name = artifact_succession_title
				value = scope:crown_title
			}
			add_scaled_artifact_modifier_rulership_effect = yes
		}
	}
}


coronation_add_magnificence_log_effect = {
	if = {
		limit = {
			$CHAR$ != involved_activity.activity_host
		}
		save_scope_value_as = {
			name = magnificence_level
			value = $VALUE$
		}
		$CHAR$ = {
			save_scope_as = char
		}
		hidden_effect = {
			involved_activity = {
				switch = {
					trigger = scope:magnificence_level
					flag:positive_massive = {
						add_activity_log_entry = {
							key = coronation_tt_positive_massive_log
							score = 10
							tags = { positive }
							character = scope:char
							custom_tooltip = coronation_tt_positive_massive
						}
					}
					flag:positive_major = {
						add_activity_log_entry = {
							key = coronation_tt_positive_major_log
							score = 10
							tags = { positive }
							character = scope:char
							custom_tooltip = coronation_tt_positive_major
						}
					}
					flag:positive_medium = {
						add_activity_log_entry = {
							key = coronation_tt_positive_medium_log
							score = 10
							tags = { positive }
							character = scope:char
							custom_tooltip = coronation_tt_positive_medium
						}
					}
					flag:positive_tiny = {
						add_activity_log_entry = {
							key = coronation_tt_positive_tiny_log
							score = 10
							tags = { positive }
							character = scope:char
							custom_tooltip = coronation_tt_positive_tiny
						}
					}
					flag:positive_miniscule = {
						add_activity_log_entry = {
							key = coronation_tt_positive_miniscule_log
							score = 10
							tags = { positive }
							character = scope:char
							custom_tooltip = coronation_tt_positive_miniscule
						}
					}
					flag:negative_tiny = {
						add_activity_log_entry = {
							key = coronation_tt_negative_tiny_log
							score = 10
							tags = { negative }
							character = scope:char
							custom_tooltip = coronation_tt_negative_tiny
						}
					}
					flag:negative = {
						add_activity_log_entry = {
							key = coronation_tt_negative_log
							score = 10
							tags = { negative }
							character = scope:char
							custom_tooltip = coronation_tt_negative
						}
					}
					flag:negative_major = {
						add_activity_log_entry = {
							key = coronation_tt_negative_major_log
							score = 10
							tags = { negative }
							character = scope:char
							custom_tooltip = coronation_tt_negative_major
						}
					} 
				}
			}
		}
	}
}

ach_host_intent_rewards_tooltip_effect = {
	if = {
		limit = {
			scope:activity.activity_host = { has_variable = host_had_intent_reward }
		}
		scope:activity.activity_host = {
			switch = {
				trigger = var:host_had_intent_reward
				flag:cultural_acceptance = {
					custom_tooltip = coronation_cultural_acceptance_reward_tt
				}
				flag:opinion_gain = {
					custom_tooltip = coronation_opinion_gain_reward_tt
				}
				flag:legitimacy_and_prestige_gain = {
					custom_tooltip = coronation_legitimacy_and_prestige_gain_reward_tt
				}
				flag:prevent_faction_joining = {
					custom_tooltip = coronation_prevent_faction_joining_reward_tt
				}
				flag:easier_imprisonment = {
					custom_tooltip = coronation_easier_imprisonment_reward_tt
				}
				flag:stress = {
					custom_tooltip = coronation_stress_reward_tt
				}
				flag:better_councillors = {
					custom_tooltip = coronation_better_councillors_reward_tt
				}
				flag:vassal_development_boost = {
					custom_tooltip = coronation_vassal_development_boost_reward_tt
				}
				flag:vassal_defensive_boost = {
					custom_tooltip = coronation_vassal_defensive_boost_reward_tt
				}
				flag:artifact_boost = {
					custom_tooltip = coronation_artifact_boost_reward_tt
				}
				flag:host_development_boost = {
					custom_tooltip = coronation_host_development_boost_reward_tt
				}
				flag:host_defense_boost = {
					custom_tooltip = coronation_host_defense_boost_reward_tt
				}
			}
			switch = {
				trigger = var:reward_tier
				1 = {
					custom_tooltip = coronation_host_reward_tier_one_tt
				}
				2 = {
					custom_tooltip = coronation_host_reward_tier_two_tt
				}
				3 = {
					custom_tooltip = coronation_host_reward_tier_three_tt
				}
				4 = {
					custom_tooltip = coronation_host_reward_tier_four_tt
				}
				5 = {
					custom_tooltip = coronation_host_reward_tier_five_tt
				}
			}
		}
	}
}

ach_host_intent_rewards_effect = {
	if = {
		limit = {
			scope:activity.activity_host = { has_variable = host_had_intent_reward }
		}
		switch = {
			trigger = scope:activity.activity_host.var:host_had_intent_reward
			flag:cultural_acceptance = {
				ach_cultural_acceptance_host_reward_effect = yes
			}
			flag:opinion_gain = {
				ach_opinion_gain_host_reward_effect = yes
			}
			flag:legitimacy_and_prestige_gain = {
				ach_legitimacy_and_prestige_gain_host_reward_effect = yes
			}
			flag:prevent_faction_joining = {
				ach_prevent_faction_joining_host_reward_effect = yes
			}
			flag:easier_imprisonment = {
				ach_easier_imprisonment_host_reward_effect = yes
			}
			flag:stress = {
				ach_stress_host_reward_effect = yes
			}
			flag:better_councillors = {
				ach_better_councillors_host_reward_effect = yes
			}
			flag:vassal_development_boost = {
				ach_vassal_development_boost_host_reward_effect = yes
			}
			flag:vassal_defensive_boost = {
				ach_vassal_defensive_boost_host_reward_effect = yes
			}
			flag:artifact_boost = {
				root = { ach_artifact_boost_host_reward_effect = yes }
			}
			flag:host_development_boost = {
				root = { ach_host_development_boost_host_reward_effect = yes }
			}
			flag:host_defense_boost = {
				root = { ach_host_defense_boost_host_reward_effect = yes }
			}
		}
			
	}
}

ach_cultural_acceptance_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
					}
					culture = { save_scope_as = first_reward_target add_to_list = culture_rewards }	
				}
			}
		}
		2 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
					}
					culture = { save_scope_as = first_reward_target add_to_list = culture_rewards }				
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
					}
					culture = { save_scope_as = second_reward_target add_to_list = culture_rewards }			
				}
			}
		}
		3 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
					}
					culture = { save_scope_as = first_reward_target add_to_list = culture_rewards }		
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
					}
					culture = { save_scope_as = second_reward_target add_to_list = culture_rewards}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
					}
					culture = { save_scope_as = third_reward_target add_to_list = culture_rewards }
				}
			}
		}
		4 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
					}
					culture = { save_scope_as = first_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
					}
					culture = { save_scope_as = second_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
					}
					culture = { save_scope_as = third_reward_target add_to_list = culture_rewards }				
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
						culture != scope:third_reward_target
					}
					culture = { save_scope_as = fourth_reward_target add_to_list = culture_rewards }				
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:fourth_reward_target }
				}
				random_culture_global = {
					limit = {
						this != scope:activity.activity_host.culture
						has_same_culture_heritage = scope:activity.activity_host.culture
					}
					alternative_limit = {
						this != scope:activity.activity_host.culture
					}
					save_scope_as = fourth_reward_target
					add_to_list = culture_rewards
				}
			}
		}
		5 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
					}
					culture = { save_scope_as = first_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
					}	
					culture = { save_scope_as = second_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
					}
					culture = { save_scope_as = third_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
						culture != scope:third_reward_target
					}
					culture = { save_scope_as = fourth_reward_target add_to_list = culture_rewards }
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						culture != scope:activity.activity_host.culture
						culture != scope:first_reward_target
						culture != scope:second_reward_target
						culture != scope:third_reward_target
						culture != scope:fourth_reward_target
					}
					culture = { save_scope_as = fifth_reward_target add_to_list = culture_rewards }
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:fourth_reward_target }
				}
				random_culture_global = {
					limit = {
						this != scope:activity.activity_host.culture
						has_same_culture_heritage = scope:activity.activity_host.culture
					}
					alternative_limit = {
						this != scope:activity.activity_host.culture
					}
					save_scope_as = fourth_reward_target
					add_to_list = culture_rewards
				}
			}
			if = {
				limit = {
					NOT = { exists = scope:fifth_reward_target }
				}
				random_culture_global = {
					limit = {
						this != scope:activity.activity_host.culture
						has_same_culture_heritage = scope:activity.activity_host.culture
						this != scope:fourth_reward_target
					}
					alternative_limit = {
						this != scope:activity.activity_host.culture
						this != scope:fourth_reward_target
					}
					save_scope_as = fifth_reward_target
					add_to_list = culture_rewards
				}
			}
		}
	}
	every_in_list = {
		list = culture_rewards
		change_cultural_acceptance = {
			target = scope:activity.activity_host.culture
			value = medium_positive_culture_acceptance
			desc = cultural_acceptance_gain_coronation_host_reward
		}
	}
}

ach_opinion_gain_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = opinion_rewards
				}
			}
		}
		2 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = opinion_rewards
				}
			}
		}
		3 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = opinion_rewards
				}
			}
		}
		4 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						is_ai = yes
					}
					save_scope_as = fourth_reward_target
					add_to_list = opinion_rewards
				}
			}
		}
		5 = {
			scope:activity = {
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						is_ai = yes
					}
					save_scope_as = fourth_reward_target
					add_to_list = opinion_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						this != scope:fourth_reward_target
						is_ai = yes
					}
					save_scope_as = fifth_reward_target
					add_to_list = opinion_rewards
				}
			}
		}
	}
	every_in_list = {
		list = opinion_rewards
		add_opinion = {
			target = scope:activity.activity_host
			modifier = ach_intent_opinion
			opinion = 25
		}
	}
}

ach_legitimacy_and_prestige_gain_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			scope:activity = {
				activity_host = {
					add_character_modifier = {
						modifier = ach_intent_prestige_modifier
						years = 10
					}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = prestige_rewards
				}
			}
		}
		2 = {
			scope:activity = {
				activity_host = {
					add_character_modifier = {
						modifier = ach_intent_prestige_modifier
						years = 20
					}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = prestige_rewards
				}
			}
		}
		3 = {
			scope:activity = {
				activity_host = {
					add_character_modifier = {
						modifier = ach_intent_prestige_modifier
						years = 30
					}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = prestige_rewards
				}
			}
		}
		4 = {
			scope:activity = {
				activity_host = {
					add_character_modifier = {
						modifier = ach_intent_prestige_modifier
						years = 40
					}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						is_ai = yes
					}
					save_scope_as = fourth_reward_target
					add_to_list = prestige_rewards
				}
			}
		}
		5 = {
			scope:activity = {
				activity_host = {
					add_character_modifier = {
						modifier = ach_intent_prestige_modifier
						years = 50
					}
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						is_ai = yes
					}
					save_scope_as = first_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						is_ai = yes
					}
					save_scope_as = second_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						is_ai = yes
					}
					save_scope_as = third_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						is_ai = yes
					}
					save_scope_as = fourth_reward_target
					add_to_list = prestige_rewards
				}
				ordered_attending_character = {
					order_by = coronation_supporter_sort_value
					limit = {
						this != scope:activity.activity_host
						this != scope:first_reward_target
						this != scope:second_reward_target
						this != scope:third_reward_target
						this != scope:fourth_reward_target
						is_ai = yes
					}
					save_scope_as = fifth_reward_target
					add_to_list = prestige_rewards
				}
			}
		}
	}
	every_in_list = {
		list = prestige_rewards
		add_character_modifier = {
			modifier = ach_intent_prestige_guest_modifier
			years = 5
		}
	}
}

ach_prevent_faction_joining_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}	
	}
	every_in_list = {
		list = faction_rewards
		add_character_modifier = {
			modifier = ach_intent_faction_joining_prevention_modifier
			years = 10
		}
	}
}

ach_easier_imprisonment_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}	
	}
	every_in_list = {
		list = faction_rewards
		add_character_modifier = {
			modifier = ach_intent_imprisonment_modifier
			years = 10
		}
	}
}

ach_stress_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}		
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_detractor_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					is_in_guest_subset = { name = detractor }
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}	
	}
	every_in_list = {
		list = faction_rewards
		add_stress = major_stress_gain
	}
}

ach_better_councillors_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = supporter }	
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					is_in_guest_subset = { name = supporter }
					OR = {
						is_vassal_of = scope:activity.activity_host
						is_courtier_of = scope:activity.activity_host
					}
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}	
	}
	every_in_list = {
		list = faction_rewards
		add_character_modifier = {
			modifier = ach_intent_better_councillors_modifier
			years = 20
		}
	}
}

ach_vassal_development_boost_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}
	}
	every_in_list = {
		list = faction_rewards
		add_character_modifier = {
			modifier = ach_intent_vassal_development_boost_modifier
			years = 20
		}
	}
}

ach_vassal_defensive_boost_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
		}
		2 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
		}
		3 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
		}
		4 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
		}
		5 = {
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 5
				limit = {
					this != scope:activity.activity_host
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = first_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 4
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = second_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 3
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = third_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 2
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fourth_reward_target
				add_to_list = faction_rewards
			}
			ordered_attending_character = {
				order_by = coronation_supporter_sort_value
				position = 1
				limit = {
					this != scope:activity.activity_host
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
					is_ai = yes
					is_vassal_of = scope:activity.activity_host
					is_in_guest_subset = { name = supporter }
				}
				save_scope_as = fifth_reward_target
				add_to_list = faction_rewards
			}
		}
	}
	every_in_list = {
		list = faction_rewards
		add_character_modifier = {
			modifier = ach_intent_vassal_defensive_boost_modifier
			years = 20
		}
	}
}

ach_artifact_boost_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = first_reward_target
				add_to_list = artifact_rewards
			}
		}
		2 = {
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = first_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = artifact_rewards
			}
		}
		3 = {
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = first_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = artifact_rewards
			}
		}
		4 = {
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = first_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = artifact_rewards
			}
		}
		5 = {
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
				}
				alternative_limit = {
					always = yes
				}
				save_scope_as = first_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = artifact_rewards
			}
			ordered_character_artifact = {
				order_by = artifact_age
				limit = {
					is_equipped = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
				alternative_limit = {
					always = yes
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
				save_scope_as = fifth_reward_target
				add_to_list = artifact_rewards
			}
		}
	}
	save_scope_as = liege
	save_scope_as = antiquarian_from_task
	add_character_flag = {
		flag = ach_intent_artifact_boost_flag
		days = 6
	}
	every_in_list = {
		list = artifact_rewards
		save_scope_as = artifact_target
		antiquarian_improve_artifact_effect = yes
	}
}

ach_host_development_boost_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
		}
		2 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
		}
		3 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
		}
		4 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = county_rewards
			}
		}
		5 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
				save_scope_as = fifth_reward_target
				add_to_list = county_rewards
			}
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:second_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:first_reward_target
				}
			}
			save_scope_as = second_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:third_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
				}
			}
			save_scope_as = third_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:fourth_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
					this != scope:third_reward_target
				}
			}
			save_scope_as = fourth_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:fifth_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
			}
			save_scope_as = fifth_reward_target
			add_to_list = county_rewards
		}
	}
	every_in_list = {
		list = county_rewards
		change_development_level = 2
		add_county_modifier = {
			modifier = ach_intent_development_boost_modifier
			years = 20
		}
	}
}

ach_host_defense_boost_host_reward_effect = {
	switch = {
		trigger = scope:activity.activity_host.var:reward_tier
		1 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
		}
		2 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
		}
		3 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
		}
		4 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = county_rewards
			}
		}
		5 = {
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				save_scope_as = first_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
				}
				save_scope_as = second_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
				}
				save_scope_as = third_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
				}
				save_scope_as = fourth_reward_target
				add_to_list = county_rewards
			}
			ordered_held_county = {
				order_by = {
					value = development_level
					multiply = -1
				}
				limit = {
					this != scope:first_reward_target
					this != scope:second_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
				save_scope_as = fifth_reward_target
				add_to_list = county_rewards
			}
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:second_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:first_reward_target
				}
			}
			save_scope_as = second_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:third_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
				}
			}
			save_scope_as = third_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:fourth_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
					this != scope:third_reward_target
				}
			}
			save_scope_as = fourth_reward_target
			add_to_list = county_rewards
		}
	}
	if = {
		limit = {
			NOT = {
				exists = scope:fifth_reward_target
			}
		}
		ordered_realm_county = {
			order_by = {
				value = development_level
				multiply = -1
			}
			limit = {
				holder = {
					is_ai = yes
					this != scope:second_reward_target
					this != scope:first_reward_target
					this != scope:third_reward_target
					this != scope:fourth_reward_target
				}
			}
			save_scope_as = fifth_reward_target
			add_to_list = county_rewards
		}
	}
	every_in_list = {
		list = county_rewards
		add_county_modifier = {
			modifier = ach_intent_defense_boost_modifier
			years = 20
		}
	}
}

coronation_create_artifact_yearly_effect = {
	save_scope_as = owner
	if = {
		limit = {
			highest_held_title_tier >= tier_empire
			realm_size >= 120
		}
		set_artifact_rarity_famed = yes
	}
	else = {
		set_artifact_rarity_masterwork = yes
	}

	if = {
		limit = {
			coronation_proper_artifact_crown_trigger = yes
		}
		save_scope_value_as = {
			name = artifact_type
			value = flag:crown
		}
	}
	else_if = {
		limit = {
			coronation_proper_artifact_regalia_trigger = yes
		}
		save_scope_value_as = {
			name = artifact_type
			value = flag:regalia
		}
	}
	else = {
		random_list = {
			1 = {
				save_scope_value_as = {
					name = artifact_type
					value = flag:crown
				}
			}
			1 = {
				save_scope_value_as = {
					name = artifact_type
					value = flag:regalia
				}
			}
		}
	}
	if = {
		limit = {
			scope:artifact_type = flag:crown
		}
		create_artifact = {
			name = ach_yearly_crown_name
			description = ach_yearly_crown_desc
			type = helmet
			visuals = crown
			wealth = scope:wealth
			template = crown_wearable_template
			quality = scope:quality
			decaying = no
			modifier = artifact_parochial_vassal_opinion_3_modifier
			creator = scope:owner
			save_scope_as = newly_created_artifact
		}
		hidden_effect_new_object = {
			scope:newly_created_artifact = {
				add_scaled_artifact_modifier_rulership_effect = yes
			}
		}
	}
	else_if = {
		limit = {
			scope:artifact_type = flag:regalia
		}
		create_artifact = {
			name = ach_yearly_regalia_name
			description = ach_yearly_regalia_desc
			type = regalia
			template = regalia_template
			visuals = regalia
			wealth = scope:wealth
			quality = scope:quality
			decaying = no
			modifier = artifact_parochial_vassal_opinion_3_modifier
			creator = scope:owner
			save_scope_as = newly_created_artifact
		}
		hidden_effect_new_object = {
			scope:newly_created_artifact = {
				add_scaled_artifact_modifier_rulership_effect = yes
			}
		}
	}
}

coronation_broken_oath_punishment_effect = {

	set_variable = {
		name = scale_of_oath_failure
		value = 0
	}

	every_vassal = {
		add_to_list = disappointed_vassals
		root = {
			change_variable = {
				name = scale_of_oath_failure
				add = prev.sub_realm_size
			}
		}
	}

	every_courtier_or_guest = {
		add_to_list = disappointed_vassals
	}

	change_variable = {
		name = scale_of_oath_failure
		add = sub_realm_size
	}

	if = {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_late_medieval }
		}
		change_variable = {
			name = scale_of_oath_failure
			multiply = 2
		}
	}
	else_if	= {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_high_medieval }
		}
		change_variable = {
			name = scale_of_oath_failure
			multiply = 1.6
		}
	}
	else_if = {
		limit = {
			culture = { has_cultural_era_or_later = culture_era_early_medieval }
		}
		change_variable = {
			name = scale_of_oath_failure
			multiply = 1.2
		}
	}
	else = {
		change_variable = {
			name = scale_of_oath_failure
			multiply = 0.8
		}
	}

	if = {
		limit = {
			has_trait = ambitious
		}
		change_variable = {
			name = scale_of_oath_failure
			multiply = 1.2
		}
	}

	if = {
		limit = {
			is_ai = no
		}
		if = {
			limit = {
				has_game_rule = very_hard_difficulty
			}
			add_prestige_level = -3
			change_variable = {
				name = scale_of_oath_failure
				multiply = 2
			}
			save_scope_value_as = {
				name = failure_opinion_value
				value = -60
			}
			if = {
				limit = {
					has_trait = ambitious
				}
				add_stress = 200
			}
			else = {
				add_stress = 100
			}
		}
		else_if = {
			limit = {
				has_game_rule = hard_difficulty
			}
			add_prestige_level = -2
			change_variable = {
				name = scale_of_oath_failure
				multiply = 1.5
			}
			save_scope_value_as = {
				name = failure_opinion_value
				value = -40
			}
			if = {
				limit = {
					has_trait = ambitious
				}
				add_stress = 150
			}
			else = {
				add_stress = 75
			}
		}
		else_if = {
			limit = {
				has_game_rule = easy_difficulty
			}
			change_variable = {
				name = scale_of_oath_failure
				multiply = 0.7
			}
			save_scope_value_as = {
				name = failure_opinion_value
				value = -10
			}
			if = {
				limit = {
					has_trait = ambitious
				}
				add_stress = medium_stress_gain
			}
			else = {
				add_stress = minor_stress_gain
			}
		}
		else_if = {
			limit = {
				has_game_rule = very_easy_difficulty
			}
			change_variable = {
				name = scale_of_oath_failure
				multiply = 0.7
			}
			save_scope_value_as = {
				name = failure_opinion_value
				value = -5
			}
			if = {
				limit = {
					has_trait = ambitious
				}
				add_stress = minor_stress_gain
			}
			else = {
				add_stress = miniscule_stress_gain
			}
		}
		else = {
			add_prestige_level = -1
			save_scope_value_as = {
				name = failure_opinion_value
				value = -15
			}
			if = {
				limit = {
					has_trait = ambitious
				}
				add_stress = massive_stress_gain
			}
			else = {
				add_stress = major_stress_gain
			}
		}
	}
	else = {
		set_variable = {
			name = scale_of_oath_failure
			value = 1
		}
		save_scope_value_as = {
			name = failure_opinion_value
			value = -1
		}
	}

	save_scope_value_as = {
		name = scale_of_oath_failure_scope
		value = var:scale_of_oath_failure
	}

	every_in_list = {
		list = disappointed_vassals
		custom = coronation_events.150.custom_list_tooltip
		add_opinion = {
			modifier = disappointed_opinion
			target = root
			opinion = scope:failure_opinion_value
		}
	}
}

coronation_update_supporters_detractors_effect = {
	#Add appropriate characters to detractors
	every_attending_character = {
		limit = {
			NOR = {
				is_in_guest_subset = { name = detractor }
				government_has_flag = government_is_herder
				this = scope:host
				has_activity_intent = coronation_offer_support
			}
			trigger_if = {
				limit = {
					has_activity_intent = coronation_disrupt_loyalists
				}
				has_activity_intent = coronation_disrupt_loyalists
			}
			trigger_else = {
				#Opinion combined with a less direct reason
				opinion = {
					target = scope:host
					value < -10
				}
				OR = {
					opinion = {
						target = scope:host
						value < -50
					}
					AND = {
						is_a_faction_member = yes
						is_vassal_of = scope:host
					}
					has_activity_intent = coronation_seize_advantages
					is_causing_raid_hostility_towards = scope:host
					scope:host = {
						is_causing_raid_hostility_towards = prev
					}
					is_at_war_with = scope:host
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:host }
				}
			}
			scope:activity = {
				trigger_if = {
					limit = {
						has_variable_list = blocked_from_detractors	
					}
					NOT = {
						is_target_in_variable_list = {
							name = blocked_from_detractors
							target = prev
						}
					}
				}
				trigger_if = {
					limit = {
						has_variable_list = locked_into_supporters
					}
					NOT = {
						is_target_in_variable_list = {
							name = locked_into_supporters
							target = prev
						}
					}
				}
			}
			#Players should have a reason they can see for their assignment
			trigger_if = {
				limit = {
					is_ai = no
				}
				OR = {
					has_activity_intent = coronation_disrupt_loyalists
					AND = {
						is_a_faction_member = yes
						is_vassal_of = scope:host
					}
					is_causing_raid_hostility_towards = scope:host
					scope:host = {
						is_causing_raid_hostility_towards = prev
					}
					is_at_war_with = scope:host
					has_any_bad_relationship_with_character_trigger = { CHARACTER = scope:host }
					reverse_opinion = {
						target = scope:host
						value < -80
					}
				}
			}
		}
		scope:activity = {
			add_to_guest_subset = {
				name = detractor
				target = prev
			}
		}
	}
	#Remove inappropriate detractors
	every_guest_subset = {
		name = detractor
		limit = {
			scope:activity = {
				trigger_if = {
					limit = {
						has_variable_list = locked_into_detractors
					}
					NOT = {
						is_target_in_variable_list = {
							name = locked_into_detractors
							target = prev
						}
					}
				}
			}
			OR = {
				government_has_flag = government_is_herder
				this = scope:host
				has_activity_intent = coronation_offer_support
				NOR = {
					has_activity_intent = coronation_disrupt_loyalists
					opinion = {
						target = scope:host
						value < -10
					}
				}
			}
		}
		scope:activity = {
			remove_from_guest_subset = {
				name = detractor
				target = prev
			}
		}
	}
	#Clear and then re-save major detractors
	clear_variable_list = major_detractor
	if = {
		limit = {
			any_guest_subset = {
				name = detractor
				count >= 3
			}
		}
		ordered_guest_subset = {
		 	name = detractor
			max = 3
			order_by = coronation_detractor_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_detractor
					target = prev
				}
			}
		}
	}
	else_if = {
		limit = {
			any_guest_subset = {
				name = detractor
				count = 2
			}
		}
		ordered_guest_subset = {
		 	name = detractor
			max = 2
			order_by = coronation_detractor_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_detractor
					target = prev
				}
			}
		}
	}
	else_if = {
		limit = {
			any_guest_subset = {
				name = detractor
				count = 1
			}
		}
		ordered_guest_subset = {
		 	name = detractor
			max = 1
			order_by = coronation_detractor_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_detractor
					target = prev
				}
			}
		}
	}
	#SUPPORTERS
	#Add appropriate characters to supporters
	every_attending_character = {
		limit = {
			NOR = {
				is_in_guest_subset = { name = detractor }
				government_has_flag = government_is_herder
				this = scope:host
				has_activity_intent = coronation_disrupt_loyalists
				AND = {
					is_vassal_of = scope:host
					is_a_faction_member = yes
				}
				is_at_war_with = scope:host
				is_causing_raid_hostility_towards = scope:host
				scope:host = {
					is_causing_raid_hostility_towards = prev
				}
			}
			trigger_if = {
				limit = {
					has_activity_intent = coronation_offer_support
				}
				has_activity_intent = coronation_offer_support
			}
			trigger_else = {
				OR = {
					opinion = {
						target = scope:host
						value > 50
					}
					is_allied_to = scope:host
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:host }
					is_obedient_to = scope:host
				}
				opinion = {
					target = scope:host
					value >= 20
				}
			}
			
			NOT = { this = scope:host }
			scope:activity = {
				trigger_if = {
					limit = {
						has_variable_list = blocked_from_supporters
					}
					NOT = {
						is_target_in_variable_list = {
							name = blocked_from_supporters
							target = prev
						}
					}
				}
				trigger_if = {
					limit = {
						has_variable_list = locked_into_detractors
					}
					NOT = {
						is_target_in_variable_list = {
							name = locked_into_detractors
							target = prev
						}
					}
				}
			}
			#Players should have a reason they can see for their assignment
			trigger_if = {
				limit = {
					is_ai = no
				}
				OR = {
					has_activity_intent = coronation_offer_support
					AND = {
						any_tributary = {
							this = scope:host
						}
						reverse_opinion = {
							target = scope:host
							value > 60
						}
					}
					AND = {
						any_vassal = {
							this = scope:host
						}
						reverse_opinion = {
							target = scope:host
							value > 60
						}
					}
					AND = {
						exists = scope:host.house
						house ?= scope:host.house
						reverse_opinion = {
							target = scope:host
							value > 60
						}
					}
					is_allied_to = scope:host
					has_any_good_relationship_with_character_trigger = { CHARACTER = scope:host }
					reverse_opinion = {
						target = scope:host
						value > 80
					}
				}
			}
		}
		scope:activity = {
			add_to_guest_subset = {
				name = supporter
				target = prev
			}
		}
	}
	#Remove inappropriate supporters
	every_guest_subset = {
		name = supporter
		limit = {
			scope:activity = {
				trigger_if = {
					limit = {
						has_variable_list = locked_into_supporters
					}
					NOT = {
						is_target_in_variable_list = {
							name = locked_into_supporters
							target = prev
						}
					}
				}
			}
			OR = {
				government_has_flag = government_is_herder
				this = scope:host
				has_activity_intent = coronation_disrupt_loyalists
				AND = {
					is_vassal_of = scope:host
					is_a_faction_member = yes
				}
				is_at_war_with = scope:host
				is_causing_raid_hostility_towards = scope:host
				scope:host = {
					is_causing_raid_hostility_towards = prev
				}
				NOR = {
					has_activity_intent = coronation_offer_support
					opinion = {
						target = scope:host
						value > 10
					}
				}
			}
		}
		scope:activity = {
			remove_from_guest_subset = {
				name = supporter
				target = prev
			}
		}
	}
	#Clear and then re-save major supporters
	clear_variable_list = major_supporter
	if = {
		limit = {
			any_guest_subset = {
				name = supporter
				count >= 3
			}
		}
		ordered_guest_subset = {
		 	name = supporter
			max = 3
			order_by = coronation_supporter_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_supporter
					target = prev
				}
			}
		}
	}
	else_if = {
		limit = {
			any_guest_subset = {
				name = supporter
				count = 2
			}
		}
		ordered_guest_subset = {
		 	name = supporter
			max = 2
			order_by = coronation_supporter_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_supporter
					target = prev
				}
			}
		}
	}
	else_if = {
		limit = {
			any_guest_subset = {
				name = supporter
				count = 1
			}
		}
		ordered_guest_subset = {
		 	name = supporter
			max = 1
			order_by = coronation_supporter_sort_value
			scope:activity = {
				add_to_variable_list = {
					name = major_supporter
					target = prev
				}
			}
		}
	}
}
play_coronation_ceremony_music_effect = {
	if = {
		limit = {
			involved_activity.activity_location.culture = { has_graphical_india_culture_group_trigger = yes }
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_india"
	}
	else_if = {
		limit = {
			involved_activity.activity_location.culture = { has_graphical_mena_culture_group_trigger = yes }
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_mena"
	}
	else = {
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_set_west"
	}
	if = {
		limit = {
			scope:activity.var:activity_special_type_progression >= 50
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_welcome"
	}
	else_if = {
		limit = {
			scope:activity.var:activity_special_type_progression >= 25
		}
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_neutral"
	}
	else = {
		play_sound_effect = "event:/DLC/EP2/SFX/Events/Grand_Activities/Tours/ep2_event_grand_tour_arrival_suspicious"
	}
}
ach_remove_oaths_on_king_minus_effect = {
	if = {
		limit = {
			has_variable = diplomacy_oath_1
		}
		remove_variable = diplomacy_oath_1
		remove_variable = diplomacy_oath_1_timer
	}
	if = {
		limit = {
			has_variable = diplomacy_oath_2
		}
		remove_variable = diplomacy_oath_2
		remove_variable = diplomacy_oath_2_timer
	}
	# Martial
	if = {
		limit = {
			has_variable = martial_oath_1
		}
		remove_variable = martial_oath_1
		remove_variable = martial_oath_1_timer
		remove_variable = oath_reconquest_title
	}
	if = {
		limit = {
			has_variable = martial_oath_2
		}
		remove_variable = martial_oath_2
		remove_variable = martial_oath_2_timer
		remove_variable = oath_conquest_size
	}
	# Stewardship
	if = {
		limit = {
			has_variable = stewardship_oath_1
		}
		remove_variable = stewardship_oath_1
		remove_variable = stewardship_oath_1_timer
	}
	if = {
		limit = {
			has_variable = stewardship_oath_2
		}
		remove_variable = stewardship_oath_2
		remove_variable = stewardship_oath_2_timer
	}
	# Learning
	if = {
		limit = {
			has_variable = learning_oath_1
		}
		remove_variable = learning_oath_1
		remove_variable = learning_oath_1_timer
		remove_variable = learning_oath_cost
	}
	# De Jure rights
	if = {
		limit = {
			has_variable = purge_pretenders_oath
		}
		remove_variable = purge_pretenders_oath
		remove_variable = purge_pretenders_oath_timer
		remove_variable = purge_pretenders_target_title
	}
	# End the struggle
	if = {
		limit = {
			has_variable = end_the_struggle_oath
		}
		remove_variable = end_the_struggle_oath
		remove_variable = end_the_struggle_oath_timer
		remove_variable = end_the_struggle_oath_type_var
	}
	# Greatest Hunter
	if = {
		limit = {
			has_variable = greatest_hunter_oath
		}
		remove_variable = greatest_hunter_oath
		remove_variable = greatest_hunter_oath_timer
		remove_variable = greatest_hunter_oath_l_counter
		remove_variable = greatest_hunter_oath_r_counter
	}
	# Heir Preparation
	if = {
		limit = {
			has_variable = heir_preparation_oath
		}
		remove_variable = heir_preparation_oath
		remove_variable = heir_preparation_oath_timer
	}
	# Install Claimants
	if = {
		limit = {
			has_variable = install_claimants_oath
		}
		remove_variable = install_claimants_oath
		remove_variable = install_claimants_oath_timer
	}
	# Mend the Fracture
	if = {
		limit = {
			has_variable = mend_the_fracture_oath
		}
		remove_variable = mend_the_fracture_oath
		remove_variable = mend_the_fracture_oath_timer
	}
	# Provide for the Warriors
	if = {
		limit = {
			has_variable = provide_for_the_warriors_oath
		}
		remove_variable = provide_for_the_warriors_oath
		remove_variable = provide_for_the_warriors_oath_timer
	}
	# Provide for the Faithful
	if = {
		limit = {
			has_variable = provide_for_the_faithful_oath
		}
		remove_variable = provide_for_the_faithful_oath
		remove_variable = provide_for_the_faithful_oath_timer
	}
	# Provide for the Poor
	if = {
		limit = {
			has_variable = provide_for_the_poor_oath
		}
		remove_variable = provide_for_the_poor_oath
		remove_variable = provide_for_the_poor_oath_timer
	}
	# Repent
	if = {
		limit = {
			has_variable = repent_oath
		}
		remove_variable = repent_oath
		remove_variable = repent_oath_timer
	}
}

