﻿# Holy Conquest - Sanctify and Exile Holy Sites 1.1.0
# Prefix: hcq. Every key and file of this mod starts with hcq / zz_hcq_.

# Character scope: may this character change the holy sites of their faith?
# Head of Faith or Head of Rite always can.
# With the default game rule, an independent ruler with piety level 3+ can too.
hcq_authority_trigger = {
	trigger_if = {
		limit = { has_game_rule = hcq_authority_strict }
		custom_tooltip = {
			text = hcq_authority_strict_tt
			OR = {
				faith ?= { religious_head ?= root }
				rite ?= { head_of_rite ?= root }
			}
		}
	}
	trigger_else = {
		custom_tooltip = {
			text = hcq_authority_relaxed_tt
			OR = {
				faith ?= { religious_head ?= root }
				rite ?= { head_of_rite ?= root }
				AND = {
					is_independent_ruler = yes
					piety_level >= 3
				}
			}
		}
	}
}

# Faith scope: the faith can lose holy site $SITE$ without going below the minimums.
# An eminent site is first demoted, then removed.
hcq_faith_can_lose_site_trigger = {
	is_faith_holy_site = $SITE$
	trigger_if = {
		limit = { is_faith_eminent_holy_site = $SITE$ }
		list_size:eminent_holy_site > religion.eminent_holy_sites_min
	}
	trigger_else = {
		list_size:holy_site > religion.holy_sites_min
	}
}

# Faith scope: the faith has room for one more holy site.
hcq_faith_has_room_trigger = {
	list_size:holy_site < religion.holy_sites_max
}

# Character scope: can sanctify holy site $SITE$ right now (decision and event).
hcq_can_sanctify_site_trigger = {
	hcq_authority_trigger = yes
	$SITE$ = {
		custom_tooltip = {
			text = hcq_site_not_ours_tt
			root.faith = { NOT = { is_faith_holy_site = prev } }
		}
		custom_tooltip = {
			text = hcq_site_in_realm_tt
			holy_site_county.holder = { target_is_same_character_or_above = root }
		}
		custom_tooltip = {
			text = hcq_site_holder_faith_tt
			holy_site_county.holder.faith = root.faith
		}
	}
	custom_tooltip = {
		text = hcq_faith_has_room_tt
		faith = { hcq_faith_has_room_trigger = yes }
	}
}

# Character scope: can exile the other faiths from holy site $SITE$ right now.
hcq_can_exile_site_trigger = {
	hcq_authority_trigger = yes
	$SITE$ = {
		custom_tooltip = {
			text = hcq_site_in_realm_tt
			holy_site_county.holder = { target_is_same_character_or_above = root }
		}
		custom_tooltip = {
			text = hcq_site_holder_faith_tt
			holy_site_county.holder.faith = root.faith
		}
		custom_tooltip = {
			text = hcq_site_county_faith_tt
			holy_site_county.faith = root.faith
		}
		custom_tooltip = {
			text = hcq_site_has_rivals_tt
			save_temporary_scope_as = hcq_check_site
			any_holy_site_faith = {
				NOT = { this = root.faith }
				hcq_faith_can_lose_site_trigger = { SITE = scope:hcq_check_site }
			}
		}
	}
}

# Holy site scope: a great holy site, eminent for at least one faith other than root's.
hcq_is_major_site_trigger = {
	save_temporary_scope_as = hcq_major_check_site
	any_holy_site_faith = {
		NOT = { this = root.faith }
		is_faith_eminent_holy_site = scope:hcq_major_check_site
	}
}
