Advertisement
MrFreeZX

Modified mekanism fusion reactor controller without Tank

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