Arktiki

ReactorRunnable - Turbine

Sep 15th, 2020
793
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local monitor = peripheral.wrap("monitor_1")
  2. local reactor = peripheral.wrap("BigReactors-Reactor_0")
  3. local keepAlive = reactor.getConnected()
  4. local bufferHardLimit = 9999000
  5.  
  6. local function checkConnectivity()
  7.     if keepAlive == nil then
  8.         print("Reactor is invalid!")
  9.        
  10.         if monitor ~= nil then
  11.             monitor.write("Reactor is invalid!")
  12.         end
  13.        
  14.         exit(1)
  15.     end
  16. end
  17.  
  18. local function updateActivity()
  19.     local running = reactor.getActive()
  20.    
  21.     monitor.setCursorPos(1,1)
  22.     monitor.setTextColor(colors.white)
  23.     monitor.write("Reactor: ")
  24.    
  25.     if running then
  26.         state = "Active"
  27.         monitor.setTextColor(colors.green)
  28.     else
  29.         state = "Inactive"
  30.         monitor.setTextColor(colors.red)
  31.     end
  32.        
  33.     monitor.write(state)
  34. end
  35.  
  36. local function updateEnergy()
  37.     local RF = reactor.getEnergyProducedLastTick()
  38.     monitor.setCursorPos(1,2)
  39.     monitor.setTextColor(colors.white)
  40.     monitor.write("RF/t: ")
  41.     monitor.setTextColor(colors.green)
  42.     monitor.write(math.floor(RF))
  43. end
  44.  
  45. local function updateEnergyStored()
  46.     local RF = reactor.getEnergyStored()
  47.     monitor.setCursorPos(1,3)
  48.     monitor.setTextColor(colors.white)
  49.     monitor.write("RF Buffer: ")
  50.     monitor.setTextColor(colors.green)
  51.     monitor.write(math.floor(RF))
  52. end
  53.  
  54. local function updateHeat()
  55.     local heatCase, heatCore = reactor.getCasingTemperature(), reactor.getFuelTemperature()
  56.     monitor.setCursorPos(1,4)
  57.     monitor.setTextColor(colors.white)
  58.     monitor.write("Case/Core Temp: ")
  59.     monitor.setTextColor(colors.green)
  60.     monitor.write(math.floor(heatCase).."°c/"..math.floor(heatCore).."°c")
  61. end
  62.  
  63. local function updateFuel()
  64.     local fuelAmt,wasteAmt = reactor.getFuelAmount(), reactor.getWasteAmount()
  65.     monitor.setCursorPos(1,5)
  66.     monitor.setTextColor(colors.white)
  67.     monitor.write("Fuel/Waste: ")
  68.     monitor.setTextColor(colors.green)
  69.     monitor.write(fuelAmt.." mB/"..wasteAmt.." mB")
  70. end
  71.  
  72. local function updateFuelConsumed()
  73.     local fuelRate = reactor.getFuelConsumedLastTick()
  74.     monitor.setCursorPos(1,6)
  75.     monitor.setTextColor(colors.white)
  76.     monitor.write("Fuel Usage Rate: ")
  77.     monitor.setTextColor(colors.yellow)
  78.     monitor.write(math.floor(fuelRate*1000)/1000)
  79.     monitor.write("mB")
  80.    
  81. end
  82.  
  83. local function updateReactivity()
  84.     local reactivity = reactor.getFuelReactivity()
  85.     monitor.setCursorPos(1,7)
  86.     monitor.setTextColor(colors.white)
  87.     monitor.write("Reactivity: ")
  88.     monitor.setTextColor(colors.green)
  89.     monitor.write(math.floor(reactivity).."%")
  90. end
  91.  
  92. local function play()
  93.     monitor.clear()
  94.     updateActivity()
  95.     updateEnergy()
  96.     updateEnergyStored()
  97.     updateHeat()
  98.     updateFuel()
  99.     updateFuelConsumed()
  100.     updateReactivity()
  101.    
  102.     if bufferHardLimit < reactor.getEnergyStored() then
  103.         print("Reactor is full")
  104.         reactor.setActive(false)
  105.     else
  106.         print("Reactor is running")
  107.         reactor.setActive(true)
  108.     end
  109.    
  110. end
  111.  
  112. while keepAlive do
  113.     if keepAlive == false then break end
  114.     print("Heartbeat")
  115.     checkConnectivity()
  116.     play()
  117.     sleep(1)
  118. end
  119.  
  120. while keepAlive == false do
  121.     if keepAlive == true then break end
  122.     print("Heartbeat")
  123.     checkConnectivity()
  124.     sleep(3)
  125. end
  126.  
RAW Paste Data