From fff8c6c9701ef875f8a2d134f24f82cdce9ec089 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 17 Apr 2024 18:48:28 +0200 Subject: Fix own supply line search. It was not returning any results if the supply line had to deviate from the closest path at any point. --- rules.js | 12 ++++++------ 1 file 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 }) } -- cgit v1.2.3