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