From 8f432713888b89e8c37a635a312fc97e29268637 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 27 Sep 2022 18:47:45 +0200 Subject: Skip pursuit fire during rout if possible. --- rules.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rules.js b/rules.js index 6d53263..a712237 100644 --- a/rules.js +++ b/rules.js @@ -5252,19 +5252,37 @@ function fastest_undisrupted_friendly_unit_speed(where) { return r } +function has_hidden_friendly_unit(x) { + for (let u = first_friendly_unit; u <= last_friendly_unit; ++u) + if (unit_hex(u) === x && !set_has(game.revealed, u)) + return true + return false +} + function goto_rout_fire(where) { set_enemy_player() game.hits = 0 game.pursuit = where + game.flash = "" + let slowest = slowest_enemy_unit_speed(game.pursuit) + let fastest = fastest_undisrupted_friendly_unit_speed(game.pursuit) + log(`Slowest was ${speed_name[slowest]} unit.`) - game.state = 'rout_fire' + if (slowest <= fastest || has_hidden_friendly_unit(game.pursuit)) { + game.state = 'rout_fire' + } else { + // too fast for pursuit fire, and we already know all the units involved + set_enemy_player() + end_rout_fire() + } } function goto_pursuit_fire_during_retreat(where) { set_passive_player() game.hits = 0 game.pursuit = where + game.flash = "" let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) let fastest = fastest_undisrupted_friendly_unit_speed(game.pursuit) -- cgit v1.2.3