SHOW:
|
|
- or go back to the newest paste.
1 | - | -- pay attention to the fact that things return error now instead of origin values |
1 | + | |
2 | - | -- especially on reassembling on restart of server and things of the sort |
2 | + | |
3 | -- ** Reactor Madness Program ** -- | |
4 | -- ** for Big Reactor ** -- | |
5 | -- ** Written by krakaen ** -- | |
6 | -- ** Video Tutorial ** -- | |
7 | -- ** https://www.youtube.com/watch?v=SbbT7ncyS2M ** -- | |
8 | -- ****************************************************** -- | |
9 | -- ****************************************************** -- | |
10 | ||
11 | -- ******** Version 0.1 Changelog (02/16/2016) ******** | |
12 | -- Changed currentRFTotal to 1 (makes power show at start) | |
13 | ||
14 | -- ******** Version 0.2 Changelog (02/16/2016) ******** | |
15 | -- Added fuel usage (mb/t) | |
16 | - | -- ******** Version 0.1 Changelog (02/16/2016) ******** |
16 | + | |
17 | -- Added function comma_value | |
18 | -- Added function format_num | |
19 | - | -- ******** Version 0.2 Changelog (02/16/2016) ******** |
19 | + | |
20 | -- ******** Version 0.3 Changelog (02/17/2016) ******** | |
21 | -- Change Rod looking for 0 instead of 1 | |
22 | ||
23 | ||
24 | local monitors = {peripheral.find("monitor")} | |
25 | - | -- ******** Version 0.3 Changelog (02/17/2016) ******** |
25 | + | local mon = monitors[1] |
26 | local reactors = {peripheral.find("BigReactors-Reactor")} | |
27 | ||
28 | - | -- ******** Version 0.4 Changelog (10/18/2016) ******** |
28 | + | local button={} |
29 | - | -- Change rodLevel to do a Math.ceil instead of Math.floor |
29 | + | |
30 | local boxes = {} | |
31 | - | -- ******** Version 0.5 Changelog (03/01/2017) ******** |
31 | + | |
32 | - | -- Change drawBoxed and drawFilledBox for drawLines with for loop |
32 | + | |
33 | - | -- to get compatibility with 1.60+ |
33 | + | |
34 | local refresh = true | |
35 | - | -- ******** Version 0.6 Changelog (03/22/2017) ******** |
35 | + | |
36 | - | -- Added Custom error handling |
36 | + | |
37 | - | -- fixed typo in controlsSize for controlsSize |
37 | + | local contorlsSize = {} |
38 | local numbersSize = {} | |
39 | - | -- ******** Version 0.7 Changelog (05/15/2018) ******** |
39 | + | |
40 | - | -- Added new functions for extreme reactor handling. Will work on both new and old versions |
40 | + | |
41 | local currentFuelConsumedLastTick = 0.00001 | |
42 | - | -- ******** Version 0.8 Changelog (31/10/2020) ******** |
42 | + | |
43 | - | -- Added new functions for Bigger reactor handling. Will work on both new, newer and old versions |
43 | + | |
44 | local rfPerTickMax = 1 | |
45 | - | -- ******** Version 0.9 Changelog (24/04/2021) ******** |
45 | + | |
46 | - | -- Added new functions for newer Bigger reactor handling. Will work on both new, newer and old versions. |
46 | + | |
47 | local currentRodLevel = 1 | |
48 | - | -- ******** Version 0.10 Changelog (19/09/2021) ******** |
48 | + | |
49 | - | -- Added fix to calculate size of power tank on Extreme Reactor and fixed the total RB decimal issue. |
49 | + | -- you need to give the index to be able to use the program |
50 | -- ex : NameOfProgram Index (reactor Krakaen) | |
51 | - | -- you need to give the index to be able to use the program |
51 | + | |
52 | - | -- ex : NameOfProgram Index (reactor Krakaen) |
52 | + | |
53 | local index = "" | |
54 | ||
55 | if (#args == 0) then | |
56 | - | local button = {} |
56 | + | error("No index Given") |
57 | end | |
58 | ||
59 | if (#args == 1) then | |
60 | index = args[1] | |
61 | end | |
62 | ||
63 | -- use the black thingy sponge to clear the chalkboard | |
64 | ||
65 | - | local controlsSize = {} |
65 | + | |
66 | mon.clear() | |
67 | mon.setTextColor(colors.white) | |
68 | mon.setBackgroundColor(colors.black) | |
69 | ||
70 | function clearTable() | |
71 | button = {} | |
72 | end | |
73 | - | local rfTotalMax = 10000000 |
73 | + | |
74 | -- All the things that make my buttons work | |
75 | ||
76 | function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color) | |
77 | button[name] = {} | |
78 | button[name]["title"] = title | |
79 | button[name]["func"] = func | |
80 | - | local reactors = {} |
80 | + | |
81 | - | local monitors = {} |
81 | + | |
82 | button[name]["ymin"] = ymin | |
83 | - | local VERSION = "NONE" |
83 | + | |
84 | button[name]["ymax"] = ymax | |
85 | - | function checkVersionTooOld() |
85 | + | |
86 | - | local uselessMonitors = {peripheral.find("monitor")} |
86 | + | |
87 | button[name]["elem2"] = elem2 | |
88 | end | |
89 | - | function checkMBFunctionAvailability() |
89 | + | |
90 | - | local uselessMbConnected = reactors[1].mbIsConnected() |
90 | + | |
91 | - | local uselessMbAssembled = reactors[1].mbIsAssembled() |
91 | + | |
92 | function fill(text, color, bData) | |
93 | mon.setBackgroundColor(color) | |
94 | - | function checkEnergyCapacityFunction() |
94 | + | |
95 | - | local uselessEnergyCapacity = reactors[1].getEnergyStats().energyCapacity |
95 | + | |
96 | local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1 | |
97 | for j = bData["ymin"], bData["ymax"] do | |
98 | - | -- VERSIONS - BIG, EXTREME, BIGGERv1, BIGGERv2 |
98 | + | |
99 | - | function initReactor() |
99 | + | |
100 | - | if pcall(checkVersionTooOld) then |
100 | + | |
101 | - | monitors = {peripheral.find("monitor")} |
101 | + | |
102 | mon.write(bData["title"]) | |
103 | - | -- allow 5 seconds to detect if the reactor is on the network |
103 | + | |
104 | - | print("Detecting reactor. This may take up to 5 seconds.") |
104 | + | |
105 | - | local looptyloop = 0 |
105 | + | |
106 | - | while looptyloop ~= 5 do |
106 | + | |
107 | - | if peripheral.find("BigReactors-Reactor") ~= nil then |
107 | + | |
108 | - | reactors = {peripheral.find("BigReactors-Reactor")} |
108 | + | |
109 | - | if pcall(checkEnergyCapacityFunction) then |
109 | + | |
110 | - | rfTotalMax = reactors[1].getEnergyStats().energyCapacity |
110 | + | |
111 | - | end |
111 | + | |
112 | - | if pcall(checkMBFunctionAvailability) then |
112 | + | |
113 | - | VERSION = "EXTREME" |
113 | + | |
114 | - | else |
114 | + | |
115 | - | VERSION = "BIG" |
115 | + | |
116 | - | end |
116 | + | |
117 | - | break |
117 | + | |
118 | - | elseif peripheral.find("bigger-reactor") ~= nil then |
118 | + | |
119 | - | reactors = {peripheral.find("bigger-reactor")} |
119 | + | |
120 | - | VERSION = "BIGGERv1" |
120 | + | |
121 | - | break |
121 | + | |
122 | - | elseif peripheral.find("BiggerReactors_Reactor") ~= nil then |
122 | + | |
123 | - | reactors = {peripheral.find("BiggerReactors_Reactor")} |
123 | + | |
124 | - | VERSION = "BIGGERv2" |
124 | + | |
125 | - | rfTotalMax = reactors[1].battery().capacity() |
125 | + | |
126 | - | break |
126 | + | |
127 | - | end |
127 | + | |
128 | ||
129 | - | sleep(1) |
129 | + | |
130 | - | looptyloop = looptyloop + 1 |
130 | + | |
131 | screen() | |
132 | end | |
133 | - | if monitors[1] == nil then |
133 | + | |
134 | - | error("The Monitor is not being detected, make sure the connections(modem) are activated", 0) |
134 | + | |
135 | ||
136 | function checkxy(x, y) | |
137 | - | if reactors[1] == nil then |
137 | + | |
138 | - | error("The Reactor is not being detected, make sure the connections(modem) are activated. The problem could also be related to chunk protection on some public servers, ask an admin about it.", 0) |
138 | + | |
139 | if x>=data["xmin"] and x<= data["xmax"] then | |
140 | data["func"](data["elem"], data["elem2"]) | |
141 | - | error("The version of ComputerCraft is too old to use this program, sorry", 0) |
141 | + | |
142 | return true | |
143 | - | print("Reactor detected. Program Starting.") |
143 | + | |
144 | --print(name) | |
145 | end | |
146 | end | |
147 | - | error("No index Given, Make sure to start the 'start' program and not the 'reactor' program", 0) |
147 | + | |
148 | return false | |
149 | end | |
150 | ||
151 | -- Don't question my code, it works on my machine... | |
152 | ||
153 | function label(w, h, text) | |
154 | - | initReactor() -- Init and Verify that everything is okay to start the program |
154 | + | |
155 | mon.write(text) | |
156 | - | local mon = monitors[1] |
156 | + | |
157 | ||
158 | - | -- Use the black thingy sponge to clear the chalkboard |
158 | + | |
159 | ||
160 | function draw() | |
161 | ||
162 | for key,value in pairs(filleds) do | |
163 | paintutils.drawFilledBox(value[1] , value[2], value[3], value[4], value[5]) | |
164 | end | |
165 | ||
166 | for key,value in pairs(boxes) do | |
167 | paintutils.drawBox(value[1] , value[2], value[3], value[4], value[5]) | |
168 | end | |
169 | ||
170 | for key,value in pairs(lines) do | |
171 | paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5]) | |
172 | end | |
173 | ||
174 | for key,value in pairs(texts) do | |
175 | mon.setCursorPos(value[1], value[2]) | |
176 | mon.setTextColor(value[4]) | |
177 | mon.setBackgroundColor(value[5]) | |
178 | mon.write(value[3]) | |
179 | end | |
180 | screen() | |
181 | resetDraw() | |
182 | end | |
183 | ||
184 | -- Resets the elements to draw to only draw the neccessity | |
185 | ||
186 | function resetDraw() | |
187 | filleds = {} | |
188 | boxes = {} | |
189 | lines = {} | |
190 | texts = {} | |
191 | end | |
192 | ||
193 | -- Handles all the clicks for the buttons | |
194 | ||
195 | function clickEvent() | |
196 | local myEvent={os.pullEvent("monitor_touch")} | |
197 | checkxy(myEvent[3], myEvent[4]) | |
198 | end | |
199 | ||
200 | -- Power up the reactor (M&N are a good source of food right?) | |
201 | ||
202 | function powerUp(m,n) | |
203 | local reactor = reactors[1] | |
204 | reactor.setActive(true) | |
205 | end | |
206 | ||
207 | -- Power down the reactor (M&N are a good source of food right?) | |
208 | ||
209 | function powerDown(m,n) | |
210 | local reactor = reactors[1] | |
211 | reactor.setActive(false) | |
212 | end | |
213 | ||
214 | -- Handles and calculate the Min and Max of the power limitation | |
215 | ||
216 | function modifyRods(limit, number) | |
217 | local tempLevel = 0 | |
218 | ||
219 | if limit == "min" then | |
220 | tempLevel = minPowerRod + number | |
221 | if tempLevel <= 0 then | |
222 | minPowerRod = 0 | |
223 | end | |
224 | ||
225 | if tempLevel >= maxPowerRod then | |
226 | minPowerRod = maxPowerRod -10 | |
227 | end | |
228 | ||
229 | if tempLevel < maxPowerRod and tempLevel > 0 then | |
230 | minPowerRod = tempLevel | |
231 | end | |
232 | else | |
233 | tempLevel = maxPowerRod + number | |
234 | if tempLevel <= minPowerRod then | |
235 | maxPowerRod = minPowerRod +10 | |
236 | end | |
237 | ||
238 | if tempLevel >= 100 then | |
239 | maxPowerRod = 100 | |
240 | end | |
241 | ||
242 | if tempLevel > minPowerRod and tempLevel < 100 then | |
243 | maxPowerRod = tempLevel | |
244 | end | |
245 | end | |
246 | ||
247 | table.insert(lines, {contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY']+(contorlsSize['sectionHeight']*1)+4, colors.black}) | |
248 | ||
249 | table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black}) | |
250 | table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black}) | |
251 | table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black}) | |
252 | ||
253 | setInfoToFile() | |
254 | adjustRodsLevel() | |
255 | end | |
256 | ||
257 | - | local counter = 1 |
257 | + | |
258 | - | for i=value[2],value[4],1 do |
258 | + | |
259 | - | paintutils.drawLine(value[1] , value[2]+counter, value[3], value[2]+counter, value[5]) |
259 | + | |
260 | - | counter = counter + 1 |
260 | + | |
261 | local rfTotalMax = 10000000 | |
262 | local currentRfTotal = reactor.getEnergyStored() | |
263 | ||
264 | differenceMinMax = maxPowerRod - minPowerRod | |
265 | - | paintutils.drawLine(value[1] , value[2], value[1], value[4], value[5]) |
265 | + | |
266 | - | paintutils.drawLine(value[1] , value[2], value[3], value[2], value[5]) |
266 | + | |
267 | - | paintutils.drawLine(value[1] , value[4], value[3], value[4], value[5]) |
267 | + | |
268 | - | paintutils.drawLine(value[3] , value[2], value[3], value[4], value[5]) |
268 | + | |
269 | if currentRfTotal >= maxPower then | |
270 | currentRfTotal = maxPower | |
271 | end | |
272 | ||
273 | if currentRfTotal <= minPower then | |
274 | currentRfTotal = minPower | |
275 | end | |
276 | ||
277 | currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod | |
278 | ||
279 | local rfInBetween = (rfTotalMax/100) * differenceMinMax | |
280 | local rodLevel = math.floor((currentRfTotal/rfInBetween)*100) | |
281 | ||
282 | reactor.setAllControlRodLevels(rodLevel) | |
283 | end | |
284 | ||
285 | -- Creates the frame and the basic of the visual | |
286 | -- Also adds the variables informations for placement of stuff and things | |
287 | ||
288 | function addDrawBoxesSingleReactor() | |
289 | local w, h = mon.getSize() | |
290 | local margin = math.floor((w/100)*2) | |
291 | ||
292 | infosSize['startX'] = margin + 1 | |
293 | infosSize['startY'] = margin + 1 | |
294 | infosSize['endX'] = (((w-(margin*2))/3)*2)-margin | |
295 | infosSize['endY'] = h - margin | |
296 | infosSize['height'] = infosSize['endY']-infosSize['startY']-(margin*2)-2 | |
297 | infosSize['width'] = infosSize['endX']-infosSize['startX']-(margin*2)-2 | |
298 | infosSize['inX'] = infosSize['startX'] + margin +1 | |
299 | infosSize['inY'] = infosSize['startY'] + margin +1 | |
300 | infosSize['sectionHeight'] = math.floor(infosSize['height']/3) | |
301 | ||
302 | table.insert(boxes, {infosSize['startX'] , infosSize['startY'], infosSize['endX'], infosSize['endY'], colors.gray}) | |
303 | local name = "INFOS" | |
304 | table.insert(lines, {infosSize['startX'] + margin , infosSize['startY'], infosSize['startX'] + (margin*2) + #name+1, infosSize['startY'], colors.black}) | |
305 | table.insert(texts, {infosSize['startX'] + (margin*2), infosSize['startY'], name, colors.white, colors.black}) | |
306 | ||
307 | local names = {} | |
308 | names[1] = 'ENERGY LAST TICK' | |
309 | names[2] = 'ENERGY STORED' | |
310 | names[3] = 'CONTROL ROD LEVEL' | |
311 | ||
312 | for i=0,2,1 do | |
313 | table.insert(texts, {infosSize['inX'] + margin, infosSize['inY'] + (infosSize['sectionHeight']*i) +i, names[i+1], colors.white, colors.black}) | |
314 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 2 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray}) | |
315 | end | |
316 | ||
317 | ||
318 | -- Controls | |
319 | ||
320 | contorlsSize['startX'] = infosSize['endX'] + margin + 1 | |
321 | contorlsSize['startY'] = margin + 1 | |
322 | contorlsSize['endX'] = w-margin | |
323 | contorlsSize['endY'] = (((h - (margin*2))/3)*2) +1 | |
324 | contorlsSize['height'] = contorlsSize['endY']-contorlsSize['startY']-(margin)-1 | |
325 | contorlsSize['width'] = contorlsSize['endX']-contorlsSize['startX']-(margin*2)-2 | |
326 | contorlsSize['inX'] = contorlsSize['startX'] + margin +1 | |
327 | contorlsSize['inY'] = contorlsSize['startY'] + margin | |
328 | ||
329 | table.insert(boxes, {contorlsSize['startX'] , contorlsSize['startY'], contorlsSize['endX'], contorlsSize['endY'], colors.gray}) | |
330 | name = "CONTROLS" | |
331 | table.insert(lines, {contorlsSize['startX'] + margin , contorlsSize['startY'], contorlsSize['startX'] + (margin*2) + #name+1, contorlsSize['startY'], colors.black}) | |
332 | table.insert(texts, {contorlsSize['startX'] + (margin*2), contorlsSize['startY'], name, colors.white, colors.black}) | |
333 | ||
334 | contorlsSize['sectionHeight'] = math.floor(contorlsSize['height']/4) | |
335 | ||
336 | reactor = reactors[1] | |
337 | ||
338 | mon.setTextColor(colors.white) | |
339 | setButton("ON","ON", powerUp, contorlsSize['inX'], contorlsSize['inY'], contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +2, 0, 0, colors.green) | |
340 | setButton("OFF","OFF", powerDown, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'], contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +2,0, 0, colors.red) | |
341 | ||
342 | table.insert(texts, {contorlsSize['inX']+8, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black}) | |
343 | ||
344 | table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black}) | |
345 | table.insert(texts, {contorlsSize['inX']+5, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black}) | |
346 | ||
347 | table.insert(texts, {contorlsSize['inX']+13, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black}) | |
348 | - | table.insert(lines, {controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, controlsSize['inX'] + controlsSize['width'], controlsSize['inY']+(controlsSize['sectionHeight']*1)+4, colors.black}) |
348 | + | table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black}) |
349 | table.insert(texts, {contorlsSize['inX']+20, contorlsSize['inY'] +(contorlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black}) | |
350 | - | table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod .. '%', colors.lightBlue, colors.black}) |
350 | + | |
351 | - | table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black}) |
351 | + | |
352 | - | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod .. '%', colors.purple, colors.black}) |
352 | + | setButton("low-10","-10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue) |
353 | setButton("high-10","-10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*2)+4, "max", -10, colors.purple) | |
354 | ||
355 | setButton("low+10","+10", modifyRods, contorlsSize['inX'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) -1, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue) | |
356 | setButton("high+10","+10", modifyRods, contorlsSize['inX'] + math.floor(contorlsSize['width']/2) +2, contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+2, contorlsSize['inX'] + contorlsSize['width'], contorlsSize['inY'] +(contorlsSize['sectionHeight']*3)+4, "max", 10, colors.purple) | |
357 | ||
358 | -- Numbers | |
359 | - | -- TOMODIFY |
359 | + | |
360 | numbersSize['startX'] = infosSize['endX'] + margin + 1 | |
361 | numbersSize['startY'] = contorlsSize['endY'] + margin + 1 | |
362 | numbersSize['endX'] = w-margin | |
363 | - | local allStats = getAllStats() |
363 | + | |
364 | - | local currentRfTotal = allStats["rfTotal"] |
364 | + | |
365 | - | local reactorRodsLevel = allStats["reactorRodsLevel"] |
365 | + | |
366 | numbersSize['inX'] = numbersSize['startX'] + margin +1 | |
367 | numbersSize['inY'] = numbersSize['startY'] + margin | |
368 | ||
369 | table.insert(boxes, {numbersSize['startX'] , numbersSize['startY'], numbersSize['endX'], numbersSize['endY'], colors.gray}) | |
370 | name = "NUMBERS" | |
371 | table.insert(lines, {numbersSize['startX'] + margin , numbersSize['startY'], numbersSize['startX'] + (margin*2) + #name+1, numbersSize['startY'], colors.black}) | |
372 | table.insert(texts, {numbersSize['startX'] + (margin*2), numbersSize['startY'], name, colors.white, colors.black}) | |
373 | ||
374 | refresh = true | |
375 | while refresh do | |
376 | parallel.waitForAny(refreshSingleReactor,clickEvent) | |
377 | end | |
378 | end | |
379 | ||
380 | -- Makes and Handles the draw function for less lag in the visual | |
381 | ||
382 | function refreshSingleReactor() | |
383 | - | local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100) |
383 | + | |
384 | - | if VERSION == "EXTREME" then |
384 | + | |
385 | - | for key,value in pairs(reactorRodsLevel) do |
385 | + | local rfTotalMax = 10000000 |
386 | - | reactorRodsLevel[key] = rodLevel |
386 | + | |
387 | ||
388 | - | reactor.setControlRodsLevels(reactorRodsLevel) |
388 | + | rfTotal = reactor.getEnergyStored() |
389 | rfPerTick = math.floor(reactor.getEnergyProducedLastTick()) | |
390 | - | reactor.setAllControlRodLevels(rodLevel) |
390 | + | rodLevel = math.floor(reactor.getControlRodLevel(0)) |
391 | fuelPerTick = reactor.getFuelConsumedLastTick(); | |
392 | ||
393 | local i = 0 | |
394 | local infotoAdd = 'RF PER TICK : ' | |
395 | ||
396 | if currentRfTick ~= rfPerTick then | |
397 | currentRfTick = rfPerTick | |
398 | if rfPerTick > rfPerTickMax then | |
399 | rfPerTickMax = rfPerTick | |
400 | end | |
401 | ||
402 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY'],numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'], colors.black}) | |
403 | table.insert(texts, {numbersSize['inX'], numbersSize['inY'], infotoAdd .. rfPerTick .. " RF", colors.white, colors.black}) | |
404 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray}) | |
405 | ||
406 | width = math.floor((infosSize['width'] / rfPerTickMax)*rfPerTick) | |
407 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green}) | |
408 | ||
409 | end | |
410 | ||
411 | i = 1 | |
412 | infotoAdd = 'ENERGY STORED : ' | |
413 | if currentRfTotal ~= rfTotal then | |
414 | currentRfTotal = rfTotal | |
415 | ||
416 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + infosSize['width'], infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.lightGray}) | |
417 | ||
418 | width = math.floor((infosSize['width'] / rfTotalMax)*rfTotal) | |
419 | table.insert(filleds, {infosSize['inX'] , infosSize['inY'] + 1 + (infosSize['sectionHeight']*i) +i, infosSize['inX'] + width, infosSize['inY'] + (infosSize['sectionHeight']*(i+1))-2 +i, colors.green}) | |
420 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY'] +2 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +2, colors.black}) | |
421 | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 2 , infotoAdd .. rfTotal .. " RF", colors.white, colors.black}) | |
422 | end | |
423 | ||
424 | i = 2 | |
425 | infotoAdd = 'CONTROL ROD LEVEL : ' | |
426 | if currentRodLevel ~= rodLevel then | |
427 | currentRodLevel = rodLevel | |
428 | ||
429 | - | controlsSize['startX'] = infosSize['endX'] + margin + 1 |
429 | + | |
430 | - | controlsSize['startY'] = margin + 1 |
430 | + | |
431 | - | controlsSize['endX'] = w-margin |
431 | + | |
432 | - | controlsSize['endY'] = (((h - (margin*2))/3)*2) +1 |
432 | + | |
433 | - | controlsSize['height'] = controlsSize['endY']-controlsSize['startY']-(margin)-1 |
433 | + | |
434 | - | controlsSize['width'] = controlsSize['endX']-controlsSize['startX']-(margin*2)-2 |
434 | + | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 4 , infotoAdd .. rodLevel .. "%", colors.white, colors.black}) |
435 | - | controlsSize['inX'] = controlsSize['startX'] + margin +1 |
435 | + | |
436 | - | controlsSize['inY'] = controlsSize['startY'] + margin |
436 | + | |
437 | i = 3 | |
438 | - | table.insert(boxes, {controlsSize['startX'] , controlsSize['startY'], controlsSize['endX'], controlsSize['endY'], colors.gray}) |
438 | + | |
439 | if currentFuelConsumedLastTick ~= fuelPerTick then | |
440 | - | table.insert(lines, {controlsSize['startX'] + margin , controlsSize['startY'], controlsSize['startX'] + (margin*2) + #name+1, controlsSize['startY'], colors.black}) |
440 | + | |
441 | - | table.insert(texts, {controlsSize['startX'] + (margin*2), controlsSize['startY'], name, colors.white, colors.black}) |
441 | + | |
442 | table.insert(lines, {numbersSize['inX'] , numbersSize['inY']+6 ,numbersSize['inX'] + numbersSize['width'] , numbersSize['inY'] +6, colors.black}) | |
443 | - | controlsSize['sectionHeight'] = math.floor(controlsSize['height']/4) |
443 | + | table.insert(texts, {numbersSize['inX'], numbersSize['inY']+ 6 , infotoAdd .. format_num(tonumber(fuelPerTick),3) .. "mb/t", colors.white, colors.black}) |
444 | end | |
445 | ||
446 | mon.setTextColor(colors.white) | |
447 | adjustRodsLevel() | |
448 | - | setButton("ON","ON", powerUp, controlsSize['inX'], controlsSize['inY'], controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +2, 0, 0, colors.green) |
448 | + | |
449 | - | setButton("OFF","OFF", powerDown, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'], controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +2,0, 0, colors.red) |
449 | + | |
450 | ||
451 | - | table.insert(texts, {controlsSize['inX']+8, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+1, 'AUTO-CONTROL', colors.white, colors.black}) |
451 | + | |
452 | end | |
453 | - | table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MIN', colors.lightBlue, colors.black}) |
453 | + | |
454 | - | table.insert(texts, {controlsSize['inX']+5, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, minPowerRod..'%', colors.lightBlue, colors.black}) |
454 | + | |
455 | -- ** Get the informations from the index file | |
456 | - | table.insert(texts, {controlsSize['inX']+13, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, '--', colors.white, colors.black}) |
456 | + | |
457 | - | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+3, 'MAX', colors.purple, colors.black}) |
457 | + | |
458 | - | table.insert(texts, {controlsSize['inX']+20, controlsSize['inY'] +(controlsSize['sectionHeight']*1)+4, maxPowerRod..'%', colors.purple, colors.black}) |
458 | + | |
459 | ||
460 | function getInfoFromFile() | |
461 | - | setButton("low-10","-10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "min", -10, colors.lightBlue) |
461 | + | |
462 | - | setButton("high-10","-10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*2)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*2)+4, "max", -10, colors.purple) |
462 | + | |
463 | file = io.open(index..".txt","w") | |
464 | - | setButton("low+10","+10", modifyRods, controlsSize['inX'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + math.floor(controlsSize['width']/2) -1, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "min", 10, colors.lightBlue) |
464 | + | |
465 | - | setButton("high+10","+10", modifyRods, controlsSize['inX'] + math.floor(controlsSize['width']/2) +2, controlsSize['inY'] +(controlsSize['sectionHeight']*3)+2, controlsSize['inX'] + controlsSize['width'], controlsSize['inY'] +(controlsSize['sectionHeight']*3)+4, "max", 10, colors.purple) |
465 | + | |
466 | file:write("100") | |
467 | file:close() | |
468 | else | |
469 | file = fs.open(index..".txt","r") | |
470 | - | numbersSize['startY'] = controlsSize['endY'] + margin + 1 |
470 | + | |
471 | maxPowerRod = tonumber(file.readLine()) | |
472 | file.close() | |
473 | end | |
474 | end | |
475 | ||
476 | - | numbersSize['inY'] = numbersSize['startY'] + margin |
476 | + | |
477 | ||
478 | function setInfoToFile() | |
479 | file = io.open(index..".txt","w") | |
480 | file:write(minPowerRod .. "\n" .. maxPowerRod) | |
481 | file:flush() | |
482 | file:close() | |
483 | end | |
484 | ||
485 | ---============================================================ | |
486 | -- add comma to separate thousands | |
487 | -- From Lua-users.org/wiki/FormattingNumbers | |
488 | -- | |
489 | - | -- Gets the stats needed for the program to function based on the version of the reactor |
489 | + | -- |
490 | - | -- TOMODIFY |
490 | + | |
491 | - | function getAllStats() |
491 | + | |
492 | - | local stats = {} |
492 | + | while true do |
493 | formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') | |
494 | if (k==0) then | |
495 | - | if VERSION == "EXTREME" then |
495 | + | |
496 | - | local reactorEnergyStats = reactor.getEnergyStats() |
496 | + | |
497 | - | local reactorFuelStats = reactor.getFuelStats() |
497 | + | |
498 | return formatted | |
499 | - | stats["reactorRodsLevel"] = reactor.getControlRodsLevels() |
499 | + | |
500 | - | stats["rfTotal"] = math.floor(reactorEnergyStats["energyStored"]) |
500 | + | |
501 | - | stats["rfPerTick"] = math.floor(reactorEnergyStats["energyProducedLastTick"]) |
501 | + | |
502 | - | stats["rodLevel"] = stats["reactorRodsLevel"][0] |
502 | + | |
503 | - | stats["fuelPerTick"] = round(reactorFuelStats["fuelConsumedLastTick"], 2) |
503 | + | |
504 | - | elseif VERSION == "BIG" or VERSION == "BIGGERv1" then |
504 | + | |
505 | - | stats["rfTotal"] = math.floor(reactor.getEnergyStored()) |
505 | + | |
506 | - | stats["rfPerTick"] = math.floor(reactor.getEnergyProducedLastTick()) |
506 | + | |
507 | - | stats["rodLevel"] = math.floor(reactor.getControlRodLevel(0)) |
507 | + | |
508 | - | stats["fuelPerTick"] = reactor.getFuelConsumedLastTick() |
508 | + | |
509 | - | elseif VERSION == "BIGGERv2" then |
509 | + | |
510 | - | stats["rfTotal"] = reactor.battery().stored() |
510 | + | |
511 | - | stats["rfPerTick"] = math.floor(reactor.battery().producedLastTick()) |
511 | + | |
512 | - | stats["rodLevel"] = math.floor(reactor.getControlRod(0).level()) |
512 | + | |
513 | - | stats["fuelPerTick"] = reactor.fuelTank().burnedLastTick() |
513 | + | |
514 | --=================================================================== | |
515 | -- given a numeric value formats output with comma to separate thousands | |
516 | - | return stats |
516 | + | |
517 | -- From Lua-users.org/wiki/FormattingNumbers | |
518 | -- | |
519 | function format_num(amount, decimal, prefix, neg_prefix) | |
520 | local str_amount, formatted, famount, remain | |
521 | ||
522 | decimal = decimal or 2 -- default 2 decimal places | |
523 | neg_prefix = neg_prefix or "-" -- default negative sign | |
524 | ||
525 | - | local allStats = getAllStats() |
525 | + | |
526 | - | rfTotal = allStats["rfTotal"] |
526 | + | |
527 | - | rfPerTick = allStats["rfPerTick"] |
527 | + | |
528 | - | rodLevel = allStats["rodLevel"] |
528 | + | |
529 | - | fuelPerTick = allStats["fuelPerTick"] |
529 | + | |
530 | -- comma to separate the thousands | |
531 | formatted = comma_value(famount) | |
532 | ||
533 | -- attach the decimal portion | |
534 | if (decimal > 0) then | |
535 | remain = string.sub(tostring(remain),3) | |
536 | formatted = formatted .. "." .. remain .. | |
537 | string.rep("0", decimal - string.len(remain)) | |
538 | end | |
539 | ||
540 | -- attach prefix string e.g '$' | |
541 | formatted = (prefix or "") .. formatted | |
542 | ||
543 | -- if value is negative then format accordingly | |
544 | if (amount<0) then | |
545 | if (neg_prefix=="()") then | |
546 | formatted = "("..formatted ..")" | |
547 | else | |
548 | formatted = neg_prefix .. formatted | |
549 | end | |
550 | end | |
551 | ||
552 | return formatted | |
553 | end | |
554 | ||
555 | -- Clear and make the pixel smaller because we are not blind | |
556 | ||
557 | mon.setBackgroundColor(colors.black) | |
558 | mon.clear() | |
559 | mon.setTextScale(0.5) | |
560 | ||
561 | -- Get the information from the index file | |
562 | getInfoFromFile() | |
563 | ||
564 | ||
565 | -- Add's the visual and starts the Loop | |
566 | addDrawBoxesSingleReactor() |