Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if require("component").isAvailable("generator")
- then
- generator=require("component").generator
- end
- withg=(generator~=nil)
- slots=16
- slotstocheck=2
- robot=require("robot")
- coords={x=0,y=0,z=0,side=1}
- extcoords={x=0,y=0,z=0,side=1}
- sx={0,1,0,-1}
- sy={1,0,-1,0}
- falsemode=false
- counter=0
- tocount=0
- --1,2,3,4
- --tl -- coords.side = (coords.side + 3)%4
- --tr -- coords.side = (coords.side + 1)%4
- --ta -- coords.side = (coords.side + 2)%4
- --all -- if coords.side == 0 then coords.side =4 end
- function save()
- file = io.open("quarryrest","w")
- file:write(coords.x.."\n"..coords.y.."\n"..coords.z.."\n"..coords.side.."\n"..counter.."\n"..x.."\n"..y.."\n"..z.."\n")
- file:close()
- end
- function restore()
- local file = io.open("quarryrest","r")
- extcoords.x=file:read()+0
- extcoords.y=file:read()+0
- extcoords.z=file:read()+0
- extcoords.side=file:read()+0
- back()
- tocount=file:read()+0
- x=file:read()+0
- y=file:read()+0
- z=file:read()+0
- falsemode=true
- end
- function checkfalse()
- if counter>=tocount then falsemode=false end
- end
- function sgo() while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end
- function sgodown() while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end
- function sgoup() while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end
- function sturnLeft() robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end
- function sturnRight() robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end
- function go() if not falsemode then while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end counter=counter+1; save();checkfalse(); end
- function godown() if not falsemode then while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end counter=counter+1; save();checkfalse(); end
- function goup() if not falsemode then while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end counter=counter+1; save();checkfalse(); end
- function check() return robot.count(slots-(slotstocheck-1)) > 0 end
- function turnLeft() if not falsemode then robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end counter=counter+1; save();checkfalse(); end
- function turnRight() if not falsemode then robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end counter=counter+1; save();checkfalse(); end
- function tosurf()
- extcoords.x=coords.x
- extcoords.y=coords.y
- extcoords.z=coords.z
- extcoords.side=coords.side
- while coords.z ~= 0 do sgoup() end
- while coords.side ~= 3 do sturnRight() end
- while coords.y ~= 0 do sgo() end
- sturnRight();
- while coords.x ~= 0 do sgo() end
- sturnLeft();
- end
- function back()
- while coords.z ~= extcoords.z do sgodown() end
- while coords.side~= 1 do sturnRight() end
- while coords.y ~= extcoords.y do sgo() end
- sturnRight();
- while coords.x ~= extcoords.x do sgo() end
- while coords.side ~= extcoords.side do sturnRight() end
- end
- function clearinv()
- alreadyhave=false
- for invcounter=1,slots do
- robot.select(invcounter)
- if withg then
- suc,error=generator.insert()
- if (error=="selected slot does not contain fuel" or alreadyhave) then robot.drop() else alreadyhave=true end
- else
- robot.drop()
- end
- end
- robot.select(1)
- sort()
- end
- function sort()
- curs=1
- for q=1,slots do
- if robot.count(q) > 0 then robot.select(q);robot.transferTo(curs);curs=curs+1 end
- end
- robot.select(1)
- end
- function prevent()
- if check() then
- tosurf()
- clearinv()
- back()
- end
- end
- function digrow(n)
- prevent()
- robot.swingUp()
- prevent()
- robot.swingDown()
- for k=1,n do
- prevent()
- go()
- prevent()
- robot.swingUp()
- prevent()
- robot.swingDown()
- end
- end
- function digdim(x,y)
- godown()
- godown()
- for n=1,y do
- if tl then turnLeft() else turnRight() end
- digrow(ex)
- if tl then turnRight() else turnLeft() end
- tl = not tl
- if n==y then print("ok") else go() end
- end
- turnRight();
- turnRight();
- tl= not tl
- end
- x,y,z=...
- if x=="-restore" then
- restore()
- end
- tl=false
- x=x+0
- y=y+0
- z=z+0
- ex=x-1
- fullz=(z-z%3)/3
- print("Fullz = " .. fullz)
- for i=1,fullz do
- digdim(x,y)
- godown()
- end
- if fullz*3==z then elseif fullz*3+1==z then goup();goup();digdim(tl,x,y) else goup();digdim(tl,x,y) end
- tosurf()
- clearinv()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement