From b8d1038fa3b37b481f5b63bd24bdda2d45cb78b7 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 18 Sep 2022 11:29:34 +0200 Subject: Don't pursuit fire from retreat if all are slower. During retreats from battle hexes, enemy units are all revealed. --- rules.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rules.js b/rules.js index f0717fb..3a9dcb9 100644 --- a/rules.js +++ b/rules.js @@ -5250,6 +5250,16 @@ function fastest_undisrupted_friendly_unit(where) { return who } +function fastest_undisrupted_friendly_unit_speed(where) { + let r = 0 + for_each_undisrupted_friendly_unit_in_hex(where, u => { + let s = unit_speed[u] + if (s > r) + r = s + }) + return r +} + function goto_rout_fire(where) { set_enemy_player() game.hits = 0 @@ -5263,9 +5273,17 @@ function goto_pursuit_fire_during_retreat(where) { set_passive_player() game.hits = 0 game.pursuit = where + let slowest = slowest_undisrupted_enemy_unit_speed(game.pursuit) + let fastest = fastest_undisrupted_friendly_unit_speed(game.pursuit) + log(`Slowest was ${speed_name[slowest]} unit.`) - game.state = 'pursuit_fire' + if (slowest <= fastest) { + game.state = 'pursuit_fire' + } else { + // too fast for pursuit fire, and we already know all the units involved + end_pursuit_fire() + } } function goto_pursuit_fire_during_refuse_battle(where) { -- cgit v1.2.3