﻿ttd_check_residence_and_save_as_temporary_scope_trigger = {
	$CHARACTER$ = {
		OR = { # Get characters's permanent location if possible
			AND = {
				exists = capital_province
				capital_province = { save_temporary_scope_as = $SCOPE_NAME$ }
			}
			AND = {
				is_courtier = yes
				exists = liege
				liege = {
					exists = capital_province
					capital_province = { save_temporary_scope_as = $SCOPE_NAME$ }
				}
			}
			AND = {
				is_pool_guest = yes
				exists = host
				host = {
					exists = capital_province
					capital_province = { save_temporary_scope_as = $SCOPE_NAME$ }
				}
			}
			AND = { # Fallback for mercenaries and wanderers, any else that don't have a captial province
				NOT = { exists = capital_province }
				is_courtier = no
				is_pool_guest = no
				exists = location # Without this I get errors for the next line when called by the seduction schemes' ai_will_do modifiers
				location = { save_temporary_scope_as = $SCOPE_NAME$ }
			}
		}
	}
}

ttd_potentially_ignore_diplomatic_range_trigger = {
	scope:actor = { has_variable = ttd_far_off_host }
}

ttd_use_diplomatic_range_with_recipient_trigger = {
	NOR = {
		scope:actor.var:ttd_far_off_host = scope:recipient
		scope:recipient = {
			any_liege_or_above = {
				scope:actor.var:ttd_far_off_host = this
			}
		}
		scope:recipient.host ?= { # So it also works for guests
			OR = {
				this = scope:actor.var:ttd_far_off_host
				any_liege_or_above = {
					scope:actor.var:ttd_far_off_host = this
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_forder_tirgger = {
	NOT = { has_trait = forder }
	$LOCATION$ = {
		OR = {
			is_coastal = yes
			is_riverside_province = yes
		}
	}
}

ttd_can_learn_foreign_tactic_forest_fighter_tirgger = {
	NOT = { has_trait = forest_fighter }
	$LOCATION$ = {
		OR = {
			terrain = forest
			terrain = taiga
			$HOST_CULTURE$ = {
				OR = {
					has_cultural_parameter = forest_fighter_trait_more_common
					has_cultural_parameter = can_recruit_forest_specialist
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_open_terrain_expert_tirgger = {
	NOT = { has_trait = open_terrain_expert }
	$LOCATION$ = {
		OR = {
			terrain = farmlands
			terrain = plains
			terrain = steppe
			$HOST_CULTURE$ = { has_cultural_parameter = can_recruit_open_specialist }
		}
	}
}

ttd_can_learn_foreign_tactic_rough_terrain_expert_tirgger = {
	NOT = { has_trait = rough_terrain_expert }
	$LOCATION$ = {
		OR = {
			terrain = hills
			terrain = mountains
			terrain = wetlands
			$HOST_CULTURE$ = {
				OR = {
					has_cultural_parameter = rough_terrain_expert_trait_more_common
					has_cultural_parameter = can_recruit_mountain_specialist
					has_cultural_parameter = can_recruit_hill_specialist
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_desert_warrior_tirgger = {
	NOT = { has_trait = desert_warrior }
	$LOCATION$ = {
		OR = {
			terrain = desert
			terrain = desert_mountains
			terrain = drylands
			terrain = oasis
			$HOST_CULTURE$ = {
				OR = {
					has_cultural_parameter = desert_warrior_trait_more_common
					has_cultural_parameter = can_recruit_dry_specialist
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_jungle_stalker_tirgger = {
	NOT = { has_trait = jungle_stalker }
	$LOCATION$ = {
		OR = {
			terrain = jungle
			$HOST_CULTURE$ = {
				OR = {
					has_cultural_parameter = jungle_stalker_trait_more_common
					has_cultural_parameter = can_recruit_jungle_specialist
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_winter_soldier_tirgger = {
	NOT = { has_trait = winter_soldier }
	$LOCATION$ = {
		OR = {
			has_province_modifier = winter_mild_modifier
			has_province_modifier = winter_normal_modifier
			has_province_modifier = winter_harsh_modifier
			$HOST_CULTURE$ = {
				OR = {
					has_cultural_parameter = winter_soldier_trait_more_common
					has_cultural_parameter = can_recruit_winter_specialist
				}
			}
		}
	}
}

ttd_can_learn_foreign_tactic_trigger = {
	OR = {
		ttd_can_learn_foreign_tactic_forder_tirgger = { LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_forest_fighter_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_open_terrain_expert_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_rough_terrain_expert_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_desert_warrior_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_jungle_stalker_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
		ttd_can_learn_foreign_tactic_winter_soldier_tirgger = { HOST_CULTURE = $HOST_CULTURE$ LOCATION = $LOCATION$ }
	}
}

ttd_is_busy_moving_to_new_court = {
	var:ttd_newlywed_traveling_to_court_of ?= { NOT = { this = scope:actor } }  # So new liege can still interact with them
}