﻿everpreg_imperial_elective = { #Atalantean Elective.
	elector_vote_strength = {
		base = 1
		modifier = { #Imperial Dignity
			desc = tooltip_feudal_vote_strength_emperor_tier
			add = 2
			highest_held_title_tier = 5
		}
		modifier = { #Royal Dignity
			desc = tooltip_feudal_vote_strength_king_tier
			add = 0
			highest_held_title_tier = 4
		}
		modifier = { #Powerful Vassal
			desc = tooltip_feudal_vote_strength_powerful_vassal
			add = {
				value = 1
				if = { #Additional point if the vassal is more powerful than the current ruler (Vassal King who meets this condition will have more voting power than the Emperor himself (1+1+1+2 = 5))
					limit = {
						max_military_strength > scope:holder.max_military_strength
					}
					add = 1
				}
			}
			NOT = { this = scope:holder }
			is_powerful_vassal = yes
		}
		modifier = { #Clerical Influence
			desc = tooltip_feudal_vote_strength_theocrat
			add = 2
			NOT = { this = scope:holder }
			OR = {
				has_government = theocracy_government
				has_council_position = councillor_court_chaplain
			}
			faith = scope:holder.faith
			faith = { has_doctrine = doctrine_theocracy_lay_clergy }
			NOT = { root = scope:holder.faith.religious_head }
			#TODO_CD:Possible trigger checking for investiture succession?
		}
		modifier = { #Papal Influence
			desc = tooltip_feudal_vote_strength_pope
			add = 4 #If the Pope is an elector, his vote is the most important of all.
			NOT = { this = scope:holder }
			root = scope:holder.faith.religious_head
			#TODO_CD:Possible trigger checking for investiture succession?
		}
	}
	
	electors = {
		max = 8  #Seven Prince-Electors + 1 Emperor.
		add = holder #The Emperor
		add = {
			type = title_dejure_vassals
			limit = {
				scope:title = { #Either title is higher than Duke-tier, or must be primary.
					OR = {
						tier >= tier_kingdom
						holder = { has_primary_title = prev }
					}
				}
				OR = { #Either de facto direct vassal, or independent ruler who is de jure vassal. (no sub-vassals)
					is_vassal_of = scope:holder
					is_independent_ruler = yes
				}
			}
		}
		priority = {
			base = 1
			modifier = { # The Emperor is always picked.
				add = 200
				this = scope:holder
				NOT = { is_female = no	}				
			}
			modifier = { # Prince-Electors. (specific titles, held by rulers of the same faith as the current holder)
				add = 75
				NOT = { 
					AND = { 
						this = scope:holder 
						is_female = no
					}
				}
				root = scope:holder.faith.religious_head
			}

			modifier = { # Prince-Electors. (specific titles, held by rulers of the same faith as the current holder)
				add = 50
				NOT = { 
					AND = { 
						this = scope:holder 
						is_female = no
					}
				}
				OR = {
					has_government = theocracy_government
					has_council_position = councillor_court_chaplain
				}
				faith = scope:holder.faith
				faith = { has_doctrine = doctrine_theocracy_lay_clergy }
				NOT = { root = scope:holder.faith.religious_head }
			}

			modifier = {
				add = {
					if = { #Fallback Electors
						limit = {
							is_female = yes
							NOT = { 
								this = scope:holder 
							}
						}
						add = 10
					}
					if = { #Slightly favor theocracies of same faith.
						limit = {
							has_trait = everpreg_1
						}
						add = 150
					}
					if = { #Slightly favor theocracies of same faith.
						limit = {
							has_trait = everpreg_2
						}
						add = 250
					}
					if = { #Slightly favor theocracies of same faith.
						limit = {
							has_trait = everpreg_3
						}
						add = 350					}					
					
					if = { #Slightly favor same faith first.
						limit = {
							faith = scope:holder.faith
						}
						add = 15
					}
					if = { #Or compatible faith at least.
						limit = {
							faith = {
								faith_hostility_level = {
									target = scope:holder.faith
									value = faith_fully_accepted_level
								}
							}
						}
						add = 5
					}
					if = { #Slightly favor theocracies of same faith.
						limit = {
							has_government = theocracy_government
							faith = scope:holder.faith
						}
						add = 4
					}
					if = { #Malus for other governments.
						limit = {
							has_government = republic_government
						}
						subtract = 5
					}
					if = { #Malus for other governments.
						limit = {
							OR = {
								has_government = tribal_government
								has_government = clan_government
								has_government = mercenary_government
								has_government = holy_order_government
							}
						}
						subtract = 4
					}
					if = { #Slight prioritization for same culture.
						limit = {
							culture = scope:holder.culture
						}
						add = 4
					}
				}
			}
		}
	}

	candidate_score = {
		base = 0
		#Princely Elective uses very similar behavior to Feudal Elective. The few changes to the modifiers are already accounted for in the scripted_modifiers themselves.
		######################	Elector self-voting pattern	##########################
		elector_self_voting_pattern_feudal_elective_modifier = yes

		##########################	Holder voting pattern	##########################
		holder_voting_pattern_feudal_elective_modifier = yes

		##########################	Elector voting patterns (circumstances)	##########################
		elector_voting_pattern_circumstances_feudal_elective_modifier = yes

		##########################	Elector voting patterns (prestige/piety)	##########################
		elector_voting_pattern_prestige_piety_feudal_elective_modifier = yes

		##########################	Elector voting patterns (traits)	##########################
		elector_voting_pattern_traits_feudal_elective_modifier = yes

		##########################	Elector voting patterns (opinion)	##########################
		elector_voting_pattern_opinion_feudal_elective_modifier = yes
	}
	
	#scope:candidate = Candidate, scope:title = Title, scope:holder_candidate = Candidate currently selected by ruler.
	candidates = {
		add = {
			type = title_claimants
			limit = {
				is_female = yes
				feudal_elective_potential_landless_claimant_candidate_trigger = yes
			}
		}
		add = {
			type = holder_close_or_extended_family
			limit = {
				is_female = yes
				#is_extended_family_of = scope:holder
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
			}
		}
	}
}