Advertisement
Guest User

ComputerCraft Big Reactor Control

a guest
Sep 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. -- set to true to get info about the reactor printed every 10 loops
  2. local debug_info = false
  3. -- once the reactor is this percent full, it will shut off
  4. -- percentage must be entered in decimal format
  5. local shutOff = 0.50
  6. -- the minimum allowed control rod insertion
  7. -- rod insertion must be entered as an integer
  8. local minInsertion = 0
  9.  
  10. -- don't edit anything below this line
  11.  
  12. local loopCount = 0
  13. local powerPercent = 0
  14. local reactorList = {peripheral.find("BigReactors-Reactor")}
  15. local reactor = reactorList[1]
  16.  
  17. if reactor == nil then
  18. error("The reactor was not detected!",0)
  19. end
  20. reactor.setActive(true)
  21.  
  22. print("Starting reactor control! :D")
  23. print("Current shutoff percent is " .. tostring(shutOff))
  24. print("Minimum control rod insertion is " .. tostring(minInsertion))
  25.  
  26. while(true) do
  27. -- calculate what percentage full the reactor is with respect to the shutoff limit
  28. powerPercent = reactor.getEnergyStored() / (10000000 * shutOff)
  29. -- calculate how much the reactor control rods should be inserted
  30. insertAmount = ((100 - minInsertion) * powerPercent) + minInsertion
  31. insertAmount = math.floor(insertAmount + 0.5) -- rounds to nearest int
  32. if insertAmount > 100 then -- avoid going out of bounds
  33. insertAmount = 100
  34. end
  35.  
  36. reactor.setAllControlRodLevels(insertAmount) -- set control rods
  37. loopCount = (loopCount + 1) % 10
  38.  
  39. if debug_info and loopCount == 0 then
  40. print("Current energy: " .. tostring(reactor.getEnergyStored()))
  41. print("Current percent to shutoff: " .. tostring(powerPercent))
  42. print("Current control rod insertion: " .. tostring(insertAmount))
  43. end
  44.  
  45. sleep(1)
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement