for s = 1, 128 do
for i = 1, s do
local j = s - i
if x + i < 63 and y + j < 63 and GetWarMap(x + i, y + j, 3) ~= 255 and War_CanMoveXY(x + i, y + j, 0) then
return x + i, y + j
end
if x + j < 63 and y - i > 0 and GetWarMap(x + j, y - i, 3) ~= 255 and War_CanMoveXY(x + j, y - i, 0) then
return x + j, y - i
end
if x - i > 0 and y - j > 0 and GetWarMap(x - i, y - j, 3) ~= 255 and War_CanMoveXY(x - i, y - j, 0) then
return x - i, y - j
end
if x - j > 0 and y + i < 63 and GetWarMap(x - j, y + i, 3) ~= 255 and War_CanMoveXY(x - j, y + i, 0) then
return x - j, y + i
end
end
end
end
今天研究WE_xy函数,才发现构思真的是太精妙了。想问一下这是谁写的?鱼神吗?这样人物今在哪?
顺问一下:WE_xy中的WE是什么意思?什么单词的缩写?war e?
感觉其实就是以(x, y)为中心,一圈一圈向外搜索,找到最近的可以移动坐标。
63和0应该是检查目标点是不是在地图内。。。
GetWarMap()函数应该是检查目标点不是墙或者障碍。。。
War_CanMoveXY()应该是检查目标点与起始点在同一连通块,可以移动过去。。
类似一个BFS的感觉。。。
以上是纯看代码瞎猜的。。
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