# 1 nothing
# 2 germans
# 3 Armia Ludowa
# 4 AK
# 5 NSZ
# 6 NZR-ONR

GGN_init_states = {
	add_to_temp_array = { temp_states = 10 }
	add_to_temp_array = { temp_states = 1381 }
	add_to_temp_array = { temp_states = 1380 }
	add_to_temp_array = { temp_states = 2261 }
	add_to_temp_array = { temp_states = 1383 }
	add_to_temp_array = { temp_states = 90 }
	add_to_temp_array = { temp_states = 1382 }
	add_to_temp_array = { temp_states = 1384 }
	add_to_temp_array = { temp_states = 92 }
	add_to_temp_array = { temp_states = 1390 }
	add_to_temp_array = { temp_states = 1389 }
	add_to_temp_array = { temp_states = 1385 }
	add_to_temp_array = { temp_states = 1386 }
	add_to_temp_array = { temp_states = 88 }
	add_to_temp_array = { temp_states = 1387 }
	add_to_temp_array = { temp_states = 1391 }
	add_to_temp_array = { temp_states = 1392 }
	add_to_temp_array = { temp_states = 1393 }
	add_to_temp_array = { temp_states = 91 }
	add_to_temp_array = { temp_states = 1394 }
	add_to_temp_array = { temp_states = 1388 }
	add_to_temp_array = { temp_states = 89 }
	for_each_scope_loop = {
		array = temp_states
		set_variable = { GGN_German_control_state = 10 }
		set_variable = { GGN_AL_control_state = 0 }
		set_variable = { GGN_AK_control_state = 0 }
		set_variable = { GGN_NSZ_control_state = 0 }
		set_variable = { GGN_NSZONR_control_state = 0 }
		set_variable = { is_starting = 1 }
	}
}
GGN_find_major_factions = {
	every_owned_state = {
		limit = {
			check_variable = { is_starting = 1 }
		}
		set_temp_variable = { i = 0 }
		clear_temp_array = GGN_major_finder
		add_to_temp_array = { GGN_major_finder = GGN_German_control_state }
		add_to_temp_array = { GGN_major_finder = GGN_AL_control_state }
		add_to_temp_array = { GGN_major_finder = GGN_AK_control_state }
		add_to_temp_array = { GGN_major_finder = GGN_NSZ_control_state }
		add_to_temp_array = { GGN_major_finder = GGN_NSZONR_control_state }
		find_highest_in_array = {
			array = GGN_major_finder
			index = i
		}
		if = {
			limit = {
				check_variable = { i = 0 }
			}
			set_variable = { GGN_majority = 2 }
		}
		else_if = {
			limit = {
				check_variable = { i = 1 }
			}
			set_variable = { GGN_majority = 3 }
		}
		else_if = {
			limit = {
				check_variable = { i = 2 }
			}
			set_variable = { GGN_majority = 4 }
		}
		else_if = {
			limit = {
				check_variable = { i = 3 }
			}
			set_variable = { GGN_majority = 5 }
		}
		else_if = {
			limit = {
				check_variable = { i = 4 }
			}
			set_variable = { GGN_majority = 6 }
		}
	}
}

GGN_count_states = {
	set_variable = { GGN_German_control = 0 }
	set_variable = { GGN_AL_control = 0 }
	set_variable = { GGN_AK_control = 0 }
	set_variable = { GGN_NSZ_control = 0 }
	set_variable = { GGN_NSZONR_control = 0 }
	every_owned_state = {
		limit = {
			check_variable = { is_starting = 1 }
		}
		if = {
			limit = { 
				check_variable = { GGN_majority = 2 }
			}
			add_to_variable = { PREV.GGN_German_control = 1 }
		}
		else_if = {
			limit = { 
				check_variable = { GGN_majority = 3 }
			}
			add_to_variable = { PREV.GGN_AL_control = 1 }
		}
		else_if = {
			limit = { 
				check_variable = { GGN_majority = 4 }
			}
			add_to_variable = { PREV.GGN_AK_control = 1 }
		}
		else_if = {
			limit = { 
				check_variable = { GGN_majority = 5 }
			}
			add_to_variable = { PREV.GGN_NSZ_control = 1 }
		}
		else_if = {
			limit = { 
				check_variable = { GGN_majority = 6 }
			}
			add_to_variable = { PREV.GGN_NSZONR_control = 1 }
		}
	}
}