Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1.  
  2. if require("component").isAvailable("generator")
  3. then
  4. generator=require("component").generator
  5. end
  6. withg=(generator~=nil)
  7. slots=16
  8. slotstocheck=2
  9. robot=require("robot")
  10. coords={x=0,y=0,z=0,side=1}
  11. extcoords={x=0,y=0,z=0,side=1}
  12. sx={0,1,0,-1}
  13. sy={1,0,-1,0}
  14. --1,2,3,4
  15. --tl -- coords.side = (coords.side + 3)%4
  16. --tr -- coords.side = (coords.side + 1)%4
  17. --ta -- coords.side = (coords.side + 2)%4
  18. --all -- if coords.side == 0 then coords.side =4 end
  19. function go() while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end
  20. function godown() while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end
  21. function goup() while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end
  22. function check() return robot.count(slots-(slotstocheck-1)) > 0 end
  23. function turnLeft() robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end
  24. function turnRight() robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end
  25. function tosurf()
  26. extcoords.x=coords.x
  27. extcoords.y=coords.y
  28. extcoords.z=coords.z
  29. extcoords.side=coords.side
  30. while coords.z ~= 0 do goup() end
  31. while coords.side ~= 3 do turnRight() end
  32. while coords.y ~= 0 do go() end
  33. turnRight();
  34. while coords.x ~= 0 do go() end
  35. turnLeft();
  36. end
  37. function back()
  38. while coords.z ~= extcoords.z do godown() end
  39. while coords.side~= 1 do turnRight() end
  40. while coords.y ~= extcoords.y do go() end
  41. turnRight();
  42. while coords.x ~= extcoords.x do go() end
  43. while coords.side ~= extcoords.side do turnRight() end
  44. end
  45. function clearinv()
  46. alreadyhave=false
  47. for invcounter=1,slots do
  48. robot.select(invcounter)
  49. if withg then
  50. suc,error=generator.insert()
  51. if (error=="selected slot does not contain fuel" or alreadyhave) then robot.drop() else alreadyhave=true end
  52. else
  53. robot.drop()
  54. end
  55. end
  56. robot.select(1)
  57. sort()
  58. end
  59. function sort()
  60. curs=1
  61. for q=1,slots do
  62. if robot.count(q) > 0 then robot.select(q);robot.transferTo(curs);curs=curs+1 end
  63. end
  64. robot.select(1)
  65. end
  66. function prevent()
  67. if check() then
  68. tosurf()
  69. clearinv()
  70. back()
  71. end
  72. end
  73.  
  74. function digrow(n)
  75. prevent()
  76. robot.swingUp()
  77. prevent()
  78. robot.swingDown()
  79. for k=1,n do
  80. prevent()
  81. go()
  82. prevent()
  83. robot.swingUp()
  84. prevent()
  85. robot.swingDown()
  86. end
  87. end
  88. function digdim(x,y)
  89. godown()
  90. godown()
  91. for n=1,y do
  92. if tl then turnLeft() else turnRight() end
  93. digrow(ex)
  94. if tl then turnRight() else turnLeft() end
  95. tl = not tl
  96. if n==y then print("ok") else go() end
  97. end
  98. turnRight();
  99. turnRight();
  100. tl= not tl
  101. end
  102. x,y,z=...
  103. tl=false
  104. x=x+0
  105. y=y+0
  106. z=z+0
  107. ex=x-1
  108. fullz=(z-z%3)/3
  109. print("Fullz = " .. fullz)
  110. for i=1,fullz do
  111. digdim(x,y)
  112. godown()
  113. end
  114. if fullz*3==z then elseif fullz*3+1==z then goup();goup();digdim(tl,x,y) else goup();digdim(tl,x,y) end
  115. tosurf()
  116. clearinv()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement