Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Program Name: Comms Quarry(turtle)
- Author: Ryder Daniel
- Creation Date: 25/12/16
- RULES OF THE QUARRY:
- 1: The turtle will travel to the location, then always dig west
- 2: The turtle always drops the items beneath it, thus prepare a cargo acceptance area accordingly
- 3: The cargo dropping area is the home coordinates
- ]]--
- args = {...} --arguments for computer/turtle ID
- --[[initialising vars for convenience]]--
- --[[
- Rules:
- 1: the initial turtle or the leftmost turtle will be the first one, acting like a clock hand
- Notes:
- I will write the code so it assumes that all the turtles are spaced out evenly according to the spacing
- variable and also that they are all facing the same direction by making the defined turtle the leftmost
- one. An example of my logic is that if you have a turtle facing south with a spacing of two, the computer
- will assume that the next turtle will be two blocks to the east facing the same way. The turtles will
- misbehave if you do it any other way because they only know what you let them...
- ]]--
- xCoord =
- zCoord =
- yCoord =
- xTarget = 0
- zTarget = 0
- yTarget = 0
- orientation = 3 --direction facing (1:N 2:E 3:S 4:W)
- defaultHomeLook = "south" --default facing direction upon going home
- spacing = 2 --spacing of the turtles. the gap in between is equal to the entry - 1
- lineLength = 0 --length of the quarry
- lines = 0 --width of the quarry
- depth = 0 --depth of the quarries
- --when setting up the turtles, dont forget to set the argument for the first turtle to 0
- function knowplace()
- if orientation == 1 then
- xCoord = xCoord + (spacing * tonumber(args[1]))
- defaultLook = "east"
- elseif orientation == 2 then
- zCoord = zCoord + (spacing * tonumber(args[1]))
- defaultLook = "south"
- elseif orientation == 3 then
- xCoord = xCoord - (spacing * tonumber(args[1]))
- defaultLook = "west"
- elseif orientation == 4 then
- zCoord = zCoord - (spacing * tonumber(args[1]))
- defaultLook = "north"
- end
- end
- --[[vars]]--
- cruise = 100 -- cruising altitude
- xHome, zHome, yHome = 0 -- declaring home coords
- xProg, zProg, yProg = 0 -- declaring progress coords
- progDir = 0 -- declarinf where the turtle was last looking
- progState = "even"
- orientations = {"north", "east", "south", "west"}
- --[[quarry vars]]--
- lineProg, linesDone = 0
- --[[functions for movement]]--
- function left()
- orientation = orientation - 1
- orientation = (orientation - 1) % 4
- orientation = orientation + 1
- turtle.turnLeft()
- end
- function right()
- orientation = orientation - 1
- orientation = (orientation + 1) % 4
- orientation = orientation + 1
- turtle.turnRight()
- end
- function moveUp()
- yCoord = yCoord + 1
- turtle.up()
- end
- function moveDown()
- yCoord = yCoord - 1
- turtle.down()
- end
- function forwardX()
- xCoord = xCoord + 1
- turtle.forward()
- end
- function backX()
- xCoord = xCoord - 1
- turtle.forward()
- end
- function forwardZ()
- zCoord = zCoord + 1
- turtle.forward()
- end
- function backZ()
- zCoord = zCoord - 1
- turtle.forward()
- end
- function look(direction)
- while direction ~= orientations[orientation] do
- right()
- end
- end
- function gotoxzyDir(xTarget, zTarget, yTarget, dir, trav)
- if trav == true then
- while yCoord < cruise do
- moveUp()
- end
- while yCoord > cruise do
- moveDown()
- end
- end
- if xTarget < xCoord then
- look("west")
- while xTarget < xCoord do
- backX()
- end
- end
- if xTarget > xCoord then
- look("east")
- while xTarget > xCoord do
- forwardX()
- end
- end
- if zTarget < zCoord then
- look("north")
- while zTarget < zCoord do
- backZ()
- end
- end
- if zTarget > zCoord then
- look("south")
- while zTarget > zCoord do
- forwardZ()
- end
- end
- while yCoord < yTarget do
- moveUp()
- end
- while yCoord > yTarget do
- moveDown()
- end
- look(dir)
- end
- function gohome()
- yProg = yCoord
- xProg = xCoord
- zProg = zCoord
- while yCoord < cruise do
- moveUp()
- end
- while yCoord > cruise do
- moveDown()
- end
- if xHome < xCoord then
- look("west")
- while xHome < xCoord do
- backX()
- end
- end
- if xHome > xCoord then
- look("east")
- while xHome > xCoord do
- forwardX()
- end
- end
- if zHome < zCoord then
- look("north")
- while zHome < zCoord do
- backZ()
- end
- end
- if zHome > zCoord then
- look("south")
- while zHome > zCoord do
- forwardZ()
- end
- end
- while yCoord < yHome do
- moveUp()
- end
- while yCoord > yHome do
- moveDown()
- end
- look(defaultHomeLook)
- end
- --[[functions for the quarry]]--
- function updateProg()
- xProg = xCoord
- zProg = zCoord
- yProg = yCoord
- progDir = orientation
- end
- function checkInvIsFull()
- if turtle.getItemCount(16) == 0 then
- return false
- end
- end
- function moveForward()
- mn = 0
- while turtle.detect() do
- turtle.dig()
- end
- moved = false
- while not(moved) do
- moved = turtle.forward()
- mn = mn +1
- if mn == 20 and yProg < 7 then
- gohome()
- getJob()
- end
- end
- if orientation == 1 then
- zCoord = zCoord - 1
- elseif orientation == 2 then
- xCoord = xCoord + 1
- elseif orientation == 3 then
- zCoord = zCoord + 1
- elseif orientation == 4 then
- xCoord = xCoord -1
- end
- updateProg()
- if checkInvIsFull() ~= false then
- gohome()
- emptyItems()
- returnAndFinishLayer()
- end
- end
- function digLine()
- for i =1, lineLength - 1 do
- moveForward()
- lineProg = lineLength - i
- end
- end
- function digLayer(lines)
- for i = 1, lines do
- digLine()
- linesDone = i
- if i % 2 == 1 and i < lines then
- progState = "even"
- left()
- moveForward()
- left()
- elseif i < lines then
- progState = "odd"
- right()
- moveForward()
- right()
- end
- end
- updateProg()
- end
- function digQuarry()
- while yProg > yTarget - depth do
- digLayer(lines)
- gotoxzyDir(xTarget, zTarget, yCoord, defaultLook, false)
- turtle.digDown()
- moveDown()
- updateProg()
- end
- gohome()
- print("FINISHED Awaiting Job...")
- end
- function returnAndFinishLayer()
- gotoxzyDir(xProg, zProg, yProg, progDir, true)
- for i=1, lineProg do
- moveForward()
- end
- linesDone = linesDone + 1
- if progState == "odd" then
- left()
- moveForward()
- left()
- elseif progState == "even" then
- right()
- moveForward()
- right()
- end
- digLayer(lines - linesDone)
- digQuarry()
- end
- function emptyItems()
- for i=1,16 do
- turtle.select(i)
- turtle.dropDown(64)
- end
- end
- --[[comms stuff]]--
- function main()
- term.clear()
- center(1,"RYDER'S QUARRY INITIALIZING INTERFACE")
- term.setCursorPos(1,3)
- print("PLEASE ENTER THE DEPTH OF THE HOLE: ")
- depth = read()
- print("PLEASE ENTER THE LENGTH: ")
- lineLength = read()
- print("PLEASE ENTER THE WIDTH: ")
- lines = read()
- print("PLEASE ENTER THE X COORDINATE FOR THE TOP LEFT OF THE QUARRY: ")
- xTarget = read()
- print("PLEASE ENTER THE Z COORDINATE FOR THE TOP LEFT OF THE QUARRY: ")
- zTarget = read()
- print("PLEASE ENTER THE SURFACE LEVEL OF THE QUARRY: ")
- yTarget = read()
- print("PLEASE ENTER THE DIRECTION OF THE TURTLE:(1:N, 2:E 3:S, 4:W)")
- orientation = read()
- t = true
- while t do
- term.clear()
- center(1,"RYDER'S QUARRY INITIALIZING INTERFACE", true)
- for i = 3, 11 do
- term.setCursorPos((w/2 - string.len(arr[i-2]) + 2),i)
- print(arr[i-2])
- end
- term.setCursorPos((w/2)+2,3)
- print(diam)
- term.setCursorPos((w/2)+2,4)
- print(depth)
- term.setCursorPos((w/2)+2,5)
- print(length)
- term.setCursorPos((w/2)+2,6)
- print(width)
- term.setCursorPos((w/2)+2,7)
- print(turts)
- term.setCursorPos((w/2)+2,8)
- print(xTar)
- term.setCursorPos((w/2)+2,9)
- print(zTar)
- term.setCursorPos((w/2)+2,10)
- print(yTar)
- term.setCursorPos((w/2)+2,11)
- print(dir)
- center(13, "IS THIS THE CORRECT INFORMATION? (Y/N)", true)
- input = read()
- if input == "y" or input == "Y" or input == "YES" or input == "yes" then
- t = false
- digQuarry()
- elseif input == "N" or input == "n" or input == "NO" or input == "no" then
- t = false
- else
- break
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement