Advertisement
bob558

Quar с проверкой

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