summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-04-17 18:48:28 +0200
committerTor Andersson <tor@ccxvii.net>2024-04-17 19:03:43 +0200
commitfff8c6c9701ef875f8a2d134f24f82cdce9ec089 (patch)
tree3333579678c02164dc54bd760eb6a553c5c05bbb
parent0cf8ffac378f451b2230f8466bf962260ad43de4 (diff)
downloadrommel-in-the-desert-master.tar.gz
Fix own supply line search.HEADmaster
It was not returning any results if the supply line had to deviate from the closest path at any point.
-rw-r--r--rules.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/rules.js b/rules.js
index f8689d2..b004507 100644
--- a/rules.js
+++ b/rules.js
@@ -1780,10 +1780,6 @@ function search_own_supply_line_rec(path, here, ssrc, sline, sdist) {
let side = to_side(here, next, s)
- // must move closer (because we only search supply line for withdrawal purposes)
- if (sdist[next] > sdist[here] && side !== BARDIA_FT_CAPUZZO)
- continue
-
// must follow supply line
if (sline[side] === 0)
continue
@@ -2146,6 +2142,10 @@ function unit_has_supply_line(who) {
return false
}
+function is_move_closer(sdist, from, to, side) {
+ return side === BARDIA_FT_CAPUZZO || sdist[to] <= sdist[from]
+}
+
function can_unit_withdraw(who) {
let result = false
if (unit_has_supply_line(who)) {
@@ -2157,7 +2157,7 @@ function can_unit_withdraw(who) {
for_each_adjacent_hex(from, to => {
let side = to_side_id(from, to)
if (side_limit[side] > 0 && !has_enemy_unit(to))
- if (own_supply_line[side] && sdist[to] <= sdist[from])
+ if (own_supply_line[side] && is_move_closer(sdist, from, to, side))
result = true
})
}
@@ -2175,7 +2175,7 @@ function can_unit_disengage_and_withdraw(who) {
for_each_adjacent_hex(from, to => {
let side = to_side_id(from, to)
if (side_limit[side] > 0 && !is_enemy_hexside(side) && !has_undisrupted_enemy_unit(to))
- if (own_supply_line[side] && sdist[to] <= sdist[from])
+ if (own_supply_line[side] && is_move_closer(sdist, from, to, side))
result = true
})
}