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