Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The turtle will always be in a loop unless it is ordered to shut down.
- -- Shut down will return the turtle to the OS after one final broadcast of its location.
- turtleShutDown = false
- -- The turtle will always be running unless it receives a signal to deactivate.
- turtleActive = true
- currentState = "Initialize"
- previoiusState = ""
- turtleStates = {"Initialize", "Refuel", "Travel", "Mine", "Tunnel", "Chop", "Escape", "Home", "Sleep", "Explore", "Build", "Organize"}
- -- Allows for turtles to be dedicated to one or more jobs. Initialize, Refuel, Travel, Escape, Home, and Sleep will always be true.
- allowedTurtleStates = {true, true, true, true, true, true, true, true, true, true, true, true}
- -- The turtle will keep track of its location and facing and will broadcast its location to the server.
- worldCoord = vector.new(0,0,0)
- relativeCoord = vector.new(0,0,0)
- facing = 1
- facings = {"West", "North", "East", "South"}
- -- A fuel slot will default to 1 unless defined otherwise.
- -- A turtle can have more than one fuel slot.
- fuelSlot = 1
- function isTurtleHome()
- isHome = false
- if xHome == 0 and zHome == 0 and yHome == 0 then
- isHome = true
- end
- return isHome
- end
- function activateState(stateName)
- message = ""
- for stateNumber = 1,12 do
- if stateName == turtleStates[stateNumber] then
- allowedTurtleStates = true
- else
- message = "Unknown state."
- end
- end
- message = turtleStates[stateNumber] .. " is active."
- return message
- end
- function deactivateState(stateName)
- message = ""
- for stateNumber = 1,12 do
- if stateName == turtleStates[stateNumber] then
- if stateNumber == 1 or stateNumber == 2 or stateNumber == 3 or stateNumber == 7 or stateNumber == 8 or stateNumber == 9 then
- message = turtleStates(stateName) .. " cannot be deactivated."
- else
- allowedTurtleStates = false
- message = turtleStates(stateName) .. " is deactivated."
- end
- else
- message = "Unknown state."
- end
- end
- return message
- end
- while not (turtleShutDown) do
- -- Active state manager. As long as the turtle is active, this loop will always run.
- while turtleActive do
- -- LISTEN FOR SIGNAL
- -- The server can send a signal to the turtle to activate/deactivate or to change its state
- -- The refueling function should be called within the individual states, as necessary.
- -- Refueling may return to the core functionality of the turtle.
- -- CORE FUNCTIONALITY
- -- THIS IS WHERE ALL OF THE CORE FUNCTIONS AND BEHAVIORS WILL BE LOCATED
- -- The functions found within will be located in their own files. (new API?)
- -- END CORE FUNCTIONALITY
- -- Broadcast location
- end
- -- Inactive manager. As long as the turtle is inactive, this loop will always run.
- while not(turtleActive) do
- -- LISTEN FOR SIGNAL
- -- If the turtle is not home, it repeatedly broadcasts its location for retrieval.
- if not(isTurtleHome()) then
- -- Broadcast location
- end
- end
- -- Broadcast location
Advertisement
Add Comment
Please, Sign In to add comment