Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Программа контроллера нестабильного реактора
- --https://i.imgur.com/vj6PPlk.png
- --https://computercraft.ru/topic/2604-programma-ochen-mnogo-elektrichestva
- --проект http://computercraft.ru
- --2018, © Asior
- local c = require("component")
- local tr = c.transposer
- local reactor = c.reactor_chamber
- local red = c.redstone
- local slotReac = {}
- local offReac = 98 --процент перегрева реактора для отрубания
- local vr, sideReac, sideInv, sideRed = false, 8, 8
- print('Поиск реактора и сундука')
- for i=0,5 do
- vr = tr.getInventoryName(i)
- if vr == 'blockReactorChamber' then
- if sideReac == 8 then
- print('Реактор в стороне: '..i)
- sideReac = i
- end
- elseif vr then
- print('Сундук в стороне: '..i)
- sideInv = i
- end
- end
- local slotsReac = tr.getInventorySize(sideReac)
- local slotsInv = tr.getInventorySize(sideInv)
- print('Сохранение расположения конденсаторов')
- local data = tr.getAllStacks(sideReac).getAll()
- for i=0, slotsReac+1 do
- if data[i] and (data[i].name == 'IC2:reactorCondensatorLap' or data[i].name == 'IC2:reactorCondensator') then
- print('Слот: '..(i+1)..'; Повреждение: '..math.ceil(100*data[i].damage/10000)..' %')
- slotReac[#slotReac+1] = i+1
- end
- end
- print('Поиск точки подключения')
- if reactor.producesEnergy() then
- print('ОСТАНОВИТЕ РЕАКТОР!')
- for i=0,5 do
- if red.getOutput(i) > 0 then
- red.setOutput(i, 0)
- end
- end
- os.exit()
- end
- for i=0,5 do
- red.setOutput(i, 15)
- if reactor.producesEnergy() then
- sideRed = i
- print('Точка активации реактора: '..sideRed)
- red.setOutput(sideRed, 0)
- break
- else
- red.setOutput(i, 0)
- end
- end
- print('Настройка завершена! Старт!')
- local function circuitCheck() --проверка схемы
- local data = tr.getAllStacks(sideReac).getAll()
- local sh = 0
- for i=1,#slotReac do
- if data[slotReac[i]-1].damage then
- sh = sh+1
- end
- end
- if sh == #slotReac then
- return true
- else
- return false
- end
- end
- local per = 0
- local data1
- red.setOutput(sideRed, 15)
- while true do
- data = tr.getAllStacks(sideReac).getAll()
- for i=1,#slotReac do
- if data[slotReac[i]-1].damage then
- per = math.ceil(100*data[slotReac[i]-1].damage/10000)
- else
- per = 0
- end
- print('Слот: '..slotReac[i]..'; Повреждение: '..per..' %')
- if per >= 97 then
- red.setOutput(sideRed, 0)
- print('ОТБОЙ реактора!')
- tr.transferItem(sideReac, sideInv, 1, slotReac[i])
- print('Выброс горелых конденсаторов')
- end
- if per == 0 then
- data1 = tr.getAllStacks(sideInv).getAll()
- for i1=0, slotsInv do
- if data1[i1] and (data1[i1].name == 'IC2:reactorCondensatorLap' or data1[i1].name == 'IC2:reactorCondensator') and data1[i1].damage < 10 then
- tr.transferItem(sideInv, sideReac, 1, i1+1, slotReac[i])
- print('Произведена замена конденсатора')
- if circuitCheck() then
- red.setOutput(sideRed, 15)
- print('Старт реактора!')
- end
- end
- end
- end
- end
- os.sleep(1)
- if red.getOutput(sideRed) == 15 and 100*reactor.getHeat()/reactor.getMaxHeat() > offReac then
- print('ПЕРЕГРЕВ')
- red.setOutput(sideRed, 0)
- end
- print('---------------')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement