diff --git a/src/main.lua b/src/main.lua index e7d78ad..cdbf353 100644 --- a/src/main.lua +++ b/src/main.lua @@ -272,7 +272,7 @@ local function placebuf(buf, x, y, z) place("down") end end -local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling) +local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz) local distance = math.huge local selected = nil @@ -280,7 +280,7 @@ local function getnearestunplaced(buf, pbuf, cx,cy,cz,co, sx,sz, setceiling) 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 + needplace = 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 @@ -305,7 +305,7 @@ local function center(direction, wanted) return false end local function moveto(x,y,cx,cz,direction) - while x ~= cx or y ~= cz do + while x ~= cx do if cx < x then -- x center(direction) direction = 0 @@ -318,7 +318,8 @@ local function moveto(x,y,cx,cz,direction) cx = cx - 1 move("back") end - + end + while y ~= cz do if y > cz then -- z if center(direction, 1) then move("right") end cz = cz + 1 @@ -345,7 +346,7 @@ local function printdes(buf, dimensions) 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) + local target = getnearestunplaced(buf, pbuf, cx,cy,cz,nil, dimensions["x"],dimensions["z"]) if not target then break end reset() -- render current work @@ -372,39 +373,44 @@ local function printdes(buf, dimensions) pbuf[posasstring(cx,cy,cz)] = true end move("up") - --[[for cz=1,dimensions["z"],1 do - for cx=1,dimensions["x"],1 do - placebuf(buf, cx, cy, cz) - move("forward") - 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 - -- return to standard pos but +1 to y - move("left") - for _=1,dimensions["z"],1 do - move("forward") - end - move("right") - move("up")]]-- end -- build ceiling/floor + local pbuf = {} + local cbuf = {} for _cz=1,dimensions["z"],1 do for _cx=1,dimensions["x"],1 do - cx,cz,direction = moveto(_cx,_cz,cx,cz,direction) if buf[posasstring(_cx,cy,_cz)] ~= 2 then - place("down") + cbuf[posasstring(_cx,0,_cz)] = 1 + else + cbuf[posasstring(_cx,0,_cz)] = 0 end end end + while true do + local target = getnearestunplaced(cbuf, pbuf, cx,0,cz,nil, dimensions["x"],dimensions["z"]) + if not target then break end + + reset() -- render current work + for x=1,dimensions["x"],1 do + for z=1,dimensions["z"],1 do + local currentbuf = pbuf[posasstring(x, cy, z)] + term.setCursorPos(x, z) + if currentbuf then -- wall + term.blit(" ", colors.toBlit(colors.white), colors.toBlit(colors.white)) + elseif currentbuf == false or currentbuf == nil then -- nothing + term.blit("\127", colors.toBlit(colors.gray), colors.toBlit(colors.black)) + end + end + end + term.setCursorPos(cx,cz) + term.blit(" ", colors.toBlit(colors.red), colors.toBlit(colors.red)) + term.setCursorPos(target[1],target[2]) + term.blit(" ", colors.toBlit(colors.lime), colors.toBlit(colors.lime)) + + cx,cz,direction = moveto(target[1],target[2],cx,cz,direction) + place("down") + pbuf[posasstring(cx,cy,cz)] = true + end -- return to standard pos but +1 to y cx,cz,direction = moveto(1,1,cx,cz,direction) move("up")