Advertisement
bob558

Effect shahta

Jul 10th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. --Хорошо продуманная программа для копки эффективной шахты.
  2. --Во время работы робот будет проверять стороны тунелей на наличие
  3. --руд(образцы руд должны лежать в первых 4 слотах) и будет брать
  4. --соответствующий инструмент в слоте ниже.
  5. --Не рекомендуется использовать для обработки уже существующих шахт.
  6. --При старте программы нужно ввести 2 параметра x и z разделяя по строкам.
  7. --x считается по положению робота изначально.
  8. --http://computercraft.ru/topic/856-effektivnaia-shakhta-dlia-robota/
  9. --author - SergOmarov, 2015
  10. --
  11.  
  12. local events=require("event")
  13. local computer=require("computer")
  14. local robot=require("robot")
  15. local term=require("term")
  16. local x=term.read()
  17. local z=term.read()
  18. local inventory_controller=require("component").getPrimary("inventory_controller")
  19. function refuel()
  20. if(computer.energy()/computer.maxEnergy())<10 then
  21. for i =  1, 16 do
  22.     require("component").getPrimary("generator").insert(64)
  23.   end
  24. end
  25. end
  26. robot.select(1)
  27. times=x*z/25
  28. events.timer(5,refuel,times)
  29.  
  30. function Sides2()
  31. robot.turnRight()
  32. mine2(1)
  33. robot.turnAround()
  34. mine2(1)
  35. robot.turnRight()
  36. end
  37. local function Sides(ifend)
  38. robot.select(1)
  39. if(robot.compareUp()) then
  40. robot.select(5)
  41. inventory_controller.equip()
  42. robot.swingUp()
  43. inventory_controller.equip()
  44. robot.select(1)
  45. end
  46. if(robot.compareDown()) then
  47. robot.select(5)
  48. inventory_controller.equip()
  49. robot.swingDown()
  50. inventory_controller.equip()
  51. robot.select(1)
  52. end
  53. end
  54.  
  55. function mine1(ismine)
  56. for j=1,4 do
  57. robot.select(j)
  58. if(robot.compare()) then
  59. robot.select(j+4)
  60. inventory_controller.equip()
  61. robot.swing()
  62. inventory_controller.equip()
  63. robot.select(1)
  64. return "move"
  65. elseif(ismine==true)then
  66. robot.swing()
  67. end
  68. end
  69. end
  70.  
  71. --копает тунель
  72. function mine(xT)
  73. for i=1,xT do
  74. mine1(true)
  75. Sides()
  76. robot.forward()
  77. Sides()
  78. if(i>1)then
  79. Sides2()
  80. end
  81. end
  82. for j=1,xT do
  83. robot.back()
  84. end
  85. end
  86.  
  87. function mine2(xT)
  88. for i=1,xT do
  89. ismove=mine1(false)
  90. Sides()
  91. if(ismove=="move")then
  92. robot.forward()
  93. Sides()
  94. end
  95. end
  96. if(ismove=="move")then
  97. for j=1,xT do
  98. robot.back()
  99. end
  100. end
  101. end
  102.  
  103. --перемещается
  104. function move(xT)
  105. for j=1,xT do
  106. robot.forward()
  107. end
  108. end
  109.  
  110. mine(x)
  111.  
  112. --теперь ответвления
  113. lZ=math.floor(z/2)
  114. robot.turnLeft()
  115. for ii=1,x,3 do--левое
  116. mine(lZ)
  117. robot.turnRight()
  118. robot.forward()
  119. robot.forward()
  120. robot.forward()
  121. robot.turnLeft()
  122. end
  123. robot.turnAround()
  124. for ii=1,x,3 do-- правое
  125. mine(lZ)
  126. robot.turnRight()
  127. robot.forward()
  128. robot.forward()
  129. robot.forward()
  130. robot.turnLeft()
  131. end
  132. mine(lZ)
  133. robot.turnRight()
  134. robot.forward()
  135. robot.turnAround()
  136. --robot.turnAround()
  137. --robot.turnRight()
  138. --move(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement