FailedFace

BigReactorsMonitor

Jan 14th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.91 KB | None | 0 0
  1. -- Monitor Program for Big Reactors
  2. -- Author: FailedFace
  3. os.loadAPI("ReactorsAPI") -- API required for program to work
  4. -- NOTE: Text Colors only work on Advanced(gold) monitors
  5.  
  6. -- Variables to Change --
  7. lowPower = 1000000  -- When internal buffer goes below this point the Reactor Turns on and text color is "lowPowColor".
  8. lowMidPower = 4000000 -- When reactor buffer is above this point the text color is changed to "midPowColor".
  9. highMidPower = 7000000 -- When reactor buffer is above this point the text color is changed to "highPowColor".
  10. highPower = 9000000 -- When internal buffer goes above this point the Reactor turns off.
  11. --[[ POWER LEVELS
  12. During the above changes the reactors scales
  13. with the power draw by cointrolling the rods,
  14. this can be seen in the "ReactorsAPI" file.
  15. --]]
  16. lowPowColor = colors.red -- See "lowPower" var note
  17. midPowColor = colors.yellow -- See "midPower" var note
  18. highPowColor = colors.green -- See "highPower" var note
  19. monScale = 1.5 -- Text scale for monitor, see below note.
  20. --[[ TEXT SCALE
  21. Change for monitors that are not 3Wx2H,
  22. This will be auto adjusted when I write the
  23. module and only be used as a manual override.
  24. --]]
  25.  
  26. function writeToMonitor(reactor,monitor)
  27.   monitor.clear()
  28.   monitor.setCursorPos(1,1)
  29.   local rawFuel = reactor.getFuelAmount()
  30.   local currentFuel = rawFuel/1000
  31.   local rawFuelMax = reactor.getFuelAmountMax()
  32.   local fuelRatio = rawFuel/rawFuelMax
  33.   monitor.setTextColor(colors.lightGray)
  34.   monitor.write("Fuel    ")
  35.   if fuelRatio < 0.30 then
  36.     monitor.setTextColor(lowPowColor)
  37.   elseif fuelRatio >= 0.30 and fuelRatio < 0.75 then
  38.     monitor.setTextColor(midPowColor)
  39.   else
  40.     monitor.setTextColor(highPowColor)
  41.   end
  42.   monitor.write(string.format("%d",currentFuel).." B")
  43.   monitor.setCursorPos(1,2)
  44.   monitor.setTextColor(colors.lightGray)
  45.   monitor.write("Buffer  ")
  46.   local rawBuffer = reactor.getEnergyStored()
  47.   local currentBuffer = rawBuffer/1000
  48.   if rawBuffer < lowMidPower then
  49.     monitor.setTextColor(lowPowColor)
  50.   elseif rawBuffer >= lowMidPower and rawBuffer < highMidPower then
  51.     monitor.setTextColor(midPowColor)
  52.   else
  53.     monitor.setTextColor(highPowColor)
  54.   end
  55.   monitor.write(string.format("%d",currentBuffer).." kRF")
  56.   monitor.setCursorPos(1,3)
  57.   monitor.setTextColor(colors.lightGray)
  58.   monitor.write("Yield   ")
  59.   monitor.setTextColor(colors.white)
  60.   monitor.write(string.format("%d",reactor.getEnergyProducedLastTick()).." RF/t")
  61.   monitor.setCursorPos(1,4)
  62.   monitor.setTextColor(colors.lightGray)
  63.   monitor.write("Rods    ")
  64.   monitor.setTextColor(colors.white)
  65.   monitor.write(reactor.getControlRodLevel(0).."%")
  66.   monitor.setCursorPos(1,5)
  67.   monitor.setTextColor(colors.lightGray)
  68.   monitor.write("React   ")
  69.   monitor.setTextColor(colors.white)
  70.   monitor.write(string.format("%d",reactor.getFuelReactivity()).."%")
  71.   monitor.setCursorPos(1,6)
  72.   monitor.setTextColor(colors.lightGray)
  73.   monitor.write("Active  ")
  74.   local activity = reactor.getActive()
  75.   if activity then
  76.     monitor.setTextColor(highPowColor)
  77.   else
  78.     monitor.setTextColor(lowPowColor)
  79.   end
  80.   monitor.write(tostring(activity))
  81.   monitor.setCursorPos(1,8)
  82.   monitor.setTextColor(colors.white)
  83.   monitor.write("CTRL+T To Terminate")
  84. end
  85.  
  86. function setupMonitor(monitor) -- Not being used currently, supposed to auto adjust textscale when built
  87.   local width, height = monitor.getSize()
  88.   print(width)
  89.   print(height)
  90.     if width < 18 or height < 12 then
  91.       print ("Monitor too small. Please use a minimum of 2x2")
  92.     else
  93.       ratio = math.sqrt(width*width + height*height)
  94.       value = math.floor(ratio)
  95.       -- monitor.setTextScale(value)
  96.     end
  97. end
  98.  
  99. reactor = peripheral.wrap(ReactorsAPI.getReactor())
  100. monitor = peripheral.wrap(ReactorsAPI.getMonitor())
  101. monitor.setTextScale(monScale)
  102.  
  103. while true do
  104.   sleep(1)
  105.   ReactorsAPI.controlReactor(reactor,lowPower,highPower)
  106.   writeToMonitor(reactor,monitor)
  107. end
Advertisement
Add Comment
Please, Sign In to add comment