Fayo

OpenComputers Qurry

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