keep direction for an more optimised moving scheme
This commit is contained in:
24
src/main.lua
24
src/main.lua
@@ -292,9 +292,7 @@ local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling)
|
||||
end
|
||||
return selected
|
||||
end
|
||||
local function moveto(x,y,cx,cz)
|
||||
local direction = 0
|
||||
local function center(wanted)
|
||||
local function center(direction, wanted)
|
||||
if direction == 1 and wanted ~= 1 then
|
||||
move("left")
|
||||
end
|
||||
@@ -302,35 +300,35 @@ local function moveto(x,y,cx,cz)
|
||||
move("right")
|
||||
end
|
||||
end
|
||||
local function moveto(x,y,cx,cz,direction)
|
||||
while x ~= cx or y ~= cz do
|
||||
if x > cx then -- x
|
||||
center()
|
||||
center(direction)
|
||||
cx = cx + 1
|
||||
move("forward")
|
||||
end
|
||||
if x < cx then
|
||||
center()
|
||||
center(direction)
|
||||
cx = cx - 1
|
||||
move("back")
|
||||
end
|
||||
|
||||
if y > cz then -- z
|
||||
center(1)
|
||||
center(direction, 1)
|
||||
cz = cz + 1
|
||||
move("right")
|
||||
move("forward")
|
||||
direction = 1
|
||||
end
|
||||
if y < cz then
|
||||
center(-1)
|
||||
center(direction, -1)
|
||||
cz = cz - 1
|
||||
move("left")
|
||||
move("forward")
|
||||
direction = -1
|
||||
end
|
||||
end
|
||||
center()
|
||||
return cx,cz
|
||||
return cx,cz,direction
|
||||
end
|
||||
local function printdes(buf, dimensions)
|
||||
move("up")
|
||||
@@ -338,13 +336,14 @@ local function printdes(buf, dimensions)
|
||||
|
||||
local cx = 1
|
||||
local cz = 1
|
||||
local direction = 0
|
||||
for cy=1,dimensions["y"],1 do
|
||||
for _=1,3,1 do -- build walls
|
||||
local pbuf = {}
|
||||
while true do
|
||||
local target = getnearestunplaced(buf, pbuf, cx,cy,cz,nil, dimensions["x"],dimensions["z"], false)
|
||||
if not target then break end
|
||||
cx,cz = moveto(target[1],target[2],cx,cz)
|
||||
cx,cz = moveto(target[1],target[2],cx,cz,direction)
|
||||
place("down")
|
||||
pbuf[posasstring(cx,cy,cz)] = true
|
||||
end
|
||||
@@ -376,16 +375,17 @@ local function printdes(buf, dimensions)
|
||||
-- build ceiling/floor
|
||||
for _cz=1,dimensions["z"],1 do
|
||||
for _cx=1,dimensions["x"],1 do
|
||||
moveto(_cx,_cz,cx,cz)
|
||||
moveto(_cx,_cz,cx,cz,direction)
|
||||
if buf[posasstring(_cx,cy,_cz)] ~= 2 then
|
||||
place("down")
|
||||
end
|
||||
end
|
||||
end
|
||||
-- return to standard pos but +1 to y
|
||||
moveto(1,1,cx,cz)
|
||||
moveto(1,1,cx,cz,direction)
|
||||
move("up")
|
||||
end
|
||||
center(direction)
|
||||
end
|
||||
|
||||
while true do
|
||||
|
||||
Reference in New Issue
Block a user