|
|
local function FindNearestMovePos(x, y)
local MAP_MIN = 0
local MAP_MAX = 63
local BLOCK_VALUE = 255
local SEARCH_RANGE = 128
local function canMoveTo(nx, ny)
return nx > MAP_MIN
and nx < MAP_MAX
and ny > MAP_MIN
and ny < MAP_MAX
and GetWarMap(nx, ny, 3) ~= BLOCK_VALUE
and War_CanMoveXY(nx, ny, 0)
end
for s = 1, SEARCH_RANGE do
for i = 1, s do
local j = s - i
local nx, ny
nx, ny = x + i, y + j
if canMoveTo(nx, ny) then
return nx, ny
end
nx, ny = x + j, y - i
if canMoveTo(nx, ny) then
return nx, ny
end
nx, ny = x - i, y - j
if canMoveTo(nx, ny) then
return nx, ny
end
nx, ny = x - j, y + i
if canMoveTo(nx, ny) then
return nx, ny
end
end
end
return nil, nil
end |
|