summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js40
1 files changed, 31 insertions, 9 deletions
diff --git a/rules.js b/rules.js
index b004507..2b6bd72 100644
--- a/rules.js
+++ b/rules.js
@@ -17,7 +17,7 @@ var timeout = 0
function check_timeout() {
if (Date.now() > timeout)
- throw new Error("timeout (too many withdrawal options)")
+ throw "TIMEOUT"
}
var states = {}
@@ -3241,9 +3241,15 @@ function goto_move_phase() {
game.rommel = 1
if (game.turn_option === 'pass') {
- save_withdrawal_supply_lines()
- game.group = list_valid_withdrawal_group_moves()
- game.regroup = list_valid_withdrawal_regroup_command_points()
+ try {
+ save_withdrawal_supply_lines()
+ game.group = list_valid_withdrawal_group_moves()
+ game.regroup = list_valid_withdrawal_regroup_command_points()
+ } catch (err) {
+ if (err !== "TIMEOUT")
+ throw err
+ game.state = 'select_moves_timeout'
+ }
} else {
game.group = list_valid_group_moves()
game.regroup = list_valid_regroup_moves()
@@ -3258,6 +3264,8 @@ function show_move_commands() {
}
function has_valid_group_move_left() {
+ if (!game.group)
+ return false
if (game.group.length > 1)
return true
if (game.group.length > 0) {
@@ -3293,6 +3301,13 @@ states.select_moves = {
view.prompt = `Movement: Designate ${game.turn_option} move.`
}
+ if (game.state === 'select_moves_timeout') {
+ if (game.group && !game.regroup)
+ view.prompt = "Movement: Computation timed out. Regroup moves not available."
+ else
+ view.prompt = "Movement: Computation timed out. Some moves may not be available."
+ }
+
let can_group_move = has_valid_group_move_left() ? 1 : 0
let can_regroup_move = has_valid_regroup_move_left() ? 1 : 0
@@ -3347,6 +3362,8 @@ states.select_moves = {
},
}
+states.select_moves_timeout = states.select_moves
+
function list_valid_group_moves() {
let result = []
for (let x of all_hexes) {
@@ -3375,13 +3392,18 @@ function list_valid_withdrawal_group_moves() {
set_add(result, TOBRUK)
mandatory = true
}
- if (!mandatory) {
- for (let x of all_hexes) {
- if (has_undisrupted_friendly_unit(x)) {
- if (is_valid_withdrawal_group_move_from(x))
- set_add(result, x)
+ try {
+ if (!mandatory) {
+ for (let x of all_hexes) {
+ if (has_undisrupted_friendly_unit(x)) {
+ if (is_valid_withdrawal_group_move_from(x))
+ set_add(result, x)
+ }
}
}
+ } catch (err) {
+ if (err !== "TIMEOUT")
+ throw err
}
return result
}