Advertisement
fatboychummy

Fixed(?) draconic reactors program

Jul 13th, 2024 (edited)
1,787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.35 KB | None | 0 0
  1. --peripheral config
  2. local sideGateOut = "top"
  3. local sideGateIn = "networked_name"
  4.  
  5. --output multiplier: set by modpack (default = 1.0), change this to the value of draconic evolution config (!!!not tested yet!!!)
  6. local outputMultiplier = 1.0
  7.  
  8. local reactornumber = "1"
  9.  
  10. local tempPinpoint = 0
  11.  
  12. --Do not change anything below
  13.  
  14. --originally made by electronx3
  15. --modified by jona23 to work in 1.16+
  16.  
  17. --constants
  18. local val_1div3 = 1.0/3.0
  19.  
  20. --config
  21.  
  22. --emergency shutdown parameters
  23. local maxOvershoot = 200.0      --reactor will shutdown when temperature gets hotter than defaultTemp+maxOvershoot
  24. local minFuel = 0.05
  25.  
  26. --default parameters
  27. local defaultTemp = 8000.0
  28. local defaultField = 0.09
  29. local restartFix = 100
  30.  
  31.  
  32. local maxTempInc = 400.0        --max. temperature increase per computer tick
  33. local maxOutflow = 30000000.0
  34.  
  35. local chargeInflow = 20000000
  36. local shutDownField = 0.1       --field strength while shutdown
  37.  
  38. local safeMode = true           --when set to false, the automatic emergency shutdown function is disabled
  39.  
  40.  
  41. --peripherals
  42. local reactor
  43. local gateIn
  44. local gateOut
  45. local mon
  46.  
  47. --info
  48. local info
  49.  
  50. local currentEmergency = false
  51. local currentField
  52. local currentFuel
  53.  
  54. local stableTicks = 0
  55. local screenPage = 0
  56. local openConfirmDialog = false
  57.  
  58. local manualStart = false
  59. local manualCharge = false
  60. local manualStop = false
  61.  
  62.  
  63. --the program
  64. function updateInfo()
  65.     info = reactor.getReactorInfo()
  66.    
  67.     if info == nil or info == null then
  68.         gClear()
  69.         gWrite("System Crash!", 1, 1, colors.white, colors.blue)
  70.         gWrite("CODE: invalid_core_setup", 1, 2, colors.white, colors.blue)
  71.       error("Reactor has an invalid setup")
  72.     end
  73.    
  74.     currentField = info.fieldStrength / info.maxFieldStrength
  75.     currentFuel = 1.0 - (info.fuelConversion / info.maxFuelConversion)
  76. end
  77.  
  78. function isEmergency()
  79.     currentEmergency = safeMode and not (info.temperature < 2000.0) and (info.status == "running" or info.status == "online" or info.status == "stopping") and (info.temperature > defaultTemp + maxOvershoot or currentField < 0.004 or currentFuel < minFuel)
  80.     return currentEmergency
  81. end
  82.  
  83. function calcInflow(targetStrength, fieldDrainRate)
  84.     return fieldDrainRate / (1.0 - targetStrength)
  85. end
  86.  
  87. --creators of the setupPeripherals function: https://github.com/acidjazz/drmon/blob/master/drmon.lua
  88. function setupPeripherals()
  89.     local tmpMon = periphSearch("monitor")
  90.     if tmpMon == null then
  91.         mon = null
  92.         print("WARN: No valid monitor was found!")
  93.  
  94.     else
  95.         monX, monY = tmpMon.getSize()
  96.         mon = {}
  97.         mon.monitor, mon.x, mon.y = tmpMon, monX, monY
  98.     end
  99.  
  100.     print("Setup peripherals...")
  101.     reactor = periphSearch("draconic_reactor")
  102.     gateIn = peripheral.wrap(sideGateIn)
  103.     gateOut = peripheral.wrap(sideGateOut)
  104.    
  105.     if reactor == null then
  106.         gClear()
  107.         gWrite("System Crash!", 1, 1, colors.white, colors.blue)
  108.         gWrite("CODE: no_valid_core_found", 1, 2, colors.white, colors.blue)
  109.         error("No valid reactor was found!")
  110.     end
  111.     if gateIn == null then
  112.         gClear()
  113.         gWrite("System Crash!", 1, 1, colors.white, colors.blue)
  114.         gWrite("CODE: no_valid_input_gate", 1, 2, colors.white, colors.blue)
  115.         error("No valid input fluxgate was found!")
  116.     end  
  117.     if gateOut == null then
  118.         gClear()
  119.         gWrite("System Crash!", 1, 1, colors.white, colors.blue)
  120.         gWrite("CODE: no_valid_output_gate", 1, 2, colors.white, colors.blue)
  121.         error("No valid output fluxgate was found!")
  122.     end
  123.    
  124.     gateIn.setOverrideEnabled(true)
  125.     gateIn.setFlowOverride(0)
  126.     gateOut.setOverrideEnabled(true)
  127.     gateOut.setFlowOverride(0)
  128.    
  129.     print("Done!")
  130. end
  131.  
  132. function periphSearch(type)
  133.     local names = peripheral.getNames()
  134.     local i, name
  135.     for i, name in pairs(names) do
  136.         if peripheral.getType(name) == type then
  137.             return peripheral.wrap(name)
  138.         end
  139.     end
  140.     return null
  141. end
  142.  
  143. function clickListener()
  144.     if mon == null then
  145.         return
  146.     end
  147.    
  148.     while true do
  149.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  150.        
  151.         local cFlow = 0 --remove local later
  152.        
  153.         if yPos == mon.y and xPos >= 1 and xPos <= 4 then
  154.             openConfirmDialog = false
  155.             screenPage = (screenPage + 1) % 2
  156.         elseif screenPage == 1 then        
  157.             if yPos == 8 then
  158.                 local tmpTemp = defaultTemp
  159.            
  160.                 if xPos >= 2 and xPos <= 3 then
  161.                     tmpTemp = tmpTemp - 1.0
  162.                 elseif xPos >= 5 and xPos <= 6 then
  163.                     tmpTemp = tmpTemp - 10.0
  164.                 elseif xPos >= 9 and xPos <= 11 then
  165.                     tmpTemp = tmpTemp - 100.0
  166.                 elseif xPos >= 14 and xPos <= 16 then
  167.                     tmpTemp = 8000.0
  168.                 elseif xPos >= 19 and xPos <= 21 then
  169.                     tmpTemp = tmpTemp + 100.0
  170.                 elseif xPos >= 24 and xPos <= 25 then
  171.                     tmpTemp = tmpTemp + 10.0
  172.                 elseif xPos >= 27 and xPos <= 28 then
  173.                     tmpTemp = tmpTemp + 1.0
  174.                 end
  175.                
  176.                 if tmpTemp < 20.0 then
  177.                     tmpTemp = 20.0
  178.                 elseif tmpTemp > 20000.0 then
  179.                     tmpTemp = 20000.0
  180.                 end
  181.                
  182.                 defaultTemp = tmpTemp
  183.                 --print("new default temperature: " .. math.floor(defaultTemp) .. "°C")
  184.             elseif yPos == 12 then
  185.                 local tmpField = defaultField
  186.                
  187.                 if xPos >= 2 and xPos <= 3 then
  188.                     tmpField = tmpField - 0.001
  189.                 elseif xPos >= 5 and xPos <= 6 then
  190.                     tmpField = tmpField - 0.01
  191.                 elseif xPos >= 9 and xPos <= 11 then
  192.                     tmpField = tmpField - 0.1
  193.                 elseif xPos >= 14 and xPos <= 16 then
  194.                     tmpField = 0.01
  195.                 elseif xPos >= 19 and xPos <= 21 then
  196.                     tmpField = tmpField + 0.1
  197.                 elseif xPos >= 24 and xPos <= 25 then
  198.                     tmpField = tmpField + 0.01
  199.                 elseif xPos >= 27 and xPos <= 28 then
  200.                     tmpField = tmpField + 0.001
  201.                 end
  202.                
  203.  
  204.                 if safeMode then
  205.                 if tmpField < 0.005 then
  206.                     tmpField = 0.005
  207.                 elseif tmpField > 0.6 then
  208.                     tmpField = 0.6
  209.                 end
  210.                 else
  211.                 if tmpField < 0.0001 then
  212.                     tmpField = 0.0001
  213.                 elseif tmpField > 0.6 then
  214.                     tmpField = 0.6
  215.                 end
  216.                 end
  217.                
  218.                 defaultField = tmpField
  219.                 --print("new default field strength: " .. math.floor(defaultField*1000.0)/10.0 .. "%")
  220.             elseif yPos == 15 then              
  221.                 if openConfirmDialog then
  222.                     if xPos >= 25 and xPos <= 28 then
  223.                         openConfirmDialog = false
  224.                     elseif xPos >= 16 and xPos <= 22 then
  225.                         openConfirmDialog = false
  226.                         safeMode = false
  227.                         --print("WARN: Safe mode deactivated!")
  228.                     end
  229.                 elseif xPos >= 26 and xPos <= 28 then
  230.                     if safeMode then
  231.                         openConfirmDialog = true
  232.                     else
  233.                         safeMode = true
  234.                         --print("Safe mode activated!")
  235.                     end
  236.                 end
  237.             elseif yPos == 17 and info ~= null then
  238.                 if not currentEmergency then
  239.                     if (info.status == "running" or info.status == "online") and xPos >= 2 and xPos <= 5 then
  240.                         manualStop = true
  241.                     elseif (info.status == "cold" or info.status == "offline" or info.status == "cooling") and xPos >= 2 and xPos <= 7 then
  242.                         manualCharge = true
  243.                     elseif (info.status == "stopping" or info.status == "warming_up" or info.status == "charged") and xPos >= 2 and xPos <= 6 then
  244.                         manualStart = true
  245.                     elseif info.status == "warming_up" and xPos >= 9 and xPos <= 12 then
  246.                         manualStop = true
  247.                     end
  248.                 end
  249.                 if info.temperature < 2000.0 and xPos >= 26 and xPos <= 28 then
  250.                     print("Program stopped!")
  251.                     return
  252.                 end
  253.             end
  254.         end
  255.         saveConfig()
  256.     end
  257. end
  258.  
  259. --graphic stuff: inspired by https://github.com/acidjazz/drmon/blob/master/drmon.lua
  260. function gClear()
  261.   mon.monitor.setBackgroundColor(colors.black)
  262.   mon.monitor.clear()
  263.   mon.monitor.setCursorPos(1,1)
  264. end
  265. function gWrite(text, x, y, cl, clBg)
  266.     mon.monitor.setCursorPos(x, y)
  267.     mon.monitor.setTextColor(cl)
  268.     mon.monitor.setBackgroundColor(clBg)
  269.     mon.monitor.write(text)
  270. end
  271. function gWriteR(text, x, y, cl, clBg)
  272.     gWrite(text, mon.x - string.len(tostring(text)) - x, y, cl, clBg)
  273. end
  274. function gWriteLR(textL, textR, xL, xR, y, clL, clR, clBg)
  275.     gWrite(textL, xL, y, clL, clBg)
  276.     gWriteR(textR, xR, y, clR, clBg)
  277. end
  278. function gDrawLine(x, y, length, cl)
  279.     if length < 0 then
  280.         return
  281.     end
  282.     mon.monitor.setCursorPos(x, y)
  283.     mon.monitor.setBackgroundColor(cl)
  284.     mon.monitor.write(string.rep(" ", length))
  285. end
  286. function gDrawProgressBar(x, y, length, proportion, cl, clBg)
  287.     if proportion < 0.0 or proportion > 1.0 then
  288.         gDrawLine(x, y, length, cl)
  289.     else
  290.         gDrawLine(x, y, length, clBg)
  291.         gDrawLine(x, y, math.floor(proportion*length), cl)
  292.     end
  293. end
  294. function gDrawStandardProgressBar(y, proportion, cl)
  295.     gDrawProgressBar(2, y, mon.x-2, proportion, cl, colors.gray)
  296. end
  297.  
  298.  
  299. function update()
  300.     local newInflow = 0.0
  301.     local newOutflow = 0.0  
  302.    
  303.     while true do  
  304.         updateInfo()        
  305.         local isStable = true
  306.         local tmpShutDownField = math.max(shutDownField, defaultField)
  307.    
  308.         if peripheral.wrap(sideGateOut) == null then
  309.             reactor.stopReactor()
  310.             newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  311.             gClear()
  312.             gWrite("System Crash!", 1, 1, colors.white, colors.blue)
  313.             gWrite("CODE: output_gate_missing", 1, 2, colors.white, colors.blue)
  314.             error("Output gate missing!")
  315.         end
  316.        
  317.         if manualStop then
  318.             manualStart = false
  319.             manualStop = false
  320.             manualCharge = false
  321.             reactor.stopReactor()
  322.         end
  323.        
  324.         if isEmergency() == true then
  325.             reactor.stopReactor()
  326.             newInflow = calcInflow(0.8, info.fieldDrainRate)
  327.             newOutflow = 0.0
  328.             manualStart = false
  329.             manualCharge = false
  330.         elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  331.             newInflow = 0.0
  332.             newOutflow = 0.0
  333.             if manualCharge then
  334.                 manualStart = false
  335.                 manualCharge = false
  336.                 reactor.chargeReactor()
  337.             end
  338.         elseif info.status == "charging" then
  339.             newInflow = chargeInflow
  340.             newOutflow = 0.0
  341.             manualStart = false
  342.             manualCharge = false
  343.         elseif info.status == "warming_up" or info.status == "charged" then
  344.             newInflow = chargeInflow
  345.             newOutflow = 0.0
  346.             if manualStart then
  347.                 manualStart = false
  348.                 manualCharge = false
  349.                 reactor.activateReactor()
  350.             end
  351.         elseif info.status == "running" or info.status == "online" then
  352.             manualStart = false
  353.             manualCharge = false
  354.             local temp = info.temperature
  355.            
  356.             if defaultTemp < info.temperature then
  357.             if tempPinpoint < 10 then
  358.             tempPinpoint = tempPinpoint - 0.01
  359.             end
  360.             end
  361.  
  362.             if defaultTemp > info.temperature then
  363.             if tempPinpoint > -10 then
  364.             tempPinpoint = tempPinpoint + 0.01
  365.             end
  366.             end
  367.            
  368.             defaultTemp = defaultTemp + tempPinpoint
  369.  
  370.             if temp > defaultTemp - 6.0 and temp < defaultTemp + 5.0 then
  371.                 stableTicks = stableTicks + 1
  372.                 if stableTicks > 100 then
  373.                     isStable = true
  374.                 end
  375.             else
  376.                 stableTicks = 0
  377.             end
  378.        
  379.             if temp < defaultTemp then              
  380.                 local tempInc
  381.                 if temp < defaultTemp - 50.0 then
  382.                     tempInc = math.sqrt(defaultTemp - temp)
  383.                 elseif temp < defaultTemp - 0.5 then
  384.                     tempInc = math.sqrt(defaultTemp - temp)/2.0
  385.                 end
  386.            
  387.                 if tempInc == nil or tempInc < 0.0 then
  388.                     tempInc = 0
  389.                 elseif tempInc > maxTempInc then
  390.                     tempInc = maxTempInc
  391.                 end
  392.  
  393.                
  394.                 local t50 = temp/200.0
  395.                 local convLvl = (info.fuelConversion / info.maxFuelConversion)*1.3 - 0.3
  396.                
  397.                 local y = (t50^4)/(100.0-t50)*(1-convLvl) + 1000.0*(tempInc-convLvl) - 444.7
  398.                 local dSqrt = math.sqrt((50.0*y)^2 + (y/3.0)^3)
  399.                
  400.                 local x            
  401.                 local tmpValRoot = dSqrt - 50.0*y
  402.                 if tmpValRoot > 0.0 then
  403.                     x = math.pow(dSqrt + 50.0*y, val_1div3) - math.pow(tmpValRoot, val_1div3)
  404.                 else
  405.                     x = math.pow(dSqrt + 50.0*y, val_1div3) + math.pow(0.0-tmpValRoot, val_1div3)
  406.                 end
  407.                
  408.                 newOutflow = info.maxEnergySaturation*x/99.0 + info.energySaturation - info.maxEnergySaturation
  409.                 if newOutflow > maxOutflow then
  410.                     newOutflow = maxOutflow
  411.                 end
  412.             else
  413.                 newOutflow = 0.0
  414.             end
  415.        
  416.             if isStable == true then
  417.                 if currentField > defaultField + 0.05 then
  418.                     newInflow = 0.0
  419.                 elseif currentField > defaultField*1.2 then
  420.                     newInflow = calcInflow(defaultField*0.98, info.fieldDrainRate)
  421.                 elseif currentField > defaultField*0.97 then
  422.                     newInflow = calcInflow(defaultField, info.fieldDrainRate)
  423.                 else
  424.                     newInflow = calcInflow(defaultField*1.5, info.fieldDrainRate)
  425.                 end
  426.             else
  427.                 if currentField > tmpShutDownField then
  428.                     newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  429.                 else
  430.                     newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  431.                 end
  432.             end
  433.             defaultTemp = defaultTemp - tempPinpoint
  434.  
  435.         elseif info.status == "stopping" then
  436.             if currentField > tmpShutDownField then
  437.                 newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  438.             else
  439.                 newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  440.             end
  441.             newOutflow = 0.0
  442.            
  443.             if manualStart then
  444.                 manualStart = false
  445.                 manualCharge = false
  446.                 reactor.activateReactor()
  447.             end
  448.         end
  449.        
  450.         if newInflow < 0.0 then
  451.             newInflow = 0.0
  452.         end
  453.         if newOutflow < 0.0 then
  454.             newOutflow = 0.0
  455.         end
  456.        
  457.         if newInflow > 0.0 then
  458.             newInflow = math.floor(newInflow)
  459.         else
  460.             newInflow = 0
  461.         end
  462.         local outflowMultiplied = 0
  463.         if newOutflow > 0.0 then
  464.             outflowMultiplied = math.floor(newOutflow*outputMultiplier)
  465.         else
  466.             newOutflow = 0.0
  467.         end
  468.         if restartFix > 0 then
  469.             outflowMultiplied = 0.0
  470.             newInflow = 10000000.0
  471.             restartFix = restartFix - 1.0
  472.         end
  473.         gateIn.setFlowOverride(newInflow)
  474.         gateOut.setFlowOverride(outflowMultiplied)
  475.        
  476.        
  477.         if mon ~= null then
  478.             gClear()
  479.            
  480.             if screenPage == 0 then
  481.                 local clTemp
  482.                 if info.temperature < defaultTemp*0.95 then
  483.                     clTemp = colors.green
  484.                 elseif info.temperature < defaultTemp + 1.0 then
  485.                     clTemp = colors.yellow
  486.                 elseif info.temperature < defaultTemp + maxOvershoot then
  487.                     clTemp = colors.orange
  488.                 else
  489.                     clTemp = colors.red
  490.                 end
  491.                
  492.                 gWriteLR("temperature:", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  493.                 gWriteLR("set: " .. math.floor(defaultTemp) .. "°C", "max: " .. math.floor(defaultTemp + maxOvershoot) .. "°C", 2, 0, 8, colors.white, colors.white, colors.black)
  494.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)              
  495.                
  496.                 local clField
  497.                 if currentField > defaultField*1.05 then
  498.                     clField = colors.green
  499.                 elseif currentField > defaultField*0.95 then
  500.                     clField = colors.yellow
  501.                 else
  502.                     clField = colors.red
  503.                 end
  504.                
  505.                 gWriteLR("field strength:", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  506.                 gWriteLR("set: " .. math.floor(defaultField*1000)/10.0 .. "%", "min: 0.4%", 2, 0, 12, colors.white, colors.white, colors.black)
  507.                 gDrawStandardProgressBar(13, currentField, clField)
  508.                
  509.                 gWriteLR("status", info.status:upper(), 2, 0, 15, colors.white, colors.white, colors.black)
  510.                
  511.                 local clFuel
  512.                 if currentFuel > 0.15 then
  513.                     clFuel = colors.green
  514.                 elseif currentFuel > 0.05 then
  515.                     clFuel = colors.yellow
  516.                 elseif currentFuel > 0.01 then
  517.                     clFuel = colors.orange
  518.                 else
  519.                     clFuel = colors.red
  520.                 end
  521.                 gWriteLR("fuel:", math.floor(currentFuel*10000.0)/100.0 .. "%", 2, 0, 16, colors.white, clFuel, colors.black)
  522.             elseif screenPage == 1 then
  523.                 local clTemp
  524.                 if info.temperature < defaultTemp*0.95 then
  525.                     clTemp = colors.green
  526.                 elseif info.temperature < defaultTemp + 1.0 then
  527.                     clTemp = colors.yellow
  528.                 elseif info.temperature < defaultTemp + maxOvershoot then
  529.                     clTemp = colors.orange
  530.                 else
  531.                     clTemp = colors.red
  532.                 end
  533.                
  534.                 gWriteLR("temp: " .. math.floor(defaultTemp) .. " (" .. math.floor(defaultTemp + maxOvershoot) .. ")", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  535.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)
  536.                
  537.                 gWrite("<", 2, 8, colors.white, colors.blue)
  538.                 gWrite("<<", 5, 8, colors.white, colors.blue)
  539.                 gWrite("<<<", 9, 8, colors.white, colors.blue)
  540.                 gWrite("res", 14, 8, colors.white, colors.blue)
  541.                 gWrite(">>>", 19, 8, colors.white, colors.blue)
  542.                 gWrite(">>", 24, 8, colors.white, colors.blue)
  543.                 gWrite(">", 28, 8, colors.white, colors.blue)              
  544.                
  545.                 local clField
  546.                 if currentField > defaultField*1.05 then
  547.                     clField = colors.green
  548.                 elseif currentField > defaultField*0.95 then
  549.                     clField = colors.yellow
  550.                 else
  551.                     clField = colors.red
  552.                 end
  553.                
  554.                 gWriteLR("field: " .. math.floor(defaultField*1000)/10.0 .. "% (0.4%)", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  555.                 gDrawStandardProgressBar(13, currentField, clField)
  556.                
  557.                 gWrite("<", 2, 12, colors.white, colors.blue)
  558.                 gWrite("<<", 5, 12, colors.white, colors.blue)
  559.                 gWrite("<<<", 9, 12, colors.white, colors.blue)
  560.                 gWrite("res", 14, 12, colors.white, colors.blue)
  561.                 gWrite(">>>", 19, 12, colors.white, colors.blue)
  562.                 gWrite(">>", 24, 12, colors.white, colors.blue)
  563.                 gWrite(">", 28, 12, colors.white, colors.blue)
  564.                
  565.                 if safeMode then
  566.                     if openConfirmDialog then
  567.                         gWrite("DISABLE?", 2, 15, colors.white, colors.black)
  568.                         gWrite("CONFIRM", 16, 15, colors.white, colors.green)
  569.                         gWrite("EXIT", 25, 15, colors.white, colors.red)
  570.                     else
  571.                         gWrite("safe mode:", 2, 15, colors.white, colors.black)
  572.                         gWrite("ON", 27, 15, colors.green, colors.black)
  573.                     end
  574.                 else
  575.                     gWrite("safe mode:", 2, 15, colors.white, colors.black)
  576.                     gWrite("OFF", 26, 15, colors.red, colors.black)
  577.                 end
  578.                
  579.                 if not currentEmergency then
  580.                     if info.status == "running" or info.status == "online" then
  581.                         gWrite("STOP", 2, 17, colors.white, colors.red)
  582.                     elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  583.                         gWrite("CHARGE", 2, 17, colors.white, colors.blue)
  584.                     elseif info.status == "stopping" or info.status == "charged" then
  585.                         gWrite("START", 2, 17, colors.white, colors.green)
  586.                     elseif info.status == "warming_up" then
  587.                         gWrite("START", 2, 17, colors.white, colors.green)
  588.                         gWrite("STOP", 9, 17, colors.white, colors.red)
  589.                     end
  590.                 end
  591.                
  592.                 if info.temperature < 2000.0 then
  593.                     gWrite("END", 26, 17, colors.white, colors.red)
  594.                 end
  595.             end
  596.            
  597.             gWriteLR("Draconic Reactor Number", reactornumber, 2, 0, 1, colors.white, colors.white, colors.black)        
  598.            
  599.             gWriteLR("inflow:", newInflow .. " RF/t", 2, 0, 3, colors.white, colors.white, colors.black)
  600.             gWriteLR("outflow:", outflowMultiplied .. " RF/t", 2, 0, 4, colors.white, colors.white, colors.black)      
  601.             local gain = outflowMultiplied - newInflow
  602.             if gain > 0.0 then
  603.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.green, colors.black)
  604.             elseif gain < 0.0 then
  605.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.red, colors.black)
  606.             elseif gain == 0.0 then
  607.                 gWriteLR("-> gain:", "0 RF/t", 2, 0, 5, colors.white, colors.white, colors.black)
  608.             end
  609.            
  610.             gDrawLine(1, mon.y, 4, colors.gray)
  611.         end
  612.        
  613.         sleep(0.02)
  614.     end
  615. end
  616.  
  617. function setup()
  618.     term.clear()
  619.     print("Starting program...")    
  620.    
  621.     if fs.exists("config.txt") then
  622.         print("Loading config...")
  623.         loadConfig()
  624.         print("Done!")
  625.     else
  626.         print("Creating config...")
  627.         saveConfig()
  628.         print("Done!")
  629.     end
  630.  
  631.     if chargeInflow < 0 then
  632.         chargeInflow = 0
  633.     end
  634.    
  635.     stableTicks = 0
  636.    
  637.     setupPeripherals()
  638.     print("Started!")
  639. end
  640. function loadConfig()
  641.     local config = fs.open("config.txt", "r")
  642.     outputMultiplier = tonumber(config.readLine())/1000000.0
  643.     maxOvershoot = tonumber(config.readLine())
  644.     minFuel = tonumber(config.readLine())/100.0
  645.     defaultTemp = tonumber(config.readLine())
  646.     defaultField = tonumber(config.readLine())/1000.0
  647.     maxTempInc = tonumber(config.readLine())
  648.     maxOutflow = tonumber(config.readLine())
  649.     chargeInflow = tonumber(config.readLine())
  650.     shutDownField = tonumber(config.readLine())/1000.0
  651.     config.close()
  652. end
  653. function saveConfig()
  654.     local config = fs.open("config.txt", "w")
  655.     config.writeLine(outputMultiplier*1000000.0)
  656.     config.writeLine(maxOvershoot)
  657.     config.writeLine(minFuel*100.0)
  658.     config.writeLine(defaultTemp)
  659.     config.writeLine(defaultField*1000.0)
  660.     config.writeLine(maxTempInc)
  661.     config.writeLine(maxOutflow)
  662.     config.writeLine(chargeInflow)
  663.     config.writeLine(shutDownField*1000.0)
  664.     config.close()
  665. end
  666.  
  667. function main()
  668.     setup()
  669.     if mon == null then
  670.         update()
  671.     else
  672.         parallel.waitForAny(update, clickListener)
  673.         gClear()
  674.         gWrite("Program stopped!", 1, 1, colors.white, colors.black)
  675.     end
  676. end
  677.  
  678. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement