summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-08-06 16:40:32 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:26 +0100
commit6c381c875b9f469ff8d32f0b900ba76201283df9 (patch)
tree037e1d9429fb4170cabf0e292d5f038b3b294bcd
parent38f5d4dd069953d5a03787e9e593914e73ea4cfd (diff)
downloadrommel-in-the-desert-6c381c875b9f469ff8d32f0b900ba76201283df9.tar.gz
Fix bug in supply network calculations.
Setting supply_src on highway prevents certain chains forming. Remove broken optimization.
-rw-r--r--rules.js26
1 files changed, 8 insertions, 18 deletions
diff --git a/rules.js b/rules.js
index 89fd3b7..0930ef5 100644
--- a/rules.js
+++ b/rules.js
@@ -1130,7 +1130,7 @@ function ind(d, msg, here, ...extra) {
var supply_defender, supply_defender_sides, supply_friendly, supply_enemy, supply_net, supply_line, supply_fortress_enemy
var supply_visited = new Array(hexcount).fill(0)
-var supply_src = new Array(hexcount).fill(0)
+var supply_src = 0
var trace_total
@@ -1164,7 +1164,7 @@ function trace_supply_highway(here, d) {
ind(d, "> highway", here)
// TODO: hoist to call sites to avoid function call overhead
- if (supply_src[here]) {
+ if (supply_src === here) {
ind(d, "! source highway", here)
return true
}
@@ -1207,11 +1207,8 @@ function trace_supply_highway(here, d) {
supply_visited[here] = 0
- if (has_supply) {
+ if (has_supply)
supply_net[here] = 1
- if (supply_enemy[here] <= 1)
- supply_src[here] = 1
- }
return has_supply
}
@@ -1220,7 +1217,7 @@ function trace_supply_chain(here, d, n, range) {
trace_total++
ind(d, "> chain", here, n, range)
- if (supply_src[here]) {
+ if (supply_src === here) {
ind(d, "! source chain", here)
return true
}
@@ -1282,23 +1279,18 @@ function trace_supply_chain(here, d, n, range) {
supply_visited[here] = 0
- if (has_supply) {
+ if (has_supply)
supply_net[here] = 1
- // undisrupted units can chain supply
- if (supply_friendly[here] > 1 && supply_enemy[here] <= 1)
- supply_src[here] = 1
- }
return has_supply
}
function trace_supply_network(start, ss) {
supply_visited.fill(0)
- supply_src.fill(0)
supply_net.fill(0)
supply_line.fill(0)
- supply_src[start] = 1
+ supply_src = start
supply_net[start] = 1
trace_total = 0
@@ -1311,11 +1303,10 @@ function trace_supply_network(start, ss) {
function trace_fortress_network(fortress, ss) {
supply_visited.fill(0)
- supply_src.fill(0)
supply_net.fill(0)
supply_line.fill(0)
- supply_src[fortress] = 1
+ supply_src = fortress
supply_net[fortress] = 1
trace_total = 0
@@ -1358,8 +1349,7 @@ function init_trace_supply_to_base_or_fortress() {
function can_trace_supply_to_base_or_fortress(base, from) {
supply_visited.fill(0)
- supply_src.fill(0)
- supply_src[base] = 1
+ supply_src = base
return trace_supply_chain(from, 0, 0, 3)
}