From 1e159b0e793fe3f53b37109e37d36bf5e45a2d7b Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 8 Sep 2022 01:09:38 +0200 Subject: Engage and rout enemy after forced marches. --- rules.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/rules.js b/rules.js index defbfd4..55b7b2c 100644 --- a/rules.js +++ b/rules.js @@ -3413,6 +3413,7 @@ states.move = { } flush_move_summary() init_move_summary() + // TODO: auto-select or allow undo? if (n === 1) { goto_overrun(where) } else { @@ -3847,9 +3848,9 @@ states.forced_marches = { if (roll >= 4) { log(`>${die_face_hit[roll]} to #${to}`) visit_hex(to) - if (has_enemy_unit(to)) - engage_via_hexside(who, via, to, false) set_unit_hex(who, to) + if (has_enemy_unit(to)) + engage_via_hexside(who, via, to) } else { log(`>${die_face_miss[roll]} disrupted at #${from}`) set_unit_hex(who, from) @@ -3871,17 +3872,24 @@ function end_forced_marches() { } function goto_forced_marches_rout() { - let n = 0, where = 0 + let friend_count = 0, friend_where = 0 + let enemy_count = 0, we = 0 for (let x of all_hexes) { if (is_friendly_rout_hex(x)) { - where = x - n++ + friend_where = x + friend_count++ + } + if (is_enemy_rout_hex(x)) { + enemy_where = x + enemy_count++ } } - if (n === 0) + if (friend_count + enemy_count === 0) goto_refuse_battle() - else if (n === 1) - goto_rout(where, false, goto_forced_marches_rout) + else if (friend_count === 1 && enemy_count === 0) + goto_rout(friend_where, false, goto_forced_marches_rout) + else if (friend_count === 0 && enemy_count === 1) + goto_rout(enemy_where, true, goto_forced_marches_rout) else game.state = 'forced_marches_rout' } @@ -3890,12 +3898,15 @@ states.forced_marches_rout = { inactive: "forced marches", prompt() { view.prompt = `Forced Marches: Rout!` - for (let x of all_hexes) - if (is_friendly_hexside(x)) + for (let x of all_hexes) { + if (is_friendly_rout_hex(x)) + gen_action_hex(x) + if (is_enemy_rout_hex(x)) gen_action_hex(x) + } }, hex(where) { - goto_rout(where, false, goto_forced_marches_rout) + goto_rout(where, is_enemy_rout_hex(x), goto_forced_marches_rout) } } @@ -4269,7 +4280,6 @@ states.refuse_battle = { gen_action('pass') }, hex(x) { - push_undo() log_h3(`Refused battle at #${x}`) game.refuse = x set_delete(game.active_battles, x) @@ -4552,7 +4562,7 @@ states.select_active_battles = { set_add(game.active_battles, x) }, next() { - push_undo() + clear_undo() if (game.active_battles.length > 0) { if (game.turn_option === 'assault') game.state = 'select_assault_battles' @@ -4579,7 +4589,7 @@ states.select_assault_battles = { set_add(game.assault_battles, x) }, next() { - push_undo() + clear_undo() goto_select_battle() } } -- cgit v1.2.3