Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local emax=10000000
- local ok,msg=pcall(function ()
- local r
- local m
- local redirected=false
- local p
- function findDev (dType)
- local d
- for _,d in pairs(peripheral.getNames()) do
- if (peripheral.getType(d) == dType) then
- return peripheral.wrap(d)
- end
- end
- return nil, dType..": not found"
- end
- function setupDevs()
- r=assert(findDev("BigReactors-Reactor"))
- if (not r.getConnected()) then
- return nil, "Computer port not connected to a valid reactor"
- end
- --if (r.getNumberOfControlRods() <1) then
- -- return nil, "Reactor seems invalid"
- --end
- r.getEnergyPercent = function ()
- return math.floor(1000 * r.getEnergyStored() / emax)/10
- end
- if r.nativeEPLT then
- r.getEnergyProducedLastTick = r.nativeEPLT
- end
- r.nativeEPLT = r.getEnergyProducedLastTick
- r.getEnergyProducedLastTick = function ()
- return math.floor(r.nativeEPLT()*1000)/1000
- end
- if redirected then
- term.restore()
- redirected = false
- end
- m=findDev("monitor")
- if m then
- m.setTextScale(1)
- term.clear()
- m.setCursorPos(1,1)
- m.setTextColor(colors.red)
- m.setBackgroundColor(colors.black)
- print("Redirecting to attached monitor")
- term.redirect(m)
- redirected = true
- end
- term.setCursorBlink(false)
- p=findDev("printer")
- end
- function log (msg)
- local stamp=ft()
- print (stamp..": "..msg)
- end
- function tableWidth(t)
- local width=0
- for _,v in pairs(t) do
- if #v>width then width=#v end
- end
- return width
- end
- function ljust(s,w)
- local pad=w-#s
- return s .. string.rep(" ",pad)
- end
- function rjust(s,w)
- local pad=w-#s
- return string.rep(" ",pad) .. s
- end
- function display()
- term.clear()
- term.setCursorPos(18,1)
- print("Reactor Status")
- print("")
- local funcs={"Active","EnergyStored","EnergyPercent","CasingTemperature","FuelTemperature","FuelAmount","WasteAmount","FuelAmountMax","EnergyProducedLastTick"}
- local units={"","RF","%","C","C","mB","mB","mB","RF/t"}
- local values={}
- for _,v in pairs(funcs) do
- values[#values+1] = tostring(r["get"..v]())
- end
- local funcW=tableWidth(funcs)
- local valW=tableWidth(values)
- for i,v in pairs(funcs) do
- print(rjust(v,funcW)..": "..rjust(values[i],valW).." "..units[i])
- end
- end
- log("Starting")
- setupDevs()
- while true do
- local e=r.getEnergyStored()
- local p=r.getAllControlRodLevels()
- local a=p<100
- local elt=r.getEnergyProducedLastTick()
- display()
- r.getAllControlRodLevels(p)
- r.getActive(a)
- os.startTimer(0.8333334)
- local event,p1,p2,p3,p4,p5 = os.pullEvent()
- if event == "key" then
- break
- elseif event == "peripheral_detach" or event == "peripheral" or event == "monitor_resize" then
- setupDevs()
- elseif not (event == "timer" or event=="disk" or event=="disk_eject") then
- error("received "..event)
- end
- end
- end)
- error(msg)
Advertisement
Add Comment
Please, Sign In to add comment