bennyclams

Untitled

Aug 24th, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.74 KB | None | 0 0
  1. local reactor = peripheral.find("fissionReactorLogicAdapter")
  2. local turbine = peripheral.find("turbineValve")
  3. local induction_matrix = peripheral.find("inductionPort")
  4. local coolant_reserve = peripheral.wrap("right")
  5. peripheral.find("modem", rednet.open)
  6.  
  7. local function clear()
  8. term.setBackgroundColor(colours.black) -- Set the background colour to black.
  9. term.clear() -- Paint the entire display with the current background colour.
  10. term.setCursorPos(1,1) -- Move the cursor to the top left position.
  11. end
  12.  
  13. local function enableReserveCoolant()
  14. redstone.setOutput("back", false)
  15. end
  16.  
  17. local function disableReserveCoolant()
  18. redstone.setOutput("back", true)
  19. end
  20.  
  21. local function checkCoolantLevels(output)
  22. if reactor.getCoolantFilledPercentage() < 0.65 then
  23. if output == true then
  24. print("Alert, Coolant Low! (" .. reactor.getCoolantFilledPercentage() * 100 .. "%)")
  25. end
  26. return false
  27. elseif reactor.getCoolantFilledPercentage() < 0.95 then
  28. if output == true then
  29. print("Warning, Coolant below 95% (" .. reactor.getCoolantFilledPercentage() * 100 .. "%), injecting coolant from reserve ...")
  30. end
  31. enableReserveCoolant()
  32. return true
  33. else
  34. if output == true then
  35. print("Coolant levels normal (" .. reactor.getCoolantFilledPercentage() * 100 .. "%)")
  36. end
  37. disableReserveCoolant()
  38. return true
  39. end
  40. end
  41.  
  42. local function checkHeatedCoolantLevels(output)
  43. if reactor.getHeatedCoolantFilledPercentage() > 0.65 then
  44. if output == true then
  45. print("Alert, Heated Coolant High! (" .. reactor.getHeatedCoolantFilledPercentage() * 100 .. "%)")
  46. end
  47. return false
  48. else
  49. if output == true then
  50. print("Heated Coolant levels normal (" .. reactor.getHeatedCoolantFilledPercentage() * 100 .. "%)")
  51. end
  52. return true
  53. end
  54. end
  55.  
  56. local function checkTurbinePower(output)
  57. if turbine.getEnergyFilledPercentage() > 0.50 then
  58. if output == true then
  59. print("Turbine Power OK. (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
  60. end
  61. return false
  62. elseif turbine.getEnergyFilledPercentage() > 0.75 then
  63. if output == true then
  64. print("Turbine Power High! Consider venting. (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
  65. end
  66. return false
  67. else
  68. if output == true then
  69. print("Turbine Power levels normal (" .. turbine.getEnergyFilledPercentage() * 100 .. "%)")
  70. end
  71. return true
  72. end
  73. end
  74.  
  75. local function checkInductionMatrixPower(output)
  76. if induction_matrix.getEnergyFilledPercentage() > 0.75 then
  77. if output == true then
  78. print("Induction Matrix power OK. (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
  79. end
  80. return false
  81. elseif induction_matrix.getEnergyFilledPercentage() > 0.90 then
  82. if output == true then
  83. print("Induction Matrix Power High! Consider venting. (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
  84. end
  85. return false
  86. else
  87. if output == true then
  88. print("Induction Matrix Power levels normal (" .. induction_matrix.getEnergyFilledPercentage() * 100 .. "%)")
  89. end
  90. return true
  91. end
  92. end
  93.  
  94. local function checkFuelLevels(output)
  95. if reactor.getFuelFilledPercentage() < 0.25 then
  96. if output == true then
  97. print("Alert, Reactor Fuel Low! (" .. reactor.getFuelFilledPercentage() * 100 .. "%)")
  98. end
  99. return false
  100. else
  101. if output == true then
  102. print("Fuel levels normal (" .. reactor.getFuelFilledPercentage() * 100 .. "%)")
  103. end
  104. return true
  105. end
  106. end
  107.  
  108. local function checkDamageLevels(output)
  109. if reactor.getDamagePercent() > 0 then
  110. if output == true then
  111. print("Alert, Reactor Damaged! (" .. reactor.getDamagePercent() * 100 .. "%)")
  112. end
  113. return false
  114. else
  115. if output == true then
  116. print("Damage levels normal (" .. reactor.getDamagePercent() * 100 .. "%)")
  117. end
  118. return true
  119. end
  120. end
  121.  
  122. local function checkWasteLevels(output)
  123. if reactor.getWasteFilledPercentage() > 0.75 then
  124. if output == true then
  125. print("Alert, Reactor Waste High! (" .. reactor.getWasteFilledPercentage() * 100 .. "%)")
  126. end
  127. return false
  128. else
  129. if output == true then
  130. print("Waste levels normal (" .. reactor.getWasteFilledPercentage() * 100 .. "%)")
  131. end
  132. return true
  133. end
  134. end
  135.  
  136. local function checkReserveCoolantEnabled()
  137. if redstone.getOutput("back") == true then
  138. return false
  139. else
  140. return true
  141. end
  142. end
  143.  
  144. local function checkReserveCoolantLevels(output)
  145. if coolant_reserve.getFilledPercentage() < 0.25 then
  146. if output == true then
  147. print("Alert, Reserve Coolant Low! (" .. coolant_reserve.getFilledPercentage() * 100 .. "%)")
  148. end
  149. return false
  150. else
  151. if output == true then
  152. print("Reserve Coolant levels normal (" .. coolant_reserve.getFilledPercentage() * 100 .. "%)")
  153. end
  154. return true
  155. end
  156. end
  157.  
  158. local function checkCoolantOrScram(output)
  159. if checkCoolantLevels() == false and checkReserveCoolantEnabled() == false then
  160. if output == true then
  161. print("Coolant levels too low, enabling reserve coolant!")
  162. end
  163. enableReserveCoolant()
  164. elseif checkCoolantLevels() == false and checkReserveCoolantEnabled() == true then
  165. if output == true then
  166. print("Coolant levels too low, SCRAM! ...")
  167. end
  168. reactor.scram()
  169. end
  170. end
  171.  
  172. local function checkDamageOrScram(output)
  173. if checkDamageLevels() == false then
  174. if output == true then
  175. print("Damage levels too high, SCRAM!")
  176. end
  177. reactor.scram()
  178. end
  179. end
  180.  
  181. local function checkReactorCritical()
  182. if checkCoolantLevels(false) == false or checkFuelLevels(false) == false or checkDamageLevels(false) == false or checkWasteLevels(false) == false or checkHeatedCoolantLevels(false) == false then
  183. return true
  184. else
  185. return false
  186. end
  187. end
  188.  
  189. local function autoStart()
  190. local coolant_levels = checkCoolantLevels(true)
  191. if coolant_levels == true and checkFuelLevels(true) == true and checkDamageLevels(true) == true and checkWasteLevels(true) == true and checkHeatedCoolantLevels(true) == true and checkTurbinePower(true) == true and checkInductionMatrixPower(true) == true then
  192. print("Reactor is ready, starting...")
  193. reactor.activate()
  194. elseif coolant_levels == false then
  195. if checkReserveCoolantEnabled() == false then
  196. if checkReserveCoolantLevels() == false then
  197. print("Coolant levels too low to start reactor, waiting for reserves ...")
  198. else
  199. print("Coolant levels too low, enabling reserve coolant!")
  200. enableReserveCoolant()
  201. end
  202. else
  203. if checkCoolantLevels() == false then
  204. print("Coolant levels too low to start reactor, waiting for reserves ...")
  205. end
  206. end
  207. end
  208. end
  209.  
  210. local function autoStop()
  211. local coolant_levels = checkCoolantLevels(true)
  212. if coolant_levels == false or checkFuelLevels(true) == false or checkDamageLevels(true) == false or checkWasteLevels(true) == false or checkHeatedCoolantLevels(true) == false then
  213. print("Reactor critical! Scramming reactor!")
  214. if coolant_levels == false and checkReserveCoolantEnabled() == false then
  215. print("Coolant levels too low, enabling reserve coolant!")
  216. enableReserveCoolant()
  217. end
  218. reactor.scram()
  219. elseif checkTurbinePower() == false or checkInductionMatrixPower() == false then
  220. if reactor.getStatus() == true then
  221. print("Power levels OK, stopping reactor.")
  222. reactor.scram()
  223. else
  224. print("Power levels OK, not starting reactor.")
  225. reactor.scram()
  226. end
  227. else
  228. checkTurbinePower(true)
  229. checkInductionMatrixPower(true)
  230. end
  231. end
  232.  
  233. local function autoMonitor()
  234. while true do
  235. clear()
  236. if checkReactorCritical() == true then
  237. rednet.broadcast("alarm", "alarm_listener")
  238. else
  239. rednet.broadcast("ok", "alarm_listener")
  240. end
  241. if reactor.getStatus() == true then
  242. autoStop()
  243. else
  244. autoStart()
  245. end
  246. sleep(5)
  247. end
  248. end
  249.  
  250. autoMonitor()
Advertisement
Add Comment
Please, Sign In to add comment