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