admin_emperor = {
	default_candidates = { holder_close_family landed_vassal }
	invested_candidates = { holder_close_extended_family landed_vassal_close_extended_family unlanded_noble_close_extended_family unlanded_noble_house_head }

	allow_children = yes

	candidate_score = {
		value = {
			# AGE
			if = {
				limit = { age <= 5 }
				subtract = {
					value = 100
					desc = infant_candidate_desc
				}
			}
			else_if = {
				limit = { age < 10 }
				subtract = {
					value = 50
					desc = child_candidate_desc
				}
			}
			else_if = {
				limit = { age < 16 }
				subtract = {
					value = 20
					desc = adolescent_candidate_desc
				}
			}
			else_if = {
				limit = { age > 60 }
				subtract = {
					value = 20
					desc = geriatric_candidate_desc
				}
			}

			# SKILLS
			add = {
				value = {
					add = diplomacy
					add = learning
					add = martial
					add = intrigue
					add = stewardship
					multiply = 2
				}
				desc = sum_of_skills_desc
			}

			# TRAITS
			if = {
				limit = {
					has_trait = born_in_the_purple
				}
				add = {
					value = 50
					desc = trait_born_in_the_purple
				}
			}
			if = {
				limit = {
					has_trait = disfigured
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1000
					desc = trait_disfigured
				}
			}
			if = {
				limit = { has_trait = clubfooted }
				subtract = {
					value = 15
					desc = trait_clubfooted
				}
			}
			if = {
				limit = { has_trait = dwarf }
				subtract = {
					value = 15
					desc = trait_dwarf
				}
			}
			if = {
				limit = { has_trait = hunchbacked }
				subtract = {
					value = 15
					desc = trait_hunchbacked
				}
			}
			if = {
				limit = { has_trait = lisping }
				subtract = {
					value = 20
					desc = trait_lisping
				}
			}
			if = {
				limit = {
					OR = {
						has_trait = inbred
						has_trait = spindly
						has_trait = scaly
						has_trait = albino
						has_trait = wheezing
						has_trait = bleeder
						has_trait = infirm
					}
				}
				subtract = {
					value = 50
					desc = negative_trait_succession
				}
			}
			if = {
				limit = {
					has_trait = incapable
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1000
					desc = trait_incapable
				}
			}
			if = {
				limit = {
					has_trait = blind
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1000
					desc = trait_blind
				}
			}
			if = {
				limit = {
					has_trait = eunuch_1
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1000
					desc = trait_eunuch
				}
			}
			if = {
				limit = {
					has_trait = beardless_eunuch
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1500
					desc = trait_beardless_eunuch
				}
			}
			if = {
				limit = {
					has_trait = disinherited
					scope:title.holder.culture = { has_cultural_parameter = physical_disfigurement_blocks_inheritance }
				}
				subtract = {
					value = 1000
					desc = trait_disinherited
				}
			}
			if = {
				limit = { has_trait = gallivanter }
				subtract = {
					value = 1000
					desc = trait_gallivanter
				}
			}

			# CRIMINAL
			if = {
				limit = {
					has_trait = deviant
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "deviant_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = incestuous
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "incestuous_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = sodomite
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "sodomite_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = cannibal
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "cannibal_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_1
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "kinslayer_1_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_2
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "kinslayer_2_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = kinslayer_3
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "kinslayer_3_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = witch
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "witch_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = adulterer
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "adulterer_and_criminal_desc"
				}
			}
			if = {
				limit = {
					has_trait = fornicator
					exists = top_liege.primary_title.state_faith
					trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
				}
				add = {
					value = -20
					desc = "fornicator_and_criminal_desc"
				}
			}

			# COUNCIL POSITIONS
			if = {
				limit = {
					top_liege ?= {
						legitimacy_level >= 3
						any_councillor ?= { this = root }
					}
				}
				add = {
					value = 20
					desc = councillor_position_desc
				}
			}
			else_if = {
				limit = {
					top_liege ?= {
						any_councillor ?= { this = root }
					}
				}
				add = {
					value = 10
					desc = councillor_position_desc
				}
			}

			# COURT POSITIONS
			if = {
				limit = {
					top_liege ?= {
						legitimacy_level >= 3
						any_court_position_holder ?= {
							this = root
						}
					}
				}
				add = {
					value = 10
					desc = court_position_succession_desc
				}
			}
			else_if = {
				limit = {
					top_liege ?= {
						any_court_position_holder ?= {
							this = root
						}
					}
				}
				add = {
					value = 5
					desc = court_position_succession_desc
				}
			}

			# FAITH HOSTILITY
			if = {
				limit = {
					top_liege.primary_title.state_faith ?= {
						NOT = { this = root.faith }
						faith_hostility_level = {
							target = root.faith
							value = faith_fully_accepted_level
						}
					}
				} #Change to faith acceptance
				subtract = {
					value = 5
					desc = accepted_faith_succession_desc
				}
			}
			else_if = {
				limit = {
					top_liege.primary_title.state_faith ?= {
						faith_hostility_level = {
							target = root.faith
							value = faith_astray_level
						}
					}
				} #Change to faith acceptance
				subtract = {
					value = 20
					desc = astray_faith_succession_desc
				}
			}
			else_if = {
				limit = {
					top_liege.primary_title.state_faith ?= {
						faith_hostility_level = {
							target = root.faith
							value = faith_hostile_level
						}
					}
				} #Change to faith acceptance
				subtract = {
					value = 50
					desc = hostile_faith_succession_desc
				}
			}
			else_if = {
				limit = {
					top_liege.primary_title.state_faith ?= {
						faith_hostility_level = {
							target = root.faith
							value >= faith_evil_level
						}
					}
				} #Change to faith acceptance
				subtract = {
					value = 100
					desc = evil_faith_sucession_desc
				}
			}

			# CLAIMS
			if = {
				limit = { has_strong_claim_on = scope:title }
				add = {
					value = 50
					desc = title_claim_desc
				}
			}
			else_if = {
				limit = { has_weak_claim_on = scope:title }
				add = {
					value = 30
					desc = title_weak_claim_desc
				}
			}

			# POPULAR OPINION
			if = {
				limit = { is_landed = yes }
				add = {
					value = {
						value = capital_county.county_holder_opinion
						multiply = 0.5
					}
					desc = county_holder_opinion_desc
				}
			}

			# LIFESTYLE PERKS
			if = {
				limit = { has_perk = dignitas_perk }
				add = {
					value = 30
					desc = dignitas_perk_name
				}
			}

			#TITLE TIER
			if = {
				limit = {
					is_landed = yes
					highest_held_title_tier = tier_duchy
				}
				add = {
					value = 10
					desc = duchy_tier_desc
				}
			}
			if = {
				limit = {
					is_landed = yes
					highest_held_title_tier = tier_kingdom
				}
				add = {
					value = 20
					desc = kingdom_tier_desc
				}
			}

			#LOWBORN? EW no
			if = {
				limit = {
					is_lowborn = yes
				}
				subtract = {
					value = 100
					desc = lowborn_desc_succession
				}
			}

			#INFLUENCE LEVEL
			if = {
				limit = {
					influence_level = 0
				}
				subtract = {
					value = 20
					desc = "[influence_level|E]"
				}
			}
			if = {
				limit = {
					influence_level >= 2
				}
				add = {
					value = 20
					multiply = {
						value = influence_level
						subtract = 1 # Base value should start at 2
					}
					desc = "[influence_level|E]"
				}
			}

			#DIFFERENT CULTURE FROM IMPERIAL CAPITAL
			if = {
				limit = {
					root.top_liege.capital_county.culture ?= {
						NOT = { this = root.culture }
						cultural_acceptance = {
							target = root.culture
							value = 0
						}
					}
				}
				subtract = {
					value = 50
					desc = no_cultural_acceptance
				}
			}
			else_if = {
				limit = {
					root.top_liege.capital_county.culture ?= {
						NOT = { this = root.culture }
						cultural_acceptance = {
							target = root.culture
							value <= 20
						}
					}
				}
				subtract = {
					value = 40
					desc = terrible_cultural_acceptance
				}
			}
			else_if = {
				limit = {
					root.top_liege.capital_county.culture ?= {
						NOT = { this = root.culture }
						cultural_acceptance = {
							target = root.culture
							value <= 40
						}
					}
				}
				subtract = {
					value = 30
					desc = poor_cultural_acceptance
				}
			}
			else_if = {
				limit = {
					root.top_liege.capital_county.culture ?= {
						NOT = { this = root.culture }
						cultural_acceptance = {
							target = root.culture
							value <= 60
						}
					}
				}
				subtract = {
					value = 20
					desc = mediocre_cultural_acceptance
				}
			}
			else_if = {
				limit = {
					root.top_liege.capital_county.culture ?= {
						NOT = { this = root.culture }
						cultural_acceptance = {
							target = root.culture
							value <= 80
						}
					}
				}
				subtract = {
					value = 10
					desc = accepted_foreign_culture
				}
			}

			#ELDEST ELIGIBLE CHILD OF EMPEROR
			if = {
				limit = {
					scope:title.holder = {
						OR = {
							has_realm_law = male_preference_law
							has_realm_law = male_only_law
						}
					}
					is_male = yes
					is_child_of = scope:title.holder
					is_eunuch_trigger = no
					NOT = { has_trait = bastard }
					any_sibling = {
						count = 0
						is_male = yes
						age > prev.age
						is_eunuch_trigger = no
						NOT = { has_trait = bastard }
					}
				}
				add = {
					value = 30
					multiply = scope:title.holder.legitimacy_level
					desc = eldest_imperial_son_desc
				}
			}
			else_if = {
				limit = {
					scope:title.holder = {
						OR = {
							has_realm_law = female_preference_law
							has_realm_law = female_only_law
						}
					}
					is_female = yes
					is_child_of = scope:title.holder
					NOT = { has_trait = bastard }
					any_sibling = {
						count = 0
						is_female = yes
						age > prev.age
						NOT = { has_trait = bastard }
					}
				}
				add = {
					value = 30
					multiply = scope:title.holder.legitimacy_level
					desc = eldest_imperial_daughter_desc
				}
			}
			else_if = {
				limit = {
					scope:title.holder = {
						has_realm_law = equal_law
					}
					is_eunuch_trigger = no
					NOT = { has_trait = bastard }
					is_child_of = scope:title.holder
					any_sibling = {
						count = 0
						age > prev.age
						is_eunuch_trigger = no
						NOT = { has_trait = bastard }
					}
				}
				add = {
					value = 30
					multiply = scope:title.holder.legitimacy_level
					desc = eldest_imperial_child_desc
				}
			}
			#CLOSE FAMILY
			else_if = {
				limit = {
					is_close_family_of = scope:title.holder
				}
				add = {
					value = 20
					multiply = scope:title.holder.legitimacy_level
					desc = imperial_close_family_desc
				}
			}
			#EXTENDED FAMILY
			else_if = {
				limit = {
					is_close_or_extended_family_of = scope:title.holder
				}
				add = {
					value = 15
					multiply = scope:title.holder.legitimacy_level
					desc = imperial_close_extended_family_desc
				}
			}
			#SAME HOUSE
			else_if = {
				limit = {
					house = top_liege.house
				}
				add = {
					value = 10
					multiply = scope:title.holder.legitimacy_level
					desc = imperial_same_house_desc
				}
			}

			#SPOUSE AND THEIR FAMILY
			if = {
				limit = {
					is_spouse_of = scope:title.holder
				}
				add = {
					value = 4
					multiply = scope:title.holder.legitimacy_level
					desc = spouse_of_emperor_desc
				}
			}
			if = {
				limit = {
					scope:title.holder = {
						any_spouse = { is_close_family_of = root }
						NOT = { is_close_family_of = root }
					}
				}
				add = {
					value = 4
					multiply = scope:title.holder.legitimacy_level
					desc = close_family_married_to_holder_desc
				}
			}

			#FRIENDS OF THE EMPEROR
			if = {
				limit = {
					has_relation_friend = scope:title.holder
				}
				add = {
					value = scope:title.holder.legitimacy_level
					multiply = 4
					desc = imperial_friend_desc
				}
			}
			if = {
				limit = {
					has_relation_best_friend = scope:title.holder
				}
				add = {
					value = scope:title.holder.legitimacy_level
					multiply = 8
					desc = imperial_best_friend_desc
				}
			}
			if = {
				limit = {
					has_relation_guardian = scope:title.holder
				}
				add = {
					value = scope:title.holder.legitimacy_level
					multiply = 8
					desc = imperial_guardian_desc
				}
			}
			if = {
				limit = {
					exists = house
				}
				# All get to use their Family Rating
				add = {
					value = house.house_power_score
					multiply = 0.5
					desc = "[powerful_family_rating|E]"
				}
			}

			#CO-EMPEROR OF EMPEROR
			if = {
				limit = {
					is_diarch_of_target = scope:title.holder
					scope:title.holder = { character_has_co_emperorship_trigger = yes }
				}
				# Once for their raw status.
				add = {
					value = 50
					desc = imperial_co_emperor_desc
				}
				# And once again for their actual power.
				add = {
					value = scope:title.holder.diarchy_swing
					desc = imperial_diarch_desc
				}
			}
			#OTHER DIARCHS OF EMPEROR
			else_if = {
				limit = {
					is_diarch_of_target = scope:title.holder
					# Civil servants excluded.
					scope:title.holder = {
						NOT = { has_diarchy_active_parameter = diarchy_is_primeministership }
					}
				}
				add = {
					value = scope:title.holder.diarchy_swing
					desc = imperial_diarch_desc
				}
			}

			# MODIFIERS
			if = {
				limit = {
					has_character_flag = patriarch_support_2030
				}
				add = {
					value = 10
					desc = patriarch_support_2030_desc
				}
			}

			if = {
				limit = { has_character_modifier = restored_greek_theme_modifier }
				add = {
					value = 50
					desc = restored_greek_theme_modifier
				}
			}
			if = {
				limit = {
					has_character_flag = decried_weakness_score
				}
				add = {
					value = 20
					desc = decried_weakness_score_desc
				}
			}
			if = {
				limit = {
					has_character_flag = insulted_trait_candidate_score
				}
				add = {
					value = 15
					desc = insulted_trait_score_desc
				}
			}
			if = {
				limit = {
					has_character_flag = boosted_by_sycophant_score
				}
				add = {
					value = 15
					desc = boosted_by_sycophant_score_desc
				}
			}

			# SCHEMES
			if = {
				limit = {
					has_character_modifier = scheme_slandered_modifier
				}
				add = {
					value = slander_acclamation_score_value
					desc = scheme_slandered_modifier
				}
			}
			if = {
				limit = {
					has_character_modifier = scheme_promoted_modifier
				}
				add = {
					value = promote_acclamation_score_value # Keep this balanced if more values are added!
					desc = scheme_promoted_modifier
				}
			}
			
			# Renounced imperial aspriations (from decision)
			if = {
				limit = {
					OR = {
						has_character_modifier = ep3_admin_renounce_throne_personal
						house ?= { has_house_modifier = ep3_admin_renounce_throne_house }
					}
				}
				add = {
					value = -1000
					desc = admin_renounced_throne
				}
			}

			# ADJUST BASED ON GENDER LAW - MUST GO AT THE END
			save_temporary_value_as = pre_gender_law_calc
			if = { # If the temp value is negative, flip it for the coming calculations
				limit = { scope:pre_gender_law_calc < 0 }
				if = {
					limit = {
						scope:title.holder = {
							has_realm_law = male_preference_law
						}
						is_female = yes
					}
					subtract = {
						value = scope:pre_gender_law_calc
						multiply = -1
						multiply = 0.5
						desc = male_preference_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = male_only_law
						}
						is_female = yes
					}
					multiply = {
						value = 0
						desc = male_only_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = female_preference_law
						}
						is_female = no
					}
					subtract = {
						value = scope:pre_gender_law_calc
						multiply = -1
						multiply = 0.5
						desc = female_only_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = female_only_law
						}
						is_female = no
					}
					multiply = {
						value = 0
						desc = female_only_law
					}
				}
			}
			else = {
				if = {
					limit = {
						scope:title.holder = {
							has_realm_law = male_preference_law
						}
						is_female = yes
					}
					subtract = {
						value = scope:pre_gender_law_calc
						multiply = 0.5
						desc = male_preference_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = male_only_law
						}
						is_female = yes
					}
					multiply = {
						value = 0
						desc = male_only_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = female_preference_law
						}
						is_female = no
					}
					subtract = {
						value = scope:pre_gender_law_calc
						multiply = 0.5
						desc = female_only_law
					}
				}
				else_if = {
					limit = {
						scope:title.holder = {
							has_realm_law = female_only_law
						}
						is_female = no
					}
					multiply = {
						value = 0
						desc = female_only_law
					}
				}
			}

			# ROUND THE NUMBER
			divide = 1
			ceiling = yes
			multiply = 1
		}
	}
}
