﻿succession_crisis_start_effect = {

	# 3. Heir Location - Guarded check
	if = {
		limit = { exists = scope:crisis_heir }
		scope:crisis_heir = {
			location = { save_scope_as = heir_original_location }
		}
	}

	# 4. Find Claimants
	if = {
		limit = { exists = scope:crisis_title }
		scope:crisis_title = {
			every_claimant = {
				limit = {
					is_alive = yes
					is_imprisoned = no
					is_at_war = no
					NOT = { has_character_flag = active_succession_crisis }
					NOT = { this = scope:crisis_heir }
					OR = {
						has_trait = arrogant
						has_trait = callous
						has_trait = deceitful
						has_trait = wrathful
						has_trait = ambitious
					}
				}
				add_to_list = potential_rebels
			}
		}
	}

	random_in_list = {
		list = potential_rebels
		weight = {
			base = 1
			modifier = {
				add = 100
				max_military_strength >= 1000
			}
		}
		save_scope_as = primary_claimant
		add_to_list = active_crisis_rebels
	}

	random_in_list = {
		list = potential_rebels
		limit = { NOT = { this = scope:primary_claimant } }
		save_scope_as = secondary_rebel
		add_to_list = active_crisis_rebels
	}

	# Arrival/Journey Events Logic
	# Heir/Claimant at destination
	if = {
		limit = { 
			exists = scope:crisis_heir
			exists = scope:crisis_destination
			scope:crisis_heir = { location = scope:crisis_destination } 
		}
		scope:crisis_heir = { trigger_event = { id = succession_crisis_arrival.0001 days = 1 } }
	}

	if = {
		limit = { 
			exists = scope:primary_claimant
			exists = scope:crisis_destination
			scope:primary_claimant = { location = scope:crisis_destination } 
		}
		scope:primary_claimant = { trigger_event = { id = succession_crisis_arrival.0001 days = 1 } }
	}

	# Heir not at destination
	if = {
		limit = { 
			exists = scope:crisis_heir
			NOT = { scope:crisis_heir = { location = scope:crisis_destination } } 
		}
		scope:crisis_heir = { trigger_event = { id = succession_crisis_heir_event.0001 days = 1 } }
	}

	# Other rebels not at destination
	every_in_list = {
		list = active_crisis_rebels
		limit = { exists = location NOT = { location = scope:crisis_destination } }
		trigger_event = { id = succession_crisis_claimant_event.0001 days = 1 }
	}
}