ai_helper.move_unit_out_of_way: prevent potential for divide-by-zero

dx = dy = 0 is a perfectly acceptable choice of values when there is no preferred direction.
This commit is contained in:
mattsc 2018-10-21 19:25:46 -07:00
parent 7f7217cf15
commit 09e3891668

View file

@ -1464,7 +1464,7 @@ function ai_helper.move_unit_out_of_way(ai, unit, cfg)
local dx, dy
if cfg.dx and cfg.dy then
local r = math.sqrt(cfg.dx * cfg.dx + cfg.dy * cfg.dy)
dx, dy = cfg.dx / r, cfg.dy / r
if (r ~= 0) then dx, dy = cfg.dx / r, cfg.dy / r end
end
local reach = wesnoth.find_reach(unit, cfg)