Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Big Reactors Controller Suite v1.0
- =====================================
- Reactor Controller for passive mode
- by NexAdn
- modified by fatboychummy for backwards compatibility
- ]]
- --[[===== USER CONFIGURATION =====]]--
- local tConfig = {
- -- Priority list for Reactor Computer Ports
- priorityPorts = { "back" },
- -- Tick interval (Time between checks in seconds)
- tickInterval = 0.5,
- -- Automatic security and economical mechanisms
- preventOverheat = true,
- fuelSave = true,
- ---- Overheat prevention
- -- Unit: Degrees Celsius
- -- When to start inserting fuel rods
- tempLimitSoft = 1500,
- -- When to shut down the reactor
- tempLimitHard = 1900,
- -- When to restart the reactor after overheat shutdown (IMPORTANT: The lowest possible temperature is 20 degrees!)
- tempRestartTarget = 30,
- ---- Fuel save (Rod insertion according to energy buffer level)
- -- Unit: Per cent
- -- Start inserting the control rod
- energyMarkLow = 20,
- -- Fully insert the control rod
- energyMarkHigh = 90,
- }
- --[[===== DO NOT CHANGE ANYTHING BELOW THIS LINE =====]]--
- -- Change if needed
- local portName = "BigReactors-Reactor"
- local maxEnergy = 10000000
- local maxTemp = 2000
- ------------------------
- ---- INITIALIZATION ----
- ------------------------
- local overheatShutdown = false
- local dispHeight = 0
- local dispWidth = 0
- local reactorPort = {}
- targetRodInsertion = 0
- dispWidth, dispHeight = term.getSize()
- function multiblockSleep ()
- while not reactorPort.getConnected() do
- print("Not connected to a valid multiblock.\nWaiting...")
- sleep(3)
- end
- end
- function connectReactorPort ()
- local function find(name)
- local ls = peripheral.getNames()
- for i, n in ipairs(ls) do
- if (n):find(name) then
- return peripheral.wrap(n)
- end
- end
- end
- reactorPort = find(portName)
- for k,v in pairs(tConfig.priorityPorts) do
- if peripheral.getType(v) == portName then
- reactorPort = peripheral.wrap(v)
- end
- end
- multiblockSleep()
- end
- ---------------------
- ---- GENERAL I/O ----
- ---------------------
- function getStorageRate ()
- multiblockSleep()
- return reactorPort.getEnergyStored()*100/maxEnergy
- end
- function getTemperature ()
- multiblockSleep()
- return math.max(reactorPort.getFuelTemperature(), reactorPort.getCasingTemperature())
- end
- function getActive ()
- multiblockSleep()
- return reactorPort.getActive()
- end
- function setRodInsertion (insertionLevel)
- multiblockSleep()
- reactorPort.setAllControlRodLevels(math.min(100,math.max(0,insertionLevel)))
- end
- function setActive (isActive)
- multiblockSleep()
- reactorPort.setActive(isActive)
- end
- function setRS(color)
- rs.setBundledOutput(tConfig.rsOutput, color)
- end
- ------------------------
- ---- GUI AND ENGINE ----
- ------------------------
- function calcSet ()
- multiblockSleep()
- local storageRate = getStorageRate()
- local temp = getTemperature()
- targetRodInsertion = 0
- if tConfig.preventOverheat then
- if temp >= tConfig.tempLimitSoft then
- targetRodInsertion = (temp - tConfig.tempLimitSoft) * 100 / (tConfig.tempLimitHard - tConfig.tempLimitSoft)
- end
- if temp > tConfig.tempLimitHard then
- setActive(false)
- overheatShutdown = true
- end
- if getActive() and overheatShutdown and temp <= tConfig.tempRestartTarget then
- setActive(true)
- overheatShutdown = false
- end
- end
- if tConfig.fuelSave then
- if storageRate > tConfig.energyMarkLow then
- targetRodInsertion = math.max( (storageRate - tConfig.energyMarkLow) * 100 / (tConfig.energyMarkHigh - tConfig.energyMarkLow), targetRodInsertion)
- end
- if storageRate > tConfig.energyMarkHigh then
- targetRodInsertion = 100
- end
- end
- setRodInsertion(targetRodInsertion)
- end
- function getCol(num, maxcols)
- --return math.floor((dispWidth / (2*maxcols)) * num)
- return math.floor(((dispWidth / maxcols)) * num - (dispWidth/(2*maxcols)))
- end
- function initCol(num, maxcols, prefix)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(getCol(num,maxcols), 1)
- term.write(prefix)
- for i=2,dispHeight-1,1 do
- for j=1,3,1 do
- term.setCursorPos(getCol(num,maxcols)-2+j, i)
- term.setBackgroundColor(colors.gray)
- term.write(" ")
- end
- end
- end
- function drawCol(num, maxcols, rela)
- local height =math.min(math.max(dispHeight-2-math.floor( ( rela * (dispHeight-2) )/100 ), 0), dispHeight-2)
- for i=height+1,dispHeight-1,1 do
- for j=1,3,1 do
- term.setCursorPos(getCol(num,maxcols)-2+j,i)
- term.write(" ")
- end
- end
- end
- function drawGUI()
- -- INIT
- term.clear()
- if term.isColor() then
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- initCol(1, 4, "T")
- initCol(2, 4, "E")
- initCol(3, 4, "I")
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.red)
- drawCol(1, 4, getTemperature()*100/maxTemp)
- drawCol(2, 4, getStorageRate())
- drawCol(3, 4, targetRodInsertion)
- term.setBackgroundColor(colors.white)
- if getTemperature() < 1000 then
- term.setCursorPos(getCol(1,4)-1, dispHeight)
- else
- term.setCursorPos(getCol(1,4)-2, dispHeight)
- end
- term.write(math.floor(getTemperature()))
- term.setBackgroundColor(colors.white)
- term.setCursorPos(getCol(2,4), dispHeight)
- term.write(math.floor(getStorageRate()))
- term.setBackgroundColor(colors.white)
- term.setCursorPos(getCol(3,4), dispHeight)
- term.write(math.floor(targetRodInsertion))
- else
- print("Please use an advanced computer/monitor to enable GUI functionality.")
- end
- end
- function main()
- if term.isColor() then
- term.setCursorBlink(false)
- end
- connectReactorPort()
- if tConfig.preventOverheat and getTemperature() > tConfig.tempLimitHard then
- setActive(false)
- overheatShutdown = true
- else
- setActive(true)
- overheatShutdown = false
- end
- while true do
- calcSet()
- drawGUI()
- sleep(tConfig.tickInterval)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement