Advertisement
troty

DraconicControl-1.16.5-0.0.1

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