summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-07-04 16:41:26 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:25 +0100
commit689061a44d01813f2cd9faf0299321d0a1d6498a (patch)
treecb6de7cf3ffd3c1b0c02f2f8b4154ae2240cb094 /play.js
parente8a5f5410a0e876d889a2a8137c34bb925f65408 (diff)
downloadrommel-in-the-desert-689061a44d01813f2cd9faf0299321d0a1d6498a.tar.gz
Moves.
Diffstat (limited to 'play.js')
-rw-r--r--play.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/play.js b/play.js
index 0c116bf..125bb19 100644
--- a/play.js
+++ b/play.js
@@ -6,6 +6,26 @@ const svgNS = "http://www.w3.org/2000/svg"
const round = Math.round
const sqrt = Math.sqrt
+function set_index(set, item) {
+ let a = 0
+ let b = set.length - 1
+ while (a <= b) {
+ let m = (a + b) >> 1
+ let x = set[m]
+ if (item < x)
+ b = m - 1
+ else if (item > x)
+ a = m + 1
+ else
+ return m
+ }
+ return -1
+}
+
+function set_has(set, item) {
+ return set_index(set, item) >= 0
+}
+
let ui = {
hexes: [],
sides: [],
@@ -52,6 +72,22 @@ function is_hex_axis_supply(hex) {
return view.axis_supply[hex] > 0
}
+function is_hex_axis_controlled(hex) {
+ return set_has(view.axis_hexes, hex)
+}
+
+function is_hex_allied_controlled(hex) {
+ return set_has(view.allied_hexes, hex)
+}
+
+function is_side_axis_controlled(side) {
+ return set_has(view.axis_sides, side)
+}
+
+function is_side_allied_controlled(side) {
+ return set_has(view.allied_sides, side)
+}
+
function is_side_axis_supply_line(side) {
return view.axis_supply_line[side] > 0
}
@@ -236,7 +272,7 @@ function build_hexes() {
for (let month = 1; month <= 20; ++month) {
ui.hex_y[map_w * map_h + month] = 24 + 37
- ui.hex_x[map_w * map_h + month] = 1000 + 37 + (month-1) * 81
+ ui.hex_x[map_w * map_h + month] = 1840 + 37 + (month-1) * 81
}
document.getElementById("mapsvg").getElementById("grid").setAttribute("d", path.join(" "))
@@ -315,9 +351,16 @@ function update_map() {
e.classList.toggle("action", is_unit_action(u))
e.classList.toggle("selected", is_unit_selected(u))
+ e.classList.toggle("disrupted", is_unit_disrupted(u))
+ e.classList.toggle("moved", is_unit_moved(u))
+ // e.classList.toggle("unsupplied", !is_unit_supplied(u))
}
if (ui.hexes[hex]) {
ui.hexes[hex].classList.toggle("action", is_hex_action(hex))
+ ui.hexes[hex].classList.toggle("from", hex === view.from1 || hex === view.from2)
+ ui.hexes[hex].classList.toggle("to", hex === view.to1 || hex === view.to2)
+ ui.hexes[hex].classList.toggle("axis_control", is_hex_axis_controlled(hex))
+ ui.hexes[hex].classList.toggle("allied_control", is_hex_allied_controlled(hex))
if (view.axis_supply) {
ui.hexes[hex].classList.toggle("axis_supply", is_hex_axis_supply(hex))
for (let s = 0; s < 3; ++s)
@@ -328,6 +371,10 @@ function update_map() {
for (let s = 0; s < 3; ++s)
ui.sides[hex*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(hex*3+s))
}
+ for (let s = 0; s < 3; ++s) {
+ ui.sides[hex*3+s].classList.toggle("axis_control", is_side_axis_controlled(hex*3+s))
+ ui.sides[hex*3+s].classList.toggle("allied_control", is_side_allied_controlled(hex*3+s))
+ }
}
}
}