Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- --------------------------------------------------------------------------------------- --
- -- START OF THE DEFAULT CONFIG OF THIS PROGRAM, THOUGH COMMAND LINE PARAMETERS CAN BE USED --
- -- FOR THE DIRECTION PARAMETERS USE up/down/left/right/forward/back --
- -- --------------------------------------------------------------------------------------- --
- args={...}
- local configuration={}
- -- THE NUMBER OF LEVELS
- configuration.numL = 1
- -- THE NUMBER OF TUNNELS
- configuration.numT = 4
- -- THE NUMBER OF SHAFTS TO EXCAVATE
- configuration.numS = 21
- -- HOW MANY LEVELS TO SKIP
- configuration.skipL = 0
- -- HOW MANY TUNNELS TO SKIP
- configuration.skipT = 0
- -- HOW MANY SHAFTS TO SKIP
- configuration.skipS = 0
- -- THE DIRECTION OF THE NEXT LEVEL (UP or DOWN)
- configuration.nextDirL = "up"
- -- THE DIRECTION OF THE NEXT TUNNEL (LEFT or RIGHT)
- configuration.nextDirT = "left"
- -- THE HEIGHT OF THE LEVELS/TUNNELS
- configuration.height = 3
- -- THE NUMBER OF BLOCKS BETWEEN EACH SHAFT
- configuration.blocksBetweenShafts = 2
- -- HOW MANY BLOCKS WILL THE TURTLE MOVE BEFORE DIGGING THE FIRST SHAFT
- configuration.firstShaftOffset = 4
- -- THE NUMBER OF BLOCKS THE EVEN LEVEL SHAFTS WILL BE OFFSET
- configuration.evenLevelOffset = 2
- -- DOES THE TURTLE ALSO PLACE TORCHES
- configuration.placeTorches = false
- -- IS THERE A SINGLE DROPOFF CHEST (true) OR ONE PER DIRECTION, PER LEVEL (false)
- configuration.singleChest = false
- -- THE RADIUS OF THE CIRCLE ON WHICH THE REFUELING STATIONS ARE POSITIONED
- configuration.centerRadius = 5
- -- THE NUMBER OF BLOCK TYPES THE TURTLE WILL _NOT_ DIG UNLESS NEEDED
- -- DEFAULT CONSIDERS: Smooth stone, Dirt, Gravel, Marble (Tekkit), Wood, stone bricks
- configuration.numIgnoreBlocks = 4
- -- DOES THE TURTLE REQUIRE FUEL TO OPERATE?
- configuration.requiresFuel = false
- -- THE AMOUNT OF FUEL THE TURTLE WILL STORE BEFORE HEADING OF TO A SHAFT
- configuration.departureFuel = 1200
- -- THE AMOUNT OF FUEL AT WHICH THE TURTLE WILL RETURN TO DROPOFF
- configuration.returnFuel = 200
- -- THE DIRECTION OF THE FUEL ITEMS (IN THE REFUELING STATION)
- configuration.fuelSuckDir = "up"
- -- THE DIRECTION WHERE THE TURTLE WILL DROP LEFTOVERS (BUCKETS)
- configuration.fuelDropDir = "down"
- -- THE DIRECTION WHERE THE TURTLE WILL DROP ANY MINED ITEMS
- configuration.itemDropDir = "down"
- -- THE DIRECTION OF THE TORCHES
- configuration.torchSuckDir = "right"
- -- THE DIRECTION OF THE IGNORE BLOCKS
- configuration.ignoreDir = "left"
- -- USED TO KEEP TRACK OF THE POSITION OF THE TUNNEL
- configuration.currentL = 1
- configuration.currentT = 1
- configuration.currentS = 0
- -- ------------------------------------------------------------------------------------- --
- -- END OF THE DEFAULT CONFIG OF THIS PROGRAM, THOUGH COMMAND LINE PARAMETERS CAN BE USED --
- -- FOR THE DIRECTION PARAMETERS USE up/down/left/right/forward/back --
- -- ------------------------------------------------------------------------------------- --
- -- -------------------------------------------------- --
- -- START OF THE PARSING OF THE COMMAND LINE ARGUMENTS --
- -- -------------------------------------------------- --
- -- PRINTS THE MANUAL TO THE TERMINAL IN CASE THE USER SPECIFIED INCORRECT VALUES
- function printManual()
- term.clear()
- print("Usage: digOres [OPTIONS] (1/3)")
- print("------------------------------")
- print(" -numL <num> (=nr. of levels)")
- print(" -numT <num> (=nr. of tunnels)")
- print(" -numS <num> (=nr. of shafts)")
- print(" -skipL <num> (=skip # levels)")
- print(" -skipT <num> (=skip # tunnels)")
- print(" -skipS <num> (=skip # shafts)")
- print(" -dirNextL <dir> (=next lev. U/D)")
- print(" -dirNextT <dir> (=next tun. L/R)")
- print("PRESS ANY KEY TO CONTINUE")
- print("")
- read()
- term.clear()
- print("Usage: digOres [OPTIONS] (2/3)")
- print("------------------------------")
- print(" -height <num> (=level height 2/3)")
- print(" -betw <num> (=blocks betw shafts)")
- print(" -firstOffs <num>(=first shaft offset)")
- print(" -evenOffs <num> (=even level offset)")
- print(" -torches (=place torches)")
- print(" -oneChest (=single drop chest)")
- print(" -rad <num> (=center radius)")
- print(" -numIgnore <num>(=num ignore blocks)")
- print("PRESS ANY KEY TO CONTINUE")
- print("")
- read()
- term.clear()
- print("Usage: digOres [OPTIONS] (3/3)")
- print("------------------------------")
- print(" -noFuel (=no need for fuel)")
- print(" -depFuel <num> (=departure fuel)")
- print(" -retFuel <num> (=return fuel)")
- print(" -fuelS <dir> (=fuel suck dir)")
- print(" -fuelD <dir> (=fuel drop dir)")
- print(" -torchS <dir> (=torch suck dir)")
- print(" -itemD <dir> (=item drop dir)")
- print(" -ignoreS <dir> (=ignore block dir)")
- print("")
- print("")
- end
- -- PRINTS THE POSSIBLE DIRECTION VALUES TO THE TERMINAL
- function printDirs()
- term.clear()
- print("Invalid direction chosen: pick from:")
- print("------------------------------------")
- print(" up")
- print(" down")
- print(" forward")
- print(" back")
- print(" right")
- print(" left")
- print("")
- print("")
- print("")
- print("")
- end
- -- CHECKS IF A STRING DENOTES A DIRECTION
- function isDir(dir)
- if dir=="forward" or dir=="back" or dir=="left" or dir=="right" or dir=="up" or dir=="down" then
- return true
- end
- return false
- end
- -- READS IN THE COMMAND LINE ARGUMENTS AND PARSES THEM
- readParams = 0
- while readParams < #args do
- if args[readParams+1] == "-numL" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.numL=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-numT" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.numT=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-numS" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.numS=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-skipL" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.skipL=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-skipT" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.skipT=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-skipS" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.skipS=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-dirNextL" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.nextDirL=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-dirNextT" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.nextDirT=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-height" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.height=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-betw" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.blocksBetweenShafts=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-firstOffs" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.firstShaftOffset=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-evenOffs" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.evenLevelOffset=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-torches" then
- configuration.placeTorches=true
- readParams=readParams+1
- elseif args[readParams+1] == "-oneChest" then
- configuration.singleChest=true
- readParams=readParams+1
- elseif args[readParams+1] == "-rad" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.centerRadius=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-numIgnore" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.numIgnoreBlocks=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-noFuel" then
- configuration.requiresFuel=false
- readParams=readParams+1
- elseif args[readParams+1] == "-depFuel" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.departureFuel=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-retFuel" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- configuration.returnFuel=tonumber(args[readParams+2])
- readParams=readParams+2
- elseif args[readParams+1] == "-fuelS" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.fuelSuckDir=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-fuelD" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.fuelDropDir=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-torchS" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.torchSuckDir=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-itemD" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.itemDropDir=args[readParams+2]
- readParams=readParams+2
- elseif args[readParams+1] == "-ignoreS" then
- if not (readParams + 1 < #args) then
- printManual()
- return
- end
- if not isDir(args[readParams+2]) then
- printDirs()
- return
- end
- configuration.ignoreDir=args[readParams+2]
- readParams=readParams+2
- else
- printManual()
- return
- end
- end
- -- ------------------------------------------------ --
- -- END OF THE PARSING OF THE COMMAND LINE ARGUMENTS --
- -- ------------------------------------------------ --
- -- ---------------------------------------------------------------------- --
- -- START OF COPY/PASTED CODE EXTENDING THE FUNCTIONALITY OF THE BASIC API --
- -- SOME OF THESE FUNCTIONS MIGHT BE REDUNDANT FOR THIS PROGRAM --
- -- ---------------------------------------------------------------------- --
- up = "up"
- down = "down"
- forward = "forward"
- back = "back"
- right = "right"
- left = "left"
- -- ALIGNS THE TURTLE TO MOVE, DIG, ... IN A CERTAIN DIRECTION
- function turnTo(dir)
- if dir==back then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif dir==right then
- turtle.turnRight()
- elseif dir==left then
- turtle.turnLeft()
- end
- end
- -- REALIGNS THE TURTLE TO THE ORIGINAL DIRECTION
- function turnFrom(dir)
- if dir==back then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif dir==right then
- turtle.turnLeft()
- elseif dir==left then
- turtle.turnRight()
- end
- end
- -- RETURNS THE DIRECTION THE TURTLE SHOULD MOVE, DIG, ... AFTER THE PREVIOUS ALIGNMENT
- function turnedDir(dir)
- if dir==right or dir==left or dir==back then
- return forward
- else
- return dir
- end
- end
- -- RETURNS THE REVERSE DIRECTION SO UP BECOMES DOWN ETC
- function reverseDir(dir)
- if dir==forward then
- return back
- elseif dir==back then
- return forward
- elseif dir==up then
- return down
- elseif dir==down then
- return up
- elseif dir==right then
- return left
- elseif dir==left then
- return right
- end
- end
- -- RETURNS THE DIRECTION USED BY THE PERIPHERAL FUNCTIONS
- function peripheralDir(dir)
- if dir==forward then
- return "front"
- elseif dir==up then
- return "top"
- elseif dir==down then
- return "bottom"
- end
- end
- -- MOVES THE TURTLE A CERTAIN DISTANCE IN A CERTAIN DIRECTION
- -- IF NO DISTANCE IS SPECIFIED IT WILL JUST MOVE 1 STEP
- function move(dir, steps)
- steps = steps or 1
- local stepsTaken = 0
- turnTo(dir)
- local tDir=turnedDir(dir)
- for i=1,steps,1 do
- local tries=0
- local success=false
- while ((not success) and (tries<10)) do
- if tDir==forward then
- success=turtle.forward()
- elseif tDir==up then
- success=turtle.up()
- elseif tDir==down then
- success=turtle.down()
- end
- if success then
- break
- end
- attack(tDir)
- tries = tries+1
- sleep(0.5)
- end
- if not success then
- break
- end
- stepsTaken=stepsTaken+1
- end
- turnFrom(dir)
- return stepsTaken
- end
- -- DIGS IN A CERTAIN DIRECTION
- function dig(dir)
- turnTo(dir)
- local tDir=turnedDir(dir)
- local tries=0
- local success=false
- if not (peripheral.getType(peripheralDir(tDir))=="turtle") then
- while ((detect(tDir)) and (tries<10)) do
- if tDir==forward then
- success=turtle.dig()
- elseif tDir==up then
- success=turtle.digUp()
- elseif tDir==down then
- success=turtle.digDown()
- end
- if not success then
- tries = tries+1
- end
- sleep(0.5)
- end
- end
- turnFrom(dir)
- return success
- end
- -- DIGS AND MOVES A CERTAIN DISTANCE IN A CERTAIN DIRECTION
- -- IF NO DISTANCE IS SPECIFIED IT WILL JUST MOVE 1 STEP
- function digAndMove(dir, steps)
- steps = steps or 1
- local stepsTaken = 0
- turnTo(dir)
- local tDir=turnedDir(dir)
- for i=1,steps,1 do
- dig(tDir)
- local success=move(tDir)
- if success==0 then
- turnFrom(dir)
- return stepsTaken
- end
- stepsTaken=stepsTaken+1
- end
- turnFrom(dir)
- return stepsTaken
- end
- -- ATTACKS IN A CERTAIN DIRECTION
- function attack(dir)
- turnTo(dir)
- local tDir=turnedDir(dir)
- while turtle.attack(tDir) do
- sleep(0.3)
- end
- turnFrom(dir)
- end
- -- PLACES A BLOCK FROM A CERTAIN SLOT IN A CERTAIN DIRECTION
- function place(dir, slot)
- turtle.select(slot)
- turnTo(dir)
- local tDir=turnedDir(dir)
- if tDir==forward then
- turtle.place()
- elseif tDir==up then
- turtle.placeUp()
- elseif tDir==down then
- turtle.placeDown()
- end
- turnFrom(dir)
- end
- -- DETECTS IF THERE IS A BLOCK IN A CERTAIN DIRECTION
- function detect(dir)
- local block = false
- turnTo(dir)
- local tDir=turnedDir(dir)
- if tDir==forward then
- block = turtle.detect()
- elseif tDir==up then
- block = turtle.detectUp()
- elseif tDir==down then
- block = turtle.detectDown()
- end
- turnFrom(dir)
- return block
- end
- -- COMPARES A BLOCK IN A CERTAIN DIRECTION TO THE BLOCK IN A CERTAIN INVENTORY SLOT
- function compare(dir, slot)
- local same = false
- turtle.select(slot)
- turnTo(dir)
- local tDir=turnedDir(dir)
- if tDir==forward then
- same = turtle.compare()
- elseif tDir==up then
- same = turtle.compareUp()
- elseif tDir==down then
- same = turtle.compareDown()
- end
- turnFrom(dir)
- return same
- end
- -- COMPARES A BLOCK IN A CERTAIN DIRECTION TO A CERTAIN INVENTORY SLOT
- -- IF IT MATCHES THE BLOCK WILL BE REPLACED BY A BLOCK IN THE SPECIFIED SLOT
- function compareAndReplace(dir, compareSlot, replaceSlot)
- local replaced = false
- turnTo(dir)
- local tDir=turnedDir(dir)
- if not compare(tDir, compareSlot) then
- replaced = true
- dig(tDir)
- place(tDir, replaceSlot)
- end
- turnFrom(dir)
- return replaced
- end
- -- DROPS A CERTAIN NUMBER OF ITEMS IN A CERTAIN DIRECTION
- -- IF NO NUMBER IS SPECIFIED IT WILL DROP ALL THE ITEMS
- function drop(dir, num)
- turnTo(dir)
- local tDir=turnedDir(dir)
- if num == null then
- if tDir==forward then
- turtle.drop()
- elseif tDir==up then
- turtle.dropUp()
- elseif tDir==down then
- turtle.dropDown()
- end
- else
- if tDir==forward then
- turtle.drop(num)
- elseif tDir==up then
- turtle.dropUp(num)
- elseif tDir==down then
- turtle.dropDown(num)
- end
- end
- turnFrom(dir)
- end
- -- SUCKS UP ITEMS FROM A CERTAIN DIRECTION
- function suck(dir)
- turnTo(dir)
- local tDir=turnedDir(dir)
- if tDir==forward then
- turtle.suck()
- elseif tDir==up then
- turtle.suckUp()
- elseif tDir==down then
- turtle.suckDown()
- end
- turnFrom(dir)
- end
- -- REFUELS THE TURTLE, PARAMETERS DENOTE IN WHICH DIRECTION THE FUEL ITEMS WILL BE, WHERE TO DROP ANY
- -- LEFTOVERS (BUCKETS) IN WHICH INVENTORY SPOT THE FUEL WILL BE AND HOW MUCH FUEL NEEDS TO BE STORED
- function refuel(suckDir, dropDir, fuelSlot, requiredFuel)
- --[[turtle.select(fuelSlot)
- while turtle.getFuelLevel() < requiredFuel do
- suck(suckDir)
- turtle.refuel()
- drop(dropDir)
- sleep(0)
- end]]--
- turtle.select(1)
- end
- -- -------------------------------------------------------------------- --
- -- END OF COPY/PASTED CODE EXTENDING THE FUNCTIONALITY OF THE BASIC API --
- -- -------------------------------------------------------------------- --
- -- -------------------------------------------------- --
- -- START OF THE FUNCTIONS SHARED BETWEEN ALL PROGRAMS --
- -- -------------------------------------------------- --
- -- CHECKS IF THE TURTLE NEEDS RESTOCKING
- function needsRestocking(configuration)
- --[[if turtle.getFuelLevel() < configuration.returnFuel then
- return true
- end]]--
- if turtle.getItemCount(15)~=0 or turtle.getItemCount(16)~=0 then
- return true
- end
- if configuration.placeTorches and turtle.getItemCount(1)==0 then
- return true
- end
- return false
- end
- -- EMPTIES THE INVENTORY, GETS NEW TORCHES AND NEW FUEL
- function restockTurtle(configuration, ignoreBlocks)
- tempL = configuration.currentL
- tempT = configuration.currentT
- tempS = configuration.currentS
- if configuration.singleChest then
- moveToLocation(configuration, 1, 1, 0)
- else
- moveToLocation(configuration, tempL, tempT, 0)
- end
- dropoff(configuration, ignoreBlocks)
- if configuration.placeTorches then
- restockTorches(configuration, ignoreBlocks)
- end
- if configuration.requiresFuel then
- refuel(configuration.fuelSuckDir, configuration.fuelDropDir, 16, configuration.departureFuel)
- end
- moveToLocation(configuration, tempL, tempT, tempS)
- end
- -- PARTIALLY EMPTIES THE INVENTORY
- function dropoff(configuration, ignoreBlocks)
- ignoreBlocks = ignoreBlocks or 0
- local torchSlot=0
- if configuration.placeTorches then
- torchSlot=1
- end
- -- Drop the extras of the ignore blocks
- turnTo(configuration.itemDropDir)
- for i=1+torchSlot,torchSlot+ignoreBlocks do
- turtle.select(i)
- drop(turnedDir(configuration.itemDropDir), math.max(turtle.getItemCount(i)-1, 0))
- end
- turnFrom(configuration.itemDropDir)
- -- Drop the other items
- turnTo(configuration.itemDropDir)
- for i=torchSlot+ignoreBlocks+1,16 do
- turtle.select(i)
- drop(turnedDir(configuration.itemDropDir), turtle.getItemCount(i))
- end
- turnFrom(configuration.itemDropDir)
- turtle.select(1)
- end
- -- COMPLETELY EMPTIES THE INVENTORY
- function dropAll(configuration, ignoreBlocks)
- ignoreBlocks = ignoreBlocks or 0
- local torchSlot=0
- -- Drop the torches
- if configuration.placeTorches then
- torchSlot=1
- drop(configuration.torchSuckDir)
- end
- -- Drop the extras of the ignore blocks
- turnTo(configuration.itemDropDir)
- for i=1+torchSlot,torchSlot+ignoreBlocks do
- turtle.select(i)
- drop(turnedDir(configuration.itemDropDir), math.max(turtle.getItemCount(i)-1, 0))
- end
- turnFrom(configuration.itemDropDir)
- -- Drop the ignore blocks
- turnTo(configuration.ignoreDir)
- for i=1+torchSlot,torchSlot+ignoreBlocks do
- turtle.select(i)
- drop(turnedDir(configuration.ignoreDir), 1)
- end
- turnFrom(configuration.ignoreDir)
- -- Drop the other items
- turnTo(configuration.itemDropDir)
- for i=torchSlot+ignoreBlocks+1,16 do
- turtle.select(i)
- drop(turnedDir(configuration.itemDropDir), turtle.getItemCount(i))
- end
- turnFrom(configuration.itemDropDir)
- turtle.select(1)
- end
- -- GETS NEW TORCHES
- function restockTorches(configuration, ignoreBlocks)
- ignoreBlocks = ignoreBlocks or 0
- turnTo(configuration.torchSuckDir)
- local tDir = turnedDir(configuration.torchSuckDir)
- turtle.select(1)
- suck(tDir)
- turtle.select(2+ignoreBlocks)
- drop(tDir)
- turnFrom(configuration.torchSuckDir)
- end
- -- CALCULATES HOW MUCH MOVES NEED TO BE MADE TO GO FROM ONE SHAFT TO ANOTHER
- function calculateMoves(configuration, numL, fromS, toS)
- local lowS = fromS
- local highS = toS
- if highS < lowS then
- lowS = toS
- highS = fromS
- end
- if lowS == highS then
- return 0
- end
- local requiredMoves = 0
- if highS == (configuration.numS + 1) then
- if numL % 2 == 1 then
- requiredMoves = requiredMoves+configuration.evenLevelOffset
- end
- highS = highS - 1
- end
- if lowS == 0 then
- requiredMoves = requiredMoves+configuration.firstShaftOffset
- if numL % 2 == 0 then
- requiredMoves = requiredMoves+configuration.evenLevelOffset
- end
- requiredMoves = requiredMoves+((configuration.blocksBetweenShafts+1)*(highS-1))
- else
- requiredMoves = requiredMoves+((configuration.blocksBetweenShafts+1)*(highS-lowS))
- end
- return requiredMoves
- end
- -- MOVES FROM THE CURRENT LOCATION TO ANOTHER
- function moveToLocation(configuration, newL, newT, newS)
- if newL == configuration.currentL and newT == configuration.currentT then
- if configuration.currentS < newS then
- digAndMove(forward, calculateMoves(configuration, newL, configuration.currentS, newS))
- elseif newS < configuration.currentS then
- digAndMove(reverseDir(forward), calculateMoves(configuration, newL, configuration.currentS, newS))
- end
- else
- local turnDir = configuration.nextDirT
- local moves = newT - configuration.currentT
- if configuration.currentT > newT then
- turnDir = reverseDir(turnDir)
- moves = configuration.currentT - newT
- end
- if configuration.currentS == 0 then
- digAndMove(forward)
- turnTo(turnDir)
- else
- turnTo(back)
- digAndMove(forward, calculateMoves(configuration, configuration.currentL, 0, configuration.currentS)-1)
- turnFrom(turnDir)
- end
- digAndMove(forward, configuration.centerRadius+1)
- if configuration.currentL < newL then
- digAndMove(configuration.nextDirL, (newL-configuration.currentL)*(configuration.height+1))
- end
- if configuration.currentL > newL then
- digAndMove(reverseDir(configuration.nextDirL), (configuration.currentL-newL)*(configuration.height+1))
- end
- if newT == configuration.currentT then
- turnTo(back)
- else
- turnTo(turnDir)
- for i=2, moves do
- digAndMove(forward, 2*(configuration.centerRadius+1))
- turnTo(turnDir)
- end
- end
- if newT == configuration.currentT then
- turnDir = reverseDir(turnDir)
- end
- digAndMove(forward, configuration.centerRadius+1)
- if newS == 0 then
- turnTo(turnDir)
- digAndMove(forward)
- turnTo(back)
- else
- turnFrom(turnDir)
- digAndMove(forward, calculateMoves(configuration, newL, 0, newS)-1)
- end
- end
- configuration.currentL = newL
- configuration.currentT = newT
- configuration.currentS = newS
- end
- -- ------------------------------------------------ --
- -- END OF THE FUNCTIONS SHARED BETWEEN ALL PROGRAMS --
- -- ------------------------------------------------ --
- -- ------------------------------------------ --
- -- START OF THE FUNCTIONS SPECIFIC TO digOres --
- -- ------------------------------------------ --
- -- EXCAVATES A SHAFT, DIGGING OUT ALL THE SPECIAL BLOCKS (ORES ETC)
- function excavateShaft(configuration, dir)
- local squaresMoved=0
- for i=1,configuration.centerRadius+calculateMoves(configuration, configuration.currentL, 0, configuration.currentS) do
- if needsRestocking(configuration) then
- turnTo(back)
- exitShaftAndRestock(configuration, dir, squaresMoved)
- end
- if digAndMove(forward)==0 then
- print("Encountered obstruction in:")
- print(" LEV: "..configuration.currentL)
- print(" TUN: "..configuration.currentT)
- print(" SH : "..configuration.currentS.." ("..dir..")")
- break
- end
- squaresMoved = squaresMoved + 1
- checkSides(configuration, up)
- end
- digAndMove(down)
- turnTo(back)
- checkSides(configuration, down)
- for i=1,squaresMoved do
- if configuration.placeTorches and (squaresMoved%8==7) then
- place(up, 1)
- end
- if needsRestocking(configuration) then
- digAndMove(up)
- exitShaftAndRestock(configuration, dir, squaresMoved)
- turnTo(back)
- digAndMove(down)
- end
- if digAndMove(forward)==0 then
- print("Encountered obstruction in:")
- print(" LEV: "..configuration.currentL)
- print(" TUN: "..configuration.currentT)
- print(" SH : "..configuration.currentS.." ("..dir..")")
- break
- end
- squaresMoved = squaresMoved - 1
- checkSides(configuration, down)
- end
- digAndMove(up)
- digAndMove(forward, squaresMoved)
- end
- -- CHECKS IF THE BLOCKS AT THE LEFT OR RIGHT ARE SPECIAL (AND THE TOP OR BOTTOM, DEPENDING ON THE INPUT)
- -- IF SO IT WILL DIG OUT THAT BLOCK AND EXCAVATE THE REST OF THE VEIN
- function checkSides(configuration, vDir)
- check(configuration, vDir)
- check(configuration, left)
- check(configuration, right)
- end
- -- DROPS THE ITEMS IN THE INVENTORY AND REFUELS THE TURTLE
- function exitShaftAndRestock(configuration, dir, squaresMoved)
- local cur
- digAndMove(forward, squaresMoved)
- turnTo(dir)
- restockTurtle(configuration, configuration.numIgnoreBlocks)
- turnTo(dir)
- digAndMove(forward, squaresMoved)
- end
- -- CHECKS IF A BLOCK IN A CERTAIN DIRECTION IS SPECIAL
- -- IF SO IT WILL DIG OUT THAT BLOCK AND EXCAVATE THE REST OF THE VEIN
- function check(configuration, dir)
- turnTo(dir)
- local tDir=turnedDir(dir)
- if detect(tDir) then
- if isSpecial(configuration, tDir) then
- if digAndMove(tDir) == 1 then
- excavate(configuration)
- digAndMove(reverseDir(tDir))
- end
- end
- end
- turnFrom(dir)
- end
- -- CHECKS IF A BLOCK IN A CERTAIN DIRECTION IS SPECIAL (NOT ONE OF THE REFERENCE COMPONENTS (DIRT ETC))
- function isSpecial(configuration, dir)
- turnTo(dir)
- local tDir=turnedDir(dir)
- local torchSlot=0
- if configuration.placeTorches then
- torchSlot=1
- end
- if not detect(tDir) then
- return false
- end
- for i=1, configuration.numIgnoreBlocks do
- if compare(tDir, i+torchSlot) then
- turnFrom(dir)
- return false
- end
- end
- turnFrom(dir)
- return true
- end
- -- EXCAVATES AN ORE VEIN
- function excavate(configuration)
- local numSteps = 0
- local steps = {}
- repeat
- steps[numSteps] = steps[numSteps] or 0
- steps[numSteps] = lookForOres(configuration, steps[numSteps])
- if steps[numSteps] ~= 7 then
- if digAndMove(turnedDir(intToDir(steps[numSteps]))) == 1 then
- numSteps = numSteps + 1
- end
- else
- steps[numSteps] = 0
- numSteps = numSteps - 1
- if numSteps >= 0 then
- digAndMove(reverseDir(turnedDir(intToDir(steps[numSteps]))))
- end
- end
- until numSteps < 0
- end
- -- LOOKS AROUND THE CURRENT POSITION, LOOKING FOR ORES
- function lookForOres(configuration, dir)
- if dir < 1 then
- dir = dir + 1
- if isSpecial(configuration, up) then
- return 1
- end
- end
- if dir < 2 then
- dir = dir + 1
- if isSpecial(configuration, down) then
- return 2
- end
- end
- if dir > 2 then
- turnTo(left)
- end
- for dir=dir+1, 6 do
- if isSpecial(configuration, forward) then
- return dir
- end
- turnTo(left)
- end
- return 7
- end
- -- CONVERTS AN INTEGER TO A DIRECTION
- function intToDir(dir)
- if dir == 1 then
- return up
- elseif dir == 2 then
- return down
- elseif dir == 3 then
- return forward
- elseif dir == 4 then
- return left
- elseif dir == 5 then
- return back
- elseif dir == 6 then
- return right
- end
- end
- -- PUTS THE IGNORE BLOCKS IN THE INVENTORY
- function restockIgnore(configuration, ignoreBlocks)
- local torchSlot=0
- if configuration.placeTorches then
- torchSlot=1
- end
- turnTo(configuration.ignoreDir)
- local tDir = turnedDir(configuration.ignoreDir)
- for i=1+torchSlot,ignoreBlocks+torchSlot do
- suck(tDir)
- end
- turnFrom(configuration.ignoreDir)
- end
- -- CHECKS IF THE USER PLACED ENOUGH BLOCKS IN THE INVENTORY
- function enoughBlocksProvided(configuration)
- local torchSlot=0
- if configuration.placeTorches then
- torchSlot=1
- end
- for i=1+torchSlot,configuration.numIgnoreBlocks+torchSlot do
- if turtle.getItemCount(i)==0 then
- return false
- end
- end
- return true
- end
- -- ---------------------------------------- --
- -- END OF THE FUNCTIONS SPECIFIC TO digOres --
- -- ---------------------------------------- --
- -- ------------------------------------------------------------ --
- -- START OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS --
- -- ------------------------------------------------------------ --
- restockTurtle(configuration, configuration.numIgnoreBlocks)
- restockIgnore(configuration, configuration.numIgnoreBlocks)
- if not enoughBlocksProvided(configuration) then
- term.clear()
- print("You said you wanted to turtle")
- print("To ignore "..configuration.numIgnoreBlocks.." blocks but didn't")
- print("place them all in the inventory")
- return
- end
- if (configuration.departureFuel < 400) then
- print("Warning: Low fuel value chosen")
- print("Do you wish to proceed? (Y/N)")
- local answer=io.read()
- if not (answer=="Y") then
- return
- end
- end
- -- For every level
- for curL = 1 + configuration.skipL, configuration.numL do
- local firstT = 1
- if curL == 1 + configuration.skipL then
- firstT = firstT + configuration.skipT
- end
- -- For every tunnel
- for curT = firstT, configuration.numT do
- local firstS = 1
- if (curL == 1 + configuration.skipL) and (curT == 1 + configuration.skipT) and (configuration.skipS~=0) then
- firstS = 1 + configuration.skipS
- end
- -- For every shaft
- for curS = firstS, configuration.numS do
- moveToLocation(configuration, curL, curT, curS)
- turnTo(left)
- excavateShaft(configuration, left)
- excavateShaft(configuration, right)
- turnTo(right)
- if needsRestocking(configuration) then
- restockTurtle(configuration, configuration.numIgnoreBlocks)
- end
- end
- end
- end
- -- Return to start
- moveToLocation(configuration, 1, 1, 0)
- dropAll(configuration, configuration.numIgnoreBlocks)
- -- ---------------------------------------------------------- --
- -- END OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS --
- -- ---------------------------------------------------------- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement