Advertisement
Guest User

Untitled

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