Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----config----
- maxRun = 0 --up to what number can the reactor run (Number is of the Reactor Controll rods)
- maxThemp =1200 --maximal temperature
- useThemp =false --Use temperature to define at which controll the therperature is reached it set maxRun according to maxThemp
- startCD = 9000000 --at what energy the Cooldown starts
- endCD = 7000000 --at what energy the Cooldown ends
- endWarmup =3000000 --at what energy does the Powerup stops
- maxItemsPerMonitor =10 --when gets the Monitor Special scrolled
- ShowInfos =true --Additional infos like RF/Tick etc will be displayed
- changeMonitors=false -- If set to true the Monitors will change so the Normal one is the other one
- mapTrys=10 --How many times the RF/TICK shall be mesured to make one mesurement out of it
- firstRun =true --the Reactor runs the first time and have to get mapped
- reactorMap = {} --This will be replaced with the MAP for THIS SPECIFIC reactor after the First run
- thempMap = {} --THIS will be replaced with a Temperature map for THIS SPECIFIC reactor
- check=2 --difference between Mesurements
- tickTime =0.5 --time per tick of the programm (NOT MINECRAFT) lower is faster information does have to be a denominator of check so that a Int is the solution ALSO if tickTIme 0.25 or lower it seems buggy
- wait = 10 --time between mesurements for the MAPPING the higher the more accurate (more than 20 should be useless)
- -----End of Config-----
- --Made By Xarlas (FTB Forum and Computercraft Forums)
- --Do NOT Republish as own work
- --If you want to use parts of this code for your own code
- --give Credits ! (for example Link to my Profile on FTB Forums or the therad where this was Published )
- --DO NOT CHANGE ANYTHING AFTER HERE (exept you know what you are doing)
- -- IN THE CODE "reactorMap =" or "thempMap =" or "firstRun =" MUST NOT BEEN USED use no space betwen the Variable and the = (reason is the Function replaceConfig replaceCONFIG) or type --NOT CHANGE in the line
- Var =0 --Differenz from last Messure (variance)
- Cont=0 -- Controll rod Level while Cooldown (CD)
- NoCD =true --NO Coodlown
- NoPU =true --NO Powerup
- LastN = false --last variance negative
- Stabil = false --Reactor seems stable
- Port= nil --Compouter port (Reactor)
- UnvPeriph=nil --Peripheral not Validated
- MonitorNormal = nil --Monitor that displays information that change often
- MonitorSpecial = nil --Monitor that displays special events
- CounterMain=0 --CounterMain checking when regulator can be called
- EnergyVarTick = 0-- Energy Variance per tick
- function startup() --Initialisation
- searchSide()
- if MonitorSpecial ~=nil then
- MonitorSpecial.clear()
- MonitorSpecial.setCursorPos(1,1)
- end
- if Port == nil then
- special_out("Place Computer next to a Big Reactors Reactor Computer Port or Connect it Via MODEMS and try again ")
- end
- if firstRun then
- special_out("Please Wait The Reactor is getting Mapped ")
- reactorMap={}
- thempMap={}
- MapReactor()
- saveProg(replaceConfig(loadProg()))
- end
- if useThemp then
- special_out("Detect Temprature and adjust to maximum ")
- getMaxControll()
- end
- Checker()
- end
- function searchSide() --searches al 4 sides for peripherals when it found any it trys to Validate them maybe add top and pottom for Monitors
- allPeripherals = peripheral.getNames()
- i=1
- while allPeripherals[i] do
- thing = allPeripherals[i]
- UnvPeriph=peripheral.wrap(thing)
- if string.find(thing,"monitor") then
- pcall(ValidateMonitor)
- elseif string.find(thing,"BigReactors-Reactor") then
- pcall(ValidateReactor)
- else
- pcall(ValidateReactor)
- pcall(ValidateMonitor)
- end
- i=i+1
- end
- end
- function ValidateReactor () --Validates if the Peripheral is An Reactor Computer port JUST CALL WITH "pcall" or else the Program will crash
- if UnvPeriph.getEnergyStored()~=nil then
- Port=UnvPeriph
- print("Reactor Validated")
- UnvPeriph =nil
- end
- end
- function ValidateMonitor() --Will Validate Peripherals as Monitors and wrap them ( and assign them)
- if not changeMonitors then
- if UnvPeriph.getSize()~=nil and MonitorSpecial ==nil then
- MonitorSpecial=UnvPeriph
- UnvPeriph=nil
- print("Special Monitor Validated")
- end
- if UnvPeriph.getSize()~=nil and MonitorNormal ==nil then
- MonitorNormal=UnvPeriph
- UnvPeriph=nil
- print("Normal Monitor Validated")
- end
- end
- if changeMonitors then
- if UnvPeriph.getSize()~=nil and MonitorNormal ==nil then
- MonitorNormal=UnvPeriph
- UnvPeriph=nil
- print("Normal Monitor Validated")
- end
- if UnvPeriph.getSize()~=nil and MonitorSpecial ==nil then
- MonitorSpecial=UnvPeriph
- UnvPeriph=nil
- print("Special Monitor Validated")
- end
- end
- end
- function getMaxControll() --Calculates maxRun so that it runs not higher than MaxThemp themerature
- for i=1,101,1 do
- if thempMap[i]>=maxRun then
- maxRun=i-1
- end
- if thempMap[i]< maxThemp then
- special_out("Set MAXRUN to ".. maxRun)
- break
- end
- end
- end
- function Checker() --checks Energy und Calculates variance
- while true do
- Energy = Port.getEnergyStored() --initialize Energy with Energy stored
- os.sleep(tickTime)
- Var = Port.getEnergyStored()-Energy --Energy Varianze to tlast Mesurement tickTime ago
- EnergyVarTick=math.floor(Var/((tickTime/0.05)+1)) -- +1 workaround for mesuring one tick to long
- CounterMain=CounterMain+tickTime
- if ShowInfos then
- displayInfos()
- end
- if CounterMain>=check then
- Regulator()
- CounterMain=0
- end
- end
- end
- function Regulator() --Reguliert The Rods
- EnergyUsed = reactorMap[Port.getControlRodLevel(0)+1] -EnergyVarTick
- if NoCD and NoPU then --Suche wert der am nächsten an EnergyUsed von der Positiven dran ist und setzte diesen
- for i=1,101,1 do
- if reactorMap[maxRun+1]<=EnergyUsed then --wenn mehr energy als maximal an controll erlaubt
- Port.setAllControlRodLevels(maxRun)
- break
- end
- if reactorMap[i]>=EnergyUsed then
- Port.setAllControlRodLevels(i-1)
- end
- if reactorMap[i]< EnergyUsed then
- break
- end
- end
- end
- if Port.getEnergyStored()> startCD and NoCD then
- special_out ("Start Cooldown")
- Cont = Port.getControlRodLevel(0)
- Port.setAllControlRodLevels(100)
- NoCD= false
- end
- if not NoCD and Port.getEnergyStored()< endCD then
- special_out("Stop Cooldown")
- NoCD=true
- LastN=false
- Stabil=false
- Port.setAllControlRodLevels(Cont)
- end
- if Port.getEnergyStored()<endWarmup and NoPU then
- special_out ("Start Startup")
- NoPU = false
- Port.setAllControlRodLevels(maxRun)
- end
- if not NoPU and Port.getEnergyStored()>endWarmup then
- special_out ("Stop Startup")
- NoPU=true
- LastN=false
- Stabil=false
- end
- end
- function MapReactor () --Does the MAPPING for the reactor
- Port.setActive(true)
- Port.setAllControlRodLevels(0)
- os.sleep(wait)
- for i=0,100,1 do --All 100 % mappen
- Port.setAllControlRodLevels(i)
- os.sleep(wait)
- try={}
- tryThemp={}
- for j=1,mapTrys,1 do --Try Map trys time
- produce=0
- Themp = Port.getFuelTemperature()
- while i~=100 and produce==0 do
- displayInfos()
- produce=Port.getEnergyProducedLastTick()
- os.sleep(0.1)
- end
- table.insert(try,produce)
- table.insert(tryThemp,Themp)
- displayInfos()
- os.sleep(1)
- end
- produced=0
- FullThemp=0
- for h=1,mapTrys,1 do
- produced=produced+try[h]
- FullThemp=FullThemp+tryThemp[h]
- end
- produced =math.floor(produced/mapTrys) --round it to avoid .XXXX which are useles because Messungenauigkeit
- FullThemp=math.floor(FullThemp/mapTrys) --round it to avoid .XXXX which are useles because Messungenauigkeit
- if i==100 then
- produced=0
- end
- table.insert(reactorMap,produced)
- table.insert(thempMap,FullThemp)
- special_out("At ".. i .." % control the Reactor Produce ".. produced .. "RF/Tick")
- special_out("and has a Temperature of " .. FullThemp .." C" )
- displayInfos()
- end
- special_out("Reactor Mapped")
- firstRun = false
- end
- function loadProg() --loads this Programm as a table
- local file = io.open(shell.getRunningProgram() , "r"); --trys to get Filname while running if fails use name directly
- local data = {}
- for line in file:lines() do
- table.insert (data, line);
- end
- io.close(file)
- return data
- end
- function replaceConfig(data) --makes changes in the config and returns new programm optimize with replace (remove than insert) Do NOT remove the "NOT CHANGE" or the Function will stop working
- notEnd =true
- newData={}
- --länge einer tabelle mit table.getn( myTable ) dann for schleife
- i=1
- while notEnd do
- line = data[i]
- if string.find(data[i],"firstRun =") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
- line = "firstRun = false" --NOT CHANGE
- end
- if string.find( data[i],"reactorMap = {") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
- line="reactorMap = {" --NOT CHANGE
- for z = 1, 100, 1 do
- line = line .. reactorMap[z].." , "
- end
- line =line .. " 0 } " --say the LAST (100%) is = RF/TICK THIS is a fix for a problem in the MapReactor where one if does not work
- end
- if string.find( data[i],"thempMap = ") and not string.find(data[i],"--NOT CHANGE") then --NOT CHANGE
- line="thempMap = {" --NOT CHANGE
- for z = 1, 100, 1 do
- line = line .. thempMap[z].." , "
- end
- line = line .. thempMap[101] .. " } " --say the LAST (100%) is = RF/TICK THIS is a fix for a problem in the MapReactor where one if does not work
- end
- if data[i]=="--end" then
- notEnd = false
- end
- table.insert (newData,line);
- i=i+1
- end
- return newData
- end
- function saveProg (data) --saves table as Programm
- local file=io.open(shell.getRunningProgram() , "w"); --trys to get Filname while running if fails use name directly
- notEnd =true
- i=1
- while notEnd do --länge einer tabelle mit table.getn( myTable ) mit for schleife
- file:write(data[i]);
- file:write("\n");
- if data[i]=="--end" then
- notEnd = false
- end
- i=i+1
- end
- file:flush()
- io.close(file)
- end
- function normal_out(text) --does print information on NORMAL Monitor use for Things everytime should be displayed
- if MonitorNormal ~=nil then
- local positionXNormal,positionYNormal=MonitorNormal.getCursorPos()
- MonitorNormal.write(text)
- MonitorNormal.setCursorPos(1,positionYNormal+1) --place cursor on next line
- else
- print (text)
- end
- end
- function special_out(text) -- use this instead of print
- if MonitorSpecial ~=nil then
- local positionX,positionY=MonitorSpecial.getCursorPos()
- if positionY> maxItemsPerMonitor then
- MonitorSpecial.scroll(1)
- MonitorSpecial.setCursorPos(1,positionY-1)
- positionY=positionY-1
- end
- MonitorSpecial.write(text)
- MonitorSpecial.setCursorPos(1,positionY+1) --place cursor on netxt line
- end
- if MonitorSpecial ==nil then
- print (text)
- end
- end
- function displayInfos() --does show a few informations about the Reactor
- if MonitorNormal ~= nil then
- MonitorNormal.clear()
- MonitorNormal.setCursorPos(1,1)
- end
- if ShowInfos then
- normal_out("The Energy in the Reactor is "..Port.getEnergyStored().." RF")
- normal_out("Which is "..Port.getEnergyStored()/100000 .." % of the Maximal Capacity" )
- normal_out("It uses "..Port.getFuelConsumedLastTick().." MB per Tick ")
- normal_out("To generate ".. math.floor(Port.getEnergyProducedLastTick()).." RF/Tick ")
- normal_out("The Efficiency of the Reactor is ".. math.floor(Port.getEnergyProducedLastTick()/Port.getFuelConsumedLastTick()) .. " RF per MB")
- if not firstRun then
- normal_out (EnergyVarTick.. " is the Energy Variance per Tick")
- end
- normal_out(Port.getControlRodLevel(0).." is The Control Level")
- normal_out( "The Reactor Fuel is " .. math.floor(Port.getFuelTemperature()) .." C Hot")
- end
- end
- startup()
- -- DONT REMOVE THE LAST LINE even if it seems to be a comment it wont save the controll Temperature otherwise and WILL NOT WORK (program wont do ANYTHING !!!)
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement