summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-07-02 15:57:11 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-02 15:57:33 +0200
commita31dcb4819c0524d9fdf6eb202fef09f30d4051d (patch)
treeee4e61e8b4bcc2d60171f39b1784999ba7431bcc
parent7a99a95a616a73073982e2432b49f57c23135859 (diff)
downloadwilderness-war-a31dcb4819c0524d9fdf6eb202fef09f30d4051d.tar.gz
New undo functions.
Can handle supply queries during replay without crashing on clear undo.
-rw-r--r--rules.js51
1 files changed, 24 insertions, 27 deletions
diff --git a/rules.js b/rules.js
index b7de0e4..8399cad 100644
--- a/rules.js
+++ b/rules.js
@@ -9595,34 +9595,38 @@ exports.setup = function (seed, scenario, options) {
// ACTION HANDLERS
function clear_undo() {
- if (game.undo.length > 0)
+ if (game.undo && game.undo.length > 0)
game.undo.length = 0
}
function push_undo() {
- let copy = {}
- for (let k in game) {
- let v = game[k]
- if (k === "undo") continue
- else if (k === "log") v = v.length
- else if (k === "retro_foul_weather") v = 1
- else if (typeof v === "object" && v !== null) v = object_copy(v)
- copy[k] = v
+ if (game.undo) {
+ let copy = {}
+ for (let k in game) {
+ let v = game[k]
+ if (k === "undo") continue
+ else if (k === "log") v = v.length
+ else if (k === "retro_foul_weather") v = 1
+ else if (typeof v === "object" && v !== null) v = object_copy(v)
+ copy[k] = v
+ }
+ game.undo.push(copy)
}
- game.undo.push(copy)
}
function pop_undo() {
- let save_log = game.log
- let save_undo = game.undo
- let save_retro_fw = game.retro_foul_weather
- game = save_undo.pop()
- save_log.length = game.log
- game.log = save_log
- game.undo = save_undo
- if (game.retro_foul_weather)
- game.retro_foul_weather = save_retro_fw
- update_active_aliases()
+ if (game.undo) {
+ let save_log = game.log
+ let save_undo = game.undo
+ let save_retro_fw = game.retro_foul_weather
+ game = save_undo.pop()
+ save_log.length = game.log
+ game.log = save_log
+ game.undo = save_undo
+ if (game.retro_foul_weather)
+ game.retro_foul_weather = save_retro_fw
+ update_active_aliases()
+ }
}
function gen_action_undo() {
@@ -9715,13 +9719,6 @@ exports.query = function (state, current, q) {
return null
}
-exports.is_checkpoint = function (a, b) {
- let x = b.log[b.log.length-2]
- if (x === ".h2 Britain") return true
- if (x === ".h2 France") return true
- return false
-}
-
function inactive_prompt(name, who, where) {
view.prompt = `Waiting for ${game.active} \u2014 ${name}...`
if (who)