Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local evt = require("event")
- local thr = require("thread")
- local term = require("term")
- local shell = require("shell")
- local fs = require("filesystem")
- local cwd = shell.getWorkingDirectory()
- local reactor = com.draconic_reactor
- term.clear()
- if not fs.exists(cwd.."/secondsun.cfg") then
- -- create config file
- local _ = io.open("secondsun.cfg", "w")
- print("Entering config utility...")
- io.write("Max temperature: ")
- _:write("MaxTemp "..io.read().."\n")
- io.write("Max energy saturation percentage: ")
- _:write("MaxSatPercent "..io.read().."\n")
- io.write("Minmum field strength percentage: ")
- _:write("MinStrengthPercent "..io.read().."\n")
- io.write("Input flux gate address: ")
- _:write("InputGate "..io.read().."\n")
- io.write("Output flux gate address: ")
- _:write("OutputGate "..io.read().."\n")
- io.write("Input kRF/t: ")
- _:write("InputEnergy "..io.read().."\n")
- io.write("Output kRF/t: ")
- _:write("OutputEnergy "..io.read().."\n")
- _:close()
- end
- local configFile = io.open("secondsun.cfg")
- local configData = configFile:read("*a")
- local maxTemp = configData:match("MaxTemp%s%d*"):gsub("%D", "")
- local maxSatPercentage = configData:match("MaxSatPercent%s%d*"):gsub("%D", "")
- local maxSat = maxSatPercentage * 10000000
- local minStrPercentage = configData:match("MinStrengthPercent%s%d*"):gsub("%D", "")
- local minStr = minStrPercentage * 1000000
- local inGateAddr = configData:match("InputGate%s[%x%-]*"):gsub("InputGate%s", "")
- local outGateAddr = configData:match("OutputGate%s[%x%-]*"):gsub("OutputGate%s", "")
- local inAmount = configData:match("InputEnergy%s%d*"):gsub("%D", "") * 1000
- local outAmount = configData:match("OutputEnergy%s%d*"):gsub("%D", "") * 1000
- local inGate = component.proxy(inGateAddr)
- local outGate = component.proxy(outGateAddr)
- inGate.setOverrideEnabled(true)
- inGate.setFlowOverride(inAmount)
- outGate.setOverrideEnabled(true)
- outGate.setFlowOverride(outAmount)
- term.clear()
- local interruptThread = thr.create(function()
- evt.pull("interrupted")
- io.write("Are you sure you want to shutdown SecondSun (Y/N)? ")
- local input = io.read()
- if input:lower() == "y" then
- print("Exiting..")
- os.exit()
- else
- print("Abort.")
- return
- end
- end)
- local function getTempData(_, _, newTemp, oldTemp)
- if newTemp > 8000 then
- -- try and stop reactor
- print("Warning: Temperature above max temperature of "..maxTemp..".")
- print("Attempting to stop..")
- local result = reactor.stopReactor()
- if result == false then
- print("Stop failed! RUN!")
- for component in component.list("colorful_lamp") do
- component.invoke(component, "setLampColor", tonumber("111110000000000", 2))
- end
- for component in component.list("os_alarm") do
- component.invoke(component, "setAlarm", "klaxon2")
- component.invoke(component, "activate")
- end
- end
- end
- end
- local function getStatus(_, addr, newStatus, oldStatus)
- print("Status of reactor "..addr.." changed from "..oldStatus.." to "..newStatus..".")
- end
- evt.listen("reactor_temp_change", getTempData)
- evt.listen("reactor_status_change", getStatus)
- print("SecondSun loaded into memory!")
- if reactor.getReactorInfo()["status"] == "cold" then
- io.write("Start reactor (Y/N)? ")
- local input = io.read()
- if input:lower() == "y" then
- reactor.chargeReactor()
- print("Reactor started!")
- else
- print("Reactor not started. Please manually start reactor.")
- end
- end
- thr.waitForAll(interruptThread)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement