Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c = require("component")
- e = require("event")
- t = require("term")
- r = c.br_reactor
- tList = {}
- controlLevel = 50
- tTotals = {}
- tTotals["steamNeed"] = 0
- tTotals["energyOutput"] = 0
- targetSpeed = 1800
- event = {}
- function startReactor()
- r.setActive(true)
- r.setAllControlRodLevels(50)
- end
- function startTurbine()
- tListBuild()
- for k, v in pairs(tList) do
- c.invoke(k, "setActive", true)
- c.invoke(k, "setInductorEngaged", false)
- c.invoke(k, "setFluidFlowRateMax", 2000)
- end
- end
- function updateTotals()
- tTotals["steamNeed"] = 0
- for k, v in pairs(tList) do
- tTotals["steamNeed"] = tTotals["steamNeed"] + c.invoke(k, "getFluidFlowRateMax")
- tTotals["energyOutput"] = tTotals["energyOutput"] + c.invoke(k, "getEnergyProducedLastTick")
- end
- print("steam needed " .. tostring(tTotals["steamNeed"]))
- end
- function monReactor()
- updateTotals()
- if r.getHotFluidProducedLastTick() < tTotals["steamNeed"] then
- if controlLevel > 0 then controlLevel = controlLevel - 1 end
- else
- if controlLevel < 100 then controlLevel = controlLevel + 1 end
- end
- r.setAllControlRodLevels(controlLevel)
- end
- function tListBuild()
- for k, v in c.list("br_turbine") do
- tList[k] = {}
- tList[k]["steamUsed"] = c.invoke(k, "getFluidFlowRateMax")
- tList[k]["lastRotorSpeed"] = c.invoke(k, "getRotorSpeed")
- tList[k]["isActive"] = false
- tList[k]["coilsEngaged"] = false
- tList[k]["rotorSpeed"] = 0
- tList[k]["energyOutput"] = 0
- tList[k]["turbineStable"] = false
- end
- end
- function tSpeedControl()
- for k, v in pairs(tList) do
- print("Rotor speed " .. tList[k]["rotorSpeed"])
- end
- end
- function tListData()
- for k, v in pairs(tList) do
- for l, b in pairs(tList[k]) do
- print(tList[k][l])
- end
- end
- end
- function tStartup()
- for k, v in pairs(tList) do
- tList[k]["lastRotorSpeed"] = tList[k]["rotorSpeed"]
- tList[k]["rotorSpeed"] = c.invoke(k, "getRotorSpeed")
- if tList[k]["rotorSpeed"] <= 1000 then
- tList[k]["coilsEngaged"] = false
- else
- tList[k]["coilsEngaged"] = true
- end
- acc = tList[k]["rotorSpeed"] - tList[k]["lastRotorSpeed"]
- if acc <= 0 then
- if tList[k]["rotorSpeed"] < 1780 then
- c.invoke(k, "setFluidFlowRateMax", c.invoke(k, "getFluidFlowRateMax") + 10)
- print("adding 10")
- end
- end
- c.invoke(k, "setInductorEngaged", tList[k]["coilsEngaged"])
- end
- end
- --Main code block
- startTurbine()
- startReactor()
- for k, v in pairs(tList) do
- c.invoke(k, "setFluidFlowRateMax", 200)
- end
- while true do
- event = {e.pull(1)}
- if event[4] == 207 then
- os.exit()
- end
- tStartup()
- t.clear()
- monReactor()
- tSpeedControl()
- end
Advertisement
Add Comment
Please, Sign In to add comment