diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-08-06 14:17:41 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:26 +0100 |
commit | 38f5d4dd069953d5a03787e9e593914e73ea4cfd (patch) | |
tree | b8c065c75ba2a6e192c9bdffb70d99157d88a967 | |
parent | e5975714d50be01485499822543e1c1fb5dad1f3 (diff) | |
download | rommel-in-the-desert-38f5d4dd069953d5a03787e9e593914e73ea4cfd.tar.gz |
Raiders and rout elimination due to no retreat.
-rw-r--r-- | play.js | 1 | ||||
-rw-r--r-- | rules.js | 83 |
2 files changed, 68 insertions, 16 deletions
@@ -813,7 +813,6 @@ function battle_button(id, action) { function on_update() { if (!ui.loaded) { - document.getElementById("prompt").textContent = "ERROR" return setTimeout(on_update, 500) } @@ -1,7 +1,5 @@ "use strict" -// TODO: RAIDERS - // TODO: MINEFIELDS // TODO: create minefields // TODO: tear down 2 minefields to create new minefield @@ -1982,13 +1980,13 @@ function union_allied_line() { const FORTRESS_HEX_LIST = [ BARDIA, BENGHAZI, TOBRUK ] const FORTRESS_SRC_LIST = [ SS_BARDIA, SS_BENGHAZI, SS_TOBRUK ] -function all_friendly_unsupplied_units() { - let unsupplied = [] +function all_friendly_unsupplied_and_undisrupted_units() { + let result = [] for_each_friendly_unit_on_map(u => { - if (is_unit_unsupplied(u)) - unsupplied.push(u) + if (!is_unit_disrupted(u) && is_unit_unsupplied(u)) + result.push(u) }) - return unsupplied + return result } function resume_fortress_supply() { @@ -2249,7 +2247,18 @@ function goto_final_supply_check() { capture_fortress(BENGHAZI, 2) capture_fortress(TOBRUK, 5) - game.disrupt = all_friendly_unsupplied_units() + // Raiders! + for (let [u, side] of game.raiders) { + let x = unit_hex(u) + if (is_map_hex(x) && is_enemy_hexside(side)) { + log(`Disrupted raider at #${x}.`) + set_unit_disrupted(u) + } + } + game.raiders.length = 0 + + // Unsupplied and in danger of disruption! + game.disrupt = all_friendly_unsupplied_and_undisrupted_units() // Now in supply! let base_net = friendly_supply_network() @@ -2258,6 +2267,7 @@ function goto_final_supply_check() { set_unit_supply(u, SS_BASE) } + // Assign leftover fortress and oasis supply game.state = 'final_fortress_supply' game.assign = 0 resume_fortress_supply() @@ -2265,7 +2275,7 @@ function goto_final_supply_check() { function goto_final_supply_check_disrupt() { for (let u of game.disrupt) { - if (!is_unit_disrupted(u) && !is_unit_supplied(u)) { + if (!is_unit_supplied(u)) { log(`Disrupted at #${unit_hex(u)}`) set_unit_disrupted(u) } @@ -2901,7 +2911,14 @@ function engage_via(who, via, to) { else game.side_limit[side] = 1 - claim_hexside_control(side) + if (is_unit_supplied(who)) { + claim_hexside_control(side) + } else { + // new battle or enemy hexside (is_friendly_hexside is false before claiming control) + if (!is_friendly_hexside(side)) + game.raiders.push([who, side]) + } + if (is_new_battle_hex(to)) { claim_hex_control_for_defender(to) set_add(game.active_battles, to) @@ -3062,6 +3079,12 @@ function is_friendly_hexside(side) { return set_has(game.allied_sides, side) } +function is_enemy_hexside(side) { + if (is_allied_player()) + return set_has(game.axis_sides, side) + return set_has(game.allied_sides, side) +} + function can_unit_disengage_and_withdraw(who) { let sline = unit_supply_line(who) let sdist = unit_supply_distance(who) @@ -3378,7 +3401,7 @@ states.refuse_battle = { for (let x of game.active_battles) if (can_all_refuse_battle(x)) gen_action_hex(x) - gen_action('next') + gen_action('pass') }, hex(x) { push_undo() @@ -3387,7 +3410,7 @@ states.refuse_battle = { set_delete(game.active_battles, x) goto_pursuit_fire_during_refuse_battle(x) }, - next() { + pass() { goto_combat_phase() } } @@ -3456,6 +3479,16 @@ function end_refuse_battle_move_2() { // withdraw by group move // eliminated if cannot +function can_rout_from_hex(from) { + let n = 0 + for_each_adjacent_hex(from, to => { + let side = to_side_id(from, to) + if (side_limit[side] > 0 && !is_enemy_hexside(side)) + ++n + }) + return n > 0 +} + function goto_rout(from, enemy, after) { // remember state and callback so we can resume after routing @@ -3476,12 +3509,32 @@ function goto_rout(from, enemy, after) { if (enemy) set_enemy_player() + log_h3(`Rout at #${from}`) + // RULES: Will be disrupted again, so won't be able to recover. for_each_friendly_unit_in_hex(from, u => { set_delete(game.recover, u) }) - game.state = 'rout_attrition' + if (can_rout_from_hex(from)) + game.state = 'rout_attrition' + else + game.state = 'rout_elimination' +} + +states.rout_elimination = { + prompt() { + view.prompt = "Rout: Eliminate all units that can not disengage." + for_each_friendly_unit_in_hex(game.rout.from, u => { + gen_action_unit(u) + }) + }, + unit(who) { + log(`Eliminated at #${game.rout.from}.`) + eliminate_unit(who) + if (!has_friendly_unit(game.rout.from)) + end_rout() + }, } states.rout_attrition = { @@ -3784,9 +3837,9 @@ function goto_battle(x) { game.battle = x if (is_assault_battle()) - log_h3(`Assault in #${x}`) + log_h3(`Assault at #${x}`) else - log_h3(`Battle in #${x}`) + log_h3(`Battle at #${x}`) // goto defensive fire set_passive_player() |