﻿court_physician_court_position = {
	sort_order = 399
	max_available_positions = 1
	skill = learning
	minimum_rank = barony				  

	court_position_asset = {
		trigger = {
			government_has_flag = government_is_landless_adventurer
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/study_physician.dds"
		localization_key = court_physician_landless_adventurer
	}

	court_position_asset = {
		trigger = {
			OR = {
				government_has_flag = government_is_tribal
				government_has_flag = government_is_nomadic
			}
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/fp4_physician_tribal.dds"
	}

	court_position_asset = {
		trigger = {
			is_independent_ruler = yes
			highest_held_title_tier >= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/tgp_physician_asia.dds"
		localization_key = court_physician_celestial_imperial
	}

	court_position_asset = {
		trigger = {
			is_independent_ruler = no
			highest_held_title_tier <= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/tgp_physician_asia.dds"
		localization_key = court_physician_celestial
	}

	court_position_asset = {
		trigger = {
			exists = culture
			culture_has_east_asian_heritage_pillar_trigger = yes
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/tgp_physician_asia.dds"
	}

	court_position_asset = {
		trigger = {
			exists = culture
			culture_has_mena_heritage_pillar_trigger = yes
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/fp4_study_physician_mena.dds"
	}

	court_position_asset = {
		trigger = {
			exists = culture
			culture_has_south_asian_heritage_pillar_trigger = yes
		}
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/fp4_study_physician_indian.dds"
	}

	court_position_asset = {
		animation = physician
		background = "gfx/interface/illustrations/event_scenes/study_physician.dds"
	}

	opinion = {
		value = regular_court_position_opinion
	}

	# 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 = 1
		# Skill
		add = {
			value = learning
			multiply = 1.75
			max = 50
			desc = court_position_skill_learning
		}
		# Physician
		if = {
			limit = { has_trait = lifestyle_physician }
			if = {
				limit = {
					has_trait_xp = { trait = lifestyle_physician value >= 100 }
				}
				add = {
					value = 45
					desc = court_position_physician_3_trait
				}
			}
			else_if = {
				limit = {
					has_trait_xp = { trait = lifestyle_physician value >= 50 }
				}
				add = {
					value = 30
					desc = court_position_physician_2_trait
				}
			}
			else = {
				add = {
					value = 15
					desc = court_position_physician_1_trait
				}
			}
		}
		# Mystic
		if = {
			limit = { has_trait = lifestyle_mystic }
			if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_mystic
						value >= 100
					}
				}
				add = {
					value = 20
					desc = court_position_mystic_3_trait
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_mystic
						value >= 50
					}
				}
				add = {
					value = 10
					desc = court_position_mystic_2_trait
				}
			}
			else = {
				add = {
					value = 5
					desc = court_position_mystic_1_trait
				}
			}
		}
		# Herbalist
		if = {
			limit = { has_trait = lifestyle_herbalist }
			add = {
				value = 15
				desc = court_position_herbalist_trait
			}
		}
		# Education
		if = {
			limit = { has_trait = education_learning }
			add = {
				if = {
					limit = { has_trait = education_learning_2 }
					add = 8
				}
				else_if = {
					limit = { has_trait = education_learning_3 }
					add = 12
				}
				else_if = {
					limit = { has_trait = education_learning_4 }
					add = 16
				}
				else_if = {
					limit = { has_trait = education_learning_5 }
					add = 20
				}
				else = {
					add = 4
				}
				desc = education_learning
			}
		}
		if = {
			limit = {
				has_trait = blind
			}
			add = {
				value = -50
				desc = court_position_blind_trait
			}
		}
		if = {
			limit = {
				any_character_artifact = {
					has_artifact_modifier = artifact_physician_aptitude_1_modifier
				}
			}
			add = 20
		}
		# domiciles
		if = {
			limit = {
				exists = employer.domicile
			}
			# Camp has different way
			if = {
				limit = {
					employer.domicile ?= { has_domicile_parameter = camp_improved_court_physician_aptitude }
				}
				add = {
					value = camp_improved_court_physician_aptitude_value
					desc = camp_improved_court_physician_aptitude_desc
				}
			}
			# All others are level-scaled
			if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_1 }
				}
				add = {
					value = estate_increase_physician_aptitude_1_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
			else_if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_2 }
				}
				add = {
					value = estate_increase_physician_aptitude_2_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
			else_if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_3 }
				}
				add = {
					value = estate_increase_physician_aptitude_3_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
			else_if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_4 }
				}
				add = {
					value = estate_increase_physician_aptitude_4_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
			else_if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_5 }
				}
				add = {
					value = estate_increase_physician_aptitude_5_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
			else_if = {
				limit = {
					liege.domicile ?= { has_domicile_parameter = estate_increase_physician_aptitude_6 }
				}
				add = {
					value = estate_increase_physician_aptitude_6_value
					desc = estate_increase_physician_aptitude_desc
				}
			}
		}

		# general values
		# Bonus from court.8311
		if = {
			limit = { var:bonus_aptitude_role ?= flag:court_physician }
			add = {
				value = cp_bonus_aptitude_value
				desc = cp_bonus_aptitude
			}
		}

		add = court_position_aptitude_low_penalty_value
		add = general_aptitude_bonus
	}

	is_shown = {
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_barony
			}
			always = no
		}
	}

	# Is this an available position for this court? (root is court owner)
	valid_position = { }

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

	valid_character = {
		valid_camp_officer_trigger = {
			OFFICER = court_physician
		}
	}

	revoke_cost = { # root is the liege, no other scopes are passed here!
		prestige =  {
			value = major_court_position_prestige_revoke_cost
			if = {
				limit = { free_court_position_revoke_trigger = { POS = court_physician } }
				multiply = 0
			}
			#Lowering for LAAMPS, to match Camp Officer revoke cost
			if = {
				limit = {
					exists = this
					government_has_flag = government_is_landless_adventurer
				}
				value = minor_court_position_prestige_revoke_cost
			}
		}
	}

	salary = {
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = court_physician_total_salary_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = court_physician_total_salary_value
			}
		}
		round = no
	}

	received_salary = {
		gold = {
			value = court_physician_total_salary_value
		}
		round = no
	}

	is_powerful_agent = yes

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			epidemic_resistance = 1
		}
		poor = {
			epidemic_resistance = 3
		}
		average = {
			epidemic_resistance = 5
		}
		good = {
			epidemic_resistance = 7
		}
		excellent = {
			epidemic_resistance = 10
		}
	}

	scaling_employer_court_modifiers = {
		terrible = {
			health = 0.01
		}
		poor = {
			health = 0.03
		}
		average = {
			health = 0.05
		}
		good = {
			health = 0.07
		}
		excellent = {
			health = 0.1
		}
	}

	custom_employer_modifier_description = court_physician_employer_custom_effect_description

	modifier = {
		health = 0.1
	}

	#custom_employee_modifier_description = court_physician_employee_custom_effect_description

	on_court_position_received = {
		court_physician_title_accepted_effect = yes
	}
	on_court_position_revoked = {
		court_physician_title_revoked_effect = yes
	}
	on_court_position_invalidated = {
		court_physician_title_invalidated_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = court_physician_court_position
		}
	}

	search_for_courtier = {
		send_interface_toast = {
			type = event_toast_effect_neutral
			title = hire_physician_decision
			custom_tooltip = hire_physician_decision_effect_tooltip
		}
		hidden_effect = {
			add_character_flag = {
				flag = health_3001_hire_physician_decision_text
				days = 20
			}
		}

		trigger_event = {
			id = health.3001
			days = 14
		}
	}

	# Scripted value to determine whether an AI will hire/fire a position or not. Hires over 0, fires under -50. Look in _court_positions.info for more extensive documentation!
	ai_position_score = {
		value = 150

		if = {
			limit = {
				scope:liege = {
					any_held_county = {
						has_province_with_epidemic = { intensity = minor }
					}
				}
			}
			add = 50
		}
		if = {
			limit = {
				scope:liege = {
					any_held_county = {
						has_province_with_epidemic = { intensity = major }
					}
				}
			}
			add = 100
		}
		if = {
			limit = {
				scope:liege = {
					any_held_county = {
						has_province_with_epidemic = { intensity = apocalyptic }
					}
				}
			}
			add = 150
		}
	}
	ai_candidate_score = {
        value = 150
        # Always have this position if you can, regardless of monetary situation
        add = court_position_candidate_score_base_value
        add = court_position_candidate_aptitude_value

		# No debt considerations for Physicians, they are too important
        # AI is less likely to fire the court physician, unless they have a better candidate.
        if = {
            limit = {
                exists = scope:firing_court_position
            }
            add = 200
            scope:employee = {
                # Does the liege have a better candidate that they should be hiring instead?
                if = {
                    limit = {
                        scope:highest_available_aptitude > scope:employee_aptitude
                    }
                    add = -150
                }
            }
        }

        add = adjust_court_position_score_for_unity

		if = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = court_physician }
			}
			add = 1000
		}
    }
}

travel_leader_court_position = {
	sort_order = 375
	max_available_positions = 1
	is_travel_related = yes
	skill = stewardship

	court_position_asset = {
		trigger = {
			is_independent_ruler = yes
			highest_held_title_tier >= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = holding_staff
		background = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
		localization_key = travel_leader_celestial_imperial
	}

	court_position_asset = {
		trigger = {
			is_independent_ruler = no
			highest_held_title_tier <= tier_empire
			government_has_flag = government_is_celestial
		}
		animation = holding_staff
		background = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
		localization_key = travel_leader_celestial
	}

	court_position_asset = {
		animation = holding_staff
		background = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
	}

	opinion = {
		value = regular_court_position_opinion
	}

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

	minimum_rank = barony				  
	# How good is this character in this position? root scope is the holder of the court position
	aptitude = {
		value = 1
		add = {
			value = learning
			multiply = 1
			max = 50
			desc = court_position_skill_learning
		}
		add = {
			value = stewardship
			multiply = 1.3
			max = 50
			desc = court_position_skill_stewardship
		}
		if = {
			limit = {
				num_of_known_languages >= 2
			}
			add = {
				value = num_of_known_languages
				subtract = 1
				multiply = 5
				max = 50
				desc = court_position_languages
			}
		}

		# SPEED
		add = {
			value = travel_leader_speed
			multiply = 1.8
			subtract = 10
			min = 0
			desc = court_position_speed
		}

		# SAFETY
		add = {
			value = travel_leader_safety
			multiply = 1.8
			subtract = 10
			min = 0
			desc = court_position_safety
		}

		# POSITIVES
		if = {
			limit = {
				has_trait = adventurer
			}
			add = {
				value = 10
				desc = court_position_adventurer_trait
			}
		}
		if = {
			limit = {
				has_trait = brave
			}
			add = {
				value = 5
				desc = court_position_brave_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_herbalist
			}
			add = {
				value = 5
				desc = court_position_herbalist_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_hunter
			}
			add = {
				value = 5
				desc = court_position_hunter_1_trait
			}
		}
		if = {
			limit = {
				has_trait = diligent
			}
			add = {
				value = 5
				desc = court_position_diligent_trait
			}
		}
		if = {
			limit = {
				has_trait = flexible_leader
			}
			add = {
				value = 10
				desc = court_position_flexible_leader_trait
			}
		}
		if = {
			limit = {
				has_trait = forest_fighter
			}
			add = {
				value = 10
				desc = court_position_forest_fighter_trait
			}
		}
		if = {
			limit = {
				has_trait = open_terrain_expert
			}
			add = {
				value = 10
				desc = court_position_open_terrain_expert_trait
			}
		}
		if = {
			limit = {
				has_trait = rough_terrain_expert
			}
			add = {
				value = 10
				desc = court_position_rough_terrain_expert_trait
			}
		}
		if = {
			limit = {
				has_trait = desert_warrior
			}
			add = {
				value = 10
				desc = court_position_desert_warrior_trait
			}
		}
		if = {
			limit = {
				has_trait = jungle_stalker
			}
			add = {
				value = 10
				desc = court_position_jungle_stalker_trait
			}
		}
		if = {
			limit = {
				has_trait = winter_soldier
			}
			add = {
				value = 10
				desc = court_position_winter_soldier_trait
			}
		}
		if = {
			limit = {
				has_trait = administrator
			}
			add = {
				value = 5
				desc = court_position_administrator_trait
			}
		}
		if = {
			limit = {
				has_trait = erudite
			}
			add = {
				value = 5
				desc = court_position_erudite_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_physician
			}
			add = {
				value = 5
				desc = court_position_physician_1_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_traveler
			}
			if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value >= 75
					}
				}
				add = {
					value = 40
					desc = court_position_traveler_trait_experienced
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_traveler
						track = danger
						value >= 75
					}
				}
				add = {
					value = 40
					desc = court_position_traveler_trait_experienced_danger
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_traveler
						track = travel
						value >= 50
					}
				}
				add = {
					value = 30
					desc = court_position_traveler_trait_experienced
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = lifestyle_traveler
						track = danger
						value >= 50
					}
				}
				add = {
					value = 30
					desc = court_position_traveler_trait_experienced_danger
				}
			}
			else = {
				add = {
					value = 20
					desc = court_position_traveler_trait
				}
			}
		}
		if = {
			limit = {
				has_character_modifier = ep2_beastmaster_modifier
			}
			add = {
				value = 30
				desc = court_position_beastmaster_modifier
			}
		}

		if = {
			limit = {
				has_perk = travel_companion_perk
			}
			add = {
				value = 15
				desc = court_position_travel_companion_modifier
			}
		}
		if = {
			limit = {
				liege ?= { has_perk = travel_companion_perk }
			}
			add = {
				value = 15
				desc = court_position_travel_companion_liege_modifier
			}
		}

		# NEGATIVES
		if = {
			limit = {
				has_trait = craven
			}
			add = {
				value = -20
				desc = court_position_craven_trait
			}
		}
		if = {
			limit = {
				has_trait = lazy
			}
			add = {
				value = -10
				desc = court_position_lazy_trait
			}
		}
		if = {
			limit = {
				has_trait = clubfooted
			}
			add = {
				value = -30
				desc = court_position_clubfooted_trait
			}
		}
		if = {
			limit = {
				has_trait = blind
			}
			add = {
				value = -50
				desc = court_position_blind_trait
			}
		}
		if = {
			limit = {
				has_trait = incapable
			}
			multiply = {
				value = 0
				desc = court_position_incapable_trait
			}
		}
		if = {
			limit = {
				has_trait = infirm
			}
			add = {
				value = -50
				desc = court_position_infirm_trait
			}
		}
		if = {
			limit = {
				has_trait = maimed
			}
			add = {
				value = -30
				desc = court_position_maimed_trait
			}
		}
		if = {
			limit = {
				has_trait = lifestyle_reveler
			}
			add = {
				value = -5
				desc = court_position_reveler_1_trait
			}
		}

		# Bonus from court.8311
		if = {
			limit = { var:bonus_aptitude_role ?= flag:travel_leader }
			add = {
				value = cp_bonus_aptitude_value
				desc = cp_bonus_aptitude
			}
		}
		# Japan
		if = {
			limit = {
				liege.house ?= { has_house_aspiration_parameter = improved_stewardship_court_position_efficiency }
			}
			add = {
				value = cp_bonus_aptitude_value
				desc = improved_stewardship_court_position_efficiency_desc
			}
		}

		add = court_position_aptitude_high_penalty_value
		add = general_aptitude_bonus
		min = 0
	}

	is_shown = {
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_barony
			}
			always = no
		}
	}

	# Is this an available position for this court? (root is court owner)
	valid_position = { }

	is_shown_character = {
		scope:employee = {
			is_clergy = no
			bannable_serving_diarch_trigger = no
			NOT = { has_variable = gone_adventuring }
			court_position_employee_shown_trigger = yes
		}
	}

	valid_character = {
		valid_camp_officer_trigger = {
			OFFICER = travel_leader
		}
	}

	salary = {
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = travel_leader_total_salary_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = travel_leader_total_salary_value
			}
		}
		round = no
	}

	received_salary = {
		gold = {
			value = travel_leader_total_salary_value
		}
		round = no
	}

	revoke_cost = { # root is the liege, no other scopes are passed here!
		prestige = {
			value = minor_court_position_prestige_revoke_cost
			if = {
				limit = { free_court_position_revoke_trigger = { POS = travel_leader } }
				multiply = 0
			}
		}
	}

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints)
	scaling_employer_modifiers = {
		terrible = {
			monthly_wanderer_lifestyle_xp_gain_mult = 0.025
		}
		poor = {
			monthly_wanderer_lifestyle_xp_gain_mult = 0.05
		}
		average = {
			monthly_wanderer_lifestyle_xp_gain_mult = 0.075
		}
		good = {
			monthly_wanderer_lifestyle_xp_gain_mult = 0.15
		}
		excellent = {
			monthly_wanderer_lifestyle_xp_gain_mult = 0.25
		}
	}

	custom_employer_modifier_description = travel_leader_court_position_custom_desc

	modifier = {
		diplomacy = 1
		health = 0.1
	}

	on_court_position_received = {
		court_travel_leader_title_accepted_effect = yes
	}
	on_court_position_revoked = {
		court_travel_leader_title_revoked_effect = yes
	}
	on_court_position_invalidated = {
		court_travel_leader_title_invalidated_effect = yes
	}
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = travel_leader_court_position
		}
	}

	search_for_courtier = {
		send_interface_toast = {
			type = event_toast_effect_neutral
			title = hire_travel_leader_decision
			custom_tooltip = hire_travel_leader_decision_tooltip
		}

		trigger_event = {
			id = travel_events.1010
			days = 14
		}
	}

	# Scripted value to determine whether an AI will hire/fire a position or not. Hires over 0, fires under -50. Look in _court_positions.info for more extensive documentation!
	ai_position_score = {
		value = 150
	}
	ai_candidate_score = {
        value = 150
    	# Always have this position if you can, regardless of monetary situation
    	add = court_position_candidate_score_base_value
    	add = court_position_candidate_aptitude_value

		# No debt considerations for Travel Leaders, they are too important

        if = {
            limit = {
                exists = scope:firing_court_position
            }
            add = 200
            scope:employee = {
                # Does the liege have a better candidate that they should be hiring instead?
                if = {
                    limit = {
                        scope:highest_available_aptitude > scope:employee_aptitude
                    }
                    add = -150
                }
            }
        }

        if = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = travel_leader }
			}
			add = 1000
		}
    }
}