summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-01-03 18:06:07 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-03 23:58:59 +0100
commitfb54e6b4b0df7b90ffd68124400fefda0af89d09 (patch)
treedfa2131a4d026a1acddd601e2efed46a54365a6b
parent165421013f25743df1b8ac52a8ca2c5c668fc870 (diff)
downloadrommel-in-the-desert-fb54e6b4b0df7b90ffd68124400fefda0af89d09.tar.gz
Fix supply search optimization.
-rw-r--r--rules.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/rules.js b/rules.js
index d6efbf3..88a977f 100644
--- a/rules.js
+++ b/rules.js
@@ -1361,9 +1361,18 @@ function trace_unit_supply_line(path, here, here_move, ssrc) {
if (next_move === TRACE_ABORT)
continue
- // reached supply source, or reached supplied highway (that we searched before)
- /* if (next === ssrc) -- fallback without short cut in case the optimization below is wrong... */
- if (next === ssrc || (hex_road[next] === HIGHWAY && supply_net[next] === 2)) {
+ let reached = (next === ssrc)
+ if (!reached) {
+ // Stop searching if we reach a supplied highway,
+ // but only if we can't continue by trail or track.
+ // Example: Tobruk - EL Adem - Sidi Rezegh - Ft. Capuzzo
+ if (hex_road[next] === HIGHWAY && supply_net[next] === 2)
+ if (next_move === BACK_HIGHWAY_3 || next_move === BACK_STOP)
+ reached = true
+ }
+
+ // reached supply source
+ if (reached) {
for (let x of path)
supply_line[x] = 2
supply_line[side] = 2