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

saxon_elective = { #Farmer Elective
	elector_vote_strength = {
		base = 1
		modifier = { #Each voter is the "representative" of all the free men living in his domain. The larger the domain, the more voting power he has.
			desc = tooltip_scandinavian_elective_development
			domain_size >= 1
			any_held_title = {
				title_tier = county
				development_level > 0
				target_is_de_jure_liege_or_above = scope:title
			}
			add = {
				every_held_title = {
					title_tier = county
					limit = {
						development_level > 0
						target_is_de_jure_liege_or_above = scope:title
					}
					add = {
						value = this.development_level
						if = {
							limit = {
								this.faith != root.faith
							}
							divide = 2
						}
						if = {
							limit = {
								NOT = { this.culture = { has_same_culture_heritage = root.culture } }
							}
							divide = 2
						}
						min = 1
					}
				}
			}
		}
		modifier = { #Further boost/reduction is given depending on capital county's opinion.
			desc = tooltip_scandinavian_elective_capital_opinion
			exists = capital_county
			OR = {
				capital_county.county_opinion <= -5
				capital_county.county_opinion >= 5
			}
			add = {
				value = capital_county.county_opinion
				multiply = 0.2
			}
		}
		min = 1
	}
	
	electors = {
		add = holder
		add = {
			type = title_dejure_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
		add = {
			type = holder_council_members
			limit = {
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
		add = {
			type = holder_direct_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
	}

	candidate_score = {
		base = 0
		######################	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_pattern_circumstances_saxon_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 = title_dejure_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				feudal_elective_potential_landed_candidate_trigger = yes
				government_has_flag = government_is_prepublic
				OR = {
					culture = {
						has_cultural_tradition = tradition_farmer_republics
					}
					faith = {
						has_doctrine = tenet_communal_possessions
					}
					any_liege_or_above = {
						government_has_flag = government_is_prepublic
					}
				}
			}
		}
		add = {
			type = holder_close_or_extended_family
			limit = {
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
				NOT = {
					government_has_flag = government_is_theocracy
				}
				OR = {	
					culture = {
						has_cultural_tradition = tradition_farmer_republics
					}
					faith = {
						has_doctrine = tenet_communal_possessions
					}
					any_liege_or_above = {
						government_has_flag = government_is_prepublic
					}
				}
			}
		}
		add = {
			type = holder_direct_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				government_has_flag = government_is_prepublic
				OR = {
					culture = {
						has_cultural_tradition = tradition_farmer_republics
					}
					faith = {
						has_doctrine = tenet_communal_possessions
					}
					any_liege_or_above = {
						government_has_flag = government_is_prepublic
					}
				}
			}
		}
		add = {
			type = holder_council_members
			limit = {
				OR = {
					is_courtier_of = scope:holder
					target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				}
				NOT = {
					government_has_flag = government_is_theocracy
				}
				OR = {
					culture = {
						has_cultural_tradition = tradition_farmer_republics
					}
					faith = {
						has_doctrine = tenet_communal_possessions
					}
					any_liege_or_above = {
						government_has_flag = government_is_prepublic
					}
				}
			}
		}
	}
}

urban_elective = { #Urban Elective
	elector_vote_strength = {
		base = 1
		modifier = { #Each voter is the "representative" of all the free men living in his domain. The larger the domain, the more voting power he has.
			desc = tooltip_scandinavian_elective_development
			domain_size >= 1
			any_held_title = {
				title_tier = county
				development_level > 0
				target_is_de_jure_liege_or_above = scope:title
			}
			add = {
				every_held_title = {
					title_tier = county
					limit = {
						development_level > 0
						target_is_de_jure_liege_or_above = scope:title
					}
					add = {
						value = this.development_level
						if = {
							limit = {
								this.faith != root.faith
							}
							divide = 2
						}
						if = {
							limit = {
								NOT = { this.culture = { has_same_culture_heritage = root.culture } }
							}
							divide = 2
						}
						min = 1
					}
				}
			}
		}
		modifier = { #Further boost/reduction is given depending on capital county's opinion.
			desc = tooltip_scandinavian_elective_capital_opinion
			is_landed_or_landless_administrative = yes
			exists = capital_county
			OR = {
				capital_county.county_opinion <= -5
				capital_county.county_opinion >= 5
			}
			add = {
				value = capital_county.county_opinion
				multiply = 0.2
			}
		}
		modifier = { #Further boost/reduction is given depending on capital county's opinion.
			desc = tooltip_urbanrep_vote_strength_influence
			add = {
				value = 3
				multiply = influence_level
			}
		}
		min = 1
	}
	
	electors = {
		add = holder
		add = {
			type = title_dejure_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
		add = {
			type = holder_council_members
			limit = {
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
		add = {
			type = holder_direct_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				is_adult = yes
				NOT = { has_trait = incapable }
			}
		}
	}

	candidate_score = {
		base = 0
		######################	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_pattern_circumstances_saxon_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 = title_dejure_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				feudal_elective_potential_landed_candidate_trigger = yes
				government_has_flag = government_is_urepublic
				NOT = {
					government_has_flag = government_is_theocracy
				}
				OR = {
					culture = {
						has_cultural_tradition = tradition_republican_legacy
					}
					faith = {
						has_doctrine = tenet_egalite
					}
					any_liege_or_above = {
						government_has_flag = government_is_urepublic
					}
				}
			}
		}
		add = {
			type = holder_close_or_extended_family
			limit = {
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
				NOT = {
					government_has_flag = government_is_theocracy
				}
				OR = {	
					culture = {
						has_cultural_tradition = tradition_republican_legacy
					}
					faith = {
						has_doctrine = tenet_egalite
					}
					any_liege_or_above = {
						government_has_flag = government_is_urepublic
					}
				}
			}
		}
		add = {
			type = holder_direct_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				government_has_flag = government_is_urepublic
				OR = {
					culture = {
						has_cultural_tradition = tradition_republican_legacy
					}
					faith = {
						has_doctrine = tenet_egalite
					}
					any_liege_or_above = {
						government_has_flag = government_is_urepublic
					}
				}
			}
		}
		add = {
			type = holder_council_members
			limit = {
				OR = {
					is_courtier_of = scope:holder
					target_is_liege_or_above = scope:holder #All de jure vassals, no matter the tier, sub-vassals included.
				}
				NOT = {
					government_has_flag = government_is_theocracy
				}
				OR = {
					culture = {
						has_cultural_tradition = tradition_republican_legacy
					}
					faith = {
						has_doctrine = tenet_egalite
					}
					any_liege_or_above = {
						government_has_flag = government_is_urepublic
					}
				}
			}
		}
	}
}
