implemented new way of movement and printing designs.
This commit is contained in:
98
src/main.lua
98
src/main.lua
@@ -268,13 +268,83 @@ local function placebuf(buf, x, y, z)
|
|||||||
place("down")
|
place("down")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling)
|
||||||
|
local distance = math.huge
|
||||||
|
local selected = nil
|
||||||
|
|
||||||
|
for x=1,sx,1 do
|
||||||
|
for y=1,sz,1 do
|
||||||
|
local needplace = buf[posasstring(x,cy,y)]
|
||||||
|
if pbuf[posasstring(x,cy,y)] then needplace = 0 end -- already placed
|
||||||
|
needplace = setceiling and (needplace == 2 or needplace == 1) or needplace == 1
|
||||||
|
if needplace then -- needs to be placed, calculate distance
|
||||||
|
local cd = math.abs(y-cz)+math.abs(x-cx) -- raw distance (amount of blocks between)
|
||||||
|
if cd < distance then
|
||||||
|
distance = cd
|
||||||
|
selected = {x,y}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return selected
|
||||||
|
end
|
||||||
|
local function moveto(x,y,cx,cz)
|
||||||
|
local direction = 0
|
||||||
|
local function center(wanted)
|
||||||
|
if direction == 1 and wanted ~= 1 then
|
||||||
|
move("left")
|
||||||
|
end
|
||||||
|
if direction == -1 and wanted ~= -1 then
|
||||||
|
move("right")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
while x ~= cx or y ~= cz do
|
||||||
|
if x > cx then -- x
|
||||||
|
center()
|
||||||
|
cx = cx + 1
|
||||||
|
move("forward")
|
||||||
|
end
|
||||||
|
if x < cx then
|
||||||
|
center()
|
||||||
|
cx = cx - 1
|
||||||
|
move("back")
|
||||||
|
end
|
||||||
|
|
||||||
|
if y > cz then -- z
|
||||||
|
center(1)
|
||||||
|
cz = cz + 1
|
||||||
|
move("right")
|
||||||
|
move("forward")
|
||||||
|
direction = 1
|
||||||
|
end
|
||||||
|
if y < cz then
|
||||||
|
center(-1)
|
||||||
|
cz = cz - 1
|
||||||
|
move("left")
|
||||||
|
move("forward")
|
||||||
|
direction = -1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return cx,cz
|
||||||
|
end
|
||||||
local function printdes(buf, dimensions)
|
local function printdes(buf, dimensions)
|
||||||
move("up")
|
move("up")
|
||||||
move("forward")
|
move("forward")
|
||||||
|
|
||||||
|
local cx = 1
|
||||||
|
local cz = 1
|
||||||
for cy=1,dimensions["y"],1 do
|
for cy=1,dimensions["y"],1 do
|
||||||
for _=1,3,1 do -- build walls
|
for _=1,3,1 do -- build walls
|
||||||
for cz=1,dimensions["z"],1 do
|
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)
|
||||||
|
place("down")
|
||||||
|
pbuf[posasstring(cx,cy,cz)] = true
|
||||||
|
end
|
||||||
|
move("up")
|
||||||
|
--[[for cz=1,dimensions["z"],1 do
|
||||||
for cx=1,dimensions["x"],1 do
|
for cx=1,dimensions["x"],1 do
|
||||||
placebuf(buf, cx, cy, cz)
|
placebuf(buf, cx, cy, cz)
|
||||||
move("forward")
|
move("forward")
|
||||||
@@ -296,33 +366,19 @@ local function printdes(buf, dimensions)
|
|||||||
move("forward")
|
move("forward")
|
||||||
end
|
end
|
||||||
move("right")
|
move("right")
|
||||||
move("up")
|
move("up")]]--
|
||||||
end
|
end
|
||||||
-- build ceiling/floor
|
-- build ceiling/floor
|
||||||
for cz=1,dimensions["z"],1 do
|
for _cz=1,dimensions["z"],1 do
|
||||||
for cx=1,dimensions["x"],1 do
|
for _cx=1,dimensions["x"],1 do
|
||||||
if buf[posasstring(cx,cy,cz)] ~= 2 then
|
moveto(_cx,_cz,cx,cz)
|
||||||
|
if buf[posasstring(_cx,cy,_cz)] ~= 2 then
|
||||||
place("down")
|
place("down")
|
||||||
end
|
end
|
||||||
move("forward")
|
|
||||||
end
|
end
|
||||||
-- return to standard pos but +1 to z
|
|
||||||
--move("back")
|
|
||||||
move("right")
|
|
||||||
move("forward")
|
|
||||||
move("right")
|
|
||||||
for _=1,dimensions["x"],1 do
|
|
||||||
move("forward")
|
|
||||||
end
|
|
||||||
move("right")
|
|
||||||
move("right")
|
|
||||||
end
|
end
|
||||||
-- return to standard pos but +1 to y
|
-- return to standard pos but +1 to y
|
||||||
move("left")
|
moveto(1,1,cx,cz)
|
||||||
for _=1,dimensions["z"],1 do
|
|
||||||
move("forward")
|
|
||||||
end
|
|
||||||
move("right")
|
|
||||||
move("up")
|
move("up")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user