Advertisement
serafim7

дронофера [OpenComputers]

Jun 10th, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. --https://pastebin.com/9TBqRHPw
  2. --https://computercraft.ru/topic/2503-dronoferma/
  3. --
  4. --Автор: BrightYC
  5.  
  6. d = component.proxy(component.list("drone")())
  7.  
  8. size_x, size_z = 8, 8 --Размер фермы по X и Z
  9. wait = 1200 --Ожидание (в секундах)
  10. wait_charge = 15 --Ожидание зарядки(Если кончится заряд при СБОРЕ(в секундах))
  11. procent_go_back = 20 --Процент заряда, при котором идёт возвращение домой
  12.  
  13. status = {
  14.   collect = {"Сбор\nурожая...", 0xe8e81e},
  15.   wait = {"Ожидание\n...", 0xffffff},
  16.   charge = {"Зарядка...", 0x64ea12}
  17. }
  18.    
  19. function sleep(timeout)
  20.   deadline = computer.uptime() + timeout
  21.   repeat
  22.   computer.pullSignal(deadline - computer.uptime())
  23.   until computer.uptime() >= deadline
  24. end
  25.  
  26. function move(x, y, z)
  27.   d.move(x, y, z)
  28.   while math.floor(d.getOffset()) ~= 0 do
  29.     sleep(0.1)
  30.   end
  31. end
  32.  
  33. function go_home()
  34.   move(-x + 1, 0, -z)
  35.   move(-1, 0, -2)
  36.   for i = 1, d.inventorySize() do
  37.      d.select(i)
  38.      d.drop(0)
  39.   end
  40.   d.select(1)
  41.   move(0, -1, 1)
  42. end
  43.  
  44. function go_back()
  45.   move(0, 1, 1)
  46.   move(x, 0, z)
  47. end
  48.  
  49. function check_energy()
  50.   if computer.energy() <= procent_go_back * (computer.maxEnergy() / 100) then
  51.     go_home()
  52.     d.setStatusText(status.charge[1])
  53.     d.setLightColor(status.charge[2])
  54.     sleep(wait_charge)
  55.     if computer.energy() <= procent_go_back * (computer.maxEnergy() / 100) then
  56.       d.setStatusText("Кончилась\nЭнергия")
  57.       computer.shutdown()
  58.     else
  59.       d.setStatusText(status.collect[1])
  60.       d.setLightColor(status.collect[2])
  61.       go_back()
  62.     end
  63.   end
  64. end
  65.  
  66. function check_count()
  67.   if d.count(d.inventorySize()) >= 1 then
  68.     go_home()
  69.     go_back()
  70.   end
  71. end
  72.  
  73. function stuff()
  74.   if d.detect(0) then
  75.     d.use(0)
  76.     check_count()
  77.   end
  78.   check_energy()
  79. end
  80.  
  81. function farm()
  82.   d.setStatusText(status.collect[1])
  83.   d.setLightColor(status.collect[2])
  84.   move(0, 1, 1)
  85.   stuff()
  86.   x, z = 0, 0
  87.   while true do
  88.     if x == 1 and z + 1 == size_z or x == size_x and z + 1 == size_z then
  89.       go_home()
  90.       break
  91.     elseif x == size_x or x == 1 and z ~= 0 then
  92.       z = z + 1
  93.       move(0, 0, 1)
  94.       stuff()
  95.     end
  96.     if z % 2 == 0 then
  97.       move(1, 0, 0)
  98.       x = x + 1
  99.     else
  100.       move(-1, 0, 0)
  101.       x = x - 1
  102.     end
  103.     stuff()
  104.   end
  105.   d.setStatusText(status.wait[1])
  106.   d.setLightColor(status.wait[2])
  107. end
  108.  
  109. while true do
  110.   farm()
  111.   sleep(wait)
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement