PonyKuu

mastermine 1.481-compatible version

Mar 25th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Mastermine is a Master part of turtle swarm quarry made by PonyKuu
  2. -- It uses my master API
  3.  
  4. -- Version 0.1(481): 1.481-compatible
  5.  
  6. os.loadAPI ("master")
  7.  
  8. local tArgs = {...}
  9.  
  10. if #tArgs ~= 5 then
  11.     print ("Usage: mastermine <xstart> <ystart> <zstart> <xsize> <zsize>")
  12.     return
  13. end
  14.  
  15. -- set up a table with all the mining locations
  16. local mineLocations = {}
  17. local xstart, ystart, zstart, xsize, zsize = unpack (tArgs)
  18. for i = 0, xsize/4 - 1 do
  19.     for j = 0, zsize/4 - 1 do
  20.         local x = xstart + i*4
  21.         local z = zstart + j*4
  22.         table.insert (mineLocations, {x = x, y = ystart, z = z, f = 0})
  23.     end
  24. end
  25.  
  26. -- Calculate the navigation zones. The point that divides area into zones is in the middle of the mining area.
  27. local naviX = xstart + xsize/2
  28. local naviZ = zstart + zsize/2
  29. local naviHeight = ystart + 2
  30. master.setNavigation (naviX, naviZ, naviHeight)
  31.  
  32. local function mineMachine (ID)
  33.     -- If there are untouched locations
  34.     if #mineLocations > 0 then
  35.         master.setState (ID, "Mining")
  36.         -- remove one from table
  37.         local nextLocation = table.remove (mineLocations)
  38.         -- Some debug output
  39.         print ("Module ", ID, " is mining at {", nextLocation.x, " ,", nextLocation.y, " ,", nextLocation.z, "}")
  40.         -- And make a task to mine that location
  41.         return master.makeTask ("Mine", nextLocation, {holeSize = 4})
  42.     else
  43.         -- No locations. Return home.
  44.         master.setState(ID, "Returning")
  45.         print ("Module ", ID, " is returning to Master")
  46.         return master.makeReturnTask ()
  47.     end
  48. end
  49.  
  50. -- Associate this function with type "Miner"
  51. master.setType("Miner", mineMachine)
  52. -- And initialize the master
  53. master.init("modulemine", 1000, #mineLocations)
  54.  
  55. local function stateFunction ()
  56.     if #mineLocations > 0 then
  57.         return true
  58.     else
  59.         return false
  60.     end
  61. end
  62. master.operate (stateFunction)
  63. print "Mining finished! Have a nice day!"
Advertisement
Add Comment
Please, Sign In to add comment