Negasus

Untitled

Nov 24th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.60 KB | None | 0 0
  1. -- Slot settings
  2. local slotFuel        = 1;
  3. local slotRail        = 2;
  4. local slotPoweredRail = 3;
  5. local slotRedTorch    = 4;
  6. local slotFoundament  = 5;
  7. local slotTorch       = 6;
  8.  
  9. local minFuelLevel = 10;
  10. local minResourcesCount = 3;
  11.  
  12. local poweredRailDistance = 16; -- place powered rail each X blocks on LEFT side
  13. local torchDistance = 8; -- place Torch each X blocks on RIGHT side
  14.  
  15. local roadLength = 64;
  16.  
  17. -- Проверим уровень топлива и заправимся, пока не будет достигнут минимальный уровень
  18. function checkFuel()
  19.   while turtle.getFuelLevel() < minFuelLevel do
  20.     if turtle.getItemCount(slotFuel) < 1 then
  21.       -- Топливо закончилось
  22.       return 0;
  23.     end
  24.     turtle.select(slotFuel);
  25.     turtle.refuel(1);
  26.   end
  27.   return 1;
  28. end
  29.  
  30. -- Проверка ресурсов в ячейках 1-6 и пополнение их из другиз ячеек, если найден ресурс
  31. function checkResources()
  32.   -- 6 resources for check
  33.   for i = 1, 6 do
  34.     turtle.select(i);
  35.     if turtle.getItemCount(i) < minResourcesCount then
  36.       -- find resoirces in cell 7-16
  37.       for c = 7, 16 do
  38.         if turtle.compareTo(c) then
  39.           turtle.select(c);
  40.           turtle.transferTo(i);
  41.           break;
  42.         end
  43.       end
  44.       -- Ресурсы так и не были найдены. Остановим работу.
  45.       if turtle.getItemCount(i) < minResourcesCount then
  46.         return 0;
  47.       end
  48.     end
  49.   end
  50.   return 1;
  51. end
  52.  
  53. -- Установить рельсы
  54. function placeRail()
  55.   turtle.select(slotRail);
  56.   turtle.placeDown();
  57. end
  58.  
  59. -- Установить электрорельсы
  60. function placePoweredRail()
  61.   turtle.select(slotPoweredRail);
  62.   turtle.placeDown();
  63. end
  64.  
  65. -- Установить фундамент (подразумевается, что черепаха уже опущена для установки)
  66. function placeFoundament()
  67.   turtle.select(slotFoundament);
  68.   turtle.placeDown();
  69. end
  70.  
  71. -- Установить факел (установить сбоку фундамент и на него факел)
  72. function placeTorch()
  73.   turtle.turnRight();
  74.  
  75.   if turtle.detect() then
  76.     turtle.dig();
  77.   end
  78.   turtle.forward();
  79.   if turtle.detectDown() then
  80.     turtle.digDown();
  81.   end
  82.   turtle.down();
  83.   if turtle.detectDown() then
  84.     turtle.digDown();
  85.   end
  86.  
  87.   -- place foundament
  88.   turtle.select(slotFoundament);
  89.   turtle.placeDown();
  90.   turtle.up();
  91.  
  92.   turtle.select(slotTorch);
  93.   turtle.placeDown();
  94.   turtle.turnRight();
  95.   turtle.turnRight();
  96.   turtle.forward();
  97.   turtle.turnRight();
  98. end
  99.  
  100. -- Установить красный факел (сбоку фундамент и на него факел)
  101. function placeRedTorch()
  102.   turtle.turnLeft();
  103.  
  104.   if turtle.detect() then
  105.     turtle.dig();
  106.   end
  107.   turtle.forward();
  108.   if turtle.detectDown() then
  109.     turtle.digDown();
  110.   end
  111.   turtle.down();
  112.   if turtle.detectDown() then
  113.     turtle.digDown();
  114.   end
  115.  
  116.   -- place foundament
  117.   turtle.select(slotFoundament);
  118.   turtle.placeDown();
  119.   turtle.up();
  120.  
  121.   turtle.select(slotRedTorch);
  122.   turtle.placeDown();
  123.   turtle.turnRight();
  124.   turtle.turnRight();
  125.   turtle.forward();
  126.   turtle.turnLeft();
  127. end
  128.  
  129. -- Основной рабочий цикл
  130. function doWork()
  131.  
  132.   local flagPoweredRailDistance = 0;
  133.   local flagTorchDistance = 0;
  134.  
  135.   for i = 0, roadLength do
  136.     -- Check fuel and resources. Refuel and get resources from cells
  137.     if checkFuel() == 0 then
  138.       print "Warning! Fuel empty";
  139.       print "Stop";
  140.       return 0;
  141.     end
  142.     if checkResources() == 0 then
  143.       print ("Warning! Check resources in slot: ", i);
  144.       print "Stop";
  145.       return 0;
  146.     end
  147.  
  148.     flagPoweredRailDistance = flagPoweredRailDistance + 1;
  149.     flagTorchDistance = flagTorchDistance + 1;
  150.  
  151.     -- Clear blocks
  152.     if turtle.detect() then
  153.       turtle.dig();
  154.     end
  155.     turtle.forward();
  156.     if turtle.detectDown() then
  157.       turtle.digDown();
  158.     end
  159.     turtle.down();
  160.     if turtle.detectDown() then
  161.       turtle.digDown();
  162.     end
  163.  
  164.     --
  165.     placeFoundament();
  166.     turtle.up();
  167.  
  168.     if flagTorchDistance > torchDistance then
  169.       flagTorchDistance = 0;
  170.       placeTorch();
  171.     end
  172.  
  173.     if flagPoweredRailDistance > poweredRailDistance then
  174.       flagPoweredRailDistance = 0;
  175.       placePoweredRail();
  176.       placeRedTorch();
  177.     else
  178.       placeRail();
  179.     end
  180.  
  181.   end
  182.   print "Road complete";
  183.   print "Stop";
  184.   return 1;
  185. end
  186.  
  187. -- Запуск программы
  188. print "Monorails v1.0";
  189. print "Run...";
  190. doWork();
Advertisement
Add Comment
Please, Sign In to add comment