﻿calculate_succession_instability_points = {
	if = {
		limit = {
			scope:crisis_heir = {
				is_alive = yes
			}
		}
		scope:crisis_heir = {
			set_variable = {
				name = reasons_for_crisis
				value = 0
			}

			# Personality & Vices (Standard 1 point)
			if = { limit = { has_trait = craven } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = lustful } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = lazy } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = wrathful } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = arbitrary } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = sadistic } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = callous } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = gluttonous } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = greedy } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = fickle } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = shy } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = impatient } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = deceitful } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = paranoid } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = arrogant } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = cynical } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = vengeful } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = irritable } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = reclusive } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = profligate } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = reckless } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = improvident } change_variable = { name = reasons_for_crisis add = 1 } }

			# Status & Legitimacy
			if = { limit = { is_adult = no } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { is_female = yes } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { is_lowborn = yes } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = bastard } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = wild_oat } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = disputed_heritage } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = legitimized_bastard } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { 
				limit = { OR = { has_trait = denounced has_trait = disinherited } } 
				change_variable = { name = reasons_for_crisis add = 3 } 
			}
			if = { limit = { has_trait = disloyal } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = heresiarch } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { age > 60 } change_variable = { name = reasons_for_crisis add = 2 } }

			# Education & Incompetence
			if = { limit = { has_trait = education_diplomacy_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = education_martial_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = education_stewardship_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = education_intrigue_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = education_learning_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = education_martial_prowess_1 } change_variable = { name = reasons_for_crisis add = 1 } }

			# Physical Defects & Health
			if = { limit = { has_trait = disfigured } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = infirm } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = incapable } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { has_trait = blind } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = one_eyed } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = one_legged } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = maimed } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = eunuch } change_variable = { name = reasons_for_crisis add = 10 } }
			if = { limit = { has_trait = hunchbacked } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = lisping } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = wheezing } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = stuttering } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = spindly } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = bleeder } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = clubfooted } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = scaly } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = albino } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = dwarf } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = beauty_bad_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = beauty_bad_2 } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = beauty_bad_3 } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = physique_bad_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = physique_bad_2 } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = physique_bad_3 } change_variable = { name = reasons_for_crisis add = 5 } }

			# Acute Diseases
			if = { limit = { has_trait = leper } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { has_trait = bubonic_plague } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = smallpox } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = typhus } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = cancer } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = consumption } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = gout_ridden } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = sickly } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = ill } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = pneumonic } change_variable = { name = reasons_for_crisis add = 2 } }

			# Genetics & Mental Health
			if = { limit = { has_trait = infertile } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = impotent } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = inbred } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { has_trait = intellect_bad_1 } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = intellect_bad_2 } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = intellect_bad_3 } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = dull } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = weak } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { OR = { has_trait = lunatic_1 has_trait = lunatic } } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = lunatic_genetic } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { OR = { has_trait = possessed_1 has_trait = possessed } } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = possessed_genetic } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { OR = { has_trait = depressed_1 has_trait = depressed_genetic } } change_variable = { name = reasons_for_crisis add = 1 } }

			# Crimes & Vices
			if = { limit = { has_trait = drunkard } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = rakish } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = hashishiyah } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = flagellant } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = inappetetic } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = comfort_eater } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = murderer } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = adulterer } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = fornicator } change_variable = { name = reasons_for_crisis add = 1 } }
			if = { limit = { has_trait = deviant } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = sodomite } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = incestuous } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = kinslayer_1 } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = kinslayer_2 } change_variable = { name = reasons_for_crisis add = 3 } }
			if = { limit = { has_trait = kinslayer_3 } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { has_trait = gallowsbait } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { has_trait = burdened } change_variable = { name = reasons_for_crisis add = 1 } }

			# Severe Social/Religious Taboos
			if = { limit = { has_trait = witch } change_variable = { name = reasons_for_crisis add = 4 } }
			if = { limit = { has_trait = cannibal } change_variable = { name = reasons_for_crisis add = 5 } }
			if = { limit = { has_trait = excommunicated } change_variable = { name = reasons_for_crisis add = 5 } }
			
			# Cultural & Religious Friction
			if = { limit = { NOT = { faith = root.faith } } change_variable = { name = reasons_for_crisis add = 2 } }
			if = { limit = { NOT = { culture = root.culture } } change_variable = { name = reasons_for_crisis add = 2 } }
		}

		if = { 
			limit = { short_term_gold < 0 } 
			scope:crisis_heir = { change_variable = { name = reasons_for_crisis add = 1 } }
		}

		if = {
			limit = {
				root = {
					OR = {
						AND = {
							has_realm_law = male_preference_law
							scope:crisis_heir = { is_female = yes }
						}
						AND = {
							has_realm_law = female_preference_law
							scope:crisis_heir = { is_male = yes }
						}
					}
				}
			}
			scope:crisis_heir = { change_variable = { name = reasons_for_crisis add = 3 } }
		}

		if = {
			limit = {
				root = {
					OR = {
						AND = {
							has_realm_law = male_only_law
							scope:crisis_heir = { is_female = yes }
						}
						AND = {
							has_realm_law = female_only_law
							scope:crisis_heir = { is_male = yes }
						}
					}
				}
			}
			scope:crisis_heir = { change_variable = { name = reasons_for_crisis add = 10 } }
		}

		if = {
			limit = {
				scope:crisis_title = {
					any_claimant = {
						is_eligible_crisis_claimant = yes
					}
				}
			}
			scope:crisis_heir = { change_variable = { name = reasons_for_crisis add = 1 } }
		}
	}
}