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