summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-03-27 00:15:38 +0100
committerTor Andersson <tor@ccxvii.net>2024-03-27 00:26:11 +0100
commit3e201b997a8f5f6957c57a2af3db8a206e653b26 (patch)
treee7086d6cb5bd59e0c0cbcb8d813939530eeecf0d
parenta3a6f64bff60b5b216d24561a722775faa676669 (diff)
downloadwilderness-war-3e201b997a8f5f6957c57a2af3db8a206e653b26.tar.gz
More robust lone leader retreat checks.
Handle cases when (defending) units retreat or avoid battle to spaces with lone leaders.
-rw-r--r--rules.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/rules.js b/rules.js
index 2c2dbe5..6341afa 100644
--- a/rules.js
+++ b/rules.js
@@ -2954,20 +2954,33 @@ function resume_move() {
let who = moving_piece()
let where = moving_piece_space()
- let enemy_units = has_unbesieged_enemy_units(where)
- let enemy_leader = has_unbesieged_enemy_leader(where)
- let friendly_units = has_unbesieged_friendly_units(where)
- let friendly_leader = has_unbesieged_friendly_leader(where)
+ // First retreat enemy lone leaders with our units.
+ // Can happen if defender retreats into space(s) with lone enemy leaders.
+ for (let p = first_enemy_leader; p <= last_enemy_leader; ++p) {
+ let s = piece_space(p)
+ let enemy_units = has_unbesieged_enemy_units(s)
+ let enemy_leader = has_unbesieged_enemy_leader(s)
+ let friendly_units = has_unbesieged_friendly_units(s)
- if (enemy_leader && !enemy_units && friendly_units) {
- return goto_retreat_lone_leader(where, 'move')
+ if (enemy_leader && !enemy_units && friendly_units) {
+ return goto_retreat_lone_leader(s, 'move')
+ }
}
- // Can happen if enemy intercepted into moving piece and lone friendly leaders remain after battle.
- if (friendly_leader && !friendly_units && enemy_units) {
- game.state = 'retreat_lone_leader'
- game.retreat = { from: where, reason: 'friendly_move' }
- return
+ // Then retreat our lone leaders with enemy units.
+ // Can happen if enemy intercepted into moving piece and
+ // lone friendly leaders remain after battle.
+ for (let p = first_friendly_leader; p <= last_friendly_leader; ++p) {
+ let s = piece_space(p)
+ let enemy_units = has_unbesieged_enemy_units(s)
+ let friendly_units = has_unbesieged_friendly_units(s)
+ let friendly_leader = has_unbesieged_friendly_leader(s)
+
+ if (friendly_leader && !friendly_units && enemy_units) {
+ game.state = 'retreat_lone_leader'
+ game.retreat = { from: s, reason: 'friendly_move' }
+ return
+ }
}
// Interrupt for Foul Weather response at first opportunity to move.