summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-01-26 17:53:20 +0100
committerTor Andersson <tor@ccxvii.net>2023-02-18 13:02:39 +0100
commit4f50d6a4f53d69b627948815b6f042e409f689e7 (patch)
tree3b1c9af312635f7216361f76d223152732ee29f7 /rules.js
parent870052c751ea5c84231eafb8d4a374fb5142ee52 (diff)
downloadnevsky-4f50d6a4f53d69b627948815b6f042e409f689e7.tar.gz
Skip Avoid Battle if impossible.
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/rules.js b/rules.js
index 30e5b5c..077efa9 100644
--- a/rules.js
+++ b/rules.js
@@ -1,6 +1,5 @@
"use strict"
-
// FIXME: lift_sieges / besieged needs checking! (automatic after disband_lord, manual after move/sail, extra careful manual after battle)
// FIXME: remove_legate_if_endangered needs checking! (automatic after disband_lord, manual after move/sail, manual after battle)
@@ -4862,6 +4861,14 @@ function spoil_loot(lord) {
add_spoils(LOOT, 1)
}
+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
+ return false
+}
+
function can_avoid_battle(to, way) {
if (way === game.march.approach)
return false
@@ -4875,10 +4882,15 @@ function can_avoid_battle(to, way) {
function goto_avoid_battle() {
clear_undo()
set_active_enemy()
- game.march.group = game.group // save group
- game.state = "avoid_battle"
- game.spoils = 0
- resume_avoid_battle()
+ if (can_any_avoid_battle()) {
+ // TODO: pre-select lone lord?
+ game.march.group = game.group // save group
+ game.state = "avoid_battle"
+ game.spoils = 0
+ resume_avoid_battle()
+ } else {
+ goto_march_withdraw()
+ }
}
function resume_avoid_battle() {