From 0e8fb16e6f787da2ec0b5cd0a759fb9ca228ab39 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 3 Sep 2022 19:35:56 +0200 Subject: Misc fixes. End battle properly when routing. Forced march into battle. Skip combat phase during pass turns. Clear moved flags before buildup. --- play.js | 17 ++++++++--------- rules.js | 57 +++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/play.js b/play.js index e948dcc..1756db7 100644 --- a/play.js +++ b/play.js @@ -841,17 +841,16 @@ function update_battle() { ui.battle.classList.remove("hide") ui.battle_header.textContent = hex_name[view.battle] ui.battle_message.textContent = view.flash - // TODO: don't show disrupted units? if (player === ALLIED) { - update_battle_line(view.battle, ui.battle_line_1, u => is_axis_unit(u) && is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_2, u => is_axis_unit(u) && !is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_3, u => is_allied_unit(u) && !is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_4, u => is_allied_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_1, u => is_axis_unit(u) && is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_2, u => is_axis_unit(u) && !is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_3, u => is_allied_unit(u) && !is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_4, u => is_allied_unit(u) && is_artillery_unit(u) && !is_unit_disrupted(u)) } else { - update_battle_line(view.battle, ui.battle_line_1, u => is_allied_unit(u) && is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_2, u => is_allied_unit(u) && !is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_3, u => is_axis_unit(u) && !is_artillery_unit(u)) - update_battle_line(view.battle, ui.battle_line_4, u => is_axis_unit(u) && is_artillery_unit(u)) + update_battle_line(view.battle, ui.battle_line_1, u => is_allied_unit(u) && is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_2, u => is_allied_unit(u) && !is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_3, u => is_axis_unit(u) && !is_artillery_unit(u) && !is_unit_disrupted(u)) + update_battle_line(view.battle, ui.battle_line_4, u => is_axis_unit(u) && is_artillery_unit(u) && !is_unit_disrupted(u)) } for (let i = 0; i < 4; ++i) ui.battle_hits[i].textContent = view.hits[i] diff --git a/rules.js b/rules.js index 29181bc..1d4f31c 100644 --- a/rules.js +++ b/rules.js @@ -467,6 +467,12 @@ function reveal_units_in_hex(x) { set_add(game.revealed, u) } +function hide_friendly_units_in_hex(x) { + for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) + if (unit_hex(u) === x) + set_delete(game.revealed, u) +} + function hide_units_in_hex(x) { for (let u = 0; u < unit_count; ++u) if (unit_hex(u) === x) @@ -2853,13 +2859,15 @@ function goto_final_supply_check() { // Now in supply! let base_net = friendly_supply_network() + let summary = [] for (let u of game.disrupt) { if (base_net[unit_hex(u)]) { - // TODO: summary? - log(`Restored supply at #${unit_hex(u)}.`) + set_add(summary, unit_hex(u)) set_unit_supply(u, SS_BASE) } } + for (let x of summary) + log(`Restored supply at #${x}.`) // Assign leftover fortress and oasis supply game.state = 'final_fortress_supply' @@ -3851,11 +3859,9 @@ states.forced_marches = { if (roll >= 4) { log(`>${die_face_hit[roll]} to #${to}`) visit_hex(to) - if (has_enemy_unit(to)) { + if (has_enemy_unit(to)) engage_via_hexside(who, via, to, false) - } else { - set_unit_hex(who, to) - } + set_unit_hex(who, to) } else { log(`>${die_face_miss[roll]} disrupted at #${from}`) set_unit_hex(who, from) @@ -4421,6 +4427,7 @@ states.rout_attrition = { function goto_rout_move() { if (has_friendly_unit(game.rout.from)) { + hide_friendly_units_in_hex(game.rout.from) // TODO: auto-eliminate if no withdraw path available game.state = 'rout_move' log(`Withdrew`) @@ -4515,15 +4522,16 @@ function goto_combat_phase() { return goto_rout(BENGHAZI, false, goto_combat_phase) if (is_mandatory_combat(TOBRUK)) return goto_rout(TOBRUK, false, goto_combat_phase) - } else { - if (is_mandatory_combat(BARDIA)) - set_add(game.active_battles, BARDIA) - if (is_mandatory_combat(BENGHAZI)) - set_add(game.active_battles, BENGHAZI) - if (is_mandatory_combat(TOBRUK)) - set_add(game.active_battles, TOBRUK) + return end_combat_phase() } + if (is_mandatory_combat(BARDIA)) + set_add(game.active_battles, BARDIA) + if (is_mandatory_combat(BENGHAZI)) + set_add(game.active_battles, BENGHAZI) + if (is_mandatory_combat(TOBRUK)) + set_add(game.active_battles, TOBRUK) + let n = count_and_reveal_battle_hexes() if (n > 0) { if (n > game.active_battles.length) @@ -4717,7 +4725,13 @@ function goto_battle(x) { game.hits = [ 0, 0, 0, 0 ] } -function end_battle() { +function end_battle_1() { + game.flash = "" + game.battle = 0 + game.hits = 0 +} + +function end_battle_2() { if (!is_battle_hex(game.battle)) { release_hex_control(game.battle) hide_units_in_hex(game.battle) @@ -4726,10 +4740,6 @@ function end_battle() { set_delete(game.active_battles, game.battle) set_delete(game.assault_battles, game.battle) - game.flash = "" - game.battle = 0 - game.hits = 0 - set_active_player() if (game.active_battles.length > 0) game.state = 'select_battle' @@ -4990,7 +5000,9 @@ states.battle_hits = { function end_battle_hits() { if (is_friendly_rout_hex(game.battle)) { - goto_rout(game.battle, false, end_battle) + let where = game.battle + end_battle_1() + goto_rout(where, false, end_battle_2) } else if (game.active === game.phasing && has_friendly_units_in_battle()) { // goto offensive fire log_br() @@ -4998,7 +5010,8 @@ function end_battle_hits() { game.state = 'battle_fire' game.hits = [ 0, 0, 0, 0 ] } else { - end_battle() + end_battle_1() + end_battle_2() } } @@ -5054,6 +5067,7 @@ states.probe_hits = { } function end_probe_hits() { + // TODO: rout during probe combat? if (game.active !== game.phasing && has_friendly_units_in_battle()) { // goto offensive fire game.state = 'probe_fire' @@ -5384,6 +5398,9 @@ function end_rout_fire() { // === BUILDUP - SUPPLY CHECK === function end_month() { + set_clear(game.fired) + set_clear(game.moved) + // Forget captured fortresses (for bonus cards) clear_fortresses_captured() -- cgit v1.2.3