﻿# Regula Appointment Succession values/modifiers

# Scoring method for age
# age	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30
# score	5	10	15	20	25	30	40	50	60	70	80	90	125	150	175	250	150	125	100	75	70	65	60	55	50	40	30	20	10	-1000
# Above 30 we do a hard-cutoff aka -1000
# Also, being older then the current older is -1000
regula_age_young_blood_appointment_succession_scoring = {
	if = {
		limit = {
			age <= 6
		}
		add = {
			value = 5
			multiply = age
			desc = regula_age_young_child_desc
		}
	}
	else_if = {
		limit = {
			age <= 12
		}
		add = {
			value = 30
			add = {
				value = 10
				multiply = {
					value = age
					subtract = 6
				}
			}
			desc = regula_age_child_desc
		}
	}
	else_if = {
		limit = {
			age <= 15
		}
		add = {
			value = 100
			add = {
				value = 25
				multiply = {
					value = age
					subtract = 12
				}
			}
			desc = regula_age_teenager_desc
		}
	}
	else_if = {
		limit = {
			age = 16
		}
		add = {
			value = 250
			desc = regula_age_become_adult_desc
		}
	}
	else_if = {
		limit = {
			age <= 20
		}
		add = {
			value = 175
			subtract = {
				value = 25
				multiply = {
					value = age
					subtract = 16
				}
			}
			desc = regula_age_young_adult_desc
		}
	}
	else_if = {
		limit = {
			age <= 25
		}
		add = {
			value = 75
			subtract = {
				value = 5
				multiply = {
					value = age
					subtract = 20
				}
			}
			desc = regula_age_adult_desc
		}
	}
	else_if = {
		limit = {
			age < 30
		}
		add = {
			value = 50
			subtract = {
				value = 10
				multiply = {
					value = age
					subtract = 25
				}
			}
			desc = regula_age_adult_desc
		}
	}
	# At 30, we hard stop you being chosen
	# When you come to it
	# And you can't go through it
	# And you can't knock it down
	# You know that you've found
	# The wall, the wall, the wall
	else_if = {
		limit = {
			age >= 30
		}
		add = {
			value = -1000
			desc = regula_age_old_desc
		}
	}

	# Finally, check if this candidate is older then current holder
	# But only if this candidate is an adult (aka age >= 16)
	if = {
		limit = {
			is_adult = yes
			age > scope:title.holder.age
		}
		add = {
			value = -1000
			desc = regula_age_older_then_current_desc
		}
	}
}

# Score based on traits etc
regula_good_breeding_appointment_succession_scoring = {
	# Congenital traits
	add = {
		value = 50
		multiply = num_of_good_genetic_traits
		desc = regula_positive_congenital_traits_desc
	}
	add = {
		value = -50
		multiply = num_of_bad_genetic_traits
		desc = regula_negative_congenital_traits_desc
	}

	# Regula Bloodline Traits
	if = {
		limit = {
			OR = {
				has_trait = regula_fascinare_bloodline
				has_trait = regula_domitans_bloodline
				has_trait = regula_obedience_bloodline
				has_trait = regula_contubernalis_bloodline
				has_trait = regula_domination_war_bloodline
				has_trait = regula_servitude_war_bloodline
				has_trait = regula_potestas_queen_bloodline
				has_trait = regula_multitasker_bloodline
				has_trait = regula_bun_bloodline
			}
		}
		add = {
			value = 10
			multiply = regula_num_bloodline_traits
			desc = regula_negative_regula_bloodline_traits_desc
		}
	}

	# Child of the Book
	if = {
		limit = { has_trait = regula_child_of_the_book }
		add = {
			value = 100
			desc = regula_negative_regula_child_of_the_book_desc
		}
	}

	# Virtues/Sins traits
	add = {
		value = 25
		multiply = num_virtuous_traits
		desc = regula_virtuous_traits_desc
	}
	add = {
		value = -25
		multiply = num_sinful_traits
		desc = regula_sinful_traits_desc
	}

	# Should be retired (Orba/Retired Paelex)
	# Also if Contubernalis
	if = {
		limit = {
			OR = {
				has_trait = orba
				has_trait = retired_paelex
				has_trait = contubernalis
			}
		}
		add = {
			value = -1000
			desc = regula_succession_retired_desc
		}
	}
}

# Check Marital status
# Stuff that makes target more or less viable for marriage to Magister
regula_marital_appointment_succession_scoring = {

	# Check Consanguinity
	if = {
		limit = {
			relation_with_character_is_incestuous_in_faith_trigger = {
				FAITH = top_liege.primary_title.state_faith
				CHARACTER = top_liege
			}
		}
		add = {
			value = -1000
			desc = regula_succession_incest_desc
		}
	}

	# Check Marriage status
	# Checks only apply to adults
	if = {
		limit = {
			is_adult = yes
		}

		# Is character married?
		if = {
			limit = {
				is_married = no
			}
			add = {
				value = 25
				desc = regula_succession_unmarried_desc
			}
		}
		else = {
			add = {
				value = -50
				desc = regula_succession_married_desc
			}
		}

		# Does character already have children?
		if = {
			limit = {
				is_pregnant = no
				any_child = {
					count = 0
				}
			}
			add = {
				value = 25
				desc = regula_succession_no_children_desc
			}
		}
		else = {
			add = {
				value = -25
				desc = regula_succession_has_children_desc
			}
		}

		# Is Fertile?
		if = {
			limit = {
				is_visibly_fertile = no
			}
			add = {
				value = -1000
				desc = regula_succession_does_not_look_fertile_desc
			}
		}
	}

	# Check Sexuality
	if = {
		limit = {
			has_sexuality = heterosexual
		}
		add = {
			value = 15
			desc = regula_succession_heterosexual_desc
		}
	}
	else_if = {
		limit = {
			has_sexuality = bisexual
		}
		add = {
			value = 10
			desc = regula_succession_bisexual_desc
		}
	}
	else_if = {
		limit = {
			has_sexuality = homosexual
		}
		add = {
			value = -10
			desc = regula_succession_homosexual_desc
		}
	}
	else_if = {
		limit = {
			has_sexuality = asexual
		}
		add = {
			value = -25
			desc = regula_succession_asexual_desc
		}
	}

}

# All of the vanilla modifiers for being a Governor
regula_vanilla_appointment_succession_scoring = {
	# Base - Based on skills
	add = {
		value = martial
		add = diplomacy
		add = stewardship
		add = intrigue
		add = learning
		multiply = 1
		desc = sum_of_skills_desc
	}

	# Traits
	if = {
		limit = {
			OR = {
				has_trait = blind
				has_trait = incapable
				has_trait = infirm
			}
		}
		subtract = {
			value = 50
			desc = negative_trait_succession
		}
	}
	if = {
		limit = { has_trait = disinherited }
		subtract = {
			value = 200
			desc = trait_disinherited
		}
	}
	if = {
		limit = { has_trait = gallivanter }
		subtract = {
			value = 200
			desc = trait_gallivanter
		}
	}
	# CRIMINAL
	if = {
		limit = {
			has_trait = deviant
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = deviant FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "deviant_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = incestuous
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = incestuous FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "incestuous_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = sodomite
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = sodomite FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "sodomite_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = cannibal
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = cannibal FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "cannibal_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = kinslayer_1
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_1 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "kinslayer_1_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = kinslayer_2
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_2 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "kinslayer_2_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = kinslayer_3
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = kinslayer_3 FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "kinslayer_3_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = witch
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = witch FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "witch_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = adulterer
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = adulterer FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "adulterer_and_criminal_desc"
		}
	}
	if = {
		limit = {
			has_trait = fornicator
			exists = top_liege.primary_title.state_faith
			trait_is_criminal_in_faith_trigger = { TRAIT = fornicator FAITH = top_liege.primary_title.state_faith GENDER_CHARACTER = root }
		}
		add = {
			value = -30
			desc = "fornicator_and_criminal_desc"
		}
	}

	# COUNCIL POSITIONS
	if = {
		limit = {
			scope:title.holder ?= {
				any_councillor ?= { this = root }
			}
		}
		add = {
			value = 20
			multiply = scope:title.holder.governor_efficiency
			desc = councillor_position_governor_desc
		}
	}
	# COURT POSITIONS
	if = {
		limit = {
			scope:title.holder ?= {
				any_court_position_holder ?= {
					this = root
				}
			}
		}
		add = {
			value = 5
			multiply = scope:title.holder.governor_efficiency
			desc = court_position_succession_governor_desc
		}
	}

	# FAITH HOSTILITY
	if = {
		limit = {
			scope:title.holder.primary_title.state_faith ?= {
				faith_hostility_level = {
					target = root.faith
					value = faith_astray_level
				}
			}
		} #Change to faith acceptance
		subtract = {
			value = 10
			desc = astray_faith_succession_desc
		}
	}
	if = {
		limit = {
			scope:title.holder.primary_title.state_faith ?= {
				faith_hostility_level = {
					target = root.faith
					value = faith_hostile_level
				}
			}
		} #Change to faith acceptance
		subtract = {
			value = 25
			desc = hostile_faith_succession_desc
		}
	}
	if = {
		limit = {
			scope:title.holder.primary_title.state_faith ?= {
				faith_hostility_level = {
					target = root.faith
					value >= faith_evil_level
				}
			}
		} #Change to faith acceptance
		subtract = {
			value = 50
			desc = evil_faith_sucession_desc
		}
	}

	# CLAIMS
	if = {
		limit = { has_strong_claim_on = scope:title }
		add = {
			value = 25
			desc = title_claim_desc
		}
	}
	else_if = {
		limit = { has_weak_claim_on = scope:title }
		add = {
			value = 15
			desc = title_weak_claim_desc
		}
	}

	# POPULAR OPINION
	if = {
		limit = { is_landed = yes }
		add = {
			value = {
				value = capital_county.county_holder_opinion
				multiply = 0.25
			}
			desc = county_holder_opinion_desc
		}
	}

	# PERKS
	if = {
		limit = { has_perk = ducal_conquest_perk }
		add = {
			value = 30
			desc = ducal_conquest_perk_name
		}
	}

	# LOWBORN? EW no
	if = {
		limit = {
			is_lowborn = yes
		}
		subtract = {
			value = 25
			desc = lowborn_desc_succession
		}
	}

	# INFLUENCE LEVEL
	if = {
		limit = {
			influence_level = 0
		}
		subtract = {
			value = 10
			desc = "[influence_level|E]"
		}
	}
	if = {
		limit = {
			influence_level >= 2
		}
		add = {
			value = 10
			multiply = {
				value = influence_level
				subtract = 1 # Base value should start at 2
			}
			desc = "[influence_level|E]"
		}
	}

	#SAME CULTURE AS REGION
	if = {
		limit = { culture ?= scope:title.holder.capital_county.culture }
		add = {
			value = 10
			desc = of_local_culture_succession_desc
		}
	}

	# Personal reasons
	if = {
		limit = {
			scope:title.holder ?= { is_close_family_of = root }
		}
		add = {
			value = 10
			multiply = scope:title.holder.governor_efficiency
			desc = "close_family_holder_desc"
		}
	}
	else_if = {
		limit = {
			scope:title.holder ?= {
				any_spouse = { is_close_family_of = root }
				NOT = { is_close_family_of = root }
			}
		}
		add = {
			value = 10
			desc = "close_family_married_to_holder_desc"
		}
	}

	#FRIENDS OF THE HOLDER
	if = {
		limit = {
			scope:title.holder ?= { has_relation_friend = root }
		}
		add = {
			value = 5
			multiply = scope:title.holder.governor_efficiency
			desc = governor_friend_desc
		}
	}
	if = {
		limit = {
			scope:title.holder ?= { has_relation_best_friend = root }
		}
		add = {
			value = 15
			multiply = scope:title.holder.governor_efficiency
			desc = governor_best_friend_desc
		}
	}

	#REGENT OF EMPEROR
	if = {
		limit = { scope:title.holder.diarch ?= root }
		add = {
			value = scope:title.holder.diarchy_swing
			desc = governor_diarch_desc
		}
	}

	# Schemes
	if = {
		limit = { has_character_modifier = scheme_slandered_modifier }
		add = {
			value = slander_appointment_score_value
			desc = scheme_slandered_modifier
		}
	}
	if = {
		limit = { has_character_modifier = scheme_promoted_modifier }
		add = {
			value = promote_appointment_score_value	# Keep this balanced if more values are added!
			desc = scheme_promoted_modifier
		}
	}

	# Decisions
	if = {
		limit = {
			has_character_modifier = ep3_integration_promoter_modifier
			has_variable = integration_promoted_in
			var:integration_promoted_in.duchy ?= scope:title
		}
		add = {
			value = 30
			desc = ep3_integration_promoter_modifier
		}
	}

	# PETITION
	if = {
		limit = { scope:title.var:petition_house_rights ?= house }
		add = {
			value = 250
			desc = petition_liege_house_province_rights_value_desc
		}
	}

	# EXISTING GOVERNORSHIPS
	if = {
		limit = { is_governor = yes }
		add = {
			value = -1000
			desc = already_a_governor_tt
		}
	}

	#ADJUST BASED ON GENDER LAW - MUST GO AT THE END
	if = {
		limit = {
			scope:title.holder.top_liege ?= { has_realm_law = male_preference_law }
			is_female = yes
		}
		multiply = {
			value = {
				value = 1
				subtract = appointment_non_preferred_gender_penalty_value
			}
			desc = appointment_male_preference_desc
		}
	}
	else_if = {
		limit = {
			scope:title.holder.top_liege ?= { has_realm_law = male_only_law }
			is_female = yes
		}
		multiply = {
			value = {
				value = 1
				subtract = appointment_opposite_gender_penalty_value
			}
			desc = appointment_male_only_desc
		}
	}
	else_if = {
		limit = {
			scope:title.holder.top_liege ?= { has_realm_law = female_preference_law }
			is_female = no
		}
		multiply = {
			value = {
				value = 1
				subtract = appointment_non_preferred_gender_penalty_value
			}
			desc = appointment_female_preference_desc
		}
	}
	else_if = {
		limit = {
			scope:title.holder.top_liege ?= { has_realm_law = female_only_law }
			is_female = no
		}
		multiply = {
			value = {
				value = 1
				subtract = appointment_opposite_gender_penalty_value
			}
			desc = appointment_female_only_desc
		}
	}
	
	# We remove all score from the emperor, to make sure you don't inherit governorships needlessly
	if = {
		limit = {
			is_independent_ruler = yes
		}
		multiply = {
			value = 0
			desc = appointment_is_top_liege
		}
	}
}