SHOW:
|
|
- or go back to the newest paste.
1 | local cells = {peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_10"), | |
2 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_11"), | |
3 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_12"), | |
4 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_13"), | |
5 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_14"), | |
6 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_15"), | |
7 | peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_16") | |
8 | ||
9 | } | |
10 | ||
11 | local energyTable = {} | |
12 | local maxEnergyTable = {} | |
13 | ||
14 | local reactor = peripheral.wrap("BigReactors-Reactor_1") | |
15 | local monitor = peripheral.wrap("monitor_1") | |
16 | ||
17 | local enableReactorAt = 20 | |
18 | - | local isReactorProcessing = false |
18 | + | |
19 | function monitorClear() | |
20 | monitor.setTextColor(colors.white) | |
21 | monitor.clear() | |
22 | monitor.setCursorPos(1,1) | |
23 | end | |
24 | ||
25 | function monitorNewLine() | |
26 | x, y = monitor.getCursorPos() | |
27 | newY = y + 1 | |
28 | monitor.setCursorPos(1, newY) | |
29 | end | |
30 | ||
31 | function writeTextTable(text) | |
32 | monitorClear() | |
33 | for i = 1, #text do | |
34 | monitor.write(text[i]) | |
35 | monitorNewLine() | |
36 | end | |
37 | end | |
38 | ||
39 | function writeText(text, color) | |
40 | monitor.setTextColor(color) | |
41 | monitor.write(text) | |
42 | monitorNewLine() | |
43 | end | |
44 | ||
45 | ||
46 | function monitorUpdate(totalEnergyStored, totalEnergyCapacity) | |
47 | text = {} | |
48 | strStart = "Energy Cell " | |
49 | for i = 1, #energyTable do | |
50 | text[i] = strStart .. tostring(i) .. " : " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) | |
51 | end | |
52 | writeTextTable(text) | |
53 | textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. " / " .. tostring(totalEnergyCapacity) | |
54 | writeText(textTotal, colors.orange) | |
55 | end | |
56 | ||
57 | function disableReactor() | |
58 | reactor.setActive(false) | |
59 | end | |
60 | ||
61 | function enableReactor() | |
62 | reactor.setActive(true) | |
63 | end | |
64 | ||
65 | function checkPower(totalEnergyStored, totalEnergyCapacity) | |
66 | isReactorActive = reactor.isActive() | |
67 | p = math.floor((totalEnergyStored / totalEnergyCapacity) * 100) | |
68 | - | if isReactorProcessing then |
68 | + | if isReactorActive then |
69 | if totalEnergyStored == totalEnergyCapacity then | |
70 | disableReactor() | |
71 | else | |
72 | return | |
73 | end | |
74 | elseif p <= enableReactorAt then | |
75 | enableReactor() | |
76 | end | |
77 | end | |
78 | ||
79 | while true do | |
80 | totalEnergyStored = 0 | |
81 | totalEnergyCapacity = 0 | |
82 | for i = 1, #cells do | |
83 | energyStored = cells[i].getEnergyStored() | |
84 | maxEnergyStored = cells[i].getMaxEnergyStored() | |
85 | energyTable[i] = energyStored | |
86 | maxEnergyTable[i] = maxEnergyStored | |
87 | totalEnergyStored = totalEnergyStored + tonumber(energyStored) | |
88 | totalEnergyCapacity = totalEnergyCapacity + tonumber(maxEnergyStored) | |
89 | end | |
90 | monitorUpdate(totalEnergyStored, totalEnergyCapacity) | |
91 | checkPower(totalEnergyStored, totalEnergyCapacity) | |
92 | sleep(2) | |
93 | end |