eternalclickbait

Untitled

Nov 16th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. --Reactor and turbine control script by EternalClickbait
  2. --Reactor, turbine and monitor must be connected with wired modems to the computer
  3. --Only works for actively cooled reactors
  4.  
  5. local reactors = {}
  6. local turbines = {}
  7. local monitors = {}
  8.  
  9. -----VARIABLES TO CHANGE FOR YOUR NEEDS-----
  10. --The maximum temperature for the reactor
  11. local reactorMaxTemp = 200
  12. --The maximum energy in our turbine's buffer. Max a turbine can hold is 1M (1,000,000)
  13. local turbineMaxEnergy = 500000
  14. --------------------------------------------
  15.  
  16.  
  17. --Prints a message to all monitors/windows
  18. function log(message)
  19. print(message)
  20. for _, side in ipairs(monitors) do
  21. peripheral.wrap(side).write(message)
  22. end
  23. end
  24.  
  25. -- maps a given range from a specific iterator to a new range
  26. local function map(n, start, stop, newStart, newStop, withinBounds)
  27. local value = ((n - start) / (stop - start)) * (newStop - newStart) + newStart
  28.  
  29. --// Returns basic value
  30. if not withinBounds then
  31. return value
  32. end
  33.  
  34. --// Returns values constrained to exact range
  35. if newStart < newStop then
  36. return math.max(math.min(value, newStop), newStart)
  37. else
  38. return math.max(math.min(value, newStart), newStop)
  39. end
  40. end
  41.  
  42. --Sets the scales on all monitors for easily visible text
  43. function setMonitorScales()
  44. for _, side in ipairs(monitors) do
  45. local m = peripheral.wrap(side)
  46. m.setTextScale(2)
  47. end
  48. end
  49.  
  50. --Clears all monitors/windows
  51. function clear()
  52. term.clear()
  53. for _, side in ipairs(monitors) do
  54. peripheral.wrap(side).clear()
  55. peripheral.wrap(side).setCursorPos(1,1)--Reset the cursor position
  56. end
  57. term.setCursorPos(1,1)
  58. end
  59.  
  60. --Updates the list of reactors, turbines and monitor
  61. function updatePeripherals()
  62. local peripherals = peripheral.getNames() --Get a list of all the peripherals
  63. log("Peripherals:")
  64. for _, pSide in ipairs(peripherals) do
  65. local pType = peripheral.getType(pSide)
  66. local pFunctions = peripheral.wrap(pSide)
  67.  
  68. if(pType == "BigReactors-Reactor") then --If we found a reactor
  69. table.insert(reactors, pSide)
  70. elseif (pType == "BigReactors-Turbine") then
  71. table.insert(turbines, pSide)
  72. elseif (pType == "monitor") then
  73. table.insert(monitors, pSide)
  74. end
  75. end
  76. end
  77.  
  78. --Lists all of the peripherals connected
  79. function listPeripherals()
  80. log("Reactors:")
  81. for i, pSide in ipairs(reactors) do
  82. log("\t" ..i.. ":\t" ..pSide)
  83. end
  84.  
  85. log("Turbines:")
  86. for i, pSide in ipairs(turbines) do
  87. log("\t" ..i.. ":\t" ..pSide)
  88. end
  89.  
  90. log("Monitors:")
  91. for i, pSide in ipairs(monitors) do
  92. log("\t" ..i.. ":\t" ..pSide)
  93. end
  94. end
  95.  
  96.  
  97. --Updates all info on screen
  98. function update()
  99. --Clear the window(s)
  100. clear()
  101.  
  102. --Now print out the info for each turbine/reactor, and enable/disable them as needed
  103. for _,pSide in ipairs(reactors) do
  104. local r = peripheral.wrap(pSide)
  105.  
  106. local temp = r.getFuelTemperature()
  107.  
  108. local shouldBeActive = true
  109.  
  110. --If the reactor's at or above the max temp, it shouldn't run
  111. if(temp >= reactorMaxTemp) then shouldBeActive = false end
  112.  
  113. --If it has less than 1 bucket of water (coolant), it shoudn't run
  114. if(r.getCoolantAmount() <= 1000) then shouldBeActive = false end
  115.  
  116. --Set the reactor's active state
  117. r.setActive(shouldBeActive)
  118.  
  119. log(pSide.. ":\t" ..temp.. " C\t")
  120. end
  121.  
  122. for _,pSide in ipairs(turbines) do
  123. local t = peripheral.wrap(pSide)
  124.  
  125. local energy = t.getEnergyStored()
  126. local rpm = t.getRotorSpeed()
  127.  
  128. --If the turbine's above the amount of energy allowed, disable the coils
  129. if(energy >= turbineMaxEnergy) then
  130. t.setInductorEngaged(false)
  131. else
  132. t.setInductorEngaged(true)
  133. end
  134.  
  135. log(pSide.. ":\t" ..energy.. " RF\t" ..rpm.. " RPM")
  136. end
  137. end
  138.  
  139. log ("Turbine max energy: " ..turbineMaxEnergy)
  140. log ("Reactor max temp:" ..reactorMaxTemp)
  141.  
  142. updatePeripherals()
  143. listPeripherals()
  144. sleep(2)
  145. local i = 1
  146. while true do
  147. update()
  148. setMonitorScales(i)
  149. log("Current scale: " ..i)
  150. i = i +0
  151. sleep(2)
  152. end
Advertisement
Add Comment
Please, Sign In to add comment