Advertisement
Imeguras2

montanhaComputador2

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