diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-07-22 15:40:10 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:25 +0100 |
commit | b6b5a40502751ecf66bc3ac00890634df0504ecc (patch) | |
tree | 2377a769edb3b5ef34fdd7c400c1b58fce032933 /rules.js | |
parent | bacef63f254d26e593bb59dc4799eee495136f06 (diff) | |
download | rommel-in-the-desert-b6b5a40502751ecf66bc3ac00890634df0504ecc.tar.gz |
refuse battle pursuit fire
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 86 |
1 files changed, 52 insertions, 34 deletions
@@ -67,8 +67,6 @@ const first_allied_unit = units.findIndex(item => item.nationality === 'allied') const last_axis_unit = first_allied_unit - 1 const last_allied_unit = units.length - 1 -console.log("FOO", first_axis_unit, last_axis_unit, first_allied_unit, last_allied_unit) - function debug_hexes3(n, list) { console.log("--", n, "--") list = list.map((x,i) => hex_exists[i] ? x : "") @@ -111,6 +109,7 @@ const AXIS = 'Axis' const ALLIED = 'Allied' const firepower_name = [ "0", "1", "2", "3", "TF", "DF", "SF" ] +const speed_name = [ "zero", "leg", "motorized", "mechanized", "recon" ] const SF = 6 const DF = 5 @@ -955,7 +954,7 @@ function print_path(who, from, to, road) { to = path_from[road][to] p.unshift(hex_name[to]) } - log(unit_name(who) + " moved " + p.join(", ") + ".") + log(">" + p.join(" - ") + ".") } function search_move(start, start_cost, start_road) { @@ -1241,7 +1240,7 @@ function set_active_player() { } function set_passive_player() { - if (game.active === AXIS) + if (game.phasing === AXIS) game.active = ALLIED else game.active = AXIS @@ -1286,7 +1285,7 @@ function goto_initial_supply_check() { if (snet[x]) { set_unit_supply(u, ssrc) if (is_unit_disrupted(u) && set_has(game.recover, u) && !is_battle_hex(x)) { - log(`%${u} recovered at #${x}`) + log(`Recovered at #${x}`) set_delete(game.recover, u) clear_unit_disrupted(u) } @@ -1501,7 +1500,7 @@ function goto_move_who() { log(`Group move from #${game.from1} (Rommel).`) } else { if (game.from1 && game.to1) - log(`Regroup move from #${game.from1} to #${game.to1}.`) + log(`Regroup move\nfrom #${game.from1}\nto #${game.to1}.`) else if (game.from1) log(`Group move from #${game.from1}.`) } @@ -1516,6 +1515,8 @@ function goto_move_who() { else if (game.from2) log(`Group move from #${game.from2}.`) } + log_br() + log("Moved:") game.state = 'move_who' } @@ -1571,10 +1572,12 @@ states.move_who = { }, retreat() { push_undo() + log_br() game.state = 'retreat_select_from' }, end_move() { clear_undo() + log_br() end_move_phase() } } @@ -1602,8 +1605,6 @@ function apply_move(move, who, from, to) { if (is_battle_hex(to)) { let side = to_side_id(to, path_from[road][to]) - log(`cross ${side} ${hex_name[to]}/${hex_name[path_from[road][to]]}`) - if (game.side_limit[side]) game.side_limit[side] = 2 else @@ -1697,7 +1698,6 @@ states.move_to = { search_move(from, 0, 4) if (can_move_group_1(who, from, to)) { - log(`group moved ${who} to ${to}`) game.move_from = from if (apply_move(1, who, from, to)) stop_move(who) @@ -1707,7 +1707,6 @@ states.move_to = { } if (can_move_group_2(who, from, to)) { - log(`group moved ${who} to ${to}`) game.move_from = from if (apply_move(2, who, from, to)) stop_move(who) @@ -1717,7 +1716,6 @@ states.move_to = { } if (can_move_regroup_1(who, from, to)) { - log(`regrouped ${who} to ${to}`) apply_move(1, who, from, to) stop_move(who) game.state = 'move_who' @@ -1725,7 +1723,6 @@ states.move_to = { } if (can_move_regroup_2(who, from, to)) { - log(`regrouped ${who} to ${to}`) apply_move(2, who, from, to) stop_move(who) game.state = 'move_who' @@ -1882,7 +1879,7 @@ states.retreat_select_who = { }) game.retreat_units = game.selected game.selected = [] - goto_retreat_pursuit_fire(game.retreat) + goto_pursuit_fire_during_retreat(game.retreat) }, partial_retreat() { clear_undo() @@ -1911,7 +1908,7 @@ states.provoke_probe_combat = { if (shielded) goto_retreat_who() else - goto_retreat_pursuit_fire(game.retreat) + goto_pursuit_fire_during_retreat(game.retreat) }, } @@ -2018,8 +2015,9 @@ states.refuse_battle = { }, hex(x) { push_undo() + log_h3(`Refused battle at #${x}`) set_delete(game.active_battles, x) - goto_refuse_pursuit_fire(x) + goto_pursuit_fire_during_refuse_battle(x) }, next() { goto_combat_phase() @@ -2068,6 +2066,7 @@ states.refuse_battle_to = { }, hex(to) { let who = game.selected[0] + log(`>to #${to}`) set_unit_hex(who, to) set_unit_disrupted(who) game.selected = [] @@ -2390,31 +2389,46 @@ function end_probe() { // === PURSUIT FIRE === -function goto_retreat_pursuit_fire(where) { +// Refuse battle +// active pursuit fire +// passive apply hits +// passive moves + +// Retreat +// passive pursuit fire +// active apply hits +// active moves + +// Rout +// non-routing pursuit fire +// routing apply hits +// routing moves + +function goto_pursuit_fire_during_retreat(where) { clear_undo() set_passive_player() game.hits = 0 game.pursuit = where if (can_pursuit_fire()) - game.state = 'retreat_pursuit_fire' + game.state = 'pursuit_fire' else goto_pursuit_hits() } -function goto_refuse_pursuit_fire(where) { +function goto_pursuit_fire_during_refuse_battle(where) { clear_undo() set_active_player() game.hits = 0 game.pursuit = where - if (can_pursuit_fire()) - game.state = 'refuse_pursuit_fire' + if (can_pursuit_fire(true)) + game.state = 'pursuit_fire' else goto_pursuit_hits() } function goto_pursuit_hits() { + set_enemy_player() if (game.hits > 0) { - set_passive_player() let hp = count_hp_in_pursuit() if (game.hits > hp) game.hits = hp @@ -2434,10 +2448,11 @@ function slowest_undisrupted_enemy_unit_speed(where) { return r } -function can_pursuit_fire() { +function can_pursuit_fire(verbose) { let result = false let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) - log(`Slowest enemy speed is ${slowest}.`) + if (verbose) + log(`Slowest enemy was ${speed_name[slowest]}.`) for_each_undisrupted_friendly_unit_in_hex(game.pursuit, u => { if (unit_speed(u) >= slowest && !is_unit_fired(u)) result = true @@ -2445,11 +2460,11 @@ function can_pursuit_fire() { return result } -function roll_pursuit_fire(n) { +function roll_pursuit_fire(who, n) { if (n === 2) { let a = random(6) + 1 let b = random(6) + 1 - log(`Pursuit fire ${a}, ${b}.`) + log(`>%${who} pursuit fired ${a}, ${b}.`) if (a >= 4) game.hits++ if (b >= 4) @@ -2457,13 +2472,18 @@ function roll_pursuit_fire(n) { } if (n === 1) { let a = random(6) + 1 - log(`Pursuit fire ${a}.`) + log(`>%${who} pursuit fired ${a}.`) if (a >= 4) game.hits++ } + + let hp = count_hp_in_pursuit() + if (game.hits > hp) + game.hits = hp + return game.hits === hp } -const xxx_pursuit_fire = { +states.pursuit_fire = { inactive: "pursuit fire (fire)", prompt() { view.prompt = `Pursuit Fire.` @@ -2472,22 +2492,22 @@ const xxx_pursuit_fire = { if (unit_speed(u) >= slowest && !is_unit_fired(u)) gen_action_unit(u) }) + // TODO: only save fire if there are shielded enemy units? gen_action('next') }, unit(who) { let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) - if (unit_speed(who) > slowest) - roll_pursuit_fire(2) - else - roll_pursuit_fire(1) set_unit_fired(who) + let done = roll_pursuit_fire(who, (unit_speed(who) > slowest ? 2 : 1)) + if (done || !can_pursuit_fire(false)) + goto_pursuit_hits() }, next() { goto_pursuit_hits() } } -const xxx_pursuit_hits = { +states.pursuit_hits = { inactive: "pursuit fire (hits)", prompt() { view.prompt = `Pursuit Fire: Apply ${game.hits} hits.` @@ -2532,10 +2552,8 @@ function end_pursuit_fire() { game.from1 = game.pursuit game.pursuit = 0 if (game.retreat) { - set_active_player() game.state = 'retreat_who' } else { - set_passive_player() game.state = 'refuse_battle_who' } } |