Hastwell

BigReactors Control Script

Oct 17th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. -- Hastwell's BigReactor Control Script
  2. -- aka "Hardcore/HC-NUKE"
  3. --
  4. -- Features:
  5. --  Slow, power-efficent recharge when draw is low (think overnight recharge)
  6. --
  7. local reactorMaxTemp = 200
  8. local reactorMinTemp = 180
  9.  
  10. local periList = peripheral.getNames()
  11. local reactors = {}
  12. local debugMonitor = nil
  13.  
  14. for i = 1, #periList do
  15.     if peripheral.getType(periList[i]) == "BigReactors-Reactor" then
  16.         reactor = peripheral.wrap(periList[i])
  17.         print("Reactor "..(#reactors+1).." mounted")
  18.         table.insert(reactors,reactor)
  19.     elseif peripheral.getType(periList[i]) == "monitor" then
  20.         debugMonitor = peripheral.wrap(periList[i])
  21.         debugMonitor.setTextScale(0.6)
  22.     end
  23. end
  24.  
  25. function round(num, idp)
  26.   local mult = 10^(idp or 0)
  27.   return math.floor(num * mult + 0.5) / mult
  28. end
  29.  
  30. local function setControlRodRelative(react, change)
  31.     local effectiveLv = react.getControlRodLevel(1) + change
  32.     if effectiveLv > 100 or effectiveLv < 0 then
  33.         -- nothing to do here! *blasts off*
  34.     else
  35.         react.setAllControlRodLevels(effectiveLv)
  36.     end
  37. end
  38.  
  39. local function controlReactor(react)
  40.         -- begin reactor control loop
  41.        
  42.         -- first, is it too hot? ramp it down!
  43.         if react.getFuelTemperature() > reactorMaxTemp then
  44.             setControlRodRelative(react, 1)
  45.         elseif react.getFuelTemperature() < reactorMinTemp then
  46.             setControlRodRelative(react, -1)
  47.         end
  48.         -- keep above 180c
  49.        
  50.        
  51.        
  52.         -- print reactor stats
  53.         debugMonitor.clear()
  54.         debugMonitor.setCursorPos(1,1)
  55.         debugMonitor.write("HC-Nuke - Controlling Reactor")
  56.         debugMonitor.setCursorPos(1,2)
  57.         debugMonitor.write("Temps - Core "..math.floor(react.getFuelTemperature()).."   Case "..math.floor(react.getCasingTemperature()))
  58.         debugMonitor.setCursorPos(1,3)
  59.         debugMonitor.write("Rods "..react.getControlRodLevel(1).."%")
  60.         debugMonitor.setCursorPos(1,4)
  61.         debugMonitor.write("Output "..math.floor(react.getEnergyProducedLastTick()).." MJ/t at "..round(react.getEnergyProducedLastTick()/react.getFuelConsumedLastTick(),3).." MJ/mB")
  62.        
  63. end
  64.  
  65. -- mainloop
  66. while true do
  67.     for i = 1, #reactors do
  68.         controlReactor(reactors[i])
  69.     end
  70.     os.sleep(0.4)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment