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

historicinvasions_mamluk_elective = {
	elector_vote_strength = {
		base = 1
		modifier = { # current ruler
			desc = tooltip_elective_current_ruler
			add = 3
			this = scope:holder
		}
		modifier = { # powerful vassal
			desc = tooltip_feudal_vote_strength_powerful_vassal
			add = 4
			#NOT = { this = scope:holder }
			is_powerful_vassal = yes
			liege = scope:holder
		}
		modifier = { # councillor
			desc = tooltip_feudal_vote_strength_is_councillor
			add = 3
			is_councillor_of = scope:holder
			OR = {
				has_council_position = councillor_marshal
				has_council_position = councillor_chancellor
				has_council_position = councillor_steward
				has_council_position = councillor_spymaster
				has_council_position = councillor_court_chaplain
			}
			liege = scope:holder
		}
		modifier = { # terrible skill
			desc = tooltip_feudal_vote_strength_is_terrible_skill
			add = -1
			average_of_all_skills <= terrible_skill_level
			top_liege = scope:holder
		}
		modifier = { # average skill
			desc = tooltip_feudal_vote_strength_is_average_skill
			add = 2
			average_of_all_skills >= average_skill_level
			average_of_all_skills < good_skill_level
			top_liege = scope:holder
		}
		modifier = { # good skill
			desc = tooltip_feudal_vote_strength_is_good_skill
			add = 3
			average_of_all_skills >= good_skill_level
			average_of_all_skills < excellent_skill_level
			top_liege = scope:holder
		}
		modifier = { # excellent skill
			desc = tooltip_feudal_vote_strength_is_good_skill
			add = 4
			average_of_all_skills >= excellent_skill_level
			top_liege = scope:holder
		}
		modifier = { # knight
			desc = tooltip_feudal_vote_strength_is_knight
			add = 1
			is_ruler = yes
			is_knight_of = scope:holder
			top_liege = scope:holder
		}
		modifier = { # regent influence
			desc = tooltip_feudal_vote_strength_is_diarch
			add = 9
			is_diarch_of_target = scope:holder
		}
		min = 1
	}
	electors = {
		add = holder # current emperor
		add = { # any direct or indirect de jure vassal
			type = title_dejure_vassals
			limit = {
				is_vassal_or_below_of = scope:holder
				NOT = { has_trait = incapable }
				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_direct_vassals # sadly can't go further down
			limit = {
				is_vassal_or_below_of = scope:holder
				NOT = { has_trait = incapable }
				# 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
				# }
			}
		}
	}
	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 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

		# mamluk voting patterns
		elector_voting_pattern_opinion_mamluk_elective_modifier = yes
	}
	candidates = {
		# own children
		add = {
			type = holder_close_or_extended_family
			limit = {
				is_child_of = scope:holder # filter only the children of the current emperor
				is_adult = yes
				feudal_elective_potential_landless_dynastic_candidate_trigger = yes
			}
		}
		# de facto powerful vassals
		add = {
			#type = title_dejure_vassals # direct & indirect vassals in the de jure hierarchy under the title, lowest level: minimum playable tier (county)
			type = holder_direct_vassals # direct vassals in the de facto hierarchy under the title
			limit = {
				is_vassal_of = scope:holder # only Powerful, direct, de jure vassals are potential candidates
				is_adult = yes
				is_powerful_vassal = yes
				feudal_elective_potential_landed_candidate_trigger = yes
			}
		}
		# skilled vassals, landed knights or council members (de jure)
		add = {
			type = title_dejure_vassals # direct & indirect vassals in the de jure hierarchy under the title, lowest level: minimum playable tier (county)
			limit = {
				is_vassal_or_below_of = scope:holder
				is_adult = yes
				is_powerful_vassal = no
				feudal_elective_potential_landed_candidate_trigger = yes
				OR = {
					average_of_all_skills >= average_skill_level
					has_council_position = councillor_marshal
					has_council_position = councillor_chancellor
					has_council_position = councillor_steward
					has_council_position = councillor_spymaster
					has_council_position = councillor_court_chaplain
					AND = {
						is_knight_of = scope:holder
						prowess >= average_skill_level
					}
				}
			}
		}
		# skilled vassals, landed knights or council members (de facto)
		add = {
			type = holder_direct_vassals
			limit = {
				is_vassal_or_below_of = scope:holder
				is_adult = yes
				is_powerful_vassal = no
				feudal_elective_potential_landed_candidate_trigger = yes
				OR = {
					average_of_all_skills >= average_skill_level
					has_council_position = councillor_marshal
					has_council_position = councillor_chancellor
					has_council_position = councillor_steward
					has_council_position = councillor_spymaster
					has_council_position = councillor_court_chaplain
					AND = {
						is_knight_of = scope:holder
						prowess >= average_skill_level
					}
				}
			}
		}
	}
}