Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Big Reactors Control Program
- --Brydon Lezchuk <90littlegreenmen@gmail.com>
- --Some code inspiration came from similar
- --programs by:
- --Emily Backes <lucca@accela.net>
- --pastebin.com/uALkzjWt
- --and Direwolf20
- --pastebin.com/4qNyaPav
- --pastebin.com/XBbMUYNn
- --This version only works with 1 reactor and
- --1 turbine, though it is written to be
- --expanded upon.
- --Must be ran from the top level directory /
- --This is where config.txt gets saved
- --Outputs text in red
- function errorprint(txt)
- term.setTextColor(colors.red)
- print(txt)
- term.setTextColor(colors.white)
- end
- --Outputs the given text then returns
- --true or false given the user input
- function yesno(txt)
- print(txt.." (y/n)")
- local input = read()
- if input=="y" then
- return true
- elseif input=="n" then
- return false
- else
- errorprint("Please use 'y' or 'n'")
- return yesno(txt)
- end
- end
- --Checks for the config.txt file
- --Returns true if file exists
- --Returns true if setup ran
- --Returns false if setup was not ran
- function chkconfig()
- if not fs.exists("config.txt") then
- if yesno("Configuration not found, would you like to run setup?")
- then
- setup()
- return true
- else
- return false
- end
- else
- return true
- end
- end
- --loads in config settings from config.txt
- function loadconfig()
- local file = fs.open("config.txt","r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- --saves configs to config.txt
- function saveconfig(config)
- local file = fs.open("config.txt","w")
- file.write(textutils.serialize(config))
- file.close()
- end
- --Gets config settings from user and saves
- --them to config.txt
- function setup(config)
- print("How many capacitors are connected to network?")
- config.numcap = read()
- print("At what power capacity should Reactor/Turbine shut off?")
- config.powermax = read()
- print("How low should the capacity be to turn on Reactor/Turbine?")
- config.powermin = read()
- saveconfig(config)
- end
- --Gets devices from the network given the type
- --and returns them in a table
- function getdev(type)
- local dev
- local key
- local d = {} --table of the specified device type
- local wrapped = {}
- for key,dev in pairs(peripheral.getNames()) do
- if (peripheral.getType(dev)==type) then
- table.insert(d, dev)
- print("Found Device: "..dev)
- end
- end
- return wrapped
- end
- --calculates the optimal fuel rod insertion rate
- --to generate the steam needed by turbines
- --given a reactor and the steam needed
- function getoptfuelrod(r,s)
- resetdisplay()
- --print(r)
- --r.setActive(false)
- --while r.getFuelTemperature() > 99 do
- -- print("Waiting for reactor to cool off")
- -- print("Reactor Temp: "..r.getFuelTemperature())
- -- sleep(1)
- --end
- end
- --Clears the screen and moves cursor
- function resetdisplay()
- term.clear()
- term.setCursorPos(1,1)
- end
- --The backbone of the program
- function main()
- local config = {} --table of configs
- local r --table of reactors
- local t --table of turbines
- local m --table of monitors
- local c --table of capacitors
- local reactor
- local turbine
- local numpassreactor = 0
- local steamneeded = 0
- local steamperreactor = 0
- local optfuelrod = {}
- errorprint("Please note, if anything has changed on the network, delete the config.txt")
- print()
- if not chkconfig() then
- errorprint("No configuration set, exiting program.")
- return
- end
- r = getdev("BigReactors-Reactor")
- t = getdev("BigReactors-Turbine")
- c = getdev("tile_blockcapacitorbank_name")
- m = getdev("monitor")
- if t~=nil then
- steamneeded = 2000 * (#t)
- getoptfuelrod(r[1],steamneeded)
- end
- while true do
- for i,reactor in pairs(r) do
- if reactor.isActivelyCooled() then
- --actively cooled reactor
- else
- --code here for passively cooled reactor
- end
- end
- end
- end
- --local args = {...}
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement