Advertisement
ivan52

test

Aug 26th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.64 KB | None | 0 0
  1. local r = require('robot')
  2. local comp = require('computer')
  3. local term = require('term')
  4. local sides = require('sides')
  5. local inv = require('component').inventory_controller
  6. local fs = require('filesystem')
  7. x1=10
  8. y1=13
  9. --================СПИСОК БЛОКОВ ДЛЯ ЗАПОЛНЕНИЯ================--
  10. musor={}
  11. musor['minecraft:stone'] = true
  12. musor['minecraft:cobblestone'] = true
  13. musor['minecraft:dirt'] = true
  14. musor['minecraft:gravel'] = true
  15. musor['minecraft:sandstone'] = true
  16. musor['minecraft:stonebrick'] = true
  17. --===============ПОИСК БЛОКОВ ДЛЯ ФУНДАМЕНТА==================--
  18. function find()
  19.   for i = 12,16 do
  20.   r.select(i)
  21.     if r.compareTo(16) == true then
  22.       r.select(slot)
  23.     end
  24.   end  
  25. end
  26. --================ПОИСК БЛОКОВ ДЛЯ РАВНЕНИЯ===================--
  27. function poisk(slots)
  28.   for slot = 1, slots do
  29.     if r.count(slot) > 0 then
  30.       if musor[inv.getStackInInternalSlot(slot).name] ~= nil then
  31.         r.select(slot)
  32.         return true
  33.       end
  34.     end
  35.   end
  36.   return false
  37. end
  38. --=======ЗАПОЛНЕНИЕ ИНВЕНТАРЯ БЛОКАМИ ДЛЯ СТРОИТЕЛЬСТВА========--
  39. function zapoln(slot1)
  40.   for a=1,inv.getInventorySize(3) do
  41.     if inv.getStackInSlot(3,a) ~= nil then
  42.       if musor[inv.getStackInSlot(3,a).name] then
  43.         r.select(slot1)
  44.         inv.suckFromSlot(3,a)
  45.         return true
  46.       end
  47.     end
  48.   end
  49. return false  
  50. end
  51. --====================УСТАНОВКА БЛОКОВ=========================--
  52. function placeDown()
  53.   while not r.placeDown() do
  54.     r.swingDown()  
  55.   end
  56. end
  57. --========================НАВИГАЦИЯ============================--
  58. loc = {x=0, y=0, z=0, b=0}
  59. function forward()
  60.     while not r.forward() do
  61.       r.swing()
  62.     end
  63.     if loc.b == 0 then loc.y = loc.y+1
  64.     elseif loc.b == 1 then loc.x = loc.x+1
  65.     elseif loc.b == 2 then loc.y = loc.y-1
  66.     else loc.x = loc.x-1 end
  67.     return true
  68. end
  69. function back()
  70.    if not r.back() then
  71.      r.turnAround()
  72.      while not r.forward() do
  73.        r.swing()
  74.      end
  75.      r.turnAround()
  76.    end
  77.    if loc.b == 0 then loc.y = loc.y-1
  78.    elseif loc.b == 1 then loc.x = loc.x-1
  79.    elseif loc.b == 2 then loc.y = loc.y+1
  80.    else loc.x = loc.x+1 end
  81.    return true
  82. end
  83. function up()
  84.   while not r.up() do
  85.     r.swingUp()
  86.   end
  87.   loc.z = loc.z+1
  88.   return true
  89. end
  90. function down()
  91.   while not r.down() do
  92.     r.swingDown()
  93.   end
  94.   loc.z = loc.z-1
  95.   return true
  96. end
  97. function turnRight()
  98.   loc.b = (loc.b+1)%4
  99.   r.turnRight()
  100. end
  101. function turnAround()
  102.   loc.b = (loc.b+2)%4
  103.   r.turnAround()
  104. end
  105. function turnLeft()
  106.   loc.b = (loc.b+3)%4
  107.   r.turnLeft()
  108. end
  109.  
  110. --=====================ВОЗВРАТ ДОМОЙ====================--
  111. function dom()
  112.   local d = loc.b
  113.   local p = loc.x
  114.   local t = loc.y
  115.   local g = loc.z
  116.   if loc.b ~= 2 then
  117.     while loc.b ~= 2 do
  118.       turnRight()
  119.     end
  120.   end
  121.   if loc.z>0 then
  122.     while loc.z > 0 do
  123.       down()
  124.     end
  125.   end
  126.   if loc.z < 0 then
  127.     while loc.z < 0 do
  128.       up()
  129.     end
  130.   end
  131.   if loc.x > 0 then
  132.     turnRight()
  133.     while loc.x > 0 do
  134.       forward()
  135.     end
  136.     turnLeft()
  137.   end
  138.   while loc.y > 0 do
  139.     forward()
  140.   end
  141.   while comp.energy() < comp.maxEnergy() * 0.8 do
  142.     os.sleep(8)
  143.   end
  144.   for i=13,16 do
  145.     r.select(i)
  146.     if not r.compareTo(16) then
  147.       if r.count(i)>0 then
  148.         turnRight()
  149.         r.drop()
  150.         turnLeft()
  151.       end
  152.     end
  153.     if r.count(i)<64 then
  154.       while not r.suck(64-r.count(i)) do
  155.         os.sleep(0.2)
  156.       end
  157.     end
  158.   end
  159.   turnRight()
  160.   for i=1,12 do
  161.     r.select(i)
  162.     r.drop()
  163.   end
  164.   for i=1,8 do
  165.     while not zapoln(i) do
  166.       os.sleep(0.2)
  167.     end
  168.   end
  169.   turnRight()
  170.    while loc.y ~= t do
  171.       forward()
  172.     end
  173.     if loc.x ~= p then
  174.       turnRight()
  175.       while loc.x ~=p do
  176.         forward()
  177.       end
  178.     end
  179.     if loc.b ~= d then
  180.       while loc.b ~= d do
  181.         turnLeft()
  182.       end
  183.     end
  184.     if g<0 then
  185.       while loc.z>g do
  186.         down()
  187.       end
  188.     end
  189.     if g>0 then
  190.       while loc.z<g do
  191.         up()
  192.       end
  193.     end
  194. end
  195. --========================ВЫРАВНИВАНИЕ ПОВЕРХНОСТИ=========================--
  196. function rovnenie()
  197.   local bl,en=r.detectUp()
  198.   if en == 'solid' then
  199.       while (en=='solid') and (loc.z<10) do
  200.         up()
  201.         r.swingUp()
  202.         bl,en=r.detectUp()
  203.       end
  204.       while loc.z>0 do
  205.         down()
  206.       end
  207.    end
  208.    local bl,en = r.detectDown()
  209.   if en ~= 'solid' then
  210.    while en ~= 'solid' do
  211.      down()
  212.      bl,en = r.detectDown()
  213.    end
  214.    while loc.z<-1 do
  215.      up()
  216.      inventar()
  217.      placeDown()
  218.    end
  219.    up()
  220.  end
  221.  r.select(16)
  222.  if (r.compareDown()==false) or (r.detectDown()==false) then
  223.     r.swingDown()
  224.     find()
  225.     placeDown()
  226.   end
  227. end
  228. function inventar()
  229.   if not poisk(12) then
  230.     dom()
  231.   end
  232. end
  233. --======================УСЛОВИЯ ДЛЯ ВОЗВРАТА ДОМОЙ======================--
  234. function usl()
  235.   if r.count(12) > 0 then
  236.     dom()
  237.   elseif r.count(1) < 32 then
  238.     dom()
  239.   elseif r.count(15) < 32 then
  240.     dom()
  241.   elseif comp.energy() < comp.maxEnergy()*0.8 then
  242.     dom()
  243.   end
  244. end
  245. --============================ГЛАВНЫЙ ЦИКЛ==============================--
  246. usl()
  247. rovnenie()
  248. for o=1,x1 do
  249.   for i=1,y1 do
  250.     forward()
  251.     usl()
  252.     rovnenie()
  253.   end
  254.   if o < x1 then
  255.     while loc.b<1 do
  256.      turnRight()
  257.     end
  258.     while loc.b>1 do
  259.        turnLeft()
  260.     end
  261.     forward()
  262.     usl()
  263.     rovnenie()
  264.     if (o)%2==0 then
  265.       turnLeft()
  266.     else
  267.       turnRight()
  268.     end
  269.   end
  270. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement