Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- keeps reactor working efficiently at all times; increases power load when necessary, goes idle at 90% power until below 10%
- local function findPeripherals() --searches around for reactor so the computer doesn't have to be placed in a particular way
- local reactor,terminal --also searches for a terminal glasses terminal
- for k,v in pairs(rs.getSides()) do
- if (peripheral.getType(v) == "BigReactors-Reactor") then
- reactor = peripheral.wrap(v)
- print(reactor)
- print('reactor found!')
- break
- elseif (peripheral.getType(v) == "openperipheral_glassesbridge") and (not terminal) then
- terminal = peripheral.wrap(v)
- end
- end
- return reactor, terminal
- end
- local reactor,terminal=findPeripherals()
- local deltaPower,curPower,oldPower,controlRodLevel,powerMode,secondsWorked=0,0,0,100,0,0
- print(not reactor)
- powerMode = reactor.getEnergyStored()<9000000
- local function reactorActivities()
- term.clear()
- secondsWorked=secondsWorked+1
- print('Yes, I am working. Total time: ' .. secondsWorked .. ' steps.')
- oldPower=curPower
- curPower=reactor.getEnergyStored()
- controlRodLevel=controlRodLevel>100 and 100 or controlRodLevel<0 and 0 or controlRodLevel
- if curPower>9000000 then
- powerMode=false
- elseif curPower<1000000 then
- powerMode=true
- end
- if powerMode then
- deltaPower=curPower-oldPower
- --let's add some derivative to this sos it doesn't go quite so slow at slower intervals
- local deltaControlRodLevel=deltaPower<0 and math.floor(deltaPower/1000) or deltaPower>100 and math.ceil(deltaPower/1000) or 0
- controlRodLevel = controlRodLevel+deltaControlRodLevel
- if curPower<10000 then
- controlRodLevel=0
- end
- reactor.setAllControlRodLevels(controlRodLevel)
- else
- reactor.setAllControlRodLevels(100)
- print("Reactor's nearly full.")
- print("Current status: off.")
- end
- end
- local function terminalActivities()
- terminal.clear()
- local wastePercent=reactor.getWasteAmount()/reactor.getFuelAmountMax()
- local fuelPercent=(reactor.getWasteAmount()+reactor.getFuelAmount())/reactor.getFuelAmountMax()
- terminal.addBox(5,5,100,10,0xcc0000,0.8)
- terminal.addBox(5,5,math.floor(curPower/100000),10,0x00cc00,0.8)
- terminal.addBox(105,5,10,100,0xcccccc,0.8)
- terminal.addBox(105,5,10,controlRodLevel,0x303030,0.8)
- terminal.addBox(5,20,100,10,0x303030,0.8)
- terminal.addBox(5,20,math.min(math.floor(100*fuelPercent),100),10,0xcccc00,0.8)
- terminal.addBox(5,20,math.min(math.floor(100*wastePercent),100),10,0x00cccc,0.8)
- end
- interval=tonumber(...)
- if interval then
- if interval<0.5 then
- interval=0.5
- end
- else
- interval=2
- end
- while reactor.getConnected() do
- if interval then os.startTimer(interval) end
- local event = {os.pullEvent()}
- reactorActivities()
- if terminal then
- terminalActivities()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement