# The entry should be named in the same way that the elective succession law is named to define its voter's logic
# ROOT 			Voter, the character voting in the election
# FROM			Candidate, character considered for the title
# FROMFROM		The title the nomination is for
# FROMFROMFROM	The title owner's candidate
# The voter will vote for the top score candidate calculated from this script

emperor_appointment_rules = {
	elector_vote_strength = {
		days = 1
	}

	elector_selection = {
		days = -5
		max_amount = 1 # 1 Emperor, or regent if any

		trigger = {
			# The title must currently exist
			FROMFROM = {
				has_holder = yes
			}
		}
		
		additive_modifier = { # top_liege is also always an Elector
			value = 100

			FROMFROM = {
				holder_scope = {
					is_vassal_or_below_of = ROOT
				}
			}
			independent = yes
			in_revolt = no
			has_regent = no
		}
		
		additive_modifier = { # Current ruler is always an elector
			value = 10

			FROMFROM = {
				holder = ROOT
			}
		}
	}

	# ROOT is current title holder
	# FROM is candidate
	# FROMFROM is title
	# FROMFROMFROM is null
	candidate_trigger = {
		# Title must currently exist
		FROMFROM = {
			has_holder = yes
		}
		
		FROM = {
			NOT = {
				is_vassal_or_below_of = ROOT
			}
			is_adult = yes
			is_landed = no
			# Sexism
			trigger_if = {
				limit = {
					always = no # Uncomment this
					ROOT = {
						top_liege = {
							OR = {
								AND = {
									is_female = yes
									has_law = cognatic_succession
								}
								has_law = true_cognatic_succession
								has_law = enatic_cognatic_succession
								has_law = enatic_succession
							}
						}
					}
				}
				is_female = yes
			}
			trigger_else = {
				is_female = no
			}

			# Candidate should not be a landless Courtier who is about to inherit a Feudal or Theocracy
			trigger_if = {
				limit = {
					any_heir_title = {
						OR = {
							#is_feudal = yes
							is_theocracy = yes
						}
					}
				}
				always = yes
			}
			
			#OR = {
			#	has_top_tier_education_trait_trigger = yes
			#	has_3rd_tier_education_trait_trigger = yes
			#	AND = {
			#		has_2nd_tier_education_trait_trigger = yes
			#		is_learned_trigger = yes
			#	}
			#}

			is_ascetic_trigger = no
			is_priest = no

			NOR = {
				trait = disinherited
			}
		}
	}

	candidate_vote_score = {
		days = 0

		## All candidates

		# Ageism
		additive_modifier = { # Still too young for older rulers
			value = -10
			localisation_key = tooltip_feudal_elector_vote_youngster

			FROM = {
				is_adult = yes
				age < 25
			}
		}

		additive_modifier = {
			value = -10
			localisation_key = tooltip_feudal_elector_vote_youngster

			FROM = {
				age >= 25
				age < 35
			}
		}

		# Culturism
		additive_modifier = { # Candidate is a foreign to the elector
			value = -500
			localisation_key = tooltip_feudal_elector_vote_encroaching_foreigner

			FROM = {
				NOT = {
					culture = ROOT
				}
			}
		}

		# Barbarism

		# Nepotism

		# Prestige
		elector_candidate_prestige_vote = yes

		# Piety
		elector_candidate_piety_vote = yes

		# Traits
		elector_candidate_traits_vote = yes
		# elector_candidate_education_traits_vote = yes

		# Ruler traits
		elector_ruler_traits_vote = yes

		# Candidate opinion
		elector_candidate_opinion_vote = yes
	}
}