Advertisement
Putnam

Big Reactors efficiency script

May 29th, 2014
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- keeps reactor working efficiently at all times; increases power load when necessary, goes idle at 90% power until below 10%
  2.  
  3. local function findPeripherals() --searches around for reactor so the computer doesn't have to be placed in a particular way
  4.   local reactor,terminal --also searches for a terminal glasses terminal
  5.   for k,v in pairs(rs.getSides()) do
  6.     if (peripheral.getType(v) == "BigReactors-Reactor") then
  7.       reactor = peripheral.wrap(v)
  8.       print(reactor)
  9.       print('reactor found!')
  10.       break
  11.     elseif (peripheral.getType(v) == "openperipheral_glassesbridge") and (not terminal) then
  12.       terminal = peripheral.wrap(v)
  13.     end
  14.   end
  15.   return reactor, terminal
  16. end
  17.  
  18.  
  19. local reactor,terminal=findPeripherals()
  20.  
  21. local deltaPower,curPower,oldPower,controlRodLevel,powerMode,secondsWorked=0,0,0,100,0,0
  22.  
  23. print(not reactor)
  24.  
  25. powerMode = reactor.getEnergyStored()<9000000
  26.  
  27. local function reactorActivities()
  28.   term.clear()
  29.   secondsWorked=secondsWorked+1
  30.   print('Yes, I am working. Total time: ' .. secondsWorked .. ' steps.')
  31.   oldPower=curPower
  32.   curPower=reactor.getEnergyStored()
  33.   controlRodLevel=controlRodLevel>100 and 100 or controlRodLevel<0 and 0 or controlRodLevel
  34.   if curPower>9000000 then
  35.     powerMode=false
  36.   elseif curPower<1000000 then
  37.     powerMode=true
  38.   end
  39.   if powerMode then
  40.     deltaPower=curPower-oldPower
  41.     --let's add some derivative to this sos it doesn't go quite so slow at slower intervals
  42.     local deltaControlRodLevel=deltaPower<0 and math.floor(deltaPower/1000) or deltaPower>100 and math.ceil(deltaPower/1000) or 0
  43.     controlRodLevel = controlRodLevel+deltaControlRodLevel
  44.     if curPower<10000 then
  45.      controlRodLevel=0
  46.     end
  47.     reactor.setAllControlRodLevels(controlRodLevel)
  48.   else
  49.     reactor.setAllControlRodLevels(100)
  50.     print("Reactor's nearly full.")
  51.     print("Current status: off.")
  52.   end
  53. end
  54.  
  55. local function terminalActivities()
  56.   terminal.clear()
  57.   local wastePercent=reactor.getWasteAmount()/reactor.getFuelAmountMax()
  58.   local fuelPercent=(reactor.getWasteAmount()+reactor.getFuelAmount())/reactor.getFuelAmountMax()
  59.   terminal.addBox(5,5,100,10,0xcc0000,0.8)
  60.   terminal.addBox(5,5,math.floor(curPower/100000),10,0x00cc00,0.8)
  61.   terminal.addBox(105,5,10,100,0xcccccc,0.8)
  62.   terminal.addBox(105,5,10,controlRodLevel,0x303030,0.8)
  63.   terminal.addBox(5,20,100,10,0x303030,0.8)
  64.   terminal.addBox(5,20,math.min(math.floor(100*fuelPercent),100),10,0xcccc00,0.8)
  65.   terminal.addBox(5,20,math.min(math.floor(100*wastePercent),100),10,0x00cccc,0.8)
  66. end
  67.  
  68. interval=tonumber(...)
  69.  
  70. if interval then
  71.     if interval<0.5 then
  72.         interval=0.5
  73.     end
  74. else
  75.     interval=2
  76. end
  77.  
  78. while reactor.getConnected() do
  79.   if interval then os.startTimer(interval) end
  80.   local event = {os.pullEvent()}
  81.   reactorActivities()
  82.   if terminal then
  83.     terminalActivities()
  84.   end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement