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 | function energyUse(totalEnergyStored) | |
58 | reactorEnergyInput = 0 | |
59 | if reactor.getActive() then | |
60 | reactorEnergyInput = reactor.getEnergyProducedLastTick() | |
61 | end | |
62 | energyTick = ((previousEnergyTotal - totalEnergyStored) / 20) + reactorEnergyInput | |
63 | return energyTick | |
64 | end | |
65 | ||
66 | function getPercentage(value1, value2) | |
67 | p = (value1 / value2) * 100 | |
68 | pClean = math.round(p) | |
69 | return pClean | |
70 | end | |
71 | - | p = math.round((energyTable[i] / maxEnergyTable[i]) * 100) |
71 | + | |
72 | - | text[i] = strStart .. tostring(i) .. ": " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) .. " : " .. p .. "%" |
72 | + | |
73 | text = {} | |
74 | strStart = "Energy Cell " | |
75 | - | p = math.round((totalEnergyStored / totalEnergyCapacity) * 100) |
75 | + | |
76 | - | textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. "/" .. tostring(totalEnergyCapacity) .. " : " .. p .. "%" |
76 | + | per = getPercentage(energyTable[i], maxEnergyTable[i]) |
77 | text[i] = strStart .. tostring(i) .. ": " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i]) .. " : " .. per .. "%" | |
78 | end | |
79 | writeTextTable(text) | |
80 | per = getPercentage(totalEnergyStored, totalEnergyCapacity) | |
81 | textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. "/" .. tostring(totalEnergyCapacity) .. " : " .. per .. "%" | |
82 | writeText(textTotal, colors.orange) | |
83 | usingEnergy = energyUse(totalEnergyStored) | |
84 | textUsing = "Using : " .. tostring(usingEnergy) .. " RF per tick" | |
85 | writeText(textUsing, colors.red) | |
86 | end | |
87 | ||
88 | function disableReactor() | |
89 | reactor.setActive(false) | |
90 | end | |
91 | ||
92 | function enableReactor() | |
93 | reactor.setActive(true) | |
94 | end | |
95 | ||
96 | function checkPower(totalEnergyStored, totalEnergyCapacity) | |
97 | isReactorActive = reactor.getActive() | |
98 | p = math.ceil((totalEnergyStored / totalEnergyCapacity) * 100) | |
99 | if isReactorActive then | |
100 | if p == 100 then | |
101 | disableReactor() | |
102 | else | |
103 | return | |
104 | end | |
105 | elseif p <= enableReactorAt then | |
106 | enableReactor() | |
107 | end | |
108 | end | |
109 | ||
110 | while true do | |
111 | totalEnergyStored = 0 | |
112 | totalEnergyCapacity = 0 | |
113 | for i = 1, #cells do | |
114 | energyStored = cells[i].getEnergyStored() | |
115 | maxEnergyStored = cells[i].getMaxEnergyStored() | |
116 | energyTable[i] = energyStored | |
117 | maxEnergyTable[i] = maxEnergyStored | |
118 | totalEnergyStored = totalEnergyStored + tonumber(energyStored) | |
119 | totalEnergyCapacity = totalEnergyCapacity + tonumber(maxEnergyStored) | |
120 | end | |
121 | monitorUpdate(totalEnergyStored, totalEnergyCapacity) | |
122 | checkPower(totalEnergyStored, totalEnergyCapacity) | |
123 | previousEnergyTotal = totalEnergyStored | |
124 | sleep(1) | |
125 | end |