Advertisement
Guest User

reactorInfo

a guest
Jan 18th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.26 KB | None | 0 0
  1. --[[
  2. zzReactor - reactorInfo
  3. Copyright 2017 Steven Jennings (zzApotheosis)
  4.  
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8.  
  9.     http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. ]]--
  17.  
  18. -- Change these values for your setup. You should only need to change the monitor ID.
  19. r = peripheral.wrap("back")
  20. m = peripheral.wrap("monitor_3")
  21.  
  22. term.clear()
  23. m.clear()
  24.  
  25. term.write("Initializing...")
  26.  
  27. -- Initialize some variables
  28. previousTemp = 0
  29. currentTemp = 0
  30. previousField = 0
  31. currentField = 0
  32. previousSat = 0
  33. currentSat = 0
  34. emergency = false
  35.  
  36. -- Program Introduction
  37. sleep(1)
  38. term.setCursorPos(1,1)
  39. m.setCursorPos(1,1)
  40. m.setTextScale(2)
  41. m.setTextColor(colors.blue)
  42. m.write("Java's")
  43. sleep(1)
  44. m.setCursorPos(1,2)
  45. m.write("Draconic Reactor")
  46. sleep(1)
  47.  
  48. while true do
  49.   index = 1
  50.  
  51.   -- Print terminal information
  52.   term.clear()
  53.   term.setCursorPos(1,1)
  54.   info = r.getReactorInfo()
  55.   print(textutils.serialize(info))
  56.  
  57.   -- Get monitor ready for information
  58.   m.clear()
  59.   m.setTextScale(1)
  60.  
  61.   -- Assign variables
  62.   status = info["status"]
  63.   gen = info["generationRate"]
  64.   temp = info["temperature"]
  65.   fieldStrength = info["fieldStrength"]
  66.   fieldPower = info["fieldDrainRate"]
  67.   maxFieldStrength = info["maxFieldStrength"]
  68.   sat = info["energySaturation"]
  69.   maxSat = info["maxEnergySaturation"]
  70.   fuel = info["fuelConversion"]
  71.   fuelRate = info["fuelConversionRate"]
  72.   maxFuel = info["maxFuelConversion"]
  73.  
  74.   -- Write Reactor Status
  75.   m.setCursorPos(1,index)
  76.   m.setTextColor(colors.white)
  77.   m.write("Draconic Reactor Status: ")
  78.   if (status == "online") then
  79.     m.setTextColor(colors.lime)
  80.     m.write("Online")
  81.   elseif (status == "stopping") then
  82.     if (emergency) then
  83.       m.setTextColor(colors.red)
  84.       m.write("Emergency Shutdown")
  85.     else
  86.       m.setTextColor(colors.lightBlue)
  87.       m.write("Shutting down")
  88.     end
  89.   elseif (status == "charging") then
  90.     m.setTextColor(colors.yellow)
  91.     m.write("Charging")
  92.   elseif (status == "charged") then
  93.     m.setTextColor(colors.lime)
  94.     m.write("Ready")
  95.   elseif (status == "offline") then
  96.     m.setTextColor(colors.red)
  97.     m.write("Offline")
  98.   else
  99.     m.setTextColor(colors.white)
  100.     m.write("???")
  101.   end
  102.  
  103.   -- Write Power
  104.   index = index + 2
  105.   m.setCursorPos(1,index)
  106.   m.setTextColor(colors.white)
  107.   m.write("Total Power: ")
  108.   m.setTextColor(colors.red)
  109.   m.write(gen.." RF/t")
  110.  
  111.   -- Write Temperature
  112.   index = index + 2
  113.   m.setCursorPos(1,index)
  114.   m.setTextColor(colors.white)
  115.   m.write("Temperature: ")
  116.   if (temp < 7000) then
  117.     m.setTextColor(colors.lightBlue)
  118.     m.write(temp)
  119.   elseif (temp >= 7500) then
  120.     m.setTextColor(colors.red)
  121.     m.write(temp)
  122.   else
  123.     m.setTextColor(colors.yellow)
  124.     m.write(temp)
  125.   end
  126.   -- Display Temperature Status
  127.   if (temp >= 7500 and (status == "online" or status == "stopping")) then
  128.     m.setTextColor(colors.red)
  129.     m.setCursorPos(45,index)
  130.     m.write("DANGER")
  131.   elseif (temp < 7000 and (status == "online" or status == "stopping")) then
  132.     m.setTextColor(colors.lime)
  133.     m.setCursorPos(49,index)
  134.     m.write("OK")
  135.   elseif ((temp >= 7000 and temp < 7500) and (status == "online" or status == "stopping")) then
  136.     m.setTextColor(colors.yellow)
  137.     m.setCursorPos(44,index)
  138.     m.write("WARNING")
  139.   end
  140.  
  141.   -- Write Containment Field Strength
  142.   index = index + 2
  143.   m.setCursorPos(1,index)
  144.   m.setTextColor(colors.white)
  145.   m.write("Field Strength: ")
  146.   if ((fieldStrength/maxFieldStrength) <= 0.15) then
  147.     m.setTextColor(colors.red)
  148.     m.write((fieldStrength/maxFieldStrength*100).."%")
  149.   elseif ((fieldStrength/maxFieldStrength) >= 0.20) then
  150.     m.setTextColor(colors.lime)
  151.     m.write((fieldStrength/maxFieldStrength*100).."%")
  152.   elseif ((fieldStrength/maxFieldStrength) > 0.15 and (fieldStrength/maxFieldStrength) < 0.20) then
  153.     m.setTextColor(colors.yellow)
  154.     m.write((fieldStrength/maxFieldStrength*100).."%")
  155.   else
  156.     m.setTextColor(colors.lightBlue)
  157.     m.write("0%")
  158.   end
  159.   -- Display Containment Field Strength Status
  160.   if ((fieldStrength/maxFieldStrength) <= 0.15 and (status == "online" or status == "stopping")) then
  161.     m.setCursorPos(45,index)
  162.     m.setTextColor(colors.red)
  163.     m.write("DANGER")
  164.   elseif ((fieldStrength/maxFieldStrength) >= 0.20 and (status == "online" or status == "stopping")) then
  165.     m.setCursorPos(49,index)
  166.     m.setTextColor(colors.lime)
  167.     m.write("OK")
  168.   elseif ((fieldStrength/maxFieldStrength) > 0.15 and (fieldStrength/maxFieldStrength) < 0.20 and (status == "online" or status == "stopping")) then
  169.     m.setCursorPos(44,index)
  170.     m.setTextColor(colors.yellow)
  171.     m.write("WARNING")
  172.   end
  173.  
  174.   -- Write Containment Field Power Demand
  175.   index = index + 1
  176.   m.setCursorPos(1,index)
  177.   m.setTextColor(colors.white)
  178.   m.write("Field Power Demand: ")
  179.   m.setTextColor(colors.red)
  180.   m.write(fieldPower.." RF/t")
  181.  
  182.   -- Write Energy Saturation
  183.   index = index + 2
  184.   m.setCursorPos(1,index)
  185.   m.setTextColor(colors.white)
  186.   m.write("Energy Saturation: ")
  187.   if ((sat/maxSat) <= 0.15) then
  188.     m.setTextColor(colors.red)
  189.     m.write(((sat/maxSat)*100).."%")
  190.   elseif ((sat/maxSat) >= 0.20) then
  191.     m.setTextColor(colors.lime)
  192.     m.write(((sat/maxSat)*100).."%")
  193.   elseif ((sat/maxSat) > 0.15 and (sat/maxSat) < 0.20) then
  194.     m.setTextColor(colors.yellow)
  195.     m.write(((sat/maxSat)*100).."%")
  196.   else
  197.     m.setTextColor(colors.lightBlue)
  198.     m.write("0%")
  199.   end
  200.   -- Display Energy Saturation Status
  201.   if ((sat/maxSat) <= 0.15 and (status == "online" or status == "stopping")) then
  202.     m.setCursorPos(45,index)
  203.     m.setTextColor(colors.red)
  204.     m.write("DANGER")
  205.   elseif ((sat/maxSat) >= 0.20 and (status == "online" or status == "stopping")) then
  206.     m.setCursorPos(49,index)
  207.     m.setTextColor(colors.lime)
  208.     m.write("OK")
  209.   elseif ((sat/maxSat) > 0.15 and (sat/maxSat) < 0.20 and (status == "online" or status == "stopping")) then
  210.     m.setCursorPos(44,index)
  211.     m.setTextColor(colors.yellow)
  212.     m.write("WARNING")
  213.   end
  214.  
  215.   -- Write Fuel Conversion
  216.   index = index + 2
  217.   m.setCursorPos(1,index)
  218.   m.setTextColor(colors.white)
  219.   m.write("Fuel Conversion: ")
  220.   if ((fuel/maxFuel) <= 0.70) then
  221.     m.setTextColor(colors.lime)
  222.     m.write(((fuel/maxFuel)*100).."%")
  223.     index = index + 1
  224.     m.setCursorPos(18,index)
  225.     m.write(fuelRate.." nb/t")
  226.   elseif ((fuel/maxFuel) >= 0.80) then
  227.     m.setTextColor(colors.red)
  228.     m.write(((fuel/maxFuel)*100).."%")
  229.     index = index + 1
  230.     m.setCursorPos(18,index)
  231.     m.write(fuelRate.." nb/t")
  232.   elseif ((fuel/maxFuel) > 0.70 and (fuel/maxFuel) < 0.80) then
  233.     m.setTextColor(colors.yellow)
  234.     m.write(((fuel/maxFuel)*100).."%")
  235.     index = index + 1
  236.     m.setCursorPos(18,index)
  237.     m.write(fuelRate.." nb/t")
  238.   else
  239.     m.setTextColor(colors.lightBlue)
  240.     m.write("0%")
  241.     index = index + 1
  242.     m.setCursorPos(18,index)
  243.     m.write(fuelRate.." nb/t")
  244.   end
  245.   -- Display Fuel Conversion Status
  246.   if ((fuel/maxFuel) < 0.70 and (status == "online" or status == "stopping")) then
  247.     index = index - 1
  248.     m.setCursorPos(49,index)
  249.     m.setTextColor(colors.lime)
  250.     m.write("OK")
  251.   elseif ((fuel/maxFuel) >= 0.80 and (status == "online" or status == "stopping")) then
  252.     index = index - 1
  253.     m.setCursorPos(45,index)
  254.     m.setTextColor(colors.red)
  255.     m.write("DANGER")
  256.   elseif ((fuel/maxFuel) >= 0.70 and (fuel/maxFuel) < 0.80 and (status == "online" or status == "stopping")) then
  257.     index = index - 1
  258.     m.setCursorPos(44,index)
  259.     m.setTextColor(colors.yellow)
  260.     m.write("WARNING")
  261.   end
  262.  
  263.   -- Write any problems
  264.   if (status == "online" or status == "stopping") then
  265.     index = index + 2
  266.     m.setCursorPos(1,index)
  267.     m.setTextColor(colors.white)
  268.     m.write("Problems:")
  269.     if (temp < 7000 and (fieldStrength/maxFieldStrength) >= 0.20 and (sat/maxSat) >= 0.20 and (fuel/maxFuel) < 0.70) then
  270.       problems = false
  271.       index = index + 1
  272.       m.setCursorPos(1,index)
  273.       m.setTextColor(colors.lightBlue)
  274.       m.write("No problems!")
  275.     else
  276.       problems = true -- Houston... we have a problem...
  277.      
  278.       -- Display Temperature Problems
  279.       if (temp >= 7000 and temp < 7500) then
  280.         index = index + 1
  281.         m.setCursorPos(1,index)
  282.         m.setTextColor(colors.yellow)
  283.         m.write("*Reactor is too hot.")
  284.       elseif (temp >= 7500) then
  285.         index = index + 1
  286.         m.setCursorPos(1,index)
  287.         m.setTextColor(colors.red)
  288.         m.write("*Reactor is too hot.")
  289.       end
  290.      
  291.       -- Display Containment Field Strength Problems
  292.       if ((fieldStrength/maxFieldStrength) > 0.15 and (fieldStrength/maxFieldStrength) < 0.20) then
  293.         index = index + 1
  294.         m.setCursorPos(1,index)
  295.         m.setTextColor(colors.yellow)
  296.         m.write("*Containment field is not strong enough.")
  297.       elseif ((fieldStrength/maxFieldStrength) <= 0.15) then
  298.         index = index + 1
  299.         m.setCursorPos(1,index)
  300.         m.setTextColor(colors.red)
  301.         m.write("*Containment field is not strong enough.")
  302.       end
  303.      
  304.       -- Display Energy Saturation Problems
  305.       if (sat/maxSat > 0.15 and sat/maxSat < 0.20) then
  306.         index = index + 1
  307.         m.setCursorPos(1,index)
  308.         m.setTextColor(colors.yellow)
  309.         m.write("*Energy Saturation is too low.")
  310.       elseif (sat/maxSat < 0.15) then
  311.         index = index + 1
  312.         m.setCursorPos(1,index)
  313.         m.setTextColor(colors.red)
  314.         m.write("*Energy Saturation is too low.")
  315.       end
  316.      
  317.       -- Display Fuel Conversion Problems
  318.       if (fuel/maxFuel >= 0.70 and fuel/maxFuel < 0.80) then
  319.         index = index + 1
  320.         m.setCursorPos(1,index)
  321.         m.setTextColor(colors.yellow)
  322.         m.write("*Fuel is getting too old.")
  323.       elseif (fuel/maxFuel >= 0.80) then
  324.         index = index + 1
  325.         m.setCursorPos(1,index)
  326.         m.setTextColor(colors.red)
  327.         m.write("*Fuel is getting too old.")
  328.       end
  329.     end
  330.   elseif (status == "charging") then
  331.     index = index + 2
  332.     m.setCursorPos(1,index)
  333.     m.setTextColor(colors.white)
  334.     m.write("Problems:")
  335.    
  336.     previousTemp = currentTemp
  337.     currentTemp = temp
  338.     previousField = currentField
  339.     currentField = fieldStrength
  340.     previousSat = currentSat
  341.     currentSat = sat
  342.    
  343.     if (previousTemp == currentTemp and previousField == currentField and previousSat == currentSat) then
  344.       problems = true
  345.       index = index + 1
  346.       m.setCursorPos(1,index)
  347.       m.setTextColor(colors.yellow)
  348.       m.write("*Reactor is not charging.")
  349.     else
  350.       problems = false
  351.       index = index + 1
  352.       m.setCursorPos(1,index)
  353.       m.setTextColor(colors.lightBlue)
  354.       m.write("No problems!")
  355.     end
  356.   elseif (status == "charged") then
  357.     index = index + 2
  358.     m.setCursorPos(1,index)
  359.     m.setTextColor(colors.white)
  360.     m.write("Problems:")
  361.    
  362.     problems = false
  363.     index = index + 1
  364.     m.setCursorPos(1,index)
  365.     m.setTextColor(colors.lightBlue)
  366.     m.write("No problems!")
  367.   end
  368.  
  369.   -- Write Solutions to Existing Problems
  370.   if (problems) then
  371.     index = index + 2
  372.     m.setCursorPos(1,index)
  373.     m.setTextColor(colors.white)
  374.     m.write("Solutions:")
  375.     m.setTextColor(colors.lightBlue)
  376.     if (status == "online" or status == "stopping") then
  377.       if (temp > 7000 or sat/maxSat < 0.20) then
  378.         index = index + 1
  379.         m.setCursorPos(1,index)
  380.         m.write("*Reduce power demand.")
  381.       end
  382.       if (fieldStrength/maxFieldStrength < 0.20) then
  383.         index = index + 1
  384.         m.setCursorPos(1,index)
  385.         m.write("*Supply more power to the Energy Injector.")
  386.       end
  387.       if (fuel/maxFuel >= 0.70) then
  388.         index = index + 1
  389.         m.setCursorPos(1,index)
  390.         m.write("*Change fuel.")
  391.       end
  392.     elseif (status == "charging") then
  393.       if (previousTemp == currentTemp and previousField == currentField and previousSat == currentSat) then
  394.         index = index + 1
  395.         m.setCursorPos(1,index)
  396.         m.write("Supply power to the Energy Injector.")  
  397.       end
  398.     end
  399.   end
  400.  
  401.   -- Handle Energy Injector for shutdown and charging
  402.   local d = (fieldStrength/maxFieldStrength)
  403.   local e = (sat/maxSat)
  404.   if ((status == "stopping" and d <= 0.25) or status == "charging") then
  405.     redstone.setAnalogOutput("left", 15)
  406.   else
  407.     redstone.setAnalogOutput("left", 0)
  408.   end
  409.  
  410.   -- Monitor for Emergency Shutdown Situation
  411.   if (status == "online" and (d <= 0.1 or e <= 0.1)) then
  412.     emergency = true
  413.     r.stopReactor()
  414.     m.clear()
  415.     m.setCursorPos(1,1)
  416.     m.setTextColor(colors.red)
  417.     m.setTextScale(2)
  418.     m.write("Commencing Emergency")
  419.     m.setCursorPos(1,2)
  420.     m.write("Shutdown")
  421.     sleep(1.5)
  422.     m.setTextScale(1)
  423.   elseif (emergency and status ~= "stopping") then
  424.     emergency = false
  425.   end
  426.  
  427.   sleep(0.2)
  428. end
  429.  
  430. m.clear()
  431. m.setCursorPos(1,3)
  432. m.setTextColor(colors.red)
  433. m.setTextScale(1)
  434. m.write("Please reboot computer")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement