From df6618a44e69058b424f6f31c993affa5dc27e54 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 7 Apr 2022 00:43:40 +0200 Subject: Handle case where force moving into space with lone leader retreat. If a force moves into a space with a lone leader and is intercepted and defeated, the lone leader must also retreat. --- rules.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/rules.js b/rules.js index dc6886a..fa0e9f3 100644 --- a/rules.js +++ b/rules.js @@ -3542,6 +3542,13 @@ function end_move_step(final=false, overrun=false) { && !has_unbesieged_enemy_units(where)) return goto_retreat_lone_leader(where, 'move'); + // If enemy intercepted into moving piece and lone friendly leaders remain after battle. + if (has_unbesieged_friendly_leader(where) && !has_unbesieged_friendly_units(where) && has_unbesieged_enemy_units(where)) { + game.state = 'retreat_lone_leader'; + game.retreat = { from: where, reason: 'friendly_move' }; + return; + } + resume_move(); } @@ -5315,7 +5322,8 @@ function can_defender_retreat_from_to(p, from, to) { if (has_unbesieged_enemy_fortifications(to)) return false; if (game.move && moving_piece_came_from() === to) - return false; + if (!game.retreat || game.retreat.reason !== 'friendly_move') + return false; if (force_has_drilled_troops(p)) { if (is_cultivated(to) || has_friendly_fortifications(to)) return true; @@ -5593,13 +5601,18 @@ function resume_retreat_lone_leader(from) { let who = pick_unbesieged_leader(from); if (!who) { flush_summary(); - set_active_enemy(); switch (game.retreat.reason) { case 'indian_alliance': + set_active_enemy(); delete game.retreat; game.state = 'indian_alliance'; break; case 'move': + set_active_enemy(); + delete game.retreat; + resume_move(); + break; + case 'friendly_move': delete game.retreat; resume_move(); break; -- cgit v1.2.3