﻿celestial_minister = {
	default_candidates = { landed_vassal unlanded_noble_house_head }

	allow_same_tier_candidates = yes

	level = merit

	candidate_score = {
		value = {
			# Age - With age comes experience. We provide a rather small bonus for the elderly, to exist as a potential tie-breaker.
			if = { # Too old
				limit = {
					tgp_is_above_retirement_age_trigger = { REALM_OWNER = root }
				}
				add = {
					value = {
						value = retirement_age_current_value
						subtract = age
						divide = 4
						round = yes
					}
					desc = is_above_retirement_age_desc
				}
			}
			else_if = { # Old and experienced
				limit = {
					age >= 40
				}
				add = {
					value = 10
					desc = old_age_desc
				}
			}
			else_if = { # Too young
				limit = {
					age < 30
				}
				add = {
					value = -5
					desc = young_age_desc
				}
			}

			# Influence
			if = {
				limit = {
					influence_level != 1
				}
				add = {
					value = 10
					multiply = {
						value = influence_level
						subtract = 1 # Baseline is at 1, so we want the bonus to start at 2
					}
					desc = "[influence_level|E]"
				}
			}

			# Domicile Buildings
			if = {
				limit = {
					domicile ?= { has_domicile_parameter = celestial_minister_score_bonus_1 }
				}
				add = {
					value = celestial_ministry_score_bonus_1_value
					desc = "[GetDomicileBuilding('east_asian_minister_office_01').GetName]"
				}
			}
			else_if = {
				limit = {
					domicile ?= { has_domicile_parameter = celestial_minister_score_bonus_2 }
				}
				add = {
					value = celestial_ministry_score_bonus_2_value
					desc = "[GetDomicileBuilding('east_asian_minister_office_02').GetName]"
				}
			}
			else_if = {
				limit = {
					domicile ?= { has_domicile_parameter = celestial_minister_score_bonus_3 }
				}
				add = {
					value = celestial_ministry_score_bonus_3_value
					desc = "[GetDomicileBuilding('east_asian_minister_office_03').GetName]"
				}
			}
			else_if = {
				limit = {
					domicile ?= { has_domicile_parameter = celestial_minister_score_bonus_4 }
				}
				add = {
					value = celestial_ministry_score_bonus_4_value
					desc = "[GetDomicileBuilding('east_asian_minister_office_04').GetName]"
				}
			}
			
			# Aspirations
			if = {
				limit = {
					house ?= { has_house_power_parameter = poet_trait_provides_candidate_score_1 }
				}
				add = {
					value = "has_trait_xp(lifestyle_poet)"
					multiply = poet_trait_provides_candidate_score_1_value
					desc = celestial_governor_poet_trait_desc
				}
			}
			else_if = {
				limit = {
					house ?= { has_house_power_parameter = poet_trait_provides_candidate_score_2 }
				}
				add = {
					value = "has_trait_xp(lifestyle_poet)"
					multiply = poet_trait_provides_candidate_score_2_value
					desc = celestial_governor_poet_trait_desc
				}
			}
			else_if = {
				limit = {
					house ?= { has_house_power_parameter = poet_trait_provides_candidate_score_3 }
				}
				add = {
					value = "has_trait_xp(lifestyle_poet)"
					multiply = poet_trait_provides_candidate_score_3_value
					desc = celestial_governor_poet_trait_desc
				}
			}
			else_if = {
				limit = {
					house ?= { has_house_power_parameter = poet_trait_provides_candidate_score_4 }
				}
				add = {
					value = "has_trait_xp(lifestyle_poet)"
					desc = celestial_governor_poet_trait_desc
				}
			}

			# Relations
			if = { # Is holder's elder
				limit = {
					scope:title.holder ?= { has_relation_elder = root }
				}
				add = {
					value = 20
					desc = governor_elder_desc
				}
			}
			if = { # Is holder's disciple
				limit = {
					scope:title.holder ?= { has_relation_disciple = root }
				}
				add = {
					value = 10
					desc = governor_disciple_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
				}
			}

			# Conquest Dynasty has a favored culture
			if = {
				limit = {
					top_liege = { has_title = title:h_china }
					situation:dynastic_cycle ?= {
						has_variable = dynastic_cycle_favored_culture
						root.culture = var:dynastic_cycle_favored_culture
					}
				}
				add = {
					value = 100
					desc = dynastic_cycle_conquerer_promoted_culture
				}
			}

			# Movements
			# Movement leader
			if = {
				limit = {
					is_any_movement_leader = yes
				}
				add = {
					value = 100
					desc = is_a_movement_leader_desc
				}
			}
			# Part of the favored movement
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_participant_group:expansion_movement = {
							participant_group_has_character = root
							is_movement_in_power = { MOVEMENT = expansion_movement }
						}
					}
				}
				add = {
					value = 25
					desc = expansion_movement_is_favored_appointment_desc
				}
			}
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_participant_group:advancement_movement = {
							participant_group_has_character = root
							is_movement_in_power = { MOVEMENT = advancement_movement }
						}
					}
				}
				add = {
					value = 25
					desc = advancement_movement_is_favored_appointment_desc
				}
			}
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_participant_group:pro_hegemon_movement = {
							participant_group_has_character = root
							NOT = { is_movement_in_power = { MOVEMENT = pro_hegemon_movement } }
						}
					}
				}
				add = {
					value = 10
					desc = pro_hegemon_movement_appointment_desc
				}
			}
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_participant_group:pro_hegemon_movement = {
							participant_group_has_character = root
							is_movement_in_power = { MOVEMENT = pro_hegemon_movement }
						}
					}
				}
				add = {
					value = 25
					desc = pro_hegemon_movement_is_favored_appointment_desc
				}
			}
			if = {
				limit = {
					situation:dynastic_cycle ?= {
						situation_participant_group:conservative_movement = {
							participant_group_has_character = root
							is_movement_in_power = { MOVEMENT = conservative_movement }
						}
					}
				}
				add = {
					value = 25
					desc = conservative_movement_is_favored_appointment_desc
				}
			}

			# Minister specific score
			if = {
				limit = {
					scope:title = {
						OR = {
							this = title:e_minister_chancellor
							this = title:e_minister_of_personnel
						}
					}
				}
				if = {
					limit = {
						scope:title = title:e_minister_chancellor
						tgp_is_any_minister = yes
					}
					add = {
						value = 100
						desc = is_a_minister_desc
					}
				}
				add = {
					value = diplomacy
					desc = diplomacy_concept
				}
			}
			else_if = {
				limit = {
					scope:title = title:e_minister_censor
				}
				add = {
					value = intrigue
					desc = intrigue_concept
				}
			}
			else_if = {
				limit = {
					scope:title = title:e_minister_of_war
				}
				add = {
					value = martial
					desc = martial_concept
				}
			}
			else_if = {
				limit = {
					scope:title = {
						OR = {
							this = title:e_minister_of_revenue
							this = title:e_minister_of_works
						}
					}
				}
				add = {
					value = stewardship
					desc = stewardship_concept
				}
			}
			else_if = {
				limit = {
					scope:title = {
						OR = {
							this = title:e_minister_of_rites
							this = title:e_minister_of_justice
						}
					}
				}
				add = {
					value = learning
					desc = learning_concept
				}
			}
			
			### EXPANDED POWER BASE
			save_temporary_value_as = temp_total
			if = {
				limit = { has_character_modifier = ep3_expanded_power_base_minor_modifier }
				add = {
					value = scope:temp_total
					multiply = 0.10
					round = yes
					min = 25
					desc = ep3_expanded_power_base_minor_modifier
				}
			}
			if = {
				limit = { has_character_modifier = ep3_expanded_power_base_medium_modifier }
				add = {
					value = scope:temp_total
					multiply = 0.20
					round = yes
					min = 50
					desc = ep3_expanded_power_base_medium_modifier
				}
			}
			if = {
				limit = { has_character_modifier = ep3_expanded_power_base_major_modifier }
				add = {
					value = scope:temp_total
					multiply = 0.30
					round = yes
					min = 75
					desc = ep3_expanded_power_base_major_modifier
				}
			}

			# 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 = -1000
					desc = appointment_is_top_liege
				}
			}
		}
	}
}
