Advertisement
Jaylocke

Extreme Reactors OC

May 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. --This program is designed for a T1 computer, running any sized extreme reactor. It will try to float the power level at 80% by raising or lowering all rods every second. In the event that power drops below 10%, all rods will be removed to maximize power generation up until 30% power, in which normal operations will resume.
  2. --Minimum components required are a T1 Computer, screen is optional. This program was written by JayLocke with the assistance of the #OC IRC channel on irc.esper.net server.
  3. --Version 1.0 released 27 May 2018
  4.  
  5. local component = require( "component" )
  6. local math = require( "math" )
  7. local term = require( "term" )
  8. local br = component.br_reactor
  9. local allrods = br.setAllControlRodLevels
  10. local rodlevel = br.getControlRodLevel(0)
  11. local maxpower = 10000000
  12. local percentstore = math.floor((br.getEnergyStored() / maxpower) * 100)
  13. local condition = "INITIALIZING."
  14. br.setActive(true)
  15. allrods(100)
  16.  
  17. function refresh()
  18.     term.clear()
  19.     print("Power Level = " ..br.getEnergyStored().. " RF")
  20.     print("Current power = " ..percentstore.. "%")
  21.     print("Rods at = " ..rodlevel.. "%")
  22.     print("Condition is " ..condition..".")
  23.     if condition == "INITIALIZING." then print("Initial Conditions, Set!") end
  24. end
  25.  
  26. function ploss()
  27.     if condition ~= "NORMAL." then condition = "NORMAL." end
  28.     if (rodlevel ~= 0) then allrods(rodlevel-1) end
  29. end
  30.  
  31. function pgain()
  32.     if condition ~= "NORMAL." then condition = "NORMAL." end
  33.     if (rodlevel ~= 100) then allrods(rodlevel+1) end
  34. end
  35.  
  36. function emeregency()
  37.     if condition ~= "EMERGENCY!" then condition = "EMERGENCY!" end
  38.     while (percentstore <= 30) do
  39.         if(rodlevel ~= 0) then allrods(0) end
  40.         component.computer.beep()
  41.         os.sleep(.5)
  42.         component.computer.beep()
  43.         os.sleep(.5)
  44.         refresh()
  45.     end
  46. end
  47.  
  48. refresh()
  49. while true do
  50.     os.sleep(1)
  51.     if (percentstore <= 10) then
  52.         emergency()
  53.     elseif (percentstore < 80) then
  54.         print("Raising Rods")
  55.         ploss()
  56.     else
  57.         print("Lowering Rods")
  58.         pgain()
  59.     end
  60.     percentstore = math.floor((br.getEnergyStored() / maxpower) * 100)
  61.     rodlevel = br.getControlRodLevel(0)
  62.     refresh()
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement