﻿
###TRIGGER LIST

# has_strong_religious_conviction_trigger
# is_christian_trigger AGOT DISABLED
# is_fots_trigger

###DOCTRINE BASED###
# is_weak_claimant_due_to_gender_trigger
# can_be_combatant_based_on_gender_trigger
# can_be_clergy_due_to_gender_trigger
# faith_is_aniconic_trigger
# relation_with_character_is_incestuous_in_faith_trigger 	- Relation would be shunned in faith
# relation_with_character_is_incestuous_in_my_faith_trigger 			- Relation would be shunned in the faith of character you use trigger in
# relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger - Relation would be shunned in the faith of the character you use trigger in or their liege's faith
# faith_allows_marriage_consanguinity_trigger
# relation_with_character_is_sodomy_in_faith_trigger
# relation_with_character_is_sodomy_trigger
# relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger
# trait_is_shunned_in_faith_trigger
# trait_is_criminal_in_faith_trigger
# trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger
# has_negative_attitude_towards_trait_trigger
# secret_is_shunned_in_faith_trigger
# secret_is_criminal_in_faith_trigger
# secret_is_shunned_or_criminal_in_my_or_lieges_faith_trigger
# religion_has_angels_trigger
# highgod_is_passive_trigger
# highgod_is_active_trigger
# is_reincarnation_trigger
# holy_order_1000_request_target_trigger 		- Is this ruler a valid target for a holy order to request land from?

###HERESY TRIGGERS###
# is_valid_heresiarch

###RELIGIOUS INTERACTIONS###
# can_take_religious_vows_trigger


# CHECK A NUMBER OF RELIGION-RELATED CONDITIONS TO DETERMINE HOW STRONG OF A BELIEVER THEY SEEM TO BE
has_strong_religious_conviction_trigger = {
	NOR = {
		has_trait = cynical
		# has_trait = excommunicated # AGOT Disabled
	}
	OR = {
		has_trait = zealous
		#has_trait = pilgrim # AGOT Disabled - pilgrim removed from game.
		has_trait = devoted
		# has_trait = sayyid # AGOT Disabled - Sayyid removed from game.
		# has_trait = saoshyant # AGOT Disabled - Saoshyant removed from game.
		has_trait = savior
		has_trait = divine_blood
		has_trait = blood_of_prophet
		has_trait = faith_warrior
		has_trait = saint
	}
}

is_christian_trigger = {
	OR = {
		#faith = { religion_tag = christianity_religion }
	}
}

is_fots_trigger = { #AGOT ADDED
	OR = {
		faith = { religion_tag = faith_of_the_seven_religion }
	}
}

# Not-non-XYZ triggers allow us to check for specific historical faiths whilst still defaulting to something positive for variant faiths.
## E.g., looking to see if something would only be of interest to Catholics, but if we're dealing with a player-made heresy, still return true. This way mechanics will default to on rather than off (still likely to result in weird GHWs, but at least less random ones).
#not_non_catholic_standard_christian_faith_trigger = { # AGOT TODO Fix Code Block
#	NOR = {
#		this = faith:orthodox
#		this = faith:iconoclast
#		this = faith:coptic
#		this = faith:armenian_apostolic
#	}
#}

#not_non_orthodox_standard_christian_faith_trigger = { # AGOT TODO Fix Code Block
#	NOR = {
#		this = faith:catholic
#		this = faith:coptic
#		this = faith:armenian_apostolic
#	}
#}

#not_non_coptic_standard_christian_faith_trigger = { # AGOT TODO Fix Code Block
#	NOR = {
#		this = faith:catholic
#		this = faith:orthodox
#		this = faith:iconoclast
#		this = faith:armenian_apostolic
#	}
#}

#not_non_armenian_standard_christian_faith_trigger = { # AGOT TODO Fix Code Block
#	NOR = {
#		this = faith:catholic
#		this = faith:orthodox
#		this = faith:iconoclast
#		this = faith:coptic
#	}
#}

is_weak_claimant_due_to_gender_trigger = {
	OR = {
		AND = {
			$FAITH$ = { has_doctrine_parameter = female_claims_are_weak }
			$CHARACTER$ = { is_female = yes }
		}
		AND = {
			$FAITH$ = { has_doctrine_parameter = male_claims_are_weak }
			$CHARACTER$ = { is_male = yes }
		}
	}
}

can_be_combatant_based_on_gender_trigger = {
	custom_description = {
		text = "can_be_combatant_based_on_gender"
		object = this
		subject = $ARMY_OWNER$
		OR = {
			trigger_if = { # Has the Royal Court and thus can modify pillars
				limit = {
					has_dlc_feature = diverge_culture # Can modify pillars
				}
				OR = {
					$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_equal_combatant } }
					AND = {
						$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_male_only_combatant } }
						is_male = yes
					}
					AND = {
						$ARMY_OWNER$ = { culture = { has_cultural_parameter = martial_custom_female_only_combatant } }
						is_female = yes
					}
				}
				
			}
			trigger_else = { # Does not have the Royal Court and thus combatant is governed by faith
				OR = {
					$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_can_be_either_gender_if_no_roco } }
					AND = {
						$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_must_be_male_if_no_roco } }
						is_male = yes
					}
					AND = {
						$ARMY_OWNER$ = { faith = { has_doctrine_parameter = combatant_must_be_female_if_no_roco } }
						is_female = yes
					}
				}
			}
			 AND = {
			 	$ARMY_OWNER$ = {
			 		culture = { has_cultural_parameter = has_access_to_shieldmaidens }
			 	}
			 	# No need to gender diversify this: if they're a right-gender shieldperson of the culture, then they've already got permission to fight from the previous AND conditions.
			 	has_trait = shieldmaiden
			 }
		}
	}
}

can_be_clergy_due_to_gender_trigger = {
	OR = {
		AND = {
			faith = { has_doctrine_parameter = clergy_must_be_female }
			is_female = yes
		}
		AND = {
			faith = { has_doctrine_parameter = clergy_must_be_male }
			is_male = yes
		}
		faith = { has_doctrine_parameter = clergy_can_be_either_gender }
	}
}

is_wrong_gender_in_faith_trigger = {
	OR = {
		AND = {
			is_female = yes
			$FAITH$ = { has_doctrine_parameter = male_dominated_law }
		}
		AND = {
			is_male = yes
			$FAITH$ = { has_doctrine_parameter = female_dominated_law }
		}
	}
}

faith_is_aniconic_trigger = {
	faith = {
		OR = {	
			#religion = religion:islam_religion # AGOT TODO Fix Code Block
			has_doctrine = tenet_aniconism
		}
	}
}

#Needs CHARACTER and FAITH
relation_with_character_is_incestuous_in_faith_trigger = {
	OR = {
		#doctrine_consanguinity_restricted; absolutely no family business 
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_restricted }
			is_close_or_extended_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren, cousins, uncles, aunts, nephews, nieces]
		}
		#doctrine_consanguinity_cousins; the only acceptable incest is with your cousin
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_cousins }
			OR = {
	            is_close_family_of = $CHARACTER$ #[parents, children, siblings, grandparents, grandchildren]
	            is_uncle_or_aunt_of = $CHARACTER$
	            is_nibling_of = $CHARACTER$
	        }
		}
		#doctrine_consanguinity_aunt_nephew_and_uncle_niece; extended family is ok
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_aunt_nephew_and_uncle_niece }	
			is_close_family_of = $CHARACTER$
		}
		#doctrine_consanguinity_siblings; siblings are ok
		AND = {
			$FAITH$ = { has_doctrine = doctrine_consanguinity_siblings }	
			OR = {
				is_parent_of = $CHARACTER$
				is_child_of = $CHARACTER$
				is_grandchild_of = $CHARACTER$
				is_grandparent_of = $CHARACTER$
				is_great_grandchild_of = $CHARACTER$
				is_great_grandparent_of = $CHARACTER$
	        }	
		}
		#doctrine_consanguinity_unrestricted; all forms of incest is acceptable
	}	
	NAND = { # AGOT Added
		$CHARACTER$ = {
			agot_adelphogamous_incest_allowed = yes
		}
		NOR = {
            is_parent_of = $CHARACTER$
            is_child_of = $CHARACTER$
            is_grandchild_of = $CHARACTER$
            is_grandparent_of = $CHARACTER$
            is_great_grandchild_of = $CHARACTER$
            is_great_grandparent_of = $CHARACTER$
        }
	}
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_incestuous_in_my_faith_trigger = {
	faith = { save_temporary_scope_as = my_faith }
	relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:my_faith }
}

relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			relation_with_character_is_incestuous_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
	}
}

#Needs CHARACTER_1 and CHARACTER_2
faith_allows_marriage_consanguinity_trigger = {
	save_temporary_scope_as = consanguinity_faith

	NOT = {
		$CHARACTER_1$ = {
			relation_with_character_is_incestuous_in_faith_trigger = {
				CHARACTER = $CHARACTER_2$
				FAITH = scope:consanguinity_faith
			}
		}
	}
}
relation_between_characters_is_sodomy_in_my_faith_trigger = {
	$CHARACTER_1$ = { is_male = yes }
	$CHARACTER_2$ = { is_male = yes }
	faith = { 
		OR = {
			has_doctrine_parameter = homosexuality_shunned 
			has_doctrine_parameter = homosexuality_illegal
		}
	}
}

relation_with_character_is_sodomy_in_faith_trigger = {
	is_male = yes
	$CHARACTER$ = { is_male = yes }
	$FAITH$ = {
		OR = {
			has_doctrine_parameter = homosexuality_shunned
			has_doctrine_parameter = homosexuality_illegal
		}
	}
}

#Note: only checks from the viewpoint of current scope. Needs CHARACTER
relation_with_character_is_sodomy_trigger = {
	faith = { save_temporary_scope_as = my_faith }
	relation_with_character_is_sodomy_in_faith_trigger = {
		CHARACTER = $CHARACTER$
		FAITH = scope:my_faith
	}
}

relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			relation_with_character_is_sodomy_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			relation_with_character_is_sodomy_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith }
		}
	}
}

murdering_character_is_kinslaying_in_faith_trigger = {
	OR = {
		is_close_or_extended_family_of = $CHARACTER$
		dynasty = $CHARACTER$.dynasty
	}
	$FAITH$ = { NOT = { has_doctrine = doctrine_kinslaying_accepted } }
}

murdering_character_is_kinslaying_in_my_or_same_dynasty_lieges_faith_trigger = {
	save_temporary_scope_as = kinslayer_me
	faith = {
		save_temporary_scope_as = check_faith
	}
	trigger_if = {
		limit = {
			exists = liege
			liege = { dynasty = scope:kinslayer_me.dynasty }
		}
		liege = {
			faith = {
				save_temporary_scope_as = check_faith_liege
			}
		}
	}
	OR = {
		murdering_character_is_kinslaying_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith } #My faith doesn't approve
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = { dynasty = scope:kinslayer_me.dynasty }
			murdering_character_is_kinslaying_in_faith_trigger = { CHARACTER = $CHARACTER$ FAITH = scope:check_faith_liege }
		}
	}
}



trait_is_shunned_in_faith_trigger = {
	save_temporary_scope_value_as = {
		name = shunned_trait_check
		value = flag:$TRAIT$
	}
	OR = {
		#INCEST
		AND = {
			scope:shunned_trait_check = flag:incestuous
			$FAITH$ = { NOT = { has_doctrine_parameter = allows_unrestricted_marriage } }
		}
		#WITCH
		AND = {
			scope:shunned_trait_check = flag:witch	
			$FAITH$ = { has_doctrine_parameter = witchcraft_shunned }
		}
		#SODOMITE
		AND = {
			scope:shunned_trait_check = flag:sodomite
			$FAITH$ = { has_doctrine_parameter = homosexuality_shunned }
		}
		#DEVIANT
		AND = {
			scope:shunned_trait_check = flag:deviant
			$FAITH$ = { has_doctrine_parameter = deviancy_shunned }
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				scope:shunned_trait_check = flag:adulterer
				scope:shunned_trait_check = flag:fornicator
			}
			OR = {
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_female_shunned }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_male_shunned }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
		#KINSLAYER
		AND = {
			OR = {
				scope:shunned_trait_check = flag:kinslayer_1
				scope:shunned_trait_check = flag:kinslayer_2
				scope:shunned_trait_check = flag:kinslayer_3
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_shunned }
		}
	}
}

trait_is_criminal_in_faith_trigger = {
	save_temporary_scope_value_as = {
		name = criminal_trait_check
		value = flag:$TRAIT$
	}
	OR = {
		#KINSLAYER
		AND = {
			OR = {
				scope:criminal_trait_check = flag:kinslayer_3
				scope:criminal_trait_check = flag:kinslayer_2
				scope:criminal_trait_check = flag:kinslayer_1
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_any_dynasty_member_crime }
		}
		AND = {
			OR = {
				scope:criminal_trait_check = flag:kinslayer_3
				scope:criminal_trait_check = flag:kinslayer_2
			}
			$FAITH$ = { has_doctrine_parameter = kinslaying_extended_family_crime }
		}
		AND = {
			scope:criminal_trait_check = flag:kinslayer_3
			$FAITH$ = { has_doctrine_parameter = kinslaying_close_kin_crime }
		}
		#WITCH
		AND = {
			scope:criminal_trait_check = flag:witch
			$FAITH$ = { has_doctrine_parameter = witchcraft_illegal }
		}
		#CANNIBAL
		AND = {
			scope:criminal_trait_check = flag:cannibal
			NOT = {
				$FAITH$ = { has_doctrine_parameter = cannibalism_legal }
			}
		}
		#SODOMITE
		AND = {
			scope:criminal_trait_check = flag:sodomite
			$FAITH$ = { has_doctrine_parameter = homosexuality_illegal }
		}
		#DEVIANT
		AND = {
			scope:criminal_trait_check = flag:deviant
			$FAITH$ = { has_doctrine_parameter = deviancy_illegal }
		}
		#INCEST
		AND = {
			scope:criminal_trait_check = flag:incestuous
			$FAITH$ = { NOT = { has_doctrine_parameter = consanguinity_unrestricted_incest } }
		}
		#ADULTERER/FORNICATOR
		AND = {
			OR = {
				scope:criminal_trait_check = flag:adulterer
				scope:criminal_trait_check = flag:fornicator
			}
			OR = {
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_female_crime }
					$GENDER_CHARACTER$ = { is_female = yes }
				}
				AND = {
					$FAITH$ = { has_doctrine_parameter = adultery_male_crime }
					$GENDER_CHARACTER$ = { is_male = yes }
				}
			}
		}
	}	
}

trait_is_shunned_or_criminal_in_faith_trigger = {
	OR = {
		trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = $FAITH$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = $FAITH$ GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

trait_is_shunned_or_criminal_in_my_or_lieges_faith_trigger = {
	OR = {
		AND = {
			faith = { #My faith doesn't approve
				save_temporary_scope_as = check_faith
			}
			trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:check_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
		AND = { #Liege's faith doesn't approve
			exists = liege
			liege = {
				faith = {
					save_temporary_scope_as = check_faith
				}
			}
			trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:check_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		}
	}
}

has_any_shunned_or_criminal_trait_in_faith_trigger = {
	$CHARACTER$ = {
		OR = {
			#KINSLAYER
			AND = {
				has_trait = kinslayer_3
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_2
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = kinslayer_1
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#WITCH
			AND = {
				has_trait = witch
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = witch FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#CANNIBAL
			AND = {
				has_trait = cannibal
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#SODOMITE
			AND = {
				has_trait = sodomite
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#DEVIANT
			AND = {
				has_trait = deviant
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = deviant FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = incestuous
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			#ADULTERER/FORNICATOR
			AND = {
				has_trait = adulterer
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
			AND = {
				has_trait = fornicator
				trait_is_shunned_or_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = $FAITH$ GENDER_CHARACTER = $CHARACTER$ }
			}
		}
	}
}


has_negative_attitude_towards_trait_trigger = {
	save_temporary_scope_value_as = {
		name = negative_status_check
		value = flag:$TRAIT$
	}

	NOR = {
		has_trait = $TRAIT$
		#INCESTUOUS
		AND = {
			scope:negative_status_check = flag:incestuous
			any_secret = { secret_type = secret_incest }
		}
		#WITCH
		AND = {
			scope:negative_status_check = flag:witch
			any_secret = { secret_type = secret_witch }
		}
		#CANNIBAL
		AND = {
			scope:negative_status_check = flag:cannibal
			any_secret = { secret_type = secret_cannibal }
		}
		#SODOMITE
		AND = {
			scope:negative_status_check = flag:sodomite
			OR = {
				has_sexuality = homosexual
				has_sexuality = bisexual
			}
			any_secret = {
				secret_type = secret_homosexual
			}
		}
		#ADULTERER
		AND = {
			scope:negative_status_check = flag:adulterer
			OR = {
				has_trait = lustful
				AND = {
					is_married = yes
					any_relation = { type = lover NOT = { is_spouse_of = prev } }
				}
				any_relation = {
					type = lover
					is_married = yes
					NOT = { is_spouse_of = prev }
				}
			}
		}
		#FORNICATOR
		AND = {
			scope:negative_status_check = flag:fornicator
			OR = {
				has_trait = lustful
				any_relation = { type = lover always = yes }
			}
		}
	}

	faith = { save_temporary_scope_as = my_faith }
	OR = {
		trait_is_shunned_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:my_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
		trait_is_criminal_in_faith_trigger = { TRAIT = $TRAIT$ FAITH = scope:my_faith GENDER_CHARACTER = $GENDER_CHARACTER$ }
	}
}

has_followers_trigger = {
	OR = {
		num_character_followers >= 1
		num_county_followers >= 1
	}
}

secret_is_blackmailable_trigger = {
	OR = {
		secret_is_blackmailable_strong_hook_trigger = { TARGET = $TARGET$ }
		secret_is_blackmailable_weak_hook_trigger = { TARGET = $TARGET$ }
	}
}


###################
# Heresy Triggers #
###################

is_preferred_heresy = {
	is_valid_heresy = {
		ORIGIN_FAITH = $ORIGIN_FAITH$
		HERETICAL_FAITH = $HERETICAL_FAITH$
	}

	OR = {
		#If we're Chistian, pick a heretical faiths which is in the same regional group as our origin faith (i.e., Lollards for Catholics, Iconoclasts for Orthodox, etc.)
		AND = {
			#religion_tag = christianity_religion # AGOT TODO Fix Code Block
			OR = {
				faiths_are_in_western_christianity_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
				faiths_are_in_orthodox_christianity_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
				faiths_are_in_eastern_christianity_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$ }
			}
		}

		#If we're Muslim, we want to stay within our 'branch' of Islam:
		AND = {
			#religion_tag = islam_religion # AGOT TODO Fix Code Block
			OR = {
				faiths_are_in_sunni_islam_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
				faiths_are_in_shia_islam_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
				faiths_are_in_muhakkima_islam_group = {FAITH_1 = $ORIGIN_FAITH$ FAITH_2 = $HERETICAL_FAITH$}
			}
		}

		#Otherwise, we don't have any special preferences.
		#AND = { # AGOT TODO Fix Code Block
		#	NOT = {
		#		religion_tag = islam_religion
		#		religion_tag = christianity_religion
		#	}
		#}
	}
}

is_valid_heresy = {
	#The origin faith can never be its own heresy.
	NOT = { $ORIGIN_FAITH$ = $HERETICAL_FAITH$ }
	# A heretical faith can't be currently locked off via variable.
	$HERETICAL_FAITH$ = {
		NOR = {
			has_variable = block_conversion_till_decision_taken
			has_variable = block_conversion_till_nebulous_circumstances
		}
	}
	#Depending on the origin faith's religion/religion group, there may have additional requirements for a heresy to be considered valid.
	OR = { # AGOT TODO Fix Code Block
		#For Christian Faiths, the origin and heretical faiths must not both be Ecumenical (excepting the faiths which aren't technically ecumenical).
		#AND = {
		#	religion_tag = christianity_religion
		#	NAND = {
		#		$ORIGIN_FAITH$ = {
		#			has_doctrine = special_doctrine_ecumenical_christian
		#			OR = {
		#				this = faith:insular_celtic
		#				this = faith:bosnian_church
		#				this = faith:mozarabic_church
		#			}
		#		}
		#		$HERETICAL_FAITH$ = {
		#			has_doctrine = special_doctrine_ecumenical_christian
		#			OR = {
		#				this = faith:insular_celtic
		#				this = faith:bosnian_church
		#				this = faith:mozarabic_church
		#			}
		#		}
		#	}
		#}
		#No special requirements for Muslims, Jews, Yazidis, or Zoroastrians.
		#religion_tag = islam_religion
		#religion_tag = judaism_religion
		#religion_tag = zoroastrianism_religion
		#Eastern Faiths can shift and spread amongst each other.
		#AND = {
		#	OR = {
		#		religion_tag = buddhism_religion
		#		religion_tag = hinduism_religion
		#		religion_tag = jainism_religion
		#		religion_tag = dualism_religion
		#	}
		#}
		#No special requirements for Pagan religions.
		# has_doctrine = pagan_hostility_doctrine # AGOT Disabled
	}
}

is_valid_heresiarch = {
	is_adult = yes
	is_imprisoned = no
	is_incapable = no
	is_landed = yes
	exists = capital_county
	NOT = { has_trait = heresiarch }
	no_heretical_hof_faith_trigger = yes
	recently_converted_faith_trigger = no
	OR = { 
		AND = {
			faith = root
			OR = {
				highest_held_title_tier = tier_duchy
				highest_held_title_tier = tier_county
			}
		}
		is_ai = no
	}
}

no_heretical_hof_faith_trigger = { #Head of Faith shouldn't convert.
	OR = {
		NOT = { exists = root.religious_head }
		AND = {
			exists = root.religious_head
			NOT = { this = root.religious_head }
		}
	}
}

#Christian Heresy Groups
faiths_are_in_western_christianity_group = { # AGOT TODO Fix Code Block
	#OR = {
	#	$FAITH_1$ = faith:catholic
	#	$FAITH_1$ = faith:cathar
	#	$FAITH_1$ = faith:waldensian
	#	$FAITH_1$ = faith:lollard
	#	$FAITH_1$ = faith:insular_celtic
	#	$FAITH_1$ = faith:mozarabic_church
	#}
	#OR = {
	#	$FAITH_2$ = faith:catholic
	#	$FAITH_2$ = faith:cathar
	#	$FAITH_2$ = faith:waldensian
	#	$FAITH_2$ = faith:lollard
	#	$FAITH_2$ = faith:priscillianism
	#	$FAITH_2$ = faith:insular_celtic
	#	$FAITH_2$ = faith:mozarabic_church
	#}
}

faiths_are_in_orthodox_christianity_group = { # AGOT TODO Fix Code Block
	#OR = {
	#	$FAITH_1$ = faith:orthodox
	#	$FAITH_1$ = faith:iconoclast
	#	$FAITH_1$ = faith:bogomilist
	#	$FAITH_1$ = faith:paulician
	#	$FAITH_1$ = faith:bosnian_church
	#}
	#OR = {
	#	$FAITH_2$ = faith:orthodox
	#	$FAITH_2$ = faith:iconoclast
	#	$FAITH_2$ = faith:bogomilist
	#	$FAITH_2$ = faith:paulician
	#	$FAITH_2$ = faith:bosnian_church
	#	$FAITH_2$ = faith:cainitism
	#}
}

faiths_are_in_eastern_christianity_group = { # AGOT TODO Fix Code Block
	#OR = {
	#	$FAITH_1$ = faith:coptic
	#	$FAITH_1$ = faith:armenian_apostolic
	#	$FAITH_1$ = faith:nestorian
	#	$FAITH_1$ = faith:messalian
	#	$FAITH_1$ = faith:paulician
	#}
	#OR = {
	#	$FAITH_2$ = faith:coptic
	#	$FAITH_2$ = faith:armenian_apostolic
	#	$FAITH_2$ = faith:nestorian
	#	$FAITH_2$ = faith:messalian
	#	$FAITH_2$ = faith:paulician
	#	$FAITH_2$ = faith:mandeaism
	#}
}

faiths_are_shia_zandaqa_sub_group = { # AGOT TODO Fix Code Block
	#OR = {
	#	this = faith:quranist
	#	this = faith:qarmatian
	#	this = faith:ghulat
	#	this = faith:alawite
	#	this = faith:alevi
	#	this = faith:druze
	#}
}

faiths_are_in_sunni_islam_group = { # AGOT TODO Fix Code Block
	$FAITH_1$ = {
		has_doctrine = muhammad_succession_sunni_doctrine
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_sunni_doctrine
			has_doctrine = muhammad_succession_muhakkima_doctrine
		#	this = faith:sabianism # AGOT Disabled
		#	this = faith:manichean # AGOT Disabled
		#	this = faith:quranist # AGOT Disabled
		}
	}
}

faiths_are_in_shia_islam_group = { # AGOT TODO Fix Code Block
	$FAITH_1$ = {
		OR = {
			has_doctrine = muhammad_succession_shia_doctrine
			faiths_are_shia_zandaqa_sub_group = yes
		}
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_shia_doctrine
			has_doctrine = muhammad_succession_muhakkima_doctrine
			faiths_are_shia_zandaqa_sub_group = yes
		#	this = faith:valentinianism # AGOT Disabled
		#	this = faith:sabianism # AGOT Disabled
		}
	}
}

faiths_are_in_muhakkima_islam_group = { # AGOT TODO Fix Code Block
	$FAITH_1$ = {
		has_doctrine = muhammad_succession_muhakkima_doctrine
	}
	$FAITH_2$ = {
		OR = {
			has_doctrine = muhammad_succession_muhakkima_doctrine
		#	this = faith:manichean
		#	this = faith:valentinianism
		}
	}
}

refusing_conversion_is_crime_trigger = { # AGOT TODO Fix Code Block
	faith = {
		#OR = {
		#	religion_tag = christianity_religion
		#	religion_tag = islam_religion
		#	religion_tag = judaism_religion
		#	religion_tag = zoroastrianism_religion
		#}
		NOT = {
			faith_hostility_level = {
				target = $CHARACTER$.faith
				value <= faith_astray_level
			}
		}
	}
}

is_hostile_enough_for_holy_war_trigger = {
	faith_hostility_level = {
		target = $FAITH$
		value >= religious_cb_enabled_hostility_level
	}
}

barony_is_valid_for_holy_order_lease_trigger = {
	title_province = {
		OR = {
			has_holding_type = castle_holding
			has_holding_type = city_holding
		}
	}
	trigger_if = {
		limit = {
			holder.primary_title.tier != tier_barony
		}
		can_be_leased_out = yes
	}
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder.primary_title.tier = tier_barony	
	}
	NOT = {
		is_leased_out = yes
		this = title:b_goldguard_heights
	}
}

barony_is_valid_for_holy_order_lease_cancellation_trigger = {
	is_under_holy_order_lease = yes
	has_revokable_lease = yes
	title_province = { save_temporary_scope_as = location }
	exists = lessee_title.holder
	lessee_title.holder = {
		save_temporary_scope_as = title_holder
		any_religion_global = {
			any_faith = {
				any_faith_holy_order = {
					exists = leader
					leader = {
						this = scope:title_holder
						location = scope:location
						save_temporary_scope_as = holy_order_grand_master
					}
				}
			}
		}
	}
}

religion_has_angels_trigger = {
	#OR = { # AGOT TODO Fix Code Block
	#	religion = religion:christianity_religion
	#	religion = religion:islam_religion
	#	religion = religion:zoroastrianism_religion
	#	religion = religion:dualism_religion
	#	religion = religion:judaism_religion
	#}
}

is_heretic_trigger = {
	$WHO$.faith.religion = $TARGET$.faith.religion
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_heathen_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	# $TARGET$.faith = { # AGOT Disabled
	# 	has_doctrine = pagan_hostility_doctrine
	# }
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

is_infidel_trigger = {
	NOT = { $WHO$.faith.religion = $TARGET$.faith.religion }
	# $TARGET$.faith = { # AGOT Disabled
	# 	NOT = { has_doctrine = pagan_hostility_doctrine }
	# }
	$WHO$.faith = {
		faith_hostility_level = {
			target = $TARGET$.faith
			value >= religious_cb_enabled_hostility_level
		}
	}
}

valid_demand_conversion_conditions_trigger = {
	scope:recipient = { is_busy_in_events_localised = yes }
	scope:recipient = { NOT = { has_strong_hook = scope:actor } }
	scope:recipient = { NOT = { has_trait = devoted } }
	scope:recipient = { NOT = { has_trait = order_member } }
	scope:recipient = {
		NOT = { is_imprisoned_by = scope:actor }
	}

	custom_description = {
		text = "is_head_of_religion"
		subject = scope:recipient
		NOT = { scope:recipient.faith.religious_head = scope:recipient }
	}

	custom_description = {
		text = "is_protected_via_contract"
		subject = scope:recipient
		NAND = { # Vassal Contract forbids meddling by liege
			exists = scope:recipient.liege
			scope:recipient.liege = scope:actor
			scope:recipient = {
				is_ruler = yes
				vassal_contract_has_flag = religiously_protected
			}
		}
	}
}

highgod_is_passive_trigger = {
	#OR = { # AGOT TODO Fix Code Block
	#	religion_tag = buddhism_religion
	#	religion_tag = jainism_religion
	#	religion_tag = taoism_religion
	#	religion_tag = west_african_roog_religion
	#	religion_tag = zunism_religion
	#}
}

highgod_is_active_trigger = {
	highgod_is_passive_trigger = no
}


fertilitygod_is_active_trigger = {
	highgod_is_active_trigger = yes
}


###REINCARNATION###
can_become_reincarnation_trigger = {
	save_temporary_scope_as = reincarnated_child
	faith = {
		has_doctrine = tenet_reincarnation
	}
	any_parent = {
		is_landed = yes
		faith = scope:reincarnated_child.faith
	}
}

can_reincarnate_trigger = {
	is_alive = no
	OR = {
		has_trait = temperate
		has_trait = greedy
		has_trait = generous
		has_trait = diligent
		has_trait = calm
		has_trait = arrogant
		has_trait = humble
		has_trait = deceitful
		has_trait = honest
		has_trait = brave
		has_trait = gregarious
		has_trait = ambitious
		has_trait = just
		has_trait = zealous
		has_trait = compassionate
		has_trait = stubborn
		has_trait = forgiving
		has_trait = lunatic
		has_trait = dull
		has_trait = intellect_bad
		has_trait = shrewd
		has_trait = intellect_good
		has_trait = strong
		has_trait = physique_good
	}
}

is_reincarnation_trigger = {
	can_become_reincarnation_trigger = yes
	OR = {
		AND = {
			has_variable = reincarnation_of

		}

	}
}

# Used in faith scope, COUNT is number of faiths to at least have and CHARACTER is who must own them
num_realm_holy_sites_faithful_holders = {
	custom_description = {
		text = number_realm_holy_sites_held_by_faithful
		subject = $CHARACTER$
		object = this
		value = $COUNT$
		any_holy_site = {
			count >= $COUNT$
			county = {
				is_holy_site_controlled_by = $CHARACTER$
				holder.faith = $CHARACTER$.faith
			}
		}
	}
}

### Head of Faith
can_create_temporal_head_of_faith_title_trigger = {
	num_realm_holy_sites_faithful_holders = {
		COUNT = holy_sites_to_create_temporal_head_of_faith
		CHARACTER = ROOT
	}
	root = { piety_level >= high_piety_level }
	trigger_if = {
		limit = {
			root = { agot_is_independent_ruler = no }
		}
		custom_description = {
			text = cannot_create_hof_title_at_or_above_liege_tier
			root.liege.primary_title.tier > tier_duchy
		}
	}
}

can_create_spiritual_head_of_faith_title_trigger = {
	num_realm_holy_sites_faithful_holders = {
		COUNT = holy_sites_to_create_spiritual_head_of_faith
		CHARACTER = ROOT
	}
	root = { piety_level >= medium_piety_level }
}

# this = Person trying to create the title
can_afford_create_head_of_faith_title_cost_trigger = {
	trigger_if = {
		limit = {
			faith = {
				has_doctrine_parameter = temporal_head_of_faith
				# OR = { # AGOT Disabled - Muhammed doesn't exist!
				# 	has_doctrine = muhammad_succession_sunni_doctrine
				# 	has_doctrine = muhammad_succession_shia_doctrine
				# }
			}		
		}
		trigger_if = {
			# limit = { NOT = { has_trait = sayyid } } # AGOT Disabled - Sayyid removed from game.
			piety >= massive_piety_value
		}
	}
	trigger_else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = temporal_head_of_faith
			}
		}
		piety >= major_piety_value
	}
	trigger_else = {
		limit = {
			faith = {
				has_doctrine_parameter = spiritual_head_of_faith
			}
		}
		gold >= medium_gold_max_value
	}
}

# FAITH = The faith we are trying to make the head of faith title for
# this = Person trying to create the title
can_create_head_of_faith_title_trigger = {
	$FAITH$ = {
		trigger_if = {
			limit = {
				has_doctrine_parameter = spiritual_head_of_faith
			}
			can_create_spiritual_head_of_faith_title_trigger = yes
		}
		trigger_else_if = {
			limit = {
				has_doctrine_parameter = temporal_head_of_faith
			}
			can_create_temporal_head_of_faith_title_trigger = yes
		}
		trigger_else = {
			# We shouldn't hit this point, but if we do use the following as error messages.
			has_doctrine_parameter = spiritual_head_of_faith
			has_doctrine_parameter = temporal_head_of_faith
		}
	}
	can_afford_create_head_of_faith_title_cost_trigger = yes
}

#can_perform_the_hajj_trigger = { # AGOT TODO Fix Code Block
#	faith.religion = religion:islam_religion
#	NOR = {
#		faith = faith:druze
#		faith = faith:alevi
#		faith = faith:alawite
#		faith = faith:qarmatian
#	}
#}


###RELIGIOUS INTERACTIONS###
#Triggers that applies to both Monastery or Holy Order requirements
can_take_religious_vows_trigger = {
	can_take_religious_vows_disregard_marriage_trigger = yes
	
	#Do they have the "wrong" marriage type?
	NOR = {
		custom_description = {
			text = is_married_matrilineally
			subject = scope:recipient
			any_spouse = {
				is_female = yes
				matrilinear_marriage = yes
			}
		}
		custom_description = {
			text = is_married_patrilineally
			subject = scope:recipient
			any_spouse = {
				is_male = yes
				patrilinear_marriage = yes
			}
		}
		custom_description = {
			text = matrilinear_betrothal
			subject = scope:recipient
			exists = betrothed
			betrothed = {
				is_female = yes
				matrilinear_betrothal = yes
			}
		}
		custom_description = {
			text = patrilinear_betrothal
			subject = scope:recipient
			exists = betrothed
			betrothed = {
				is_male = yes
				patrilinear_betrothal = yes
			}
		}
	}
}

can_take_religious_vows_disregard_marriage_trigger = {
	is_available_ai = yes
	faith = scope:actor.faith
	is_ruler = no
	# NOT = { has_trait = excommunicated } # AGOT Disabled
	NOT = { has_character_flag = holy_order_member_requested_return_home }
}

does_religion_exist_in_world_region_trigger = { # The most efficient way I could think of to esentially do diplomatic range triggers on religions # AGOT TODO FIX THIS VERY URGENT I GUESS!!!!
	trigger_if = {
		limit = { location = { geographical_region = world_westeros } } #Same with vanilla europe, we'll use westeros as one for now
		any_county_in_region = {
			region = world_westeros
			faith.religion = $RELIGION$
		}
	}
	#trigger_if = {
	#	limit = { location = { geographical_region = world_europe } } # Even though europe has many sub regions, it's overall size is small so no need to sub-divide!
	#	any_county_in_region = {
	#		region = world_europe
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = {
	#	limit = { location = { geographical_region = world_asia_minor } } # Maybe this should be grouped with both the one above and the one below...
	#	any_county_in_region = {
	#		region = world_asia_minor
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = {
	#	limit = { location = { geographical_region = world_middle_east } }
	#	any_county_in_region = {
	#		region = world_middle_east
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = {
	#	limit = {
	#		location = { geographical_region = world_india } }
	#	any_county_in_region = {
	#		region = world_india
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = {
	#	limit = { location = { geographical_region = world_africa } }
	#	any_county_in_region = {
	#		region = world_africa
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = {
	#	limit = { location = { geographical_region = world_steppe } }
	#	any_county_in_region = {
	#		region = world_steppe
	#		faith.religion = $RELIGION$
	#	}
	#}
	#trigger_else_if = { # We group two smaller world regions into one
	#	limit = {
	#		location = {
	#			OR = {
	#				geographical_region = world_tibet
	#				geographical_region = world_burma
	#			}
	#		}
	#	}
	#	OR = {
	#		any_county_in_region = {
	#			region = world_tibet
	#			faith.religion = $RELIGION$
	#		}
	#		any_county_in_region = {
	#			region = world_burma
	#			faith.religion = $RELIGION$
	#		}
	#	}
	#}
	trigger_else = { always = no } # This should always go at the end of this scripted trigger
}

### HOLY ORDERS ###
holy_order_1000_holy_order_trigger = {
	title = {
		NOR = {
			has_variable = received_new_land
			has_variable = discarded_for_being_too_big
		}
	}
}

holy_order_1000_target_barony_trigger = {
	tier = tier_barony
	barony_is_valid_for_holy_order_lease_trigger = { CHARACTER = $CHARACTER$ }
	#Don't grab something that's held by a vassal player of the one receiving the event.
	trigger_if = {
		limit = {
			NOT = { holder = $CHARACTER$ }
		}
		holder = { is_ai = yes }
	}
}

holy_order_1000_request_target_trigger = {
	highest_held_title_tier >= tier_duchy
	is_landed = yes
	faith = root
	is_available = yes
	NOR = {
		has_character_flag = holy_order_recently_requested_land
		has_character_flag = holy_order_recently_received_land
	}
	save_temporary_scope_as = ruler
	any_sub_realm_barony = {
		holy_order_1000_target_barony_trigger = { CHARACTER = scope:ruler }
	}
}

faith_dominant_gender_male_or_equal = {
	faith = {
		OR = {
			has_doctrine_parameter = male_dominated_law
			has_doctrine_parameter = gender_equal_law
		}
	}
}

faith_dominant_gender_female_or_equal = {
	faith = {
		OR = {
			has_doctrine_parameter = female_dominated_law
			has_doctrine_parameter = gender_equal_law
		}
	}
}

is_theological_character_trigger = {
	OR = {
		has_trait = theologian
		has_trait = devoted
		has_trait = order_member
		AND = {
			is_landed = yes
			has_government = theocracy_government
		}

	}	
}

would_be_sinful_adulterer_trigger = {
	is_married = yes
	trigger_if = {
		limit = { is_male = yes }
		NOT = {
			faith = { has_doctrine = doctrine_adultery_men_accepted }
		}
	}
	trigger_else = {
		NOT = {
			faith = { has_doctrine = doctrine_adultery_women_accepted }
		}
	}
}

has_tolerant_faith_or_culture_trigger = {
	OR = {
		faith = { has_doctrine = doctrine_pluralism_pluralistic }
		culture = { has_cultural_parameter = less_likely_to_force_conversion }
	}
}

believes_in_pilgrimage_trigger = {
	#NOR = { # AGOT TODO Fix Code Block
	#	# These Faiths historically shunned going on pilgrimages, saying they were a waste of time & money.
	#	faith = faith:waldensian
	#	faith = faith:paulician
	#	faith = faith:lollard
	#	faith = faith:qarmatian
	#}
	# Also we must have an actual holy site we can visit.
	faith = {	
		any_holy_site = {
			exists = this
		}
	}
}

#is_mainstream_jewish_faith = {} # AGOT Disabled

is_unprotected_hostile_faith = { # Checks if the faith is at least hostile but not protected by a contract, used in a county scope
	faith = {
		faith_hostility_level = {
			target = prev.holder.top_liege.faith
			value >= 2
		}
	}
	holder = {
		NOT = { vassal_contract_has_flag = religiously_protected }
	}
	trigger_if = { # Does anyone in the hierarchy have religious protection?
		limit = {
			holder = {
				any_liege_or_above = {
					faith = prev.faith
				}
			}
		}
		holder = {
			any_liege_or_above = {
				NOT = { vassal_contract_has_flag = religiously_protected }
			}
		}
	}
}

### SYNCRETIC TRIGGERS ###

islam_or_syncretic_with_islam_trigger = {
	always = no # AGOT TODO
	#$CHARACTER$ = {
	#	faith = {
	#		OR = {
	#			#religion = religion:islam_religion # AGOT TODO Fix Code Block
	#			has_doctrine = tenet_islamic_syncretism
	#		}
	#	}
	#}
}

judaism_or_syncretic_with_judaism_trigger = {
	always = no # AGOT TODO
	#$CHARACTER$ = {
	#	faith = {
	#		OR = {
	#			#religion = religion:judaism_religion # AGOT TODO Fix Code Block
	#			has_doctrine = tenet_jewish_syncretism
	#		}
	#	}
	#}
}

christianity_or_syncretic_with_christianity_trigger = {
	always = no # AGOT TODO
	#$CHARACTER$ = {
	#	faith = {
	#		OR = {
	#			#religion = religion:christianity_religion # AGOT TODO Fix Code Block
	#			has_doctrine = tenet_christian_syncretism
	#		}
	#	}
	#}
}

unreformed_or_syncretic_with_unreformed_trigger = {
	always = no # AGOT TODO #AGOT TODO - unreformed syncretism doesn't exist
	# $CHARACTER$ = {
	# 	faith = {
	# 		OR = {
	# 			#religion = religion:unreformed_religion # AGOT TODO Fix Code Block
	# 			has_doctrine = tenet_unreformed_syncretism
	# 		}
	# 	}
	# }
}
