Advertisement
GauHelldragon

ReactorControl.lua

Mar 31st, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. local comp = require("component")
  2.  
  3.  
  4. reactor = comp.getPrimary("br_reactor")
  5. turbine = comp.getPrimary("br_turbine")
  6.  
  7. maxSteam = reactor.getHotFluidAmountMax() + turbine.getFluidAmountMax()
  8.  
  9. function getSteam ()
  10.   local mySteam = reactor.getHotFluidAmount() + turbine.getInputAmount()
  11.   return ( 100 * mySteam ) / maxSteam
  12. end
  13.  
  14. local lastSteam = getSteam()
  15.  
  16. os.sleep(1)
  17.  
  18.  
  19. local control = reactor.getControlRodLevel(0)
  20. local delay = 0
  21.  
  22. while true do
  23.   steam = getSteam()
  24.   delay = 0
  25.   if ( delay == 0 ) then
  26.     if ( control > 0 and (( steam < 25 or ( steam < 50 and steam < lastSteam )))) then
  27.       control = control - 1
  28.       reactor.setAllControlRodLevels(control)
  29.       delay = 1
  30.     end
  31.     if ( control < 100 and (( steam > 95 or ( steam > 85 and steam > lastSteam )))) then
  32.       control = control + 1
  33.       reactor.setAllControlRodLevels(control)
  34.       delay = 1
  35.     end
  36.  
  37.  
  38.   else
  39.     delay = 0
  40.   end
  41.  
  42.   lastSteam = steam
  43.  
  44.   print("Steam: " .. math.floor(steam) .. "%, Control rods: " .. control .."%")  
  45.  
  46.   os.sleep(10)
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement