View difference between Paste ID: YidCrWCG and nkxgfyM9
SHOW: | | - or go back to the newest paste.
1
--[[opencomputers контроль реактора IC2(1.7.10) на конденсаторах
2
    pastebin.com/kxgfyM9                         update 26.10.21
3-
    
3+
4-
использовать только вместе с модом OpenPeripheral 
4+
использовать только вместе с модом OpenPeripheral
5
pastebin run YidCrWCG
6-
для проекта computercraft.ru  
6+
для проекта computercraft.ru
7
https://computercraft.ru/topic/2604-programma-ochen-mnogo-elektrichestva
8
авторы: Asior, serafim
9
10
требования:
11
монитор и видеокарта 2-го уровня,
12
адаптер, транспозер, контроллер красного камня.
13
14
пример сборки:
15
https://i.imgur.com/eRb0iAx.png
16
https://i.imgur.com/UqrFVkC.png
17
https://i.imgur.com/y42OiO7.png
18
19
схема реактора:
20
https://i.imgur.com/SXbeOu8.png
21
https://i.imgur.com/OW27suK.png
22
23
использование:
24
собрать установку, для плутония нагреть реактор до 8400 градусов,
25
в сундук положить запасные конденсаторы и стержни,
26
желательно обеспечить автокрафт перезарядки конденсаторов
27
https://pastebin.com/WgcCKBFn
28
]]--
29
30-
local offReac = 8400 --температура перегрева реактора до отключения
30+
local offReac = 8500 --температура перегрева реактора до отключения
31-
local perDamage = 95 --процент износа конденсатора при котором он меняется
31+
local perDamage = 80 --процент износа конденсатора при котором он меняется
32
33
local com = require("component")
34
local computer = require("computer")
35
local event = require("event")
36
local gpu = com.gpu
37
local w,h = gpu.getResolution()
38
local per,noFuel,lowEu,toReac,run = 0,0,0,1,true
39
local sideReac,sideInv,sideRed,OutputEUt,StartEUt
40
local slotReac,Reflector = {},{}
41
42-
if not com.isAvailable("chest") then
42+
if not com.isAvailable("inventory") then
43-
  print("нет сундука")
43+
    print("нет сундука")
44-
  print("использовать только вместе с модом OpenPeripheral")
44+
    print("использовать только вместе с модом OpenPeripheral")
45-
  os.exit()
45+
46
end
47-
local chest = com.chest
47+
if not com.isAvailable("me_interface") then
48-
local slotsInv = chest.getInventorySize()
48+
    print("нет interface")
49
    print("использовать только вместе с модом OpenPeripheral")
50
    os.exit()
51-
  print("нет контроллера красного камня")
51+
52-
  os.exit()
52+
local chest = com.inventory
53
local slotsInv = chest.getSize()
54
55
local interface = com.me_interface
56
57-
  print("камера реактора не найдена")
57+
58-
  os.exit()
58+
    print("нет контроллера красного камня")
59
    os.exit()
60
end
61
local red = com.redstone
62
63-
  print("\n".."остановите реактор !")
63+
64-
  for i = 0,5 do
64+
    print("камера реактора не найдена")
65-
    if red.getOutput(i) > 0 then
65+
66-
      red.setOutput(i, 0)
66+
67
local reactor = com.reactor_chamber
68-
  end
68+
69-
  os.exit()
69+
70
    print("\n".."остановите реактор !")
71
    for i = 0,5 do
72
        if red.getOutput(i) > 0 then
73-
  print("\n".."перегрев реактора !")
73+
            red.setOutput(i, 0)
74-
  os.exit()
74+
75
    end
76
    os.exit()
77
end
78
79
if reactor.getHeat() > offReac then
80
    print("\n".."перегрев реактора !")
81-
  if data[i] and data[i].name then
81+
82-
    if string.find(data[i].name,"ondensator") then
82+
83-
      local per = math.ceil(100*data[i].dmg/data[i].max_dmg)
83+
84-
      print("слот: "..(i).."  износ: "..per.." %")
84+
85-
      if per >= perDamage then
85+
86-
        print("\n".."замените конденсатор в слоте: "..(i))
86+
87
for i = 0,54 do
88-
      end
88+
    if data[i] and data[i].name then
89-
      table.insert(slotReac, i)
89+
        if string.find(data[i].name,"ondensator") then
90
            local per = math.ceil(100*data[i].dmg/data[i].max_dmg)
91-
  end
91+
            print("слот: "..(i).."  износ: "..per.." %")
92
            if per >= perDamage then
93
                print("\n".."замените конденсатор в слоте: "..(i))
94
                os.exit()
95-
  if data[i] and data[i].name then
95+
96-
    if string.find(data[i].name,"eflector") then
96+
            table.insert(slotReac, i)
97-
      print("слот: "..(i))
97+
98-
      table.insert(Reflector, i)
98+
99
end
100-
  end
100+
101
for i = 0,54 do
102
    if data[i] and data[i].name then
103
        if string.find(data[i].name,"eflector") then
104
            print("слот: "..(i))
105-
  red.setOutput(n, 15)
105+
            table.insert(Reflector, i)
106-
  if reactor.producesEnergy() then
106+
107-
    os.sleep(1)
107+
108-
    StartEUt = math.ceil(reactor.getReactorEUOutput())
108+
109-
    print("StartEUt = "..StartEUt)
109+
110-
    sideRed = n
110+
111-
    red.setOutput(n, 0)
111+
112-
    print("редстоун в стороне: "..sideRed)
112+
    red.setOutput(n, 15)
113-
    break
113+
114-
  else
114+
        os.sleep(1)
115-
    red.setOutput(n, 0)
115+
        StartEUt = math.ceil(reactor.getReactorEUOutput())
116-
  end
116+
        print("StartEUt = "..StartEUt)
117-
  if k == 6 then
117+
        sideRed = n
118-
    print("\n".."реактор не запускается")
118+
        red.setOutput(n, 0)
119
        print("редстоун в стороне: "..sideRed)
120-
  end
120+
        break
121
    else
122
        red.setOutput(n, 0)
123
    end
124
    if k == 6 then
125
        print("\n".."реактор не запускается")
126-
local function gui() 
126+
127-
  gpu.setResolution(28,15)
127+
128-
  gpu.setBackground(0x000000)
128+
129-
  gpu.fill(1,1,28,15," ")
129+
130-
  gpu.setForeground(0x669999)
130+
131-
  gpu.set(1,1,"┌──────────────────────────┐")
131+
132-
  gpu.set(1,2,"│  │  │  │  │  │  │  │  │  │")
132+
-- ▀ ▄ █
133-
  gpu.set(1,3,"│──────────────────────────│")
133+
local function gui()
134-
  gpu.set(1,4,"│  │  │  │  │  │  │  │  │  │")
134+
    gpu.setResolution(28,15)
135-
  gpu.set(1,5,"│──────────────────────────│")
135+
    gpu.setBackground(0x696969)
136-
  gpu.set(1,6,"│  │  │  │  │  │  │  │  │  │")
136+
    gpu.fill(1,1,28,15," ")
137-
  gpu.set(1,7,"│──────────────────────────│")
137+
    gpu.setForeground(0x3C3C3C)
138-
  gpu.set(1,8,"│  │  │  │  │  │  │  │  │  │")
138+
    gpu.set(1,1,"████████████████████████████")
139-
  gpu.set(1,9,"│──────────────────────────│")
139+
    gpu.set(1,2,"█  █  █  █  █  █  █  █  █  █")
140-
 gpu.set(1,10,"│  │  │  │  │  │  │  │  │  │")
140+
    gpu.setForeground(0x008000)
141-
 gpu.set(1,11,"│──────────────────────────│")
141+
    gpu.set(2,2,"█")
142-
 gpu.set(1,12,"│  │  │  │  │  │  │  │  │  │")
142+
    gpu.set(5,2,"█")
143-
 gpu.set(1,13,"└──────────────────────────┘")
143+
    gpu.set(8,2,"█")
144
    gpu.set(11,2,"█")
145
    gpu.set(14,2,"█")
146
    gpu.set(17,2,"█")
147-
{"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
147+
    gpu.set(20,2,"█")
148-
{"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
148+
    gpu.set(23,2,"█")
149-
{"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
149+
    gpu.set(26,2,"█")
150-
{"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
150+
    --
151-
{"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
151+
    gpu.setForeground(0x00ff00)
152-
{"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
152+
    gpu.set(3,2,"█")
153
    gpu.set(6,2,"█")
154
    gpu.set(9,2,"█")
155-
local function stop(wait) 
155+
    gpu.set(12,2,"█")
156-
  local e = ({event.pull(wait,"key_down")})[4]
156+
    gpu.set(15,2,"█")
157-
  if e == 18 or e == 20 then
157+
    gpu.set(18,2,"█")
158-
    red.setOutput(sideRed, 0)
158+
    gpu.set(21,2,"█")
159-
    gpu.setResolution(w, h)
159+
    gpu.set(24,2,"█")
160
    gpu.set(27,2,"█")
161-
    gpu.setForeground(0xFFFFFF)
161+
    gpu.setForeground(0x3C3C3C)
162-
    gpu.fill(1, 1, w, h, " ")
162+
    gpu.set(1,3,"████████████████████████████")
163-
    print("программа завершена")
163+
    gpu.set(1,4,"█  █  █  █  █  █  █  █  █  █")
164-
    os.sleep(1)
164+
    gpu.setForeground(0x008000)
165
    gpu.set(2,4,"█")
166-
      print("ВНИМАНИЕ реактор по прежнему активен !!!")
166+
    gpu.set(5,4,"█")
167
    gpu.set(8,4,"█")
168-
      print("реактор остановлен")
168+
    gpu.set(11,4,"█")
169
    gpu.set(14,4,"█")
170-
    run = false
170+
    gpu.set(17,4,"█")
171-
  end
171+
    gpu.set(20,4,"█")
172
    gpu.set(23,4,"█")
173
    gpu.set(26,4,"█")
174-
local function alert(message) 
174+
    --
175-
  gpu.setForeground(0xFF9900)
175+
    gpu.setForeground(0x00ff00)
176-
  gpu.set(1,14,"  для завершения нажмите E  ")
176+
    gpu.set(3,4,"█")
177-
  gpu.setForeground(0xFF0000)
177+
    gpu.set(6,4,"█")
178-
  gpu.set(1,15,message)
178+
    gpu.set(9,4,"█")
179-
  computer.beep(500, 1)
179+
    gpu.set(12,4,"█")
180-
  stop(3)
180+
    gpu.set(15,4,"█")
181
    gpu.set(18,4,"█")
182
    gpu.set(21,4,"█")
183
    gpu.set(24,4,"█")
184-
  local function redstone(state)
184+
    gpu.set(27,4,"█")
185-
    if state then
185+
    gpu.setForeground(0x3C3C3C)
186-
      red.setOutput(sideRed, 15)
186+
    gpu.set(1,5,"████████████████████████████")
187
    gpu.set(1,6,"█  █  █  █  █  █  █  █  █  █")
188-
      while red.getOutput(sideRed) > 0 or reactor.getReactorEUOutput() > 0 do
188+
    gpu.setForeground(0x008000)
189
    gpu.set(2,6,"█")
190-
        os.sleep(0.2)
190+
    gpu.set(5,6,"█")
191-
      end
191+
    gpu.set(8,6,"█")
192-
      gpu.setForeground(0x00FF00)
192+
    gpu.set(11,6,"█")
193-
      gpu.set(1,14,"      eu/t =  0           ")
193+
    gpu.set(14,6,"█")
194
    gpu.set(17,6,"█")
195-
  end
195+
    gpu.set(20,6,"█")
196-
  local data = reactor.getAllStacks(0)
196+
    gpu.set(23,6,"█")
197-
  for i = 1,#slotReac do
197+
    gpu.set(26,6,"█")
198-
    if data[slotReac[i]] then
198+
    --
199-
      per = math.ceil(100*data[slotReac[i]].dmg/data[slotReac[i]].max_dmg)
199+
    gpu.setForeground(0x00ff00)
200-
      gpu.setForeground(0xFF9900)
200+
    gpu.set(3,6,"█")
201-
      gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per))
201+
    gpu.set(6,6,"█")
202
    gpu.set(9,6,"█")
203-
      per = 0
203+
    gpu.set(12,6,"█")
204
    gpu.set(15,6,"█")
205-
    if per == 100 then
205+
    gpu.set(18,6,"█")
206-
      redstone(false)
206+
    gpu.set(21,6,"█")
207-
      alert(" снизте % замены конденсат. ")
207+
    gpu.set(24,6,"█")
208-
      while run do
208+
    gpu.set(27,6,"█")
209-
        computer.beep(500, 1)
209+
    gpu.setForeground(0x3C3C3C)
210-
        stop(3)
210+
    gpu.set(1,7,"████████████████████████████")
211-
      end
211+
    gpu.set(1,8,"█  █  █  █  █  █  █  █  █  █")
212-
      os.exit()
212+
    gpu.setForeground(0x008000)
213
    gpu.set(2,8,"█")
214-
    if per >= perDamage or per == 0 then
214+
    gpu.set(5,8,"█")
215-
      gpu.setForeground(0xFF9900)
215+
    gpu.set(8,8,"█")
216-
      gpu.set(1,15,"    замена конденсаторов    ")
216+
    gpu.set(11,8,"█")
217-
      redstone(false)
217+
    gpu.set(14,8,"█")
218-
      chest.pullItem("DOWN",slotReac[i])
218+
    gpu.set(17,8,"█")
219-
      gpu.setForeground(0xFF0000)
219+
    gpu.set(20,8,"█")
220-
      gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
220+
    gpu.set(23,8,"█")
221-
      local data1 = chest.getAllStacks(0)
221+
    gpu.set(26,8,"█")
222-
      for i1 = 1,slotsInv do
222+
    --
223-
        if data1[i1] and data1[i1].name then
223+
    gpu.setForeground(0x00ff00)
224-
          local per = math.ceil(100*data1[i1].dmg/data1[i1].max_dmg)
224+
    gpu.set(3,8,"█")
225-
          if string.find(data1[i1].name,"ondensator") and per < 90 then
225+
    gpu.set(6,8,"█")
226-
            toReac = chest.pushItemIntoSlot("DOWN",i1,1,slotReac[i])
226+
    gpu.set(9,8,"█")
227-
            if toReac then
227+
    gpu.set(12,8,"█")
228-
              gpu.setForeground(0x00FF00)
228+
    gpu.set(15,8,"█")
229-
              gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
229+
    gpu.set(18,8,"█")
230
    gpu.set(21,8,"█")
231-
            break
231+
    gpu.set(24,8,"█")
232-
          else
232+
    gpu.set(27,8,"█")
233-
            toReac = 0
233+
    gpu.setForeground(0x3C3C3C)
234-
          end
234+
    gpu.set(1,9,"████████████████████████████")
235
    gpu.set(1,10,"█  █  █  █  █  █  █  █  █  █")
236-
      end
236+
    gpu.setForeground(0x008000)
237
    gpu.set(2,10,"█")
238-
  end
238+
    gpu.set(5,10,"█")
239-
  local function circuitCheck() 
239+
    gpu.set(8,10,"█")
240
    gpu.set(11,10,"█")
241-
    local sh = 0
241+
    gpu.set(14,10,"█")
242
    gpu.set(17,10,"█")
243-
      if data[slotReac[i]] then
243+
    gpu.set(20,10,"█")
244-
        sh = sh + 1
244+
    gpu.set(23,10,"█")
245-
      end
245+
    gpu.set(26,10,"█")
246
    --
247-
    if sh == #slotReac then
247+
    gpu.setForeground(0x00ff00)
248-
      return true
248+
    gpu.set(3,10,"█")
249
    gpu.set(6,10,"█")
250-
      return false
250+
    gpu.set(9,10,"█")
251
    gpu.set(12,10,"█")
252-
  end
252+
    gpu.set(15,10,"█")
253-
  if reactor.getHeat() > offReac then
253+
    gpu.set(18,10,"█")
254-
    redstone(false)
254+
    gpu.set(21,10,"█")
255-
    alert("     перегрев реактора !    ")
255+
    gpu.set(24,10,"█")
256-
  elseif not circuitCheck() then
256+
    gpu.set(27,10,"█")
257-
    alert(" нет целых конденсаторов !  ")
257+
    gpu.setForeground(0x3C3C3C)
258-
  elseif toReac == 0 then
258+
    gpu.set(1,11,"████████████████████████████")
259-
    alert("    в сундуке нет места !   ")
259+
    gpu.set(1,12,"█  █  █  █  █  █  █  █  █  █")
260-
  elseif noFuel >= 5 then
260+
    gpu.setForeground(0x008000)
261-
    alert("       нет топлива !        ")
261+
    gpu.set(2,12,"█")
262-
  else
262+
    gpu.set(5,12,"█")
263-
    redstone(true)
263+
    gpu.set(8,12,"█")
264-
    if not reactor.producesEnergy() then
264+
    gpu.set(11,12,"█")
265-
      alert("  реактор не запускается !  ")
265+
    gpu.set(14,12,"█")
266
    gpu.set(17,12,"█")
267-
      OutputEUt = math.ceil(reactor.getReactorEUOutput())
267+
    gpu.set(20,12,"█")
268-
      gpu.setForeground(0x00FF00)
268+
    gpu.set(23,12,"█")
269-
      gpu.set(1,14,"      eu/t =  "..OutputEUt.."            ")
269+
    gpu.set(26,12,"█")
270-
      gpu.set(1,15,"      реактор активен       ")
270+
    --
271
    gpu.setForeground(0x00ff00)
272-
  end
272+
    gpu.set(3,12,"█")
273-
  stop(0.7)
273+
    gpu.set(6,12,"█")
274-
  if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then
274+
    gpu.set(9,12,"█")
275-
    noFuel = noFuel + 1
275+
    gpu.set(12,12,"█")
276-
  else
276+
    gpu.set(15,12,"█")
277-
    noFuel = 0
277+
    gpu.set(18,12,"█")
278-
    if OutputEUt and OutputEUt < StartEUt then
278+
    gpu.set(21,12,"█")
279-
      lowEu = lowEu + 1
279+
    gpu.set(24,12,"█")
280
    gpu.set(27,12,"█")
281-
      lowEu = 0
281+
    gpu.setForeground(0x3C3C3C)
282
    gpu.set(1,13,"████████████████████████████")
283-
  end
283+
284-
  if noFuel == 3 or lowEu == 3 then
284+
285-
    local data2 = reactor.getAllStacks(0)
285+
286-
    local data3 = chest.getAllStacks(0)
286+
    {"2","2"},{"5","2"},{"8","2"},{"11","2"},{"14","2"},{"17","2"},{"20","2"},{"23","2"},{"26","2"},
287-
    for i2 = 1,54 do
287+
    {"2","4"},{"5","4"},{"8","4"},{"11","4"},{"14","4"},{"17","4"},{"20","4"},{"23","4"},{"26","4"},
288-
      if data2[i2] and data2[i2].name then
288+
    {"2","6"},{"5","6"},{"8","6"},{"11","6"},{"14","6"},{"17","6"},{"20","6"},{"23","6"},{"26","6"},
289-
        if string.find(data2[i2].name,"depleted") then
289+
    {"2","8"},{"5","8"},{"8","8"},{"11","8"},{"14","8"},{"17","8"},{"20","8"},{"23","8"},{"26","8"},
290-
          redstone(false)
290+
    {"2","10"},{"5","10"},{"8","10"},{"11","10"},{"14","10"},{"17","10"},{"20","10"},{"23","10"},{"26","10"},
291-
          gpu.setForeground(0xFF9900)
291+
    {"2","12"},{"5","12"},{"8","12"},{"11","12"},{"14","12"},{"17","12"},{"20","12"},{"23","12"},{"26","12"},
292-
          gpu.set(1,15,"      замена стержней       ")
292+
293-
          chest.pullItem("DOWN",i2)
293+
294-
          for i3 = 0,slotsInv do
294+
local function stop(wait)
295-
            if data3[i3] and data3[i3].name then
295+
296-
              if string.find(data3[i3].name,"MOX") or string.find(data3[i3].name,"Uran") then
296+
    local e = ({event.pull(wait,"key_down")})[4]
297-
                if not string.find(data3[i3].name,"depleted") then
297+
    if e == 18 or e == 20 then
298-
                  chest.pushItemIntoSlot("DOWN",i3,1,i2)
298+
299-
                  break
299+
        gpu.setResolution(w, h)
300
        gpu.setBackground(0x000000)
301-
              end
301+
        gpu.setForeground(0xFFFFFF)
302
        gpu.fill(1, 1, w, h, " ")
303-
          end
303+
        print("программа завершена")
304
        os.sleep(1)
305-
      end
305+
        if reactor.producesEnergy() then
306
            print("ВНИМАНИЕ реактор по прежнему активен !!!")
307-
    StartEUt = 0
307+
        else
308-
    lowEu = 0
308+
            print("реактор остановлен")
309-
    for i4 = 1,#Reflector do
309+
310-
      if not data2[Reflector[i4]] then
310+
        run = false
311-
        for i5 = 0,slotsInv do
311+
312-
          if data3[i5] and data3[i5].name then
312+
    gpu.setBackground(0x696969)
313-
            if string.find(data3[i5].name,"eflector") then
313+
314-
              redstone(false)
314+
315-
              gpu.setForeground(0xFF9900)
315+
local function alert(message)
316-
              gpu.set(1,15,"      замена отражателя     ")
316+
317-
              chest.pushItemIntoSlot("DOWN",i5,1,Reflector[i4])
317+
    gpu.setForeground(0xFF9900)
318
    gpu.set(1,14,"  для завершения нажмите E  ")
319-
          end
319+
    gpu.setForeground(0xFF0000)
320
    gpu.set(1,15,message)
321-
      end
321+
    computer.beep(500, 1)
322
    stop(3)
323-
  end
323+
    gpu.setBackground(0x696969)
324-
  if OutputEUt and OutputEUt > StartEUt then
324+
325-
    StartEUt = math.ceil(reactor.getReactorEUOutput())
325+
326-
  end
326+
327
    local function redstone(state)
328
        if state then
329
            red.setOutput(sideRed, 15)
330
        else
331
            while red.getOutput(sideRed) > 0 or reactor.getReactorEUOutput() > 0 do
332
                red.setOutput(sideRed, 0)
333
                os.sleep(0.2)
334-
  local ok,err = pcall(ReactorControl)
334+
335-
  if not ok then
335+
            gpu.setBackground(0x000000)
336-
    red.setOutput(sideRed, 0)
336+
            gpu.setForeground(0x00FF00)
337-
    gpu.setResolution(w, h)
337+
            gpu.set(1,14,"      eu/t =  0           ")
338
            gpu.setBackground(0x696969)
339-
    gpu.setForeground(0xFFFFFF)
339+
340-
    os.execute("cls")
340+
341-
    print("программа аварийно завершена")
341+
342-
    if type(err) == "table" then
342+
343-
      io.stderr:write(table.unpack(err))
343+
        if data[slotReac[i]] then
344
            per = math.ceil(100*data[slotReac[i]].dmg/data[slotReac[i]].max_dmg)
345-
      io.stderr:write(err)
345+
            gpu.setForeground(0xFF9900)
346
            gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),tostring(per))
347-
    run = false
347+
        else
348-
  end
348+
            per = 0
349
        end
350
        if per == 100 then
351
            gpu.setBackground(0x000000)
352
            redstone(false)
353
            alert(" снизте % замены конденсат. ")
354
            while run do
355
                computer.beep(500, 1)
356
                stop(3)
357
                gpu.setBackground(0x696969)
358
            end
359
            os.exit()
360
        end
361
        if per >= perDamage or per == 0 then
362
            gpu.setBackground(0x000000)
363
            gpu.setForeground(0xFF9900)
364
            gpu.set(1,15,"    замена конденсаторов    ")
365
            gpu.setBackground(0x696969)
366
            redstone(false)
367
            interface.pullItem("DOWN",slotReac[i])
368
            gpu.setForeground(0xFF0000)
369
            gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
370
            local data1 = chest.getAllStacks(0)
371
            for i1 = 1,slotsInv do
372
                if data1[i1] and data1[i1].name then
373
                    local per = math.ceil(100*data1[i1].dmg/data1[i1].max_dmg)
374
                    if string.find(data1[i1].name,"ondensator") and per < 90 then
375
                        toReac = chest.pushItemIntoSlot("DOWN",i1,1,slotReac[i])
376
                        if toReac then
377
                            gpu.setForeground(0x696969)
378
                            gpu.setBackground(0x696969)
379
                            gpu.set(tonumber(xy[slotReac[i]][1]),tonumber(xy[slotReac[i]][2]),"██")
380
                        end
381
                        break
382
                    else
383
                        toReac = 0
384
                    end
385
                end
386
            end
387
        end
388
    end
389
    local function circuitCheck()
390
391
        local data = reactor.getAllStacks(0)
392
        local sh = 0
393
        for i = 1,#slotReac do
394
            if data[slotReac[i]] then
395
                sh = sh + 1
396
            end
397
        end
398
        if sh == #slotReac then
399
            return true
400
        else
401
            return false
402
        end
403
    end
404
    gpu.setBackground(0x000000)
405
    if reactor.getHeat() > offReac then
406
        redstone(false)
407
        alert("     перегрев реактора !    ")
408
    elseif not circuitCheck() then
409
        alert(" нет целых конденсаторов !  ")
410
    elseif toReac == 0 then
411
        alert("    в сундуке нет места !   ")
412
    elseif noFuel >= 5 then
413
        alert("       нет топлива !        ")
414
    else
415
        redstone(true)
416
        if not reactor.producesEnergy() then
417
            alert("  реактор не запускается !  ")
418
        else
419
            OutputEUt = math.ceil(reactor.getReactorEUOutput())
420
421
            gpu.set(1,14,"      eu/t =  "..OutputEUt.."            ")
422
            gpu.set(1,15,"      реактор активен       ")
423
        end
424
    end
425
    stop(0.7)
426
    gpu.setBackground(0x696969)
427
    if reactor.producesEnergy() and reactor.getReactorEUOutput() == 0 then
428
        noFuel = noFuel + 1
429
    else
430
        noFuel = 0
431
        if OutputEUt and OutputEUt < StartEUt then
432
            lowEu = lowEu + 1
433
        else
434
            lowEu = 0
435
        end
436
    end
437
    gpu.setBackground(0x000000)
438
    if noFuel == 3 or lowEu == 3 then
439
        local data2 = reactor.getAllStacks(0)
440
        local data3 = chest.getAllStacks(0)
441
        for i2 = 1,54 do
442
            if data2[i2] and data2[i2].name then
443
                if string.find(data2[i2].name,"depleted") then
444
                    redstone(false)
445
                    gpu.setForeground(0xFF9900)
446
                    gpu.set(1,15,"      замена стержней       ")
447
                    interface.pullItem("DOWN",i2)
448
                    for i3 = 0,slotsInv do
449
                        if data3[i3] and data3[i3].name then
450
                            if string.find(data3[i3].name,"MOX") or string.find(data3[i3].name,"Uran") then
451
                                if not string.find(data3[i3].name,"depleted") then
452
                                    chest.pushItemIntoSlot("DOWN",i3,1,i2)
453
                                    break
454
                                end
455
                            end
456
                        end
457
                    end
458
                end
459
            end
460
        end
461
        StartEUt = 0
462
        lowEu = 0
463
        for i4 = 1,#Reflector do
464
            if not data2[Reflector[i4]] then
465
                for i5 = 0,slotsInv do
466
                    if data3[i5] and data3[i5].name then
467
                        if string.find(data3[i5].name,"eflector") then
468
                            redstone(false)
469
                            gpu.setForeground(0xFF9900)
470
                            gpu.set(1,15,"      замена отражателя     ")
471
                            chest.pushItemIntoSlot("DOWN",i5,1,Reflector[i4])
472
                        end
473
                    end
474
                end
475
            end
476
        end
477
    end
478
    gpu.setBackground(0x696969)
479
    if OutputEUt and OutputEUt > StartEUt then
480
        StartEUt = math.ceil(reactor.getReactorEUOutput())
481
    end
482
end
483
484
gui()
485
gpu.setBackground(0x000000)
486
gpu.setForeground(0xFF9900)
487
gpu.set(1,14,"  для завершения нажмите E  ")
488
gpu.setBackground(0x696969)
489
os.sleep(1)
490
while run do
491
    local ok,err = pcall(ReactorControl)
492
    if not ok then
493
        red.setOutput(sideRed, 0)
494
        gpu.setResolution(w, h)
495
        gpu.setBackground(0x000000)
496
        gpu.setForeground(0xFFFFFF)
497
        os.execute("cls")
498
        print("программа аварийно завершена")
499
        if type(err) == "table" then
500
            io.stderr:write(table.unpack(err))
501
        else
502
            io.stderr:write(err)
503
        end
504
        run = false
505
    end
506
end