Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local reactor = component.nc_fission_reactor
- local modem = component.modem
- local term = require("term")
- local gpu = component.gpu
- local serialization = require("serialization")
- local w, h = gpu.getResolution()
- local colors = {}
- colors.red = 0xff0000
- colors.gray = 0x555555
- colors.lime = 0x00ff00
- local data = {}
- data.heat = 0.0
- data.energy = 0.0
- data.active = False
- local cnt = 0
- function label(x, y, color, message, ...)
- local color = color or gpu.getForeground()
- local oldColor = gpu.getForeground()
- gpu.setForeground(color)
- term.setCursor(x,y)
- print(string.format(message, ...))
- gpu.setForeground(oldColor)
- end
- modem.open(10)
- term.clear()
- repeat
- data.energy = (reactor.getEnergyStored()/reactor.getMaxEnergyStored()) * 100
- data.heat = (reactor.getHeatLevel()/reactor.getMaxHeatLevel())*100
- data.active = reactor.isProcessing()
- label(1, 1, colors.lime, "Fission Reactor")
- label(1, 3, colors.lime, "Energy Buffer %.2f", data.energy)
- label(1, 5, colors.red, "Heat Buffer %.2f", data.heat)
- if (data.heat > 30) then
- --generating heat, unbalanced fuel
- reactor.deactivate()
- label(w/2, 1, colors.red, "Off")
- end
- if (data.active and data.energy > 98) then
- --conserve fuel
- reactor.deactivate()
- label(w/2, 1, colors.red, "Off")
- end
- if (not data.active and data.energy < 20 and data.heat < 1) then
- reactor.activate()
- label(w/2, 1, colors.lime, "On ")
- end
- local msg = {}
- msg.type = "reactor_update"
- msg.id = os.getenv("HOSTNAME")
- msg.data = data
- modem.broadcast(10, serialization.serialize(msg))
- until event.pull(0.5, "interrupt")
- modem.close(10)
- os.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement