MrFreeZX

Modified mekanism fusion reactor controller

Sep 21st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.01 KB | None | 0 0
  1. -- pastebin get wsk4MCJf startup
  2.  
  3. --config
  4. MinProcenttoBoost = 10           -- means min Tank amount vor max Inj Rate
  5. MinProcentforLowMode = 75        -- means min Energycelllevel for produce over mrfneed
  6. MRFBuffer = 0.1                  -- for produce over mrfneed (for KRF = 0. ; MRF = 1)
  7. xRC = 1                          -- Amount of the Rotary-Condenstrator(Leave it on 1, if u dont use D-T-Fuel)
  8.  
  9. ---===================================--Fusion-Reaktor-Proramm--v0.9.4 by Dispelnator--============================================
  10.  
  11. --Ty for using my Mekanism-Fusion-Reactor-Programm,
  12. --Its my first Lua Program, so please tell me better Solutions of this Code.
  13.  
  14. --I need help with a Function to calc the current Tritium Production
  15. --Means if tank on day < 50 then injection rate = tritium input then the tank goes over 75 %
  16.  
  17. --You need minimum ProjectRed and Mekanism(+Tools,Generators)+ draconicevolution (for flux and fluid gates) for this Program
  18.  
  19. --BundeledCable list:
  20. --                       Red for Laser (fireup)
  21. --                       Yellow for Alarm and Hohlraum-Insert
  22. --                       Black 2 power laser via Tesseract/cubes...
  23. --The fuel usage is Injection-Rate/2 => For INJ-RATE = 98 you need 49 mb Tritium and 49 mb Deuterium (per tick) => ca. 9.8 MRF
  24. --For more Power u need Draconic Fluid-Gate and Rotary-Condenstrator*x and a Chemical Infuser (D-T-Fuel)
  25. --1 Rotary-Condenstrator = max 256mb/t means  ca. + 25.6 MRF/t
  26. --Actually u can use Draconic-Energy-Core for Energy Storage but Induction-Matrix from Mekanism is better.
  27. --Actually u can use only Dynamic-Tanks but its the best one
  28. --
  29. --
  30. --Everything around the monitor I have taken from Krakaen's Big-Reactor-Program and
  31. --Thor_s_Crafter helped me with most buggs in the program
  32. --Some Videos about their Big-Reactor-Programs:
  33. --Krakaen       : https://www.youtube.com/watch?v=SbbT7ncyS2M
  34. --Thor_s_Crafter: https://www.youtube.com/watch?v=XNlsU0tSHOc
  35.  
  36. ---================================================ Edit at own Risk ===============================================================
  37.  
  38. FirstProcent = 0
  39. SecondProcent = 0
  40. k = 0.09961964844
  41. InjRate = 0
  42. DTFuelInjRate = 0
  43. FuelInjRate = 0
  44. MRFProduce = 0
  45. amountTanks = 0
  46. MRFLaser = 0
  47. MRFMaxLaser = 0
  48. MRFNeed = 0
  49. Charge = 0
  50. InjRate2 = 2
  51. w = 0
  52.  
  53. currentChargeLevel = 1
  54. currentInjRate = 1
  55.  
  56. local TType = ""
  57. local EType = ""
  58. local ChargeStatus = "UNCHARGED"
  59. local ReactorStatus = "OFFLINE"
  60.  
  61. local TankLevel = false
  62. local TankLevel1 = false
  63. local TankLevel2 = false
  64. local Auto = false
  65. local ChargeOn = false
  66. local FireUpOK = false
  67. local refresh = true
  68.  
  69. local ChargeOnOffcolor = colors.green
  70. local FireUpcolor = colors.green
  71. local powerUpcolor = colors.green
  72. local ChargeTextcolor = colors.red
  73. local RectorTextcolor = colors.red
  74.  
  75. rs.setBundledOutput("bottom", 0)
  76.  
  77. -- tabels
  78.  
  79. local Tanktypes = {"dynamic_tank"}
  80. local EnergyStoragetypesMekanism = {"Basic Energy Cube", "Advanced Energy Cube", "Elite Energy Cube", "Ultimate Energy Cube" }
  81. local EnergyStoragetypesMekanismIM = {"Induction Matrix"}
  82. --local Tanks = {}
  83.  
  84. local button={}
  85. local filleds = {}
  86. local boxes = {}
  87. local lines = {}
  88. local texts = {}
  89.  
  90. local FirstTankStats = {}
  91. local SecondTankStats = {}
  92.  
  93. local GeneralBox = {}
  94. local ReactorBox = {}
  95. local TankBox = {}
  96. local GraphicBox = {}
  97.  
  98. function initPeripherals()
  99.     local peripheralList = peripheral.getNames()
  100.     for i=1,#peripheralList do
  101.         -- Reactor
  102.         if peripheral.getType(peripheralList[i]) == "Reactor Logic Adapter" then
  103.             FReactor = peripheral.wrap(peripheralList[i])
  104.         end
  105.         -- Laser Amplifier
  106.         if peripheral.getType(peripheralList[i]) == "Laser Amplifier" then
  107.             LaserAmp = peripheral.wrap(peripheralList[i])
  108.         end
  109.         -- Energystorage
  110.         for k,v in pairs(EnergyStoragetypesMekanism) do
  111.             if peripheral.getType(peripheralList[i]) == v then
  112.                 RFStorage = peripheral.wrap(peripheralList[i])
  113.                 EType = "mekanism"
  114.             end
  115.         end
  116.         for k,v in pairs(EnergyStoragetypesMekanismIM) do
  117.             if peripheral.getType(peripheralList[i]) == v then
  118.                 RFStorage = peripheral.wrap(peripheralList[i])
  119.                 EType = "mekanismIM"
  120.             end
  121.         end
  122.         -- Monitor
  123.         if peripheral.getType(peripheralList[i]) == "monitor" then
  124.             mon = peripheral.wrap(peripheralList[i])
  125.             TType = "TankInfo"
  126.         end
  127.        
  128.     end
  129. end
  130.  
  131. initPeripherals()
  132.  
  133. term.redirect(mon)
  134. mon.clear()
  135. mon.setTextScale(0.5)
  136. mon.setTextColor(colors.white)
  137. mon.setBackgroundColor(colors.black)
  138. mon.setCursorPos(1,1)
  139.  
  140. MRFLaser = LaserAmp.getEnergy()/2500000
  141.  
  142. if MRFLaser < 400  and ChargeOn == true then
  143.     ChargeStatus = "CHARGING"
  144.     ChargeOnOffcolor = colors.orange
  145.     ChargeTextcolor = colors.orange
  146. elseif MRFLaser < 400 and  ChargeOn == false then
  147.     ChargeStatus = "UNCHARGED"
  148.     ChargeOnOffcolor = colors.green
  149.     ChargeTextcolor = colors.red
  150. else
  151.     ChargeStatus = "CHARGED"
  152.     ChargeOnOffcolor = colors.gray
  153.     ChargeTextcolor = colors.green
  154. end
  155.  
  156. Power = FReactor.isIgnited()
  157.  
  158. function recalcInj()
  159.     InjRateMax = 98
  160.     FuelInjRate = FReactor.getInjectionRate()
  161. end
  162.  
  163. function clearTable()
  164.     button = {}
  165. end
  166.  
  167. -- All the things that make my buttons work
  168.  
  169. function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
  170.     button[name] = {}
  171.     button[name]["title"] = title
  172.     button[name]["func"] = func
  173.     button[name]["active"] = false
  174.     button[name]["xmin"] = xmin
  175.     button[name]["ymin"] = ymin
  176.     button[name]["xmax"] = xmax
  177.     button[name]["ymax"] = ymax
  178.     button[name]["color"] = color
  179.     button[name]["elem"] = elem
  180.     button[name]["elem2"] = elem2
  181. end
  182.  
  183. -- stuff and things for buttons
  184.  
  185. function fill(text, color, bData)
  186.    mon.setBackgroundColor(color)
  187.    mon.setTextColor(colors.white)
  188.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  189.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
  190.    for j = bData["ymin"], bData["ymax"] do
  191.       mon.setCursorPos(bData["xmin"], j)
  192.       if j == yspot then
  193.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
  194.             if k == xspot then
  195.                mon.write(bData["title"])
  196.             else
  197.                mon.write(" ")
  198.             end
  199.          end
  200.       else
  201.          for i = bData["xmin"], bData["xmax"] do
  202.             mon.write(" ")
  203.          end
  204.       end
  205.    end
  206.    mon.setBackgroundColor(colors.black)
  207. end
  208.  
  209. -- stuff and things for buttons
  210.  
  211. function screen()
  212.    local currColor
  213.    for name,data in pairs(button) do
  214.       local on = data["active"]
  215.       currColor = data["color"]
  216.       fill(name, currColor, data)
  217.    end
  218. end
  219.  
  220. -- stuff and things for buttons
  221.  
  222. function flash(name)
  223.     screen()
  224. end
  225.  
  226. -- magical handler for clicky clicks
  227.  
  228. function checkxy(x, y)
  229.    for name, data in pairs(button) do
  230.       if y>=data["ymin"] and  y <= data["ymax"] then
  231.          if x>=data["xmin"] and x<= data["xmax"] then
  232.             data["func"](data["elem"], data["elem2"])
  233.             flash(data['name'])
  234.             return true
  235.             --data["active"] = not data["active"]
  236.             --print(name)
  237.          end
  238.       end
  239.    end
  240.    return false
  241. end
  242.  
  243. -- Draw function : put's all the beautiful magic in the screen
  244.  
  245. function draw()
  246.  
  247.     for key,value in pairs(filleds) do
  248.         paintutils.drawFilledBox(value[1] , value[2], value[3], value[4], value[5])
  249.     end
  250.  
  251.     for key,value in pairs(boxes) do
  252.         paintutils.drawBox(value[1] , value[2], value[3], value[4], value[5])
  253.     end
  254.  
  255.     for key,value in pairs(lines) do
  256.         paintutils.drawLine(value[1] , value[2], value[3], value[4], value[5])
  257.     end
  258.  
  259.     for key,value in pairs(texts) do
  260.         mon.setCursorPos(value[1], value[2])
  261.         mon.setTextColor(value[4])
  262.         mon.setBackgroundColor(value[5])
  263.         mon.write(value[3])
  264.     end
  265.     screen()
  266.     resetDraw()
  267. end
  268.  
  269. -- Resets the elements to draw to only draw the neccessity
  270.  
  271. function resetDraw()
  272.     filleds = {}
  273.     boxes = {}
  274.     lines = {}
  275.     texts = {}
  276. end
  277.  
  278. -- Handles all the clicks for the buttons
  279.  
  280. function clickEvent()
  281.     local myEvent={os.pullEvent("monitor_touch")}
  282.     checkxy(myEvent[3], myEvent[4])
  283. end
  284.  
  285. -- Power up the reactor (M&N are a good source of food right?)
  286.  
  287. function powerUp(m,n)
  288.     if FReactor.isIgnited() == false then
  289.         Auto = true
  290.         ChargeOn = true
  291.         powerUpcolor = colors.green
  292.         calcLaserAmplifier()
  293.     else
  294.         powerUpcolor = colors.gray
  295.     end
  296. end
  297.  
  298. -- Turns Fusion-Reactor off
  299.  
  300. function powerDown(m,n)
  301.     Power = false
  302.     ChargeOn = false
  303.     Auto = false
  304.     rs.setBundledOutput("bottom", 0)
  305.     calcInjRate()
  306. end
  307.  
  308. function addDrawBoxes()
  309.     local w, h = mon.getSize()
  310.     Factor = math.floor((w/100)*2)
  311.    
  312.     GeneralBox["startX"] = 2
  313.     GeneralBox["startY"] = 3
  314.     GeneralBox["endX"] = ((w-(Factor*2))/3) - Factor
  315.     GeneralBox["endY"] = (((h - (Factor*2))/3 + 1)/4)*3
  316.     GeneralBox["height"] = GeneralBox["endY"] - GeneralBox["startY"] - (Factor*2) - 2
  317.     GeneralBox["width"] = GeneralBox["endX"] - GeneralBox["startX"] - (Factor*2) - 2
  318.     GeneralBox["inX"] = GeneralBox["startX"] + Factor + 1
  319.     GeneralBox["inY"] = GeneralBox["startY"] + Factor + 1
  320.    
  321.     table.insert(boxes, {GeneralBox["startX"] , GeneralBox["startY"], GeneralBox["endX"], GeneralBox["endY"], colors.gray})
  322.     name = "LASER"
  323.     table.insert(lines, {GeneralBox["startX"] + Factor , GeneralBox["startY"], GeneralBox["startX"] + (Factor*2) + #name+1, GeneralBox["startY"], colors.black})
  324.     table.insert(texts, {GeneralBox["startX"] + (Factor*2), GeneralBox["startY"], name, colors.white, colors.black})
  325.  
  326.     TankBox["startX"] = GeneralBox["startX"]
  327.     TankBox["startY"] = (h - Factor) - ((GeneralBox["endY"] - GeneralBox["startY"])/3)*2
  328.     TankBox["endX"] = GeneralBox["endX"]
  329.     TankBox["endY"] = h - 1
  330.     TankBox["height"] = TankBox["endY"] - TankBox["startY"] - (Factor*2) - 2
  331.     TankBox["width"] = TankBox["endX"] - TankBox["startX"] - (Factor*2) - 2
  332.     TankBox["inX"] = TankBox["startX"] + Factor + 1
  333.     TankBox["inY"] = TankBox["startY"] + Factor + 1
  334.    
  335.     table.insert(boxes, {TankBox["startX"] , TankBox["startY"], TankBox["endX"], TankBox["endY"], colors.gray})
  336.     name = "TANKS"
  337.     table.insert(lines, {TankBox["startX"] + Factor , TankBox["startY"], TankBox["startX"] + (Factor*2) + #name+1, TankBox["startY"], colors.black})
  338.     table.insert(texts, {TankBox["startX"] + (Factor*2), TankBox["startY"], name, colors.white, colors.black})
  339.  
  340.     ReactorBox["startX"] = GeneralBox["startX"]
  341.     ReactorBox["startY"] = GeneralBox["endY"] + Factor
  342.     ReactorBox["endX"] = GeneralBox["endX"]
  343.     ReactorBox["endY"] = TankBox["startY"] - Factor
  344.     ReactorBox["height"] = ReactorBox["endY"] - ReactorBox["startY"] - (Factor*2) - 2
  345.     ReactorBox["width"] = ReactorBox["endX"] - ReactorBox["startX"] - (Factor*2) - 2
  346.     ReactorBox["inX"] = ReactorBox["startX"] + Factor + 1
  347.     ReactorBox["inY"] = ReactorBox["startY"] + Factor + 1
  348.    
  349.     table.insert(boxes, {ReactorBox["startX"] , ReactorBox["startY"], ReactorBox["endX"], ReactorBox["endY"], colors.gray})
  350.     name = "REACTOR"
  351.     table.insert(lines, {ReactorBox["startX"] + Factor , ReactorBox["startY"], ReactorBox["startX"] + (Factor*2) + #name+1, ReactorBox["startY"], colors.black})
  352.     table.insert(texts, {ReactorBox["startX"] + (Factor*2), ReactorBox["startY"], name, colors.white, colors.black})
  353.    
  354.     GraphicBox["startX"] = GeneralBox["endX"] + Factor
  355.     GraphicBox["startY"] = GeneralBox["startY"]
  356.     GraphicBox["endX"] = w - 2
  357.     GraphicBox["endY"] = TankBox["endY"]
  358.     GraphicBox["height"] = GraphicBox["endY"]-GraphicBox["startY"] - (Factor*2) - 2
  359.     GraphicBox["width"] = GraphicBox["endX"]-GraphicBox["startX"] - (Factor*2) - 2
  360.     GraphicBox["inX"] = GraphicBox["startX"] + Factor
  361.     GraphicBox["inY"] = GraphicBox["startY"] + 2
  362.     GraphicBox["sectionHeight"] = math.floor(GraphicBox["height"]/6)
  363.    
  364.     table.insert(boxes, {GraphicBox["startX"] , GraphicBox["startY"], GraphicBox["endX"], GraphicBox["endY"], colors.gray})
  365.     name = "GRAPHICS/BUTTONS"
  366.     table.insert(lines, {GraphicBox["startX"] + Factor , GraphicBox["startY"], GraphicBox["startX"] + (Factor*2) + #name+1, GraphicBox["startY"], colors.black})
  367.     table.insert(texts, {GraphicBox["startX"] + (Factor*2), GraphicBox["startY"], name, colors.white, colors.black})
  368.  
  369.     name = "FUSION-PLANT"
  370.     table.insert(texts, {(w/2)-(#name/2), 1, name, colors.white, colors.black})
  371.    
  372.     local names = {}
  373.     names[1] = "CHARGE LEVEL"
  374.     names[2] = "INJECTION RATE"
  375.     names[3] = "ENERGY STORED"
  376.  
  377.     for i=1,5,1 do
  378.         table.insert(texts, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 1, names[i], colors.white, colors.black})
  379.         table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  380.     end
  381.  
  382.     refresh = true
  383.     while refresh do
  384.          recalcInj()
  385.         if FReactor.isIgnited() == false then
  386.             powerUpcolor = colors.green
  387.             FireUpcolor = colors.green
  388.             ReactorStatus = "OFFLINE"
  389.             RectorTextcolor = colors.red
  390.         else   
  391.             powerUpcolor = colors.gray
  392.             FireUpcolor = colors.gray
  393.             ReactorStatus = "ONLINE"
  394.             RectorTextcolor = colors.green
  395.         end
  396.  
  397.         setButton("CHARG","CHARGE", ChargeOnOff, GraphicBox["inX"] + Factor, GraphicBox["inY"] + 1, GraphicBox["inX"] + (GraphicBox["width"]/4 - 1), GraphicBox["inY"] + 3, 0, 0, ChargeOnOffcolor)
  398.         setButton("START INJ","START INJ", FireUp, GraphicBox["inX"] + (GraphicBox["width"]/4 + Factor - 1), GraphicBox["inY"] + 1, GraphicBox["inX"] + ((GraphicBox["width"]/4)*2 - 1) , GraphicBox["inY"] + 3,0, 0, FireUpcolor)
  399.         setButton("AUTO-CHARGE","AUTO-CHARGE", powerUp, GraphicBox["inX"] + ((GraphicBox["width"]/4)*2 + Factor - 1), GraphicBox["inY"] + 1, GraphicBox["inX"] + ((GraphicBox["width"]/4)*3 - 1), GraphicBox["inY"] + 3,0, 0, powerUpcolor)
  400.         setButton("SHUT-DOWN","SHUT-DOWN", powerDown, GraphicBox["inX"] + ((GraphicBox["width"]/4)*3 + Factor - 1), GraphicBox["inY"] + 1, GraphicBox["inX"] + (GraphicBox["width"] - 1), GraphicBox["inY"] + 3,0, 0, colors.red)
  401.    
  402.         if FireUpOK == true then
  403.             sleep(10)
  404.             rs.setBundledOutput("bottom",colors.subtract(rs.getBundledOutput("bottom"), colors.yellow))
  405.             if FReactor.isIgnited() == false then
  406.                 rs.setBundledOutput("bottom", colors.red, 1)
  407.                 sleep(1)
  408.                 rs.setBundledOutput("bottom", 0, colors.red)
  409.             end
  410.             FireUpOK = false
  411.         end
  412.        
  413.         if (FirstProcent < 25 and FirstProcent >= MinProcenttoBoost) or (SecondProcent < 25 and SecondProcent >= MinProcenttoBoost) then
  414.             for w = 0, 0 do
  415.                 TankLevel = false
  416.                 TankLevel1 = false
  417.                 TankLevel2 = true
  418.             end
  419.         elseif (FirstProcent >= 25 and FirstProcent <= 75) or (SecondProcent >= 25 and SecondProcent <= 75) then
  420.             for w = 0, 0 do
  421.                 TankLevel = false
  422.                 TankLevel1 = true
  423.                 TankLevel2 = false
  424.             end
  425.         elseif (FirstProcent > 75 and SecondProcent > 75) then
  426.             for w = 0, 0 do
  427.                 TankLevel = true
  428.                 TankLevel1 = false
  429.                 TankLevel2 = false
  430.             end
  431.         elseif (FirstProcent < MinProcenttoBoost or SecondProcent < MinProcenttoBoost) then
  432.             for w = 0, 0 do
  433.                 TankLevel = false
  434.                 TankLevel1 = false
  435.                 TankLevel2 = false
  436.             end
  437.         end
  438.         parallel.waitForAny(refreshStats, loop, clickEvent)
  439.     end
  440.    
  441. end
  442.  
  443. function loop()
  444.     while true do
  445.         calcInjRate()  
  446.     end
  447. end
  448. function refreshStats()
  449.     calcInjRate()
  450.     calcLaserAmplifier()
  451.  
  452. -- Laser Visualisierung
  453.  
  454.     local i = 1
  455.    
  456.     local infotoAdd = "STATUS: "
  457.     local infotoAdd1 = "CHARGE-LEVEL: "
  458.    
  459.     if currentChargeLevel ~= MRFLaser then
  460.         currentChargeLevel = MRFLaser
  461.        
  462.         if MRFLaser > 400 then
  463.             MRFLaserT = 400
  464.         else
  465.             MRFLaserT = MRFLaser
  466.         end
  467.  
  468.         MRFLaserText = math.floor((MRFLaserT/400)*100)
  469.  
  470.         table.insert(lines, {GeneralBox["inX"] , GeneralBox["inY"],GeneralBox["inX"] + GeneralBox["width"] , GeneralBox["inY"], colors.black})
  471.         table.insert(texts, {GeneralBox["inX"] + 1, GeneralBox["inY"] - 1, infotoAdd, colors.white, colors.black})
  472.         table.insert(texts, {GeneralBox["inX"] + 1 + #infotoAdd, GeneralBox["inY"] - 1, ChargeStatus .. "   ", ChargeTextcolor, colors.black})
  473.         table.insert(texts, {GeneralBox["inX"] + 1 , GeneralBox["inY"] + Factor - 1, infotoAdd1 .. MRFLaserText .. "%   ", colors.white, colors.black})
  474.         table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) + i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  475.  
  476.         width = math.floor((GraphicBox["width"] / 400)*MRFLaserT)
  477.         table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + width - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.green})
  478.  
  479.     end
  480.  
  481. -- Reactor Visualisierung
  482.  
  483.     local i = 2
  484.    
  485.     local infotoAdd = "STATUS: "
  486.     local infotoAdd1 = "INJ-RATE: "
  487.     local infotoAdd2 = "PLASMA-HEAT: "
  488.     local infotoAdd3 = "CASE-HEAT: "
  489.     local infotoAdd4 = "ENERGY/T: "
  490.     local infotoAdd5 = "ENERGYSTORAGE: "
  491.     local infotoAdd6 = "WATER: "
  492.     local infotoAdd7 = "STEAM: "
  493.    
  494.     if InjRateText > (xRC*256+98) then
  495.         InjRateT = (xRC*256+98)
  496.     else
  497.         InjRateT = InjRateText
  498.     end
  499.  
  500.     table.insert(lines, {ReactorBox["inX"] , ReactorBox["inY"],ReactorBox["inX"] + ReactorBox["width"] , ReactorBox["inY"], colors.black})
  501.     table.insert(texts, {ReactorBox["inX"] + 1, ReactorBox["inY"] - 1, infotoAdd, colors.white, colors.black})
  502.     table.insert(texts, {ReactorBox["inX"] + 1 + #infotoAdd, ReactorBox["inY"] - 1, ReactorStatus .. " ", RectorTextcolor, colors.black})
  503.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + Factor - 1, infotoAdd1 .. InjRateT .. "    ", colors.white, colors.black})
  504.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 2*Factor - 1, infotoAdd2 .. PlasmaHeat .. " GK ", colors.white, colors.black})
  505.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 3*Factor - 1, infotoAdd3 .. CaseHeat .. " GK ", colors.white, colors.black})
  506.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 4*Factor - 1, infotoAdd4 .. RFOutputT .. " MRF/t   ", colors.white, colors.black})
  507.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 5*Factor - 1, infotoAdd5 .. RFStoragePercent .. "%  ", colors.white, colors.black})
  508.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 6*Factor - 1, infotoAdd6 .. "--- ", colors.white, colors.black})
  509.     table.insert(texts, {ReactorBox["inX"] + 1 , ReactorBox["inY"] + 7*Factor - 1, infotoAdd7 .. "--- ", colors.white, colors.black})
  510.    
  511.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  512.     width = math.floor((GraphicBox["width"] / InjRateMax)*InjRateT)
  513.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + width - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.green})
  514.  
  515.     local i = 3
  516.  
  517.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  518.     width = math.floor(GraphicBox["width"]*(RFStoragePercent/100))
  519.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + width - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.green})
  520.  
  521. -- Tank Visualisierung 
  522.    
  523.     local i = 4
  524.    
  525.     local infotoAdd = " : "
  526.  
  527.     table.insert(lines, {TankBox["inX"] , TankBox["inY"],TankBox["inX"] + TankBox["width"] , TankBox["inY"], colors.black})
  528.     table.insert(texts, {TankBox["inX"] + 1, TankBox["inY"] - 1, FirstTankText .. infotoAdd .. FirstProcent .."% ", colors.white, colors.black})
  529.     table.insert(texts, {TankBox["inX"] + 1, TankBox["inY"] + Factor - 1, SecondTankText .. infotoAdd .. SecondProcent .. "% ", colors.white, colors.black})
  530.    
  531.     table.insert(texts, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 1, FirstTankName, colors.white, colors.black})
  532.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  533.     width = math.floor(GraphicBox["width"]*(FirstProcent/100))
  534.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + width - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, FirstTankcolor})
  535.    
  536.     local i = 5
  537.    
  538.     table.insert(texts, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 1, SecondTankName, colors.white, colors.black})
  539.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + GraphicBox["width"] - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, colors.lightGray})
  540.     width = math.floor(GraphicBox["width"]*(SecondProcent/100))
  541.     table.insert(filleds, {GraphicBox["inX"] + Factor, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*i) +i + 2, GraphicBox["inX"] + width - 1, GraphicBox["inY"] + (GraphicBox["sectionHeight"]*(i+1)) +i, SecondTankcolor})
  542.    
  543.     draw()
  544.     sleep(1)
  545. end
  546.  
  547. -- Calcs and Sets Inj Rate
  548.  
  549. function calcInjRate()
  550.     recalcInj()
  551.     calcMRFProduce()
  552.     calcTankStats()
  553.     if(Power == true) then
  554.         InjRate = 2
  555.         FuelInjRate = 2
  556.         InjRateMax = 98
  557.     else
  558.         FuelInjRate = 0
  559.     end
  560.  
  561.     InjRateText = FuelInjRate
  562.     FReactor.setInjectionRate(FuelInjRate)
  563.     RFOutputT = round((FReactor.getProducing()/2500000), 1)
  564.     PlasmaHeat = round((FReactor.getPlasmaHeat()/1000000000), 1)
  565.     CaseHeat = round((FReactor.getCaseHeat()/1000000000), 1)
  566.     sleep(1)
  567. end
  568.  
  569. -- Calcs MRFProduce
  570.  
  571. function calcMRFProduce()
  572.     if EType == "mekanism" then
  573.         local MRFNeed = RFStorage.getOutput()/2500000
  574.         RFStoraged = RFStorage.getEnergy()/2500000
  575.         RFMaxStorage = RFStorage.getMaxEnergy()/2500000
  576.         RFStoragePercent =  math.floor(RFStoraged / RFMaxStorage * 100)
  577.         if RFStoragePercent > MinProcentforLowMode then
  578.             MRFProduce = MRFNeed + MRFBuffer                                                -- LowRF Mode but everytime over RFOutput
  579.         else
  580.             MRFProduce = RFMaxStorage                                                       -- MaxRF Mode
  581.         end
  582.     end
  583.     if EType == "mekanismIM" then
  584.         local MRFNeed = RFStorage.getOutput()/2500000
  585.         RFStoraged = RFStorage.getEnergy()/2500000
  586.         RFMaxStorage = RFStorage.getMaxEnergy()/2500000
  587.         RFMaxTransfer = RFStorage.getTransferCap()/2500000
  588.         RFStoragePercent =  math.floor(RFStoraged / RFMaxStorage * 100)
  589.         if RFStoragePercent > MinProcentforLowMode then
  590.             MRFProduce = MRFNeed + MRFBuffer                                                -- LowRF Mode but everytime over RFOutput
  591.         else
  592.             MRFProduce = RFMaxTransfer                                                      -- MaxRF Mode
  593.         end
  594.     end
  595. end
  596.  
  597. -- Stats of Tanks
  598.  
  599. function calcTankStats()
  600.     FirstTankText ="NO FLUID     "
  601.     FirstTankName = "NO FLUID         "
  602.     FirstTankLiquid = "NO FLUID     "
  603.     FirstAmount = 0
  604.     FirstProcent = 0
  605.     FirstTankcolor = colors.lightGray
  606.  
  607.     SecondTankText ="NO FLUID     "
  608.     SecondTankName = "NO FLUID         "
  609.     SecondTankLiquid = "NO FLUID     "
  610.     SecondAmount = 0
  611.     SecondProcent = 0
  612.     SecondTankcolor = colors.lightGray
  613. end
  614.  
  615. -- Laser Amplifier
  616.  
  617. function calcLaserAmplifier()                                                              
  618.     MRFMaxLaser = LaserAmp.getMaxEnergy()/2500000
  619.     MRFLaser = LaserAmp.getEnergy()/2500000
  620.     if MRFLaser < 400  and ChargeOn == true then
  621.         Charge = 10000000
  622.         ChargeStatus = "CHARGING"
  623.         ChargeOnOffcolor = colors.orange
  624.         ChargeTextcolor = colors.orange
  625.     elseif MRFLaser < 400 and  ChargeOn == false then
  626.         Charge = 0
  627.         ChargeStatus = "UNCHARGED"
  628.         ChargeOnOffcolor = colors.green
  629.         ChargeTextcolor = colors.red
  630.     else
  631.         Charge = 0
  632.         ChargeStatus = "CHARGED"
  633.         ChargeOnOffcolor = colors.gray
  634.         ChargeTextcolor = colors.green
  635.     end
  636.     if MRFLaser < 400 then
  637.         rs.setBundledOutput("bottom",colors.combine(rs.getBundledOutput("bottom"), colors.black))
  638.     end
  639.     if MRFLaser >= 400 then
  640.         if Auto == true then
  641.             FReactor.setInjectionRate(2)
  642.             FireUp()
  643.         end
  644.     end
  645. end
  646.  
  647. -- Alarm + Hohlraum insert 
  648.  
  649. function FireUp()
  650.     if FReactor.isIgnited() == false then
  651.         Auto = false
  652.         Power = true
  653.         FireUpOK = true
  654.         rs.setBundledOutput("bottom",colors.combine(rs.getBundledOutput("bottom"), colors.yellow))                                             
  655.         FireUpcolor = colors.green
  656.         calcInjRate()
  657.     else
  658.         FireUpcolor = colors.gray
  659.     end
  660. end
  661.  
  662. function ChargeOnOff()
  663.     ChargeOn = true
  664.     calcLaserAmplifier()
  665. end
  666.  
  667.  
  668.  
  669.  
  670. --============================================================
  671. -- add comma to separate thousands
  672. -- From Lua-users.org/wiki/FormattingNumbers
  673. --
  674. --
  675. function comma_value(amount)
  676.   local formatted = amount
  677.   while true do
  678.     formatted, zz = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  679.     if (zz==0) then
  680.       break
  681.     end
  682.   end
  683.   return formatted
  684. end
  685.  
  686. ---============================================================
  687. -- rounds a number to the nearest decimal places
  688. -- From Lua-users.org/wiki/FormattingNumbers
  689. --
  690. --
  691. function round(val, decimal)
  692.   if (decimal) then
  693.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  694.   else
  695.     return math.floor(val+0.5)
  696.   end
  697. end
  698.  
  699. --===================================================================
  700. -- given a numeric value formats output with comma to separate thousands
  701. -- and rounded to given decimal places
  702. -- From Lua-users.org/wiki/FormattingNumbers
  703. --
  704. function format_num(amount, decimal, prefix, neg_prefix)
  705.   local str_amount,  formatted, famount, remain
  706.  
  707.   decimal = decimal or 2  -- default 2 decimal places
  708.   neg_prefix = neg_prefix or "-" -- default negative sign
  709.  
  710.   famount = math.abs(round(amount,decimal))
  711.   famount = math.floor(famount)
  712.  
  713.   remain = round(math.abs(amount) - famount, decimal)
  714.  
  715.         -- comma to separate the thousands
  716.   formatted = comma_value(famount)
  717.  
  718.         -- attach the decimal portion
  719.   if (decimal > 0) then
  720.     remain = string.sub(tostring(remain),3)
  721.     formatted = formatted .. "." .. remain ..
  722.                 string.rep("0", decimal - string.len(remain))
  723.   end
  724.  
  725.         -- attach prefix string e.g '$'
  726.   formatted = (prefix or "") .. formatted
  727.  
  728.         -- if value is negative then format accordingly
  729.   if (amount<0) then
  730.     if (neg_prefix=="()") then
  731.       formatted = "("..formatted ..")"
  732.     else
  733.       formatted = neg_prefix .. formatted
  734.     end
  735.   end
  736.  
  737.   return formatted
  738. end
  739.  
  740. addDrawBoxes()
Add Comment
Please, Sign In to add comment