Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mainMonitorSide = 'monitor_1'
- local laserPowerSide = 'bottom'
- local laserPulseSide = 'top'
- local hohlraumSide = 'north'
- local reactorInjectionRate = 4
- local mon = peripheral.wrap(mainMonitorSide)
- local ria = peripheral.wrap('redstone_integrator_1')
- local dtn = peripheral.wrap('Elite Gas Tank_2')
- local ttn = peripheral.wrap('Elite Gas Tank_3')
- local ind = peripheral.find('Induction Matrix')
- local amp = peripheral.find('Laser Amplifier')
- local rla = peripheral.find('Reactor Logic Adapter')
- local trb = peripheral.find('Industrial Turbine')
- local monW, monH = mon.getSize()
- print("Reactor monitoring script")
- mon.setTextScale(1.25)
- mon.setBackgroundColor(colors.black)
- local monW, monH = mon.getSize()
- if not fs.exists("ui.lua") then
- print("Downloadind UI API")
- shell.run("pastebin get W13Fx2tv ui.lua")
- end
- if not fs.exists("buttons.lua") then
- print("Downloadind Buttons API")
- shell.run("pastebin get 3nqSJzqc buttons.lua")
- end
- os.loadAPI("ui.lua")
- local ui = ui.initUI(mon)
- os.loadAPI("buttons.lua")
- local reactorQuenchBtn = nil
- local reactorIgniteBtn = nil
- local increaseInjectionBtn = nil
- local decreaseInjectionBtn = nil
- local autoIgnited = false
- local autoQuenched = false
- info = {}
- local function collectInfo()
- info.dPct = math.floor((100 * dtn.getStoredGas()) / dtn.getMaxGas())
- info.tPct = math.floor((100 * ttn.getStoredGas()) / ttn.getMaxGas())
- info.cTemp, info.pTemp, info.iTemp = math.floor(rla.getCaseHeat() / 1000000), math.floor(rla.getPlasmaHeat() / 1000000), math.floor(rla.getIgnitionTemp() / 1000000)
- info.injRate = rla.getInjectionRate()
- info.ignited = rla.isIgnited()
- info.hasFuel = rla.hasFuel()
- info.laserEnergyMRF = math.floor(amp.getEnergy() * 0.0000004)
- info.indPct = math.ceil(100.0 * (ind.getEnergy() / ind.getMaxEnergy()))
- end
- local function igniteReactor()
- ria.setOutput(hohlraumSide, true)
- rla.setInjectionRate(reactorInjectionRate)
- os.sleep(1)
- ria.setOutput(laserPulseSide, true)
- os.sleep(0.3)
- ria.setOutput(hohlraumSide, false)
- ria.setOutput(laserPulseSide, false)
- end
- local function quenchReactor()
- rla.setInjectionRate(0)
- end
- local function drawReactor()
- local cx, cy = mon.getCursorPos()
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- cy = cy + 1
- mon.setCursorPos(cx, cy)
- local disabled = true
- if rla.isIgnited() then
- mon.setTextColor(colors.green)
- mon.write("REACTOR ONLINE ")
- autoIgnited = false
- if not autoQuenched and info.indPct > 95 then
- print("Autoquenching reactor!")
- autoQuenched = true
- quenchReactor()
- end
- else
- mon.setTextColor(colors.red)
- mon.write("REACTOR OFFLINE")
- autoQuenched = false
- if not autoIgnited and info.indPct < 20 then
- print("Autoigniting reactor")
- autoIgnited = true
- igniteReactor()
- end
- end
- cy = cy + 1
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Injection: ")
- if info.injRate < 2 then mon.setTextColor(colors.red) elseif info.injRate < 4 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.green) end
- mon.write(info.injRate .. "mB/t")
- if increaseInjectionBtn then increaseInjectionBtn.enabled = info.ignited and info.hasFuel else
- increaseInjectionBtn = buttons.createButton(cx, cy, buttons.createProceduralStyle(
- buttons.createStyle("+2mB/t Injection Rate", colors.lightGray, colors.green, 1, 1), -- Enabled
- buttons.createStyle("+2mB/t Injection Rate", colors.gray, colors.black, 1, 1)), -- Disabled
- false, function()
- rla.setInjectionRate(reactorInjectionRate + 2)
- reactorInjectionRate = rla.getInjectionRate()
- end)
- buttons.addButton(increaseInjectionBtn)
- end buttons.monitorDrawButton(mon, increaseInjectionBtn)
- cy = cy + 4
- if decreaseInjectionBtn then decreaseInjectionBtn.enabled = info.ignited and info.hasFuel and reactorInjectionRate > 2 else
- decreaseInjectionBtn = buttons.createButton(cx, cy, buttons.createProceduralStyle(
- buttons.createStyle("-2mB/t Injection Rate", colors.lightGray, colors.red, 1, 1), -- Enabled
- buttons.createStyle("-2mB/t Injection Rate", colors.gray, colors.black, 1, 1)), -- Disabled
- false, function()
- rla.setInjectionRate(reactorInjectionRate - 2)
- reactorInjectionRate = rla.getInjectionRate()
- end)
- buttons.addButton(decreaseInjectionBtn)
- end buttons.monitorDrawButton(mon, decreaseInjectionBtn)
- if reactorIgniteBtn then reactorIgniteBtn.enabled = (not info.ignited) and (info.hasFuel) and (info.laserEnergyMRF > 500) else
- reactorIgniteBtn = buttons.createButton(2, monH - 3, buttons.createProceduralStyle(
- buttons.createStyle("IGNITE", colors.lightGray, colors.yellow, 1, 1), -- Enabled
- buttons.createStyle("IGNITE", colors.gray, colors.black, 1, 1)), -- Disabled
- false, function()
- if reactorIgniteBtn.enabled then
- reactorIgniteBtn.s.pStyle.dispTxt = " WAIT "
- buttons.monitorDrawButton(mon, reactorIgniteBtn)
- igniteReactor()
- reactorIgniteBtn.s.pStyle.dispTxt = "IGNITE"
- reactorIgniteBtn.enabled = false
- buttons.monitorDrawButton(mon, reactorIgniteBtn)
- print("Reactor ignited!")
- end
- print("Reactor ignite button handled!")
- end)
- buttons.addButton(reactorIgniteBtn)
- end buttons.monitorDrawButton(mon, reactorIgniteBtn)
- if reactorQuenchBtn then reactorQuenchBtn.enabled = info.ignited else
- reactorQuenchBtn = buttons.createButton(12, monH - 3, buttons.createProceduralStyle(
- buttons.createStyle("QUENCH", colors.lightGray, colors.red, 1, 1), -- Enabled
- buttons.createStyle("QUENCH", colors.gray, colors.black, 1, 1)), -- Disabled
- false, function()
- if reactorQuenchBtn.enabled then
- quenchReactor()
- reactorIgniteBtn.enabled = false
- print("Reactor quenched!")
- end
- print("Reactor quench button handled!")
- end)
- buttons.addButton(reactorQuenchBtn)
- end buttons.monitorDrawButton(mon, reactorQuenchBtn)
- end
- local function drawLaser()
- local cx, cy = mon.getCursorPos()
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- cy = cy + 1
- mon.setCursorPos(cx, cy)
- mon.write("Laser: ")
- local charged = info.laserEnergyMRF > 500
- if charged then mon.setTextColor(colors.green) elseif info.laserEnergyMRF > 250 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.red) end
- mon.write(info.laserEnergyMRF .. " / 500MRF ")
- if charged then
- mon.setTextColor(colors.green)
- mon.write("Charged!")
- ria.setOutput(laserPowerSide, false)
- else
- mon.setTextColor(colors.yellow)
- mon.write("Charging!")
- ria.setOutput(laserPowerSide, true)
- end
- cy = cy + 1
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Casing temp: ")
- if info.cTemp < 50 then mon.setTextColor(colors.red) elseif info.cTemp < 100 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.green) end
- mon.write(info.cTemp .. "MK")
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Plasma temp: ")
- if info.pTemp < info.iTemp then mon.setTextColor(colors.red) else mon.setTextColor(colors.green) end
- mon.write(info.pTemp .. "/" .. info.iTemp .. "MK")
- cy = cy + 1
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Deuterium reserve: ")
- if info.dPct < 90 then mon.setTextColor(colors.red) else mon.setTextColor(colors.green) end mon.write(info.dPct .. "%")
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Tritium reserve: ")
- if info.tPct < 90 then mon.setTextColor(colors.red) else mon.setTextColor(colors.green) end mon.write(info.tPct .. "%")
- cy = cy + 1
- cy = cy + 1 mon.setCursorPos(cx, cy) mon.setTextColor(colors.yellow) mon.write("Injection rate: ")
- if info.injRate < 2 then mon.setTextColor(colors.red) elseif info.injRate < 4 then mon.setTextColor(colors.yellow) else mon.setTextColor(colors.green) end mon.write(info.injRate .. "mB/t")
- end
- local loopTimer = os.startTimer(0.3)
- local blinky = false
- while true do
- local event, param1, param2, param3, param4 = os.pullEvent()
- local wasTouched = event == "monitor_touch" and param1 == mainMonitorSide
- local wasTimer = event == "timer" and param1 == loopTimer
- if wasTouched or wasTimer then -- Touchscreen or timer event!
- loopTimer = os.startTimer(0.3)
- collectInfo()
- mon.clear()
- if wasTouched then
- buttons.onTouch(mon, param2, param3)
- loopTimer = os.startTimer(0.3)
- end
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(1, 1)
- mon.setTextColor(colors.white)
- ui.spacer(1, "Systems overview")
- ui.spacer(2, "")
- mon.setCursorPos(monW, 1)
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.gray)
- if blinky then mon.write("\\") blinky = false else mon.write("/") blinky = true end
- mon.setTextColor(colors.white)
- local monW2 = monW / 2
- mon.setCursorPos(2, 3)
- drawReactor()
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(monW2 - 1, 3) ui.drawVbar(3, monH)
- mon.setCursorPos(monW2, 3) ui.drawVbar(3, monH)
- mon.setCursorPos(monW2 + 2, 3)
- drawLaser()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment