Skip to content

Commit

Permalink
ai_helper.next_hop: fix bug in fan-out code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattsc committed Jul 8, 2020
1 parent f620314 commit a666a34
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion data/ai/lua/ai_helper.lua
Expand Up @@ -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])))
Expand Down

0 comments on commit a666a34

Please sign in to comment.