Zone Guardian MAI: ensure functionality even if no goal hex is found

In that case, the guardian stays put where it is.
This commit is contained in:
mattsc 2013-06-27 12:24:45 -07:00
parent 79f2147034
commit 1e02ffc77b

View file

@ -262,8 +262,15 @@ return {
end
local locs = locs_map:to_pairs()
local newind = math.random(#locs)
newpos = {locs[newind][1], locs[newind][2]}
-- If possible locations were found, move unit toward a random one,
-- otherwise the unit stays where it is
if (#locs > 0) then
local newind = math.random(#locs)
newpos = { locs[newind][1], locs[newind][2] }
else
newpos = { unit.x, unit.y }
end
end
-- Next hop toward that position