﻿visit_local_settlement_decision = {
	picture = { reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds" }
	desc = visit_local_settlement_decision_desc
	selection_tooltip = visit_local_settlement_decision_tooltip
	sort_order = 200
	decision_group_type = adventurer_minor

	#The cooldown is set separately, if you only entered and left you shouldn't get punished for it

	is_shown = {
		#DLC check.
		has_ep3_dlc_trigger = yes
		has_government = landless_adventurer_government
	}

	is_valid_showing_failures_only = {
		is_alive = yes
		is_available_adult = yes
		has_contagious_deadly_disease_trigger = no
		root.location = {
			has_holding = yes
			is_occupied = no
			is_raided = no	
		}
		custom_description = {
			text = "visit_local_settlement_decision_sieged"
			subject = root
			root.location = {
				NOT = {
					any_army_in_location = {
						is_army_in_siege = yes
					}
				}
			}
		}
		custom_description = {
			text = "decision_already_visiting_local_settlement"
			subject = root
			NOT = { has_variable = ep3_laamp_decision_1000_is_visiting }
		}
	}

	widget = {
		gui = "vls_decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "SELECT_ACTION"
		show_from_start = yes

		item = { # Visit Local Settlement
			value = vls_decision
			is_shown = {
				always = yes
			}
			is_valid = {
				always = yes
			}
			is_default = yes
			localization = visit_local_settlement_decision
			current_description = visit_local_settlement_decision_desc
			icon = "gfx/interface/icons/travel/icon_visit_settlement.dds"
			ai_chance = { value = 100 }
		}

		item = { # Visit Local Settlement Slot 1
			value = vls_decision_slot_1
			is_shown = {
				vls_decision_slot_1_is_shown_trigger = yes
			}
			is_valid = {
				vls_decision_slot_1_is_valid_trigger = yes
			}
			localization = vls_decision_slot_1
			current_description = vls_decision_slot_1_desc
			icon = "gfx/interface/icons/decisions/vls_decision_slot_1.dds"
			ai_chance = {
				value = vls_decision_slot_1_ai_chance_value
				if = {
					limit = { has_character_flag = vls_decision_slot_1 }
					multiply = 0
				}
			}
		}

		item = { # Visit Local Settlement Slot 2
			value = vls_decision_slot_2
			is_shown = {
				vls_decision_slot_2_is_shown_trigger = yes
			}
			is_valid = {
				vls_decision_slot_2_is_valid_trigger = yes
			}
			localization = vls_decision_slot_2
			current_description = vls_decision_slot_2_desc
			icon = "gfx/interface/icons/decisions/vls_decision_slot_2.dds"
			ai_chance = {
				value = vls_decision_slot_2_ai_chance_value
				if = {
					limit = { has_character_flag = vls_decision_slot_2 }
					multiply = 0
				}
			}
		}
	}

	effect = {
		if = {
			limit = { scope:vls_decision = yes }

			vls_debug_log_effect = { MSG = vls_debug_msg_visiting_holding }

			if = {
				limit = { vls_decision_slot_1_is_shown_trigger = yes }
				vls_decision_slot_1_prepare_effect = yes
			}
			if = {
				limit = { vls_decision_slot_2_is_shown_trigger = yes }
				vls_decision_slot_2_prepare_effect = yes
			}

			if = {
				limit = {
					root.location = {
						OR = {
							has_holding = no
							has_holding_type = tribal_holding
							has_holding_type = nomad_holding
							has_holding_type = herder_holding
						}
					}
				}
				#The base tooltip
				if = {
					limit = { vls_decision_slot_1_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_1_vanilla_tribal_holding_tt_overwrite
				}
				else_if = {
					limit = { vls_decision_slot_2_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_2_vanilla_tribal_holding_tt_overwrite
				}
				else = {
					custom_tooltip = visit_local_settlement_tribal_holding_decision_tt
				}
			}
			else_if = {
				limit = {
					root.location = {
						OR = {
							has_holding_type = church_holding
							has_holding_type = temple_citadel_holding
						}
					}
				}
				#Add on church holding-specific effects
				if = {
					limit = { vls_decision_slot_1_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_1_vanilla_church_holding_tt_overwrite
				}
				else_if = {
					limit = { vls_decision_slot_2_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_2_vanilla_church_holding_tt_overwrite
				}
				else = {
					custom_tooltip = visit_local_settlement_church_holding_decision_tt
				}
			}
			else_if = {
				limit = {
					root.location = { has_holding_type = castle_holding }
				}
				#Add on castle holding-specific effects
				if = {
					limit = { vls_decision_slot_1_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_1_vanilla_castle_holding_tt_overwrite
				}
				else_if = {
					limit = { vls_decision_slot_2_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_2_vanilla_castle_holding_tt_overwrite
				}
				else = {
					custom_tooltip = visit_local_settlement_castle_holding_decision_tt
				}
			}
			else_if = {
				limit = {
					root.location = { has_holding_type = city_holding }
				}
				#Add on castle holding-specific effects
				if = {
					limit = { vls_decision_slot_1_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_1_vanilla_city_holding_tt_overwrite
				}
				else_if = {
					limit = { vls_decision_slot_2_is_shown_trigger = yes }
					custom_tooltip = vls_decision_slot_2_vanilla_city_holding_tt_overwrite
				}
				else = {
					custom_tooltip = visit_local_settlement_city_holding_decision_tt
				}
			}
			temporarily_lock_visit_settlement_effect = yes
			trigger_event =  ep3_laamp_decision_event.1000

			# Properly cleanup after ep3_laamp_decision_event.1000
			# See https://forum.paradoxplaza.com/forum/threads/ai-landless-adventurers-are-not-visiting-settlements-if-you-switch-to-any-of-them-you-cant-as-well.1712826/
			trigger_event = {
				id = vls_decision_events.0001
				delayed = yes
			}
		}
		else_if = {
			limit = { scope:vls_decision_slot_1 = yes }
			vls_decision_slot_1_main_effect = yes
			add_character_flag = { flag = vls_decision_slot_1 years = 2 }
		}
		else_if = {
			limit = { scope:vls_decision_slot_2 = yes }
			vls_decision_slot_2_main_effect = yes
			add_character_flag = { flag = vls_decision_slot_2 years = 2 }
		}

		close_view = {
			view = decisions
			player = root
		}
	}
	
	# It's now disabled for AI in vanilla, why?
	ai_check_interval = 24

	ai_potential = {
		government_has_flag = government_is_landless_adventurer
		is_available = yes
	}
	
	ai_will_do = {
		base = 100
	}
}
