SHARE
TWEET

Эффективная шахта для робота

SergOmarov Jun 19th, 2015 (edited) 344 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --
  2. --author - SergOmarov, 2015
  3. --
  4.  
  5. local events=require("event")
  6. local computer=require("computer")
  7. local robot=require("robot")
  8. local term=require("term")
  9. local x=term.read()
  10. local z=term.read()
  11. local inventory_controller=require("component").getPrimary("inventory_controller")
  12. function refuel()
  13. if(computer.energy()/computer.maxEnergy())<10 then
  14. for i =  1, 16 do
  15.     require("component").getPrimary("generator").insert(64)
  16.   end
  17. end
  18. end
  19. robot.select(1)
  20. times=x*z/25
  21. events.timer(5,refuel,times)
  22.  
  23. function Sides2()
  24. robot.turnRight()
  25. mine2(1)
  26. robot.turnAround()
  27. mine2(1)
  28. robot.turnRight()
  29. end
  30. local function Sides(ifend)
  31. robot.select(1)
  32. if(robot.compareUp()) then
  33. robot.select(5)
  34. inventory_controller.equip()
  35. robot.swingUp()
  36. inventory_controller.equip()
  37. robot.select(1)
  38. end
  39. if(robot.compareDown()) then
  40. robot.select(5)
  41. inventory_controller.equip()
  42. robot.swingDown()
  43. inventory_controller.equip()
  44. robot.select(1)
  45. end
  46. end
  47.  
  48. function mine1(ismine)
  49. for j=1,4 do
  50. robot.select(j)
  51. if(robot.compare()) then
  52. robot.select(j+4)
  53. inventory_controller.equip()
  54. robot.swing()
  55. inventory_controller.equip()
  56. robot.select(1)
  57. return "move"
  58. elseif(ismine==true)then
  59. robot.swing()
  60. end
  61. end
  62. end
  63.  
  64. --копает тунель
  65. function mine(xT)
  66. for i=1,xT do
  67. mine1(true)
  68. Sides()
  69. robot.forward()
  70. Sides()
  71. if(i>1)then
  72. Sides2()
  73. end
  74. end
  75. for j=1,xT do
  76. robot.back()
  77. end
  78. end
  79.  
  80. function mine2(xT)
  81. for i=1,xT do
  82. ismove=mine1(false)
  83. Sides()
  84. if(ismove=="move")then
  85. robot.forward()
  86. Sides()
  87. end
  88. end
  89. if(ismove=="move")then
  90. for j=1,xT do
  91. robot.back()
  92. end
  93. end
  94. end
  95.  
  96. --перемещается
  97. function move(xT)
  98. for j=1,xT do
  99. robot.forward()
  100. end
  101. end
  102.  
  103. mine(x)
  104.  
  105. --теперь ответвления
  106. lZ=math.floor(z/2)
  107. robot.turnLeft()
  108. for ii=1,x,3 do--левое
  109. mine(lZ)
  110. robot.turnRight()
  111. robot.forward()
  112. robot.forward()
  113. robot.forward()
  114. robot.turnLeft()
  115. end
  116. robot.turnAround()
  117. for ii=1,x,3 do-- правое
  118. mine(lZ)
  119. robot.turnRight()
  120. robot.forward()
  121. robot.forward()
  122. robot.forward()
  123. robot.turnLeft()
  124. end
  125. mine(lZ)
  126. robot.turnRight()
  127. robot.forward()
  128. robot.turnAround()
  129. --robot.turnAround()
  130. --robot.turnRight()
  131. --move(x)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top