summaryrefslogtreecommitdiff
path: root/rules.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-03-09 12:00:38 +0100
committerTor Andersson <tor@ccxvii.net>2023-03-09 12:00:38 +0100
commit09fded7925fe932927c8308de446e29d03d8eccd (patch)
treee675fcce3aa2d5c1b99303229b8f296ee0ea1906 /rules.js
parent609a7d051dba455b9f37bc68ab8ab15059f45fa6 (diff)
downloadrommel-in-the-desert-09fded7925fe932927c8308de446e29d03d8eccd.tar.gz
Allow backtracking from supply chains!
A supply chain can backtrack over another supply chain. Example: Axis Unit A is in supply in Skeleidima. It can trace supply via Ghemines. It can also trace supply via Msus/Antelat/Agedabia. Axis Unit B in Mechili SW can trace a line to A in Skeleidima. This line overlaps with the Skeleidima/Msus/Antelat line, and our "don't backtrack" code would either prevent one of these lines from forming. Track the "visit depth" instead of a boolean, and increase the depth every time we start a new supply line. Allow re-visits of a hex unless it's been visited before during this depth, or unless it is the head of a supply line.
Diffstat (limited to 'rules.js')
-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() {