kozelkaricsi

Reactor Program in Hungarian Language

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