Jobs2k

Jobs2k Reactor

Aug 20th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. local term = require("term")
  2. local component = require("component")
  3.  
  4. -------------------------------------------------
  5. -------These can be configured as you need-------
  6.  
  7. -- The percentage of steam you wish to hold in the tank.
  8. -- Range 1 - 99
  9. steamTarget = 70
  10.  
  11. -- The amount of time the program rests before begining again.
  12. -- Lower than 0.2 is not advised.
  13. loopSleep = 0.2
  14.  
  15. -- How many seconds before the turbine is checked for required adjustments.
  16. turbineTimer = 10
  17.  
  18. -- The amount of steam the turbine should allow at the start.
  19. -- Range: 0 - 2000.
  20. flowStart = 0
  21.  
  22. -- The amount the reactor rods are inserted at the start. Higher values equal less steam.
  23. -- Range 0 - 100.
  24. rodStart = 100
  25.  
  26. -- The increase or decrease of steam flowing into the turbine.
  27. -- A higher value increase response to energy draw, but is harder to stabalise.
  28. flowUpDown = 1
  29.  
  30. -- The percentage of the turbine buffer that will trigger activation/deactivation.
  31. -- Going lower than 30 (or outside the range) is not advised.
  32. -- Range 1 - 99
  33. tBuffer = 50
  34.  
  35. -----Changing the rest can break the program-----
  36. -------------------------------------------------
  37.  
  38. reactor = component.br_reactor
  39. turbine = component.br_turbine
  40.  
  41. reactor.setActive(true)
  42. turbine.setActive(true)
  43. turbine.setFluidFlowRateMax(flowStart)
  44. reactor.setAllControlRodLevels(rodStart)
  45.  
  46. function turbineCheck ()
  47.     if turbine.getEnergyStored() >= (tBuffer * 10000) then
  48.         turbine.setActive(false)
  49.         if turbine.getRotorSpeed() < 1901 then
  50.             turbine.setFluidFlowRateMax(turbine.getFluidFlowRateMax()-flowUpDown)
  51.         elseif turbine.getRotorSpeed() >= 1901 then
  52.             turbine.setFluidFlowRateMax(turbine.getFluidFlowRateMax()-flowUpDown)
  53.         end
  54.     elseif turbine.getEnergyStored() < (tBuffer * 10000) then
  55.         turbine.setActive(true)
  56.         if turbine.getRotorSpeed() < 1901 then
  57.             if turbine.getFluidFlowRateMax() <= (turbine.getFluidFlowRateMaxMax()-flowUpDown) then
  58.                 turbine.setFluidFlowRateMax(turbine.getFluidFlowRateMax()+flowUpDown)
  59.             else
  60.                 turbine.setFluidFlowRateMax(2000)
  61.             end
  62.         elseif turbine.getRotorSpeed() > 1901 then
  63.             turbine.setActive(false)
  64.         end
  65.     end
  66. end
  67.  
  68. function reactorCheck ()
  69.     if reactor.getHotFluidAmount() < 7000 then
  70.         if reactor.getControlRodLevel(0) <= 100 then
  71.             reactor.setAllControlRodLevels(reactor.getControlRodLevel(0)-1)
  72.             reactor.setActive(true)
  73.         end
  74.     elseif reactor.getHotFluidAmount() > 7000 then
  75.         if reactor.getControlRodLevel(0) >= 0 then
  76.             reactor.setAllControlRodLevels(reactor.getControlRodLevel(0)+1)
  77.             reactor.setActive(false)
  78.         end
  79.     end
  80. end
  81.  
  82. i = 1
  83.  
  84. while true do
  85.    
  86.     if math.ceil(i) == 0 then
  87.         turbineCheck()
  88.         reactorCheck()
  89.         i = turbineTimer
  90.     elseif i < turbineTimer then
  91.         reactorCheck()
  92.     end
  93.     term.clear()
  94.     print("Turbine Output: "..math.ceil(turbine.getEnergyProducedLastTick()))
  95.     print("Turbine Buffer: "..turbine.getEnergyStored())
  96.     print("Reactor Rods at "..reactor.getControlRodLevel(0))
  97.     steamTank = math.ceil(reactor.getHotFluidAmount() / (reactor.getHotFluidAmountMax() / 100))
  98.     print("Steam tank "..steamTank.."% full")
  99.     i = i - loopSleep
  100.     if math.ceil(i) <= 0 then
  101.         print("Turbine check in: 0")
  102.     else
  103.         print("Turbine check in: "..math.ceil(i))
  104.     end
  105.     print("Reactor Producing: "..reactor.getHotFluidProducedLastTick())
  106.     print("Turbine Accepting: "..turbine.getFluidFlowRateMax())
  107.     os.sleep(loopSleep)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment