Advertisement
Asioron

reactor_control_pc

May 6th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.59 KB | None | 0 0
  1. --Программа контроллера нестабильного реактора
  2. --https://i.imgur.com/vj6PPlk.png
  3. --https://computercraft.ru/topic/2604-programma-ochen-mnogo-elektrichestva
  4. --проект http://computercraft.ru
  5. --2018, © Asior
  6.  
  7. local c = require("component")
  8. local tr = c.transposer
  9. local reactor = c.reactor_chamber
  10. local red = c.redstone
  11. local slotReac = {}
  12. local offReac = 98 --процент перегрева реактора для отрубания
  13. local vr, sideReac, sideInv, sideRed = false, 8, 8
  14.  
  15. print('Поиск реактора и сундука')
  16. for i=0,5 do
  17.   vr = tr.getInventoryName(i)
  18.   if vr == 'blockReactorChamber' then
  19.     if sideReac == 8 then
  20.       print('Реактор в стороне: '..i)
  21.       sideReac = i
  22.     end
  23.   elseif vr then
  24.     print('Сундук в стороне: '..i)
  25.     sideInv = i
  26.   end
  27. end
  28. local slotsReac = tr.getInventorySize(sideReac)
  29. local slotsInv = tr.getInventorySize(sideInv)
  30.  
  31. print('Сохранение расположения конденсаторов')
  32. local data = tr.getAllStacks(sideReac).getAll()
  33. for i=0, slotsReac+1 do
  34.   if data[i] and (data[i].name == 'IC2:reactorCondensatorLap' or data[i].name == 'IC2:reactorCondensator') then
  35.     print('Слот: '..(i+1)..'; Повреждение: '..math.ceil(100*data[i].damage/10000)..' %')
  36.     slotReac[#slotReac+1] = i+1
  37.   end
  38. end
  39.  
  40. print('Поиск точки подключения')
  41. if reactor.producesEnergy() then
  42.   print('ОСТАНОВИТЕ РЕАКТОР!')
  43.   for i=0,5 do
  44.     if red.getOutput(i) > 0 then
  45.       red.setOutput(i, 0)
  46.     end
  47.   end
  48.   os.exit()
  49. end
  50.  
  51. for i=0,5 do
  52.   red.setOutput(i, 15)
  53.   if reactor.producesEnergy() then
  54.     sideRed = i
  55.     print('Точка активации реактора: '..sideRed)
  56.     red.setOutput(sideRed, 0)
  57.     break
  58.   else
  59.     red.setOutput(i, 0)
  60.   end
  61. end
  62.  
  63. print('Настройка завершена! Старт!')
  64.  
  65. local function circuitCheck() --проверка схемы
  66.   local data = tr.getAllStacks(sideReac).getAll()
  67.   local sh = 0
  68.   for i=1,#slotReac do
  69.     if data[slotReac[i]-1].damage then
  70.       sh = sh+1
  71.     end
  72.   end
  73.   if sh == #slotReac then
  74.     return true
  75.   else
  76.     return false
  77.   end
  78. end
  79.  
  80. local per = 0
  81. local data1
  82. red.setOutput(sideRed, 15)
  83. while true do
  84.   data = tr.getAllStacks(sideReac).getAll()
  85.   for i=1,#slotReac do
  86.     if data[slotReac[i]-1].damage then
  87.       per = math.ceil(100*data[slotReac[i]-1].damage/10000)
  88.     else
  89.       per = 0
  90.     end
  91.     print('Слот: '..slotReac[i]..'; Повреждение: '..per..' %')
  92.     if per >= 97 then
  93.       red.setOutput(sideRed, 0)
  94.       print('ОТБОЙ реактора!')
  95.       tr.transferItem(sideReac, sideInv, 1, slotReac[i])
  96.       print('Выброс горелых конденсаторов')
  97.     end
  98.     if per == 0 then
  99.       data1 = tr.getAllStacks(sideInv).getAll()
  100.       for i1=0, slotsInv do
  101.         if data1[i1] and (data1[i1].name == 'IC2:reactorCondensatorLap' or data1[i1].name == 'IC2:reactorCondensator') and data1[i1].damage < 10 then
  102.           tr.transferItem(sideInv, sideReac, 1, i1+1, slotReac[i])
  103.           print('Произведена замена конденсатора')
  104.           if circuitCheck() then
  105.             red.setOutput(sideRed, 15)
  106.             print('Старт реактора!')
  107.           end
  108.         end
  109.       end
  110.     end
  111.   end
  112.   os.sleep(1)
  113.   if red.getOutput(sideRed) == 15 and 100*reactor.getHeat()/reactor.getMaxHeat() > offReac then
  114.     print('ПЕРЕГРЕВ')
  115.     red.setOutput(sideRed, 0)
  116.   end
  117.   print('---------------')
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement