Advertisement
brainytwoo

FindOptimaleRodLevel

Nov 27th, 2023 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | Gaming | 0 0
  1. local reactors = {}
  2. local turbines = {}
  3.  
  4. for _, name in pairs(peripheral.getNames()) do
  5.     if peripheral.getType(name) == "BigReactors-Reactor" then
  6.         local wrapped = peripheral.wrap(name)
  7.         if wrapped.isActivelyCooled() then
  8.             table.insert(reactors, wrapped)
  9.         end
  10.     elseif peripheral.getType(name) == "BigReactors-Turbine" then
  11.         local wrapped = peripheral.wrap(name)
  12.         table.insert(turbines, wrapped)
  13.         wrapped.setActive(true)
  14.         wrapped.setFluidFlowRateMax(2000)
  15.         wrapped.setVentOverflow(true)
  16.     end
  17. end
  18.  
  19. print("Reactors found  : " .. #reactors)
  20. print("Turbines found  : " .. #turbines)
  21.  
  22. print("\n")
  23.  
  24. -- Ensure program should succeed
  25. if #reactors == 0 then
  26.     print("No Activly Cooled Reactors were found, Optimal Rod Level Finder will Fail.")
  27.     print("\nPress Enter to exit...")
  28.     read()
  29.     if shell then
  30.         shell.exit()
  31.     end
  32. end
  33.  
  34. local reactor = reactors[1]
  35. local TargetProduction = (2000 * #turbines) / #reactors
  36.  
  37. if #turbines == 0 then
  38.     print("No turbines detected, program will assume you want to power a single turbine")
  39.     print("\nPress Enter to continue...")
  40.     read()
  41.     TargetProduction = 2000
  42. end
  43.  
  44. print("This script will attempt find the optimal level for the control rods of 1 reactor. The optimal level is determined by the number of turbines and reactors you have.")
  45. print("It simply takes the number of turbines and devides by the number of reactors. If you have 2 turbines and 2 reactors then the Optimal steam output will be 2000mb for each reactor.")
  46. print("It only tests 1 reactor and assumes the others are built exactly the same.")
  47. print("\nPress Enter to proceed with the test...")
  48. read()
  49.  
  50. print("Beginning Test...")
  51. sleep(4)
  52.  
  53. -- Begin test
  54. local production = 0
  55. local rodLevels = 0
  56.  
  57. -- Set Reactor Rod Level
  58. function SetRods(targetLevel)
  59.     -- Ensure targetLevel is within spec
  60.     if targetLevel < 0 or targetLevel > 100 then targetLevel = 99 end
  61.     local controlRodsCount = reactor.getNumberOfControlRods()
  62.     -- Calculate floor and ceiling values
  63.     local floorLevel = math.floor(targetLevel)
  64.     local ceilLevel = math.ceil(targetLevel)
  65.     -- Calculate how many rods should be set to each level
  66.     local remainder = (targetLevel - floorLevel) * controlRodsCount
  67.     local ceilCount = math.floor(remainder)
  68.     local floorCount = controlRodsCount - ceilCount
  69.     -- Build the levels table
  70.     local controlRodsLevels = {}
  71.     for i = 0, (floorCount - 1) do
  72.         controlRodsLevels[i] = floorLevel
  73.     end
  74.     for i = floorCount, (controlRodsCount - 1) do
  75.         controlRodsLevels[i] = ceilLevel
  76.     end
  77.     -- Set control rods levels
  78.     reactor.setControlRodsLevels(controlRodsLevels)
  79. end
  80.  
  81. reactor.setAllControlRodLevels(95)
  82. reactor.setActive(true)
  83. print("Set all rod levels to 95")
  84. print("Waiting 12 seconds to stabilize...")
  85. sleep(12)
  86. production = reactor.getHotFluidProducedLastTick()
  87. print(production .. " of " .. TargetProduction .. " MB/t of steam")
  88. rodLevels = 100 - (TargetProduction / production)
  89. print(TargetProduction .. "/" .. production .. " = " .. rodLevels)
  90. print("Estimated Level: " .. rodLevels)
  91. print("Waiting 12 seconds to stabilize...")
  92. print("\nBeginning test loop...")
  93.  
  94. while production > TargetProduction or production < TargetProduction - 200 do
  95.     production = reactor.getHotFluidProducedLastTick()
  96.     print(production .. " of " .. TargetProduction .. " MB/t of steam")
  97.     rodLevels = 100 - (TargetProduction / production)
  98.     print(TargetProduction .. "/" .. production .. " = " .. rodLevels)
  99.     print("Estimated Level: " .. rodLevels)
  100.     print("Waiting 12 seconds to stabilize...")
  101.     sleep(12)
  102. end
  103.  
  104. print("Final production: " .. production)
  105. print("Deactivating reactor... Done")
  106. reactor.setActive(false)
  107. print("\nOptimal fuel rod level for your Reactors: " .. rodLevels .. "%")
  108. print("\nPress Enter to exit...")
  109. read()
  110. if shell then
  111.     shell.exit()
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement