Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local powerThreshold = -20000
- local interval = 10
- local turbineDifferenceThreshold = 200000000
- local turbineRunSpeed = 1800
- local controlRodPercent = 18
- local component = require("component")
- local term = require("term")
- local sides = require("sides")
- local reactor = component.br_reactor
- local turbine = component.br_turbine
- local crystal = component.deepresonance_controller
- local storage = component.draconic_rf_storage
- local redstone = component.redstone
- local crystalOn = false
- local function updateRedstone()
- -- This is a hack to support reporting of reactor and crystal status on a RFTools screen when
- -- toggled by this script and manually.
- if reactor.getControlRodLevel(0) < 100 then
- redstone.setOutput(sides.west, 15)
- else
- redstone.setOutput(sides.west, 0)
- end
- if crystalOn or redstone.getInput(sides.bottom) > 0 then
- redstone.setOutput(sides.east, 15)
- else
- redstone.setOutput(sides.east, 0)
- end
- end
- local function startReactor()
- reactor.setAllControlRodLevels(controlRodPercent)
- turbine.setInductorEngaged(false)
- print("Turbine spinning up.")
- updateRedstone()
- end
- local function startCrystal()
- crystal.activate()
- crystalOn = true
- print("Deep Resonance reactor started.")
- updateRedstone()
- end
- local function stopReactor()
- reactor.setAllControlRodLevels(100)
- -- If storage is full, free spin the turbine to save momentum. We can't use the spin down power anyway.
- if storage.getEnergyStored() == storage.getMaxEnergyStored() then
- turbine.setInductorEngaged(false)
- end
- updateRedstone()
- end
- local function stopCrystal()
- if crystalOn == true then
- crystal.deactivate()
- crystal.setRSControlled(true)
- crystalOn = false
- print("Deep Resonance reactor stopped.")
- updateRedstone()
- end
- end
- --
- -- Start main logic here
- --
- local highWater = 0
- local maxStorage = storage.getMaxEnergyStored()
- while true do
- rfTick = storage.getTransferPerTick()
- if rfTick <= powerThreshold then
- -- Over the threshold. Go into power production mode.
- print("Start power production.")
- -- Start up the crystal gen since the turbine takes 5 minutes to spin up.
- startCrystal()
- -- How far off the high water mark are we? The crystal gen will put out 162 mil in the time it takes the
- -- turbine to start so we might want to just do that.
- local turbineSpinUp = false
- if highWater - storage.getEnergyStored() > turbineDifferenceThreshold then
- -- Start the reactor and spin up the turbine.
- startReactor()
- turbineSpinUp = true
- end
- -- Power recovery loop
- while storage.getEnergyStored() < highWater do
- -- Check to see how big the hole is. We might want to turn on the turbine at this point.
- if (not tubineSpinUp) and (highWater - storage.getEnergyStored() > turbineDifferenceThreshold) then
- -- Start the reactor and spin up the turbine.
- startReactor()
- turbineSpinUp = true
- end
- -- Are we spinning up the turbine? If so, keep an eye on that. When it comes up, turn off the crystal gen.
- if turbineSpinUp then
- if turbine.getRotorSpeed() >= turbineRunSpeed then
- turbine.setInductorEngaged(true)
- turbineSpinUp = false
- print("Turbine spun up.")
- stopCrystal()
- end
- end
- os.sleep(1)
- end
- -- If we fell out of the power recovery loop, we are recovered. Shut down everything.
- stopCrystal()
- stopReactor()
- print("Recovered. End power production.")
- end
- highWater = storage.getEnergyStored()
- term.clear()
- print("Stored: " .. highWater .. " Transfer: " .. rfTick)
- updateRedstone()
- os.sleep(interval)
- end
Add Comment
Please, Sign In to add comment