﻿# A title is transferred to a new character
# root = the new holder
# scope:title = the title that changes hands
# scope:previous_holder = previous holder. Might be dead
on_title_gain = {
	on_actions = {
		ttd_on_title_gain_far_off_location
	}
}

ttd_on_title_gain_far_off_location = {
	trigger = {
		any_player = {
			var:ttd_far_off_location ?= { county = scope:title }
			var:ttd_far_off_target ?= scope:previous_holder
		}
	}
	effect = {
		every_player = {
			limit = {
				var:ttd_far_off_location ?= { county = scope:title }
				var:ttd_far_off_target ?= scope:previous_holder
			}
			if = {
				limit = { this = root }
				current_travel_plan = { cancel_travel_plan = yes } # Cancel travel plans
				ttd_cancel_far_off_realm_travel_clean_up_effect = yes
			}
			else = {
				trigger_event = tdd_visit_far_off_realm_events.0003 # Chance to change travel plans
			}
		}
	}
}

# A title is inherited by a character
# root = the new holder
# scope:title = the title that changes hands
# scope:previous_holder = previous holder. Should be dead
on_title_gain_inheritance = {
	on_actions = {
		ttd_on_title_gain_inheritance_newlywed_cancel_travel
	}
}

ttd_on_title_gain_inheritance_newlywed_cancel_travel = {
	trigger = {
		has_variable = ttd_newlywed_traveling_to_court_of
		exists = current_travel_plan
	}
	effect = {
		current_travel_plan ?= { cancel_travel_plan = yes } # Cancel travel plans
		ttd_newlywed_travel_to_hosts_court_clean_up_effect = yes
	}
}