Cozza38

Untitled

Jan 16th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.58 KB | None | 0 0
  1. -- module API by PonyKuu
  2. -- Version 0.2a
  3.  
  4. os.loadAPI("ccc")
  5. -- A little change to standard assert function
  6. _G.assert = function(condition, errMsg, level)
  7. if not condition then
  8. error(errMsg, (tonumber(level) or 1) + 1)
  9. end
  10. return condition
  11. end
  12.  
  13. --[[
  14. *********************************************************************************************
  15. * Communication Part *
  16. *********************************************************************************************
  17. ]]--
  18. -- There are some variables used for communication
  19. -- ID is the turtle's unique identifier
  20. -- Master is the ID of the master
  21. -- Channel is the channel used to send messages to Master
  22. -- Master should respond on channel+1
  23. -- Type is the type of the module. Used by Master to determine what it can do
  24. local ID = 0
  25. local Master = 0
  26. local channel = 100
  27. local Type = "default"
  28.  
  29. function progressReport(progress)
  30. ccc.sendSerialized("swarmling","bridge",{
  31. ["type"]="swarmling",
  32. ["turtleId"]=tostring(ID),
  33. ["msg"]="update",
  34. ["complete"]=progress
  35. })
  36. end
  37.  
  38. function setType (newType)
  39. assert (type(newType) == "string", "Bad module type: String required", 2)
  40. Type = newType
  41. end
  42.  
  43. -- Wee need a modem to communicate.
  44. local modem = peripheral.wrap ("right")
  45.  
  46. -- The first function is used to parse a message received on modem
  47. -- It determines whether the message is valid or not
  48. -- Message should be a table with fields
  49. -- 1) Protocol - must be equal to "KuuNet"
  50. -- 2) ID - that must be equal to turtle's ID
  51. -- 3) Master - that must be equal to Master variable.
  52. -- Some other fiels
  53. local function isValid (message)
  54. return message ~= nil and
  55. type(message) == "table" and
  56. message.Protocol == "KuuNet" and
  57. message.ID == ID and
  58. message.Master == Master
  59. end
  60.  
  61. -- This function sends a request to Master and waits for a response.
  62. -- Request is just a simple string
  63. -- It returns response as message or nil
  64. function request (message, timeout)
  65. assert (type(message) == "string", "Bad message: String required, got "..type(message), 2)
  66. assert (type(timeout) == "number", "Bad timeout: Number required, got "..type(timeout), 2)
  67. -- open a channel to listen for response
  68. modem.open (channel+1)
  69. -- Make a message
  70. local request = {
  71. Protocol = "KuuNet",
  72. ID = ID,
  73. Type = Type,
  74. Master = Master,
  75. Request = message
  76. }
  77. -- And send it!
  78. modem.transmit (channel, channel+1, textutils.serialize(request))
  79. local response = nil
  80. -- Wait for a valid message as response until the timeout
  81. parallel.waitForAny (
  82. function ()
  83. sleep (timeout)
  84. end,
  85. function ()
  86. while true do
  87. local _, _, _, _, textMessage = os.pullEvent("modem_message")
  88. local msg = textutils.unserialize (textMessage)
  89. if isValid(msg) then
  90. response = msg
  91. break
  92. end
  93. end
  94. end
  95. )
  96. modem.close (channel+1)
  97. return response
  98. end
  99.  
  100. --[[
  101. *********************************************************************************************
  102. * Navigation Part *
  103. *********************************************************************************************
  104. ]]--
  105.  
  106. -- Navigation variables.
  107.  
  108. -- Location is a global table containing all the coordinates and facing direction of the turtle
  109. local location = {x = 0, y = 0, z = 0, f = 0}
  110. -- naviData is the table used to organize the navigation of the modules so they don't lock one another movement
  111. -- Details are explaind a bit later
  112. local naviData = {x = 0, z = 0, height = 0}
  113.  
  114. -- This is the variable used to store the numbers of slots, where Ender Chests are located. Fuel chest is used to refuel the turtle, and
  115. -- Stuff chest is used to dump all the stuff mined by turtle. You can switch it off simply by setting the corresponding field to nil
  116. local chests = {Fuel = 1, Stuff = 2}
  117.  
  118. -- Here is the function to set the position of the turtle and another one to get it.
  119. function setPosition (newPosition)
  120. assert (type(newPosition) == "table", "Bad position: Table required, got "..type(newPosition), 2)
  121. for key, value in pairs(location) do
  122. assert (type(value) == "number", "Bad coordinate "..key..": Number required, got "..type(value), 2)
  123. location[key] = value
  124. end
  125. end
  126.  
  127. function getPosition ()
  128. return {x = location.x,
  129. y = location.y,
  130. z = location.z,
  131. f = location.f,} -- return a copy of the location table.
  132. end
  133.  
  134. -- And a small function to print the position. For debug purposes
  135. function printPosition ()
  136. print ("Currrent turtle position:")
  137. print (" x = "..location.x)
  138. print (" y = "..location.y)
  139. print (" z = "..location.z)
  140. print (" f = "..location.f)
  141. end
  142.  
  143. -- A functions to set and get the navigation data.
  144. function setNaviData (newNaviData)
  145. assert (type(newNaviData) == "table", "Bad navigation data: Table required, got "..type(newNaviData), 2)
  146. naviData = newNaviData
  147. end
  148. function getNaviData ()
  149. return naviData
  150. end
  151.  
  152. -- A function to set the chest configuration
  153. function setChests (newConfiguration)
  154. assert (type(newConfiguration) == "table", "Bad chests configuration: Table required, got "..type(newConfiguration), 2)
  155. for chest, slot in pairs(newConfiguration) do
  156. assert (type(slot) == "number" and slot > 0 and slot < 17, "Bad chest field "..chest.." : Not a slot number", 2)
  157. chests [chest] = slot
  158. end
  159. end
  160.  
  161. -- Now let's move on to our navigation functions
  162.  
  163. -- A simple turning function. tTurns is used to chech whether the argument is valid
  164. local tTurns = {left = true, right = true, around = true}
  165. function turn (direction)
  166. assert (type(direction) == "string", "Bad direction. String required, got ".. type(direction), 2)
  167. assert (tTurns[direction], "Bad turn direction. Turn directions are \"left\", \"right\" and \"around\", got "..direction, 2)
  168. if direction == "left" then
  169. turtle.turnLeft()
  170. location.f = location.f - 1
  171. elseif direction == "right" then
  172. turtle.turnRight()
  173. location.f = location.f + 1
  174. elseif direction == "around" then
  175. turtle.turnLeft()
  176. turtle.turnLeft()
  177. location.f = location.f - 2
  178. end
  179. location.f = (location.f + 4) % 4 -- This is used to handle the f < 0 and f > 3 situations
  180. return true
  181. end
  182.  
  183. -- This one is used to turn the turtle to specified f direction.
  184. -- A little bit of pony magic is used to calculate how should it turn
  185. function turnTo (face)
  186. assert (type (face) == "number", "Bad f direction. Number required, got "..type (face), 2)
  187. assert (face >= 0 and face < 4, "Bad f direction. Required integer between 0 and 3, got "..face, 2)
  188. local diff = face - location.f
  189. if math.abs(diff) == 2 then --this is true if the difference between f and face is 2 or -2, so it should turn around
  190. return turn ("around")
  191. elseif math.fmod(diff + 4, 4) == 1 then --this is true if the difference between f and face is 1
  192. return turn ("right") --f = 0 and face = 3 is also satisfies the condition (-3 + 4 == 1)
  193. elseif math.fmod(diff - 4, 4) == -1 then --this is true if the difference between f and face is -1
  194. return turn ("left") --f = 3 and face = 1 is also satisfies the condition ( 3 - 4 == 1)
  195. end
  196. return false --returned if turtle is already faced the specified direction
  197. end
  198.  
  199. -- This function is used to return actual x and z shifts
  200. -- These shifts are the numbers which you should add to the coordinates when turtle moves forward.
  201. -- I use a table to decode it since it is more compact and easier to read than lots of conditions
  202. local tShifts = {
  203. [0] = { 1, 0},
  204. [1] = { 0, 1},
  205. [2] = {-1, 0},
  206. [3] = { 0, -1},
  207. }
  208. local function fDirection ()
  209. return unpack (tShifts[location.f])
  210. end
  211.  
  212. -- This function is used to update the turtle location when it has moved
  213. local function updateLocation (direction)
  214. if direction == "up" then
  215. location.y = location.y + 1
  216. elseif direction == "down" then
  217. location.y = location.y - 1
  218. elseif direction == "forward" then
  219. local xShift, zShift = fDirection ()
  220. location.x = location.x + xShift
  221. location.z = location.z + zShift
  222. end
  223. end
  224.  
  225. -- This function helps us with our EnderChests if there is something that obstructs placement
  226. -- It checks what's going on on top of it, and if there is a turtle, it waits.
  227. local function forcePlaceUp ()
  228. while not turtle.placeUp() do
  229. if turtle.detectUp() then
  230. if peripheral.isPresent ("top") and peripheral.getType ("top") == "turtle" then
  231. print "Other turtle detected. Waiting..."
  232. while peripheral.isPresent ("top") do
  233. sleep (2)
  234. end
  235. end
  236. turtle.digUp()
  237. elseif turtle.attackUp() then
  238. print "Attacking obstructing entity"
  239. end
  240. end
  241. end
  242.  
  243. -- This function tries to refuel the turtle to make it have an <amount> of fuel
  244. -- If it can't, it waits
  245. -- It also returns true if fuel is infinity
  246. function checkFuel (amount)
  247. assert (type(amount) == "number", "Bad fuel amount. Number required, got "..type(amount), 2)
  248. local fuel = turtle.getFuelLevel()
  249. if fuel == "unlimited" or fuel > amount then
  250. return true
  251. else
  252. turtle.select (chests.Fuel)
  253. forcePlaceUp ()
  254. turtle.suckUp ()
  255. while true do
  256. if not turtle.refuel (1) then
  257. if turtle.getItemCount (chests.Fuel) then
  258. turtle.dropUp ()
  259. end
  260. sleep (1)
  261. turtle.suckUp ()
  262. end
  263. if turtle.getFuelLevel () >= amount then
  264. if turtle.getItemCount (chests.Fuel) > 0 then
  265. turtle.dropUp ()
  266. end
  267. -- If it can't drop all the fuel into chest, just consume it all
  268. if turtle.getItemCount (chests.Fuel) > 0 then
  269. turtle.refuel (turtle.getItemCount(chests.Fuel))
  270. end
  271. turtle.digUp ()
  272. turtle.select (1)
  273. return true
  274. end
  275. sleep (1)
  276. end
  277. end
  278. end
  279.  
  280. -- This function used to empty the turtle's inventory into the ender chest in the second slot
  281. -- Warning! Required a good sorting system able to empty the chest as quickly as possible!
  282. -- It does something only if chests.Stuff is set
  283. function dumpStuff ()
  284. if chests.Stuff ~= nil then
  285. turtle.select (chests.Stuff)
  286. forcePlaceUp ()
  287. for i = 1,16 do
  288. if i ~= chests.Fuel and i ~= chests.Stuff then
  289. while turtle.getItemCount (i) > 0 do
  290. turtle.select (i)
  291. turtle.dropUp ()
  292. end
  293. end
  294. end
  295. turtle.select (chests.Stuff)
  296. turtle.digUp ()
  297. turtle.select (1)
  298. end
  299. end
  300.  
  301. -- This function checks if there is any empty slots in inventory (basically, in 16th slot)
  302. function checkSpace ()
  303. if turtle.getItemCount (16) > 0 then
  304. dumpStuff ()
  305. end
  306. end
  307.  
  308. -- Advanced movement function.
  309. -- Again, I use a set of tables with all the movements and other "directional" turtle actions
  310. -- The fuction detects if there is a turtle in the direction it wants to move, and if there is one, it waits while it moves away.
  311. -- If it waits too long (60 seconds), however, it just eats that turtle
  312. tMove = {
  313. forward = turtle.forward,
  314. up = turtle.up,
  315. down = turtle.down
  316. }
  317. tDetect = {
  318. forward = turtle.detect,
  319. up = turtle.detectUp,
  320. down = turtle.detectDown
  321. }
  322. tDig = {
  323. forward = turtle.dig,
  324. up = turtle.digUp,
  325. down = turtle.digDown
  326. }
  327. tAttack = {
  328. forward = turtle.attack,
  329. up = turtle.attackUp,
  330. down = turtle.attackDown
  331. }
  332. tIsTurtle = {
  333. forward = function ()
  334. if peripheral.isPresent ("front") and peripheral.getType ("front") == "turtle" then
  335. return true
  336. end
  337. return false
  338. end,
  339. up = function ()
  340. if peripheral.isPresent ("top") and peripheral.getType ("top") == "turtle" then
  341. return true
  342. end
  343. return false
  344. end,
  345. down = function ()
  346. if peripheral.isPresent ("bottom") and peripheral.getType ("bottom") == "turtle" then
  347. return true
  348. end
  349. return false
  350. end
  351. }
  352. function move (direction)
  353. assert (type(direction) == "string", "Bad move direction. String required, got "..type(direction), 2)
  354. assert (tMove[direction], "Bad move direction. Move directions are \"up\", \"down\" and \"forward\", got"..direction, 2)
  355. -- First, check whether we have fuel to move
  356. if not checkFuel (1) then
  357. return false
  358. end
  359. -- Second, try to move
  360. while not tMove[direction]() do
  361. -- If can't, check if there is a block
  362. if tDetect[direction]() then
  363. -- If it's a turtle, just wait while it moves away.
  364. -- WARNING! This may cause turtle interlocks!
  365. if tIsTurtle[direction]() then
  366. print "Other turtle detected. Waiting..."
  367. while tIsTurtle[direction]() do
  368. sleep (2)
  369. end
  370. else
  371. -- If it's not a turtle, try to dig that block
  372. if tDig[direction]() then
  373. checkSpace ()
  374. -- If we can't - we just can't move.
  375. else
  376. print "Can't pass the obstruction!"
  377. return false
  378. end
  379. end
  380. -- If it's not a block, that's probably an entity, so we attack it!
  381. elseif tAttack[direction]() then
  382. checkSpace ()
  383. end
  384. end
  385. -- If moved successfully, update the coordinates and return true
  386. updateLocation (direction)
  387. return true
  388. end
  389.  
  390. -- This one is used to move turtle to specified f direction OR up/down <count times>
  391. function moveEx (direction, count)
  392. assert (type(direction) == "number" or type(direction) == "string", "Bad direction. String or number required, got "..type(direction), 2)
  393. assert (type(count) == "number", "Bad count. Positive number required, got "..type(count), 2)
  394. assert (count > 0, "Bad count. Positive number required, got "..count, 2)
  395. if type(direction) == "number" then
  396. assert (direction >= 0 and direction < 4, "Bad direction. Numeric direction should be between 0 and 3, got "..direction)
  397. turnTo (direction)
  398. for i = 1, count do
  399. move ("forward")
  400. end
  401. else
  402. assert (direction == "up" or direction == "down", "Bad direction. String direction should either \"up\" or \"down\", got "..direction, 2)
  403. for i = 1, count do
  404. move (direction)
  405. end
  406. end
  407. end
  408.  
  409. -- A height function. For convinience
  410. function height (value)
  411. assert (type(value) == "number", "Bad value. Integer required, got "..type(value), 2)
  412. assert (value % 1 == 0, "Bad value. Integer required, got "..value, 2)
  413. local diff = value - location.y
  414. checkFuel(math.abs(diff))
  415. if diff > 0 then
  416. moveEx ("up", diff)
  417. elseif diff < 0 then
  418. moveEx ("down", -diff)
  419. end
  420. end
  421.  
  422. -- Small goto function. It moves turtle in one axis.
  423. -- Example: module.gotoOne ("x", 10) moves the turtle to x = 10
  424. -- tCoordinates is used to check if the coordinate is valid
  425. local tCoordinates = {x = true, y = true, z = true}
  426. function gotoOne (coordinate, value)
  427. assert (type(coordinate) == "string", "Bad coordinate. String required, got "..type(coordinate), 2)
  428. assert (tCoordinates[coordinate], "Bad coordinate. Coordinates are \"x\", \"y\" and \"z\", got "..coordinate, 2)
  429. assert (type(value) == "number", "Bad value. Integer required, got "..type(value), 2)
  430. assert (value % 1 == 0, "Bad value. Integer required, got "..value, 2)
  431. if coordinate == "y" then
  432. height (value)
  433. elseif coordinate == "x" then
  434. local diff = value - location.x
  435. checkFuel(math.abs(diff))
  436. if diff > 0 then
  437. moveEx (0, diff)
  438. elseif diff < 0 then
  439. moveEx (2, -diff)
  440. end
  441. elseif coordinate == "z" then
  442. local diff = value - location.z
  443. checkFuel(math.abs(diff))
  444. if diff > 0 then
  445. moveEx (1, diff)
  446. elseif diff < 0 then
  447. moveEx (3, -diff)
  448. end
  449. end
  450. end
  451.  
  452. -- Let's organize our movement a bit to avoid movement deadlocks. Thanks to Doyle3694 for the idea
  453. -- It is 2D navigation, so height is not taken into account. It will allow turtles to relocate themselves to their mining positions
  454. -- without stucking.
  455. -- I'll divide all the 2D area to four zones. In each zone turtle can move only in two directions.
  456. -- Zones are determinated by the pair of coordinates. Turtles will move clockwise relative to the point with that coordinates
  457. -- height is the height at which all navigation is done
  458.  
  459. -- There is a table used to determine to which directions turtle is allowed to move.
  460. -- Direction "first" is the direction turtle will move first ^_^ This one can't lead out of the zone.
  461. -- Direction "second" is leading to the next zone.
  462. -- Directions are the tables of coordinate and direction (+1 - positive, -1 - negative)
  463. local tZones = {
  464. z1 = {first = {"x", 1}, second = {"z", 1}},
  465. z2 = {first = {"z", 1}, second = {"x", -1}},
  466. z3 = {first = {"x", -1}, second = {"z", -1}},
  467. z4 = {first = {"z", -1}, second = {"x", 1}}
  468. }
  469.  
  470. -- Here is a function to determine in which zone turtle is
  471. local function currentZone ()
  472. if location.x > naviData.x then
  473. if location.z > naviData.z then
  474. return "z2"
  475. else
  476. return "z1"
  477. end
  478. else
  479. if location.z > naviData.z then
  480. return "z3"
  481. else
  482. return "z4"
  483. end
  484. end
  485. end
  486.  
  487. -- And there is one used to navigate turtle, taking into account zones.
  488. -- All the navigation is done at naviData.height and then turtle changes it's height
  489. function highwayNavigate (destination)
  490. -- check destination
  491. assert (type(destination) == "table", "Bad destination. Table required, got "..type(destination), 2)
  492. local tCoordinates = {"x", "y", "z", "f"}
  493. for i, coordinate in ipairs (tCoordinates) do
  494. assert (type(destination[coordinate]) == "number", "Bad destination parameter: "..coordinate..". Integer required, got "..type(destination[coordinate]), 2)
  495. assert (destination[coordinate] % 1 == 0, "Bad destination parameter: "..coordinate..". Integer required, got "..destination[coordinate], 2)
  496. end
  497. -- check navigation data
  498. for key, value in pairs (naviData) do
  499. assert (type(value) == "number", "Bad navigation parameter: "..key..". Number required, got "..type(value), 2)
  500. assert (value % 1 == 0, "Bad navigation parameter: "..key..". Integer required, got "..value, 2)
  501. end
  502. -- go to naviData.height only if we need to move
  503. if destination.x ~= location.x or destination.z ~= location.z then
  504. height (naviData.height)
  505. end
  506. while location.x ~= destination.x or location.z ~= destination.z do -- navigate between zones until we are in the place
  507. local zone = currentZone ()
  508. -- Let's unpack all the coordinates
  509. local coordinateFirst, directionFirst = unpack (tZones[zone].first)
  510. local coordinateSecond, directionSecond = unpack (tZones[zone].second)
  511. -- And check some things
  512. -- if we are allowed to move at both directions - just do it!
  513. if (destination[coordinateFirst]-location[coordinateFirst]) * directionFirst >= 0
  514. and (destination[coordinateSecond]-location[coordinateSecond]) * directionSecond >= 0 then
  515. -- BTW, we just check there that coordinate difference and destination has the same sign
  516. -- Otherwise turtle that is already went to "second" coordinate won't be able to change it's "first" coordinate
  517. -- Then just use gotoOne to go to the desired location
  518. gotoOne (coordinateFirst, destination[coordinateFirst])
  519. gotoOne (coordinateSecond, destination[coordinateSecond])
  520. else
  521. -- If we are not allowed to move by any of those coordinates in current zone
  522. -- Just head up to the second zone
  523. local nextPosition = naviData[coordinateSecond]
  524. -- We need to do that for actually leave z1 and z4 since they are one block bigger
  525. if zone == "z4" or zone == "z1" then
  526. nextPosition = nextPosition + 1
  527. end
  528. -- go to the next zone!
  529. gotoOne (coordinateSecond, nextPosition)
  530. end
  531. end
  532. height(destination.y)
  533. turnTo(destination.f)
  534. end
  535.  
  536. -- This function is used to actually navigate the turtle. By default it is set to Highway Navigation, but user may set it to other function
  537. -- It's just have to receive a location-like table with 4 coordinates and move turtle.
  538. navigateTo = highwayNavigate
  539.  
  540. function navigationMethod (newMethod)
  541. assert (type(newMethod) == "function", "Bad navigation method: Function required, got "..type(newMethod), 2)
  542. navigateTo = newMethod
  543. end
  544.  
  545. --[[
  546. *********************************************************************************************
  547. * Operation part *
  548. *********************************************************************************************
  549. ]]--
  550. -- Fallback location is the point where module goes if it can't get a task from Master
  551. local fallbackLocation = nil
  552. function setFallback (newFallbackLocation)
  553. fallbackLocation = newFallbackLocation
  554. end
  555.  
  556. -- We need to read all the data we need to move around - turtle's position and navigation zones
  557. -- "initdata" is the file created by Master and containing all the data that's similar for each module placed by that Master
  558. function init ()
  559. sleep(2)
  560. local file = fs.open ("/disk/initdata", "r")
  561. local communicationData = textutils.unserialize (file.readLine ())
  562. Master = communicationData.MasterID
  563. channel = communicationData.channel
  564. -- set module's location
  565. location = textutils.unserialize (file.readLine ())
  566. -- set navigation data
  567. naviData = textutils.unserialize (file.readLine ())
  568.  
  569. -- Then send a request to Master, to get our ID and to let Master remember us in its state table for modules
  570. local response = request ("Master", 5)
  571. ID = response.NewID
  572. end
  573.  
  574. -- Here is the task table. It is the table, that contains all the task module can get form Master and associated functions
  575. -- The table should be filled by user of this API ^_~
  576. -- Module operation is
  577. -- 1) Requesting a task from master
  578. -- 2) Moving to the location specified in response (if present)
  579. -- 3) Executing the associated function
  580. -- There is always a default task "return" which returns module to Master.
  581. -- response from Master is always passed to the function, so, if it contains additional data, you can use it
  582. -- Return is a task to return. Master should pass a set of coordinates as well as "f" direction to make module face the Master.
  583. tTasks = {
  584. Return = function (response)
  585. move ("forward")
  586. dumpStuff ()
  587. request ("Returned", 3)
  588. sleep (30)
  589. end
  590. }
  591.  
  592. -- Function to add tasks to the task table
  593. function addTasks (taskTable)
  594. assert (type(taskTable) == "table", "Bad task table. Table required, got "..type(taskTable), 2)
  595. for key, value in pairs (taskTable) do
  596. assert (type(key) == "string", "Bad task. String required, got "..type(key), 2)
  597. assert (type(value) == "function", "Bad task function. Function required, got "..type(value), 2)
  598. tTasks[key] = value
  599. end
  600. end
  601.  
  602. -- And one to remove a task ^_^
  603. function rmTask (task)
  604. assert (type(task) == "string", "Bad task. String required, got "..type(task), 2)
  605. tTasks [task] = nil
  606. end
  607.  
  608. -- And a main operation function
  609. function operate ()
  610. move ("forward")
  611. while true do
  612. local task
  613. -- failedRequests indicates how many times Master didn't answered to request
  614. local failedRequests = 0
  615. while task == nil do
  616. task = request ("Task", 5)
  617. if task == nil then
  618. failedRequests = failedRequests + 1
  619. -- if there are 6 requests failed, and fallbackLocation is set then change position to fallback position
  620. if failedRequests >= 6 and fallbackLocation ~= nil then
  621. print "No response from Master after 6 attempts. Moving to fallback position..."
  622.  
  623. local packet = {}
  624. packet.type = "swarmling"
  625. packet.value = {}
  626. packet.turtleId = tostring(ID)
  627. packet.msg = "waiting"
  628. ccc.sendSerialized("swarmling","bridge",packet)
  629.  
  630. navigateTo (fallbackLocation)
  631. end
  632. end
  633. end
  634. if task.x ~= nil and task.z ~= nil then
  635.  
  636. local packet = {}
  637. packet.type = "swarmling"
  638. packet.value = {}
  639. packet.turtleId = tostring(ID)
  640. packet.msg = "moving"
  641. ccc.sendSerialized("swarmling","bridge",packet)
  642.  
  643. navigateTo (task)
  644. end
  645. local packet = {}
  646. packet.type = "swarmling"
  647. packet.value = {}
  648. packet.turtleId = tostring(ID)
  649. packet.msg = "mining"
  650. ccc.sendSerialized("swarmling","bridge",packet)
  651. tTasks [task.Task](task) -- Task. tttTask. Tasktask. taskataskatask. HerpDerp.
  652. end
  653. end
Advertisement
Add Comment
Please, Sign In to add comment