DerReuter

reactortest

Sep 21st, 2019
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.    /---------------------------------\
  3.    | Big Reactors Status Display     |
  4.    \---------------------------------/
  5. ]]
  6.  
  7. -- Config
  8.  
  9. -- This is the side on which your reactor is connected
  10. local reactor_side = "BigReactors-Reactor_0"
  11. -- This is the side on which your monitor is connected
  12. local monitor_side = "right"
  13.  
  14. -- Target Core Temperature
  15. local target_temp = 900
  16. -- Hysteresis +/- temperature offset before controlling rods
  17. local hysteresis = 30
  18.  
  19.  
  20. -- If the reactor is not connected, exit the program
  21. if not peripheral.isPresent(reactor_side) then
  22.   print("Please check, that the reactor is connected to the same side as in your config!")
  23.   return
  24. end
  25. -- If the monitor is not connected, exit
  26. if not peripheral.isPresent(monitor_side) then
  27.   print("Please check, that the monitor is connected to the same side as in your config!")
  28.   return
  29. end
  30.  
  31. -- Wrap the peripherals
  32. local r = peripheral.wrap(reactor_side)
  33. while not r.getConnected() do sleep(10) end
  34. local m = peripheral.wrap(monitor_side)
  35.  
  36. print("The program is now running on the monitor!")
  37.  
  38. -- BEGIN FUNCTIONS PART
  39. function clear()
  40.   m.clear()
  41.   m.setTextColor(colors.white)
  42.   m.setBackgroundColor(colors.black)
  43.   m.setCursorPos(1, 1)
  44. end
  45.  
  46. function resetColors()
  47.   m.setTextColor(colors.white)
  48.   m.setBackgroundColor(colors.black)
  49. end
  50.  
  51. function newLine()
  52.   local x, y = m.getCursorPos()
  53.   m.setCursorPos(1, y+1)
  54. end
  55.  
  56. function drawUI()
  57.   m.write("/---------------------------\\")
  58.  
  59.   for x = 2, 11, 1 do
  60.     m.setCursorPos(1, x)
  61.         m.write("|")
  62.         m.setCursorPos(29, x)
  63.         m.write("|")
  64.   end
  65.  
  66.   m.setCursorPos(2, 3)
  67.   m.write("---------------------------")
  68.  
  69.   m.setCursorPos(2, 5)
  70.   m.write("---------------------------")
  71.   m.setCursorPos(2, 8)
  72.   m.write("---------------------------")
  73.  
  74.   m.setCursorPos(1, 12)
  75.   m.write("\\---------------------------/")
  76. end
  77.  
  78. -- END FUNCTIONS PART
  79.  
  80. -- Repeat forever
  81. while true do
  82.   -- Clear the terminal
  83.   clear()
  84.   -- Draw the basic UI layout
  85.   drawUI()
  86.  
  87.   -- Reactor status
  88.   active = r.getActive()    
  89.   m.setCursorPos(3, 2)
  90.  
  91.   m.write("Status: ")
  92.   if active then
  93.     m.setBackgroundColor(colors.green)
  94.     m.setTextColor(colors.white)
  95.     m.write("ACTIVE (Auto)")
  96.   else
  97.     m.setBackgroundColor(colors.red)
  98.     m.setTextColor(colors.white)
  99.     m.write("INACTIVE")
  100.   end
  101.   -- End Reactor status
  102.  
  103.  
  104.   resetColors()  
  105.   m.setCursorPos(3, 4)  
  106.   -- Steam Output
  107.   energy = r.getHotFluidProducedLastTick()
  108.  
  109.    
  110.   -- Print out the reactor status
  111.   m.setTextColor(colors.white)
  112.   m.write("Steam Output: ")
  113.   m.setTextColor(colors.yellow)
  114.   m.write(energy)
  115.   m.write(" mB/T")
  116.   -- END reactor status
  117.  
  118.   -- Temperatures
  119.   m.setCursorPos(3, 6)
  120.   m.setTextColor(colors.red)
  121.   m.write("Core Temp:")
  122.   m.setCursorPos(15, 6)
  123.   m.setTextColor(colors.white)
  124.   m.write("| Power Level:")
  125.   m.setCursorPos(15, 7)
  126.   m.write("|")
  127.  
  128.   local coreTemp = math.floor(r.getFuelTemperature())
  129.   local powerLevel = 100 - math.floor(r.getControlRodLevel(1))
  130.   local controlRods = r.getControlRodLevel(1)
  131.  
  132.   m.setCursorPos(3, 7)
  133.   m.setTextColor(colors.cyan)
  134.   m.write(coreTemp .. " C")
  135.   m.setCursorPos(17, 7)
  136.   m.write(powerLevel .. " %")
  137.  
  138.   -- If core temp rises above the target_temp + hysteresis value, lower control rods
  139.   if coreTemp >= (target_temp + hysteresis) then
  140.   r.setAllControlRodLevels(controlRods  + 1)
  141.   end
  142.   -- If core temp falls below the target_temp - hysteresis value, raise control rods
  143.   if coreTemp <= (target_temp - hysteresis) then
  144.   r.setAllControlRodLevels(controlRods  - 1)
  145.   end
  146.   -- Avoid critial core temp
  147.   if coreTemp >= 2000 then
  148.   r.setAllControlRodLevels(100)
  149.   end
  150.  
  151.     -- END temperature control
  152.  
  153.   -- Waste and fuel status
  154.   local waste = math.floor(r.getFuelConsumedLastTick()*1000+0.5)/1000
  155.   local fuel = math.floor(r.getFuelAmount())
  156.  
  157.   m.setTextColor(colors.white)
  158.   m.setCursorPos(3, 9)
  159.   m.write("Burnup Rate:")
  160.   m.setCursorPos(15, 9)
  161.   m.write("| Fuel Left:")
  162.   m.setCursorPos(3, 10)
  163.   m.setTextColor(colors.yellow)
  164.   m.write(waste)
  165.   m.setTextColor(colors.white)
  166.   m.setCursorPos(15, 10)
  167.   m.write("|")
  168.   m.setCursorPos(17, 10)
  169.   m.setTextColor(colors.red)
  170.   m.write(fuel)
  171.   -- END Waste and Fuel Status
  172.  
  173.   -- Sleep for 1 second
  174.   sleep(1)
  175. end
RAW Paste Data