﻿coronation_trigger = {
	has_ach_dlc_trigger = yes
	is_landed = yes
	highest_held_title_tier >= tier_kingdom
	# Governments where independent king+ rulers can hold Coronations
	trigger_if = {
		limit = { tgp_realm_has_ceremonial_liege_trigger = yes }
		custom_tooltip = {
			text = tgp_ceremonial_liege_coronation_trigger
			tgp_has_ceremonial_liege_title_trigger = yes
		}
	}
	trigger_if = {
		limit = { government_has_mechanic = administrative }
		is_independent_ruler = yes
	}
	trigger_else = {
		NOR = {
			government_has_flag = government_is_theocracy
			government_has_flag = government_is_republic
			government_has_flag = government_is_mercenary
			government_has_flag = government_is_holy_order
		}
	}
}

coronation_living_officiator_trigger = {
	involved_activity = { 
		has_variable = officiator 
		var:officiator = {
			is_alive = yes
			is_imprisoned = no
		}
	}
}

coronation_has_emperor_law = {
	has_realm_law = crowned_emperor
}

coronation_has_king_law = {
	has_realm_law = crowned_king
}

has_any_coronation_law = {
	OR = {
		coronation_has_emperor_law = yes
		coronation_has_king_law = yes
	}
}

coronation_feast_phase = {
	trigger_if = {
		limit = {
			has_activity_type = activity_coronation
		}
		has_current_phase = coronation_phase_feast
	}
}

coronation_hostile_to_host_trigger = {
	OR = {
		is_in_guest_subset = { name = detractor }
		has_any_bad_relationship_with_character_trigger = { CHARACTER = involved_activity.activity_host }
		has_activity_intent = coronation_disrupt_loyalists
	}
}

# We save coronation_anointment_authority silently because another tooltip trigger already reports it
coronation_anointment_save_authority_trigger = {
	trigger_if = {
		limit = { exists = religious_head_or_challenger }
		religious_head_or_challenger = { save_temporary_scope_as = coronation_anointment_authority }
	}
	trigger_else_if = {
		limit = {
			exists = rite.head_of_rite
			rite.head_of_rite = { pam_is_clergy_ruler_trigger = yes }
		}
		rite.head_of_rite = { save_temporary_scope_as = coronation_anointment_authority }
	}
	trigger_else = {
		# No authority: callers check scope:coronation_anointment_authority
		always = yes
	}
}

coronation_anointment_authority_available_trigger = {
	coronation_anointment_save_authority_trigger = yes
	custom_description = {
		text = CORONATION_RELIGIOUS_AUTHORITY_DOESNT_EXIST
		exists = scope:coronation_anointment_authority
	}
}

# Kept in step with activity_types/coronation.txt is_location_valid for anointment location
coronation_anointment_no_holy_site_available_trigger = {
	NOT = {
		AND = {
			$AUTHORITY$ = { is_landed = yes }
			$AUTHORITY$.faith = {
				any_holy_site_barony = {
					holder = {
						target_is_same_character_or_above = $AUTHORITY$
					}
				}
			}
		}
	}
	NOT = {
		$HOST$.faith = {
			any_holy_site_barony = {
				holder = {
					target_is_same_character_or_above = $HOST$
				}
			}
		}
	}
}

coronation_anointment_authority_is_trigger = {
	trigger_if = {
		limit = { exists = religious_head_or_challenger }
		religious_head_or_challenger ?= $CHARACTER$
	}
	trigger_else_if = {
		limit = {
			exists = rite.head_of_rite
			rite.head_of_rite = { pam_is_clergy_ruler_trigger = yes }
		}
		rite.head_of_rite ?= $CHARACTER$
	}
	trigger_else = {
		always = no
	}
}

is_important_hof_trigger = {
	# The HoF actually matters
	rite = { NOT = { rite_has_doctrine = doctrine_theocracy_temporal } }
	government_has_flag = government_is_theocracy
	OR = {
		AND = {
			# Preserve the ordinary-coronation Head of Faith behavior
			faith = scope:host.faith
			any_held_title = { is_head_of_faith = yes }
		}
		AND = {
			scope:host.involved_activity ?= {
				has_activity_option = {
					category = special_type
					option = coronation_type_anointment
				}
			}
			scope:host = {
				coronation_anointment_authority_is_trigger = { CHARACTER = root }
			}
		}
	}
}

is_coronation_artifact_trigger = {
	artifact_owner = {
		trigger_if = {
			limit = {
				faith = {
					coronation_proper_artifact_crown_trigger = yes
					coronation_proper_artifact_regalia_trigger = no
				}
			}
			prev = {
				artifact_slot_type = helmet
			}
		}
		trigger_else_if = {
			limit = {
				faith = {
					coronation_proper_artifact_regalia_trigger = yes
					coronation_proper_artifact_crown_trigger = no
				}
			}
			prev = {
				artifact_slot_type = regalia
			}
		}
		trigger_else = {
			prev = {
				OR = {
					artifact_slot_type = helmet
					artifact_slot_type = regalia
				}
			}
		}
	}
}

coronation_has_proper_artifact_trigger = {
	trigger_if = {
		limit = {
			faith = {
				coronation_proper_artifact_crown_trigger = yes
				coronation_proper_artifact_regalia_trigger = no
			}
		}
		any_character_artifact = {
			artifact_slot_type = helmet
		}
	}
	trigger_else_if = {
		limit = {
			faith = {
				coronation_proper_artifact_regalia_trigger = yes
				coronation_proper_artifact_crown_trigger = no
			}
		}
		any_character_artifact = {
			artifact_slot_type = regalia
		}
	}
	trigger_else = {
		any_character_artifact = {
			OR = {
				artifact_slot_type = helmet
				artifact_slot_type = regalia
			}
		}
	}
}

coronation_proper_artifact_crown_trigger = {
	religion = {
		OR = {
			this = religion:baltic_religion
#			this = religion:bon_religion
			this = religion:oriental_orthodox_religion 
			this = religion:eastern_orthodox_religion
			this = religion:catholic_religion
			this = religion:protestant_religion
#			this = religion:dualism_religion
#			this = religion:theomach_religion
			this = religion:judaism_religion
#			this = religion:kushitism_religion
#			this = religion:siberian_religion
#			this = religion:tengrism_religion
#			this = religion:west_african_orisha_religion
#			this = religion:yazidi_religion
			this = religion:zoroastrianism_religion
		}
	}
}

coronation_proper_artifact_regalia_trigger = {
	religion = {
		OR = {
			this = religion:buddhism_religion
			this = religion:uralic_religion
			this = religion:hinduism_religion
			this = religion:jainism_religion
			this = religion:slavic_religion
#			this = religion:west_african_bori_religion
			this = religion:taoism_religion
		}
	}
}

# Religions that are not included in the triggers above can have both regalia or a crown.
# The list is intentional and includes:
# akom_religion
# basque_paganism_religion
# donyipolism_religion
# folk_germanic_religion
# islam_religion
# mediterranean_religion
# mundhum_religion
# north_african_religion
# paganism_religion
# qiangic_religion
# taoism_religion
# waaqism_religion
# west_african_roog_religion
# zunism_religion

has_regal_presence_trait_trigger = {
	#Done this way to prevent traits blocking event option text
	trigger_if = {
		limit = {
			has_trait = greatest_of_khans
		}
		has_trait = greatest_of_khans
	}
	trigger_else_if = {
		limit = {
			has_trait = chakravarti
		}
		has_trait = chakravarti
	}
	trigger_else_if = {
		limit = {
			has_trait = augustus
		}
		has_trait = augustus
	}
	trigger_else_if = {
		limit = {
			has_trait = golden_lineage
		}
		has_trait = golden_lineage
	}
	trigger_else_if = {
		limit = {
			has_trait = legend
		}
		has_trait = legend
	}
	trigger_else_if = {
		limit = {
			has_trait = golden_lineage
		}
		has_trait = golden_lineage
	}
	trigger_else_if = {
		limit = {
			has_trait = conqueror
		}
		has_trait = conqueror
	}
	trigger_else_if = {
		limit = {
			has_trait = lifestyle_surveyor
		}
		has_trait = lifestyle_surveyor
	}
	trigger_else_if = {
		limit = {
			has_trait = administrator
		}
		has_trait = administrator
	}
	trigger_else_if = {
		limit = {
			has_trait = family_first
		}
		has_trait = family_first
	}
	trigger_else_if = {
		limit = {
			has_trait = august
		}
		has_trait = august
	}
	trigger_else_if = {
		limit = {
			has_trait = overseer
		}
		has_trait = overseer
	}
	trigger_else_if = {
		limit = {
			has_trait = giant
		}
		has_trait = giant
	}
	trigger_else_if = {
		limit = {
			has_trait = arrogant
		}
		has_trait = arrogant
	}
	trigger_else_if = {
		limit = {
			has_trait = gregarious
		}
		has_trait = gregarious
	}
	trigger_else_if = {
		limit = {
			has_trait = ambitious
		}
		has_trait = ambitious
	}
	trigger_else_if = {
		limit = {
			has_trait = just
		}
		has_trait = just
	}
	trigger_else_if = {
		limit = {
			has_trait = calm
		}
		has_trait = calm
	}
	trigger_else_if = {
		limit = {
			has_trait = zealous
		}
		has_trait = zealous
	}
	trigger_else_if = {
		limit = {
			has_trait = strong
		}
		has_trait = strong
	}
	trigger_else_if = {
		limit = {
			has_trait = beauty_good_3
		}
		has_trait = beauty_good_3
	}
	trigger_else_if = {
		limit = {
			has_trait = beauty_good_2
		}
		has_trait = beauty_good_2
	}
	trigger_else_if = {
		limit = {
			has_trait = physique_good_3
		}
		has_trait = physique_good_3
	}
	trigger_else = {
		has_trait = physique_good_2
	}
}

coronation_being_crowned_trigger = {
	exists = involved_activity
	coronation_living_officiator_trigger = yes
	involved_activity.activity_host = {
		OR = {
			coronation_proper_artifact_crown_trigger = yes
			AND = {
				coronation_proper_artifact_regalia_trigger = no
				any_character_artifact = {
					artifact_slot_type = helmet
				}
				involved_activity = {
					has_activity_option = {
						category = special_type
						option = coronation_type_anointment
					}
				}
			}
		}
	}
	
}

coronation_self_crowning_trigger = {
	exists = involved_activity
	involved_activity.activity_host = {
		OR = {
			coronation_proper_artifact_crown_trigger = yes
			AND = {
				coronation_proper_artifact_regalia_trigger = no
				any_character_artifact = {
					artifact_slot_type = helmet
				}
				#Doesn't have title regalia
				save_temporary_scope_as = host_temp
				NOT = {
					any_character_artifact = {
						artifact_slot_type = regalia
						has_variable = artifact_succession_title
						var:artifact_succession_title = {
							this = scope:host_temp.primary_title
						}
					}
				}
			}
		}
	}
}

coronation_host_east_asian_admin_or_mandala_trigger = {
	OR = {
		government_has_flag = government_is_celestial
		government_has_flag = government_is_meritocratic
		government_has_flag = government_is_mandala
		government_is_japanese_trigger = yes
	}
}

coronation_host_east_asian_trigger = {
	OR = {
		government_has_flag = government_is_celestial
		government_has_flag = government_is_meritocratic
		government_is_japanese_trigger = yes
	}
}

coronation_host_east_asian_steppe_admin_trigger = {
	OR = {
		government_has_flag = government_is_celestial
		government_has_flag = government_is_meritocratic
		government_has_flag = government_is_steppe_admin
		government_is_japanese_trigger = yes
	}
}
