﻿##############
# Decisions for PAM
# pam_decision_confession
# pam_decision_act_of_devotion
# pam_mentor_sp_decision
# pam_establish_theocratic_dynasty_decision
# pam_convert_to_theocracy_decision
# pam_convert_theocracy_to_feudal_decision
# pam_determine_patron_saint_decision
# pam_decision_last_rites
# create_hof_decision
# pam_levy_the_tithes_decision
# pam_send_legatine_mission_decision
# pam_reform_monastic_endowment_decision
# pam_kingdom_of_heaven_decision
# pam_shape_the_christian_church_decision
# pam_declare_rite_heresy_decision
# pam_permit_tenet_decision
# pam_prohibit_tenet_decision
# pam_raise_khachkar_decision
# pam_proclaim_crusade_age_tenet_decision
# pam_secure_pilgrim_routes_decision
# pam_prevent_great_schism_decision
# pam_cause_great_schism_decision
#################
pam_decision_confession = {
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					spiritual_fulfillment < 0
				}
				desc = pam_decision_confession_name_low
			}
			desc = pam_decision_confession_name
		}
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_confession.dds"
	}
	decision_group_type = religious
	
	desc = pam_decision_confession_desc
	selection_tooltip = pam_decision_confession_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	sort_order = 110
	
	is_shown = {
		has_spiritual_fulfillment_type = christian_fulfillment
		root.rite ?= {
			has_at_least_tenet_status = {
				tenet = tenet_confession
				status = permitted
			}
		}
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		NOT = { has_trait = excommunicated }
		custom_tooltip = {
			text = pam_decision_confession_sp_court_chaplain
			exists = cp:councillor_court_chaplain
		}
	}
	
	is_valid_showing_failures_only = {
		is_alive = yes
		is_in_activity = no
		is_imprisoned = no
		cp:councillor_court_chaplain ?= {
			is_available = yes
		}
	}

	cooldown = { years = 5 }

	effect = {
		if = {
			limit = { spiritual_fulfillment < 0 }
			custom_tooltip = pam_decision_confession_tooltip_sp_effect
		}
		custom_tooltip = pam_decision_confession_tooltip_stress_effect
		custom_tooltip = pam_decision_events.0001.a.confession_random_outcome
		trigger_event = pam_decision_events.0001
	}

	ai_potential = {
		stress_level >= 1
	}

	ai_will_do = {
		base = 35
		modifier = {
			stress_level >= 2
			add = 30
		}
		modifier = {
			stress_level >= 3
			add = 30
		}
		modifier = {
			has_trait = humble
			add = 20
		}
		modifier = {
			has_trait = zealous
			add = 20
		}
		modifier = {
			has_trait = cynical
			add = -40
		}
	}
}

# Stage an Act of Devotion
pam_decision_act_of_devotion = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_act_of_devotion.dds"
	}
	decision_group_type = religious
	
	desc = pam_decision_act_of_devotion_desc
	selection_tooltip = pam_decision_act_of_devotion_desc_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 60
		duchy = 60
		kingdom = 48
		empire = 48
		hegemony = 24
	}

	sort_order = 80
	
	is_shown = {
		has_spiritual_fulfillment_type = christian_fulfillment
		has_pam_dlc_trigger = yes
		is_landless_adventurer = no
	}

	is_valid = {
		is_at_war = no
		custom_tooltip = {
			text = pam_decision_act_of_devotion_sp_tooltip
			has_fulfillment_parameter = sp_act_of_devotion_decision
		}
	}
	
	is_valid_showing_failures_only = {
		is_available_quick = {
			alive = yes
			adult = yes
			at_war = no
			imprisoned = no
			activity = no
		}
	}

	cooldown = { years = 10 }
	
	cost = {
		piety = major_piety_value
	}

	effect = {
		custom_tooltip = pam_decision_act_of_devotion_tooltip_effect
		trigger_event = pam_decision_events.0002
		# Catalysts
		if = {
			limit = {
				has_pam_dlc_trigger = yes
				is_christian_trigger = yes
				situation:the_christian_church ?= {
					situation_top_has_catalyst = catalyst_the_christian_church_staged_act_of_devotion
				}
			}
			situation:the_christian_church = {
				trigger_situation_catalyst = catalyst_the_christian_church_staged_act_of_devotion
			}
		}
	}

	ai_potential = {
		piety >= major_piety_value
	}

	ai_will_do = {
		base = 20
		modifier = {
			prestige < major_prestige_value
			add = 5
		}
		modifier = {
			prestige < medium_prestige_value
			add = 10
		}
		modifier = {
			prestige < minor_prestige_value
			add = 10
		}
		modifier = {
			has_trait = arrogant
			add = 20
		}
	}
}

pam_mentor_sp_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_mentor_sp.dds"
	}
	decision_group_type = religious
	
	desc = pam_mentor_sp_decision_desc
	selection_tooltip = pam_mentor_sp_decision_desc_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	sort_order = 80
	
	is_shown = {
		has_spiritual_fulfillment_type = christian_fulfillment
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		is_at_war = no
		custom_tooltip = {
			text = pam_mentor_sp_decision_sp_tooltip
			has_fulfillment_parameter = sp_mentor_in_sp
		}
	}
	
	is_valid_showing_failures_only = {
		is_available_quick = {
			adult = yes
			at_war = no
			imprisoned = no
			activity = no
			incapable = no
		}
		custom_tooltip = {
			text = pam_mentor_sp_decision_valid_child_tt
			any_child = {
				age >= 16
				faith = root.faith
				NOT = { has_variable = pam_mentor_sp_taken_var }
				OR = {
					root.primary_heir ?= this
					has_relation_favorite_child = root
				}
				spiritual_fulfillment < 75
			}
		}
	}

	cooldown = { years = 15 }
	
	cost = {
		piety = major_piety_value
	}
	
	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = yes

		item = { # Primary Heir
			value = primary_heir
			is_valid = {
				custom_tooltip = {
					text = pam_mentor_sp_decision_primary_heir_tt
					any_child = {
						is_primary_heir_of = root
						age >= 16
						faith = root.faith
						NOT = { has_variable = pam_mentor_sp_taken_var }
						spiritual_fulfillment < 75
					}
				}
			}
			localization = pam_mentor_sp_decision_primary_heir_name
			icon = "gfx/interface/icons/message_feed/heir.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Favorite Child
			value = favorite_child
			is_valid = {
				custom_tooltip = { 
					text = pam_mentor_sp_decision_primary_favorite_child_tt
					any_relation = {
						type = favorite_child
						age >= 16
						faith = root.faith
						NOT = { has_variable = pam_mentor_sp_taken_var }
						spiritual_fulfillment < 75
					}
				}
			}
			localization = pam_mentor_sp_decision_primary_favorite_child_name
			icon = "gfx/interface/icons/character_interactions/designate_favorite.dds"
			ai_chance = {
				value = 0
			}
		}
	}

	effect = {
		custom_tooltip = pam_mentor_sp_decision_tooltip_effect
		trigger_event = pam_decision_events.0003
	}

	ai_potential = {
		piety >= major_piety_value
	}

	ai_will_do = {
		base = 20
		modifier = {
			has_trait = theologian
			add = 20
		}
		modifier = {
			has_trait = lifestyle_mystic
			add = 20
		}
	}
}

# Establish a Theocratic Dynasty
pam_establish_theocratic_dynasty_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_dynasty_house.dds"
	}
	sort_order = 200
	decision_group_type = major
	desc = pam_establish_theocratic_dynasty_decision_desc
	selection_tooltip = pam_establish_theocratic_dynasty_decision_desc_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 48
		kingdom = 24
		empire = 12
		hegemony = 12
	}

	sort_order = 110
	
	is_shown = {
		government_has_flag = government_is_theocracy
		is_lowborn = yes
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		prestige_level >= 3
		custom_description = {
			text = "church_authority_establish_dynasty_requirement"
			has_realm_law_flag = can_establish_theocratic_dynasty
		}
	}
	
	is_valid_showing_failures_only = {
		is_available_quick = {
			alive = yes
			adult = yes
			at_war = no
			imprisoned = no
			activity = no
		}
	}
	
	cost = {
		prestige = massive_prestige_value
	}

	effect = {
		custom_tooltip = pam_establish_theocratic_dynasty_decision_effects_tt
		show_as_tooltip = {
			pam_create_theocratic_dynasty_extra_effects = yes
		}
		trigger_event = pam_decision_events.0004
	}

	ai_potential = {
		prestige >= massive_prestige_value
	}

	ai_will_do = {
		base = 35
		modifier = {
			has_trait = arrogant
			add = 20
		}
		modifier = {
			has_trait = ambitious
			add = 20
		}
	}
}

# Adopt Theocratic Rule
pam_convert_to_theocracy_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"
	}
	decision_group_type = realm
	desc = pam_convert_to_theocracy_decision_desc
	selection_tooltip = pam_convert_to_theocracy_decision_tooltip

	ai_check_interval = 0

	is_shown = {
		highest_held_title_tier <= tier_duchy
		highest_held_title_tier >= tier_county
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_clan
			government_has_flag = government_is_japan_feudal
			government_has_flag = government_is_mandala
		}
		trigger_if = {
			limit = {
				exists = faith.religious_head
			}
			faith.religious_head = {
				NOT = { government_has_flag = government_is_ecclesiastical } #blocked for Christians as they should seek the Ecclesiastical path
			}
		}
		has_pam_dlc_trigger = yes
		is_ruler = yes
	}

	is_valid = {
		custom_tooltip = {
			text = HOF_INTERACTION_UNREFORMED_FAITH
			NOT = {
				faith = { has_doctrine_parameter = unreformed }
			}
		}
		piety_level >= medium_piety_level
		liege = {
			trigger_if = {
				limit = {
					this != root
					government_has_flag = government_is_theocracy
				}
				custom_tooltip = {
					text = same_faith_as_liege
					OR = {
						religion = liege.religion
						faith = {
							faith_hostility_level = {
								target = root.liege.faith
								value <= faith_fully_accepted_level
							}
						}
					}
				}
				custom_tooltip = {
					text = same_culture_as_liege
					OR = {
						culture = liege.culture
						culture = {
							cultural_acceptance = { target = root.liege.culture value >= 90 }
						}
					}
				}
			}
			trigger_else = {
				NOT = { rite = { rite_has_doctrine = doctrine_theocracy_lay_clergy } }
			}
		}
		trigger_if = {
			limit = {
				faith = {
					exists = religious_head
				}
			}
			OR = {
				custom_tooltip = {
					text = empire_faith_gate_hof_temporal_is_hof
					this = faith.religious_head
				}
				custom_tooltip = {
					text = different_rite_than_hof
					rite != faith.main_rite
					rite = { "divergence(faith.main_rite)" >= faith.heresy_threshold }
				}
				rite = { rite_has_parameter = no_head_of_faith }
			}
		}
		trigger_if = {
			limit = {
				top_liege = this
				is_ai = no
			}
			custom_tooltip = {
				text = all_powerful_vassals_required_tt
				any_powerful_vassal = {
					count = all
					opinion = {
						target = root
						value >= 50
					}
				}
			}
		}
		trigger_if = {
			limit = { is_ai = yes }
			calc_true_if = {
				amount >= 2
				has_trait = zealous
				rite = { rite_has_doctrine = doctrine_theocracy_temporal }
				rite = { rite_has_tenet = tenet_communal_identity }
				culture = { has_cultural_pillar = ethos_spiritual }
				culture = { has_cultural_pillar = ethos_communal }
				culture = { has_cultural_tradition = tradition_monastic_communities }
				dynasty = { has_dynasty_perk = erudition_legacy_2 }
				dynasty = { has_dynasty_perk = erudition_legacy_4 }
				dynasty = { has_dynasty_perk = glory_legacy_5 }
				dynasty = { has_dynasty_perk = law_legacy_2 }
			}
		}
	}

	is_valid_showing_failures_only = {
		is_at_war = no
	}
	cost = {
		piety = massive_piety_value
		prestige = massive_prestige_value
	}

	effect = {
		show_as_tooltip = {
			primary_title = {
				every_title_heir = {
					add_opinion = {
						modifier = angry_opinion
						target = root
						opinion = -50
					}
				}
			}
			change_government = theocracy_government
		}
		hidden_effect = {
			every_held_title = {
				title_tier >= county
				every_title_heir = {
					add_to_list = heirs
				}
			}
			every_in_list = {
				list = heirs
				add_opinion = {
					modifier = angry_opinion
					target = root
					opinion = -50
				}
			}
		}
		government_type = {
			save_scope_as = old_government
		}
		add_piety_level = 1
		trigger_event = pam_decision_events.0009
		hidden_effect = {
			save_scope_as = theocratic_ruler
			every_vassal_or_below = {
				trigger_event = {
					id = pam_decision_events.0010
					days = 1
				}
			}
		}
	}

	ai_potential = {
		prestige >= massive_prestige_value
		piety >= massive_piety_value
		piety_level >= high_piety_level
	}

	ai_will_do = {
		base = 0
	}
}

# Restore Temporal Rule
pam_convert_theocracy_to_feudal_decision = {
	picture = {
		trigger = {
			has_tgp_dlc_trigger = yes
			liege = {
				culture = { has_cultural_pillar = heritage_japonic }
			}
		}
		reference = "gfx/interface/illustrations/decisions/tgp_dominance.dds"
	}
	picture = {
		trigger = {
			liege = {
				government_has_flag = government_is_clan
			}
		}
		reference = "gfx/interface/illustrations/event_scenes/bp1_courtyard_mena.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_realm.dds"
	}
	decision_group_type = realm
	desc = pam_convert_theocracy_to_feudal_decision_desc
	selection_tooltip = pam_convert_theocracy_to_feudal_decision_tooltip

	ai_check_interval = 0

	is_shown = {
		government_has_flag = government_is_theocracy
		is_landed = yes
		has_pam_dlc_trigger = yes
		NOT = { any_held_title = { is_head_of_faith = yes } }
		rite.head_of_rite != root
	}

	is_valid = {
		trigger_if = {
			limit = {
				top_liege = this
				is_ai = no
			}
			prestige_level >= high_prestige_level
		}
		trigger_if = {
			limit = {
				top_liege = this
				is_ai = no
			}
			custom_tooltip = {
				text = all_powerful_vassals_required_tt
				any_powerful_vassal = {
					count = all
					opinion = {
						target = root
						value >= 50
					}
				}
			}
		}
		trigger_if = {
			limit = { is_ai = yes }
			calc_true_if = {
				amount >= 2
				prestige_level >= high_prestige_level
				has_trait = cynical
				culture = { has_cultural_pillar = ethos_bureaucratic }
				culture = { has_cultural_pillar = ethos_courtly }
				culture = { has_cultural_pillar = ethos_stoic }
				culture = { has_cultural_tradition = tradition_legalistic }
				has_realm_law = church_authority_3
				capital_county = { development_level > medium_development_level }
				dynasty ?= { has_dynasty_perk = law_legacy_5 }
				dynasty ?= { has_dynasty_perk = erudition_legacy_5 }
				NOT = { has_trait = zealous }
				NOT = { rite = { rite_has_doctrine = doctrine_theocracy_temporal } }
			}
		}
		is_landed = yes
	}

	is_valid_showing_failures_only = {
		is_at_war = no
		custom_tooltip = {
			text = is_antipope_blocked_tt
			pam_is_antipope_trigger = no
		}
	}
	cost = {
		prestige = major_prestige_value
	}

	effect = {
		if = {
			limit = {
				government_has_flag = government_is_ecclesiastical
			}
			if = {
				limit = {
					exists = faith.religious_head
					can_set_relation_rival_trigger = { CHARACTER = faith.religious_head }
				}
				progress_towards_rival_effect = {
					REASON = rival_refuted_faith
					CHARACTER = faith.religious_head
					OPINION = default_rival_opinion
				}
			}
			else_if = {
				limit = {
					exists = rite.head_of_rite
					can_set_relation_rival_trigger = { CHARACTER = rite.head_of_rite }
				}
				progress_towards_rival_effect = {
					REASON = rival_refuted_faith
					CHARACTER = rite.head_of_rite
					OPINION = default_rival_opinion
				}
			}
			if = {
				limit = { exists = clerical_elector_title }
				destroy_title = clerical_elector_title
				remove_character_flag = cardinal_flag
			}
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			every_held_title = {
				limit = {
					has_clerical_region = yes
				}
				change_title_holder_include_vassals = {
					holder = current_heir
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
		trigger_event = major_decisions.0001
		convert_whole_realm_to_feudalism_effect = yes
		add_piety_level = -1
		hidden_effect = {
			save_scope_as = actor
			every_vassal = {
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
		}
	}

	ai_potential = {
		prestige >= major_prestige_value
		piety_level < 1
		NOT = { government_has_flag = government_is_ecclesiastical }
	}

	ai_will_do = {
		base = 0
	}
}

### Kowtow to the Pope ###
pam_kowtow_to_pope_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_legitimacy.dds"
	}
	decision_group_type = religious
	sort_order = 90
	desc = pam_kowtow_to_pope_decision_desc
	selection_tooltip = pam_kowtow_to_pope_decision_tooltip
	confirm_text = pam_kowtow_to_pope_decision_confirm

	ai_check_interval = 24

	is_shown = {
		exists = top_participant_group:the_christian_church
		situation:the_christian_church ?= {
			situation_current_phase = investiture_crisis
		}
		government_is_religious_trigger = no
		is_christian_trigger = yes
		has_pam_dlc_trigger = yes
	}

	is_valid_showing_failures_only = {
		is_available_quick = {
			alive = yes
			adult = yes
			imprisoned = no
		}
		custom_tooltip = {
			text = pam_kowtow_to_pope_not_already_pledged_tt
			NAND = {
				has_variable = investiture_stance
				var:investiture_stance = flag:spiritual_revocable
			}
		}
		custom_tooltip = {
			text = pam_kowtow_to_pope_needs_head_of_faith_tt
			exists = faith.religious_head
		}
	}

	cost = { piety = major_piety_value }

	effect = {
		set_variable = {
			name = investiture_stance
			value = flag:spiritual_revocable
		}
		# Symbolic, visible marker of the pledge (cleared by the end-of-crisis council).
		add_character_modifier = pam_kowtowed_to_pope_modifier
		# The Head of Faith is pleased by the public submission
		if = {
			limit = { exists = faith.religious_head }
			reverse_add_opinion = {
				target = faith.religious_head
				modifier = grateful_opinion
				opinion = 20
			}
		}
		send_interface_toast = {
			type = event_toast_effect_good
			title = pam_kowtow_to_pope_toast
			left_icon = root
			right_icon = faith.religious_head
			# Mechanical explanation, shown both in the decision's effect tooltip and in the toast
			custom_tooltip = pam_kowtow_to_pope_effect_tt
		}
	}

	ai_potential = {
		has_pam_dlc_trigger = yes
		government_is_religious_trigger = no
	}

	ai_will_do = {
		base = 25
		modifier = {
			add = 25
			piety_level >= 2
		}
		modifier = {
			add = 20
			is_at_war = yes
		}
		modifier = {
			add = -40
			has_trait = ambitious
		}
	}
}

### Determine Patron Saint ###
pam_determine_patron_saint_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_legitimacy.dds"
	}
	decision_group_type = religious
	sort_order = 100
	desc = pam_determine_patron_saint_decision_desc
	selection_tooltip = pam_determine_patron_saint_decision_tooltip

	is_shown = {
		# Christian specific
		is_christian_trigger = yes
		NOT = { has_variable = pam_chose_patron_saint_var }
		has_pam_dlc_trigger = yes
	}

	is_valid_showing_failures_only = {
		piety_level > 0
		custom_tooltip = {
			text = pam_determine_patron_saint_decision_dulia_tt
			rite = {
				has_at_least_tenet_status = {
					tenet = tenet_dulia
					status = permitted
				}
			}		
		}
		custom_tooltip = {
			text = pam_determine_patron_saint_decision_personal_tenet_tt
			has_personal_tenet_flag = tenet_dulia_can_select_patron_saint
		}
	}
	
	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = yes

		item = { # Saint Peter
			value = peter
			localization = pam_determine_patron_saint_decision_peter
			icon = "gfx/interface/icons/artifact/artifact_rock.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Saint Paul
			value = paul
			localization = pam_determine_patron_saint_decision_paul
			icon = "gfx/interface/icons/court_position_types/court_tutor_court_position.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Saint John
			value = john
			localization = pam_determine_patron_saint_decision_john
			icon = "gfx/interface/icons/court_position_types/cupbearer_court_position.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Saint Matthew
			value = matthew
			localization = pam_determine_patron_saint_decision_matthew
			icon = "gfx/interface/icons/court_position_types/bookmaker_court_position.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Saint Mark
			value = mark
			localization = pam_determine_patron_saint_decision_mark
			icon = "gfx/interface/icons/traits/knight_of_the_lion.dds"
			ai_chance = {
				value = 100
			}
		}
		item = { # Saint Luke
			value = luke
			localization = pam_determine_patron_saint_decision_luke
			icon = "gfx/interface/icons/trait_level_tracks/lifestyle_physician.dds"
			ai_chance = {
				value = 100
			}
		}
	}

	effect = {
		set_variable = pam_chose_patron_saint_var
		if = {
			limit = {
				scope:peter = yes
			}
			add_character_modifier = pam_patron_saint_peter
		}
		else_if = {
			limit = {
				scope:paul = yes
			}
			add_character_modifier = pam_patron_saint_paul
		}
		else_if = {
			limit = {
				scope:john = yes
			}
			add_character_modifier = pam_patron_saint_john
		}
		else_if = {
			limit = {
				scope:matthew = yes
			}
			add_character_modifier = pam_patron_saint_matthew
		}
		else_if = {
			limit = {
				scope:mark = yes
			}
			add_character_modifier = pam_patron_saint_mark
		}
		else = {
			add_character_modifier = pam_patron_saint_luke
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 96
		duchy = 96
		kingdom = 96
		empire = 96
		hegemony = 96
	}

	ai_potential = {
		NOT = { has_variable = pam_chose_patron_saint_var }
		piety_level > 1
	}

	ai_will_do = {
		base = 100
	}
}

# Last Rites
# Laurence Kennedy
pam_decision_last_rites = {
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					spiritual_fulfillment < 0
				}
				desc = pam_decision_last_rites_name_low
			}
			desc = pam_decision_last_rites_name
		}
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_last_rites.dds"
	}
	decision_group_type = major
	desc = pam_decision_last_rites_desc
	selection_tooltip = pam_decision_last_rites_tooltip
	cooldown = { years = 15 }
	sort_order = 70
	ai_check_interval = 0
	is_shown = {
		is_ai = no
		has_pam_dlc_trigger = yes
		has_spiritual_fulfillment_type = christian_fulfillment
		OR = {
			health <= death_chance_dying_health
			has_character_flag = about_to_die_but_not_dead_yet_flag
		} 	
	}

	is_valid = {
		NOT = { has_trait = excommunicated }
		custom_tooltip = {
			text = pam_decision_last_rites_doctrine_tt
			rite = {
				rite_has_parameter = last_rites_active
			}
		}
	}
	
	is_valid_showing_failures_only = {
		is_alive = yes
		is_adult = yes
	}

	effect = {
		custom_tooltip = pam_decision_events.0005.no_last_rites_warning
		custom_tooltip = pam_decision_events.0005.secret_reveal
		custom_tooltip = pam_decision_last_rites_tooltip_sp_effect
		custom_tooltip = pam_decision_events.0005.details
		add_character_flag = did_last_rites_flag
		trigger_event = pam_decision_events.0005
	}
	
	ai_potential = {
		always = no
	}

	ai_will_do = {
		base = 0
	}
}

create_hof_decision = {
	picture = {
		trigger = { religion = religion:islam_religion }
		reference = "gfx/interface/illustrations/holding_types/temple_islamic.dds"
	}
	picture = {
		trigger = { religion = religion:judaism_religion }
		reference = "gfx/interface/illustrations/holding_types/temple_generic_arid.dds"
	}
	picture = {
		trigger = {
			OR = {
				religion = religion:zoroastrianism_religion
				religion = religion:dualism_religion
			}
		}
		reference = "gfx/interface/illustrations/holding_types/fp3_temple_iranian_zoroastrian.dds"
	}
	picture = {
		trigger = { religion = religion:shintoism_religion }
		reference = "gfx/interface/illustrations/holding_types/tgp_shinto_temple.dds"
	}
	picture = {
		trigger = { faith.religion = { is_in_family = rf_sinitic } }
		reference = "gfx/interface/illustrations/holding_types/tgp_chinese_pagoda.dds"
	}
	picture = {
		trigger = { faith.religion = { is_in_family = rf_eastern } }
		reference = "gfx/interface/illustrations/holding_types/temple_india.dds"
	}
	picture = {
		trigger = { religion = religion:tengrism_religion }
		reference = "gfx/interface/illustrations/holding_types/mpo_temple_steppe.dds"
	}
	picture = {
		trigger = {
			OR = {
				religion = religion:germanic_religion
				religion = religion:baltic_religion
				religion = religion:finno_ugric_religion
				religion = religion:slavic_religion
				religion = religion:magyar_religion
			}
		}
		reference = "gfx/interface/illustrations/holding_types/temple_northern_pagan.dds"
	}
	picture = {
		trigger = { faith.religion = { is_in_family = rf_pagan } }
		reference = "gfx/interface/illustrations/event_scenes/ep2_holysite_tribal.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_create_hof.dds"
	}
	decision_group_type = major

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 24
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_shown = {
		# The decision needs a landed ruler to control a holy site and found the title.
		is_landed = yes
		faith ?= {
			OR = {
				has_doctrine_parameter = spiritual_head_of_faith
				has_doctrine_parameter = temporal_head_of_faith
			}
			NOT = { exists = religious_head }
			NOT = { has_doctrine_parameter = block_from_create_hof_parameter }
		}
	}

	is_valid = {
		is_landed = yes
		can_create_head_of_faith_title_trigger = { FAITH = root.faith } # Includes Schism requirements
	}

	cost = {
		treasury_or_gold = create_hof_gold_cost
		piety = create_hof_piety_cost
	}

	effect = {
		faith = { save_scope_as = faith }
		# Tell the player who will actually receive the title
		if = {
			limit = { faith = { has_doctrine_parameter = temporal_head_of_faith } }
			custom_tooltip = create_hof_decision_temporal_self_tt
		}
		else_if = {
			limit = { is_clergy = yes }
			custom_tooltip = create_hof_decision_spiritual_self_tt
		}
		else_if = {
			limit = { puppet:theological_agent_puppet ?= { rite = root.rite } }
			custom_tooltip = create_hof_decision_spiritual_puppet_tt
		}
		else_if = {
			limit = { puppet:external_theological_agent_puppet ?= { rite = root.rite } }
			custom_tooltip = create_hof_decision_spiritual_external_puppet_tt
		}
		else_if = {
			limit = { cp:councillor_court_chaplain ?= { rite = root.rite } }
			custom_tooltip = create_hof_decision_spiritual_realm_priest_tt
		}
		else = {
			custom_tooltip = create_hof_decision_spiritual_other_tt
		}
		if = {
			limit = {
				faith = { has_doctrine_parameter = spiritual_head_of_faith }
				NOT = { rite = faith.main_rite }
			}
			custom_tooltip = create_hof_decision_mainline_rite_tt
		}
		if = {
			limit = {
				faith = { has_doctrine_parameter = spiritual_head_of_faith }
				is_clergy = no
			}
			custom_tooltip = create_hof_decision_landed_hof_warning_tt
		}
		force_create_head_of_faith_title_effect = yes
	}

	ai_potential = {
		is_adult = yes
		# Defer to a same-faith liege; they should be the one establishing the HoF
		OR = {
			top_liege = this
			NOT = {
				any_liege_or_above = {
					faith = root.faith
				}
			}
		}
	}

	ai_will_do = {
		base = 100
	}
}

# Levy the Tithes
pam_levy_the_tithes_decision = {
	picture = {
		trigger = { culture = { has_graphical_east_asia_culture_group_trigger = yes } }
		reference = "gfx/interface/illustrations/decisions/tgp_scholars.dds"
	}
	decision_group_type = religious
	picture = {
		trigger = { culture = { has_graphical_mena_culture_group_trigger = yes } }
		reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_spend_money.dds"
	}

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	is_shown = {
		any_character_situation = { # You are part of the Christian Situation
			situation_type = the_christian_church
		}
		has_pam_dlc_trigger = yes
		is_clergy = no
		is_ruler = yes
	}

	is_valid = {
		custom_tooltip = {
			text = pam_christian_church_instability_tt
			top_participant_group:the_christian_church ?= {
				has_participant_group_parameter = the_christian_church_levy_the_tithes_decision
			}
		}
		any_vassal = {
			custom_tooltip = {
				text = pam_levy_the_tithes_decision_theocracy_tt
				government_has_flag = government_is_theocracy
			}
		}
	}

	cooldown = { years = 10 }

	cost = {
		piety = {
			value = major_piety_value
			multiply = spiritual_fulfillment_tithe_legate_cost_mult
		}
	}

	effect = {
		show_as_tooltip = {
			pam_levy_the_tithes_decision_effects = yes
		}
		if = {
			limit = {
				NOT = { any_vassal = { government_has_flag = government_is_theocracy } }
			}
			custom_tooltip = pam_levy_the_tithes_decision_effects_no_vassals_tt
		}
		trigger_event = pam_decision_events.0008
	}

	ai_potential = {
		ai_greed > medium_positive_ai_value
		NOR = {
			has_trait = content
			has_trait = craven
		}
	}

	ai_will_do = {
		base = 10

		modifier = {
			add = 25
			has_trait = greedy
		}
	}
}

# Send Legatine Mission
pam_send_legatine_mission_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_misc.dds"
	}
	decision_group_type = religious

	desc = pam_send_legatine_mission_decision_desc
	selection_tooltip = pam_send_legatine_mission_decision_tooltip

	sort_order = 109

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 24
		empire = 12
		hegemony = 12
	}

	is_shown = {
		is_clergy = yes
		any_sub_realm_county = {
			always = yes
		}
		has_pam_dlc_trigger = yes
		is_ruler = yes
		exists = top_participant_group:the_christian_church
	}

	is_valid = {
		custom_tooltip = {
			text = pam_send_legatine_mission_decision_parameter_tt
			top_participant_group:the_christian_church ?= {
				has_participant_group_parameter = the_christian_church_legatine_mission
			}
		}
	}

	is_valid_showing_failures_only = {
		is_physically_able = yes
		is_in_activity = no
		scope:selected_item ?= {
			tier = tier_county
			holder = {
				OR = {
					this = root
					target_is_liege_or_above = root
				}
			}
		}
	}

	cooldown = { years = 10 }

	cost = {
		treasury = {
			value = major_gold_value
			multiply = spiritual_fulfillment_tithe_legate_cost_mult
		}
	}

	widget = {
		gui = "decision_view_widget_select_realm_county"
		controller = select_scope_object

		setup_items = {
			scope:actor = {
				every_sub_realm_county = {
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				capital_county = {
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			tier = tier_county
		}

		ai_item_will_do = {
			value = 10
			if = {
				limit = {
					this = scope:actor.capital_county
				}
				add = 10
			}
			if = {
				limit = {
					development_level <= bad_development_level
				}
				add = 10
			}
			if = {
				limit = {
					county_control <= 50
				}
				add = 50
			}
		}
	}

	effect = {
		custom_tooltip = pam_send_legatine_mission_decision_effect_tt
		hidden_effect = {
			scope:actor = {
				send_interface_toast = {
					type = event_toast_effect_good
					title = pam_send_legatine_mission_decision_toast
					right_icon = scope:selected_item
					scope:selected_item = {
						add_county_modifier = {
							modifier = pam_under_legatine_scrutiny_county_modifier
							years = 10
						}
					}
				}
			}
		}
	}

	ai_potential = {
		treasury >= major_gold_value
		any_sub_realm_county = {
			always = yes
		}
	}

	ai_will_do = {
		base = 25
		modifier = {
			add = 20
			has_trait = diligent
		}
		modifier = {
			add = 40
			ai_has_builder_or_pious_builder_personality = yes
		}
	}
}

# Reform Monastic Endowment
pam_reform_monastic_endowment_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_reform_monastic_endowment.dds"
	}
	decision_group_type = religious

	desc = pam_reform_monastic_endowment_decision_desc
	selection_tooltip = pam_reform_monastic_endowment_decision_tooltip

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 36
		empire = 24
		hegemony = 24
	}

	is_shown = {
		exists = top_participant_group:the_christian_church
		has_pam_dlc_trigger = yes
		is_ruler = yes
	}

	is_valid = {
		custom_tooltip = {
			text = pam_reform_monastic_endowment_decision_patron_tt
			any_patroned_holy_order = {
				leader = {
					government_has_flag = government_is_monastic_holy_order
				}
			}
		}
		custom_tooltip = {
			text = pam_reform_monastic_endowment_decision_parameter_tt
			top_participant_group:the_christian_church ?= {
				has_participant_group_parameter = the_christian_church_reform_monastic_endowment
			}
		}
	}

	is_valid_showing_failures_only = {
		is_physically_able = yes
		is_in_activity = no
	}

	cooldown = { years = 5 }

	cost = {
		gold = pam_reform_monastic_endowment_gold_cost_value # Scaled by Holy Order count
	}

	effect = {
		send_interface_toast = {
			title = pam_reform_monastic_endowment_decision_toast
			left_icon = root
			add_piety = pam_reform_monastic_endowment_piety_gain_value
			change_spiritual_fulfillment = pam_reform_monastic_endowment_sp_gain_value
			every_patroned_holy_order = {
				limit = {
					leader = {
						government_has_flag = government_is_monastic_holy_order
					}
				}
				leader = {
					add_opinion = {
						target = root
						modifier = pam_reform_monastic_endowment_grandmaster_opinion
					}
				}
			}
		}
	}

	ai_potential = {
		short_term_gold >= pam_reform_monastic_endowment_gold_cost_value
		any_patroned_holy_order = {
			leader = {
				government_has_flag = government_is_monastic_holy_order
			}
		}
	}

	ai_will_do = {
		base = 15
		modifier = {
			add = 25
			ai_has_pious_builder_personality = yes
		}
		modifier = {
			add = 15
			has_trait = zealous
		}
		modifier = {
			add = -20
			short_term_gold < major_gold_value
		}
	}
}

# Shape the Christian Church
# pam_shape_the_christian_church_decision = {
# 	picture = {
# 		reference = "gfx/interface/illustrations/decisions/pam_decision_shape_the_christian_church.dds"
# 	}
# 	decision_group_type = religious

# 	desc = pam_shape_the_christian_church_decision_desc
# 	selection_tooltip = pam_shape_the_christian_church_decision_tooltip
# 	sort_order = 112

# 	is_shown = {
# 		exists = top_participant_group:the_christian_church
# 		# The Controversy phase only exits through the Council ruling
# 		NOT = {
# 			situation:the_christian_church ?= {
# 				has_situation_top_phase_parameter = the_christian_church_investiture_controversy
# 			}
# 		}
# 		has_pam_dlc_trigger = yes
# 	}

# 	is_valid_showing_failures_only = {
# 		is_available_adult = yes
# 		NOT = { has_trait = excommunicated }
# 	}

# 	is_valid = {
# 		OR = {
# 			any_held_title = { is_head_of_faith = yes }
# 			custom_tooltip = {
# 				text = pam_shape_the_christian_church_decision_hor_tt
# 				rite.head_of_rite ?= this
# 			}
# 			custom_tooltip = {
# 				text = pam_shape_the_christian_church_decision_cardinal_tt
# 				exists = clerical_elector_title
# 			}
# 			custom_tooltip = {
# 				text = pam_shape_the_christian_church_decision_archbishop_tt
# 				any_held_title = { has_clerical_region = yes }
# 			}
# 			highest_held_title_tier >= tier_empire
# 			AND = {
# 				highest_held_title_tier >= tier_kingdom
# 				OR = {
# 					has_trait = lifestyle_scholar
# 					has_trait = theologian
# 					piety_level >= 3
# 				}
# 			}
# 			custom_tooltip = {
# 				text = pam_shape_the_christian_church_decision_dynasty_tt
# 				dynasty ?= { has_dynasty_perk = pam_legacy_5 }
# 			}
# 		}
# 	}

# 	cooldown = { years = 10 }

# 	cost = {
# 		piety = major_piety_value
# 	}

# 	widget = {
# 		gui = "decision_view_widget_generic_multichoice_with_effects"
# 		controller = decision_option_list_controller
# 		decision_to_second_step_button = "SELECT_ACTION"
# 		show_from_start = yes

# 		item = {
# 			value = push_fragile_unity
# 			current_description = pam_shape_the_christian_church_push_fragile_unity_desc
# 			localization = pam_shape_the_christian_church_push_fragile_unity_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/fragile_unity.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = saeculum_obscurum
# 						situation_current_phase = conversion_phase
# 						situation_current_phase = investiture_crisis
# 						situation_current_phase = crusade_phase
# 						situation_current_phase = concord
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 						pam_is_the_christian_church_main_power_trigger = no
# 					}
# 					add = 25
# 				}
# 				if = { limit = { has_trait = content } add = 12 }
# 				if = { limit = { has_trait = humble } add = 12 }
# 				if = { limit = { has_trait = patient } add = 10 }
# 				if = { limit = { has_trait = lazy } add = 10 }
# 				if = { limit = { has_trait = craven } add = 10 }
# 				if = { limit = { has_trait = fickle } add = 10 }
# 				if = { limit = { has_trait = paranoid } add = 8 }
# 				if = { limit = { has_trait = calm } add = 8 }
# 			}
# 		}

# 		item = {
# 			value = push_saeculum_obscurum
# 			current_description = pam_shape_the_christian_church_push_saeculum_obscurum_desc
# 			localization = pam_shape_the_christian_church_push_saeculum_obscurum_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/saeculum_obscurum.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = reform_phase
# 						situation_current_phase = fragile_unity
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 						pam_is_the_christian_church_main_power_trigger = no
# 					}
# 					add = 25
# 				}
# 				if = { limit = { has_trait = lustful } add = 14 }
# 				if = { limit = { has_trait = deceitful } add = 14 }
# 				if = { limit = { has_trait = greedy } add = 12 }
# 				if = { limit = { has_trait = gluttonous } add = 10 }
# 				if = { limit = { has_trait = cynical } add = 12 }
# 				if = { limit = { has_trait = lifestyle_reveler } add = 14 }
# 				if = { limit = { has_trait = arbitrary } add = 10 }
# 				if = { limit = { has_trait = sadistic } add = 8 }
# 			}
# 		}

# 		item = {
# 			value = push_conversion
# 			current_description = pam_shape_the_christian_church_push_conversion_desc
# 			localization = pam_shape_the_christian_church_push_conversion_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/conversion.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = saeculum_obscurum
# 						situation_current_phase = investiture_crisis
# 						situation_current_phase = concord
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 					}
# 					add = 6
# 					if = { limit = { ai_zeal >= medium_positive_ai_value } add = 10 }
# 					if = { limit = { ai_energy >= medium_positive_ai_value } add = 6 }
# 				}
# 				if = { limit = { has_trait = zealous } add = 16 }
# 				if = { limit = { has_trait = brave } add = 12 }
# 				if = { limit = { has_trait = diligent } add = 10 }
# 				if = { limit = { has_trait = ambitious } add = 10 }
# 				if = { limit = { has_trait = lifestyle_hunter } add = 14 }
# 				if = { limit = { has_trait = wrathful } add = 8 }
# 			}
# 		}

# 		item = {
# 			value = push_reform
# 			current_description = pam_shape_the_christian_church_push_reform_desc
# 			localization = pam_shape_the_christian_church_push_reform_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/reform.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = saeculum_obscurum
# 						situation_current_phase = conversion_phase
# 						situation_current_phase = investiture_crisis
# 						situation_current_phase = crusade_phase
# 						situation_current_phase = concord
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 					}
# 					add = 6
# 					if = { limit = { ai_honor >= medium_positive_ai_value } add = 10 }
# 					if = { limit = { ai_energy >= medium_positive_ai_value } add = 6 }
# 				}
# 				if = { limit = { has_trait = zealous } add = 12 }
# 				if = { limit = { has_trait = just } add = 14 }
# 				if = { limit = { has_trait = honest } add = 10 }
# 				if = { limit = { has_trait = temperate } add = 10 }
# 				if = { limit = { has_trait = lifestyle_mystic } add = 12 }
# 				if = { limit = { has_trait = theologian } add = 16 }
# 				if = { limit = { has_trait = stubborn } add = 8 }
# 			}
# 		}

# 		item = {
# 			value = push_investiture_crisis
# 			current_description = pam_shape_the_christian_church_push_investiture_crisis_desc
# 			localization = pam_shape_the_christian_church_push_investiture_crisis_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/investiture.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = fragile_unity
# 						situation_current_phase = reform_phase
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						government_is_religious_trigger = no
# 						highest_held_title_tier >= tier_kingdom
# 					}
# 					add = 25
# 				}
# 				if = {
# 					limit = {
# 						OR = {
# 							any_held_title = {
# 								OR = {
# 									is_head_of_faith = yes
# 									has_clerical_region = yes
# 								}
# 							}
# 							rite.head_of_rite ?= this
# 							exists = clerical_elector_title
# 						}
# 						faith ?= { has_doctrine = doctrine_clerical_succession_conditional }
# 					}
# 					add = 25
# 				}
# 				if = { limit = { has_trait = ambitious } add = 16 }
# 				if = { limit = { has_trait = arrogant } add = 12 }
# 				if = { limit = { has_trait = greedy } add = 10 }
# 				if = { limit = { has_trait = cynical } add = 10 }
# 				if = { limit = { has_trait = deceitful } add = 8 }
# 				if = { limit = { has_trait = stubborn } add = 10 }
# 			}
# 		}

# 		item = {
# 			value = push_crusade
# 			current_description = pam_shape_the_christian_church_push_crusade_desc
# 			localization = pam_shape_the_christian_church_push_crusade_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/crusade.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = concord
# 						situation_current_phase = saeculum_obscurum
# 						situation_current_phase = investiture_crisis
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 					}
# 					add = 6
# 					if = { limit = { ai_zeal >= medium_positive_ai_value } add = 8 }
# 					if = { limit = { ai_boldness >= medium_positive_ai_value } add = 10 }
# 				}
# 				if = { limit = { has_trait = crusader_king } add = 25 }
# 				if = { limit = { has_trait = zealous } add = 14 }
# 				if = { limit = { has_trait = brave } add = 12 }
# 				if = { limit = { has_trait = wrathful } add = 10 }
# 				if = { limit = { has_trait = ambitious } add = 10 }
# 				if = { limit = { has_trait = lifestyle_blademaster } add = 14 }
# 				if = { limit = { has_trait = callous } add = 8 }
# 			}
# 		}

# 		item = {
# 			value = push_concord
# 			current_description = pam_shape_the_christian_church_push_concord_desc
# 			localization = pam_shape_the_christian_church_push_concord_name
# 			icon = "gfx/interface/icons/the_christian_church/phase_type_icons/concord.dds"
# 			is_shown = {
# 				situation:the_christian_church ?= {
# 					OR = {
# 						situation_current_phase = fragile_unity
# 						situation_current_phase = conversion_phase
# 						situation_current_phase = reform_phase
# 						situation_current_phase = crusade_phase
# 					}
# 				}
# 			}
# 			ai_chance = {
# 				value = 0
# 				if = {
# 					limit = {
# 						any_held_title = { is_head_of_faith = yes }
# 						pam_is_the_christian_church_main_power_trigger = yes
# 					}
# 					add = 6
# 					if = { limit = { ai_rationality >= medium_positive_ai_value } add = 10 }
# 					if = { limit = { ai_boldness <= low_negative_ai_value } add = 6 }
# 				}
# 				if = {
# 					limit = {
# 						is_clergy = no
# 						has_trait = lifestyle_scholar
# 					}
# 					add = 8
# 				}
# 				if = {
# 					limit = {
# 						is_clergy = no
# 						has_trait = theologian
# 					}
# 					add = 8
# 				}
# 				if = { limit = { has_trait = patient } add = 12 }
# 				if = { limit = { has_trait = calm } add = 12 }
# 				if = { limit = { has_trait = humble } add = 10 }
# 				if = { limit = { has_trait = temperate } add = 10 }
# 				if = { limit = { has_trait = just } add = 8 }
# 				if = {
# 					limit = {
# 						is_clergy = no
# 						NOT = { faith.religious_head ?= this }
# 					}
# 					multiply = 0.5
# 				}
# 			}
# 		}
# 	}

# 	effect = {
# 		add_character_flag = {
# 			flag = pam_shaped_the_christian_church_recently
# 			years = 20
# 		}
# 		situation:the_christian_church ?= {
# 			switch = {
# 				trigger = yes
# 				scope:push_fragile_unity = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_fragile_unity
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_fragile_unity_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_fragile_unity_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_fragile_unity_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_fragile_unity_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_fragile_unity
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_fragile_unity }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_saeculum_obscurum = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_saeculum_obscurum
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_saeculum_obscurum_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_saeculum_obscurum_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_saeculum_obscurum_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_saeculum_obscurum_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_saeculum_obscurum
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_saeculum_obscurum }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_conversion = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_conversion_phase
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_conversion_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_conversion_phase_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_conversion_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_conversion_phase_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_conversion
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_conversion_phase }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_reform = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_reform_phase
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_reform_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_reform_phase_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_reform_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_reform_phase_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_reform
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_reform_phase }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_investiture_crisis = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_investiture_crisis
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_investiture_crisis_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_investiture_crisis_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_investiture_crisis_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_investiture_crisis_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_investiture_crisis
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_investiture_crisis }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_crusade = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_crusade_phase
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_crusade_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_crusade_phase_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_crusade_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_crusade_phase_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_crusade
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_crusade_phase }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 				scope:push_concord = {
# 					if = {
# 						limit = {
# 							situation_top_has_catalyst = catalyst_shaped_the_christian_church_concord
# 						}
# 						if = {
# 							limit = { root = { any_held_title = { is_head_of_faith = yes } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_concord_hof
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_concord_hof }
# 									}
# 								}
# 							}
# 						}
# 						else_if = { # Princes of the Church dynasty legacy: the push counts double
# 							limit = { root = { dynasty ?= { has_dynasty_perk = pam_legacy_5 } } }
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_concord_dynasty
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_concord_dynasty }
# 									}
# 								}
# 							}
# 						}
# 						else = {
# 							root = {
# 								send_interface_toast = {
# 									title = pam_shape_the_christian_church_decision_toast
# 									left_icon = root
# 									custom_tooltip = {
# 										text = pam_shape_the_christian_church_decision_toast_concord
# 										situation:the_christian_church = { trigger_situation_catalyst = catalyst_shaped_the_christian_church_concord }
# 									}
# 								}
# 							}
# 						}
# 					}
# 				}
# 			}
# 		}
# 	}

# 	ai_check_interval_by_tier = {
# 		barony = 0
# 		county = 0
# 		duchy = 144
# 		kingdom = 72
# 		empire = 60
# 		hegemony = 36
# 	}

# 	ai_potential = {
# 		is_available_at_peace = yes
# 		NOT = { has_trait = excommunicated }
# 		OR = {
# 			any_held_title = { is_head_of_faith = yes }
# 			rite.head_of_rite ?= this
# 			exists = clerical_elector_title
# 			any_held_title = { has_clerical_region = yes }
# 			AND = { # Pious kings
# 				is_clergy = no
# 				highest_held_title_tier >= tier_kingdom
# 				OR = {
# 					has_trait = lifestyle_scholar
# 					has_trait = theologian
# 					piety_level >= 3
# 				}
# 			}
# 			highest_held_title_tier >= tier_empire
# 			dynasty ?= { has_dynasty_perk = pam_legacy_5 } # Princes of the Church dynasty legacy
# 		}
# 		piety >= massive_piety_value # Do not go into piety debt for this
# 	}

# 	ai_will_do = {
# 		base = 0
# 		modifier = { # HoF
# 			any_held_title = { is_head_of_faith = yes }
# 			add = 25
# 		}
# 		modifier = { # HoR
# 			rite.head_of_rite ?= this
# 			add = 25
# 		}
# 		modifier = { # Cardinals
# 			exists = clerical_elector_title
# 			add = 15
# 		}
# 		modifier = { # Archbishops
# 			any_held_title = { has_clerical_region = yes }
# 			add = 10
# 		}
# 		modifier = { # Other people that would care
# 			is_clergy = no
# 			OR = {
# 				has_trait = lifestyle_scholar
# 				has_trait = theologian
# 				has_trait = zealous
# 				piety_level >= 4
# 			}
# 			add = 15
# 		}
# 		modifier = { # And people who wouldn't
# 			has_trait = cynical
# 			add = -40
# 		}
# 		modifier = { # Princes of the Church dynasty legacy
# 			dynasty ?= { has_dynasty_perk = pam_legacy_5 }
# 			add = 15
# 		}
# 		modifier = { # More likely to happen to push for IC
# 			add = 10
# 			faith ?= { has_doctrine = doctrine_clerical_succession_conditional }
# 			OR = {
# 				any_held_title = {
# 					OR = {
# 						is_head_of_faith = yes
# 						has_clerical_region = yes
# 					}
# 				}
# 				rite.head_of_rite ?= this
# 				exists = clerical_elector_title
# 			}
# 		}
# 		modifier = { # Already guided the Church within the last 20 years
# 			has_character_flag = pam_shaped_the_christian_church_recently
# 			factor = 0
# 		}
# 		modifier = {
# 			piety <= massive_piety_value
# 			factor = 0
# 		}
# 	}
# }

# Kingdom of Heaven (Christian HoF hegemony)
# pam_kingdom_of_heaven_decision = {
# 	picture = {
# 		reference = "gfx/interface/illustrations/decisions/pam_decision_kingdom_of_heaven.dds"
# 	}
# 	desc = pam_kingdom_of_heaven_decision_desc
# 	selection_tooltip = pam_kingdom_of_heaven_decision_tooltip
# 	decision_group_type = major
# 	sort_order = 125

# 	ai_check_interval_by_tier = {
# 		barony = 0
# 		county = 0
# 		duchy = 0
# 		kingdom = 36
# 		empire = 24
# 		hegemony = 0
# 	}

# 	is_shown = {
# 		any_held_title = {
# 			is_head_of_faith = yes
# 		}
# 		is_christian_trigger = yes
# 		exists = situation:the_christian_church
# 		NOT = { has_global_variable = created_kingdom_of_heaven }
# 		has_pam_dlc_trigger = yes
# 	}

# 	is_valid = {
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_hof_tt
# 			any_held_title = {
# 				is_head_of_faith = yes
# 			}
# 		}
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_situation_tt
# 			top_participant_group:the_christian_church ?= {
# 				has_participant_group_parameter = the_christian_church_can_create_kingdom_of_heaven
# 			}
# 		}
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_jerusalem_tt
# 			completely_controls = title:c_jerusalem
# 		}
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_holy_sites_tt
# 			faith = {
# 				any_holy_site_barony = {
# 					OR = {
# 						holder = root
# 						holder.top_liege = root
# 					}
# 					count >= 3
# 				}
# 			}
# 		}
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_piety_highest_tt
# 			pam_kingdom_of_heaven_has_highest_piety_level_in_faith_trigger = yes
# 		}
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_emperor_hooks_tt
# 			pam_kingdom_of_heaven_hooks_on_all_faith_emperors_or_none_trigger = yes
# 		}
# 		save_temporary_scope_as = root_scope
# 		custom_tooltip = {
# 			text = pam_kingdom_of_heaven_decision_half_faith_tt
# 			pam_kingdom_of_heaven_half_faith_in_realm_trigger = yes
# 		}
# 	}

# 	is_valid_showing_failures_only = {
# 		is_alive = yes
# 		is_imprisoned = no
# 		is_at_war = no
# 		NOT = { has_trait = excommunicated }
# 	}

# 	cost = {
# 		piety = monumental_piety_value
# 	}

# 	effect = {
# 		custom_tooltip = pam_kingdom_of_heaven_decision_hegemony_effect_tt
# 		custom_tooltip = pam_kingdom_of_heaven_decision_vassals_effect_tt
# 		custom_tooltip = pam_kingdom_of_heaven_decision_subjugation_effect_tt
# 		custom_tooltip = pam_kingdom_of_heaven_decision_de_jure_effect_tt
# 		show_as_tooltip = {
# 			dynasty ?= {
# 				add_dynasty_prestige = 10000
# 				add_dynasty_modifier = pam_founded_kingdom_of_heaven_modifier
# 			}
# 		}
# 		trigger_event = pam_kingdom_of_heaven.0001
# 	}

# 	ai_potential = {
# 		any_held_title = { is_head_of_faith = yes }
# 		exists = situation:the_christian_church
# 	}

# 	ai_will_do = {
# 		base = 100 # Do it if you can
# 	}
# }

# Proclaim yourself a living voice of the faith and gain the herald trait
pam_proclaim_living_word_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_act_of_devotion.dds"
	}
	desc = pam_proclaim_living_word_decision_desc
	selection_tooltip = pam_proclaim_living_word_decision_tooltip
	decision_group_type = major
	sort_order = 120

	ai_check_interval_by_tier = {
		barony = 0
		county = 60
		duchy = 48
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		OR = {
			government_has_flag = government_is_theocracy
			has_perk = prophet_perk
		}
		NOR = {
			faith.religious_head ?= this
			has_trait = herald
		}
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		calc_true_if = {
			amount >= 6
			has_perk = prophet_perk
			custom_tooltip = {
				text = pam_proclaim_living_word_decision_sf_tt
				spiritual_fulfillment >= spiritual_fulfillment_3
			}
			piety_level >= max_piety_level
			has_trait_xp = {
				trait = pilgrim
				value >= 100
			}
			has_trait_xp = {
				trait = lifestyle_scholar
				value >= 100
			}
			has_trait_xp = {
				trait = lifestyle_mystic
				value >= 100
			}
			custom_tooltip = {
				text = pam_proclaim_living_word_decision_archbishop_tt
				any_held_title = { has_clerical_region = yes }
			}
			custom_tooltip = {
				text = pam_proclaim_living_word_decision_puppet_tt
				OR = {
					puppet:theological_agent_puppet ?= { pam_is_archbishop_or_higher_trigger = yes }
					puppet:external_theological_agent_puppet ?= { pam_is_archbishop_or_higher_trigger = yes }
				}
			}
			custom_tooltip = {
				text = pam_proclaim_living_word_decision_realm_rite_tt
				is_landed = yes
				# count = all is satisfied by a single county, so the floor is what makes this a real bar
				any_sub_realm_county = {
					count >= 5
					rite = root.rite
				}
				any_sub_realm_county = {
					count = all
					rite = root.rite
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		NOT = { has_trait = excommunicated }
	}

	cost = {
		piety = 3000
		prestige = 1500
	}

	effect = {
		add_trait = herald
		custom_tooltip = pam_proclaim_living_word_decision_effect_tt
		trigger_event = pam_decision_events.0021
	}

	ai_potential = {
		ai_zeal >= 40
	}

	ai_will_do = {
		base = 100 # The requirements are the hard part; a zealous AI that qualifies should take it
	}
}

pam_prevent_great_schism_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_shape_the_christian_church.dds"
	}
	decision_group_type = religious

	sort_order = 109

	is_shown = {
		has_pam_dlc_trigger = yes
		NOT = { has_global_variable = pam_great_schism_decision_taken }
		situation:the_christian_church ?= {
			var:pam_great_schism_status ?= flag:ongoing
			has_situation_top_phase_parameter = the_christian_church_great_schism
			pam_great_schism_progress_value >= pam_great_schism_progress_threshold_value
		}
		exists = top_participant_group:the_christian_church
		is_christian_trigger = yes # Christian Only
	}

	is_valid = {
		OR = {
			custom_description = {
				text = is_head_of_faith_or_rite_tt
				subject = root
				OR = {
					faith.religious_head ?= this
					this = rite.head_of_rite
				}
 			}
			custom_tooltip = {
				text = has_theological_agent_puppet_hof_or_hor_tt
				puppet:theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
						this = rite.head_of_rite
					}
				}
			}
			custom_tooltip = {
				text = has_external_theological_agent_puppet_hof_or_hor_tt
				puppet:external_theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
			 			this = rite.head_of_rite
					}
				}
 			}
		}
		highest_held_title_tier >= tier_kingdom
		calc_true_if = {
			amount >= 4
			piety_level >= very_high_piety_level
			custom_description = {
				text = appoint_a_righteous_caliph_decision.control_one_holy_site
				faith = {
					any_holy_site_barony = {
						count >= 1
						holder = { target_is_same_character_or_above = root }
					}
				}
			}
			custom_description = {
				text = appoint_a_righteous_caliph_decision.control_two_holy_sites
				faith = {
					any_holy_site_barony = {
						count >= 2
						holder = { target_is_same_character_or_above = root }
					}
				}
			}
			custom_tooltip = {
				text = pam_schism_event_stance_no_schism_tt
				var:pam_schism_stance ?= flag:no_schism
			}
			custom_description = {
				text = pam_prevent_great_schism_clerical_support_tt
				value = prevent_schism_requirement_value
				prevent_schism_requirement_value >= 7
			}
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
	}

	effect = {
		set_global_variable = pam_great_schism_decision_taken
		set_global_variable = pam_great_schism_prevented
		save_scope_as = schism_peacemaker
		# This runs before the phase change and outside the check below, so the see can always be named
		pam_save_schism_head_of_faith_effect = yes
		pam_prevent_great_schism_effect = yes
		# Same gate as 0062 peacemaker options - only promise what that event offers
		if = {
			limit = { pam_schism_can_seat_head_of_faith_trigger = yes }
			custom_tooltip = pam_prevent_great_schism_choose_head_tt
		}
		situation:the_christian_church ?= {
			every_situation_participant = {
				limit = {
					is_ruler = yes
					is_christian_trigger = yes
				}
				trigger_event = pam_the_christian_church.0062
			}
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 0
	}
	ai_will_do = { base = 0 }
}

pam_cause_great_schism_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_send_legatine_mission.dds"
	}
	decision_group_type = religious

	sort_order = 108

	is_shown = {
		NOT = { has_global_variable = pam_great_schism_decision_taken }
		has_pam_dlc_trigger = yes
		is_christian_trigger = yes # Christian Only
		exists = top_participant_group:the_christian_church
		exists = rite:byzantine_rite
		exists = rite:roman_rite
		situation:the_christian_church ?= {
			var:pam_great_schism_status ?= flag:ongoing
			has_situation_top_phase_parameter = the_christian_church_great_schism
			pam_great_schism_progress_value >= pam_great_schism_progress_threshold_value
		}
	}

	is_valid = {
		OR = {
			custom_description = {
				text = is_head_of_faith_or_rite_tt
				subject = root
				OR = {
					faith.religious_head ?= this
					this = rite.head_of_rite
				}
 			}
 			custom_tooltip = {
				text = has_theological_agent_puppet_hof_or_hor_tt
				puppet:theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
						this = rite.head_of_rite
					}
				}
			}
			custom_tooltip = {
				text = has_external_theological_agent_puppet_hof_or_hor_tt
				puppet:external_theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
			 			this = rite.head_of_rite
					}
				}
 			}
		}
		highest_held_title_tier >= tier_kingdom
		calc_true_if = {
			amount >= 4
			piety_level >= very_high_piety_level
			custom_description = {
				text = appoint_a_righteous_caliph_decision.control_one_holy_site
				faith = {
					any_holy_site_barony = {
						count >= 1
						holder = { target_is_same_character_or_above = root }
					}
				}
			}
			custom_description = {
				text = appoint_a_righteous_caliph_decision.control_two_holy_sites
				faith = {
					any_holy_site_barony = {
						count >= 2
						holder = { target_is_same_character_or_above = root }
					}
				}
			}
			custom_tooltip = {
				text = pam_schism_event_stance_cause_tt
				OR = {
					var:pam_schism_stance ?= flag:mainline
					var:pam_schism_stance ?= flag:competitor
				}
			}
			custom_description = {
				text = pam_prevent_great_schism_clerical_support_tt
				value = prevent_schism_requirement_value
				prevent_schism_requirement_value >= 7
			}
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
	}

	effect = {
		set_global_variable = pam_great_schism_decision_taken
		set_variable = pam_caused_the_great_schism_var
		pam_great_schismat_effect = yes
		situation:the_christian_church ?= {
			pam_create_great_schism_effect = yes
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 0
	}
	ai_will_do = { base = 0 }
}
### Mend the Great Schism ### diplomatic path, a twin decision to the conquest route
# pam_mend_great_schism_decision = {
# 	picture = {
# 		reference = "gfx/interface/illustrations/decisions/pam_decision_create_hof.dds"
# 	}
# 	desc = pam_mend_great_schism_decision_desc
# 	selection_tooltip = pam_mend_great_schism_decision_tooltip
# 	decision_group_type = religious
# 	sort_order = 2

# 	ai_check_interval_by_tier = {
# 		barony = 0
# 		county = 0
# 		duchy = 0
# 		kingdom = 0
# 		empire = 120
# 		hegemony = 120
# 	}

# 	is_shown = {
# 		is_christian_trigger = yes # Christian Only
# 		is_playable_character = yes
# 		has_pam_dlc_trigger = yes
# 		# Schism has happened
# 		has_global_variable = pam_great_schism_decision_taken
# 		NOT = { has_global_variable = pam_great_schism_prevented }
# 		NOT = {  #Can only do it once.
# 			is_target_in_global_variable_list = {
# 				name = unavailable_unique_decisions
# 				target = flag:flag_mended_great_schism
# 			}
# 		}
# 		# Schism faiths must still exist to merge
# 		faith:roman_catholic_faith = {
# 			num_county_followers > 0
# 			exists = religious_head
# 		}
# 		faith:orthodox = {
# 			num_county_followers > 0
# 			exists = religious_head
# 		}
# 	}

# 	is_valid = {
# 		custom_tooltip = {
# 			text = pam_christian_church_stability_tt
# 			top_participant_group:the_christian_church ?= {
# 				has_participant_group_parameter = the_christian_church_mending_the_schism_active
# 			}
# 		}
# 		OR = {
# 			custom_description = {
# 				text = is_head_of_faith_or_rite_tt
# 				subject = root
# 				OR = {
# 					faith.religious_head ?= this
# 					this = rite.head_of_rite
# 				}
#  			}
#  			custom_tooltip = {
# 				text = has_theological_agent_puppet_hof_or_hor_tt
# 				puppet:theological_agent_puppet ?= {
# 					OR = {
# 						any_held_title = { is_head_of_faith = yes }
# 						this = rite.head_of_rite
# 					}
# 				}
# 			}
# 			custom_tooltip = {
# 				text = has_external_theological_agent_puppet_hof_or_hor_tt
# 				puppet:external_theological_agent_puppet ?= {
# 					OR = {
# 						any_held_title = { is_head_of_faith = yes }
# 			 			this = rite.head_of_rite
# 					}
# 				}
#  			}
# 		}
# 		highest_held_title_tier >= tier_kingdom
# 		piety_level >= very_high_piety_level
# 		faith = { holy_sites_controlled >= 1 }
# 		# Orthodox HoF must be on board if not you
# 		trigger_if = {
# 			limit = {
# 				exists = faith:orthodox.religious_head
# 				NOT = { faith:orthodox.religious_head = root }
# 			}
# 			custom_description = {
# 				text = pam_prevent_great_schism_orthodox_hof_tt
# 				faith:orthodox.religious_head = {
# 					OR = {
# 						has_relation_friend = root
# 						has_relation_lover = root
# 						root = { has_hook = prev }
# 						root.puppet:theological_agent_puppet ?= this
# 						root.puppet:external_theological_agent_puppet ?= this
# 					}
# 				}
# 			}
# 		}
# 		# Catholic HoF must be on board if not you
# 		trigger_if = {
# 			limit = {
# 				exists = faith:roman_catholic_faith.religious_head
# 				NOT = { faith:roman_catholic_faith.religious_head = root }
# 			}
# 			custom_description = {
# 				text = pam_prevent_great_schism_catholic_hof_tt
# 				faith:roman_catholic_faith.religious_head = {
# 					OR = {
# 						has_relation_friend = root
# 						has_relation_lover = root
# 						root = { has_hook = prev }
# 						root.puppet:theological_agent_puppet ?= this
# 						root.puppet:external_theological_agent_puppet ?= this
# 					}
# 				}
# 			}
# 		}
# 		custom_description = {
# 			text = pam_mend_great_schism_clerical_support_tt
# 			value = mend_schism_clerical_support_requirement_value
# 			subject = root
# 			mend_schism_clerical_support_requirement_value >= mend_schism_clerical_support_count_value
# 		}
# 		custom_description = {
# 			text = pam_mend_great_schism_secondary_support_tt
# 			value = mend_schism_secondary_support_requirement_value
# 			subject = root
# 			mend_schism_secondary_support_requirement_value >= mend_schism_secondary_support_count_value
# 		}
# 	}

# 	is_valid_showing_failures_only = {
# 		is_capable_adult = yes
# 		is_imprisoned = no
# 		custom_tooltip = {
# 			text = you_caused_great_schism
# 			NOT = { has_variable = pam_caused_the_great_schism_var }
# 		}
# 	}

# 	effect = {
# 		gain_holy_legend_seed_tooltip_effect = yes
# 		show_as_tooltip = {
# 			mend_great_schism_scripted_effect = yes
# 		}
# 		pam_mend_great_schism_reward_effect = {
# 			MODIFIER = pam_mended_great_schism_diplomatic_dynasty_modifier
# 			CHARACTER_MODIFIER = pam_mended_great_schism_diplomatic_character_modifier
# 		}
# 		trigger_event = roman_restoration.0100
# 		hidden_effect = {
# 			add_to_global_variable_list = {
# 				name = unavailable_unique_decisions
# 				target = flag:flag_mended_great_schism
# 			}
# 		}
# 	}

# 	ai_potential = {
# 		always = yes
# 	}

# 	ai_will_do = {
# 		base = 100
# 	}
# }

# Unite the Miaphysite Churches - fold the other Miaphysite-communion faith into your own as a rite
pam_unite_miaphysite_churches_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_create_hof.dds"
	}
	desc = pam_unite_miaphysite_churches_decision_desc
	selection_tooltip = pam_unite_miaphysite_churches_decision_tooltip
	decision_group_type = major
	sort_order = 2

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	is_shown = {
		OR = {
			faith = faith:miaphysitism
			faith = faith:armenian_apostolic
		}
		is_playable_character = yes
		has_pam_dlc_trigger = yes
		NOT = { #Can only do it once.
			is_target_in_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_united_miaphysite_churches
			}
		}
		# Both communion faiths must still exist to merge
		faith:miaphysitism = {
			num_county_followers > 0
			exists = religious_head
		}
		faith:armenian_apostolic = {
			num_county_followers > 0
			exists = religious_head
		}
	}

	is_valid = {
		OR = {
			custom_description = {
				text = is_head_of_faith_or_rite_tt
				subject = root
				OR = {
					faith.religious_head ?= this
					this = rite.head_of_rite
				}
			}
			custom_tooltip = {
				text = has_theological_agent_puppet_hof_or_hor_tt
				puppet:theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
						this = rite.head_of_rite
					}
				}
			}
			custom_tooltip = {
				text = has_external_theological_agent_puppet_hof_or_hor_tt
				puppet:external_theological_agent_puppet ?= {
					OR = {
						any_held_title = { is_head_of_faith = yes }
						this = rite.head_of_rite
					}
				}
			}
		}
		highest_held_title_tier >= tier_kingdom
		piety_level >= max_piety_level
		faith = { holy_sites_controlled >= 3 }
		# The Coptic Pope must be on board if not you
		trigger_if = {
			limit = {
				exists = faith:miaphysitism.religious_head
				NOT = { faith:miaphysitism.religious_head = root }
			}
			custom_description = {
				text = pam_unite_miaphysite_churches_coptic_hof_tt
				faith:miaphysitism.religious_head = {
					OR = {
						has_relation_friend = root
						has_relation_lover = root
						root = { has_hook = prev }
					}
				}
			}
		}
		# The Armenian Catholicos must be on board if not you
		trigger_if = {
			limit = {
				exists = faith:armenian_apostolic.religious_head
				NOT = { faith:armenian_apostolic.religious_head = root }
			}
			custom_description = {
				text = pam_unite_miaphysite_churches_apostolic_hof_tt
				faith:armenian_apostolic.religious_head = {
					OR = {
						has_relation_friend = root
						has_relation_lover = root
						root = { has_hook = prev }
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_capable_adult = yes
		is_imprisoned = no
	}

	cost = {
		piety = 5000
	}

	effect = {
		pam_unite_miaphysite_churches_effect = yes
		dynasty ?= {
			add_dynasty_prestige = monumental_dynasty_prestige_gain
		}
		hidden_effect = {
			add_to_global_variable_list = {
				name = unavailable_unique_decisions
				target = flag:flag_united_miaphysite_churches
			}
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 25
	}
}

# Promulgate Word of Pious Deeds - Boost Papal Election Score and sainthood chance
pam_promulgate_word_of_pious_deeds_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_papal_petition.dds"
	}
	decision_group_type = religious

	desc = pam_promulgate_word_of_pious_deeds_decision_desc
	selection_tooltip = pam_promulgate_word_of_pious_deeds_decision_desc_tooltip

	ai_check_interval_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	sort_order = 110

	is_shown = {
		pam_can_hold_cardinalate_trigger = yes
		is_clergy = yes
		has_spiritual_fulfillment_type = christian_fulfillment
		exists = faith.religious_head
		has_pam_dlc_trigger = yes
		NOT = { has_character_flag = pam_promulgate_word_of_pious_deeds_used }
	}

	is_valid = {
		NOT = {
			custom_description = {
				text = character_is_religious_head_of_faith
				faith.religious_head = this
			}
		}
		custom_tooltip = {
			text = cardinal_unlocks_pam_promulgate_word_of_pious_deeds_decision_tooltip
			exists = clerical_elector_title
		}
		custom_tooltip = {
			text = domicile_unlocks_pam_promulgate_word_of_pious_deeds_decision_tooltip
			domicile ?= { has_domicile_parameter = unlocks_pam_promulgate_word_of_pious_deeds_decision }
		}
	}

	is_valid_showing_failures_only = {
		is_available_quick = {
			incapable = no
			alive = yes
			adult = yes
			at_war = no
			imprisoned = no
			activity = no
		}
	}

	cost = {
		piety = massive_piety_value
	}

	effect = {
		add_character_flag = pam_promulgate_word_of_pious_deeds_used
		if = {
			limit = {
				exists = superior.primary_title
			}
			superior.primary_title = {
				save_scope_as = praise_worthy_priest_superior_title
			}
		}
		else_if = {
			limit = {
				exists = faith.religious_head_title
			}
			faith.religious_head_title = {
				save_scope_as = praise_worthy_priest_superior_title
			}
		}
		else = {
			primary_title ?= {
				save_scope_as = praise_worthy_priest_superior_title
			}
		}
		save_scope_as = praise_worthy_priest
		custom_tooltip = pam_promulgate_word_of_pious_deeds_decision_tooltip_effect
		trigger_event = pam_decision_events.0015
	}

	ai_potential = {
		piety >= major_piety_value
	}

	ai_will_do = {
		base = 35
		modifier = {
			prestige < major_prestige_value
			add = 30
		}
		modifier = {
			prestige < medium_prestige_value
			add = 30
		}
		modifier = {
			prestige < minor_prestige_value
			add = 30
		}
		modifier = {
			has_trait = arrogant
			add = 50
		}
	}
}

pam_cardinal_endow_masses_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_papal_petition.dds"
	}
	decision_group_type = religious

	desc = pam_cardinal_endow_masses_decision_desc
	selection_tooltip = pam_cardinal_endow_masses_decision_tooltip
	confirm_text = pam_cardinal_endow_masses_decision_confirm

	ai_check_interval_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 24
		empire = 24
		hegemony = 24
	}

	sort_order = 105

	is_shown = {
		is_clergy = yes
		has_spiritual_fulfillment_type = christian_fulfillment
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		#Check if they are a Cardinal
		custom_tooltip = {
			text = cardinal_unlocks_pam_cardinal_endow_masses_decision_tooltip
			exists = root.clerical_elector_title
		}
	}

	is_valid_showing_failures_only = {
		is_available_quick = {
			incapable = no
			alive = yes
			adult = yes
			imprisoned = no
			activity = no
		}
	}

	cooldown = { years = 5 }

	cost = {
		treasury_or_gold = medium_treasury_or_gold_value
	}

	effect = {
		send_interface_toast = {
			title = pam_cardinal_endow_masses_decision_toast
			left_icon = root
			add_piety = major_piety_gain
			# Simony holds the exchange of wealth for sacred benefit to be the faith working as intended
			if = {
				limit = {
					OR = {
						rite = { rite_has_tenet = tenet_simony }
						has_personal_tenet = tenet_simony
					}
				}
				change_spiritual_fulfillment = medium_spiritual_fulfillment_value
			}
			custom_tooltip = {
				text = pam_cardinal_endow_masses_decision_subordinates_tt
				every_subordinate = {
					add_piety = minor_piety_gain
					add_opinion = {
						target = root
						modifier = pam_cardinal_endowed_masses_opinion
					}
				}
			}
		}
	}

	ai_potential = {
		exists = root.clerical_elector_title
		# A cardinal holding anything beyond the cardinalate has better uses for the treasury
		NOT = {
			any_held_title = {
				this != root.clerical_elector_title
			}
		}
		trigger_if = {
			limit = { has_treasury = yes }
			short_term_treasury >= medium_treasury_or_gold_value
		}
	}

	ai_will_do = {
		base = 30
		modifier = {
			has_trait = zealous
			add = 25
		}
		modifier = {
			piety_level < 3
			add = 20
		}
	}
}

# Player-only: an AI renouncing could leave the conclave with nobody to elect
pam_renounce_papal_candidacy_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_papal_petition.dds"
	}
	decision_group_type = religious

	ai_check_interval = 0

	title = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = pam_refuses_papacy }
				desc = pam_renounce_papal_candidacy_decision_embrace
			}
			desc = pam_renounce_papal_candidacy_decision
		}
	}

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = pam_refuses_papacy }
				desc = pam_renounce_papal_candidacy_decision_desc_embrace
			}
			desc = pam_renounce_papal_candidacy_decision_desc_renounce
		}
	}

	selection_tooltip = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = pam_refuses_papacy }
				desc = pam_renounce_papal_candidacy_decision_tooltip_embrace
			}
			desc = pam_renounce_papal_candidacy_decision_tooltip_renounce
		}
	}

	confirm_text = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = pam_refuses_papacy }
				desc = pam_renounce_papal_candidacy_decision_confirm_embrace
			}
			desc = pam_renounce_papal_candidacy_decision_confirm_renounce
		}
	}

	sort_order = 110

	is_shown = {
		is_ai = no
		has_pam_dlc_trigger = yes
		is_clergy = yes
		pam_is_archbishop_or_higher_trigger = yes
		faith ?= {
			has_doctrine_parameter = has_clerical_electors
			exists = religious_head
			NOT = { religious_head = root }
		}
	}

	is_valid = {
		# The last willing cardinal may not step aside, or an election would have no candidates left
		trigger_if = {
			limit = {
				exists = clerical_elector_title
				NOT = { has_variable = pam_refuses_papacy }
			}
			custom_tooltip = {
				text = pam_renounce_papal_candidacy_decision_last_candidate_tt
				faith ?= {
					any_clerical_elector_title = {
						holder ?= {
							this != root
							NOT = { has_variable = pam_refuses_papacy }
						}
					}
				}
			}
		}
	}

	effect = {
		if = {
			limit = { has_variable = pam_refuses_papacy }
			remove_variable = pam_refuses_papacy
			custom_tooltip = pam_renounce_papal_candidacy_decision_embrace_tt
		}
		else = {
			set_variable = { name = pam_refuses_papacy value = yes }
			custom_tooltip = pam_renounce_papal_candidacy_decision_renounce_tt
		}
	}
}

pam_declare_rite_heresy_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/pam_the_christian_church_instability.dds"
	}
	decision_group_type = major

	desc = pam_declare_rite_heresy_decision_desc
	selection_tooltip = pam_declare_rite_heresy_decision_tooltip
	confirm_text = pam_declare_rite_heresy_decision_confirm

	sort_order = 108

	ai_check_interval_by_tier = {
		barony = 0
		county = 200
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	is_shown = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		} # Catholic HoFs use Bulls
		faith ?= {
			any_faith_rite = {
				pam_rite_can_be_declared_heresy_trigger = yes
			}
		}
	}

	is_valid = {
		trigger_if = {
			limit = { has_trait = zealous }
			custom_tooltip = {
				text = pam_declare_rite_heresy_decision_valid_zealous_tt
				faith = {
					any_faith_rite = {
						pam_rite_can_be_declared_heresy_trigger = yes
					}
				}
			}
		}
		trigger_else = {
			custom_tooltip = {
				text = pam_declare_rite_heresy_decision_valid_tt
				faith = {
					any_faith_rite = {
						pam_rite_can_be_declared_heresy_trigger = yes
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_imprisoned = no
		custom_tooltip = {
			text = pam_rite_heresy_select_tt
			exists = scope:selected_item
		}
	}

	cooldown = { years = 5 }

	cost = {
		piety = major_piety_value
	}

	effect = {
		save_scope_as = bull_issuer
		scope:selected_item = { save_scope_as = heresy_rite }
		send_interface_toast = {
			title = pam_declare_rite_heresy_effect_toast_tt
			right_icon = scope:heresy_rite
			pam_declare_rite_heresy_effect = yes
		}
		faith = {
			every_faith_character = {
				limit = {
					is_ruler = yes
					this != scope:bull_issuer
				}
				trigger_event = { id = pam_decision_events.0012 days = 1 }
			}
		}
		if = {
			limit = { exists = scope:heresy_rite }
			hidden_effect = {
				if = {
					limit = {
						scope:heresy_rite.faith.religious_head ?= {
							NOT = { has_trait = heresiarch }
						}
					}
					scope:heresy_rite.faith.religious_head = { add_trait = heresiarch }
				}
				else_if = {
					limit = {
						scope:heresy_rite.main_rite.head_of_rite ?= {
							NOT = { has_trait = heresiarch }
						}
					}
					scope:heresy_rite.main_rite.head_of_rite = { add_trait = heresiarch }
				}
				if = {
					limit = {
						scope:heresy_rite.faith = { has_doctrine = special_doctrine_ecumenical_christian }
					}
					scope:heresy_rite.faith = { remove_doctrine = special_doctrine_ecumenical_christian }
				}
				if = {
					limit = {
						scope:heresy_rite.faith = { has_doctrine = special_doctrine_ecumenical_miaphysite }
					}
					scope:heresy_rite.faith = { remove_doctrine = special_doctrine_ecumenical_miaphysite }
				}
			}
		}
	}

	widget = {
		gui = "decision_view_widget_select_rite"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "SELECT"

		setup_items = {
			scope:actor = {
				faith = {
					every_faith_rite = {
						limit = {
							pam_rite_can_be_declared_heresy_trigger = yes
						}
						add_to_list = item_list
					}
				}
			}
		}

		default_item = {
			scope:actor = {
				faith = {
					random_faith_rite = {
						limit = {
							pam_rite_can_be_declared_heresy_trigger = yes
						}
						save_scope_as = selected_item
					}
				}
			}
		}

		is_item_valid = {
			pam_rite_can_be_declared_heresy_trigger = yes
		}

		ai_select_item = {
			scope:actor = {
				faith = {
					ordered_faith_rite = {
						limit = {
							pam_rite_can_be_declared_heresy_trigger = yes
						}
						order_by = "divergence(faith.main_rite)"
						save_scope_as = selected_item
					}
				}
			}
		}
	}

	ai_potential = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		}
		faith = {
			any_faith_rite = {
				pam_rite_can_be_declared_heresy_trigger = yes
			}
		}
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = 25
			has_trait = zealous
		}
		modifier = {
			add = 15
			has_trait = theologian
		}
		modifier = {
			add = -25
			has_trait = cynical
		}
		modifier = {
			add = -50
			rite = { rite_has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {
			add = -100
			scope:selected_item = scope:actor.rite
		}
	}
}

# Head of Faith: formally take a stance on a tenet known to the faith or learned personally.
pam_permit_tenet_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/pam_the_christian_church_stability.dds"
	}
	decision_group_type = major

	desc = pam_permit_tenet_decision_desc
	selection_tooltip = pam_permit_tenet_decision_tooltip
	confirm_text = pam_permit_tenet_decision_confirm

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	is_shown = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		} # Catholic HoFs use Bulls
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		custom_tooltip = {
			text = pam_tenet_stance_select_tt
			exists = scope:selected_item
		}
		custom_tooltip = {
			text = ecumenical_council_already_ongoing_tt
			NOT = { faith = { has_variable = ecumenical_council_ongoing } }
		}
	}

	cooldown = { years = 3 }

	cost = {
		piety = medium_piety_value
	}

	effect = {
		save_scope_as = pam_tenet_stance_issuer
		save_scope_as = pam_tenet_stance_permit
		scope:selected_item = { save_scope_as = pam_tenet_stance_tenet }
		faith = {
			set_tenet_status = {
				tenet = scope:selected_item
				status = permitted
			}
			change_fervor = {
				value = significant_fervor_loss
				desc = fervor_loss_pam_tenet_permitted
			}
			if = {
				limit = { has_tenet_popularity_trigger = yes }
				change_tenet_popularity = {
					target = scope:selected_item
					change = medium_tenet_popularity_gain
				}
			}
			pam_faith_cleanup_forbidden_personal_tenet_secrets_effect = yes
			every_faith_character = {
				limit = {
					is_ruler = yes
					this != scope:pam_tenet_stance_issuer
				}
				trigger_event = { id = pam_decision_events.0011 days = 1 }
			}
		}
	}

	widget = {
		gui = "decision_view_widget_select_tenet"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "SELECT"

		# List is tenets the HoF personally knows + tenets the rite knows
		setup_items = {
			scope:actor = {
				ordered_character_tenet = {
					knowledge_filter = known
					order_by = pam_raw_tenet_popularity_value
					max = 200
					check_range_bounds = no
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				random_character_tenet = {
					knowledge_filter = known
					limit = { pam_tenet_can_be_permitted_trigger = yes }
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			pam_tenet_can_be_permitted_trigger = yes
		}

		ai_select_item = {
			scope:actor = {
				if = { # A tenet the faith adores gets sanctioned whether or not the Head of Faith cares for it
					limit = {
						any_character_tenet = {
							knowledge_filter = known
							pam_tenet_can_be_permitted_trigger = yes
							pam_tenet_is_overwhelmingly_popular_trigger = { CHARACTER = scope:actor }
						}
					}
					ordered_character_tenet = {
						knowledge_filter = known
						limit = {
							pam_tenet_can_be_permitted_trigger = yes
							pam_tenet_is_overwhelmingly_popular_trigger = { CHARACTER = scope:actor }
						}
						order_by = pam_raw_tenet_popularity_value
						position = 0
						save_scope_as = selected_item
					}
				}
				else = {
					random_desired_tenet = {
						limit = {
							pam_tenet_can_be_permitted_trigger = yes
							pam_tenet_ai_may_permit_trigger = { CHARACTER = scope:actor }
						}
						only_positive = yes
						threshold = 1
						selection_count = 97
						weight = {
							base = 10
							modifier = {
								add = pam_tenet_popularity_impact_value
							}
						}
						save_scope_as = selected_item
					}
				}
			}
		}
	}

	ai_potential = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		}
		OR = {
			any_desired_tenet = {
				only_positive = yes
				threshold = 1
				selection_count = 97
				root.rite = {
					NOR = {
						has_tenet_status = { tenet = prev status = permitted }
						has_tenet_status = { tenet = prev status = core }
					}
				}
				pam_tenet_ai_may_permit_trigger = { CHARACTER = root }
			}
			any_character_tenet = {
				knowledge_filter = known
				pam_tenet_can_be_permitted_no_actor_trigger = yes
				pam_tenet_is_overwhelmingly_popular_trigger = { CHARACTER = root }
			}
		}
	}

	ai_will_do = {
		base = 50
		modifier = {
			add = 20
			has_trait = zealous
		}
		modifier = {
			add = 20
			has_trait = theologian
		}
		modifier = {
			add = -30
			has_trait = cynical
		}

		modifier = {
			add = 200
			any_personal_tenet = {
				this = scope:selected_item
			}
		}
	}
}

pam_prohibit_tenet_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/pam_the_christian_church_instability.dds"
	}
	decision_group_type = major

	desc = pam_prohibit_tenet_decision_desc
	selection_tooltip = pam_prohibit_tenet_decision_tooltip
	confirm_text = pam_prohibit_tenet_decision_confirm

	sort_order = 109

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	is_shown = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		} # Catholic HoFs use Bulls
		custom_tooltip = {
			text = ecumenical_council_already_ongoing_tt
			NOT = { faith = { has_variable = ecumenical_council_ongoing } }
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		custom_tooltip = {
			text = pam_tenet_stance_select_tt
			exists = scope:selected_item
		}
	}

	cooldown = { years = 3 }

	cost = {
		piety = medium_piety_value
	}

	effect = {
		save_scope_as = pam_tenet_stance_issuer
		save_scope_as = pam_tenet_stance_prohibit
		scope:selected_item = { save_scope_as = pam_tenet_stance_tenet }
		faith = {
			set_tenet_status = {
				tenet = scope:selected_item
				status = prohibited
			}
			change_fervor = {
				value = notable_fervor_value
				desc = fervor_gain_pam_tenet_prohibited
			}
			if = {
				limit = { has_tenet_popularity_trigger = yes }
				change_tenet_popularity = {
					target = scope:selected_item
					change = major_tenet_popularity_loss
				}
			}
			pam_faith_cleanup_forbidden_personal_tenet_secrets_effect = yes
			pam_faith_grant_forbidden_personal_tenet_secrets_effect = { TENET = scope:selected_item }
			every_faith_character = {
				limit = {
					is_ruler = yes
					this != scope:pam_tenet_stance_issuer
				}
				trigger_event = { id = pam_decision_events.0011 days = 1 }
			}
		}
	}

	widget = {
		gui = "decision_view_widget_select_tenet"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "SELECT"

		# List is tenets the HoF personally knows + tenets the rite knows
		setup_items = {
			scope:actor = {
				ordered_character_tenet = {
					knowledge_filter = known
					order_by = {
						value = pam_raw_tenet_popularity_value
						multiply = -1
					}
					max = 200
					check_range_bounds = no
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				random_character_tenet = {
					knowledge_filter = known
					limit = { pam_tenet_can_be_prohibited_trigger = yes }
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			pam_tenet_can_be_prohibited_trigger = yes
		}

		ai_select_item = {
			scope:actor = {
				if = { # Reform moves against the most entrenched vice whether or not the Head of Faith minds it
					limit = {
						any_character_tenet = {
							knowledge_filter = known
							pam_tenet_can_be_prohibited_trigger = yes
							pam_tenet_ai_should_purge_trigger = { CHARACTER = scope:actor }
						}
					}
					ordered_character_tenet = {
						knowledge_filter = known
						limit = {
							pam_tenet_can_be_prohibited_trigger = yes
							pam_tenet_ai_should_purge_trigger = { CHARACTER = scope:actor }
						}
						order_by = pam_raw_tenet_popularity_value
						position = 0
						save_scope_as = selected_item
					}
				}
				else = {
					random_undesired_tenet = {
						limit = {
							pam_tenet_can_be_prohibited_trigger = yes
							pam_tenet_ai_may_prohibit_trigger = { CHARACTER = scope:actor }
						}
						known_tenets = yes
						only_negative = yes
						threshold = -1
						selection_count = 97
						weight = {
							base = 10
							modifier = {
								add = pam_tenet_unpopularity_impact_value
							}
						}
						save_scope_as = selected_item
					}
				}
			}
		}
	}

	ai_potential = {
		this = faith.religious_head
		NOR = {
			religion = religion:catholic_religion
			religion = religion:eastern_orthodox_religion
		}
		OR = {
			any_character_tenet = {
				knowledge_filter = known
				pam_tenet_can_be_prohibited_no_actor_trigger = yes
				pam_tenet_ai_should_purge_trigger = { CHARACTER = root }
			}
			any_undesired_tenet = {
				known_tenets = yes
				only_negative = yes
				threshold = -1
				selection_count = 97
				root.rite = {
					NOR = {
						has_tenet_status = { tenet = prev status = prohibited }
						has_tenet_status = { tenet = prev status = core }
					}
				}
				pam_tenet_ai_may_prohibit_trigger = { CHARACTER = root }
			}
		}
	}

	ai_will_do = {
		base = 50
		modifier = {
			add = 25
			has_trait = zealous
		}
		modifier = {
			add = 15
			has_trait = theologian
		}
		modifier = {
			add = -25
			has_trait = cynical
		}

		modifier = {
			add = -200
			any_personal_tenet = {
				this = scope:selected_item
			}
		}
	}
}


# Raise an Ancestral Khachkar - You need the right tenet, a deceasced ancestor and a county.
pam_raise_khachkar_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/fp1_decision_raise_runestone.dds"
	}
	decision_group_type = religious
	desc = pam_raise_khachkar_decision_desc
	selection_tooltip = pam_raise_khachkar_decision_tooltip
	confirm_text = pam_raise_khachkar_decision_confirm

	ai_check_interval_by_tier = {
		barony = 0
		county = 200
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	sort_order = 75
	cooldown = { years = 10 }

	is_shown = {
		has_variable = pam_khachkar_ancestral_ancestor
		has_pam_dlc_trigger = yes
		primary_title.tier > tier_barony
		rite ?= {
			rite_has_parameter = tenet_khachkar_decision_unlock
		}
		is_landed = yes
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war = no
		scope:selected_item ?= {
			tier = tier_county
			NOT = {
				has_county_modifier = pam_khachkar_ancestral_county
			}
		}
	}

	is_valid = {
		custom_description = {
			text = pam_raise_khachkar_no_catalysts
			has_variable = pam_khachkar_ancestral_ancestor
		}
		custom_description = {
			text = pam_raise_khachkar_no_valid_county_in_realm
			any_held_county = {
				NOT = {
					has_county_modifier = pam_khachkar_ancestral_county
				}
			}
		}
	}

	cost = {
		gold = medium_gold_value
	}

	widget = {
		gui = "decision_view_widget_select_realm_county"
		controller = select_scope_object

		setup_items = {
			scope:actor = {
				every_held_county = {
					limit = {
						NOT = {
							has_county_modifier = pam_khachkar_ancestral_county
						}
					}
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				capital_county = {
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			tier = tier_county
			NOT = {
				has_county_modifier = pam_khachkar_ancestral_county
			}
		}

		ai_item_will_do = {
			value = 10
			if = {
				limit = {
					this = scope:actor.capital_county
				}
				add = 10
			}
		}
	}

	effect = {
		var:pam_khachkar_ancestral_ancestor = { save_scope_as = khachkar_ancestor }
		scope:selected_item = { save_scope_as = khachkar_location }
		show_as_tooltip = {
			pam_apply_ancestral_khachkar_effects = {
				LOCATION = scope:khachkar_location
				ANCESTOR = scope:khachkar_ancestor
			}
		}
		custom_description_no_bullet = {
			text = pam_raise_khachkar_decision_warning
		}
		trigger_event = pam_decision_events.0017
	}

	ai_potential = {
		has_variable = pam_khachkar_ancestral_ancestor
		short_term_gold >= medium_gold_value
		any_held_county = {
			NOT = {
				has_county_modifier = pam_khachkar_ancestral_county
			}
		}
	}

	ai_will_do = {
		base = 25

		ai_value_modifier = {
			ai_zeal = 1
		}

		modifier = {
			has_trait = zealous
			add = 20
		}
		modifier = {
			has_trait = family_first
			add = 20
		}
		modifier = {
			has_trait = compassionate
			add = 15
		}
		modifier = {
			has_trait = humble
			add = 10
		}
		modifier = {
			has_trait = cynical
			add = -25
		}
		modifier = {
			has_trait = callous
			add = -20
		}
		modifier = {
			has_trait = greedy
			add = -20
		}
		modifier = {
			short_term_gold < major_gold_value
			add = -200
		}
	}
}

pam_proclaim_crusade_age_tenet_decision = {
	picture = {
		trigger = {
			faith ?= faith:roman_catholic_faith
		}
		reference = "gfx/interface/illustrations/event_story/pam_the_christian_church_crusade.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_major_religion.dds"
	}
	decision_group_type = major
	should_create_alert = { always = no }

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	desc = pam_proclaim_crusade_age_tenet_decision_desc
	selection_tooltip = pam_proclaim_crusade_age_tenet_decision_tooltip
	confirm_text = pam_proclaim_crusade_age_tenet_decision_confirm

	is_shown = {
		has_pam_dlc_trigger = yes
		years_from_game_start >= 10
		OR = {
			faith ?= faith:compostelan_catholic_faith 
			religion ?= religion:islam_religion
		}
		this = faith.religious_head
		current_date >= 1066.1.1
		is_ai = yes
	}

	is_valid = {
		OR = {
			pam_ai_can_proclaim_armed_pilgrimages_core_trigger = yes
			pam_ai_can_proclaim_struggle_submission_core_trigger = yes
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_imprisoned = no
	}

	cost = {
	}

	effect = {
		save_scope_as = hof_scope
		if = {
			limit = {
				faith = faith:compostelan_catholic_faith 
			}
			if = { # Remove incompatible tenets
				limit = {
					faith.main_rite = {
						any_rite_tenet = {
							status = core
							this = tenet:tenet_peace_of_god
						}
					}
				}
				faith.main_rite = {
					remove_rite_tenet = tenet:tenet_peace_of_god
					add_rite_tenet = tenet_armed_pilgrimages
				}
				# The removed tenet loses, and the new core tenet gains popularity.
				faith = {
					if = {
						limit = { has_tenet_popularity_trigger = yes }
						change_tenet_popularity = {
							target = tenet:tenet_peace_of_god
							change = major_tenet_popularity_loss
						}
						change_tenet_popularity = {
							target = tenet:tenet_armed_pilgrimages
							change = major_tenet_popularity_gain
						}
					}
				}
			}
			else_if = { # Remove incompatible tenets
				limit = {
					faith.main_rite = {
						any_rite_tenet = {
							status = core
							this = tenet:tenet_pacifism
						}
					}
				}
				faith.main_rite = {
					remove_rite_tenet = tenet:tenet_pacifism
					add_rite_tenet = tenet_armed_pilgrimages
				}
			}
			else_if = { # Remove incompatible tenets
				limit = {
					faith.main_rite = {
						any_rite_tenet = {
							status = core
							this = tenet:tenet_dharmic_pacifism
						}
					}
				}
				faith.main_rite = {
					remove_rite_tenet = tenet:tenet_dharmic_pacifism
					add_rite_tenet = tenet_armed_pilgrimages
				}
			}
			else = {
				faith = {
					main_rite = {
						random_rite_tenet = {
							status = core
							limit = {
								NOT = { this = tenet:tenet_communion }
							}
							save_scope_as = removed_tenet
						}
						remove_rite_tenet = scope:removed_tenet
						add_rite_tenet = tenet_armed_pilgrimages
					}
				}
			}
		}
		else = {
			faith = {
				main_rite = {
					random_rite_tenet = {
						status = core
						save_scope_as = removed_tenet
					}
					remove_rite_tenet = scope:removed_tenet
					add_rite_tenet = tenet_struggle_submission
				}
				# The removed tenet loses, and the new core tenet gains popularity.
				if = {
					limit = { has_tenet_popularity_trigger = yes }
					change_tenet_popularity = {
						target = scope:removed_tenet
						change = major_tenet_popularity_loss
					}
					change_tenet_popularity = {
						target = tenet:tenet_struggle_submission
						change = major_tenet_popularity_gain
					}
				}
			}
		}
		faith = {
			every_faith_character = {
				limit = {
					is_ruler = yes
					this != scope:hof_scope
				}
				trigger_event = { id = pam_decision_events.0018 days = 1 }
			}
		}
	}

	ai_potential = {
		this = faith.religious_head
		OR = {
			pam_ai_can_proclaim_armed_pilgrimages_core_trigger = yes
			pam_ai_can_proclaim_struggle_submission_core_trigger = yes
		}
	}

	ai_will_do = {
		base = 25
		modifier = {
			add = 25
			ai_has_warlike_personality = yes
		}
		modifier = {
			add = -25
			has_personality_submissive_trigger = yes
		}
		modifier = {
			add = 50
			OR = {
				AND = {
					faith = faith:compostelan_catholic_faith 
					pam_any_christian_holy_site_not_under_christian_control_trigger = yes
				}
				AND = {
					religion = religion:islam_religion
					pam_any_muslim_holy_site_not_under_muslim_control_trigger = yes
				}
			}
		}
		modifier = {
			add = 100
			OR = {
				AND = {
					title:c_jerusalem.holder = {
						faith.religion != root.religion
					}
					current_date >= 1095.1.1
				}
				current_date >= 1100.1.1
			}
		}
	}
}

pam_secure_pilgrim_routes_decision = {
	picture = {
		reference = "gfx/interface/illustrations/event_story/pam_the_christian_church_crusade.dds"
	}
	decision_group_type = major

	desc = pam_secure_pilgrim_routes_decision_desc
	selection_tooltip = pam_secure_pilgrim_routes_decision_tooltip
	confirm_text = pam_secure_pilgrim_routes_decision_confirm

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 0
	}

	is_shown = {
		is_ai = no
		faith.main_rite ?= {
			NOT = {
				has_tenet_status = {
					tenet = tenet_armed_pilgrimages
					status = core
				}
			}
		}
		this = faith.religious_head
		faith ?= faith:compostelan_catholic_faith 
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		custom_tooltip = {
			text = pam_secure_pilgrim_routes_decision_holy_site_tt
			pam_any_christian_holy_site_not_under_christian_control_trigger = yes
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_imprisoned = no
		custom_tooltip = {
			text = pam_secure_pilgrim_routes_decision_select_tt
			exists = scope:selected_item
		}
	}

	cost = {
		piety = { # Cheaper than usual
			value = faith_tenet_cost_mid
		}
		treasury = {
			value = medium_gold_value
		}
	}

	effect = {
		scope:selected_item = { save_scope_as = removed_tenet }
		show_as_tooltip = {
			faith.main_rite = {
				custom_tooltip = pam_secure_pilgrim_routes_decision_remove_tenet_tt
				add_rite_tenet = tenet_armed_pilgrimages
			}
			add_character_modifier = {
				modifier = pam_protector_of_pilgrims_modifier
				years = 25
			}
			custom_tooltip = pam_secure_pilgrim_routes_pilgrim_xp_tt
			custom_tooltip = pam_secure_pilgrim_routes_ai_pilgrimage_tt
		}
		trigger_event = pam_decision_events.0019
	}

	widget = {
		gui = "decision_view_widget_select_tenet"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "REPLACE_TENET"

		setup_items = {
			scope:actor = {
				faith.main_rite = {
					ordered_rite_tenet = {
						status = core
						order_by = pam_raw_tenet_popularity_value
						max = 200
						check_range_bounds = no
						add_to_list = item_list
					}
				}
			}
		}

		default_item = {
			scope:actor = {
				faith.main_rite = {
					random_rite_tenet = {
						status = core
						limit = { pam_tenet_can_be_replaced_for_armed_pilgrimages_trigger = yes }
						save_scope_as = selected_item
					}
				}
			}
		}

		is_item_valid = {
			pam_tenet_can_be_replaced_for_armed_pilgrimages_trigger = yes
		}
	}

	ai_potential = {
		always = no
	}
}


# formally take a stance on a tenet known to the faith or learned personally.
pam_evangelize_personal_tenet_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_kingdom_of_heaven.dds"
	}
	decision_group_type = religious

	desc = pam_evangelize_personal_tenet_decision_desc
	selection_tooltip = pam_evangelize_personal_tenet_decision_tooltip
	confirm_text = pam_evangelize_personal_tenet_decision_confirm

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	is_shown = {
		has_tenet_popularity_trigger = yes
		is_playable_character = yes
		any_personal_tenet = {}
		has_pam_dlc_trigger = yes
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = pam_evangelize_personal_tenet_religious_authority_tt
			OR = {
				is_clergy = yes
				AND = { # The puppet route is reserved for players;
					is_ai = no
					has_theological_agent_puppet_trigger = yes
				}
			}
		}
		is_available_adult = yes
		custom_tooltip = {
			text = pam_evangelize_tenet_select_tt
			exists = scope:selected_item
		}
		custom_tooltip = {
			text = pam_evangelize_personal_tenet_valid_targets_tt
			OR = {
				any_subject = {
					pam_characters_to_evangelize_personal_tenet_trigger = yes
				}
				capital_county.clerical_region_title ?= {
					any_ruler_in_clerical_region = {
						NOT = {
							is_vassal_of = root
						}
						pam_characters_to_evangelize_personal_tenet_trigger = yes
					}
				}
			}
		}
	}

	cooldown = { years = 10 }

	cost = {
		piety = {
			value = medium_piety_value
			add = {
				add = evangelized_subjects_count
				add = evangelized_clerical_region_rulers_count
				multiply = 10
			}
		}
	}

	effect = {
		scope:selected_item = { save_scope_as = pam_evangelize_tenet }
		pam_tenet_popularity_on_evangelized_tenet_effect = {
			TENET = scope:pam_evangelize_tenet
			CHANGE = medium_tenet_popularity_gain
		}
		every_subject = {
			limit = {
				pam_characters_to_evangelize_personal_tenet_trigger = yes
			}
			add_to_list = evangelized_subjects
		}
		capital_county.clerical_region_title ?= {
			save_scope_as = clerical_region
			every_ruler_in_clerical_region = {
				limit = {
					NOT = {
						is_vassal_of = root
					}
					pam_characters_to_evangelize_personal_tenet_trigger = yes
				}
				add_to_list = evangelized_clerical_region_rulers
			}
		}
		save_scope_value_as = {
			name = evangelized_subjects_count
			value = list_size:evangelized_subjects
		}
		save_scope_value_as = {
			name = evangelized_clerical_region_rulers_count
			value = list_size:evangelized_clerical_region_rulers
		}
		if = {
			limit = {
				scope:evangelized_subjects_count > 0
				scope:evangelized_clerical_region_rulers_count > 0
			}
			custom_tooltip = can_pick_one_option_tt
		}
		if = {
			limit = { scope:evangelized_subjects_count > 0 }
			custom_tooltip = decision_every_subject_evangelized_personal_tenet_tt
		}
		if = {
			limit = { scope:evangelized_clerical_region_rulers_count > 0 }
			custom_tooltip = decision_every_clerical_region_ruler_evangelized_personal_tenet_tt
		}
		trigger_event = pam_decision_events.0020
	}

	widget = {
		gui = "decision_view_widget_select_tenet"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "SELECT_TENET"

		# We leave this unfiltered on purpose, because ai_select_item and ai_potential do the AI's skipping
		setup_items = {
			scope:actor = {
				ordered_personal_tenet = {
					order_by = {
						value = pam_raw_tenet_popularity_value
						multiply = -1
					}
					max = 200
					check_range_bounds = no
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				ordered_personal_tenet = {
					order_by = pam_tenet_unpopularity_impact_value
					save_scope_as = selected_item
				}
			}
		}

		ai_select_item = {
			scope:actor = {
				random_personal_tenet = {
					limit = {
						save_temporary_scope_as = pam_evangelize_tenet_check
						scope:actor = {
							pam_evangelize_tenet_below_very_popular_trigger = yes
						}
					}
					weight = {
						base = 10
						modifier = {
							add = pam_tenet_unpopularity_impact_value
						}
						modifier = {
							scope:actor.rite  = {
								NOT = {
									has_tenet_status = {
										tenet = prev
										status = core
									}
								}
							}
							add = 10
						}
					}
					save_scope_as = selected_item
				}
			}
		}
	}

	ai_potential = {
		is_clergy = yes
		piety >= medium_piety_value
		any_personal_tenet = {
			save_temporary_scope_as = pam_evangelize_tenet_check
			root = {
				pam_evangelize_tenet_below_very_popular_trigger = yes
			}
		}
	}

	ai_will_do = {
		base = 50
		modifier = {
			add = 20
			has_trait = zealous
		}
		modifier = {
			add = 20
			has_trait = theologian
		}
		modifier = {
			add = -30
			has_trait = cynical
		}

		modifier = {
			add = 200
			any_personal_tenet = {
				root.rite  = {
					NOT = {
						has_tenet_status = {
							tenet = prev
							status = core
						}
					}
				}
				this = scope:selected_item
			}
		}

		modifier = { # Nobody in reach clings to a Popular belief worth luring them away from
			add = -200
			NOR = {
				any_subject = {
					pam_characters_to_evangelize_personal_tenet_trigger = yes
					any_personal_tenet = {
						pam_tenet_is_at_least_popular_trigger = { CHARACTER = root }
					}
				}
				capital_county.clerical_region_title ?= {
					any_ruler_in_clerical_region = {
						NOT = {
							is_vassal_of = root
						}
						pam_characters_to_evangelize_personal_tenet_trigger = yes
						any_personal_tenet = {
							pam_tenet_is_at_least_popular_trigger = { CHARACTER = root }
						}
					}
				}
			}
		}
	}
}

# Spread slander against a tenet known to the faith, chipping away at its popularity.
pam_persecute_tenet_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_send_legatine_mission.dds"
	}
	decision_group_type = religious

	desc = pam_persecute_tenet_decision_desc
	selection_tooltip = pam_persecute_tenet_decision_tooltip
	confirm_text = pam_persecute_tenet_decision_confirm

	sort_order = 110

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 200
		kingdom = 200
		empire = 200
		hegemony = 200
	}

	is_shown = {
		has_tenet_popularity_trigger = yes
		is_playable_character = yes
		has_pam_dlc_trigger = yes
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = pam_evangelize_personal_tenet_religious_authority_tt
			OR = {
				is_clergy = yes
				AND = { # The puppet route is reserved for players; the AI preaches through its own clergy
					is_ai = no
					has_theological_agent_puppet_trigger = yes
				}
			}
		}
		is_available_adult = yes
		custom_tooltip = {
			text = pam_persecute_tenet_select_tt
			exists = scope:selected_item
		}
	}

	cooldown = { years = 10 }

	cost = {
		piety = medium_piety_value
	}

	effect = {
		scope:selected_item = { save_scope_as = pam_persecute_tenet }
		# ROOT resolves to nothing in the toast's loc context, so the persecutor travels as a scope
		save_scope_as = pam_tenet_persecutor
		faith = {
			if = {
				limit = { has_tenet_popularity_trigger = yes }
				change_tenet_popularity = {
					target = scope:pam_persecute_tenet
					change = medium_tenet_popularity_loss
				}
			}
		}
		# Hidden so the new popularity is reported after the change lands, not previewed in the decision tooltip
		hidden_effect = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_persecute_tenet_decision_toast
				left_icon = root
				custom_tooltip = pam_persecute_tenet_decision_toast_tt
			}
		}
	}

	widget = {
		gui = "decision_view_widget_select_tenet"
		controller = select_scope_object
		show_from_start = yes
		decision_to_second_step_button = "SELECT"

		# List is tenets the character personally knows + tenets the rite knows
		setup_items = {
			scope:actor = {
				ordered_character_tenet = {
					knowledge_filter = known
					order_by = pam_raw_tenet_popularity_value
					max = 200
					check_range_bounds = no
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				ordered_character_tenet = {
					knowledge_filter = known
					limit = { pam_tenet_can_be_persecuted_trigger = yes }
					order_by = pam_tenet_popularity_impact_value
					position = 0
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			pam_tenet_can_be_persecuted_trigger = yes
		}

		ai_select_item = {
			scope:actor = {
				random_undesired_tenet = {
					limit = {
						pam_tenet_can_be_persecuted_trigger = yes
						pam_tenet_is_at_least_popular_trigger = { CHARACTER = scope:actor }
					}
					known_tenets = yes
					only_negative = yes
					threshold = -1
					selection_count = 97
					weight = {
						base = 10
						modifier = {
							add = pam_tenet_popularity_impact_value
						}
						modifier = { # The louder the faithful cheer it, the more worth drowning out
							factor = 2
							pam_tenet_is_at_least_very_popular_trigger = { CHARACTER = scope:actor }
						}
					}
					save_scope_as = selected_item
				}
			}
		}
	}

	ai_potential = {
		is_clergy = yes
		piety >= medium_piety_value
		any_undesired_tenet = {
			known_tenets = yes
			only_negative = yes
			threshold = -1
			selection_count = 97
			pam_tenet_can_be_persecuted_no_actor_trigger = yes
			pam_tenet_is_at_least_popular_trigger = { CHARACTER = root }
		}
	}

	ai_will_do = {
		base = 50
		modifier = {
			add = 20
			has_trait = zealous
		}
		modifier = {
			add = 20
			has_trait = theologian
		}
		modifier = {
			add = -30
			has_trait = cynical
		}

		modifier = { # A belief the whole faith cheers is the one most urgent to tear down
			add = 50
			scope:selected_item ?= {
				pam_tenet_is_at_least_very_popular_trigger = { CHARACTER = root }
			}
		}

		modifier = { # Completely immersion-breaking
			add = -200
			faith = faith:roman_catholic_faith
			scope:selected_item = {
				OR = {
					this = tenet:tenet_communion
					this = tenet:tenet_apostolic_succession
					this = tenet:tenet_divine_liturgy
				}
			}
		}
	}
}

### Consecrate a New Kingdom ###
#Found kingdom, but an interaction on the HoF that has reduced land/prestige level reqs
consecrate_kingdom_decision = {
    picture = {
        trigger = {
            culture = { has_graphical_east_asia_culture_group_trigger = yes }
        }
        reference = "gfx/interface/illustrations/activity_splash_screens/tour_arrival_asia_welcome.dds"
    }
    picture = {
        trigger = {
            culture = { has_graphical_india_culture_group_trigger = yes }
        }
        reference = "gfx/interface/illustrations/event_scenes/ep2_feast_indian.dds"
    }
    picture = {
        reference = "gfx/interface/illustrations/decisions/pam_decision_kingdom_of_heaven.dds"
    }
    decision_group_type = major
    ai_check_interval_by_tier = {
        barony = 0
        county = 0
        duchy = 60
        kingdom = 0
        empire = 0
        hegemony = 0
    }
    desc = {
    	first_valid = {
    		triggered_desc = {
    			trigger = {
    				NOT = { exists = faith.religious_head }
        			rite.head_of_rite ?= root
    			}
    			desc = consecrate_kingdom_decision_desc_self
    		}
    		desc = consecrate_kingdom_decision_desc
    	}
    }
    sort_order = 75

    #Titles outside your realm that you can choose to add
    widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "CHOOSE_ADDITIONAL_DUCHIES_DECISION_NEXT_STEP_BUTTON"

		item = { # Newly-exclaved duchies
			value = newly_exclaved_duchies
			is_valid = {
            	custom_tooltip = {
					text = consecrate_kingdom_exclave_duchies_available_tt
            		any_sub_realm_county = {
        				kingdom = {
        					any_direct_de_jure_vassal_title = {
                	   			pam_custom_kingdom_can_claim_duchy_exclave_trigger = { NEW_KING = root }
                	   		}
        				}
                	}
                }
			}
			current_description = newly_exclaved_duchies_decision
			localization = newly_exclaved_duchies_decision
			ai_chance = {
				value = 100
			}
		} 
		item = { # Only Sub-Realm Duchies
			value = only_sub_realm_duchies
			is_valid = {
				always = yes
			}
			current_description = only_sub_realm_duchies_decision
			localization = only_sub_realm_duchies_decision
			ai_chance = {
				value = 0
			}
		}
	}

    is_shown = {
        highest_held_title_tier = tier_duchy
        OR = {
        	has_legitimacy = yes
        	government_has_flag = government_is_theocracy
        }
        is_landed_or_landless_administrative = yes
        is_confederation_member = no
        OR = {
           	exists = rite.head_of_rite
            exists = faith.religious_head
        }
        NOT = {
            has_game_rule = off_custom_kingdoms
        }
        
    }
    is_valid = {
        trigger_if = {
        	limit = {
        		has_legitimacy = yes
        	}
        	legitimacy_level >= 3
        }
        OR = {
            is_independent_ruler = yes
            custom_tooltip = {
                text = liege_is_two_tiers_higher_or_more_tt
                liege ?= {
                    highest_held_title_tier >= tier_empire
                }
            }   
        }
        trigger_if = {
            limit = {
                government_has_flag = government_is_nomadic
            }
            OR = {
                has_realm_law = nomadic_authority_5
                has_realm_law = nomadic_authority_4
                has_realm_law = nomadic_authority_3
            }
        }
        #If not doing on yourself
        trigger_if = {
    		limit = {
    			NOR = {
        			faith.religious_head ?= root
        			AND = {
        				NOT = {
        					exists = faith.religious_head
        				}
        				rite.head_of_rite ?= root
        			}
        		}
    		}
    		custom_tooltip = {
    			text = court_chaplain_puppet_tt
    			exists = root.cp:councillor_court_chaplain
    			root.puppet:theological_agent_puppet ?= root.cp:councillor_court_chaplain
    		}
    		OR = {
    			trigger_if = {
    				limit = {
    					exists = faith.religious_head
    				}
    				faith.religious_head = { save_temporary_scope_as = faith_authority }
    				has_hook = faith.religious_head
    			}
    			trigger_else = {
    				rite.head_of_rite = { save_temporary_scope_as = faith_authority }
    				has_strong_hook = rite.head_of_rite
    			}
    			trigger_if = {
    				limit = {
    					exists = faith.religious_head
    				}
    				custom_tooltip = {
    					text = puppeting_faith_authority_tt
    					OR = {
    						root.puppet:theological_agent_puppet ?= this
							root.puppet:external_theological_agent_puppet ?= this
						}
    				}
    			}
    			trigger_else = {
    				custom_tooltip = {
    					text = puppeting_faith_authority_tt
    					OR = {
    						root.puppet:theological_agent_puppet ?= this
							root.puppet:external_theological_agent_puppet ?= this
						}
    				}
    			}
    			AND = {
    				trigger_if = {
    					limit = {
    						exists = faith.religious_head
    						faith.religious_head = {
    							is_ai = yes
    						}
    					}
    					faith.religious_head = {
    						opinion = {
    							target = root
    							value >= 0
    						}
    					}
    				}
    				trigger_if = {
    					limit = {
    						NOT = { exists = faith.religious_head }
    						rite.head_of_rite = {
    							is_ai = yes
    						}
    					}
    					rite.head_of_rite = {
    						opinion = {
    							target = root
    							value >= 0
    						}
    					}
    				}
    				#You gotta have a reason man
    				OR = {
    					custom_tooltip = {
    						text = realm_contains_holy_site_tt
    						any_sub_realm_county = {
    							any_county_province = {
									barony = {
										is_holy_site_of = root.faith
									}
								}
    						}
    					}
    					custom_tooltip = {
    						text = neighbors_hostile_faith_tt
    						any_sub_realm_county = {
    							any_neighboring_county = {
    								holder.top_liege ?= {
    									NOT = {
    										faith = root.faith
    									}
    									faith = {
    										faith_hostility_level = {
												target = root.faith
												value >= faith_hostile_level
											}
    									}
    								}
    							}
    						}
    					}
    					trigger_if = {
    						limit = {
    							exists = faith.religious_head
    						}
							custom_tooltip = {
    							text = house_is_faith_head_or_cardinal_tt
    							exists = root.house
    							OR = {
    								faith.religious_head.house ?= root.house
    								faith = {
    									any_faith_subordinate = {
    										exists = clerical_elector_title
    										house = root.house
    									}
    								}
    							}
    						}
    					}
    					trigger_else = {
							custom_tooltip = {
    							text = house_is_faith_head_or_cardinal_tt
    							exists = root.house
    							OR = {
    								rite.head_of_rite.house ?= root.house
    								faith = {
    									any_faith_subordinate = {
    										exists = clerical_elector_title
    										house = root.house
    									}
    								}
    							}
    						}
    					}
    					custom_tooltip = {
    						text = is_holy_order_patron_tt
    						any_patroned_holy_order = {
    							leader.faith ?= root.faith
    						}
    					}
    					piety_level >= 4
    				}
    			}
    		}
    	}
    	trigger_else = {
        	piety_level >= 3
    	}
        trigger_if = {
    		limit = {
    			any_held_title = {
    				tier = tier_duchy
    				is_landless_type_title = yes
    			}
    		}
    		custom_tooltip = {
    			text = any_landed_duchy_title_tt
    			any_held_title = {
    				tier = tier_duchy
    				is_landless_type_title = no
    			}
    		}
    	}
        #No HoF? Then we are using HoR and it must be someone ecclesiastical
      	OR = {
        	custom_tooltip = {
        	    text = head_of_faith_tt
        	    exists = faith.religious_head
        	}
        	custom_tooltip = {
        	    text = head_of_rite_can_consecrate_kingdom_tt
        	    rite.head_of_rite = {
        	        government_has_flag = government_is_theocracy
        	        highest_held_title_tier >= tier_duchy
        	    }
        	}
        }
    }
    is_valid_showing_failures_only = {
		NOT = {
			has_character_modifier = promised_pilgrimage_to_clergy_modifier
		}
        is_available_adult = yes
        is_at_war = no
        trigger_if = {
            limit = {
                exists = faith.religious_head
            }
        }
        trigger_else = {
        	trigger_if = {
        		limit = {
        			is_independent_ruler = no
        		}
        		custom_tooltip = {
					text = head_of_rite_is_not_lieges_head_of_rite_tt
					exists = liege.rite.head_of_rite
					rite.head_of_rite ?= liege.rite.head_of_rite
				}
        	}
        }
    }
    cost = {
        gold = {
            value = 150
            multiply = ecclesiastical_domicile_consecration_cost_mult
            if = {
                limit = {
                    OR = {
                        government_has_flag = government_is_nomadic
                        has_treasury = yes
                    }
                }
                multiply = 0
            }
        }
        treasury = {
            value = 150
            multiply = ecclesiastical_domicile_consecration_cost_mult
            if = {
                limit = {
                    has_treasury = no
                }
                multiply = 0
            }
        }
        piety = {
            value = 750
        	if = {
        		limit = {
        			government_has_flag = government_is_theocracy
        		}
        		add = 250
        	}
        	if = {
        		limit = {
        			OR = {
        				faith.religious_head ?= root
        				AND = {
        					rite.head_of_rite ?= root
        					NOT = {
        						exists = faith.religious_head
        					}
        				}
        			}
        		}
        		add = 250
        	}
        	multiply = ecclesiastical_domicile_consecration_cost_mult
        }
    }
    effect = {
        save_scope_as = recipient
        save_scope_as = king_aspirant
        if = {
            limit = {
                exists = faith.religious_head
            }
            faith.religious_head = {
                save_scope_as = religious_authority
                save_scope_as = puppet_or_actor
            }
        }
        else = {
            rite.head_of_rite = {
                save_scope_as = religious_authority
                save_scope_as = puppet_or_actor
            }
        }
        #Give player pope chance to approve/disapprove
        if = {
        	limit = {
        		scope:religious_authority = {
        			NOT = {
        				this = root
        			}
        			is_ai = no
        		}
        	}
        	custom_tooltip = consecrate_kingdom_player_warning_tt
        	save_scope_as = king_aspirant
        	scope:religious_authority = {
        		trigger_event = {
        			id = pam_decision_events.0030
        			days = 1
        		}
        	}
        	show_as_tooltip = {
        		consecrate_kingdom_effect = yes
        	}
        }
        #Go straight to effect
        else = {
        	consecrate_kingdom_effect = yes
        }
        if = {
        	limit = {
        		scope:religious_authority = root
        	}
        	stress_impact = {
        		humble = major_stress_impact_gain
        		content = major_stress_impact_gain
        		just = major_stress_impact_gain
        	}
        }
        if = {
        	limit = {
        		is_independent_ruler = no
        	}
        	liege = {
        		add_opinion = {
					target = root
					modifier = circumvented_my_authority_opinion
					opinion = -20
				}
        	}
        }
    }
    ai_potential = {
        NOR = {
        	has_trait = greatest_of_khans
        	has_trait = conqueror
        	has_trait = ambitious
        	has_trait = cynical
        	has_trait = just
        }
    }
    ai_will_do = {
        base = 50
        modifier = {
        	government_has_flag = government_is_theocracy
        	factor = 0.5
        }
        modifier = {
        	OR = {
        		faith.religious_head ?= root
        		AND = {
        			rite.head_of_rite ?= root
        			NOT = {
        				exists = faith.religious_head
        			}
        		}
        	}
        	OR = {
        		has_trait = humble
        		has_trait = content
        		has_trait = just
        		ai_honor > 0
        		ai_greed < 0
        	}
        	factor = 0
        }
    }
}

# Prepare the Holy Myron, with the artifact's quality set by how far the journey goes
pam_prepare_holy_myron_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_demote_holy_site.dds"
	}
	decision_group_type = religious
	desc = pam_prepare_holy_myron_decision_desc
	selection_tooltip = pam_prepare_holy_myron_decision_tooltip
	confirm_text = pam_prepare_holy_myron_decision_confirm
    sort_order = 111

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 70
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	cooldown = { years = 10 }

	is_shown = {
		# Landless heads of faith are is_landed = no, but they still hold a Court Chaplain seat.
		OR = {
			is_landed = yes
			government_has_flag = government_is_theocracy
		}
		rite ?= {
			rite_has_parameter = tenet_holy_myron_artifact
		}
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		custom_description = {
			text = pam_prepare_holy_myron_decision_needs_chaplain
			cp:councillor_court_chaplain ?= {
				is_available_adult = yes
				is_travelling = no
			}
		}
		custom_description = {
			text = pam_prepare_holy_myron_decision_already_owned
			pam_has_usable_holy_myron_trigger = no
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = pam_prepare_holy_myron_decision_journey_underway
			# The abort on_action only runs for rulers, so an unlanded chaplain never reaches cleanup
			trigger_if = {
				limit = { has_variable = pam_holy_myron_journey_active }
				NOT = {
					var:pam_holy_myron_journey_active ?= {
						is_alive = yes
						is_travelling = yes
					}
				}
			}
		}
	}

	# The selected widget option is exposed as a bool scope, so the cost tracks the chosen journey.
	cost = {
		gold = {
			if = {
				limit = { scope:pam_myron_india_journey ?= yes }
				value = pam_holy_myron_india_journey_gold_value
			}
			else_if = {
				limit = { scope:pam_myron_arabia_journey ?= yes }
				value = major_gold_value
			}
			else = {
				value = medium_gold_value
			}
		}
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = yes

		item = { # Balsam only: Jerusalem
			value = pam_myron_levant_journey
			is_default = yes
			localization = pam_prepare_holy_myron_decision_levant_name
			current_description = pam_prepare_holy_myron_decision_levant_desc
			icon = "gfx/interface/icons/artifact/pilgrim_jerusalem.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						gold < pam_holy_myron_arabia_ai_gold_value
					}
					add = 100
				}
			}
		}
		item = { # Balsam and frankincense: Jerusalem, Dhofar
			value = pam_myron_arabia_journey
			is_valid = {
				custom_tooltip = {
					text = pam_prepare_holy_myron_decision_afford_arabia_tt
					gold >= major_gold_value
				}
			}
			localization = pam_prepare_holy_myron_decision_arabia_name
			current_description = pam_prepare_holy_myron_decision_arabia_desc
			icon = "gfx/interface/icons/artifact/artifact_icons_unique_artifact_holy_branch.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						gold >= pam_holy_myron_arabia_ai_gold_value
						gold < pam_holy_myron_india_ai_gold_value
					}
					add = 100
				}
			}
		}
		item = { # The full recipe: Jerusalem, Dhofar, Kerala
			value = pam_myron_india_journey
			is_valid = {
				custom_tooltip = {
					text = pam_prepare_holy_myron_decision_afford_india_tt
					gold >= pam_holy_myron_india_journey_gold_value
				}
			}
			localization = pam_prepare_holy_myron_decision_india_name
			current_description = pam_prepare_holy_myron_decision_india_desc
			icon = "gfx/interface/icons/artifact/artifact_pressed_flowers.dds"
			ai_chance = {
				value = 0
				if = {
					limit = {
						gold >= pam_holy_myron_india_ai_gold_value
					}
					add = 100
				}
			}
		}
	}

	effect = {
		if = {
			limit = { scope:pam_myron_levant_journey = yes }
			custom_tooltip = pam_prepare_holy_myron_decision_levant_effect_tt
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = pam_prepare_holy_myron_journey_toast
				left_icon = cp:councillor_court_chaplain
				custom_tooltip = pam_prepare_holy_myron_journey_toast_tt
			}
			hidden_effect = {
				set_variable = {
					name = pam_holy_myron_journey_active
					value = cp:councillor_court_chaplain
					years = 30
				}
				cp:councillor_court_chaplain = {
					set_variable = {
						name = pam_holy_myron_journey_tier
						value = 1
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_liege
						value = root
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_legs
						value = 0
						years = 30
					}
					# The homecoming leg is skipped when the destination is already the departure province
					set_variable = {
						name = pam_holy_myron_expected_legs
						value = 2
						years = 30
					}
					if = {
						limit = { location = title:c_jerusalem.title_province }
						change_variable = {
							name = pam_holy_myron_expected_legs
							subtract = 1
						}
					}
					add_character_modifier = {
						modifier = pam_holy_myron_pilgrim_modifier
						years = 30
					}
					start_travel_plan = {
						destination = title:c_jerusalem.title_province
						return_trip = yes
						on_arrival_event = pam_holy_myron.0010
						on_arrival_destinations = all
					}
				}
			}
		}
		else_if = {
			limit = { scope:pam_myron_arabia_journey = yes }
			custom_tooltip = pam_prepare_holy_myron_decision_arabia_effect_tt
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = pam_prepare_holy_myron_journey_toast
				left_icon = cp:councillor_court_chaplain
				custom_tooltip = pam_prepare_holy_myron_journey_toast_tt
			}
			hidden_effect = {
				set_variable = {
					name = pam_holy_myron_journey_active
					value = cp:councillor_court_chaplain
					years = 30
				}
				cp:councillor_court_chaplain = {
					set_variable = {
						name = pam_holy_myron_journey_tier
						value = 2
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_liege
						value = root
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_legs
						value = 0
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_expected_legs
						value = 3
						years = 30
					}
					if = {
						limit = { location = title:c_dhofar.title_province }
						change_variable = {
							name = pam_holy_myron_expected_legs
							subtract = 1
						}
					}
					add_character_modifier = {
						modifier = pam_holy_myron_pilgrim_modifier
						years = 30
					}
					start_travel_plan = {
						destination = title:c_jerusalem.title_province
						destination = title:c_dhofar.title_province
						return_trip = yes
						on_arrival_event = pam_holy_myron.0010
						on_arrival_destinations = all
					}
				}
			}
		}
		else = {
			custom_tooltip = pam_prepare_holy_myron_decision_india_effect_tt
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = pam_prepare_holy_myron_journey_toast
				left_icon = cp:councillor_court_chaplain
				custom_tooltip = pam_prepare_holy_myron_journey_toast_tt
			}
			hidden_effect = {
				set_variable = {
					name = pam_holy_myron_journey_active
					value = cp:councillor_court_chaplain
					years = 30
				}
				cp:councillor_court_chaplain = {
					set_variable = {
						name = pam_holy_myron_journey_tier
						value = 3
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_liege
						value = root
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_legs
						value = 0
						years = 30
					}
					set_variable = {
						name = pam_holy_myron_expected_legs
						value = 4
						years = 30
					}
					if = {
						limit = { location = title:c_kerala.title_province }
						change_variable = {
							name = pam_holy_myron_expected_legs
							subtract = 1
						}
					}
					add_character_modifier = {
						modifier = pam_holy_myron_pilgrim_modifier
						years = 30
					}
					start_travel_plan = {
						destination = title:c_jerusalem.title_province
						destination = title:c_dhofar.title_province
						destination = title:c_kerala.title_province
						return_trip = yes
						on_arrival_event = pam_holy_myron.0010
						on_arrival_destinations = all
					}
				}
			}
		}
	}

	ai_potential = {
		is_at_war = no
		cp:councillor_court_chaplain ?= {
			is_ai = yes
			is_available_adult = yes
			is_travelling = no
		}
		pam_has_usable_holy_myron_trigger = no
		NOR = {
			has_trait = cynical
			has_variable = pam_holy_myron_journey_active
		}
	}

	ai_will_do = {
		base = 100
	}
}

# Anoint an artifact with the Holy Myron to sanctify it for your faith, spending a charge
pam_anoint_artifact_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_confession.dds"
	}
	decision_group_type = religious
	desc = pam_anoint_artifact_decision_desc
	selection_tooltip = pam_anoint_artifact_decision_tooltip
	confirm_text = pam_anoint_artifact_decision_confirm
    sort_order = 111
	cooldown = { years = 1 }

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 144
		kingdom = 72
		empire = 60
		hegemony = 36
	}
	
	cost = {
		piety = major_piety_value
	}

	is_shown = {
		OR = {
			rite ?= {
				rite_has_parameter = tenet_holy_myron_artifact
			}
			pam_has_usable_holy_myron_trigger = yes
		}
		is_christian_trigger = yes
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		custom_description = {
			text = pam_anoint_artifact_needs_myron_tt
			pam_has_usable_holy_myron_trigger = yes
		}
		custom_description = {
			text = pam_anoint_artifact_has_eligible_artifact_tt
			any_character_artifact = {
				pam_is_holy_myron_artifact_trigger = no
				NOT = { is_sanctified_for_faith = root.faith }
				NOT = { has_artifact_modifier = pam_chrismated_artifact_modifier }
			}
		}
	}

	is_valid_showing_failures_only = {
		is_physically_able = yes
	}

	widget = {
		gui = "decision_view_widget_select_artifact"
		controller = select_scope_object

		setup_items = {
			scope:actor = {
				every_character_artifact = {
					limit = {
						pam_is_holy_myron_artifact_trigger = no
						NOT = { is_sanctified_for_faith = scope:actor.faith }
						NOT = { has_artifact_modifier = pam_chrismated_artifact_modifier }
					}
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				random_character_artifact = {
					limit = {
						pam_is_holy_myron_artifact_trigger = no
						NOT = { is_sanctified_for_faith = scope:actor.faith }
						NOT = { has_artifact_modifier = pam_chrismated_artifact_modifier }
					}
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			custom_tooltip = {
				text = pam_anoint_artifact_not_myron_tt
				pam_is_holy_myron_artifact_trigger = no
			}
			custom_tooltip = {
				text = sanctify_artifact_not_already_sanctified_tt
				NOT = { is_sanctified_for_faith = scope:actor.faith }
			}
			custom_tooltip = {
				text = pam_anoint_artifact_not_already_chrismated_tt
				NOT = { has_artifact_modifier = pam_chrismated_artifact_modifier }
			}
		}

		ai_item_will_do = {
			value = 10
			if = {
				limit = { rarity_level >= famed }
				add = 20
			}
		}
	}

	effect = {
		# The effect tooltip renders before an item is picked, so scope:selected_item can be unset
		if = {
			limit = { exists = scope:selected_item }
			pam_holy_myron_spend_warning_effect = yes
			hidden_effect = {
				pam_save_holy_myron_artifact_effect = yes
				pam_holy_myron_consume_charge_effect = {
					ARTIFACT = scope:pam_holy_myron_artifact
				}
			}
			# Saved before add_sanctified_for_faith, or it becomes a holy relic and the check fails
			scope:selected_item = {
				save_scope_as = pam_anointed_artifact
				if = {
					limit = { is_holy_relic = no }
					add_artifact_modifier = pam_chrismated_artifact_modifier
				}
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = pam_anoint_artifact_toast
				left_icon = root
				right_icon = scope:selected_item

				scope:selected_item = {
					add_sanctified_for_faith = root.faith
					hidden_effect = {
						set_artifact_name = pam_chrismated_artifact_name
						set_artifact_description = pam_chrismated_artifact_desc
					}
				}
				if = {
					limit = { is_playable_character = yes }
					change_spiritual_fulfillment = medium_spiritual_fulfillment_value
				}
				cp:councillor_court_chaplain ?= {
					add_piety = minor_piety_gain
				}
			}
		}
	}

	ai_potential = {
		pam_has_usable_holy_myron_trigger = yes
		any_character_artifact = {
			pam_is_holy_myron_artifact_trigger = no
			NOT = { is_sanctified_for_faith = root.faith }
			NOT = { has_artifact_modifier = pam_chrismated_artifact_modifier }
		}
	}

	ai_will_do = {
		base = 15
		modifier = {
			has_trait = zealous
			add = 15
		}
		modifier = {
			has_trait = cynical
			factor = 0
		}
	}
}

### Invite Syncretic Exiles ###
pam_invite_syncretic_exiles_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_kingdom_of_heaven.dds"
	}
	decision_group_type = religious
	sort_order = 100
	cooldown = { years = 15 }

	desc = pam_invite_syncretic_exiles_decision_desc
	selection_tooltip = pam_invite_syncretic_exiles_decision_tooltip
	confirm_text = pam_invite_syncretic_exiles_decision_confirm

	is_shown = {
		pam_personal_syncretism_invite_exiles_available_trigger = yes
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		pam_personal_syncretism_invite_exiles_available_trigger = yes
		is_landed = yes
		exists = capital_province
	}

	is_valid_showing_failures_only = {
		is_landed = yes
		exists = capital_province
		custom_tooltip = {
			text = invite_exiles_same_faith_county_req
			any_sub_realm_county = {
				faith = root.faith
			}
		}
		trigger_if = {
			limit = {
				any_sub_realm_county = {
					faith = root.faith
				}
			}
			custom_tooltip = {
				text = pam_invite_syncretic_exiles_no_pool
				any_religion_global = {
					any_faith = {
						any_faith_rite = {
							pam_personal_syncretism_exile_rite_probe_trigger = yes
						}
					}
				}
			}
		}
	}

	cost = {
		piety = major_piety_value
	}

	effect = {
		save_scope_as = root_scope
		save_scope_as = from_decision
		save_scope_as = pam_syncretic_exiles_decision
		hidden_effect = {
			random_religion_global = {
				limit = {
					any_faith = {
						any_faith_rite = {
							pam_personal_syncretism_exile_rite_trigger = yes
						}
					}
				}
				random_faith = {
					limit = {
						any_faith_rite = {
							pam_personal_syncretism_exile_rite_trigger = yes
						}
					}
					ordered_faith_rite = {
						limit = {
							pam_personal_syncretism_exile_rite_trigger = yes
						}
						order_by = var:converted_development
						save_scope_as = target_rite
					}
				}
			}
			if = {
				limit = { exists = scope:target_rite }
				custom_tooltip = pam_invite_syncretic_exiles_decision_effect
				if = {
					limit = {
						scope:root_scope.faith != scope:target_rite.faith
					}
					scope:root_scope = {
						save_scope_as = ruler_target
						save_scope_as = seeking_any_counties
						trigger_event = global_religion.1000
					}
				}
				else = {
					scope:root_scope = {
						save_scope_as = ruler_target
						save_scope_as = seeking_same_faith_counties
						trigger_event = global_religion.1000
					}
				}
			}
		}
		if = {
			limit = {
				NOT = { exists = scope:target_rite }
			}
			add_piety = major_piety_value
			custom_tooltip = pam_invite_syncretic_exiles_no_pool
		}
		close_view = {
			view = decisions
			player = root
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 0
	}
}

# Take Up Religious Study: starts the Religious Study personal scheme
pam_study_scripture_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_reform_monastic_endowment.dds"
	}
	decision_group_type = religious

	desc = pam_study_scripture_decision_desc
	selection_tooltip = pam_study_scripture_decision_tooltip

	sort_order = 120

	cooldown = { years = 5 }

	cost = {
	}

	is_shown = {
		pam_government_is_religious_playable_trigger = yes
		is_playable_character = yes
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		custom_tooltip = {
			text = pam_study_scripture_decision_req_tt
			NOT = {
				any_scheme = {
					type = study_scripture
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		NOT = {
			has_character_modifier = pam_lapsed_studies_modifier
		}
		is_available = yes
		can_start_scheme = {
			type = study_scripture
			target_character = root
		}
	}

	effect = {
		custom_tooltip = {
			text = pam_study_scripture_decision_tt
			start_scheme = {
				type = study_scripture
				target_character = root
			}
			close_view = {
				view = decisions
				player = root
			}
			random_scheme = {
				type = study_scripture
				save_scope_as = scheme
			}
			save_scope_as = owner
			trigger_event = study_scripture_outcome.10
		}
		if = {
			limit = {
				any_scheme = { is_scheme_category = personal }
			}
			custom_tooltip = pam_study_scripture_decision_end_scheme_tt
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 180
		duchy = 48
		kingdom = 48
		empire = 48
		hegemony = 48
	}

	ai_potential = {
		is_imprisoned = no
		is_at_war = no
		OR = {
			piety <= 750
			ai_zeal >= 100
			has_personality_submissive_trigger = yes
			NOT = {
				has_trait = lifestyle_scholar
			}
		}
		NOR = {
			stress_level >= 1
			has_trait = lazy
			# Never overwrite a running personal scheme such as Sway
			any_scheme = { is_scheme_category = personal }
		}
	}

	ai_will_do = {
		base = 100
	}
}

# Personal Sacrifice of Wealth
pam_personal_sacrifice_of_wealth_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_act_of_devotion.dds"
	}
	decision_group_type = religious

	desc = pam_personal_sacrifice_of_wealth_decision_desc
	selection_tooltip = pam_personal_sacrifice_of_wealth_decision_tooltip
	sort_order = 80

	ai_check_interval_by_tier = {
		barony = 0
		county = 60
		duchy = 60
		kingdom = 48
		empire = 48
		hegemony = 48
	}

	is_shown = {
		has_personal_tenet_flag = gruesome_festivals_personal_sacrifice
		is_landed = yes
		any_sub_realm_county = {
			always = yes
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		scope:selected_item ?= {
			tier = tier_county
			holder = {
				OR = {
					this = root
					target_is_liege_or_above = root
				}
			}
		}
	}

	cooldown = { years = 5 }

	cost = {
		gold = medium_gold_value
	}

	widget = {
		gui = "decision_view_widget_select_realm_county"
		controller = select_scope_object

		setup_items = {
			scope:actor = {
				every_sub_realm_county = {
					add_to_list = item_list
				}
			}
		}

		default_item = {
			scope:actor = {
				capital_county = {
					save_scope_as = selected_item
				}
			}
		}

		is_item_valid = {
			tier = tier_county
			holder = {
				OR = {
					this = scope:actor
					target_is_liege_or_above = scope:actor
				}
			}
		}

		ai_item_will_do = {
			value = 10
			if = {
				limit = { development_level <= bad_development_level }
				add = 50
			}
			if = {
				limit = { this = scope:actor.capital_county }
				add = 10
			}
		}
	}

	effect = {
		change_spiritual_fulfillment = minor_spiritual_fulfillment_value
		send_interface_toast = {
			type = event_toast_effect_good
			title = pam_personal_sacrifice_of_wealth_decision_toast
			right_icon = scope:selected_item
		}
		scope:selected_item = {
			add_county_modifier = {
				modifier = pam_personal_sacrifice_of_wealth_county_modifier
				years = 5
			}
		}
	}

	ai_potential = {
		has_personal_tenet_flag = gruesome_festivals_personal_sacrifice
		any_sub_realm_county = {
			always = yes
		}
	}

	ai_will_do = {
		base = 25
		modifier = {
			add = 20
			has_trait = generous
		}
		modifier = {
			add = 20
			has_trait = zealous
		}
		modifier = {
			factor = 0
			NOT = { any_sub_realm_county = { development_level <= bad_development_level } }
		}
	}
}

# Develop Clerical Court
pam_develop_clerical_court_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_mentor_sp.dds"
	}
	decision_group_type = religious

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { is_christian_trigger = yes }
				desc = pam_develop_clerical_court_decision_desc_christian
			}
			desc = pam_develop_clerical_court_decision_desc
		}
	}
	selection_tooltip = pam_develop_clerical_court_decision_tooltip
	sort_order = 115

	cooldown = { years = 5 }

	cost = {
		treasury_or_gold = minor_treasury_or_gold_value
	}

	is_shown = {
		is_available_adult = yes
		pam_government_is_religious_playable_trigger = yes
		is_playable_character = yes
		has_pam_dlc_trigger = yes
	}

	is_valid = {
		custom_description = {
			text = pam_develop_clerical_court_decision_candidates_tt
			OR = {
				any_courtier = { pam_clerical_court_ordain_candidate_trigger = yes }
				any_courtier = { pam_clerical_court_pupil_trigger = yes }
				any_pool_character = {
					province = root.location
					pam_clerical_court_novice_trigger = { RULER = root }
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
	}

	effect = {
		custom_tooltip = pam_develop_clerical_court_decision_tt
		trigger_event = pam_decision_events.0032
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 120
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_potential = {
		is_at_war = no
		pam_government_is_religious_playable_trigger = yes
		OR = {
			any_courtier = { pam_clerical_court_ordain_candidate_trigger = yes }
			any_courtier = { pam_clerical_court_pupil_trigger = yes }
			# A novice to call on, and room left under the clergy-in-court cap so calling is productive
			AND = {
				any_pool_character = {
					province = root.location
					pam_clerical_court_novice_trigger = { RULER = root }
				}
				any_courtier = {
					count < pam_clerical_court_size_cap_value
					is_clergy = yes
				}
			}
		}
	}

	ai_will_do = {
		base = 100
		modifier = {
			add = -25
			has_trait = cynical
		}
		modifier = {
			add = -75
			has_trait = greedy
		}
	}
}

# Seize the Clerical Region at the capital
pam_seize_capital_clerical_region_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/pam_decision_papal_petition.dds"
	}
	# major is an important_decision_group, which is what makes the alert default to on
	decision_group_type = major

	desc = pam_seize_capital_clerical_region_decision_desc
	selection_tooltip = pam_seize_capital_clerical_region_decision_tooltip

	sort_order = 105

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	# Everything sits in is_shown on purpose: a Head of Faith with no seizable see has nothing to work toward here
	is_shown = {
		faith ?= { has_doctrine_parameter = has_clerical_regions }
		faith.religious_head ?= this
		# One region per ruler, which also covers already holding the one at the capital
		NOT = { any_held_title = { has_clerical_region = yes } }
		capital_county.clerical_region_title ?= {
			has_clerical_region = yes
			is_head_of_faith = no
			OR = {
				# A see still sitting on a dead holder is the broken state this clears, so it skips the faith checks
				holder ?= { is_alive = no }
				AND = {
					root.capital_county.faith ?= root.faith
					trigger_if = {
						limit = { exists = holder }
						holder = {
							is_ai = yes
							faith = root.faith
						}
					}
				}
			}
		}
		has_pam_dlc_trigger = yes
	}

	effect = {
		capital_county.clerical_region_title ?= {
			save_scope_as = pam_seized_clerical_region
			# Only a living holder is deposed; a dead one has nothing to be told
			if = {
				limit = { holder ?= { is_alive = yes } }
				holder = { save_scope_as = pam_deposed_archbishop }
			}
		}
		if = {
			limit = { exists = scope:pam_deposed_archbishop }
			custom_tooltip = pam_seize_capital_clerical_region_decision_deposed_tt
		}
		custom_tooltip = {
			text = pam_seize_capital_clerical_region_decision_effect_tt
			create_title_and_vassal_change = {
				type = granted
				save_scope_as = change
				add_claim_on_loss = no
			}
			scope:pam_seized_clerical_region = {
				change_title_holder_include_vassals = {
					holder = root
					change = scope:change
				}
			}
			resolve_title_and_vassal_change = scope:change
		}
	}

	ai_will_do = {
		base = 100
	}
}
