Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This program was created by MrNaru300
- --You can follow me in this link:
- --https://www.youtube.com/user/MrNaru300
- --[[Hint: rename this file to "startup" to]]--
- --[[initialize when you reload the world ]]--
- --The reactor controller is a program
- --that control your reactor (normal or cooler)
- --with the the lowest waste of resources
- --if you have a cooler reactor,
- --change the "coolermax" number
- --in the configs to get a better performance
- local configs = {
- lock = 0.75, --the maximum percentage of energy the reactor will produce
- noGraph = false, --don't show the interface on the screen
- waitTime = 1, --waiting time (in seconds)
- coolerLock = 0.9, --the maximum percentage of steam the reactor will produce
- coolerMax = 0.25, --The maximum percentage of "using" of the colling reactor
- direction = nil --the reactor side (nil = automatic)
- }
- -----------------------------------
- function Start ()
- --setting values
- local directions = {"back", "bottom", "top", "left", "right", "front"}
- --getting the reactor direction
- if configs.direction == nil then
- for _, direction in pairs(directions) do
- if peripheral.getType(direction) == "BigReactors-Reactor" then
- configs.direction = direction
- break
- end
- end
- end
- if configs.direction == nil or peripheral.getType(configs.direction) ~= "BigReactors-Reactor" then
- error("reactor not detected!")
- end
- end
- -----------------------------------
- Start()
- --setting other values
- local Offline = "SYSTEM OFFLINE"
- local reactor = peripheral.wrap(configs.direction)
- local rodsPos = 0
- local decimalPlaces = {"K", "Mi", "B", "T", "q", "Q", "s", "S", "O", "N", "D"}
- local lock = configs.lock
- -------------------------------------
- function reduce (number, places)
- posFix = nil
- i = 0
- while number > 1000 and i < table.getn(decimalPlaces) do
- i = i+1
- posFix = decimalPlaces[i]
- number = number/1000
- end
- if type(places) == "number" then
- number = math.floor(number*math.pow(10, places))/math.pow(10, places)
- end
- if type(posFix) == "nil" then
- return number
- else
- return number..posFix
- end
- end
- -----------------------------------
- function CursorCenter(text, ln)
- term.setCursorPos(x/2-string.len(text)/2, ln)
- end
- -----------------------------------
- function info (ps, col, name, i1, i2, type)
- local WriteTXT = name..": "..reduce(i1, 1).." / "..reduce(i2, 0).." ("..(math.floor((i1)/i2*100)).."%)"
- if type == 1 then WriteTXT = WriteTXT.." +"..reduce(reactor.getEnergyProducedLastTick(), 0) end
- if type == 2 then WriteTXT = WriteTXT.." +"..reduce(reactor.getHotFluidProducedLastTick(), 0) end
- CursorCenter(WriteTXT, ps)
- term.setTextColor(col)
- print(WriteTXT)
- end
- -----------------------------------
- function line (ln, i1, text, col, i2, col2)
- term.setCursorPos(1, ln)
- if type(i2) ~= "number" then i2 = 0 end
- if col == nil then
- col = colors.green
- if i1 > .33 and i1 < .66 then col = colors.yellow end
- if i1 < .33 then col = colors.red end
- end
- term.setBackgroundColor(col)
- for i = 0, x*i1 do
- term.setCursorPos(i, ln)
- print(" ")
- end
- if i2 > 0 then
- term.setBackgroundColor(col2)
- for i = x*i1, x*i1+x*i2+1 do
- term.setCursorPos(i, ln)
- print(" ")
- end
- end
- porc = (math.floor(i1*1000)/10).."%"
- if text ~= nil then
- porc = text..": "..porc
- end
- a = string.len(porc)
- for i = 0, a do
- if (x-a)/2+i <= x*i1 then
- term.setBackgroundColor(col)
- else if (x-a)/2+i <= x*i2 then
- term.setBackgroundColor(col2)
- else
- term.setBackgroundColor(colors.black)
- end
- end
- term.setTextColor(colors.white)
- term.setCursorPos((x-a)/2+i, ln)
- print(string.sub(porc, i+1, i+1))
- end
- term.setBackgroundColor(colors.black)
- end
- ------------------------------------
- function setRods()
- if isCooler then
- rodsPos = steam/MaxSteam/configs.coolerLock
- if rodsPos >= 1 then
- rods(100)
- else if rodsPos <= 1-configs.coolerMax then
- rods(100-configs.coolerMax*100)
- else
- rods(rodsPos*100)
- end
- end
- else
- rodsPos = energy/MaxEnergy/lock
- if rodsPos >= 1 then
- rods(100)
- else
- rods(rodsPos*100)
- end
- end
- end
- -----------------------------------
- local function offAlert()
- if ColorOff == nil then ColorOff = colors.red end
- if ColorOff == colors.black then
- term.setBackgroundColor(colors.red)
- CursorCenter(Offline, 8)
- term.setTextColor(colors.black)
- print(Offline)
- term.setBackgroundColor(colors.black)
- ColorOff = colors.red
- sleep(configs.waitTime*.2)
- else
- term.setBackgroundColor(colors.black)
- CursorCenter(Offline, 8)
- term.setTextColor(colors.red)
- print(Offline)
- term.setBackgroundColor(colors.black)
- ColorOff = colors.black
- sleep(configs.waitTime*.2)
- end
- end
- -----------------------------------
- while true do
- x, y = term.getSize()
- energy = reactor.getEnergyStored()
- MaxEnergy = 10000000
- fuel = reactor.getFuelAmount()
- MaxFuel = reactor.getFuelAmountMax()
- Activity = reactor.getActive()
- rods = reactor.setAllControlRodLevels
- isCooler = reactor.isActivelyCooled()
- if isCooler then WriLock = "Lock: "..(lock*100).."%"
- else WriLock = "Lock: "..(configs.coolerLock*100).."%" end
- steam = reactor.getHotFluidAmount()
- MaxSteam = reactor.getHotFluidAmountMax()
- getRods = reactor.getControlRodLevel(1)
- -----------------------------------
- setRods()
- -----------------------------------
- if configs.noGraph == false then
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if isCooler == false then
- info(1, colors.red, "RF", energy, MaxEnergy, 1)
- line(4, energy/MaxEnergy, "RF", colors.red)
- else
- info(1, colors.red, "Steam", steam, MaxSteam, 2)
- line(4, steam/MaxSteam, "Steam", colors.red)
- end
- CursorCenter(WriLock, 2)
- term.setTextColor(colors.gray)
- print(WriLock)
- term.setCursorPos(1, y-1)
- term.setTextColor(colors.red)
- print('Press "Ctrl + T" to stop the program')
- if Activity then line(3, 1-getRods/100, "Using", colors.gray)
- else line(3, 0, "Using", colors.gray)
- end
- info(5, colors.yellow, "Fuel", fuel, MaxFuel, 2, reactor.getWasteAmount())
- line(6, fuel/MaxFuel, nil, colors.orange, reactor.getWasteAmount()/MaxFuel, colors.blue)
- if Activity == false then
- offAlert()
- end
- end
- -----------------------------------
- sleep(configs.waitTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement