Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Waiting 1 second to make sure information is ready")
- sleep(1)
- fine = true
- targetOutput = 850000
- maxTemp = 7000
- minShieldPer = 30
- autoCharge = true
- autoActivate = true
- minFuelPer = 50
- reac = peripheral.wrap("back")
- local inRate
- outGate = peripheral.wrap("right")
- monitor = peripheral.wrap("top")
- if monitor == null then
- monitor = periphSearch("monitor")
- end
- if monitor ~= null then
- term.redirect(monitor)
- end
- if peripheral.wrap("top") then
- monitor = peripheral.wrap("top")
- end
- function reactorShutdown()
- outGate.setSignalLowFlow(0)
- reac.stopReactor()
- end
- function periphSearch(type)
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == type and name ~= "right" then
- return peripheral.wrap(name)
- end
- end
- return null
- end
- inGate = periphSearch("flux_gate")
- function safeCheck(rInfo)
- if rInfo.fieldStrength == nil or rInfo.maxFieldStrength == nil then
- print("Shield info nil for some reason. Sleeping for 5 seconds before continuing")
- sleep(5)
- rInfo = reac.getReactorInfo()
- end
- shieldPer = math.ceil(rInfo.fieldStrength / rInfo.maxFieldStrength * 10000) * .01
- if shieldPer <= minShieldPer and rInfo.status == "online" then
- print("Shield is too weak.. Shutting down! ... I'm not sure what to do about this one!")
- reactorShutdown()
- end
- if rInfo.temperature > maxTemp then
- print("Reactor is too hot! Shutting down temporarily")
- reactorShutdown()
- end
- if (rInfo.fuelConversion / rInfo.maxFuelConversion * 100) > minFuelPer then
- print("Fuel conversion: ",rInfo.fuelConversion)
- print("maxFuelConversion: ",rInfo.maxFuelConversion)
- print("Fuel level is below ",minFuelPer,"% Please refuel after finished cooling.")
- reactorShutdown()
- fine = false
- end
- end
- function stateCheck(rInfo)
- print("Status:",rInfo.status)
- --Auto charge
- if autoCharge == true and rInfo.status == "cold" or autoCharge == true and rInfo.status == "cooling" then
- if rInfo.maxFuelConversion < 10000 then
- print("I think you didn't put enough fuel in here. Double check that please")
- return
- else
- print("Reactor offline. Starting reactor in 5 seconds.")
- sleep(5)
- reac.chargeReactor()
- end
- elseif autoCharge ~= true then
- print("autoCharge Disabled. Leaving off")
- end
- if autoCharge == true and rInfo.status == "stopping" and rInfo.temperature < (maxTemp * 0.9) then
- print("Reactor is stopping... but it's cooled off a bit. Turning it back on in 5 seconds, hope you live!")
- sleep(5)
- reac.activateReactor()
- end
- if rInfo.status == "warming_up" then
- print("Setting input gate to 900k to speed up charging. Also clamping output.")
- inGate.setSignalLowFlow(900000)
- outGate.setSignalLowFlow(0)
- end
- --Auto-activate
- if autoActivate == true and rInfo.status == "warming_up" and rInfo.temperature >= 2000 then
- print("Reactor Charged. Changing input gate and activating reactor")
- inGate.setSignalLowFlow(rInfo.fieldDrainRate / (1 - (targetOutput/100)))
- reac.activateReactor()
- elseif autoActivate ~= true then
- print("Auto activate disabled. Leaving charged")
- end
- if rInfo.status == "running" then
- inRate = rInfo.fieldDrainRate / (1 - (targetOutput/1000000))
- --inRate = rInfo.fieldDrainRate / (1 - (targetOutput/100))
- print("Net output is",math.floor((outGate.getFlow() - inRate)/1000)*1000)
- print("Input gate set at",math.ceil(inRate))
- inGate.setSignalLowFlow(inRate)
- print("Output gate set at",targetOutput)
- outGate.setSignalLowFlow(targetOutput)
- end
- end
- while fine == true do
- sleep(1)
- term.clear()
- local info = reac.getReactorInfo()
- local timeLeft = (info.fuelConversion - info.maxFuelConversion) / info.fuelConversionRate * -100000 / 2
- print("Temperature:",info.temperature,"C")
- print("Shield Percent:",shieldPer,"%")
- print("Saturation:",math.ceil(info.energySaturation / info.maxEnergySaturation * 10000)/100,"%")
- print("Fuel percentage:",100 - math.ceil((info.fuelConversion / info.maxFuelConversion * 100)),"%")
- print("Fuel time left:",math.ceil(timeLeft/60/60), "hours")
- print("or",math.ceil(timeLeft/60/60/24),"days")
- -- print("Running state check")
- stateCheck(info)
- -- print("Running safe check")
- safeCheck(info)
- end
- if fine == false then
- shell.run("shutdown")
- end
Add Comment
Please, Sign In to add comment