From f3df0f68866261cdea3b34f7d8b624e59ba994b7 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 9 Sep 2023 13:16:55 +0200 Subject: Add end game supply check to eliminate unsupplied units after last month. --- rules.js | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/rules.js b/rules.js index 539ed03..3a4b767 100644 --- a/rules.js +++ b/rules.js @@ -2641,6 +2641,8 @@ function end_fortress_supply() { game.state = 'final_oasis_supply' else if (game.state === 'buildup_fortress_supply') game.state = 'buildup_oasis_supply' + else if (game.state === 'end_game_fortress_supply') + game.state = 'end_game_oasis_supply' resume_oasis_supply() } @@ -2731,6 +2733,7 @@ const xxx_fortress_supply = { states.initial_fortress_supply = xxx_fortress_supply states.final_fortress_supply = xxx_fortress_supply states.buildup_fortress_supply = xxx_fortress_supply +states.end_game_fortress_supply = xxx_fortress_supply // === OASIS SUPPLY === @@ -2752,6 +2755,8 @@ function end_oasis_supply() { goto_final_supply_check_disrupt() else if (game.state === 'buildup_oasis_supply') goto_buildup_supply_check_recover() + else if (game.state === 'end_game_oasis_supply') + goto_end_game_supply_check_recover() } function assign_oasis_supply() { @@ -2802,6 +2807,7 @@ const xxx_oasis_supply = { states.initial_oasis_supply = xxx_oasis_supply states.final_oasis_supply = xxx_oasis_supply states.buildup_oasis_supply = xxx_oasis_supply +states.end_game_oasis_supply = xxx_oasis_supply // === INITIAL SUPPLY CHECK === @@ -3322,7 +3328,13 @@ states.regroup_move_destination = { } function end_movement() { + + // TODO: track whether a regroup move has affected more than one hex + // scan summary to detect (only bother if forced march is involved) + // TODO: convert single hex regroup move to group move for forced march attempts + flush_move_summary() + game.group = null game.regroup = null game.withdraw = null @@ -5676,7 +5688,7 @@ function end_month() { clear_fortresses_captured() if (game.month === current_scenario().end) - return end_game() + return goto_end_game() goto_buildup() } @@ -6483,6 +6495,80 @@ states.axis_player_initiative = { } } +// === END GAME SUPPLY CHECK (AFTER LAST MONTH, BEFORE VICTORY CHECK) === + +function goto_end_game() { + log_h1("End Game") + + game.phasing = AXIS + set_active_player() + goto_end_game_supply_check() +} + +function goto_end_game_supply_check() { + let base_net = friendly_supply_network() + for_each_friendly_unit_on_map(u => { + if (base_net[unit_hex(u)]) + set_unit_supply(u, SS_BASE) + else + set_unit_supply(u, SS_NONE) + }) + + if (is_axis_player()) + game.capacity = [ 1, 1, 2 ] + else + game.capacity = [ 2, 2, 5 ] + game.oasis = [ 1, 1, 1 ] + + goto_fortress_supply('end_game_fortress_supply') +} + +function goto_end_game_supply_check_recover() { + let summary = [] + for_each_friendly_unit_on_map(u => { + if (is_unit_supplied(u) && is_unit_disrupted(u) && !is_battle_hex(unit_hex(u))) { + set_add(summary, unit_hex(u)) + clear_unit_disrupted(u) + } + }) + for (let x of summary) + log(`Recovered at #${x}.`) + resume_end_game_eliminate_unsupplied() +} + +function resume_end_game_eliminate_unsupplied() { + game.state = 'end_game_eliminate_unsupplied' + let done = true + for_each_friendly_unit_on_map(u => { + if (is_unit_unsupplied(u)) + done = false + }) + if (done) { + if (is_axis_player()) { + set_enemy_player() + goto_end_game_supply_check() + } else { + end_game() + } + } +} + +states.end_game_eliminate_unsupplied = { + inactive: "buildup", + prompt() { + view.prompt = `End Game: Eliminate unsupplied units.` + for_each_friendly_unit_on_map(u => { + if (is_unit_unsupplied(u)) + gen_action_unit(u) + }) + }, + unit(u) { + log(`Eliminated at #${unit_hex(u)}.`) + eliminate_unit(u) + resume_end_game_eliminate_unsupplied() + }, +} + // === VICTORY CHECK === const EXIT_EAST_EDGE = [ 99, 148 ] -- cgit v1.2.3