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

compeditae_elective = {
	elector_vote_strength = {
		base = 0
		modifier = { #Each voter is either the Magister or a Mulsa or above. The larger the domain and deeper their submission, the more voting power they have.
			desc = tooltip_scandinavian_elective_development
			is_landed = yes
			# or = {
			# 	has_trait = devoted_trait_group
			# 	has_trait = magister_trait_group
			# }
			domain_size >= 1
			any_held_title = {
				tier = tier_county
				development_level > 0
				# target_is_de_jure_liege_or_above = scope:title
			}
			add = { #Every county adds to the voting power.
				every_held_title = {
					limit = {
						tier = tier_county
						development_level > 0
						# target_is_de_jure_liege_or_above = scope:title
					}
					add = {
						value = this.development_level
						if = {
							limit = {
								NOT = { this.faith = root.faith }
							}
							divide = 2
						}
						if = {
							limit = {
								NOT = { this.culture = root.culture }
							}
							divide = 2
						}
						min = 1
					}
				}
			}
		}
		modifier = { #Trait boost Magister
			desc = tooltip_compeditae_power_magister
			has_trait = magister_trait_group
			factor = 5
		}
		modifier = { #Trait boost Mulsa
			desc = tooltip_compeditae_power_mulsa
			has_trait = mulsa
			factor = 1
		}
		modifier = { #Trait boost Tropaeum
			desc = tooltip_compeditae_power_tropaeum
			has_trait = tropaeum
			factor = 1
		}
		modifier = { #Trait boost Paelex
			desc = tooltip_compeditae_power_paelex
			has_trait = paelex
			factor = 2
		}
		modifier = { #Trait boost Paelex
			desc = tooltip_compeditae_power_familia_paelex
			has_trait = familia_paelex
			factor = 2.5
		}
		modifier = { #Trait boost Domina
			desc = tooltip_compeditae_power_domina
			has_trait = domina
			factor = 5
		}
		modifier = { #Trait boost Orba
			desc = tooltip_compeditae_power_orba
			has_trait = orba
			factor = 0.1
		}
		min = 1
	}

	electors = {
		max = 21 # Keep the number of electors sane, to limit drag on the system.
		add = holder
		add = {
			type = holder_direct_vassals
			limit = {
				target_is_liege_or_above = scope:holder #All direct vassals of the Magister.
				is_ruler = yes
				OR = {
					has_trait = devoted_trait_group
					has_trait = magister_trait_group
				}
				is_landed = yes
				exists = capital_county
				highest_held_title_tier > 1 #Barons excluded.
				domain_size >= 1
			}
		}
		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_ruler = yes
				OR = {
					has_trait = devoted_trait_group
					has_trait = magister_trait_group
				}
				is_landed = yes
				exists = capital_county
				highest_held_title_tier > 1 #Barons excluded.
				domain_size >= 1
				any_held_title = { #Elector title must be a de jure vassal of the title being voted on; multi-Dukes (or similar) might have two duchies in multiple electoral domains, which they should be able to vote on. This is only valid for the highest-tier title (so a Duke-Elector who also owns a County which is an electoral title for another title does not get a vote from that county).
					tier = root.highest_held_title_tier
					exists = de_jure_liege
					target_is_de_jure_liege_or_above = scope:title
				}
			}
		}
		add = {
			type = holder_spouses
			limit = {
				target_is_liege_or_above = scope:holder #All the Magister's spouses (in the realm).
				is_ruler = yes
				OR = {
					has_trait = devoted_trait_group
					has_trait = magister_trait_group
				}
				is_landed = yes
				exists = capital_county
				highest_held_title_tier > 1 #Barons excluded.
				domain_size >= 1
			}
		}
		priority = { # Magister then Domina, then Paelex-Queens, Paelex-Duchesses, Mulsa-Queens, Paelex-Countesses, Mulsa-Duchesses, Mulsa-Countesses.
			base = 1
			modifier = { # The Emperor is always picked.
				add = 202
				this = scope:holder
			}
			modifier = { # Queens first.
				add = 75
				highest_held_title_tier >= 4
			}
			modifier = { #Duchesses second
				add = 30
				highest_held_title_tier = 3
			}
			modifier = { #Domina will always be on the list
				add = 126
				has_trait = domina
			}
			modifier = { #Then family paelex
				add = 65
				has_trait = familia_paelex
			}
			modifier = { #Then Paelices
				add = 50
				has_trait = paelex
			}
		}
	}

	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_scandinavian_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_compeditae_elective_modifier = yes

		##########################	Elector voting patterns (opinion)	##########################
		elector_voting_pattern_opinion_compeditae_elective_modifier = yes
	}

	#scope:candidate = Candidate, scope:title = Title, scope:holder_candidate = Candidate currently selected by ruler.
	candidates = {
		# add = {
		# 	type = title_claimants
		# 	limit = {
		# 		feudal_elective_potential_landless_claimant_candidate_trigger = yes
		# 	}
		# }
		add = {
			type = holder_close_or_extended_family
			limit = {
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
			}
		}
	}
}
