﻿# Pilgrims and Preachers - scripted triggers

# Saint scope. A dead saint of the employer's faith whose tomb lies outside the
# employer's own lands (otherwise they would extract the relic themselves).
ppr_valid_relic_saint_trigger = {
	is_alive = no
	# Always leave at least one relic for the ruler of the tomb
	remaining_saint_relics > 1
	saint_burial_location ?= {
		# One relic per tomb through contracts, for a few decades
		NOT = { has_variable = ppr_relic_taken }
		squared_distance = {
			target = $EMPLOYER$.capital_province
			value < squared_distance_large
		}
		NOT = {
			county.holder ?= { target_is_same_character_or_above = $EMPLOYER$ }
		}
	}
}

# Can $EMPLOYER$ offer a relic contract? (scope-independent; pass the employer)
ppr_can_offer_relic_contract_trigger = {
	has_pam_dlc_trigger = yes
	$EMPLOYER$ = {
		is_landed = yes
		exists = capital_province
	}
	$EMPLOYER$.faith = {
		any_saint = {
			ppr_valid_relic_saint_trigger = { EMPLOYER = $EMPLOYER$ }
		}
	}
	$EMPLOYER$ = {
		NOT = {
			any_character_artifact = { has_variable = pam_saint_relic_saint }
		}
	}
}

# Character scope. Heresiarch that an adventurer can be sent after.
# Only AI, unlanded heresiarchs: never a player, never a ruler.
ppr_valid_heresiarch_target_trigger = {
	is_alive = yes
	has_trait = heresiarch
	is_ai = yes
	is_landed = no
	is_imprisoned = no
	this != $EMPLOYER$
	religion = $EMPLOYER$.religion
	faith != $EMPLOYER$.faith
	location ?= {
		squared_distance = {
			target = $EMPLOYER$.capital_province
			value < squared_distance_large
		}
	}
}

# Employer scope. Can this ruler offer a heresiarch contract?
ppr_can_offer_heresiarch_contract_trigger = {
	# Saved because prev changes meaning inside the nested blocks of the target trigger
	save_temporary_scope_as = ppr_heresiarch_employer
	is_landed = yes
	exists = capital_province
	NOT = { has_trait = heresiarch }
	any_in_global_list = {
		variable = ppr_heresiarch_list
		ppr_valid_heresiarch_target_trigger = { EMPLOYER = scope:ppr_heresiarch_employer }
	}
}

# Employer scope. Can this ruler offer a preaching contract to $LAAMP$?
# Needs the DLC's tenet popularity, a shared faith, and a personal tenet
# the faith has not yet made core.
ppr_can_offer_preaching_contract_trigger = {
	has_pam_dlc_trigger = yes
	is_landed = yes
	faith = $LAAMP$.faith
	faith = { has_tenet_popularity_trigger = yes }
	any_personal_tenet = {
		ppr_tenet_not_core_for_trigger = { CHARACTER = prev }
	}
}

# Tenet scope. Is this tenet not yet core in $CHARACTER$'s rite?
ppr_tenet_not_core_for_trigger = {
	save_temporary_scope_as = ppr_tenet_check
	$CHARACTER$.rite = {
		NOT = {
			has_tenet_status = {
				tenet = scope:ppr_tenet_check
				status = core
			}
		}
	}
}

# Adventurer scope. Can take the camp act of devotion decision?
ppr_can_stage_camp_devotion_trigger = {
	has_pam_dlc_trigger = yes
	is_landless_adventurer = yes
	has_spiritual_fulfillment_type = christian_fulfillment
}
