﻿# 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.

reformed_princely_elective = { #HRE Elective.
	elector_vote_strength = {
		base = 0 
		modifier = { #Royal Dignity
			desc = tooltip_is_emperor_reformed_elector_sclavinia
			add = 2
			highest_held_title_tier = 5
		} 
		modifier = { #Royal Dignity
			desc = tooltip_is_reformed_elector_sclavinia
			add = 2
			OR = {
				has_title = title:k_poland
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
			}
		}
		modifier = { #Royal Dignity
			desc = tooltip_is_additional_reformed_elector_sclavinia
			add = 1
			OR = {
				highest_held_title_tier = 4
				has_title = title:e_hre
			} 
			NOT = {   
				has_title = title:k_poland
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
			}
		}
		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
			liege = scope:holder
		}
		modifier = { #Regent Influence
			desc = tooltip_feudal_vote_strength_is_diarch
			add = 1
			is_diarch_of_target = scope:holder
		}
	}
	
	electors = {
		max = 5  #Seven Prince-Electors + 1 Emperor.
		add = holder
		add = {
			type = holder_direct_vassals
			limit = {
				#highest_held_title_tier >= tier_kingdom
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:e_hre
				}
				OR = { #Either de facto direct vassal, or independent ruler who is de jure vassal. (no sub-vassals)
					is_vassal_of = scope:holder
					has_title = title:e_hre
				}
				NOT = { government_has_flag = government_is_theocracy }
				has_faith = faith:catholic
			}
		}
		priority = {
			base = 1
			modifier = { # The Emperor is always picked.
				add = 200
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:e_hre
				}
			}
		}
	}

	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
			}
		}
	}
}
destabilized_princely_elective = { #HRE Elective.
	elector_vote_strength = {
		base = 0 
		modifier = { #Royal Dignity
			desc = tooltip_is_emperor_reformed_elector_sclavinia
			add = 2
			highest_held_title_tier = 5
		} 
		modifier = { #Royal Dignity
			desc = tooltip_is_reformed_elector_sclavinia
			add = 2
			OR = {
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
				has_title = title:k_poland
			}
		}
		modifier = { #Royal Dignity
			desc = tooltip_is_destabilized_reformed_elector_sclavinia
			add = 2
			has_title = title:k_poland
			NOT = { has_title = title:e_hre }
		}
		modifier = { #Royal Dignity
			desc = tooltip_is_additional_reformed_elector_sclavinia
			add = 1
			OR = {
				highest_held_title_tier = 4
				has_title = title:e_hre
			} 
			NOT = {   
				has_title = title:k_poland
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
			}
		}
		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
			liege = scope:holder
		}
		modifier = { #Regent Influence
			desc = tooltip_feudal_vote_strength_is_diarch
			add = 1
			is_diarch_of_target = scope:holder
		}
	}
	
	electors = {
		max = 5  #Seven Prince-Electors + 1 Emperor.
		add = holder
		add = {
			type = holder_direct_vassals
			limit = {
				#highest_held_title_tier >= tier_kingdom
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:e_hre
				}
				OR = { #Either de facto direct vassal, or independent ruler who is de jure vassal. (no sub-vassals)
					is_vassal_of = scope:holder
					has_title = title:e_hre
				}
				NOT = { government_has_flag = government_is_theocracy }
				has_faith = faith:catholic
			}
		}
		priority = {
			base = 1
			modifier = { # The Emperor is always picked.
				add = 200
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:e_hre
				}
			}

			modifier = { #Fallback Electors
				add = { 
					if = { 
						limit = {
							sub_realm_size >= 5
						}
						add = 5
					} 
					if = { 
						limit = {
							sub_realm_size >= 10
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 15
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 20
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 25
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 30
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 35
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 40
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 45
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 50
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 55
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 60
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 65
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 70
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 75
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 80
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 85
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 90
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 95
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 100
						}
						add = 5
					}
					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
					}
				}
			}
		}
	}

	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
			}
		}
	}
}
universal_princely_elective = { #HRE Elective.
	elector_vote_strength = {
		base = 0 
		modifier = { #Royal Dignity
			desc = tooltip_is_emperor_reformed_elector_sclavinia
			add = 2
			highest_held_title_tier = 5
		} 
		modifier = { #Royal Dignity
			desc = tooltip_is_reformed_elector_sclavinia
			add = 2
			OR = {
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
				has_title = title:k_poland
				has_title = title:k_castille
				has_title = title:k_england
				has_title = title:k_hungary
				has_title = title:k_africa
				has_title = title:k_thessalonika
				has_title = title:k_croatia
				has_title = title:k_denmark
				has_title = title:k_jerusalem
				has_title = title:k_ruthenia
			}
		}
		modifier = { #Royal Dignity
			desc = tooltip_is_destabilized_reformed_elector_sclavinia
			add = 2
			has_global_variable = destabilized_election_sclavinia
			has_title = title:k_poland
			NOT = { has_title = title:e_hre }
		}
		modifier = { #Royal Dignity
			desc = tooltip_is_additional_reformed_elector_sclavinia
			add = 1
			OR = {
				highest_held_title_tier = 4
				has_title = title:e_hre
			} 
			NOT = {   
				has_title = title:k_poland
				has_title = title:k_east_francia
				has_title = title:k_france
				has_title = title:k_italy
				has_title = title:k_castille
				has_title = title:k_england
				has_title = title:k_hungary
				has_title = title:k_africa
				has_title = title:k_thessalonika
				has_title = title:k_croatia
				has_title = title:k_denmark
				has_title = title:k_jerusalem
				has_title = title:k_ruthenia
			}
		}
		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
			liege = scope:holder
		}
		modifier = { #Regent Influence
			desc = tooltip_feudal_vote_strength_is_diarch
			add = 1
			is_diarch_of_target = scope:holder
		}
	}
	
	electors = {
		max = 99  #Seven Prince-Electors + 1 Emperor.
		add = holder
		add = {
			type = holder_direct_vassals
			limit = {
				#highest_held_title_tier >= tier_kingdom
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:k_castille
					has_title = title:k_england
					has_title = title:k_hungary
					has_title = title:k_africa
					has_title = title:k_thessalonika
					has_title = title:k_croatia
					has_title = title:k_denmark
					has_title = title:k_jerusalem
					has_title = title:k_ruthenia
					has_title = title:e_hre
				}
				OR = { #Either de facto direct vassal, or independent ruler who is de jure vassal. (no sub-vassals)
					is_vassal_of = scope:holder
					has_title = title:e_hre
				}
				NOT = { government_has_flag = government_is_theocracy }
				has_faith = faith:catholic
			}
		}
		add = {
			type = holder_direct_vassals
			limit = {
				highest_held_title_tier >= tier_kingdom
				OR = { #Either de facto direct vassal, or independent ruler who is de jure vassal. (no sub-vassals)
					is_vassal_of = scope:holder
					has_title = title:e_hre
				}
				NOT = { government_has_flag = government_is_theocracy }
				has_faith = faith:catholic
			}
		}
		priority = {
			base = 1
			modifier = { # The Emperor is always picked.
				add = 200
				OR = {
					has_title = title:k_poland
					has_title = title:k_east_francia
					has_title = title:k_france
					has_title = title:k_italy
					has_title = title:k_castille
					has_title = title:k_england
					has_title = title:k_hungary
					has_title = title:k_africa
					has_title = title:k_thessalonika
					has_title = title:k_croatia
					has_title = title:k_denmark
					has_title = title:k_jerusalem
					has_title = title:k_ruthenia
					has_title = title:e_hre
				}
			}

			modifier = { #Fallback Electors
				add = { 
					if = { 
						limit = {
							sub_realm_size >= 5
						}
						add = 5
					} 
					if = { 
						limit = {
							sub_realm_size >= 10
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 15
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 20
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 25
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 30
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 35
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 40
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 45
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 50
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 55
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 60
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 65
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 70
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 75
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 80
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 85
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 90
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 95
						}
						add = 5
					}
					if = { 
						limit = {
							sub_realm_size >= 100
						}
						add = 5
					}
					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
					}
				}
			}
		}
	}

	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
			}
		}
	}
}
