﻿take_vow_of_poverty_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = take_vow_of_poverty_decision_desc
	selection_tooltip = take_vow_of_poverty_decision_tooltip

	is_shown = {
		is_ruler = yes
		faith = {
			has_doctrine_parameter = vows_of_poverty_active
		}
		NOT = { has_character_modifier = vow_of_poverty_modifier }
	}

	effect = {
		add_character_modifier = {
			modifier = vow_of_poverty_modifier
		}

		stress_impact = {
			greedy = major_stress_impact_gain
			cynical = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
	}
	
	ai_check_interval = 120

	ai_potential = {
		# AI considers taking if their income exceeds their expenses * 1.4 (decision will reduce it by 20%).
		monthly_character_income > monthly_character_expenses_plus_fourty_percent
	}

	ai_will_do = {
		base = 0

		# If ai_zeal is 20 points higher than ai_greed, becomes 100% chance.
		ai_value_modifier = {
			ai_zeal = 5
			ai_greed = -5
		}
	}
}

renounce_vow_of_poverty_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = renounce_vow_of_poverty_decision_desc
	selection_tooltip = renounce_vow_of_poverty_decision_tooltip

	is_shown = {
		is_ruler = yes
		faith = {
			has_doctrine_parameter = vows_of_poverty_active
		}
		has_character_modifier = vow_of_poverty_modifier
	}

	effect = {
		add_piety = medium_piety_loss
		remove_character_modifier = vow_of_poverty_modifier

		stress_impact = {
			generous = major_stress_impact_gain
			zealous = medium_stress_impact_gain
			humble = minor_stress_impact_gain
		}
	}
	
	ai_check_interval = 60

	ai_potential = {
		# AI will consider if we're spending more money than we're making, and their treasury is low.
		monthly_character_expenses > monthly_character_income
		short_term_gold < minor_gold_value
		long_term_gold < minor_gold_value
	}

	ai_will_do = {
		base = 0

		# If ai_rationality + ai_greed exceeds ai_zeal by 20 points or more, becomes 100% chance.
		ai_value_modifier = {
			ai_rationality = 5
			ai_zeal = -5
			ai_greed = 5
		}
	}
}

initiate_consolamentum_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = initiate_consolamentum_decision_desc
	selection_tooltip = initiate_consolamentum_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = consolamentum_active
		}
	}

	is_valid = {
		OR = {
			age >= 60
			custom_description = {
				text = decision_consolamentum_health
				health <= 1
			}
			has_trait = incapable
		}
	}

	effect = {
		hidden_effect = {
			add_piety_level = 1
		}
		death = { death_reason = death_suicide}
		show_as_tooltip = {
			add_piety_level = 1
		}
	}

	ai_check_interval = 60
	
	ai_potential = {		
		exists = primary_heir
		primary_heir = {
			dynasty = root.dynasty
		}
		is_at_war = no
	}

	ai_will_do = {
		base = 0

		# 100% chance at 50 zeal
		ai_value_modifier = {
			ai_zeal = 2
		}

		modifier = {
			add = 40
			is_close_family_of = primary_heir
		}
	}
}

seek_aid_of_the_spirits_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = seek_aid_of_the_spirits_decision_desc
	selection_tooltip = seek_aid_of_the_spirits_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = spirit_possession_active
		}
	}

	is_valid = {
		custom_description = {
			text = decision_has_court_chaplain
			exists = cp:councillor_court_chaplain
			cp:councillor_court_chaplain = {
				is_available_adult = yes
			}
		}
		NOT = { has_trait = possessed }
		custom_description = {
			text = decision_sought_aid_of_spirits
			NOT = { has_character_flag = flag_sought_aid_of_spirits }
		}
	}

	is_valid_showing_failures_only = {
	}

	effect = {
		custom_tooltip = seek_aid_of_the_spirits_decision_effect.tt
		trigger_event = religious_decision.0001
	}

	ai_check_interval = 60
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 50

		# 100% chance at 50 zeal, 0% chance at -50 zeal.
		ai_value_modifier = {
			ai_zeal = 1
		}		
	}
}

select_personal_deity_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = select_personal_deity_decision_desc
	selection_tooltip = select_personal_deity_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = select_personal_god_active
		}
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {
	}

	effect = {
		custom_tooltip = select_personal_deity_decision_tt
		trigger_event = religious_decision.0101
	}

	ai_check_interval = 96
	
	ai_potential = {
		piety >= minor_piety_value
		NOR = {
			has_character_modifier = bhakti_hinduism_ganga
			has_character_modifier = bhakti_hinduism_saraswati
			has_character_modifier = bhakti_hinduism_kali
			has_character_modifier = bhakti_hinduism_kubera
			has_character_modifier = bhakti_vaishnavism_lakishmi
			has_character_modifier = bhakti_vaishnavism_jagganath
			has_character_modifier = bhakti_vaishnavism_hayagriva
			has_character_modifier = bhakti_shaivism_parvati
			has_character_modifier = bhakti_shaivism_virabhadra
			has_character_modifier = bhakti_shaivism_munishwarar
			has_character_modifier = bhakti_shaivism_dakshinamoorthy
			has_character_modifier = bhakti_smartism_ganesha
			has_character_modifier = bhakti_smartism_vishnu
			has_character_modifier = bhakti_smartism_shiva
		}
	}

	ai_will_do = {
		base = 100
	}
}

meditate_in_seclusion_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = meditate_in_seclusion_decision_desc
	selection_tooltip = meditate_in_seclusion_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = meditation_mechanics_active
		}
		holds_landed_title = yes
	}

	is_valid = {

	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
	}

	effect = {
		custom_tooltip = meditate_in_seclusion_tooltip
		trigger_event = religious_decision.0201
	}

	ai_check_interval = 60
	cooldown = { months = 36 }	

	ai_potential = {
		is_at_war = no
		stress >= 75
	}

	ai_will_do = {
		base = 100
	}
}

give_sky_burial_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = give_sky_burial_decision_desc
	selection_tooltip = give_sky_burial_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = sky_burials_active
		}
		has_variable = ancestor_to_bury
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {

	}

	effect = {
		show_as_tooltip = {
			add_piety = major_piety_value
			if = {
				limit = {
					any_vassal = {
						faith = {
							has_doctrine_parameter = sky_burials_active
						}
					}
				}
				every_vassal = {
					limit = {
						faith = {
							has_doctrine_parameter = sky_burials_active
						}
					}
					custom = give_sky_burial_vassals
					add_opinion = {
						modifier = pleased_opinion
						target = root
						opinion = 20
					}
				}
			}
		}
		trigger_event = religious_decision.0302
	}

	ai_check_interval = 36
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

raise_runestone_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = raise_runestone_decision_desc
	selection_tooltip = raise_runestone_decision_tooltip

	is_shown = {
		faith = faith:norse_pagan
		has_variable = ancestor_to_bury
		var:ancestor_to_bury = { dynasty = root.dynasty }
	}

	is_valid = {
	}

	is_valid_showing_failures_only = {

	}

	effect = {
		#The modifier will only be active if a character of your dynasty holds it
		capital_province = {
			county = {
				set_variable = {
					name = ancestor_to_bury
					value = root.var:ancestor_to_bury
				}
				add_county_modifier = {
					modifier = county_raised_runestone_modifier
				}
			}
		}
		remove_variable = ancestor_to_bury
		add_piety = medium_piety_value
		every_vassal = {
			limit = {
				faith = faith:norse_pagan
			}
			custom = raise_runestone_vassals
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 10
			}
		}
	}

	ai_check_interval = 36
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

divine_the_stars_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = divine_the_stars_decision_desc
	selection_tooltip = divine_the_stars_decision_tooltip

	is_shown = {
		faith = {
			has_doctrine_parameter = divine_the_stars_active
		}
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = divine_the_stars_trigger
			NOT = { has_character_flag = divining_the_stars }
		}
		NOR = {
			has_character_modifier = astrology_great_battle
			has_character_modifier = astrology_new_friends
			has_character_modifier = astrology_hard_work
			has_character_modifier = astrology_betrayal
			has_character_modifier = astrology_new_beginnings
		}
	}

	effect = {
		add_character_flag = divining_the_stars
		trigger_event = {
			id = religious_decision.0401
			days = { 14 28 }
		}
		custom_tooltip = divine_the_starts_effect
	}

	ai_check_interval = 60
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

revoke_false_conversion_decision = {	#Reveal yourself as a crypto-religionist.
	ai_check_interval = 60
	picture = "gfx/interface/illustrations/decisions/decision_major_religion.dds"

	desc = revoke_false_conversion_decision.desc
	selection_tooltip = revoke_false_conversion_decision.tt

	is_shown = {
		has_variable = false_convert
		NOR = {
			this = faith.religious_head
			var:false_convert = faith
		}
	}

	is_valid = {
		is_adult = yes
		NOT = { has_trait = zealous }
		piety >= major_piety_value
	}

	is_valid_showing_failures_only = {
		custom_description = {
			text = cannot_be_atoned_krstjani_leader_flag
			NOT = { has_character_flag = atoned_krstjani_leader_flag }
		}
	}

	cooldown = { years = 20 }

	effect = {
		trigger_event = false_conversion.0020
		custom_tooltip = revoke_false_conversion_decision.desc.tt
		custom_tooltip = revoke_false_conversion_decision.desc.tt_own_faith_counties
	}

	ai_potential = {
		has_variable = false_convert
		save_temporary_scope_as = current_character
		liege.faith = {
			faith_hostility_level_comparison = { scope:current_character.var:false_convert <= root.faith }
		}
	}

	ai_will_do = {
		base = 25

		modifier = {	#Having a tolerant liege helps.
			add = 25
			liege.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {	#If no one is fussed, and your old faith waxes while your current one wanes, then that seems like a good reason to jump ship.
			add = 35
			NOT = {
				liege.faith = { has_doctrine = doctrine_pluralism_fundamentalist }
			}
			var:false_convert = {
				fervor >= medium_fervor_value
			}
			faith = {
				fervor <= medium_fervor_value
			}
		}
	}
}

encourage_confession_of_false_conversions_decision = {	#Ask that crypto-religionists in your realm start practicing in the open.
	ai_check_interval = 120
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = encourage_confession_of_false_conversions_decision.desc
	selection_tooltip = encourage_confession_of_false_conversions_decision.tt

	cooldown = { days = 3650 }

	is_shown = {
		OR = {
			AND = {	#Pluralists will encourage anyone to convert.
				OR = {
					any_vassal = {	#... Be they person...
						has_variable = false_convert
						save_temporary_scope_as = current_character
						root.faith = {
							faith_hostility_level_comparison = {
								scope:current_character.var:false_convert <= scope:current_character.faith
							}
						}
					}
					any_sub_realm_county = {	#... Or county.
						has_variable = false_convert
						save_temporary_scope_as = current_county
						root.faith = {
							faith_hostility_level_comparison = {
								scope:current_county.var:false_convert <= scope:current_county.faith
							}
						}
					}
				}
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
			any_vassal = {	#Otherwise, you can have a vassal who practices your faith in secret.
				has_variable = false_convert
				var:false_convert = root.faith
			}
			any_sub_realm_county = {	#... Or a county!
				has_variable = false_convert
				var:false_convert = root.faith
			}
		}
	}

	is_valid = {
		is_adult = yes
		NOR = {
			has_trait = zealous
			dread >= low_dread
			tyranny >= 1
		}
		piety >= major_piety_value
	}

	effect = {
		trigger_event = false_conversion.0030
		if = {
			limit = {
				faith = { has_doctrine = doctrine_pluralism_pluralistic }
			}
			custom_tooltip = encourage_confession_of_false_conversions_decision.desc.tt_pluralist
			custom_tooltip = encourage_confession_of_false_conversions_decision.desc.tt_paranoia
			custom_tooltip = encourage_confession_of_false_conversions_decision.desc.tt_pluralist_counties
		}
		else = {
			custom_tooltip = encourage_confession_of_false_conversions_decision.desc.tt_coreligionist
			custom_tooltip = revoke_false_conversion_decision.desc.tt_own_faith_counties
		}
	}

	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 25

		modifier = {	#A tolerant liege, including yourself, makes this more likely.
			add = 5
			liege.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {	#A tolerant top-lliege, including yourself, *also* makes this more likely.
			add = 5
			top_liege.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {	#Planning for the future helps too.
			add = 5
			primary_heir.faith = { has_doctrine = doctrine_pluralism_pluralistic }
		}
		modifier = {	#If the faith isn't feeling militant, why should you?
			add = 10
			faith = { fervor <= medium_fervor_value }
		}
		modifier = {
			add = 10
			OR = {
				has_trait = compassionate
				has_trait = forgiving
				has_trait = honest
			}
		}
	}
}

go_on_pilgrimage_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"
	ai_check_interval = 60

	desc = go_on_pilgrimage_decision_desc
	selection_tooltip = go_on_pilgrimage_decision_tooltip

	cooldown = { years = pilgrimage_cooldown_year_amount }

	is_shown = {
		is_landed = yes
		NOR = {
			# These Faiths historically shunned going on pilgrimages, saying they were a waste of time & money.
			faith = faith:waldensian
			faith = faith:paulician
			faith = faith:lollard
		}

		# Also we must have an actual holy site we can visit.
		faith = {	
			any_holy_site = {
				exists = this
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war = no
	}

	effect = {
		custom_tooltip = pilgrimage_effect_1
		custom_tooltip = pilgrimage_effect_2
		custom_tooltip = pilgrimage_effect_3
		if = {
			limit = { has_trait = ill }
			custom_tooltip = line_break
			custom_tooltip = pilgrimage_illness_warning
		}
		if = {
			limit = { is_ai = yes }
			trigger_event = pilgrimage.0999
		}
		else = {
			trigger_event = pilgrimage.0001
		}
	}

	ai_potential = {
		is_landed = yes
	}

	ai_will_do = {
		base = 20
		modifier = {
			add = -100
			NOT = { short_term_gold >= pilgrimage_medium_extra_cost }
		}
		modifier = {
			add = 30
			short_term_gold >= pilgrimage_long_extra_cost
		}
		modifier = {
			add = 20
			piety_level <= 2
		}
		modifier = {
			add = 20
			has_trait = zealous
		}
		modifier = {
			add = 20
			has_trait = zealous
			NOT = { has_trait = pilgrim }
		}
		modifier = {
			add = -30
			has_trait = cynical
		}
		modifier = {
			add = -30
			has_trait = pilgrim
		}
	}
}

go_on_hajj_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	ai_check_interval = 36

	desc = go_on_pilgrimage_decision_desc
	selection_tooltip = go_on_pilgrimage_decision_tooltip

	cooldown = { years = pilgrimage_cooldown_year_amount }

	is_shown = {
		NOT = { has_trait = pilgrim }
		is_landed = yes
		faith.religion = religion:islam_religion
		NOR = {
			faith = faith:druze
			faith = faith:alevi
		}
	}

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_at_war = no
	}

	effect = {
		if = {
			limit = {
				hajj_actual_cost = {
					value >= pilgrimage_very_long_extra_cost
				}
			}
			custom_tooltip = hajj_exceptionally_long_tt
			custom_description_no_bullet = {
				text = hajj_distance_info_text
			}
			custom_tooltip = line_break
			show_as_tooltip = {
				add_trait = pilgrim
				very_long_pilgrimage_reward_effect = yes
			}
		}
		else_if = {
			limit = {
				hajj_actual_cost = {
					value >= pilgrimage_long_extra_cost
				}
			}
			custom_tooltip = hajj_very_long_tt
			custom_description_no_bullet = {
				text = hajj_distance_info_text
			}
			custom_tooltip = line_break
			show_as_tooltip = {
				add_trait = pilgrim
				long_pilgrimage_reward_effect = yes
			}
		}
		else_if = {
			limit = {
				hajj_actual_cost = {
					value >= pilgrimage_medium_extra_cost
				}
			}
			custom_tooltip = hajj_long_tt
			custom_description_no_bullet = {
				text = hajj_distance_info_text
			}
			custom_tooltip = line_break
			show_as_tooltip = {
				add_trait = pilgrim
				medium_pilgrimage_reward_effect = yes
			}
		}
		else = {
			custom_tooltip = hajj_short_tt
			custom_description_no_bullet = {
				text = hajj_distance_info_text
			}
			custom_tooltip = line_break
			show_as_tooltip = {
				add_trait = pilgrim
				short_pilgrimage_reward_effect = yes
			}
		}

		if = {
			limit = { has_trait = ill }
			custom_tooltip = line_break
			custom_tooltip = pilgrimage_illness_warning
		}
		trigger_event = hajj.0001
	}

	cost = {
		gold = hajj_actual_cost
	}

	ai_potential = {
		is_landed = yes
	}

	ai_will_do = {
		base = 5
		compare_modifier = {
			value = age
			trigger = {
				NOT = {
					has_trait = cynical
				}
			}
			max = 70
		}
	}
}

return_rome_decision = {
	picture = "gfx/interface/illustrations/decisions/decision_personal_religious.dds"

	desc = return_rome_decision_desc
	selection_tooltip = return_rome_decision_tooltip

	is_shown = {
		is_independent_ruler = yes
		faith = faith:catholic
		exists = faith.religious_head
		faith.religious_head = {
			OR = {
				is_independent_ruler = yes
				NOT = {
					any_liege_or_above = {
						this = root
					}
				}
			}
		}
		any_sub_realm_county = {
			this = title:c_roma
		}
		NAND = {
			is_ai = no
			NOT = {
				any_sub_realm_county = {
					NOT = {
						this = title:c_roma
					}
				}
			}
		}
		#Don't show to a player pope
		NOT = { faith.religious_head = root }
	}

	effect = {
		create_title_and_vassal_change = change
		scope:change = { set_title_and_vassal_change_type = returned }
		title:c_roma = {
			change_title_holder = {
				holder = faith.religious_head
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		
		add_piety = major_piety_value
		
		faith.religious_head = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}

		stress_impact = {
			cynical = medium_stress_impact_gain
			ambitious = minor_stress_impact_gain
		}
	}
	
	ai_check_interval = 12

	ai_potential = {
		is_at_war = no
		title:c_roma = {
			holder = {
				is_ai = yes
			}
		}
	}

	ai_will_do = {
		base = 100

		modifier = { # If you fought the pope to get rome, don't immediately hand it back
			factor = 0
			faith.religious_head = {
				has_opinion_modifier = {
					target = root
					modifier = declared_war
				}
			}
		}

		modifier = {
			factor = 0
			ai_zeal <= very_high_negative_ai_value
		}
	}
}
