Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Turbines
- t={}
- anzTurb = 0
- --All peripherals
- local peripheralList = peripheral.getNames()
- for i=0,#peripheralList do
- if peripheral.getType(peripheralList[i]) == "BigReactors-Turbine" then
- t[i]=peripheral.wrap(peripheralList[i])
- anzTurb = anzTurb + 1
- end
- if peripheral.getType(peripheralList[i]) == "BigReactors-Reactor" then
- r = peripheral.wrap(peripheralList[i])
- end
- if peripheral.getType(peripheralList[i]) == "monitor" then
- mon = peripheral.wrap(peripheralList[i])
- end
- if peripheral.getType(peripheralList[i]) == "tile_blockcapacitorbank_name" then
- v = peripheral.wrap(peripheralList[i])
- end
- end
- optRodLevel = 0
- anzTurb = anzTurb - 1
- --TurbineSpeed
- tspeed = {}
- function init()
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.blue)
- term.clear()
- mon.clear()
- checkRotorSpeed()
- findOptimalFuelRodLevel()
- end
- function checkRotorSpeed()
- for i=0,anzTurb,1 do
- tspeed[i] = t[i].getRotorSpeed()
- end
- end
- function reactorOn()
- r.setActive(true)
- end
- function reactorOff()
- r.setActive(false)
- end
- function getEnergy()
- return v.getEnergyStored()
- end
- function getEnergyMax()
- return v.getMaxEnergyStored()
- end
- function getEnergyPer()
- local en = getEnergy()
- local enMax = getEnergyMax()
- local enPer = math.floor(en/enMax*100)
- return enPer
- end
- function allTurbinesOn()
- for i=0,anzTurb,1 do
- t[i].setInductorEngaged(true)
- t[i].setFluidFlowRateMax(2000)
- end
- end
- function allTurbinesOff()
- for i=0,anzTurb,1 do
- t[i].setInductorEngaged(false)
- t[i].FluidFlowRateMax(0)
- end
- end
- function turbineOn(i)
- t[i].setInductorEngaged(true)
- t[i].setFluidFlowRateMax(2000)
- end
- function turbineOff(i)
- t[i].setInductorEngaged(false)
- t[i].setFluidFlowRateMax(0)
- end
- function findOptimalFuelRodLevel()
- reactorOn()
- allTurbinesOn()
- local controlRodLevel = 50
- local optRodLevelFound = true
- local steamOutput = r.getHotFluidProducedLastTick()
- local targetSteamOutput = 2000*anzTurb
- while optRodLevelFound do
- r.setAllControlRodLevels(controlRodLevel)
- steamOutput = r.getHotFluidProducedLastTick()
- sleep(2)
- if steamOutput < targetSteamOutput then
- r.setAllControlRodLevels(controlRodLevel - 1)
- end
- if steamOutput >= targetSteamOutput then
- r.setAllControlRodLevels(controlRodLevel + 1)
- sleep(5)
- if steamOutput < targetSteamOutput then
- r.setAllControlRodLevels(controlRodLevel - 1)
- optRodLevel = controlRodLevel
- optRodLevelFound = false
- end
- end
- end
- end
- function checkEnergyLevel()
- if getEnergyPer() < 50 then
- for i=0,anzTurb,1 do
- t[i].setFluidFlowRateMax(2000)
- end
- reactorOn()
- getToTargetSpeed()
- end
- if getEnergyPer() >= 90 then
- for i=0,anzTurb,1 do
- if tspeed[i] < 1800 then
- reactorOn()
- t[i].setInductorEngaged(false)
- t[i].setFluidFlowRateMax(2000)
- end
- if tspeed[i] > 1840 then
- turbineOff(i)
- end
- end
- if allAtTargetSpeed() then
- reactorOff()
- end
- end
- end
- function getToTargetSpeed()
- for i=0,anzTurb,1 do
- if tspeed[i] < 1800 then
- t[i].setInductorEngaged(false)
- t[i].setFluidFlowRateMax(2000)
- end
- if tspeed[i] > 1860 then
- t[i].setInductorEngaged(true)
- end
- end
- end
- function allAtTargetSpeed()
- local tmp = {}
- local isTrue = true
- for i=0,anzTurb,1 do
- if tspeed[i] > 1800 then
- tmp[i] = 1
- end
- if tspeed[i] < 1800 then
- tmp[i] = 0
- end
- end
- for i=0,anzTurb,1 do
- if tmp[i] == 0 then
- isTrue = false
- end
- end
- return isTrue
- end
- --This function is from http://pastebin.com/WTyFveB8 - Lines 346 to 363
- function comma_value(amount)
- local formatted = amount
- local swap = false
- if formatted < 0 then
- formatted = formatted*-1
- swap = true
- end
- while true do
- formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
- if k == 0 then
- break
- end
- end
- if swap then
- formatted = "-"..formatted
- end
- return formatted
- end
- function printStats()
- local rfGen = 0
- local reactorStatus = off
- for i=0,30,1 do
- term.clearLine(i)
- end
- for i=0,anzTurb,1 do
- rfGen = rfGen + t[i].getEnergyProducedLastTick()
- end
- if r.isActive(true) then
- reactorStatus = on
- end
- if r.isActive(false) then
- reactorStatus = off
- end
- term.setCursorPos(1,1)
- mon.write("Energy Level: ")
- mon.write(getEnergyPer())
- mon.write("%")
- term.setCursorPos(1,2)
- mon.write("RF-Gen: ")
- mon.write(math.floor(rfGen))
- mon.write(" RF/t")
- mon.setCursorPos(1,3)
- mon.write("Fuel Consumption: ")
- mon.write(comma_value(t.getFuelConsumedLastTick())
- mon.write(" RF/t")
- mon.setCursorPos(1,5)
- mon.write("Reactor: ")
- if reactorStatus == "on" then
- mon.setTextColor(colors.green)
- end
- if reactorStatus == "off" then
- mon.setTextColor(colors.red)
- end
- mon.write(reactorStatus)
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,7)
- mon.write("-- Turbine 0 --")
- mon.setCursorPos(1,8)
- mon.write("Coils: ")
- if t[0].isActive(true) then
- mon.setTextColor(colors.green)
- mon.write("engaged")
- end
- if t[0].isActive(true) then
- mon.setTextColor(colors.red)
- mon.write("disengaged")
- end
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,9)
- mon.write("Rotor Speed: ")
- mon.write(comma_value(t[0].getRotorSpeed()))
- end
- --Startet alles
- init()
- while true do
- checkRotorSpeed()
- checkEnergyLevel()
- printStats()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement