﻿# The entry should be named in the same way that the elective succession law is named to define it's voter's logic.
# Root scope - Elector, the character voting in the election.
# scope:candidate scope - Candidate, Character considered for the title.
# scope:title scope - Title, The title the nomination is for.
# scope:holder scope - Ruler, The ruler currently holding the title.
# scope:holder_candidate scope - Favored Candidate, The title owner's candidate.
# The voter will vote for the top score candidate calculated from this script.

princely_elective = { #HRE 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 = 1
			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 = 2
				}
			}
			NOT = { this = scope:holder }
			is_powerful_vassal = yes
			liege = scope:holder
		}
		modifier = { #Clerical Influence
			desc = tooltip_feudal_vote_strength_theocrat
			add = 2
			NOT = { this = scope:holder }
			OR = {
				government_has_flag = government_is_theocracy
				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 = { #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
		}
		modifier = { #Regent Influence
			desc = tooltip_feudal_vote_strength_is_diarch
			add = 1
			is_diarch_of_target = scope:holder
		}
	}
	
	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
				}
				trigger_if = { #Must be true priests
					limit = { government_has_flag = government_is_theocracy }
					trigger_if = {
						limit = { is_female = yes }
						faith_dominant_gender_female_or_equal = yes
					}
					trigger_else = { faith_dominant_gender_male_or_equal = yes }
				}
			}
		}
		priority = {
			base = 1
			modifier = { # The Emperor is always picked.
				add = 200
				this = scope:holder
			}
			modifier = { # Prince-Electors. (specific titles, held by rulers of the same faith as the current holder)
				add = 75
				faith = scope:holder.faith
				any_held_title = {
					is_target_in_global_variable_list = { name = hre_elector_list target = this }
				}
			}

			modifier = { #Fallback Electors
				add = {
					value = 10
					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 = {
							government_has_flag = government_is_theocracy
							faith = scope:holder.faith
						}
						add = 4
					}
					if = { #Malus for other governments.
						limit = {
							government_has_flag = government_is_republic
						}
						subtract = 5
					}
					if = { #Malus for other governments.
						limit = {
							OR = {
								government_has_flag = government_is_tribal
								government_has_flag = government_is_clan
								government_has_flag = government_is_mercenary
								government_has_flag = government_is_holy_order
							}
						}
						subtract = 4
					}
					if = { #Slight prioritization for same culture.
						limit = {
							culture = scope:holder.culture
						}
						add = 4
					}
					# Favor higher tier titles
					if = {
						limit = {
							highest_held_title_tier >= tier_kingdom
						}
						add = 5
					}
					# Disfavor non-theocratic counts
					if = {
						limit = {
							NOT = { government_has_flag = government_is_theocracy }
							highest_held_title_tier < tier_duchy
						}
						subtract = 5
					}
				}
			}
		}
	}

	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

		##########################	Elector voting patterns (misc)	##########################
		elector_voting_pattern_circumstances_misc_elective_modifier = yes
	}
	
	#scope:candidate = Candidate, scope:title = Title, scope:holder_candidate = Candidate currently selected by ruler.
	candidates = {
		add = {
			type = holder_direct_vassals
			limit = {
				feudal_elective_potential_landed_candidate_trigger = yes
			}
		}
		add = {
			type = title_dejure_vassals
			limit = {
				is_independent_ruler = yes #De jure vassals of the title who are not de facto vassals of the current ruler.
				feudal_elective_potential_landed_candidate_trigger = yes
			}
		}
		add = {
			type = title_claimants
			limit = {
				feudal_elective_potential_landless_claimant_candidate_trigger = yes
			}
		}
		add = {
			type = holder_close_or_extended_family
			limit = {
				is_close_family_of = scope:holder
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
			}
		}
	}
}
