Guest User

Untitled

a guest
Apr 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. local docking = component.proxy(component.list("dock")())
  2. local drone = component.proxy(component.list("drone")())
  3. local nav = component.proxy(component.list("navigation")())
  4.  
  5. local baseSleep = 5
  6. local waypointLookRadius = 64
  7. local colours = {["travelling"] = 0xFFFFFF, ["farming"] = 0x332400, ["waiting"] = 0x0092FF, ["dropping"] = 0x33B640}
  8.  
  9. local cx, cy, cz
  10. local BASE
  11. local DROPOFF
  12. local FARMROWs
  13.  
  14. function getWaypoints()
  15. BASE, DROPOFF, FARMROWs = {}, {}, {}
  16. cx, cy, cz = 0, 0, 0
  17. local waypoints = nav.findWaypoints(waypointLookRadius)
  18. for i=1, waypoints.n do
  19. if waypoints[i].label == "BASE" then
  20. BASE.x = waypoints[i].position[1]
  21. BASE.y = waypoints[i].position[2]
  22. BASE.z = waypoints[i].position[3]
  23. elseif waypoints[i].label == "DROPOFF" then
  24. DROPOFF.x = waypoints[i].position[1]
  25. DROPOFF.y = waypoints[i].position[2]
  26. DROPOFF.z = waypoints[i].position[3]
  27. elseif waypoints[i].label:find("FARMROW") == 1 then
  28. local tempTable = {}
  29. tempTable.x = waypoints[i].position[1]
  30. tempTable.y = waypoints[i].position[2]
  31. tempTable.z = waypoints[i].position[3]
  32. tempTable.l = waypoints[i].label:match("LEN(%d+)")
  33. table.insert(FARMROWs, tempTable)
  34. end
  35. end
  36. end
  37.  
  38. function colour(state)
  39. drone.setLightColor(colours[state] or 0x000000)
  40. end
  41.  
  42. function move(tx, ty, tz)
  43. local dx = tx - cx
  44. local dy = ty - cy
  45. local dz = tz - cz
  46. drone.move(dx, dy, dz)
  47. while drone.getOffset() > 0.7 or drone.getVelocity() > 0.7 do
  48. computer.pullSignal(0.2)
  49. end
  50. cx, cy, cz = tx, ty, tz
  51. end
  52.  
  53. function getCharge()
  54. return computer.energy()/computer.maxEnergy()
  55. end
  56.  
  57. function waitAtBase()
  58. colour("travelling")
  59. move(BASE.x, BASE.y+1, BASE.z)
  60. while docking.dock()~= true do computer.pullSignal(.1) end
  61.  
  62. colour("waiting")
  63. computer.pullSignal(baseSleep*#FARMROWs)
  64. --poké-heal sound GGGEC
  65. computer.beep(783.99) computer.pullSignal(.25) computer.beep(783.99) computer.pullSignal(.25) computer.beep(783.99) computer.beep(659.25) computer.beep(1046.5)
  66. docking.release()
  67. end
  68.  
  69. function findCrop()
  70. for i=2, 5 do
  71. local isBlock, type = drone.detect(i)
  72. if type == "passable" then
  73. return i
  74. end
  75. end
  76. end
  77.  
  78. function farm()
  79. for i=1, #FARMROWs do
  80. local row = FARMROWs[i]
  81. colour("travelling")
  82. move(row.x, row.y, row.z)
  83. colour("farming")
  84. local direction = findCrop()
  85. local l, r, tx, tz
  86. if direction == 2 then l,r,tx,tz = 4,5,0,-1 end
  87. if direction == 3 then l,r,tx,tz = 5,4,0,1 end
  88. if direction == 4 then l,r,tx,tz = 3,2,-1,0 end
  89. if direction == 5 then l,r,tx,tz = 2,3,1,0 end
  90.  
  91. drone.use(direction)
  92. for i=1, row.l do
  93. move(cx+tx, cy, cz+tz)
  94. colour("farming")
  95. drone.use(l)
  96. drone.use(r)
  97. if i < tonumber(row.l) then
  98. drone.use(direction)
  99. end
  100. end
  101. end
  102. end
  103.  
  104. function dropoff()
  105. colour("travelling")
  106. move(DROPOFF.x, DROPOFF.y+1, DROPOFF.z)
  107. while docking.dock()~= true do computer.pullSignal(.1) end
  108. colour("dropping")
  109. for i=1, drone.inventorySize() do
  110. docking.dropItem(i, 64)
  111. computer.pullSignal(1)
  112. end
  113. docking.release()
  114. end
  115.  
  116. function init()
  117. getWaypoints()
  118. waitAtBase()
  119. while true do
  120. getWaypoints()
  121. farm()
  122. dropoff()
  123. waitAtBase()
  124. end
  125. end
  126.  
  127. init()
Add Comment
Please, Sign In to add comment