Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- edit this
- turtleID = os.computerID()
- print("Turtle "..turtleID.." is online.")
- --- 2lines below are test
- --broadcastID, broadcastMSG = rednet.receive()
- --print("Broadcast from "..broadcastID..": "..broadcastMSG)
- rednet.close("right")
- rednet.open("right")
- xLoc, zLoc, yLoc = gps.locate(10)
- --xLoc = 10
- --zLoc = 11
- --yLoc = 12
- print("Docked at "..xLoc.." "..zLoc.." "..yLoc..".")
- xCoord = xLoc
- zCoord = zLoc
- yCoord = yLoc
- --xCoord = -256
- --zCoord = 227
- --yCoord = 70
- xQuarry = 999
- zQuarry = 999
- yQuarry = 150
- xProgress = 999
- zProgress = 999
- yProgress = 150
- oProgress = 1
- xHome = xCoord
- zHome = zCoord
- yHome = yCoord
- yTravel = 85
- orientation = 1
- orientations = {"north", "east", "south", "west"}
- zDiff = {-1, 0, 1, 0}
- xDiff = {0, 1, 0, -1}
- lineLength = 2
- lines = 3
- yMin = 999
- jobAvailable = true
- managerID = 28
- turtle.refuel(10)
- function inventoryFull()
- turtle.select(9)
- full = turtle.getItemCount(9) > 0
- turtle.select(1)
- return full
- end
- 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 moveForward()
- xCoord = xCoord + xDiff[orientation]
- zCoord = zCoord + zDiff[orientation]
- while turtle.detect() do
- turtle.dig()
- end
- moved = false
- while not(moved) do
- moved = turtle.forward()
- end
- end
- function moveUp()
- yCoord = yCoord + 1
- turtle.digUp()
- moved = false
- while not(moved) do
- moved = turtle.up()
- end
- end
- function moveDown()
- yCoord = yCoord - 1
- turtle.digDown()
- moved = false
- while not(moved) do
- moved = turtle.down()
- end
- if yMin > yCoord then
- yMin = yCoord
- end
- end
- function look(direction)
- while direction ~= orientations[orientation] do
- right()
- end
- end
- function goto(xTarget, zTarget, yTarget)
- while yTarget < yCoord do
- moveDown()
- end
- while yTarget > yCoord do
- moveUp()
- end
- if xTarget < xCoord then
- look("west")
- while xTarget < xCoord do
- moveForward()
- end
- end
- if xTarget > xCoord then
- look("east")
- while xTarget > xCoord do
- moveForward()
- end
- end
- if zTarget < zCoord then
- look("north")
- while zTarget < zCoord do
- moveForward()
- end
- end
- if zTarget > zCoord then
- look("south")
- while zTarget > zCoord do
- moveForward()
- end
- end
- end
- function returnItems()
- xProgress = xCoord
- zProgress = zCoord
- yProgress = yCoord
- oProgress = orientation
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- -- edit this was west
- look("south")
- for i = 1,9 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- goto(xProgress, zProgress, yTravel)
- goto(xProgress, zProgress, yProgress)
- look(orientations[oProgress])
- end
- function digLine()
- for i = 1,lineLength do
- if inventoryFull() then
- returnItems()
- end
- moveForward()
- end
- end
- function digLayer()
- for i = 1,lines do
- digLine()
- if (i%2) == 1 and i < lines then
- left()
- moveForward()
- left()
- elseif i < lines then
- right()
- moveForward()
- right()
- end
- end
- goto(xQuarry, zQuarry, yCoord)
- look("north")
- moveDown()
- end
- function digQuarry(xTarget, zTarget, yTarget)
- xQuarry = xTarget
- zQuarry = zTarget
- yQuarry = yTarget
- goto(xQuarry, zQuarry, yTravel)
- goto(xQuarry, zQuarry, yQuarry)
- look("north")
- while yMin > 7 do
- digLayer()
- end
- goto(xQuarry, zQuarry, yQuarry)
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- yMin = 999
- end
- function getJob()
- while jobAvailable do
- print("Requesting job...")
- -- need to fill in manager id below
- rednet.send(managerID, "getJob")
- id, message, dist = rednet.receive()
- if message == "yes" then
- id, xRec, dist = rednet.receive()
- id, zRec, dist = rednet.receive()
- id, yRec, dist = rednet.receive()
- xQuarry = tonumber(xRec)
- zQuarry = tonumber(zRec)
- yQuarry = tonumber(yRec)
- print("Received job, moving to "..xQuarry.." "..zQuarry)
- digQuarry(xQuarry, zQuarry, yQuarry)
- print("Finished job.")
- elseif message == "no" then
- print("No more jobs available.")
- jobAvailable = false
- end
- end
- end
- rednet.close("right")
- rednet.open("right")
- getJob()
Advertisement
Add Comment
Please, Sign In to add comment