summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-30 01:07:07 +0200
committerTor Andersson <tor@ccxvii.net>2023-06-30 01:09:59 +0200
commite9fbebf6bb5fd58390696138aa90e12d23a00a08 (patch)
tree75c40e8b78e9702ca8639b00449cb9163c1c3e9f
parentc0e10c476bb91fe8b0575a6fac7230cdd3265cea (diff)
downloadnevsky-e9fbebf6bb5fd58390696138aa90e12d23a00a08.tar.gz
Fix iteration of multiple ways during Avoid Battle and Retreat.
-rw-r--r--rules.js30
1 files changed, 16 insertions, 14 deletions
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