﻿theocracy = {
	default_candidates = {
		holder_close_family
		holder_close_extended_family
		holder_house_member
		landed_vassal
		landed_vassal_close_family
		landed_vassal_close_extended_family
		landed_vassal_house_member
		holder_councilor
		holder_court_position
		direct_subject
	}
	invested_candidates = {
		holder_close_family
		holder_close_extended_family
		holder_house_member
		landed_vassal
		landed_vassal_close_family
		landed_vassal_close_extended_family
		landed_vassal_house_member
		holder_councilor
		holder_court_position
		direct_subject
	}

	candidate_score = {
		value = {
			# Base - Based on skills
			add = {
				value = learning
				multiply = 3
				desc = learning
			}
			add = {
				value = {
					add = diplomacy
					add = learning
					add = martial
					add = intrigue
					add = stewardship
				}
				desc = sum_of_skills_desc
			}

			add = {
				value = num_virtuous_traits
				multiply = 25
				desc = virtuous_traits_difficulty
			}

			if = {
				limit = { piety_level = 2 }
				add = {
					value = 25
					desc = piety_level_2
				}
			}
			else_if = {
				limit = { piety_level = 3 }
				add = {
					value = 50
					desc = piety_level_3
				}
			}
			else_if = {
				limit = { piety_level = 4 }
				add = {
					value = 75
					desc = piety_level_4
				}
			}
			else_if = {
				limit = { piety_level = 5 }
				add = {
					value = 100
					desc = piety_level_5
				}
			}

			# Traits
			if = {
				limit = {
					has_trait = zealous
				}
				add = {
					value = 25
					desc = trait_zealous
				}
			}
			if = {
				limit = {
					has_trait = devoted
				}
				add = {
					value = 25
					desc = trait_devoted
				}
			}

			# Epic Learning traits
			if = {
				limit = {
					has_trait = theologian
				}
				add = {
					value = 50
					desc = theologian_desc
				}
			}
			if = {
				limit = {
					has_trait = scholar
				}
				add = {
					value = 50
					desc = scholar_desc
				}
			}

			if = {
                limit = {
					age < 45
					faith = { has_doctrine = doctrine_clerical_marriage_allowed }
					faith = { has_doctrine = doctrine_clerical_gender_female_only }
					OR = {
						faith = { has_doctrine = tenet_sacred_childbirth }
						faith = { has_doctrine = tenet_carnal_exaltation }
						faith = { has_doctrine = tenet_polyamory }
					}
                }
                add = {
					value = {
						add = 45
						subtract = age
					}
					multiply = 3
					desc = positive_desc_youthful
				}
            }

			if = {
                limit = {
					has_trait = fecund
					OR = {
						faith = { has_doctrine = tenet_sacred_childbirth }
					}
                }
                add = {
					value = 100
					desc = trait_fecund
				}
            }

			if = {
                limit = {
					has_trait = beauty_good_3
					OR = {
						faith = { has_doctrine = tenet_carnal_exaltation }
						faith = { has_doctrine = tenet_polyamory }
					}
                }
                add = {
					value = 75
					desc = trait_beauty_good_3
				}
            }

			if = {
                limit = {
					has_trait = beauty_good_2
					OR = {
						faith = { has_doctrine = tenet_carnal_exaltation }
						faith = { has_doctrine = tenet_polyamory }
					}
                }
                add = {
					value = 50
					desc = trait_beauty_good_2
				}
            }

			if = {
                limit = {
					has_trait = beauty_good_1
					OR = {
						faith = { has_doctrine = tenet_carnal_exaltation }
						faith = { has_doctrine = tenet_polyamory }
					}
                }
                add = {
					value = 25
					desc = trait_beauty_good_1
				}
            }

			# Vassal theocracies or baron level ok
			if = {
				limit = {
					OR = {
						highest_held_title_tier = tier_barony
						is_vassal_of = scope:title.holder
					}
					is_ruler = yes
					government_has_flag = government_is_theocracy
				}
				add = {
					value = 25
					desc = title_landed_name
					multiply = primary_title.tier
				}
			}

			#SAME CULTURE AS REGION
			if = {
				limit = { culture = scope:title.holder.capital_county.culture }
				add = {
					value = 100
					desc = of_local_culture_succession_desc
				}
			}
			else_if = {
				limit = {
					NOR = {
						culture = { has_same_culture_heritage = scope:title.holder.capital_county.culture }
						knows_language_of_culture = scope:title.holder.capital_county.culture
					}
				}
				subtract = {
					value = 100
					desc = CULTURE_RELATION_FOREIGN_CULTURE
				}
			}

			subtract = {
				value = num_sinful_traits
				multiply = 25
				desc = sinful_traits_difficulty
			}

			if = {
				limit = { age > 45 }
				subtract = {
					value = {
						add = -45
						add = age
					}
					desc = geriatric_candidate_desc
				}
			}

			if = {
				limit = { piety_level = 0 }
				subtract = {
					value = 50
					desc = piety_level_0
				}
			}

			if = {
				limit = {
					OR = {
						has_trait = incapable
						has_trait = infirm
					}
				}
				subtract = {
					value = 1000
					desc = negative_trait_succession
				}
			}

			# Disqualify
			if = {
				limit = {
					is_ruler = yes
					highest_held_title_tier >= tier_county
					NOT = { is_vassal_of = scope:title.holder }
				}
				subtract = {
					value = 1000
					desc = outside_realm_desc
				}
			}
			if = {
				limit = {
					NOT = { faith = scope:title.holder.faith }
				}
				subtract = {
					value = 1000
					desc = hold_court_8200_vassal_modifier
				}
			}
			if = {
                limit = {
					faith = { has_doctrine = doctrine_clerical_marriage_disallowed }
                    is_married = yes
                }
                subtract = {
					value = 1000
					desc = married_desc_third_perspective
				}
            }
            if = {
                limit = {
					faith = { has_doctrine = doctrine_clerical_gender_female_only }
                    is_male = yes
                }
                subtract = {
					value = 1000
					desc = appointment_female_only_desc
				}
            }
            if = {
                limit = { 
                    faith = { has_doctrine = doctrine_clerical_gender_male_only }
                    is_female = yes
                }
                subtract = {
					value = 1000
					desc = appointment_male_only_desc
				}
            }
			if = {
				limit = {
					has_trait = deviant
					trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "deviant_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = incestuous
					trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "incestuous_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = sodomite
					trait_is_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "sodomite_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = cannibal
					trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "cannibal_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_1
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "kinslayer_1_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_2
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "kinslayer_2_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_3
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "kinslayer_3_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = witch
					trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "witch_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = adulterer
					trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "adulterer_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = fornicator
					trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = root.faith GENDER_CHARACTER = root }
				}
				subtract = {
					value = 1000
					desc = "fornicator_and_criminal_desc"
				}
			}
		}
	}
}
