From a666a34055b36a88dab2bcdbcd6119684ba67b9b Mon Sep 17 00:00:00 2001 From: mattsc Date: Tue, 7 Jul 2020 20:14:11 -0700 Subject: [PATCH] ai_helper.next_hop: fix bug in fan-out code This fixes the case when the unit cannot reach the previously found next_hop location from the ideal next_hop location in the part of the code that tries to keep units from moving in single file. --- data/ai/lua/ai_helper.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index 807f6cf0abfa..ff4c21857f13 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -1531,7 +1531,9 @@ function ai_helper.next_hop(unit, x, y, cfg) local unit_map = LS.create() for _,u in ipairs(units) do unit_map:insert(u.x, u.y, u.id) end - local max_rating = inverse_reach_map:get(next_hop[1], next_hop[2]) -- do not move farther away + -- Do not move farther away, but if next_hop is out of reach from next_hop_ideal, + -- anything in reach is better -> set to -infinity in that case. + local max_rating = inverse_reach_map:get(next_hop[1], next_hop[2]) or - math.huge for _,loc in ipairs(reach) do if (not unit_map:get(loc[1], loc[2])) and ((not cfg) or (not cfg.avoid_map) or (not cfg.avoid_map:get(loc[1], loc[2])))