Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Automatic control program for Extreme Reactors mod for Minecraft
- --Theoretically works with infinite number of each but display only supports 20 of each
- --Prefers external storage, designed for enderIO capacitors, but can fall back to internal energy storage
- --cannot manage active cooled reactors yet, by default reactors are used as backup power generation
- --written by jdmbone003
- --to keep up to date run with the command os.execute("pastebin run 3g979aUy")
- component=require("component") --needed to work with mod components
- computer=require("computer") --needed to set a timer
- term=require("term") --needed to write to screen
- os=require("os") --needed to sleep if we execute everything before the timer is up
- gpu=component.gpu --set resolution and use color
- term.clear() --clear terminal
- gpu.setResolution(100,35) --set resolution
- set={50,80,99.5}
- reactorstats={{}} --array to store the stats for all reactors
- turbinestats={{}} --turbines
- numreactors=0 --count of reactors
- numturbines=0 --turbines
- running=true
- Reactors={}
- if component.isAvailable("br_reactor") then --if we have reactors
- for addr in component.list("br_reactor") do --get a proxy for each one
- local r=component.proxy(addr)
- table.insert(Reactors,r) --store it in this table
- numreactors=numreactors+1 --increment the number of reactors
- end
- print("Found "..numreactors.." reactors.")
- end
- Turbines={}
- if component.isAvailable("br_turbine") then --same as with the turbines
- for addr in component.list('br_turbine') do
- local t=component.proxy(addr)
- table.insert(Turbines,t)
- numturbines=numturbines+1
- end
- print("Found "..numturbines.." turbines.")
- end
- if component.isAvailable("energy_device") then
- capacitor=component.energy_device
- print("External energy storage initialized. Capacity: "..capacitor.getMaxEnergyStored())
- else
- print("No external energy storage found!")
- end
- for i=1,numreactors do --setup initial values for all reactors
- rc=Reactors[i]
- rc.setAllControlRodLevels(100)
- rc.setActive(true)
- --reactorstats {Rod Level,Min Rod Level,Fuel Temp,Case Temp,Reactivity,Energy Produced,Max Energy Produced}
- reactorstats[i]={100,0,0,0,0,0,100}
- end
- print("Reactors initialized.")
- for i=1,numturbines do --setup initial values for all turbines
- tb=Turbines[i]
- tb.setActive(true)
- --turbinestats {on,activ,hold,Fluid_Flow_Rate_Max,Max_Efficient_Flow_Rate,Blade Speed,Energy Produced,Max Energy Produced}
- turbinestats[i]={true,true,0,0,tb.getNumberOfBlades()*25,math.floor(tb.getRotorSpeed()),math.floor(tb.getEnergyProducedLastTick()),100}
- print(tb.getNumberOfBlades())
- end
- print("Turbines initialized.")
- os.sleep(2)
- term.clear()
- --main loop
- while running do
- timer=computer.uptime()+0.5 --limit updates to every .5 seconds
- if component.isAvailable("energy_device") then --if external energy device detected reference it for control
- cappct=math.floor((capacitor.getEnergyStored()/capacitor.getMaxEnergyStored())*1000)/10
- elseif numturbines > 0 then --otherwise use the first turbines
- tb=Turbines[1]
- cappct=math.floor((tb.getEnergyStored()/tb.getEnergyCapacity())*1000)/10
- elseif numreactors > 0 then --otherwise use the first Reactors
- rc=Reactors[1]
- cappct=math.floor((rc.getEnergyStored()/rc.getEnergyCapacity())*1000)/10
- else --otherwise nothing is connected so break out of the main loop
- break
- end
- for i=1,numreactors do --iterate through each reactor
- rc=Reactors[i] --get the proxy of the reactor
- minrodlvl=reactorstats[i][2] --what is the minimum rod setting?
- ftemp=math.floor(rc.getFuelTemperature()+0.5) --fuel temp
- ctemp=math.floor(rc.getCasingTemperature()+0.5) --casing temp
- reactiv=math.floor(rc.getFuelReactivity()) --fuel reactivity
- enprod=math.floor(rc.getEnergyProducedLastTick()) --energy produced
- maxprod=reactorstats[i][7] --record highest energy production
- if enprod>maxprod then maxprod=enprod end --if we produced more energy than we have before update the highest
- if cappct>set[1] then setrodlvl=100 end --if energy storage is above set limit, drop the rods to stop reaction
- if cappct<=set[1] then setrodlvl=math.floor(cappct*(100/set[1])) end --drop rods if storage is below set limit
- if ftemp>2000 then minrodlvl=setrodlvl+1 end --restrict min rod level if fuel gets above 2000
- if setrodlvl==minrodlvl and ftemp<2000 then minrodlvl=minrodlvl-1 end
- if setrodlvl<minrodlvl then setrodlvl=minrodlvl end
- rc.setAllControlRodLevels(setrodlvl) --set the rods
- reactorstats[i]={setrodlvl,minrodlvl,ftemp,ctemp,reactiv,enprod,maxprod} --save this reactors stats to the array
- if not rc.getActive() then running=false end --if reactor is off, set main loop to exit
- end
- for i=1,numturbines do --do all that again but for he turbines
- tb=Turbines[i] --proxy or turbine
- on,activ,hold,FFRM,MEFR,maxprod=turbinestats[i][1],tb.getInductorEngaged(),turbinestats[i][3],turbinestats[i][4],turbinestats[i][5],turbinestats[i][8] --get select stats of current turbine from array
- speed=math.floor(tb.getRotorSpeed()) --current rotor speed
- enprod=math.floor(tb.getEnergyProducedLastTick()) --energy produced
- if cappct<set[3] and speed>0 then activ=true end --set coils to activate
- if cappct<set[2] then on=true activ=true end --set steam flow to activate
- if cappct>=set[3] then on=false activ=false end --set both to deactivate
- if cappct<=set[1] and hold==1800 and speed<1650 then on=true activ=false end --to speed up faster keep the coils off
- if cappct<=set[1] and hold== 900 and speed< 730 then on=true activ=false end --until we get closer to set speed
- tb.setInductorEngaged(activ) --(de)activate coils from above logic
- if cappct<set[2] and MEFR>=500 then hold=1800 end --if we have enough blades and above storage % hold at 1800RPM
- if cappct>=set[2] then hold=900 end --if below storage % hold at 900RPM
- if speed<hold then
- if hold==1800 then FFRM=MEFR end --if speed is below target set steam to max effective for 1800
- if hold==900 then FFRM=MEFR/2 end --1/2 effective for 900
- end
- if speed>=hold then
- if hold==1800 then FFRM=MEFR/2 end --1/2 effective should also hold around 1800
- if hold==900 then
- if speed>950 then FFRM=0 end
- if speed<950 then FFRM=MEFR/4 end --1/4 effective should hold close to 900
- end
- end
- if speed>1850 then FFRM=0 end --if speed is too high cut the steam flow
- if not on then FFRM=0 end --if steam is not set to be on cut the steam flow
- tb.setFluidFlowRateMax(FFRM) --set steam flow from above logic
- if enprod>maxprod then maxprod=enprod end --record highest energy production
- turbinestats[i]={on,activ,hold,FFRM,MEFR,speed,enprod,maxprod} --save turbine stats to array
- if not tb.getActive() then running=false end --if turbine is off set main loop to exit
- end
- --graphs
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x990099)
- gpu.fill(1,1,cappct,1," ")
- gpu.set(1,1,""..cappct.."%")
- for tick=1,numreactors do
- rodlvl,minrodlvl,ftemp,ctemp,reavtiv,enprod,maxprod=reactorstats[tick][1],reactorstats[tick][2],reactorstats[tick][3],reactorstats[tick][4],reactorstats[tick][5],reactorstats[tick][6],reactorstats[tick][7]
- gpu.setForeground(0xFFFFFF)
- if tick<=20 then x=2 end
- if tick>20 and tick<=40 then x=10 end
- gpu.setBackground(0xAAAAAA)
- y=math.floor(6*tick-4)
- gpu.fill(y,x,5,7," ")
- gpu.set(y+1,x,""..tick)
- gpu.set(y,x+6,""..rodlvl)
- gpu.setBackground(0x000000)
- gpu.fill(y+1,x+1,3,5," ")
- gpu.setBackground(0x00FF00)
- gpu.set(y,x," ")
- if rodlvl<100 then gpu.setBackground(0x00FF00) end
- if rodlvl==100 then gpu.setBackground(0xFF0000) end
- gpu.set(y+4,x," ")
- gpu.setBackground(0x0000AA)
- if ftemp>20 then gpu.set(y+1,x+5," ") end
- if ftemp>=500 then gpu.set(y+1,x+4," ") end
- if ftemp>=1000 then gpu.set(y+1,x+3," ") end
- if ftemp>=1500 then gpu.set(y+1,x+2," ") end
- if ftemp>=2000 then gpu.setBackground(0xAA0000) gpu.set(y+1,x+1," ") end
- gpu.setBackground(0x0000AA)
- if ctemp>20 then gpu.set(y+2,x+5," ") end
- if ctemp>=500 then gpu.set(y+2,x+4," ") end
- if ctemp>=1000 then gpu.set(y+2,x+3," ") end
- if ctemp>=1500 then gpu.set(y+2,x+2," ") end
- if ctemp>=2000 then gpu.setBackground(0xAA0000) gpu.set(y+2,x+1," ") end
- gpu.setBackground(0x009900)
- if enprod>0 then gpu.set(y+3,x+5," ") end
- if enprod>(maxprod/100)*25 then gpu.set(y+3,x+4," ") end
- if enprod>(maxprod/100)*50 then gpu.set(y+3,x+3," ") end
- if enprod>(maxprod/100)*75 then gpu.set(y+3,x+2," ") end
- if enprod>(maxprod/100)*95 then gpu.set(y+3,x+1," ") end
- end
- for tick=1,numturbines do
- on,activ,hold,FFRM,MEFR,speed,enprod,maxprod=turbinestats[tick][1],turbinestats[tick][2],turbinestats[tick][3],turbinestats[tick][4],turbinestats[tick][5],turbinestats[tick][6],turbinestats[tick][7],turbinestats[tick][8]
- gpu.setForeground(0xFFFFFF)
- if tick<=20 then x=18 end
- if tick>20 and tick<=40 then x=26 end
- gpu.setBackground(0xAAAAAA)
- y=math.floor(6*tick-4)
- gpu.fill(y,x,5,7," ")
- gpu.set(y+1,x,""..tick)
- gpu.set(y,x+6,""..speed)
- gpu.setBackground(0x000000)
- gpu.fill(y+1,x+1,3,5," ")
- if on then gpu.setBackground(0x00FF00) end
- if not on then gpu.setBackground(0xFF0000) end
- gpu.set(y,x," ")
- if activ then gpu.setBackground(0x00FF00) end
- if not activ then gpu.setBackground(0xFF0000) end
- gpu.set(y+4,x," ")
- if speed>0 then gpu.setBackground(0x0000AA) gpu.set(y+1,x+5," ") end
- if speed>=750 then gpu.setBackground(0x00AA00) gpu.set(y+1,x+4," ") end
- if speed>=1100 then gpu.setBackground(0x0000AA) gpu.set(y+1,x+3," ") end
- if speed>=1650 then gpu.setBackground(0x00AA00) gpu.set(y+1,x+2," ") end
- if speed>1850 then gpu.setBackground(0xAA0000) gpu.set(y+1,x+1," ") end
- tbppct=math.floor(((enprod/maxprod)*100)/20)
- gpu.setBackground(0xFF0000)
- if FFRM==0 then gpu.set(y+2,x+5," ") end
- gpu.setBackground(0x0000FF)
- if hold==900 then gpu.set(y+2,x+4," ") end
- if hold==1800 then gpu.set(y+2,x+2," ") end
- gpu.setBackground(0x009900)
- if tbppct>0 then gpu.set(y+3,x+5," ") end
- if tbppct>1 then gpu.set(y+3,x+4," ") end
- if tbppct>2 then gpu.set(y+3,x+3," ") end
- if tbppct>3 then gpu.set(y+3,x+2," ") end
- if tbppct>4 then gpu.set(y+3,x+1," ") end
- end
- rc=Reactors[1]
- if not rc.getActive() then break end
- if computer.uptime()<timer then os.sleep(timer-computer.uptime()) end
- end --end of main loop
- for i=1,numreactors do
- rc=Reactors[i]
- rc.setAllControlRodLevels(100) --drop all rods
- rc.setActive(false) --turn off all reactors
- end
- for i=1,numturbines do
- tb=Turbines[i]
- tb.setFluidFlowRateMax(0) --cut all steam flow
- tb.setInductorEngaged(false) --turn off all coils
- tb.setActive(false) --turn off all turbines
- end
- gpu.setResolution(gpu.maxResolution())
- gpu.setBackground(0x000000)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement