# Court Positions Expanded - Grand Vizier
# Adapted for CK3 1.19 framework
# grand_vizier_court_position

### Special Court Positions ###

grand_vizier_court_position = {
	sort_order = 325
	skill = stewardship
	max_available_positions = 1
	minimum_rank = kingdom

	court_position_asset = {
		trigger = {
			culture_has_mena_heritage_pillar_trigger = yes
		}
		animation = stewardship_lifestyle
		background = "gfx/interface/illustrations/event_scenes/market_east.dds"
	}

	court_position_asset = {
		animation = stewardship_lifestyle
		background = "gfx/interface/illustrations/event_scenes/market_west.dds"
	}

	opinion = {
		value = 20
	}

	# How high the aptitude has to be to reach the 5 different modifier levels
	aptitude_level_breakpoints = { 20 40 60 80 }

	# How good is this character in this position? root scope is the holder of the court position
	aptitude = {
		value = 10
		add = {
			value = stewardship
			multiply = 3.25
			max = 65
			desc = court_position_skill_stewardship
		}
		if = {
			limit = {
				has_trait = administrator
			}
			add = {
				value = 20
				desc = court_position_administrator_trait
			}
		}
		if = {
			limit = {
				has_trait = diligent
			}
			add = {
				value = 10
				desc = court_position_diligent_trait
			}
		}
		if = {
			limit = {
				has_trait = just
			}
			add = {
				value = 10
				desc = court_position_just_trait
			}
		}
		if = {
			limit = {
				has_trait = arbitrary
			}
			add = {
				value = -5
				desc = court_position_arbitrary_trait
			}
		}
		if = {
			limit = {
				has_trait = profligate
			}
			add = {
				value = -5
				desc = court_position_profligate_trait
			}
		}
		if = {
			limit = {
				has_trait = improvident
			}
			add = {
				value = -5
				desc = court_position_improvident_trait
			}
		}
		add = court_position_aptitude_family_business_value
		add = general_aptitude_bonus
	}

	# Is this an available position for this court? (root is court owner)
	is_shown = {
		has_religion = religion:islam_religion
		is_landed_or_landless_administrative = yes
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_county
			}
			always = no
		}
	}

	valid_position = {
		has_religion = religion:islam_religion
		is_landed_or_landless_administrative = yes
		highest_held_title_tier >= tier_kingdom
	}

	is_shown_character = {
		scope:employee = {
			court_position_employee_shown_trigger = yes
		}
	}

	valid_character = {
		scope:employee = {
			is_imprisoned = no
			has_religion = religion:islam_religion
			trigger_if = {
				limit = {
					scope:liege.faith = {
						has_doctrine = doctrine_gender_male_dominated
					}
				}
				is_male = yes
			}
			trigger_if = {
				limit = {
					scope:liege.faith = {
						has_doctrine = doctrine_gender_female_dominated
					}
				}
				is_female = yes
			}
		}
	}

	revoke_cost = {
		prestige = {
			value = major_court_position_prestige_revoke_cost
			# Waived by Dynasty Perk Inner Circle (same house)
			if = {
				limit = {
					exists = dynasty
					dynasty = { has_dynasty_perk = fp2_coterie_legacy_1 }
					employs_court_position = grand_vizier_court_position
					any_court_position_holder = {
						type = grand_vizier_court_position
						exists = dynasty
						house = prev.house
					}
				}
				multiply = 0
			}
			# Avoid AI prestige issues
			if = {
				limit = {
					exists = this
					is_ai = yes
				}
				multiply = 0
			}
			# Special case for events
			if = {
				limit = {
					exists = this
					has_character_flag = free_revoke_cost
				}
				multiply = 0
			}
		}
	}

	salary = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = major_court_position_salary
					# Waived by Dynasty Perk Inner Circle (same house)
					if = {
						limit = {
							scope:liege = {
								exists = dynasty
								dynasty = { has_dynasty_perk = fp2_coterie_legacy_1 }
								employs_court_position = grand_vizier_court_position
								any_court_position_holder = {
									type = grand_vizier_court_position
									exists = dynasty
									house = prev.house
								}
							}
						}
						multiply = {
							value = 0.0
							desc = inner_circle_salary_mod
							format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
						}
					}
					# Obligation hook halves salary
					if = {
						limit = {
							scope:liege = {
								employs_court_position = grand_vizier_court_position
								any_court_position_holder = {
									type = grand_vizier_court_position
									scope:liege = {
										has_hook_of_type = {
											type = obligation_hook
											target = prev
										}
									}
								}
							}
						}
						multiply = {
							value = 0.5
							desc = obligation_hook_salary
						}
					}
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = major_court_position_salary
					# Waived by Dynasty Perk Inner Circle (same house)
					if = {
						limit = {
							scope:liege = {
								exists = dynasty
								dynasty = { has_dynasty_perk = fp2_coterie_legacy_1 }
								employs_court_position = grand_vizier_court_position
								any_court_position_holder = {
									type = grand_vizier_court_position
									exists = dynasty
									house = prev.house
								}
							}
						}
						multiply = {
							value = 0.0
							desc = inner_circle_salary_mod
							format = "BASE_VALUE_FORMAT_DECIMALS_MINUS_POSITIVE"
						}
					}
					# Obligation hook halves salary
					if = {
						limit = {
							scope:liege = {
								employs_court_position = grand_vizier_court_position
								any_court_position_holder = {
									type = grand_vizier_court_position
									scope:liege = {
										has_hook_of_type = {
											type = obligation_hook
											target = prev
										}
									}
								}
							}
						}
						multiply = {
							value = 0.5
							desc = obligation_hook_salary
						}
					}
				}
			}
		}
		prestige = {
			value = major_court_position_prestige_salary
		}
	}

	received_salary = {
		gold = {
			value = major_court_position_salary
		}
		prestige = {
			value = major_court_position_prestige_salary
		}
		round = no
	}

	# Modifiers scaled to the Grand Vizier's aptitude level
	scaling_employer_modifiers = {
		terrible = {
			vassal_limit = 3
			domain_tax_mult = 0.02
			levy_size = 0.02
			barons_and_minor_landholders_opinion = 2
			stress_gain_mult = -0.05
		}
		poor = {
			vassal_limit = 4
			domain_tax_mult = 0.03
			levy_size = 0.03
			barons_and_minor_landholders_opinion = 4
			stress_gain_mult = -0.05
		}
		average = {
			vassal_limit = 8
			domain_tax_mult = 0.04
			levy_size = 0.04
			barons_and_minor_landholders_opinion = 6
			stress_gain_mult = -0.10
		}
		good = {
			vassal_limit = 10
			domain_tax_mult = 0.05
			levy_size = 0.05
			barons_and_minor_landholders_opinion = 8
			stress_gain_mult = -0.15
		}
		excellent = {
			domain_limit = 1
			vassal_limit = 10
			domain_tax_mult = 0.06
			levy_size = 0.06
			barons_and_minor_landholders_opinion = 10
			stress_gain_mult = -0.15
		}
	}

	# Modifiers always applied to the Grand Vizier themselves
	modifier = {
		monthly_prestige = major_court_position_prestige_salary
		diplomacy = 2
		monthly_prestige_gain_mult = 0.20
		monthly_diplomacy_lifestyle_xp_gain_mult = 0.20
		monthly_stewardship_lifestyle_xp_gain_mult = 0.20
	}

	on_court_position_received = {
		basic_gained_court_position_effect = yes
	}
	on_court_position_revoked = {
		basic_revoked_court_position_effect = yes
	}
	on_court_position_invalidated = {
		basic_invalidated_court_position_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = grand_vizier_court_position
		}
	}

	# Scripted value to determine whether an AI will hire/fire a position or not. Hires over 0, fires under -50.
	ai_position_score = {
		value = 1
		scope:liege = {
			# More likely to hire if the realm is large and admin-heavy
			if = {
				limit = {
					vassal_count >= 20
				}
				add = 25
			}
			if = {
				limit = {
					vassal_count >= 40
				}
				add = 25
			}
			# More likely if the liege is a poor steward themselves
			if = {
				limit = {
					stewardship <= 8
				}
				add = 20
			}
		}
		add = court_position_debt_considerations_value
	}
	ai_candidate_score = {
		value = 50
		add = scope:base_value
		add = court_position_candidate_score_base_value
		add = court_position_candidate_aptitude_value
		add = court_position_debt_considerations_value
	}
}
