From e9fbebf6bb5fd58390696138aa90e12d23a00a08 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 30 Jun 2023 01:07:07 +0200 Subject: Fix iteration of multiple ways during Avoid Battle and Retreat. --- rules.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'rules.js') diff --git a/rules.js b/rules.js index e8a265a..ea07a91 100644 --- a/rules.js +++ b/rules.js @@ -4991,10 +4991,10 @@ function spoil_loot(lord) { } function can_any_avoid_battle() { - let here = game.march.to - for (let [to, way] of data.locales[here].ways) - if (can_avoid_battle(to, way)) - return true + for (let way of data.locales[game.march.to].ways) + for (let i = 1; i < way.length; ++i) + if (can_avoid_battle(way[0], way[i])) + return true return false } @@ -5045,10 +5045,10 @@ states.avoid_battle = { gen_action_lord(lord) if (game.group.length > 0) { - for (let [to, way] of data.locales[here].ways) { - if (can_avoid_battle(to, way)) - gen_action_locale(to) - } + for (let way of data.locales[here].ways) + for (let i = 1; i < way.length; ++i) + if (can_avoid_battle(way[0], way[i])) + gen_action_locale(way[0]) } view.actions.end_avoid_battle = 1 @@ -9468,9 +9468,10 @@ function can_retreat() { // Battle after March if (is_attacker()) return can_retreat_to(game.march.from) - for (let [to, way] of data.locales[game.battle.where].ways) - if (way !== game.march.approach && can_retreat_to(to)) - return true + for (let way of data.locales[game.battle.where].ways) + for (let i = 1; i < way.length; ++i) + if (way[i] !== game.march.approach && can_retreat_to(way[0])) + return true } else { // Battle after Sally for (let to of data.locales[game.battle.where].adjacent) @@ -9508,9 +9509,10 @@ states.retreat = { if (is_attacker()) { gen_action_locale(game.march.from) } else { - for (let [to, way] of data.locales[game.battle.where].ways) - if (way !== game.march.approach && can_retreat_to(to)) - gen_action_locale(to) + for (let way of data.locales[game.battle.where].ways) + for (let i = 1; i < way.length; ++i) + if (way[i] !== game.march.approach && can_retreat_to(way[0])) + gen_action_locale(way[0]) } } else { // after Sally -- cgit v1.2.3