Advertisement
Kodos

[OC] IC2 Reactor Status Report

Feb 27th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local unicode = require("unicode")
  4. local timeapi = require("timeapi")
  5.  
  6. local pr = component.openprinter
  7. local icr = component.reactor_chamber
  8.  
  9. local function round(num, idp)
  10.   local mult = 10^(idp or 0)
  11.   return math.floor(num * mult + 0.5) / mult
  12. end
  13.  
  14. local function checkBatt()
  15.   local curr = 0
  16.   for addr in component.list("mfsu") do
  17.     battcheck = component.proxy(addr).getStored()
  18.     curr = curr + battcheck
  19.   end
  20.   return curr
  21. end
  22.  
  23. local function checkCapacity()
  24.   local currCap = 0
  25.   for addr in component.list("mfsu") do
  26.     capCheck = component.proxy(addr).getCapacity()
  27.     currCap = currCap + capCheck
  28.   end
  29.   return currCap
  30. end
  31.  
  32. local function checkOutput()
  33.   local ertpert = 0
  34.   for addr in component.list("mfsu") do
  35.     ertpertCheck = component.proxy(addr).getOutput()
  36.     ertpert = ertpert + ertpertCheck
  37.   end
  38.   return ertpert
  39. end
  40.  
  41. local function checkOffered()
  42.   local offered = 0
  43.   for addr in component.list("mfsu") do
  44.     offerCheck = component.proxy(addr).getOfferedEnergy()
  45.     offered = offered + offerCheck
  46.   end
  47.   return offered
  48. end
  49.  
  50. local function easynum(num, places)
  51.     local ret
  52.     local placeValue = ("%%.%df"):format(places or 0)
  53.     if not num then
  54.         return 0
  55.     elseif num >= 1000000000000 then
  56.         ret = placeValue:format(num / 1000000000000) .. "T" -- trillion
  57.     elseif num >= 1000000000 then
  58.         ret = placeValue:format(num / 1000000000) .. "B" -- billion
  59.     elseif num >= 1000000 then
  60.         ret = placeValue:format(num / 1000000) .. "M" -- million
  61.     elseif num >= 1000 then
  62.         ret = placeValue:format(num / 1000) .. "k" -- thousand
  63.     else
  64.         ret = num -- hundreds
  65.     end
  66.     return ret
  67. end
  68.  
  69. pr.setTitle("Reactor Status")
  70.  
  71. pr.writeln("Current Heat:")
  72. pr.writeln(tostring(icr.getHeat()))
  73. pr.writeln("Critical Mass Heat:")
  74. pr.writeln(tostring(icr.getMaxHeat()))
  75. pr.writeln("Current EU/t Value:")
  76. pr.writeln(tostring(icr.getReactorEUOutput()))
  77. pr.writeln("Current Energy Output:")
  78. pr.writeln(tostring(icr.getReactorEnergyOutput()))
  79. pr.writeln("Current Energy Stored:")
  80. pr.writeln(tostring(easynum(checkBatt())))
  81. pr.writeln("Current Energy Capacity:")
  82. pr.writeln(tostring(easynum(checkCapacity())))
  83. pr.writeln("Current Energy Output:")
  84. pr.writeln(tostring(easynum(checkOutput())))
  85. pr.writeln("Maximum Energy Output:")
  86. pr.writeln(tostring(easynum(checkOffered())))
  87. pr.writeln(" ")
  88.  
  89. pr.writeln("Pretend Timestamp") -- Make sure you comment this one out
  90.                                 -- if using the timeapi timestamp.
  91. -- pr.writeln(timeapi.date("%25m-%25d-%25Y%20%25R") .. " UTC")
  92.  
  93. local prnt, err = pr.print()
  94. if not prnt then
  95. io.stderr:write(err)
  96. end
  97.  
  98.  
  99. pr.clear()
  100. pr.setTitle(" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement