Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program manages base turtles, and allows the user to quickly set a specialization for the turtle
- Turtle_Mode = "idle"
- Turtle_Target = {nil,nil,nil}
- Turtle_Action = nil
- ControlComputerID = nil
- Turtle_Role = "Basic"
- Turtle_RestSpot = {nil,nil,nil}
- Turtle_CommandProtocol = -1
- Turtle_WorkArea = {nil,nil,nil,nil}
- local TurtleX = nil
- local TurtleY = nil
- local TurtleZ = nil
- local Turtle_Heading = 1 --1= North, 2= East, 3= South, 4= West
- local
- start()
- function start()
- ConfigManager("Boot")
- if fuel < 20 then
- TurtleAction = "Refuel"
- Turtle_Target = Turtle_RestSpot
- TaskManager()
- else
- Boot()
- end
- end
- function Boot()
- if Turtle_Role == "Basic" then
- DirectiveReceiver()
- else
- if fs.exists("AdvControl") == false then
- SetupRole()
- else
- shell.run("AdvControl")
- end
- end
- end
- function DirectiveReceiver()
- end
- function TaskManager()
- local x, y, z = gps.locate()
- TurtleX = x
- TurtleY = y
- TurtleZ = z
- while true do
- if TurtleX == Turtle_Target[1] and TurtleY == Turtle_Target[2] and TurtleZ == Turtle_Target[3] then
- break
- else
- if TurtleX > Turtle_Target[1] then
- Turn(4)
- turtle.forward()
- elseif TurtleX < Turtle_Target[1] then
- Turn(2)
- turtle.forward()
- end
- if TurtleY > Turtle_Target[2] then
- turtle.down()
- elseif TurtleY < Turtle_Target[2] then
- turtle.up()
- end
- if TurtleZ > Turtle_Target[3] then
- Turn(3)
- turtle.forward()
- elseif TurtleZ < Turtle_Target[3] then
- Turn(1)
- turtle.forward()
- end
- end
- end
- if Turtle_Action =="Refuel" then
- FindChest("Coal")
- Turtle_Action = nil
- Turtle_Mode = "idle"
- Turtle_Target = {nil,nil,nil}
- elseif Turtle_Action == "Move" then
- Turtle_Action = nil
- Turtle_Mode = "idle"
- Turtle_Target = {nil,nil,nil}
- elseif Turtle_Action == "Scan" then
- end
- DirectiveReceiver()
- end
- function FindChest(Item)
- while true do
- if turtle.detect() == chest then
- turtle.suck(20)
- break
- else
- turtle.turnLeft()
- Turtle_Heading = Turtle_Heading + 1
- if Turtle_Heading > 4 then
- Turtle_Heading = 1
- end
- end
- end
- end
- function Turn(Direction)
- while true do
- if Turtle_Heading > Direction then
- turtle.turnLeft()
- elseif Turtle_Heading < Direction then
- turtle.turnRight()
- else
- break
- end
- end
- end
- function ConfigManager(Action)
- local file = nil
- if Action == "Boot" then
- file = fs.open("TurtleConfig","r")
- ControlComputerID = readLine(1)
- Turtle_Role = readLine(2)
- Turtle_RestSpot = readLine(3)
- Turtle_CommandProtocol = readLine(4)
- Turtle_WorkArea = readLine(5)
- elseif Action == "Save then
- file = fs.open("TurtleConfig","w")
- elseif Action == "New" then
- Setup()
- file = fs.open("TurtleConfig","w")
- file.writeLine(ControlComputerID)
- file.writeLine(Turtle_Role)
- file.writeLine(Turtle_RestSpot)
- file.writeLine(Turtle_CommandProtocol)
- file.writeLine(Turtle_WorkArea)
- end
- file.close
- end
- function Setup()
- local x, y, z = gps.locate()
- Turtle_RestSpot = {x,y,z}
- Turtle_WorkArea = "n"
- rednet.broadcast("TurtleSetup",2000)
- repeat
- local id, message, protocol = rednet.receive()
- until message == "Ap_Turtle"
- ControlComputerID = id
- Turtle_CommandProtocol = protocol
- rednet.send(ControlComputerID,"ready",TurtleCommandProtocol)
- local message = rednet.receive()
- Turtle_Role = message
- end
- function SetupRole()
- local file = fs.open("AdvControl","r")
- file.Close
- shell.run("pastebin","run","wtgkv33A")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement