Last active
August 29, 2015 14:15
-
-
Save BraynStorm/84de89c7948aacf07443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local reactor; | |
local turbines = {}; | |
local monitor; | |
local optimalRPM = 1840 | |
local maxEnergyInBufferAllowed = 900000 | |
local currentRodsLevel = 50 | |
local numOfTurbines = 0 | |
local hotFluidUsed = 0 | |
local maxFuelUsage = 0 | |
local maxCasingTempAllowed = 400 | |
--setInductorEngaged() | |
--setActive() | |
local temp = 0 | |
function main() | |
loadPeripherals(); | |
--print(reactor["BigReactors-Reactor_0"].getStoredEnergy()); | |
while true do | |
numOfTurbines = 0 | |
hotFluidUsed = 0 | |
for k,turbine in ipairs(turbines) do | |
--print (k .. turbine) | |
if turbine.getActive() == true then | |
numOfTurbines = 1 + numOfTurbines | |
hotFluidUsed = hotFluidUsed + turbine.getFluidFlowRateMax() | |
end | |
if turbine.getRotorSpeed() > (optimalRPM - 10) then | |
if turbine.getRotorSpeed() > (optimalRPM + 10) then | |
turbine.setActive(false); | |
end | |
if capacitorNeedsEnergy(turbine) then | |
turbine.setInductorEngaged(true); | |
else | |
turbine.setInductorEngaged(false); | |
end | |
else | |
turbine.setActive(true) | |
turbine.setInductorEngaged(false) | |
end | |
end | |
if maxFuelUsage < reactor.getFuelConsumedLastTick() then | |
maxFuelUsage = reactor.getFuelConsumedLastTick() | |
end | |
if reactor.getHotFluidProducedLastTick() < hotFluidUsed and reactor.getCasingTemperature() < maxCasingTempAllowed then | |
-- increase steam gen. | |
currentRodsLevel = math.max(currentRodsLevel - 1,0) | |
elseif reactor.getHotFluidProducedLastTick() > hotFluidUsed or reactor.getCasingTemperature() > maxCasingTempAllowed then | |
if reactor.getCasingTemperature() > 1000 then | |
print("Reactor OVERHEATED! Cooling Down!") | |
end | |
-- decrease steam gen. | |
currentRodsLevel = math.min(currentRodsLevel + 1,100) | |
end | |
reactor.setAllControlRodLevels(currentRodsLevel) | |
print ("Steam used: ".. hotFluidUsed .. ", produced " .. reactor.getHotFluidProducedLastTick() .. " insertion " .. currentRodsLevel) | |
print ("Current fuel usage: " .. string.sub(reactor.getFuelConsumedLastTick(),1,5) .. " mB/t, max: " .. string.sub(maxFuelUsage,1,5) .. "mB/t") | |
if reactor.getActive() == false and numOfTurbines > 1 then | |
reactor.setActive(true) | |
end | |
sleep(.5) | |
end | |
end | |
function capacitorNeedsEnergy(turbine) | |
if turbine.getEnergyStored() < maxEnergyInBufferAllowed then | |
return true; | |
end | |
return false; | |
end | |
function loadPeripherals() | |
while turbines == nil or reactor == nil do | |
reactor = peripheral.find("BigReactors-Reactor") | |
turbines[1], turbines[2], turbines[3],turbines[4] = peripheral.find("BigReactors-Turbine") | |
monitor = peripheral.find("monitor") | |
if reactor == nil then | |
print ("Didn't find a reactor, rewrapping...") | |
else | |
currentRodsLevel = reactor.getControlRodLevel(1) | |
end | |
if turbines == nil or turbines == {} then | |
print ("Didn't find any turbines, rewrapping") | |
end | |
sleep(1) | |
end | |
end | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment