SHOW:
|
|
- or go back to the newest paste.
1 | local cells = {peripheral.wrap("tile_blockcapacitorbank_name_1"), | |
2 | peripheral.wrap("tile_blockcapacitorbank_name_3"), | |
3 | peripheral.wrap("tile_blockcapacitorbank_name_4"), | |
4 | peripheral.wrap("tile_blockcapacitorbank_name_5") | |
5 | } | |
6 | ||
7 | local energyTable = {} | |
8 | local maxEnergyTable = {} | |
9 | ||
10 | local previousEnergyTotal = 0 | |
11 | ||
12 | local reactor = peripheral.wrap("BigReactors-Reactor_1") | |
13 | local monitor = peripheral.wrap("monitor_1") | |
14 | ||
15 | local enableReactorAt = 20 | |
16 | ||
17 | function getLength(text) | |
18 | length = string.len(text) | |
19 | return length | |
20 | end | |
21 | ||
22 | function centerCursor(text) | |
23 | textLength = getLength(text) | |
24 | x, y = monitor.getSize() | |
25 | x2, y2 = monitor.getCursorPos() | |
26 | term.setCursorPos(math.round((x / 2) - (textLength / 2)), y2) | |
27 | end | |
28 | ||
29 | function monitorClear() | |
30 | monitor.setTextColor(colors.white) | |
31 | monitor.clear() | |
32 | monitor.setCursorPos(1,1) | |
33 | end | |
34 | ||
35 | function monitorNewLine() | |
36 | x, y = monitor.getCursorPos() | |
37 | newY = y + 1 | |
38 | monitor.setCursorPos(1, newY) | |
39 | end | |
40 | ||
41 | function writeTextTable(text) | |
42 | monitorClear() | |
43 | for i = 1, #text do | |
44 | centerCursor(text[i]) | |
45 | monitor.write(text[i]) | |
46 | monitorNewLine() | |
47 | end | |
48 | end | |
49 | ||
50 | function writeText(text, color) | |
51 | monitor.setTextColor(color) | |
52 | centerCursor(text[i]) | |
53 | monitor.write(text) | |
54 | monitorNewLine() | |
55 | end | |
56 | ||
57 | - | text[i] = strStart .. tostring(i) .. " : " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) |
57 | + | |
58 | reactorEnergyInput = 0 | |
59 | if reactor.getActive() then | |
60 | - | textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. " / " .. tostring(totalEnergyCapacity) |
60 | + | |
61 | end | |
62 | energyTick = ((previousEnergyTotal - totalEnergyStored) / 20) + reactorEnergyInput | |
63 | return energyTick | |
64 | end | |
65 | ||
66 | ||
67 | function monitorUpdate(totalEnergyStored, totalEnergyCapacity) | |
68 | text = {} | |
69 | strStart = "Energy Cell " | |
70 | for i = 1, #energyTable do | |
71 | p = math.round((energyTable[i] / maxEnergyTable[i]) * 100) | |
72 | text[i] = strStart .. tostring(i) .. ": " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) .. " : " .. p .. "%" | |
73 | end | |
74 | writeTextTable(text) | |
75 | p = math.round((totalEnergyStored / totalEnergyCapacity) * 100) | |
76 | textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. "/" .. tostring(totalEnergyCapacity) .. " : " .. p .. "%" | |
77 | writeText(textTotal, colors.orange) | |
78 | usingEnergy = energyUse(totalEnergyStored) | |
79 | textUsing = "Using : " .. tostring(usingEnergy) .. " RF per tick" | |
80 | writeText(textUsing, colors.red) | |
81 | end | |
82 | ||
83 | function disableReactor() | |
84 | reactor.setActive(false) | |
85 | end | |
86 | ||
87 | function enableReactor() | |
88 | reactor.setActive(true) | |
89 | end | |
90 | ||
91 | function checkPower(totalEnergyStored, totalEnergyCapacity) | |
92 | isReactorActive = reactor.getActive() | |
93 | p = math.ceil((totalEnergyStored / totalEnergyCapacity) * 100) | |
94 | if isReactorActive then | |
95 | if p == 100 then | |
96 | disableReactor() | |
97 | else | |
98 | return | |
99 | end | |
100 | elseif p <= enableReactorAt then | |
101 | enableReactor() | |
102 | end | |
103 | end | |
104 | ||
105 | while true do | |
106 | totalEnergyStored = 0 | |
107 | totalEnergyCapacity = 0 | |
108 | for i = 1, #cells do | |
109 | energyStored = cells[i].getEnergyStored() | |
110 | maxEnergyStored = cells[i].getMaxEnergyStored() | |
111 | energyTable[i] = energyStored | |
112 | maxEnergyTable[i] = maxEnergyStored | |
113 | totalEnergyStored = totalEnergyStored + tonumber(energyStored) | |
114 | totalEnergyCapacity = totalEnergyCapacity + tonumber(maxEnergyStored) | |
115 | end | |
116 | monitorUpdate(totalEnergyStored, totalEnergyCapacity) | |
117 | checkPower(totalEnergyStored, totalEnergyCapacity) | |
118 | previousEnergyTotal = totalEnergyStored | |
119 | sleep(1) | |
120 | end |