﻿on_war_started = {
	on_actions = {
		LTAF_on_war_started
	}
}

LTAF_on_war_started = {
	trigger = {
		war = {
			OR = {
				using_cb = independence_faction_war
				using_cb = liberty_faction_war
				using_cb = populist_war
				using_cb = claimant_faction_war
				using_cb = depose_war
				using_cb = refused_liege_demand_war
				using_cb = independence_war
				using_cb = peasant_war
				using_cb = claim_cb
				using_cb = nation_fracturing_faction_war
			}
			scope:defender = {
				any_targeting_faction = {
					faction_is_type = loyalist_faction
				}
			}
			trigger_if = {
				limit = {
					using_cb = claim_cb
				}
				scope:defender = { is_liege_or_above_of = scope:attacker }
			}
		}
	}
	effect = {
		war = { save_scope_as = war }
		scope:defender = {
			random_targeting_faction = {
				limit = { faction_is_type = loyalist_faction }
				every_faction_member = {
					limit = {
						any_war_enemy = {
							THIS = scope:defender
							count = 0
						}
						NOT = { is_participant_in_war = scope:war }
					}
					scope:war = {
						add_defender = PREV
					}
				}
			}
		}
	}
}