summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules.js36
1 files changed, 20 insertions, 16 deletions
diff --git a/rules.js b/rules.js
index dfacafe..3408f96 100644
--- a/rules.js
+++ b/rules.js
@@ -1165,13 +1165,14 @@ function is_supply_line_blocked(here, next, side) {
return false
}
-function trace_supply_highway(here) {
+function trace_supply_highway(here, v) {
if (supply_src[here])
return true
let has_supply = false
- supply_visited[here] = 1
+ let save_v = supply_visited[here]
+ supply_visited[here] = v
for (let s = 0; s < 6; ++s) {
let next = here + hexnext[s]
@@ -1179,7 +1180,8 @@ function trace_supply_highway(here) {
if (next < first_hex || next > last_hex || !hex_exists[next])
continue
- if (supply_visited[next])
+ let next_v = supply_visited[next]
+ if (next_v === v || (next_v > 0 && supply_friendly[next] > 1))
continue
let side = to_side(here, next, s)
@@ -1189,12 +1191,12 @@ function trace_supply_highway(here) {
let road = side_road[side]
if (road === HIGHWAY) {
if (supply_friendly[next] > 1) {
- if (supply_net[next] || trace_supply_chain(next, 0, 3)) {
+ if (supply_net[next] || trace_supply_chain(next, 0, 3, v+1)) {
supply_line[side] = 1
has_supply = true
}
} else {
- if (trace_supply_highway(next)) {
+ if (trace_supply_highway(next, v)) {
supply_line[side] = 1
has_supply = true
}
@@ -1202,7 +1204,7 @@ function trace_supply_highway(here) {
}
}
- supply_visited[here] = 0
+ supply_visited[here] = save_v
if (has_supply)
supply_net[here] = 1
@@ -1210,13 +1212,14 @@ function trace_supply_highway(here) {
return has_supply
}
-function trace_supply_chain(here, n, range) {
+function trace_supply_chain(here, n, range, v) {
if (supply_src[here])
return true
let has_supply = false
- supply_visited[here] = 1
+ let save_v = supply_visited[here]
+ supply_visited[here] = v
for (let s = 0; s < 6; ++s) {
let next = here + hexnext[s]
@@ -1224,7 +1227,8 @@ function trace_supply_chain(here, n, range) {
if (next < first_hex || next > last_hex || !hex_exists[next])
continue
- if (supply_visited[next])
+ let next_v = supply_visited[next]
+ if (next_v === v || (next_v > 0 && supply_friendly[next] > 1))
continue
let side = to_side(here, next, s)
@@ -1233,7 +1237,7 @@ function trace_supply_chain(here, n, range) {
let road = side_road[side]
if (road === HIGHWAY) {
- if (trace_supply_highway(next)) {
+ if (trace_supply_highway(next, v)) {
supply_line[side] = 1
has_supply = true
}
@@ -1242,12 +1246,12 @@ function trace_supply_chain(here, n, range) {
let next_range = min(range, SUPPLY_RANGE[road])
if (n + 1 <= next_range) {
if (supply_friendly[next] > 1) {
- if (supply_net[next] || trace_supply_chain(next, 0, 3)) {
+ if (supply_net[next] || trace_supply_chain(next, 0, 3, v+1)) {
supply_line[side] = 1
has_supply = true
}
} else {
- if (trace_supply_chain(next, n + 1, next_range)) {
+ if (trace_supply_chain(next, n + 1, next_range, v)) {
supply_line[side] = 1
has_supply = true
}
@@ -1255,7 +1259,7 @@ function trace_supply_chain(here, n, range) {
}
}
- supply_visited[here] = 0
+ supply_visited[here] = save_v
if (has_supply)
supply_net[here] = 1
@@ -1289,7 +1293,7 @@ function trace_supply_network(start) {
if (supply_friendly[x] > 0 && x !== start) {
if (supply_friendly[x] > 1 && supply_net[x])
continue
- trace_supply_chain(x, 0, 3)
+ trace_supply_chain(x, 0, 3, 1)
}
}
}
@@ -1312,7 +1316,7 @@ function trace_fortress_network(fortress, ss) {
if (is_map_hex(x) && x !== fortress) {
if (supply_friendly[x] > 1 && supply_net[x])
continue
- trace_supply_chain(x, 0, 3)
+ trace_supply_chain(x, 0, 3, 1)
}
}
}
@@ -1348,7 +1352,7 @@ function can_trace_supply_to_base_or_fortress(base, from) {
supply_visited.fill(0)
supply_src.fill(0)
supply_src[base] = 1
- return trace_supply_chain(from, 0, 3)
+ return trace_supply_chain(from, 0, 3, 1, 1)
}
function update_axis_supply() {