﻿ttd_visit_far_off_realm = {
	category = interaction_category_diplomacy
	desc = ttd_visit_far_off_realm_desc
	icon = icon_travel_away
	common_interaction = yes
	
	ai_frequency = 0 # Never
	use_diplomatic_range = no

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOT = { has_variable = ttd_far_off_location }
		}
		scope:recipient = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOT = { in_diplomatic_range = scope:actor }
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			is_at_war = no
			custom_tooltip = {
				text = pdi_is_in_debt
				gold >= 0
			}
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				bannable_serving_diarch_trigger = no
			}
		}
	}

	on_accept = {
		scope:actor = {
			set_variable = {
				name = ttd_far_off_target
				value = scope:recipient
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_location
				value = scope:recipient.capital_province
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			start_travel_plan = {
				destination = var:ttd_far_off_location
				on_travel_planner_cancel_event = tdd_visit_far_off_realm_events.0001
				on_arrival_event = tdd_visit_far_off_realm_events.0002
				on_arrival_destinations = all_but_last
			}
		}
	}
}

ttd_visit_nearby_realm = {
	category = interaction_category_diplomacy
	desc = ttd_visit_nearby_realm_desc
	icon = icon_travel_away
	
	ai_frequency = 0 # Never
	use_diplomatic_range = yes

	auto_accept = yes

	is_shown = {
		scope:actor = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOT = { has_variable = ttd_far_off_location }
		}
		scope:recipient = {
			is_landed = yes
			highest_held_title_tier >= tier_county
			NOT = { top_liege = scope:actor.top_liege }
		}
	}
	is_valid_showing_failures_only = {
		scope:actor = {
			is_available_adult = yes
			is_at_war = no
			custom_tooltip = {
				text = pdi_is_in_debt
				gold >= 0
			}
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				bannable_serving_diarch_trigger = no
			}
		}
	}

	on_accept = {
		scope:actor = {
			add_character_flag = {
				flag = ttd_nearby_realm
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_target
				value = scope:recipient
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			set_variable = {
				name = ttd_far_off_location
				value = scope:recipient.capital_province
				years = 5 # So it will eventually go away if travel plan somehow gets cancelled
			}
			start_travel_plan = {
				destination = var:ttd_far_off_location
				on_travel_planner_cancel_event = tdd_visit_far_off_realm_events.0001
				on_arrival_event = tdd_visit_far_off_realm_events.0002
				on_arrival_destinations = all_but_last
			}
		}
	}
}

ttd_leave_realm = {
	category = interaction_category_diplomacy
	desc = ttd_leave_realm_desc
	icon = icon_travel_home
	common_interaction = yes
	
	ai_frequency = 0 # Never
	use_diplomatic_range = no

	auto_accept = yes

	is_shown = {
		scope:actor.var:ttd_far_off_host ?= scope:recipient
	}

	on_accept = {
		custom_tooltip = ttd_leave_realm.tt
		scope:actor = { trigger_event = tdd_visit_far_off_realm_events.0011 }
	}
}