﻿namespace = sakuya_main_04_02

# ============================================================
# 事件 1 — 选择博弈（diplomatic play）
# ============================================================
sakuya_main_04_02.1 = {
	type = country_event

	title = SKY_B4_EVT_SELECT_DP_TITLE
	desc = SKY_B4_EVT_SELECT_DP_DESC
	flavor = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = sakuya_main_04_02_dp_force_empty_notice }
				desc = SKY_B4_EVT_SELECT_DP_DESC_EMPTY
			}
			triggered_desc = {
				trigger = { NOT = { has_variable = sakuya_main_04_02_dp_slot_1 } }
				desc = SKY_B4_EVT_SELECT_DP_DESC_EMPTY
			}
			triggered_desc = {
				trigger = { has_variable = sakuya_b4_selected_dp }
				desc = SKY_B4_EVT_SELECT_DP_DESC_SELECTED
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = SKY_B4_EVT_SELECT_DP_DESC_HINT
			}
		}
	}

	event_image = { video = "gfx/event_pictures/southamerica_factory_opening.bk2" }
	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/southamerica/factory_opening"
	icon = "gfx/interface/icons/event_icons/event_trade.dds"
	duration = 0

	trigger = { is_player = yes }

	immediate = {
		save_scope_as = sakuya_main_04_02_dp_event_root

		# Reset slot flags
		remove_variable = sakuya_main_04_02_dp_slot_1
		remove_variable = sakuya_main_04_02_dp_slot_2
		remove_variable = sakuya_main_04_02_dp_slot_3
		remove_variable = sakuya_main_04_02_dp_slot_4
		remove_variable = sakuya_main_04_02_dp_slot_5
		remove_variable = sakuya_main_04_02_dp_slot_6
		remove_variable = sakuya_main_04_02_dp_slot_7
		remove_variable = sakuya_main_04_02_dp_slot_8
		remove_variable = sakuya_main_04_02_dp_has_next
		remove_variable = sakuya_main_04_02_dp_page2_valid

		if = {
			limit = { has_variable = sakuya_main_04_02_dp_force_empty_notice }
			remove_variable = sakuya_main_04_02_dp_page_2
			remove_variable = sakuya_main_04_02_dp_force_empty_notice
		}
		else = {
			# 确定源国家
			save_scope_as = sakuya_main_04_02_dp_source_country
			if = {
				limit = {
					has_variable = sakuya_main_04_02_dp_use_marked_country
					exists = scope:sakuya_main_04_02_dp_marked_country_scope
				}
				scope:sakuya_main_04_02_dp_marked_country_scope = {
					save_scope_as = sakuya_main_04_02_dp_source_country
				}
			}

			# Auto-fallback to page 1 if page 2 no longer has entries
			if = {
				limit = {
					has_variable = sakuya_main_04_02_dp_page_2
					any_diplomatic_play = {
						count >= 9
						any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country }
					}
				}
				set_variable = sakuya_main_04_02_dp_page2_valid
			}
			if = {
				limit = {
					has_variable = sakuya_main_04_02_dp_page_2
					NOT = { has_variable = sakuya_main_04_02_dp_page2_valid }
				}
				remove_variable = sakuya_main_04_02_dp_page_2
			}
			remove_variable = sakuya_main_04_02_dp_page2_valid

			# Fill 8 slots from page 1 or page 2
			if = {
				limit = { has_variable = sakuya_main_04_02_dp_page_2 }

				if = {
					limit = { any_diplomatic_play = { count >= 9 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 8
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_1
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_1 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 10 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 9
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_2
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_2 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 11 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 10
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_3
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_3 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 12 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 11
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_4
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_4 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 13 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 12
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_5
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_5 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 14 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 13
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_6
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_6 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 15 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 14
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_7
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_7 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 16 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 15
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_8
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_8 }
					}
				}
			}
			else = {
				if = {
					limit = { any_diplomatic_play = { count >= 1 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 0
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_1
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_1 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 2 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 1
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_2
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_2 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 3 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 2
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_3
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_3 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 4 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 3
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_4
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_4 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 5 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 4
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_5
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_5 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 6 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 5
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_6
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_6 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 7 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 6
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_7
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_7 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 8 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					ordered_diplomatic_play = {
						position = 7
						check_range_bounds = no
						limit = { any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } }
						save_scope_as = sakuya_main_04_02_dp_8
						scope:sakuya_main_04_02_dp_event_root = { set_variable = sakuya_main_04_02_dp_slot_8 }
					}
				}

				# Page 1 shows next page if 9th candidate exists
				if = {
					limit = { any_diplomatic_play = { count >= 9 any_scope_play_involved = { this = scope:sakuya_main_04_02_dp_source_country } } }
					set_variable = sakuya_main_04_02_dp_has_next
				}
			}
		}
	}

	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_1
		trigger = { has_variable = sakuya_main_04_02_dp_slot_1 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_1 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_2
		trigger = { has_variable = sakuya_main_04_02_dp_slot_2 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_2 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_3
		trigger = { has_variable = sakuya_main_04_02_dp_slot_3 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_3 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_4
		trigger = { has_variable = sakuya_main_04_02_dp_slot_4 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_4 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_5
		trigger = { has_variable = sakuya_main_04_02_dp_slot_5 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_5 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_6
		trigger = { has_variable = sakuya_main_04_02_dp_slot_6 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_6 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_7
		trigger = { has_variable = sakuya_main_04_02_dp_slot_7 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_7 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_DP_SLOT_8
		trigger = { has_variable = sakuya_main_04_02_dp_slot_8 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_dp value = scope:sakuya_main_04_02_dp_8 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}

	option = {
		name = SKY_B4_EVT_SELECT_PREV
		trigger = { has_variable = sakuya_main_04_02_dp_page_2 }
		ai_chance = { base = 0 }
		remove_variable = sakuya_main_04_02_dp_page_2
		hidden_effect = { trigger_event = { id = sakuya_main_04_02.1 popup = yes } }
	}
	option = {
		name = SKY_B4_EVT_SELECT_NEXT
		ai_chance = { base = 0 }
		trigger = {
			NOT = { has_variable = sakuya_main_04_02_dp_page_2 }
			has_variable = sakuya_main_04_02_dp_has_next
		}
		set_variable = sakuya_main_04_02_dp_page_2
		hidden_effect = { trigger_event = { id = sakuya_main_04_02.1 popup = yes } }
	}
	option = {
		name = SKY_B4_EVT_SELECT_CLOSE
		default_option = yes
		ai_chance = { base = 100 }
		remove_variable = sakuya_main_04_02_dp_page_2
		set_variable = sakuya_main_force_show
	}
}

# ============================================================
# 事件 2 — 选择战争（war）
# 通过 diplomatic_play(is_war=yes) 获取 war scope
# ============================================================
sakuya_main_04_02.2 = {
	type = country_event

	title = SKY_B4_EVT_SELECT_WAR_TITLE
	desc = SKY_B4_EVT_SELECT_WAR_DESC
	flavor = {
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = sakuya_main_04_02_war_force_empty_notice }
				desc = SKY_B4_EVT_SELECT_WAR_DESC_EMPTY
			}
			triggered_desc = {
				trigger = { NOT = { has_variable = sakuya_main_04_02_war_slot_1 } }
				desc = SKY_B4_EVT_SELECT_WAR_DESC_EMPTY
			}
			triggered_desc = {
				trigger = { has_variable = sakuya_b4_selected_war }
				desc = SKY_B4_EVT_SELECT_WAR_DESC_SELECTED
			}
			triggered_desc = {
				trigger = { always = yes }
				desc = SKY_B4_EVT_SELECT_WAR_DESC_HINT
			}
		}
	}

	event_image = { video = "gfx/event_pictures/southamerica_factory_opening.bk2" }
	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/southamerica/factory_opening"
	icon = "gfx/interface/icons/event_icons/event_trade.dds"
	duration = 0

	trigger = { is_player = yes }

	immediate = {
		save_scope_as = sakuya_main_04_02_war_event_root

		# Reset slot flags
		remove_variable = sakuya_main_04_02_war_slot_1
		remove_variable = sakuya_main_04_02_war_slot_2
		remove_variable = sakuya_main_04_02_war_slot_3
		remove_variable = sakuya_main_04_02_war_slot_4
		remove_variable = sakuya_main_04_02_war_slot_5
		remove_variable = sakuya_main_04_02_war_slot_6
		remove_variable = sakuya_main_04_02_war_slot_7
		remove_variable = sakuya_main_04_02_war_slot_8
		remove_variable = sakuya_main_04_02_war_has_next
		remove_variable = sakuya_main_04_02_war_page2_valid

		if = {
			limit = { has_variable = sakuya_main_04_02_war_force_empty_notice }
			remove_variable = sakuya_main_04_02_war_page_2
			remove_variable = sakuya_main_04_02_war_force_empty_notice
		}
		else = {
			# 确定源国家
			save_scope_as = sakuya_main_04_02_war_source_country
			if = {
				limit = {
					has_variable = sakuya_main_04_02_war_use_marked_country
					exists = scope:sakuya_main_04_02_war_marked_country_scope
				}
				scope:sakuya_main_04_02_war_marked_country_scope = {
					save_scope_as = sakuya_main_04_02_war_source_country
				}
			}

			# Auto-fallback to page 1 if page 2 no longer has entries
			if = {
				limit = {
					has_variable = sakuya_main_04_02_war_page_2
					any_diplomatic_play = {
						count >= 9
						is_war = yes
						any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country }
					}
				}
				set_variable = sakuya_main_04_02_war_page2_valid
			}
			if = {
				limit = {
					has_variable = sakuya_main_04_02_war_page_2
					NOT = { has_variable = sakuya_main_04_02_war_page2_valid }
				}
				remove_variable = sakuya_main_04_02_war_page_2
			}
			remove_variable = sakuya_main_04_02_war_page2_valid

			# Fill 8 slots from page 1 or page 2
			if = {
				limit = { has_variable = sakuya_main_04_02_war_page_2 }

				if = {
					limit = { any_diplomatic_play = { count >= 9 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 8
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_1
						war = { save_scope_as = sakuya_main_04_02_war_1 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_1 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 10 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 9
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_2
						war = { save_scope_as = sakuya_main_04_02_war_2 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_2 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 11 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 10
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_3
						war = { save_scope_as = sakuya_main_04_02_war_3 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_3 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 12 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 11
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_4
						war = { save_scope_as = sakuya_main_04_02_war_4 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_4 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 13 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 12
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_5
						war = { save_scope_as = sakuya_main_04_02_war_5 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_5 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 14 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 13
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_6
						war = { save_scope_as = sakuya_main_04_02_war_6 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_6 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 15 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 14
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_7
						war = { save_scope_as = sakuya_main_04_02_war_7 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_7 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 16 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 15
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						war = { save_scope_as = sakuya_main_04_02_war_8 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_8 }
					}
				}
			}
			else = {
				if = {
					limit = { any_diplomatic_play = { count >= 1 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 0
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_1
						war = { save_scope_as = sakuya_main_04_02_war_1 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_1 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 2 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 1
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_2
						war = { save_scope_as = sakuya_main_04_02_war_2 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_2 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 3 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 2
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_3
						war = { save_scope_as = sakuya_main_04_02_war_3 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_3 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 4 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 3
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_4
						war = { save_scope_as = sakuya_main_04_02_war_4 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_4 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 5 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 4
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_5
						war = { save_scope_as = sakuya_main_04_02_war_5 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_5 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 6 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 5
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_6
						war = { save_scope_as = sakuya_main_04_02_war_6 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_6 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 7 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 6
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						save_scope_as = sakuya_main_04_02_war_dp_7
						war = { save_scope_as = sakuya_main_04_02_war_7 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_7 }
					}
				}
				if = {
					limit = { any_diplomatic_play = { count >= 8 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					ordered_diplomatic_play = {
						position = 7
						check_range_bounds = no
						limit = { is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } }
						war = { save_scope_as = sakuya_main_04_02_war_8 }
						scope:sakuya_main_04_02_war_event_root = { set_variable = sakuya_main_04_02_war_slot_8 }
					}
				}

				# Page 1 shows next page if 9th candidate exists
				if = {
					limit = { any_diplomatic_play = { count >= 9 is_war = yes any_scope_play_involved = { this = scope:sakuya_main_04_02_war_source_country } } }
					set_variable = sakuya_main_04_02_war_has_next
				}
			}
		}
	}

	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_1
		trigger = { has_variable = sakuya_main_04_02_war_slot_1 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_1 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_2
		trigger = { has_variable = sakuya_main_04_02_war_slot_2 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_2 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_3
		trigger = { has_variable = sakuya_main_04_02_war_slot_3 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_3 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_4
		trigger = { has_variable = sakuya_main_04_02_war_slot_4 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_4 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_5
		trigger = { has_variable = sakuya_main_04_02_war_slot_5 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_5 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_6
		trigger = { has_variable = sakuya_main_04_02_war_slot_6 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_6 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_7
		trigger = { has_variable = sakuya_main_04_02_war_slot_7 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_7 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
	option = {
		name = SKY_B4_EVT_SELECT_WAR_SLOT_8
		trigger = { has_variable = sakuya_main_04_02_war_slot_8 }
		ai_chance = { base = 0 }
		set_variable = { name = sakuya_b4_selected_war value = scope:sakuya_main_04_02_war_8 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}

	option = {
		name = SKY_B4_EVT_SELECT_PREV
		trigger = { has_variable = sakuya_main_04_02_war_page_2 }
		ai_chance = { base = 0 }
		remove_variable = sakuya_main_04_02_war_page_2
		hidden_effect = { trigger_event = { id = sakuya_main_04_02.2 popup = yes } }
	}
	option = {
		name = SKY_B4_EVT_SELECT_NEXT
		ai_chance = { base = 0 }
		trigger = {
			NOT = { has_variable = sakuya_main_04_02_war_page_2 }
			has_variable = sakuya_main_04_02_war_has_next
		}
		set_variable = sakuya_main_04_02_war_page_2
		hidden_effect = { trigger_event = { id = sakuya_main_04_02.2 popup = yes } }
	}
	option = {
		name = SKY_B4_EVT_SELECT_CLOSE
		default_option = yes
		ai_chance = { base = 100 }
		remove_variable = sakuya_main_04_02_war_page_2
		set_variable = sakuya_main_force_show
	}
}

