﻿recruit_court_position_decision = {
	ai_check_interval = 60
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_recruitment.dds"
	}
	sort_order = 10
	decision_group_type = courtier

	is_shown = {
		is_landed_or_landless_administrative = yes
	}

	is_valid_showing_failures_only = {
		is_imprisoned = no
	}

	# TODO_CD_EP3: Fix cooldowns on options after code support is finished TIT-49117
	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "CHOOSE_CHARACTER_ROLE_DECISION_NEXT_STEP_BUTTON"
		show_from_start = yes

		item = { # Court Physician
			value = hire_physician_decision
			is_shown = {
				is_ruler = yes
				is_landless_adventurer = no
			}
			is_valid = {
				NOR = {
					employs_court_position = court_physician_court_position
					custom_tooltip = {
						text = recruit_court_physician_cooldown_tt
						has_character_flag = recruit_court_physician_cooldown
					}
				}
			}
			current_description = hire_physician_decision_desc
			localization = hire_physician_decision
			icon = "gfx/interface/icons/court_position_types/court_physician_court_position.dds"
			ai_chance = { value = 100 }
		} 
		item = { #Caraven Master
			value = hire_travel_leader_decision
			is_shown = {
				exists = primary_title 
				primary_title.tier >= tier_county
				is_landless_adventurer = no
			}
			is_valid = {
				NOR = {
					employs_court_position = travel_leader_court_position
					custom_tooltip = {
						text = recruit_travel_leader_cooldown_tt
						has_character_flag = recruit_travel_leader_cooldown
					}
				}
			}
			current_description = hire_travel_leader_decision_desc
			localization = hire_travel_leader_decision
			icon = "gfx/interface/icons/court_position_types/travel_leader_court_position.dds"
			ai_chance = {
				value = 100
				if = {
					limit = {
						NOR = {
							highest_held_title_tier > tier_barony
							is_landed_or_landless_administrative = yes
							gold > low_skill_court_physician_cost
							is_at_war = no
						}
					}
					multiply = 0
				}
			}
		}
		item = { # Wet Nurse 
			value = find_wet_nurse_decision
			is_shown = {
				is_landed_or_landless_administrative = yes
				has_bp2_dlc_trigger = yes
			}
			is_valid = {
				NOR = {
					employs_court_position = wet_nurse_court_position
					custom_tooltip = {
						text = recruit_wet_nurse_cooldown_tt
						has_character_flag = recruit_wet_nurse_cooldown
					}
				}
				custom_tooltip = {
					text = find_wet_nurse_decision.tt
					OR = {
						any_child = {
							is_adult = no
						}
						is_adult = no
						any_warden_hostage = {
							is_adult = no
						}
					}
				}
			}
			current_description = find_wet_nurse_decision_desc
			localization = find_wet_nurse_decision
			icon = "gfx/interface/icons/court_position_types/wet_nurse_court_position.dds"
			ai_chance = {
				value = 10
				if = {
					limit = {
						any_child = { #more willing if mother of your children is dead, too old or not healthy
							exists = mother
							mother = {
								OR = {
									is_alive = no
									age > 45
									health < 3
								}
							}
						}
					}
					add = 100
				}
				if = {
					limit = {
						NOR = {
							highest_held_title_tier > tier_barony
							NOT = {
								employs_court_position = wet_nurse_court_position
							}
							any_child = {
								age < 5
							}
						}
					}
					multiply = 0
				}
			}
		}
		item = { # Charioteer
			value = hire_charioteer_decision
			is_shown = {
				has_ep3_dlc_trigger = yes
				is_landless_adventurer = no
				culture = {
					has_cultural_parameter = hosts_chariot_races
				}
			}
			is_valid = {
				NOR = {
					employs_court_position = charioteer_court_position
					custom_tooltip = {
						text = recruit_charioteer_cooldown_tt
						has_character_flag = recruit_charioteer_cooldown
					}
				}
			}
			current_description = hire_charioteer_decision_desc
			localization = hire_charioteer_decision
			icon = "gfx/interface/icons/court_position_types/charioteer_court_position.dds"
			ai_chance = { value = 100 }
		}
		item = { # Bookmaker
			value = hire_bookmaker_decision
			is_shown = {
				has_ep3_dlc_trigger = yes
				is_landless_adventurer = no
				culture = {
					has_cultural_parameter = hosts_chariot_races
				}
			}
			is_valid = {
				NOR = {
					employs_court_position = bookmaker_court_position
					custom_tooltip = {
						text = recruit_bookmaker_cooldown_tt
						has_character_flag = recruit_bookmaker_cooldown
					}
				}
			}
			current_description = hire_bookmaker_decision_desc
			localization = hire_bookmaker_decision
			icon = "gfx/interface/icons/court_position_types/bookmaker_court_position.dds"
			ai_chance = { value = 100 }
		}
		item = { # Eunuch
			value = hire_eunuch_decision
			is_shown = {
				has_ep3_dlc_trigger = yes
				is_landless_adventurer = no
				culture = {
					has_cultural_parameter = can_appoint_chief_eunuch
				}
			}
			is_valid = {
				NOR = {
					employs_court_position = chief_eunuch_court_position
					custom_tooltip = {
						text = recruit_chief_eunuch_cooldown_tt
						has_character_flag = recruit_eunuch_cooldown
					}
				}
			}
			current_description = hire_eunuch_decision_desc
			localization = hire_eunuch_decision
			icon = "gfx/interface/icons/court_position_types/chief_eunuch_court_position.dds"
			ai_chance = { value = 100 }
		}
		item = { # Gardener
			value = recruit_gardener_decision
			is_shown = {
				culture = {
					has_cultural_parameter = can_recruit_gardeners
				}
				is_landless_adventurer = no
			}
			is_valid = {
				NOR = {
					employs_court_position = court_gardener_court_position
					custom_tooltip = {
						text = recruit_court_gardener_cooldown_tt
						has_character_flag = recruit_court_gardener_cooldown
					}
				}
			}
			current_description = recruit_gardener_decision_desc
			localization = recruit_gardener_decision
			icon = "gfx/interface/icons/court_position_types/court_gardener_court_position.dds"
			ai_chance = { value = 100 }
		}
		item = { # Linguist (Self)
			value = invite_a_linguist_self
			is_shown = {
				# Standard filter checks.
				is_playable_character = yes
				has_royal_court = yes
				has_dlc_feature = royal_court
				# Language checks.
				NOT = { has_court_language_of_culture = root.culture } # No need for linguist
				any_culture_global = { # Need somewhere to recruit linguist from
					exists = culture_head
					root.liege = { has_court_language_of_culture = prev }
				}
			}
			is_valid = {
				age >= 6
				is_alive = yes
				NOT = { exists = involved_activity }
				is_imprisoned = no
				NOT = { knows_court_language_of = root }
				custom_tooltip = {
					text = scheming_already
					NOT = { # Is not currently learning a language and doesn't know court language
						any_scheme = { scheme_type = learn_language }	
					}
				}
				custom_tooltip = {
					text = linguist_already_present
					NOT = {
						any_courtier = { # You don't already have a linguist at court
							has_character_flag = court_linguist_flag
							knows_court_language_of = root
						}
					}
				}
				NOT = {
					custom_tooltip = {
						text = recruit_linguist_self_cooldown_tt
						has_character_flag = recruit_linguist_self_cooldown
					}
				}
			}
			current_description = invite_a_linguist_desc
			localization = invite_a_linguist_self
			icon = "gfx/interface/icons/scheme_types/icon_scheme_learn_language.dds"
			ai_chance = { value = 100 }
		}
		item = { # Linguist (Liege)
			value = invite_a_linguist_liege
			is_shown = {
				# Standard filter checks.
				is_landed_or_landless_administrative = yes
				# Liege checks.
				is_independent_ruler = no
				liege = { has_royal_court = yes has_dlc_feature = royal_court }
				# Language checks.
				trigger_if = {
					limit = { has_royal_court = yes }
					NOT = { has_same_court_language = liege } # Can use other decision in this case
				}
				NOR = {
					liege = { has_court_language_of_culture = root.culture } # No need to learn your own culture's language
					AND = {
						knows_language_of_culture = root.liege.culture 
						trigger_if = {
							limit = {
								any_child = {
									count > 0
								}
							}
							any_child = {
								count > 0
								knows_language_of_culture = root.liege.culture 
							}
						}
					}
				}
				any_culture_global = { # Need somewhere to recruit linguist from
					exists = culture_head
					root.liege = { has_court_language_of_culture = prev }
				}
			}
			is_valid = {
				age >= 6
				is_alive = yes
				NOT = { exists = involved_activity }
				is_imprisoned = no
				custom_tooltip = {
					text = scheming_already
					NOT = { # Is not currently learning a language and doesn't know court language
						any_scheme = { scheme_type = learn_language }
					}
				}
				custom_tooltip = {
					text = linguist_already_present
					NOT = {
						any_courtier = { # You don't already have a linguist at court
							has_character_flag = court_linguist_flag
							knows_court_language_of = root.liege
						}
					}
				}
				NOT = {
					custom_tooltip = {
						text = recruit_linguist_liege_cooldown_tt
						has_character_flag = recruit_linguist_liege_cooldown
					}
				}
			}
			current_description = invite_a_linguist_desc
			localization = invite_a_linguist_liege
			icon = "gfx/interface/icons/scheme_types/icon_scheme_learn_language.dds"
			ai_chance = { value = 100 }
		}
	}

	effect = {
		custom_tooltip = recruit_court_position_decision_tt
		hidden_effect = {
			custom_tooltip = recruit_court_position_decision_tooltip
			if = { # Court Physician
				limit = { scope:hire_physician_decision = yes }
				hidden_effect = {
					add_character_flag = {
						flag = health_3001_hire_physician_decision_text
						days = 20
					}
				}
				set_variable = {
					name = recruit_court_physician_cooldown
					years = 1
				}
				trigger_event = {
					id = health.3001
					days = { 7 14 }
				}
			}
			else_if = { # Travel Leader
				limit = { scope:hire_travel_leader_decision = yes }
				add_character_flag = {
					flag = recruit_travel_leader_cooldown
					years = 1
				}
				trigger_event = {
					id = travel_events.1010
					days = { 7 14 }
				}
			}
			else_if = { # Wet Nurse
				limit = { scope:find_wet_nurse_decision = yes }
				add_character_flag = {
					flag = recruit_wet_nurse_cooldown
					years = 1
				}
				trigger_event = {
					id = bp2_decision.0001
					days = { 7 14 }
				}
			}
			else_if = { # Charioteer
				limit = { scope:hire_charioteer_decision = yes }
				add_character_flag = {
					flag = recruit_charioteer_cooldown
					years = 1
				}
				trigger_event = {
					id = ep3_decisions_event.1000
					days = { 7 14 }
				}
			}
			else_if = {
				limit = { scope:hire_bookmaker_decision = yes }
				add_character_flag = {
					flag = recruit_bookmaker_cooldown
					years = 1
				}
				trigger_event = {
					id = ep3_decisions_event.1010
				}
			}
			else_if = { # Eunuch
				limit = { scope:hire_eunuch_decision = yes }
				add_character_flag = {
					flag = recruit_eunuch_cooldown
					years = 1
				}
				trigger_event = {
					id = ep3_decisions_event.5010
					days = { 7 14 }
				}
			}
			else_if = { # Court Gardener 
				limit = { scope:recruit_gardener_decision = yes }
				hidden_effect = {
					if = {
						limit = {
							exists = root.capital_province
							any_pool_character = {
								province = root.capital_province
								stewardship >= medium_skill_rating
								culture = root.culture
								opinion = { # Just to make sure you don't pull in rivals or similar
									value >= -30
									target = root
								}
							}
						}
						random_pool_character = {
							province = root.capital_province
							limit = {
								stewardship >= medium_skill_rating
								culture = root.culture
				                is_ai = yes
								opinion = { # Just to make sure you don't pull in rivals or similar
									value >= -30
									target = root
								}
							}
							if = {
								limit = {
									NOT = {
										has_trait = lifestyle_gardener
									}
								}
								add_trait = lifestyle_gardener
							}
							save_scope_as = new_commander # Ignore the name, it's to save on localisation
						}
					}
					else = {
						create_character = {
							employer = root
							template = pool_repopulate_stewardship
							faith = root.faith
							culture = root.culture
							save_scope_as = new_commander
						}
					}
					if = {
						limit = {
							exists = scope:new_commander
						}
						scope:new_commander = {
							force_character_skill_recalculation = yes
							add_character_flag = {
								flag = blocked_from_leaving
								years = 25
							}
							if = {
								limit = {
									NOT = {
										has_trait = lifestyle_gardener
									}
								}
								add_trait = lifestyle_gardener
							}
						}
						if = {
							limit = {
								scope:new_commander = {
									NOT = {
										is_courtier_of = root
									}
								}
							}
							add_courtier = scope:new_commander
						}
						send_interface_toast = {
							type = event_toast_effect_neutral
							title = gardener_recruited.t
							left_icon = scope:new_commander
							custom_tooltip = commander_recruited.desc
						}
					}
				}
				add_character_flag = {
					flag = recruit_court_gardener_cooldown
					years = 1
				}
			}
			else_if = {
				limit = { scope:invite_a_linguist_self = yes }
				save_scope_as = target_court_language
				custom_tooltip = {
					text = invite_a_linguist_tt_self
					trigger_event = ep1_decision.0201
				}
				if = {
					limit = {
						NOT = { knows_court_language_of = root.liege }
						any_scheme = { is_hostile = no }
					}
					custom_description_no_bullet = { text = learn_language_will_cancel_ongoing_schemes_tt }
				}
				add_character_flag = {
					flag = recruit_linguist_self_cooldown
					years = 1
				}
			}
			else_if = {
				limit = { scope:invite_a_linguist_liege = yes }
				liege = { save_scope_as = target_court_language }
				save_scope_value_as = { name = language_scheme_type value = flag:liege }
				custom_tooltip = {
					text = invite_a_linguist_tt_liege
					trigger_event = ep1_decision.0201
				}
				if = {
					limit = {
						NOT = { knows_court_language_of = root.liege }
						any_scheme = { is_hostile = no }
					}
					custom_description_no_bullet = { text = learn_language_will_cancel_ongoing_schemes_tt }
				}
				add_character_flag = {
					flag = recruit_linguist_liege_cooldown
					years = 1
				}
			}
		}
	}
	
	ai_potential = {
	# TODO_CD_EP3: TIT-55684 make AI use this
		always = no # Only players can do this. AI vassals go through the normal court events/hold court activity.
	}
}