Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local leash = 128 -- how far can it go from home position
- --local spawn={x=-166,y=71,z=-260,facing="north"}-- real coordinates
- --local rfstation={x=-192,y=73,z=-255}-- real coordinates
- -- Materials: These are lists of slot numbers to draw from
- local marble = {1,2,3,4}
- local marblebrick = {9,8,7,6}
- local light = {5}
- -- Which material to use where
- local base = marble
- local wall = marble
- local column = marblebrick
- local roof = marble
- local roofdeco = marblebrick
- local rooffilling = nil -- It's the only one that can be nil
- local columnbacklight = light
- local innercolumn = marblebrick
- local innercolumntoptip = marblebrick
- local innercolumnlight = light
- local ImplicitDigging = false -- Dig unexpected blocks standing in the way
- local ErrorOnMoveFailed = true -- Error out or merely return false
- local echo = print -- because I'm more used to the name echo
- local chirality = 1 -- 1 for dextral or -1 for sinistral
- local x,y,z,dx,dz=0,0,0,0,1 -- for the odometer
- -- By convention :
- -- ^ z
- -- |
- -- |
- -- |_____> x
- --
- -- I think I picked the wrong one :(
- local stations={}
- if rfstation and spawn then
- -- Convert real coordinates into relative coordinates
- -- Also in my relative coordinate x and z are somewhat wrongly signed
- if spawn.facing=="north" then
- stations={refilling={x=rfstation.x-spawn.x,y=rfstation.y-spawn.y,z=spawn.z-rfstation.z}}
- elseif spawn.facing=="east" then
- stations={refilling={x=rfstation.z-spawn.z,y=rfstation.y-spawn.y,z=rfstation.x-spawn.x}}
- elseif spawn.facing=="south" then
- stations={refilling={x=spawn.x-rfstation.x,y=rfstation.y-spawn.y,z=rfstation.z-spawn.z}}
- elseif spawn.facing=="west" then
- stations={refilling={x=spawn.z-rfstation.z,y=rfstation.y-spawn.y,z=spawn.x-rfstation.x}}
- else
- error("Unknown facing : "..tostring(spawn.facing))
- end
- end
- local function CheckLeash()
- if math.abs(x)>leash or math.abs(y)>leash or math.abs(z)>leash then
- echo("Danger! Outbound turtle! ("..x..","..y..","..z..")>"..leash)
- echo("Emergency crashdown!")
- local tr = (math.random()<0.5) and turtle.turnRight or turtle.turnLeft
- for k=1,20 do
- if not turtle.up then
- break
- end
- end
- for k=1,32 do
- tr()
- end
- while turtle.down() do
- tr()
- end
- for k=1,128 do
- tr()
- end
- error("Crash landed")
- end
- end
- local function TurnRight()
- CheckLeash()
- turtle.turnRight()
- if dz==1 then
- dx,dz=1,0
- elseif dz==-1 then
- dx,dz=-1,0
- elseif dx==1 then
- dx,dz=0,-1
- elseif dx==-1 then
- dx,dz=0,1
- else
- echo("Turtle lost track of its direction!")
- for k=1,24 do
- turtle.turnRight()
- end
- end
- return true
- end
- local function TurnLeft()
- CheckLeash()
- turtle.turnLeft()
- if dz==1 then
- dx,dz=-1,0
- elseif dz==-1 then
- dx,dz=1,0
- elseif dx==1 then
- dx,dz=0,1
- elseif dx==-1 then
- dx,dz=0,-1
- else
- echo("Turtle lost track of its direction!")
- for k=1,24 do
- turtle.turnLeft()
- end
- end
- return true
- end
- local function Turn(quarters)
- CheckLeash()
- local q = (quarters or 1)*(chirality or 1)
- local r=true
- if q>0 then
- for t=1,math.abs(q)%4 do
- r=r and TurnRight()
- end
- elseif q<0 then
- for t=1,math.abs(q)%4 do
- r=r and TurnLeft()
- end
- end
- return r
- end
- local function Forward()
- CheckLeash()
- if turtle.forward() then
- x=x+dx
- z=z+dz
- return true
- end
- return false
- end
- local function Backward()
- CheckLeash()
- if turtle.back() then
- x=x-dx
- z=z-dz
- return true
- end
- return false
- end
- local function Upward()
- CheckLeash()
- if turtle.up() then
- y=y+1
- return true
- end
- return false
- end
- local function Downward()
- CheckLeash()
- if turtle.down() then
- y=y-1
- return true
- end
- return false
- end
- local function GetOrientation()
- if dz==1 then
- return 0
- elseif dx==1 then
- return 1
- elseif dz==-1 then
- return 2
- elseif dx==-1 then
- return 3
- else
- error("Failed to get Orientation")
- end
- end
- local function GetPosition()
- return x,y,z,GetOrientation()
- end
- local function CheckPos(line,ex,ey,ez,eo) -- prefixed by 'e' like expected
- if (not (ex==x)) or (not (ey==y)) or (not (ez==z)) then
- error("L"..line..": Wrong position! Turtle is at "..x..","..y..","..z
- .." instead of "..ex..","..ey..","..ez)
- end
- if eo then
- if not (eo==GetOrientation()) then
- error("L"..line..": orientation! Turtle is at "..GetOrientation().." instead of "..eo)
- end
- end
- end
- local function MakeStubborn(move,antimove,dig)
- return function(...)
- if ImplicitDigging then
- while dig() do
- if move() then
- return true
- end
- end
- end
- local tries = 0
- local linear = 0
- if move() then
- linear=linear+1
- else
- echo("Having trouble at ("..x..","..y..","..z..")")
- end
- while not (linear==1) do
- tries=tries+1
- if tries>16 then
- -- What do do when movement fails
- if ErrorOnMoveFailed then
- error("Failed to move.")
- end
- return false
- end
- local manner=1+(tries-1)%(ImplicitDigging and 4 or 3)
- if manner==1 then
- -- Glance sideway
- local sign=math.random()>0.5 and 1 or -1
- Turn(0+sign)
- Turn(0-sign)
- Turn(0-sign)
- Turn(0+sign)
- elseif manner==2 then
- -- Attempt to ram
- local b=math.min(4,math.floor(tries/4))
- for k=1,b do
- linear=linear-(antimove() and 1 or 0)
- end
- for k=1,b do
- linear=linear+(move() and 1 or 0)
- end
- elseif manner==3 then
- -- Attempt to move
- if move() then
- linear=linear+1
- end
- elseif manner==4 then
- -- Attempt to dig
- if ImplicitDigging then
- if dig() then
- tries=0
- end
- else
- error("We said no digging!")
- end
- else
- error("Bad manner!")
- end
- end
- return true
- end
- end
- Forward=MakeStubborn(Forward,Backward,turtle.dig)
- Backward=MakeStubborn(Backward,Forward,DigBack)
- Upward=MakeStubborn(Upward,Downward,turtle.digUp)
- Downard=MakeStubborn(Downward,Upward,turtle.digDown)
- local function Move(wx,wy,wz,wo)
- local co=0
- local reverse=false
- local function LocalTurnTo(wo)
- reverse=false
- if not ((co%4)==(wo%4)) then
- local o=(12+wo-co)%4
- if o==1 then
- TurnRight()
- co=co+1
- elseif o==3 then
- TurnLeft()
- co=co-1
- elseif o==2 then
- if wx==0 and wy==0 then
- -- If wx not 0 it will have to turn anyway.
- -- If wy not 0 it might want to sense block to go above/under
- -- and turtle can't sense from its back.
- reverse=true
- else
- if math.random()>0.5 then
- TurnRight()
- TurnRight()
- else
- TurnLeft()
- TurnLeft()
- end
- co=co+2
- end
- end
- co=co%4
- end
- end
- while not (wx==0 and wz==0) do
- if math.abs(wx)>math.abs(wz) then
- LocalTurnTo(wx>0 and 1 or 3)
- else
- LocalTurnTo(wz>0 and 0 or 2)
- end
- if not reverse and not (wy==0) and turtle.detect() then
- if wy>0 then
- if Upward() then
- wy=wy-1
- else
- return false
- end
- end
- if wy<0 then
- if Downward() then
- wy=wy+1
- else
- return false
- end
- end
- elseif (reverse and Backward or Forward)() then
- if math.abs(wx)>math.abs(wz) then
- wx=wx+(wx>0 and -1 or 1)
- else
- wz=wz+(wz>0 and -1 or 1)
- end
- else
- return false
- end
- end
- while not (wy==0) do
- if wy>0 then
- if Upward() then
- wy=wy-1
- else
- return false
- end
- end
- if wy<0 then
- if Downward() then
- wy=wy+1
- else
- return false
- end
- end
- end
- if wo then
- --echo("Move trying to get proper orientation")
- wx,wy,wz=3,5,7 -- Hack to prevent reverse
- LocalTurnTo(wo)
- --echo("ok")
- end
- return true
- end
- local function Goto(awx,awy,awz,awo)
- -- aw(x/y/z/o) : Absolute Wanted
- -- rw(x/y/z/o) : Relative Wanted
- local r = true
- local o = GetOrientation()
- local rwx = awx and awx-x or 0
- local rwy = awy and awy-y or 0
- local rwz = awz and awz-z or 0
- local rwo = awo and (16+awo-o)%4
- if o==0 then
- r = Move(rwx,rwy,rwz,rwo)
- elseif o==3 then
- r = Move(rwz,rwy,-rwx,rwo)
- elseif o==2 then
- r = Move(-rwx,rwy,-rwz,rwo)
- elseif o==1 then
- r = Move(-rwz,rwy,rwx,rwo)
- else
- error("Bad orientation!")
- end
- if awo and not (awo==GetOrientation()) then
- --echo("Goto trying to get proper orientation")
- while not (awo==GetOrientation()) do
- Turn()
- end
- --echo("ok")
- end
- return r
- end
- local GetIn = nil
- local GetOut = nil
- local function Refill(slot)
- if type(slot)=="table" then
- echo("Slots "..table.concat(slot,",").." all empty")
- else
- echo("Slot "..slot.." empty")
- end
- if (not stations) or not (stations.refilling) then
- echo("No refilling station!")
- echo("Please refill manually then press enter")
- read()
- else
- local s=stations.refilling
- local bx,by,bz,bo=GetPosition()
- local sides={"marble","marble","marble","marble","torches","marble bricks","marble bricks","marble bricks","marble bricks"}
- local sid=ImplicitDigging
- ImplicitDigging=false
- echo("Going to station")
- if GetOut then
- GetOut()
- else
- Goto(bx,by+16,bz)
- end
- Goto(s.x,by+16,s.z)
- Goto(s.x,s.y,s.z,s.o)
- os.sleep(2)
- rednet.open("right")
- local snglslt=(type(slot)=="table" and math.max(unpack(slot)) or slot)
- repeat
- echo("Asking to be fed")
- rednet.broadcast("Feed me "..sides[snglslt])
- os.sleep(12)
- until turtle.getItemCount(snglslt)>32
- rednet.broadcast("I'm filled up!")
- os.sleep(1)
- rednet.close("right")
- echo("Back to work")
- os.sleep(12)
- Goto(s.x,by+16,s.z)
- if GetIn then
- GetIn()
- else
- Goto(bx,by+16,bz)
- end
- Goto(bx,by,bz,bo)
- ImplicitDigging=sid
- end
- end
- local function SelectSlot(slot)
- if slot then
- if type(slot)=="table" then
- for _,s in ipairs(slot) do
- if turtle.getItemCount(s)>1 then-- Always leave one for reasy refilling
- turtle.select(s)
- return true
- end
- end
- Refill(slot)
- return SelectSlot(slot)
- elseif type(slot)=="number" then
- if turtle.getItemCount(slot)>1 then-- Always leave one for reasy refilling
- turtle.select(slot)
- return true
- else
- Refill(slot)
- return SelectSlot(slot)
- end
- else
- error("Unexpected slot type "..type(slot))
- end
- else
- turtle.select(1)
- return true
- end
- end
- local function PlaceFront(slot)
- SelectSlot(slot)
- local r=turtle.place()
- turtle.select(1)
- return r
- end
- local function PlaceBack(slot)
- Turn()
- Turn()
- SelectSlot(slot)
- local r=turtle.place()
- Turn()
- Turn()
- turtle.select(1)
- return r
- end
- local function PlaceDown(slot)
- SelectSlot(slot)
- local r=turtle.placeDown()
- turtle.select(1)
- return r
- end
- local function PlaceUp(slot)
- SelectSlot(slot)
- local r=turtle.placeDown()
- turtle.select(1)
- return r
- end
- local DigDown = turtle.digDown
- local DigFront = turtle.dig
- local DigUp = turtle.digUp
- local function DigBack()
- Turn()
- Turn()
- local r=turtle.dig()
- Turn()
- Turn()
- return r
- end
- local function PutTorchesAfterWard(NbrColumnLength,NbrColumnWidth,TorchHeight,yOffset)
- local colz=NbrColumnLength-1
- local colx=NbrColumnWidth-1
- local coly=yOffset+TorchHeight-1
- local corners={{1,-1,3},{1,1,0},{-1,1,1},{-1,-1,2}}
- Goto(0,yOffset,0)
- Goto(0,coly,0)
- for _,p in ipairs(corners) do
- Goto((colx-3)*p[2],coly,(colz-3)*p[1],p[3])
- DigFront()
- TurnRight()
- DigFront()
- end
- -- South
- for x=2-colx,colx-2,2 do
- Goto(x,coly,3-colz,2)
- DigFront()
- Goto(x,coly,2-colz,2)
- PlaceFront(columnbacklight)
- Goto(x,coly,3-colz,2)
- PlaceFront(wall)
- end
- Goto(colx-3,coly,3-colz)
- -- East
- for z=2-colz,colz-2,2 do
- Goto(colx-3,coly,z,1)
- DigFront()
- Goto(colx-2,coly,z,1)
- PlaceFront(columnbacklight)
- Goto(colx-3,coly,z,1)
- PlaceFront(wall)
- end
- Goto(colx-3,coly,colz-3)
- -- North
- for x=colx-2,2-colx,-2 do
- Goto(x,coly,colz-3,0)
- DigFront()
- Goto(x,coly,colz-2,0)
- PlaceFront(columnbacklight)
- Goto(x,coly,colz-3,0)
- PlaceFront(wall)
- end
- Goto(3-colx,coly,colz-3)
- -- West
- for z=colz-2,2-colz,-2 do
- Goto(3-colx,coly,z,3)
- DigFront()
- Goto(2-colx,coly,z,3)
- PlaceFront(columnbacklight)
- Goto(3-colx,coly,z,3)
- PlaceFront(wall)
- end
- Goto(3-colx,coly,colz-3)
- for _,p in ipairs(corners) do
- Goto((colx-3)*p[2],coly,(colz-3)*p[1],p[3])
- PlaceFront(wall)
- TurnRight()
- PlaceFront(wall)
- end
- Goto(0,coly,0)
- Goto(0,yOffset,0,0)
- end
- local function Temple(length,width,height)
- local x,y,z = 0,0,0
- -- Add here something that override PlaceFront and PlaceDown
- -- With version that first check if not occupied by something else
- -- Coordinates are -sx to sx, 0 to sy, -sz to sz
- local sx=math.floor(width/2-0.3)
- local sy=height
- local sz=math.floor(length/2-0.3)
- local lightlevel=math.max(1,height<=3 and height or height-1)
- -- Fly up, then go down at first corner
- Goto(0,sy,0)
- Goto(-sx,sy,-sz)
- for y=sy,0,-1 do
- DigDown()
- Downward()
- end
- -- Dig the foundation around
- CheckPos("460",-sx,-1,-sz)
- Goto(-sx,-1,-sz,0)
- for z=-sz,sz-1 do
- DigFront()
- Forward()
- DigUp()
- end
- TurnRight()
- for x=-sx,sx-1 do
- DigFront()
- Forward()
- DigUp()
- end
- TurnRight()
- for z=sz,1-sz,-1 do
- DigFront()
- Forward()
- DigUp()
- end
- TurnRight()
- for x=sx,1-sx,-1 do
- DigFront()
- Forward()
- DigUp()
- end
- TurnRight()
- CheckPos("486",-sx,-1,-sz)
- -- Place perimeter
- Goto(-sx,0,-sz,2)
- CheckPos("490",-sx,0,-sz)
- PlaceDown(base)
- for z=-sz,sz-1 do
- Backward()
- PlaceDown(base)
- if not (z==-sz) then
- PlaceFront(base)
- end
- end
- TurnRight()
- for x=-sx,sx-1 do
- Backward()
- PlaceDown(base)
- PlaceFront(base)
- end
- TurnRight()
- for z=sz,1-sz,-1 do
- Backward()
- PlaceDown(base)
- PlaceFront(base)
- end
- TurnRight()
- for x=sx,1-sx,-1 do
- Backward()
- PlaceDown(base)
- PlaceFront(base)
- end
- TurnRight()
- Upward()
- PlaceDown(base)
- CheckPos("520",-sx,1,-sz)
- -- Make the base itself
- for x=1-sx,sx-1 do
- if x%2==(1-sx)%2 then
- for z=1-sz,sz-1 do
- Goto(x,1,z)
- DigDown()
- PlaceDown(base)
- end
- else
- for z=sz-1,1-sz,-1 do
- Goto(x,1,z)
- DigDown()
- PlaceDown(base)
- end
- end
- end
- for k=1,2 do
- Upward()
- end
- -- Place columns
- local columns={}
- local function AddCol(x,z)
- local lastcol=columns[#columns]
- if lastcol then
- if not (x==lastcol.x and z==lastcol.z) then
- columns[1+#columns]={x=x,z=z}
- else
- echo("Last column same as penultimate")-- Could still happen if only one
- end
- else
- columns[1]={x=x,z=z}
- end
- end
- -- North
- for x=sx-1,3-sx,-2 do
- AddCol(x,sz-1)
- end
- -- West
- for z=sz-1,3-sz,-2 do
- AddCol(1-sx,z)
- end
- -- South
- for x=1-sx,sx-3,2 do
- AddCol(x,1-sz)
- end
- -- East
- for z=1-sz,sz-3,2 do
- AddCol(sx-1,z)
- end
- for _,c in ipairs(columns) do
- Goto(c.x,height+2,c.z)
- Goto(c.x,1,c.z)
- for y=2,height+1 do
- Upward()
- PlaceDown(column)
- TurnLeft()
- end
- Upward()
- end
- --: Walls
- --: The minimum size to have walls is:
- --: -----------
- --: -x-x-x-x-x-
- --: ----------- ^z
- --: -x-oo-oo-x- |
- --: ---o-+-o--- |
- --: -x-oo-oo-x- ---->-x
- --: -----------
- --: -x-x-x-x-x- +-is-origin
- --: -----------
- if sx>=5 and sz>=4 then
- local walls={}
- local function AddWall(x,z) walls[1+#walls]={x=x,z=z} end
- -- North
- for x=sx-3,4-sx,-1 do
- AddWall(x,sz-3)
- end
- -- West
- for z=sz-3,4-sz,-1 do
- AddWall(3-sx,z)
- end
- -- South
- for x=3-sx,sx-4,1 do
- AddWall(x,3-sz)
- end
- -- East
- for z=3-sz,sz-4,1 do
- AddWall(sx-3,z)
- end
- for y=2,height+1 do
- for _,w in ipairs(walls) do
- local isDoor = (math.abs(w.x) <= math.max(0,sx-5)) and y<=math.min(6,math.max(3,height))
- if isDoor then
- Goto(false,1+height,false)
- Goto(w.x,false,w.z)
- else
- Goto(w.x,y,w.z)
- PlaceDown(wall)
- end
- -- Light
- if y==lightlevel then
- if w.x==sx-3 and (w.z-sz)%2==1 then
- Goto(false,y,false,1)
- PlaceFront(columnbacklight)
- end
- if w.z==sz-3 and (w.x-sx)%2==1 then
- Goto(false,y,false,0)
- PlaceFront(columnbacklight)
- end
- if w.x==3-sx and (w.z-sz)%2==1 then
- Goto(false,y,false,3)
- PlaceFront(columnbacklight)
- end
- if w.z==3-sz and (w.x-sx)%2==1 then
- Goto(false,y,false,2)
- PlaceFront(columnbacklight)
- end
- end
- end
- end
- if height==1 then
- PutTorchesAfterWard(sz,sx,height,1)
- end
- else
- -- Place lights on column if no walls
- -- North
- TurnLeft()
- TurnLeft()
- TurnLeft()
- TurnLeft()
- -- North
- for x=sx-3,3-sx,-2 do
- Goto(x,lightlevel,sz-3,0)
- PlaceFront(columnbacklight)
- end
- -- West
- for z=sz-3,3-sz,-2 do
- Goto(3-sx,lightlevel,z,3)
- PlaceFront(columnbacklight)
- end
- -- South
- for x=3-sx,sx-3,2 do
- Goto(x,lightlevel,3-sz,2)
- PlaceFront(columnbacklight)
- end
- -- East
- for z=3-sz,sz-3,2 do
- Goto(sx-3,lightlevel,z,1)
- PlaceFront(columnbacklight)
- end
- TurnLeft()
- TurnLeft()
- TurnLeft()
- TurnLeft()
- end
- if sx>1 and sz>1 then
- -- Roof, first layer
- local y=2+height
- for x=sx,-sx,-1 do
- if x%2==(1-sx)%2 then
- for z=sz,-sz,-1 do
- Goto(x,y,z)
- PlaceDown(roof)
- end
- else
- for z=-sz,sz do
- Goto(x,y,z)
- PlaceDown(roof)
- end
- end
- end
- -- Roof, higher levels
- if rooffilling then
- for rx=sx,0,-1 do
- y=y+1
- for x=-rx,rx do
- for z=-sz,sz do
- if math.abs(x)>=rx-1 or rx==sx then
- Goto(x,y,z)
- PlaceDown(roof)
- elseif z==sz or z==-sz then
- Goto(x,y,z)
- PlaceDown(roofdeco)
- elseif rooffilling then
- Goto(x,y,z)
- PlaceDown(rooffilling)
- end
- end
- end
- end
- else
- for rx=sx-2,0,-2 do
- y=y+1
- for z=sz,-sz,-1 do
- Goto(rx,y,z)
- PlaceDown(roof)
- end
- for x=rx-2,2-rx,-1 do
- Goto(x,y,-sz)
- PlaceDown(roofdeco)
- end
- if rx>0 then
- for z=-sz,sz do
- Goto(-rx,y,z)
- PlaceDown(roof)
- end
- end
- for x=2-rx,rx-2 do
- Goto(x,y,sz)
- PlaceDown(roofdeco)
- end
- if rx>0 then
- for z=sz,-sz,-1 do
- Goto(rx-1,y,z)
- PlaceDown(roof)
- end
- end
- if rx>1 then
- for z=-sz,sz do
- Goto(1-rx,y,z)
- PlaceDown(roof)
- end
- end
- end
- end
- end
- GetIn = function()
- Goto(sx%2,y+1,-2-sz)
- Goto(sx%2,math.max(2,height-1),-2-sz)
- TurnLeft()
- TurnLeft()
- Goto(sx%2,math.max(2,height-1),-1-sz)
- Goto(sx%2,1,-1-sz)
- Goto(sx%2,1,2-sz)
- Goto(0,1,2-sz)
- Goto(0,1,0,0)
- TurnRight()
- TurnRight()
- end
- GetOut = function()
- Goto(0,1,0)
- Goto(0,1,2-sz)
- Goto(sx%2,1,2-sz)
- Goto(sx%2,1,-1-sz)
- Goto(sx%2,math.max(2,height-1),-1-sz)
- TurnRight()
- TurnRight()
- Goto(sx%2,math.max(2,height-1),-2-sz)
- Goto(sx%2,math.floor(height+sx/2+3),-2-sz)
- end
- -- Go inside
- Goto(false,y+1,false)
- GetIn()
- if sx>=6 and sz>=6 and height>=3 then
- Goto(0,height,0)
- -- Place columns inside
- local interior_length=(sz-4)+1
- local ncol = (interior_length-1)/4
- local rcol = interior_length-4*ncol
- for dx=-1,1,2 do
- for dz=6-sz,sz-6,4 do
- local cz=(dz+(rcol>=2 and (dz>0 and -1 or 1) or 0))*dx
- local cx=(sx-4)*dx
- Goto(0,height,cz)
- Goto(cx-2*dx,height,cz)
- for cy=1,height do
- Goto(cx-1*dx,cy,cz)
- PlaceFront(innercolumn)
- end
- Backward()
- PlaceFront(innercolumntoptip)
- TurnLeft()
- Forward()
- TurnRight()
- Forward()
- PlaceFront(innercolumntoptip)
- Backward()
- PlaceFront(innercolumntoptip)
- TurnRight()
- Forward()
- Forward()
- TurnLeft()
- Forward()
- PlaceFront(innercolumntoptip)
- Backward()
- PlaceFront(innercolumntoptip)
- Downward()
- TurnLeft()
- Backward()
- TurnRight()
- Forward()
- Forward()
- TurnLeft()
- PlaceFront(innercolumnlight)
- TurnRight()
- Backward()
- Backward()
- TurnLeft()
- Forward()
- Forward()
- TurnRight()
- PlaceFront(innercolumnlight)
- TurnLeft()
- Forward()
- Forward()
- TurnRight()
- Forward()
- Forward()
- TurnRight()
- PlaceFront(innercolumnlight)
- TurnLeft()
- Backward()
- Backward()
- end
- end
- Goto(0,height,0)
- Goto(0,1,0,2)
- end
- end
- local function CastToBool(str)
- local yes={"yes","y","1","true","ok","vrai","oui","aye"}
- local no={"no","n","0","false","nok","faux","non","nay"}
- for _,y in ipairs(yes) do
- if str==y then
- return true
- end
- end
- for _,n in ipairs(no) do
- if str==n then
- return false
- end
- end
- return nil
- end
- local function AskYesNo(question,canskip)
- echo(question)
- while true do
- local answer=read()
- if canskip and answer=="" then
- return default
- end
- local yn=CastToBool(answer)
- if not (yn==nil) then
- return yn
- end
- echo("Please say yes or no")
- end
- end
- local function AskNumber(question,canskip)
- echo(question)
- repeat
- local answer=read()
- if canskip and answer=="" then
- return nil
- end
- local n=tonumber(answer)
- if not n then
- echo("Please input a number"..(skip and ", or skip." or "!"))
- else
- return n
- end
- until false
- end
- local function RunTorch(NbrColumnLength,NbrColumnWidth,TorchHeight,extra)
- local NbrColumnLength=tonumber(NbrColumnLength)
- local NbrColumnWidth=tonumber(NbrColumnWidth)
- local TorchHeight=tonumber(TorchHeight)
- local BackOnFail = true
- if (not NbrColumnLength) or (not NbrColumnWidth) or (not TorchHeight) then
- echo("Missing arguments, interactive mode")
- NbrColumnLength=AskNumber("How many column length-wise?",false)
- NbrColumnWidth=AskNumber("How many column width-wise?",false)
- TorchHeight=AskNumber("How high to place torches height-wise?",false)
- end
- ImplicitDigging=false
- ErrorOnMoveFailed=true
- local ret,msg=pcall(PutTorchesAfterWard,NbrColumnLength,NbrColumnWidth,TorchHeight)
- if ret then
- echo("Success!")
- elseif BackOnFail then
- echo(msg)
- echo("Failure! Not even attempting to come back.")
- end
- end
- local function RunTemple(length,width,height)
- local length=tonumber(length)
- local width=tonumber(width)
- local height=tonumber(height)
- local BackOnFail = true
- if (not length) or (not width) or (not height) then
- echo("Missing arguments, interactive mode")
- length=AskNumber("Length?",false)
- width=AskNumber("Width?",false)
- height=AskNumber("Height?",false)
- end
- --ImplicitDigging=false -- Keep default from top of file
- --ErrorOnMoveFailed=true -- Keep default from top of file
- local ret,msg=pcall(Temple,length,width,height)
- if ret then
- echo("Success!")
- elseif BackOnFail then
- echo(msg)
- echo("Failure! Attempting to come back.")
- ImplicitDigging=true
- ErrorOnMoveFailed=false
- if Goto(0,0,0,0) then
- echo("Back!")
- else
- echo("Failed to come back!")
- end
- else
- echo("Sorry to have failed you!")
- end
- ImplicitDigging=false
- ErrorOnMoveFailed=true
- end
- RunTemple(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement