summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.html52
-rw-r--r--rules.js116
2 files changed, 105 insertions, 63 deletions
diff --git a/play.html b/play.html
index ea2057c..c22f700 100644
--- a/play.html
+++ b/play.html
@@ -219,6 +219,22 @@ svg .side {
stroke-width: 8px;
}
+svg .side.axis_control {
+ stroke: green;
+ stroke-width: 8px;
+ stroke-opacity: 0.8;
+ stroke-dasharray: 54 100;
+ stroke-dashoffset: -8;
+}
+
+svg .side.allied_control {
+ stroke: brown;
+ stroke-width: 8px;
+ stroke-opacity: 0.8;
+ stroke-dasharray: 54 100;
+ stroke-dashoffset: -8;
+}
+
svg .side.axis_supply {
stroke-width: 64px;
stroke-linecap: butt;
@@ -241,22 +257,6 @@ svg .side.allied_supply.axis_supply {
stroke: yellow;
}
-svg .side.axis_control {
- stroke: green;
- stroke-width: 8px;
- stroke-opacity: 0.8;
- stroke-dasharray: 54 100;
- stroke-dashoffset: -8;
-}
-
-svg .side.allied_control {
- stroke: brown;
- stroke-width: 8px;
- stroke-opacity: 0.8;
- stroke-dasharray: 54 100;
- stroke-dashoffset: -8;
-}
-
svg .hex.action {
stroke: white;
stroke-width: 2;
@@ -272,6 +272,16 @@ svg .hex.to {
fill-opacity: 0.2;
}
+svg .hex.axis_control {
+ fill: green;
+ fill-opacity: 0.2;
+}
+
+svg .hex.allied_control {
+ fill: brown;
+ fill-opacity: 0.2;
+}
+
svg .hex.axis_supply {
fill: green;
fill-opacity: 0.3;
@@ -287,16 +297,6 @@ svg .hex.axis_supply.allied_supply {
fill-opacity: 0.3;
}
-svg .hex.axis_control {
- fill: green;
- fill-opacity: 0.2;
-}
-
-svg .hex.allied_control {
- fill: brown;
- fill-opacity: 0.2;
-}
-
svg .hex.tip {
fill: black;
fill-opacity: 0.6;
diff --git a/rules.js b/rules.js
index cb9afff..b1fea97 100644
--- a/rules.js
+++ b/rules.js
@@ -390,7 +390,6 @@ function unit_cv(u) {
}
function unit_hp_per_step(u) {
- // TODO: double defense, minefields, etc
return is_unit_elite(u) ? 2 : 1
}
@@ -634,6 +633,16 @@ function for_each_hex_and_adjacent_hex(here, fn) {
}
}
+function for_each_axis_unit(fn) {
+ for (let u = first_axis_unit; u <= last_axis_unit; ++u)
+ fn(u)
+}
+
+function for_each_allied_unit(fn) {
+ for (let u = first_axis_unit; u <= last_axis_unit; ++u)
+ fn(u)
+}
+
function for_each_friendly_unit(fn) {
// TODO: first/last_enemy_unit
for (let u = 0; u < units.length; ++u)
@@ -820,14 +829,15 @@ function is_side_unit(side, u) {
return is_allied_unit(u)
}
-function list_control_hexes(side) {
- let control = new Array(hexcount).fill(0)
- for (let u = 0; u < units.length; ++u) {
- if (is_side_unit(side, u)) {
- let x = unit_hex(u)
- if (x > 0 && x < hexdeploy)
- control[x] = 1
- }
+function list_control_hexes(control, first_unit, last_unit) {
+ control.fill(0)
+ for (let u = first_unit; u <= last_unit; ++u) {
+ let x = unit_hex(u)
+ if (x >= first_hex && x <= last_hex)
+ if (is_unit_disrupted(u))
+ control[x] |= 1
+ else
+ control[x] |= 2
}
return control
}
@@ -836,11 +846,42 @@ function ind(d, msg, here, ...extra) {
console.log(new Array(d).fill("-").join("") + msg, here, "("+hex_name[here]+")", extra.join(" "))
}
-var supply_visited, supply_friendly, supply_enemy, supply_src, supply_net, supply_line
-var trace_total
+var supply_axis = new Array(hexcount)
+var supply_allied = new Array(hexcount)
+var supply_defender
+var supply_defender_sides
+var supply_visited = new Array(hexcount)
+var supply_src = new Array(hexcount)
+
+var supply_friendly, supply_enemy, supply_src, supply_net, supply_line
var trace_highway
var trace_chain
+function is_supply_line_blocked(here, next, side) {
+ // impassable hexside
+ if (side_limit[side] === 0)
+ return true
+
+ // undisrupted (only) enemies may block supply lines
+ if (supply_enemy[next] > 1) {
+ if (supply_friendly[next] > 1) {
+ // battle hex, can only trace through if defender
+ if (!set_has(supply_defender, next))
+ return true
+ } else {
+ // enemy hex
+ return true
+ }
+ }
+
+ // cannot trace through enemy hexsides
+ if (supply_friendly[here] && supply_enemy[here])
+ if (!set_has(supply_defender_sides, side))
+ return true
+
+ return false
+}
+
function trace_supply_highway(here, d) {
trace_highway++
ind(d, "> highway", here)
@@ -857,18 +898,16 @@ function trace_supply_highway(here, d) {
for (let s = 0; s < 6; ++s) {
let next = here + hexnext[s]
- let side = to_side(here, next, s)
-
- if (side_limit[side] === 0)
- continue
if (supply_visited[next])
continue
- if (supply_enemy[next])
+
+ let side = to_side(here, next, s)
+ if (is_supply_line_blocked(here, next, side))
continue
let road = side_road[side]
if (road === HIGHWAY) {
- if (supply_friendly[next]) {
+ if (supply_friendly[next] > 1) {
ind(d, "? highway head", next)
if (trace_supply_chain(next, d+1, 0, 3)) {
ind(d, "< highway chain", here, next)
@@ -889,7 +928,8 @@ function trace_supply_highway(here, d) {
if (has_supply) {
supply_net[here] = 1
- supply_src[here] = 1
+ if (supply_enemy[here] <= 1)
+ supply_src[here] = 1
}
return has_supply
@@ -910,20 +950,17 @@ function trace_supply_chain(here, d, n, range) {
for (let s = 0; s < 6; ++s) {
let next = here + hexnext[s]
- let side = to_side(here, next, s)
-
- if (side_limit[side] === 0)
- continue
if (supply_visited[next])
continue
- if (supply_enemy[next])
+
+ let side = to_side(here, next, s)
+ if (is_supply_line_blocked(here, next, side))
continue
let road = side_road[side]
-
if (road === HIGHWAY) {
ind(d, "? chain highway", next)
- if (supply_friendly[next]) {
+ if (supply_friendly[next] > 1) {
ind(d, "? chain highway head", next)
if (trace_supply_chain(next, d+1, 0, 3)) {
ind(d, "< highway chain", here, next)
@@ -940,7 +977,7 @@ function trace_supply_chain(here, d, n, range) {
} else {
let next_range = min(range, SUPPLY_RANGE[road])
if (n + 1 <= next_range) {
- if (supply_friendly[next]) {
+ if (supply_friendly[next] > 1) {
ind(d, "? chain head", next)
if (trace_supply_chain(next, d+1, 0, 3)) {
ind(d, "< highway chain", here, next)
@@ -962,16 +999,14 @@ function trace_supply_chain(here, d, n, range) {
if (has_supply) {
supply_net[here] = 1
- if (supply_friendly[here])
+ // undisrupted units can chain supply
+ if (supply_friendly[here] > 1 && supply_enemy[here] <= 1)
supply_src[here] = 1
}
return has_supply
}
-var supply_visited = new Array(hexcount)
-var supply_src = new Array(hexcount)
-
function trace_supply_network(start) {
supply_net = new Array(hexcount)
supply_line = new Array(sidecount)
@@ -989,9 +1024,9 @@ function trace_supply_network(start) {
// debug_hexes("EH", supply_enemy)
// debug_hexes("SS1", supply_src)
- trace_total = 0
- for (let x = first_hex; x <= last_hex; ++x) {
- if (supply_friendly[x]) {
+ var trace_total = 0
+ for (let x of all_hexes) {
+ if (supply_friendly[x] > 0) {
trace_highway = trace_chain = 0
ind(0, "START", x)
trace_supply_chain(x, 0, 0, 3)
@@ -1006,22 +1041,28 @@ function trace_supply_network(start) {
}
function update_axis_supply_network() {
- supply_friendly = list_control_hexes(AXIS)
- supply_enemy = list_control_hexes(ALLIED)
+ supply_defender = game.axis_hexes
+ supply_defender_sides = game.axis_sides
+ supply_friendly = supply_axis
+ supply_enemy = supply_allied
trace_supply_network(EL_AGHEILA)
game.axis_supply = supply_net
game.axis_supply_line = supply_line
}
function update_allied_supply_network() {
- supply_friendly = list_control_hexes(ALLIED)
- supply_enemy = list_control_hexes(AXIS)
+ supply_defender = game.allied_hexes
+ supply_defender_sides = game.allied_sides
+ supply_friendly = supply_allied
+ supply_enemy = supply_axis
trace_supply_network(ALEXANDRIA)
game.allied_supply = supply_net
game.allied_supply_line = supply_line
}
function update_supply_networks() {
+ list_control_hexes(supply_axis, first_axis_unit, last_axis_unit)
+ list_control_hexes(supply_allied, first_allied_unit, last_allied_unit)
update_axis_supply_network()
update_allied_supply_network()
}
@@ -3537,6 +3578,7 @@ exports.view = function(state, current) {
exports.query = function (state, current, q) {
if (q === 'supply') {
game = state
+ update_supply_networks()
return {
axis_supply: game.axis_supply,
axis_supply_line: game.axis_supply_line,