Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = "BigReactors-Reactor_244"
- mon = "monitor_434"
- turbineBase = "BigReactors-Turbine_"
- turbine = {}
- turbineCountLevels = {}
- sleepDelay = 1 -- in seconds / floats allowed --
- coil_rpm = 1600
- turbineEnergyStoredMax = 950000
- function readFromConfig()
- s = fs.open("//config", "r")
- data = s.readAll()
- if data == nil then
- return true
- else
- data = textutils.unserialise(data)
- sleepDelay = data.sleepDelay
- reactor.auto = data.reactorAuto
- for i = 1, #turbine do
- turbine[i].auto = data.turbineAuto[i]
- end
- reactor.setActive(data.reactorActive)
- for i = 1, #turbine do
- turbine[i].setActive(data.turbineActive[i])
- end
- for i = 1, #turbine do
- turbine[i].coil_rpm = data.turbineCoilRpm[i]
- end
- turbineEnergyStoredMax = data.turbineEnergyStoredMax
- reactor.setAllControlRodLevels(data.reactorControlRodLevel)
- end
- data = nil
- end
- function saveToConfig()
- s = fs.open("//config", "w")
- data = {}
- data.sleepDelay = sleepDelay
- data.turbineCoilRpm = {}
- for i = 1, #turbine do
- data.turbineCoilRpm[i] = turbine[i].coil_rpm
- end
- data.reactorActive = reactor.getActive()
- data.turbineActive = {}
- for i = 1, #turbine do
- data.turbineActive[i] = turbine[i].getActive()
- end
- data.reactorAuto = reactor.auto
- data.turbineAuto = {}
- for i = 1,#turbine do
- data.turbineAuto[i] = turbine[i].auto
- end
- data.turbineEnergyStoredMax = turbineEnergyStoredMax
- data.reactorControlRodLevel = reactor.getControlRodLevel(math.random(reactor.getNumberOfControlRods()))
- data = textutils.serialise(data)
- s.write(data)
- s.close()
- end
- function utilize()
- for i = 1, 24 do
- turbine[i] = i + 105
- end
- -- changes on names --
- for i = 1 , #turbine do
- turbine[i] = (turbineBase..tostring(turbine[i]))
- turbine[i] = peripheral.wrap(turbine[i])
- end
- mon = peripheral.wrap(mon)
- reactor = peripheral.wrap(reactor)
- turbineCountLevels = {
- [1]=96,[2]=93,[3]=89,[4]=86,[5]=83,
- [6]=79,[7]=76,[8]=73,[9]=69,[10]=66,
- [11]=63,[12]=59,[13]=56,[14]=52,[15]=49,
- [16]=45,[17]=42,[18]=38,[19]=35,[20]=31,
- [21]=27,[22]=23,[23]=20,[24]=16,[25]=11 }
- for i = 1, #turbine do
- turbine[i].coil_rpm = coil_rpm
- end
- for i = 1 , #turbine do
- turbine[i].auto = false
- end
- reactor.auto = false
- if fs.exists("//config") then
- readFromConfig()
- end
- end
- function monClear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function termClear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function getActiveTurbineCount()
- turbineCount = 0
- for i = 1, #turbine do
- if( turbine[i].getActive() ) then
- turbineCount = turbineCount + 1
- end
- end
- return turbineCount
- end
- function getAutoTurbineCount()
- turbineCount = 0
- for i = 1, #turbine do
- if( turbine[i].auto ) then
- turbineCount = turbineCount + 1
- end
- end
- return turbineCount
- end
- function getTurbineInductorEngagedCount()
- turbineCount = 0
- for i = 1, #turbine do
- if( turbine[i].getInductorEngaged() ) then
- turbineCount = turbineCount + 1
- end
- end
- return turbineCount
- end
- function getPlantProductionRate()
- x = 0
- for i = 1, #turbine do
- x = x + turbine[i].getEnergyProducedLastTick()
- end
- return x
- end
- function calcRods(turbineCount)
- if turbineCount == 0 then
- return 100
- else
- return turbineCountLevels[turbineCount]
- end
- end
- function controlTurbine(l)
- if(l.auto) then
- l.setInductorEngaged(l.getRotorSpeed() > l.coil_rpm)
- l.setActive(l.getEnergyStored() < tonumber(turbineEnergyStoredMax))
- end
- end
- function controlTurbines()
- for i = 1,#turbine do
- controlTurbine(turbine[i])
- end
- end
- function controlReactor()
- if reactor.auto then
- x = getActiveTurbineCount()
- x = calcRods(x)
- if x == 100 then
- reactor.setActive(false)
- else
- reactor.setActive(true)
- reactor.setAllControlRodLevels(x)
- end
- end
- end
- -- here and down its not ready yet --
- function createDisplay()
- --monClear()
- --for il = 1, #turbine do
- -- displayTurbine(il)
- --end
- end
- function reactorControlInterface()
- end
- function turbineControlInterface(turb)
- termClear()
- end
- function interface()
- termClear()
- term.write("Enter Your Command:")
- term.setCursorPos(1,2)
- input = read()
- if input == "reactor" then
- termClear()
- term.write("Active: ".. tostring(reactor.getActive()))
- term.setCursorPos(1,2)
- term.write("Auto: ".. tostring(reactor.auto))
- term.setCursorPos(1,3)
- term.write("ControlRods: ".. tostring(reactor.getControlRodLevel(math.random(reactor.getNumberOfControlRods()))))
- term.setCursorPos(1,4)
- term.write("What You Want To Change? ")
- term.setCursorPos(1,5)
- input = read()
- if input == "active" then
- reactor.setActive(not reactor.getActive())
- return true
- elseif input == "auto" then
- reactor.auto = (not reactor.auto)
- return true
- elseif input == "control rods" then
- termClear()
- term.write("Current reactor control rods level is ".. tostring(reactor.getControlRodLevel(math.random(reactor.getNumberOfControlRods()))))
- term.setCursorPos(1,2)
- term.write("Set to : ")
- input = read()
- input = tonumber(input)
- reactor.setAllControlRodLevels(input)
- return true
- else
- termClear()
- term.write("There was an error in your imports")
- sleep(0.2)
- os.pullEvent()
- return true
- end
- -- end of input "reactor"
- elseif input == "turbine" then
- termClear()
- term.write("turbine number: ")
- input = read()
- sd = tonumber(input)
- termClear()
- term.write("Turbine number ".. tostring(sd))
- term.setCursorPos(1,2)
- term.write("Active: ".. tostring(turbine[sd].getActive()))
- term.setCursorPos(1,3)
- term.write("Auto: ".. tostring(turbine[sd].auto))
- term.setCursorPos(1,4)
- term.write("Coils engaged: ".. tostring(turbine[sd].getInductorEngaged()))
- term.setCursorPos(1,5)
- term.write("What you want to change? ")
- term.setCursorPos(1,6)
- input = read()
- if input == "active" then
- turbine[sd].setActive(not turbine[sd].getActive())
- return true
- elseif input == "auto" then
- turbine[sd].auto = not turbine[sd].auto
- return true
- elseif input == "coils engaged" then
- turbine[sd].setInductorEngaged(not turbine[sd].getInductorEngaged())
- return true
- else
- termClear()
- term.write("There was an error to your imports")
- sleep(0.2)
- os.pullEvent()
- return true
- end
- elseif input == "turbines" then
- termClear()
- term.write("Turbines")
- term.setCursorPos(1,2)
- term.write("Active: ".. tostring(getActiveTurbineCount()), "/24 Turbines")
- term.setCursorPos(1,3)
- term.write("Auto: ".. getAutoTurbineCount(), "/24 Turbines")
- term.setCursorPos(1,4)
- term.write("Indictors engaged: ".. tostring(getTurbineInductorEngagedCount()), "/24 Turbines")
- term.setCursorPos(1,5)
- term.write("What you want to change?")
- term.setCursorPos(1,6)
- input = read()
- if input == "active" then
- if getActiveTurbineCount() == 0 then
- for i = 1, #turbine do
- turbine[i].setActive(true)
- end
- return true
- elseif getActiveTurbineCount() == 24 then
- for i = 1, #turbine do
- turbine[i].setActive(false)
- end
- return true
- else
- termClear()
- term.write("enable or disable all turbines?")
- term.setCursorPos(1,2)
- input = read()
- if input == "enable" then
- for i = 1, #turbine do
- turbine[i].setActive(true)
- end
- elseif input == "disable" then
- for i = 1, #turbine do
- turbine[i].setActive(false)
- end
- else
- termClear()
- term.write("There was an error with your imports")
- sleep(0.2)
- os.pullEvent()
- return true
- end
- return true
- end
- elseif input == "auto" then
- if getAutoTurbineCount() == 0 then
- for i = 1, #turbine do
- turbine[i].auto = true
- end
- return true
- elseif getAutoTurbineCount() == 24 then
- for i = 1, #turbine do
- turbine[i].auto = false
- end
- return true
- else
- termClear()
- term.write("enable or disable auto at all turbines?")
- term.setCursorPos(1,2)
- input = read()
- if input == "enable" then
- for i = 1, #turbine do
- turbine[i].auto = true
- end
- elseif input == "disable" then
- for i = 1, #turbine do
- turbine[i].auto = false
- end
- else
- termClear()
- term.write("There was an error with your imports")
- sleep(0.2)
- os.pullEvent()
- return true
- end
- return true
- end
- elseif input == "inductors engaged" then
- if getTurbineInductorEngagedCount() == 0 then
- for i = 1, #turbine do
- turbine[i].setInductorEngaged(true)
- end
- return true
- elseif getTurbineInductorEngagedCount() == 24 then
- for i = 1, #turbine do
- turbine[i].setInductorEngaged(false)
- end
- return true
- else
- termClear()
- term.write("engage or disengage inductors at all turbines?")
- term.setCursorPos(1,2)
- input = read()
- if input == "engage" then
- for i = 1, #turbine do
- turbine[i].setInductorEngaged(true)
- end
- elseif input == "disenage" then
- for i = 1, #turbine do
- turbine[i].setInductorEngaged(false)
- end
- else
- termClear()
- term.write("There was an error with your imports")
- os.pullEvent()
- return true
- end
- return true
- end
- end
- elseif input == "power down" then
- saveToConfig()
- for i = 1,#turbine do
- turbine[i].auto = false
- turbine[i].setInductorEngaged(false)
- turbine[i].setActive(false)
- end
- reactor.setActive(false)
- reactor.setAllControlRodLevels(100)
- monClear()
- termClear()
- os.shutdown()
- elseif input == "auto on" then
- for i = 1,#turbine do
- turbine[i].auto = true
- end
- reactor.auto = true
- return true
- elseif input == "auto off" then
- for i = 1,#turbine do
- turbine[i].auto = false
- end
- reactor.auto = false
- return true
- end
- end
- function listener()
- while true do
- interface()
- end
- end
- function loop()
- while true do
- controlReactor()
- controlTurbines()
- createDisplay()
- sleep(SleepDelay)
- end
- end
- function displayTurbine(tNumber)
- sy = 2
- z = tNumber
- if tNumber > 4 then
- sy = 5
- z = tNumber - 4
- if tNumber > 8 then
- sy = 8
- z = tNumber - 8
- if tNumber > 12 then
- sy = 11
- z = tNumber - 12
- if tNumber > 16 then
- sy = 14
- z = tNumber - 16
- if tNumber > 20 then
- sy = 17
- z = tNumber - 20
- if tNumber > 24 then
- sy = 20
- z = tNumber - 24
- end
- end
- end
- end
- end
- end
- z = z - 1
- sx = 2 + z * 3
- mon.setCursorPos(sx,sy)
- mon.setBackgroundColor(colors.red)
- if turbine[tNumber].getActive() then
- mon.setBackgroundColor(colors.lime)
- end
- mon.write(" ")
- mon.setBackgroundColor(colors.brown)
- if turbine[tNumber].getInductorEngaged() then
- mon.setBackgroundColor(colors.pink)
- end
- mon.write(" ")
- mon.setCursorPos(sx,sy + 1)
- mon.setBackgroundColor(colors.red)
- if turbine[tNumber].auto then
- mon.setBackgroundColor(colors.lightBlue)
- end
- mon.write(" ")
- end
- utilize()
- parallel.waitForAll(loop, listener)
Add Comment
Please, Sign In to add comment