summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js38
1 files changed, 31 insertions, 7 deletions
diff --git a/play.js b/play.js
index 1558960..26626ce 100644
--- a/play.js
+++ b/play.js
@@ -122,10 +122,13 @@ const adjacent_cn = [ "r3", "r2", "r4", "r1", "r5", "r0" ]
const data_rivers = []
const data_bridges = []
+const data_rivers_and_bridges = []
for (let [a, b] of data.map.rivers) {
set_add(data_rivers, a * 10000 + b)
set_add(data_rivers, b * 10000 + a)
+ set_add(data_rivers_and_bridges, a * 10000 + b)
+ set_add(data_rivers_and_bridges, b * 10000 + a)
}
for (let [a, b] of data.map.bridges) {
@@ -817,6 +820,10 @@ function is_bridge(a, b) {
return set_has(data_bridges, a * 10000 + b)
}
+function is_river_or_bridge(a, b) {
+ return set_has(data_rivers_and_bridges, a * 10000 + b)
+}
+
function piece_hex(p) {
return view.pieces[p] >> 1
}
@@ -829,24 +836,41 @@ function for_each_adjacent(x, f) {
}
}
-function update_zoc_imp(zoc, zoi, units) {
+function recalc_zoc(zoc, units) {
for (let p of units) {
let a = piece_hex(p)
zoc_cache[a - 1000] |= zoc
for_each_adjacent(a, b => {
if (!is_river(a, b)) {
zoc_cache[b - 1000] |= zoc
- if (zoi) {
- for_each_adjacent(b, c => {
- if (!is_bridge(b, c))
- zoc_cache[c - 1000] |= zoi
- })
- }
}
})
}
}
+function recalc_zoi(zoi, units) {
+ for (let p of units) {
+ let a = piece_hex(p)
+ zoc_cache[a - 1000] |= zoi
+ for_each_adjacent(a, (b) => {
+ if (!is_river_or_bridge(a, b)) {
+ zoc_cache[b - 1000] |= zoi
+ for_each_adjacent(b, (c) => {
+ if (!is_river_or_bridge(b, c)) {
+ zoc_cache[c - 1000] |= zoi
+ }
+ })
+ }
+ })
+ }
+}
+
+function update_zoc_imp(zoc, zoi, units) {
+ recalc_zoc(zoc, units)
+ if (zoi)
+ recalc_zoi(zoi, units)
+}
+
function update_zoc() {
zoc_cache.fill(0)
update_zoc_imp(1, 4, p1_corps)