bobmarley12345

Mekanism Fusion-Reactor-Control-Program

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