summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
Diffstat (limited to 'rules.js')
-rw-r--r--rules.js108
1 files changed, 79 insertions, 29 deletions
diff --git a/rules.js b/rules.js
index b650c97..314d7dc 100644
--- a/rules.js
+++ b/rules.js
@@ -1610,6 +1610,16 @@ function print_path(who, from, to, road) {
log(">" + p.join(" - ") + ".")
}
+function show_path(from, to, p, speed) {
+ let road = can_move_road(to, speed)
+ p.push(to)
+ while (to && to !== from) {
+ to = path_from[road][to]
+ p.push(to)
+ }
+ return p
+}
+
// normal move: may not leave battle hex. may engage any enemy. may move freely.
// normal withdrawal: may not leave battle hex. may engage disrupted enemy. must follow supply lines.
// retreat move: must leave battle hex via friendly side. may ignore disrupted enemy. may move freely.
@@ -1834,6 +1844,18 @@ function search_path_redeploy_bfs(cost, start, road) {
}
}
+function can_move_road(to, speed) {
+ if (path_cost[4][to] <= speed + 4)
+ return 4
+ if (path_cost[2][to] <= speed + 2)
+ return 2
+ if (path_cost[1][to] <= speed + 1)
+ return 1
+ if (path_cost[0][to] <= speed)
+ return 0
+ return -1
+}
+
function can_move_to(to, speed) {
if (path_cost[4][to] <= speed + 4)
return true
@@ -3370,47 +3392,44 @@ function goto_overrun(where) {
goto_rout(where, true, null)
}
+function do_gen_move_to(from, to, speed) {
+ if (can_move_to(to, speed)) {
+ gen_action_hex(to)
+ // view.path[to] = show_path(from, to, [], speed)
+ } else if (can_move_to(to, speed + 1)) {
+ gen_action_forced_march(to)
+ // view.path[to] = show_path(from, to, [], speed + 1)
+ }
+}
+
function gen_move() {
let rommel1 = (game.rommel === 1) ? 1 : 0
let rommel2 = (game.rommel === 2) ? 1 : 0
let speed = unit_speed[game.selected]
let from = unit_hex(game.selected)
+ // view.path = {}
+
if (!game.to1 && game.from1 === from) {
for (let to of all_hexes) {
- if (to != from) {
- if (can_move_to(to, speed + rommel1))
- gen_action_hex(to)
- else if (can_move_to(to, speed + 1 + rommel1))
- gen_action_forced_march(to)
- }
+ if (to != from)
+ do_gen_move_to(from, to, speed + rommel1)
}
}
if (!game.to2 && game.from2 === from) {
for (let to of all_hexes) {
- if (to != from) {
- if (can_move_to(to, speed + rommel2))
- gen_action_hex(to)
- else if (can_move_to(to, speed + 1 + rommel2))
- gen_action_forced_march(to)
-
- }
+ if (to != from)
+ do_gen_move_to(from, to, speed + rommel2)
}
}
if (game.to1 && is_hex_or_adjacent_to(from, game.from1)) {
- if (can_move_to(game.to1, speed + rommel1))
- gen_action_hex(game.to1)
- else if (can_move_to(game.to1, speed + 1 + rommel1))
- gen_action_forced_march(game.to1)
+ do_gen_move_to(from, game.to1, speed + rommel1)
}
if (game.to2 && is_hex_or_adjacent_to(from, game.from2)) {
- if (can_move_to(game.to2, speed + rommel2))
- gen_action_hex(game.to2)
- else if (can_move_to(game.to2, speed + 1 + rommel2))
- gen_action_forced_march(game.to2)
+ do_gen_move_to(from, game.to2, speed + rommel2)
}
}
@@ -3419,24 +3438,32 @@ function gen_withdraw() {
let speed = unit_speed[game.selected]
let from = unit_hex(game.selected)
+ // view.path = {}
+
// Group Move Withdraw
if (!game.to1) {
for (let to of all_hexes) {
if (to != from) {
- if (can_move_to(to, speed + rommel1) && set_has(game.withdraw, to))
+ if (can_move_to(to, speed + rommel1) && set_has(game.withdraw, to)) {
gen_action_hex(to)
- else if (can_move_to(to, speed + 1 + rommel1) && set_has(game.withdraw, to))
+ // view.path[to] = show_path(from, to, [], speed + rommel1)
+ } else if (can_move_to(to, speed + 1 + rommel1) && set_has(game.withdraw, to)) {
gen_action_forced_march(to)
+ // view.path[to] = show_path(from, to, [], speed + 1 + rommel1)
+ }
}
}
}
// Regroup Move Withdraw
if (game.to1) {
- if (can_move_to(game.to1, speed + rommel1))
+ if (can_move_to(game.to1, speed + rommel1)) {
gen_action_hex(game.to1)
- else if (can_move_to(game.to1, speed + 1 + rommel1))
+ // view.path[game.to1] = show_path(from, game.to1, [], speed + rommel1)
+ } else if (can_move_to(game.to1, speed + 1 + rommel1)) {
gen_action_forced_march(game.to1)
+ // view.path[game.to1] = show_path(from, game.to1, [], speed + 1 + rommel1)
+ }
}
}
@@ -3588,8 +3615,18 @@ states.forced_march_via = {
prompt() {
view.prompt = `Move: Select which path to take.`
view.selected = game.hexside.who
- for (let x of game.hexside.via)
+
+ // view.path = {}
+
+ let rommel = (game.hexside.move === game.rommel) ? 1 : 0
+ let from = unit_hex(game.hexside.who)
+ let speed = unit_speed[game.hexside.who]
+ search_move(from, speed + 1 + rommel)
+
+ for (let x of game.hexside.via) {
gen_action_hex(x)
+ // view.path[x] = show_path(from, x, [ game.hexside.to ], speed + rommel)
+ }
},
hex(via) {
let rommel = (game.hexside.move === game.rommel) ? 1 : 0
@@ -3609,11 +3646,23 @@ states.engage_via = {
prompt() {
view.prompt = `Move: Select which hex side to cross.`
view.selected = game.hexside.who
- for (let i = 0; i < game.hexside.via.length; ++i)
+
+ // view.path = {}
+
+ let rommel = (game.hexside.move === game.rommel) ? 1 : 0
+ let who = game.hexside.who
+ let from = unit_hex(who)
+ let speed = unit_speed[who]
+ search_move(from, speed + rommel)
+
+ for (let i = 0; i < game.hexside.via.length; ++i) {
+ let x = game.hexside.via[i]
if (game.hexside.forced[i])
- gen_action_forced_march(game.hexside.via[i])
+ gen_action_forced_march(x)
else
- gen_action_hex(game.hexside.via[i])
+ gen_action_hex(x)
+ // view.path[x] = show_path(from, x, [ game.hexside.to ], speed + rommel)
+ }
},
forced_march(via) {
let rommel = (game.hexside.move === game.rommel) ? 1 : 0
@@ -6069,6 +6118,7 @@ states.free_deployment = {
let axis = (game.active === AXIS)
view.prompt = `Setup: ${game.active} Deployment.`
+ view.deploy = 1
// view.prompt = `Setup: Deploy units in a supplied location in the setup area.`
let done = true