Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Program name: EZ-NUKE reactor control system
- Version: v0001 Beta
- Programmer: ScatmanJohn
- Last update: 10.1.2014
- Pastebin: http://pastebin.com/A7iGzTCH
- Description:
- This program controls a Big Reactors nuclear reactor
- in Minecraft with a Computercraft computer, using Computercraft's
- own wired modem connected to the reactors computer control port.
- Resources:
- Reactor control:
- http://pastebin.com/HjUVNDau
- FC API:
- http://pastebin.com/A9hcbZWe
- Stargate control startup:
- http://pastebin.com/L4yhWweE
- My gate:
- FUEHMVD
- Enderchests:
- Red-Blue-Red, for leaf blocks and herba jars
- Black-Blue-Black, feeds directly into AE
- Monitor size is X: 29, Y: 12 with a 3x2 size
- ]]--
- print("Initializing program...");
- if not os.loadAPI("FC_API") then
- error("Missing FC_API")
- end
- --Done loading API
- function wrapThis(thing)
- local wrapped, f = nil, 0
- while wrapped == nil and f <= 100 do
- wrapped = peripheral.wrap(thing.."_"..f)
- f = f + 1
- end
- if wrapped == nil then
- side = getDeviceSide(thing)
- if side ~= nil then
- return peripheral.wrap(side)
- else
- return nil
- end
- else
- return wrapped
- end
- end
- local function print(str, x, y)
- term.setCursorPos(x, y)
- term.write(str)
- end
- -- Done helper functions
- -- Then initialize the monitor
- local monitor = wrapThis("monitor")
- local monitorx, monitory = monitor.getSize()
- if monitorx ~= 29 and monitory ~= 12 then
- error("Monitor is the wrong size! Needs to be 3x2.")
- end
- if monitor then
- --error("No Monitor Attached")
- term.clear()
- term.setCursorPos(1,1)
- term.write("Display redirected to Monitor")
- term.redirect(monitor)
- end
- -- Let's connect to the reactor peripheral
- local reactor = wrapThis("BigReactors-Reactor")
- if reactor == nil then
- error("Can't find reactor.")
- end
- local xClick, yClick = 0,0
- local controlRodLevel = 0
- local loopTime = 0.5
- local adjustamount = 5
- local basecontrolrodlevel = 40
- local dataLogging = false
- reactor.setAllControlRodLevels(basecontrolrodlevel)
- FC_API.clearMonitor("EZ-NUKE Control")
- --Done initializing
- local function displayBars()
- -- Draw some cool lines
- term.setBackgroundColor(colors.black)
- local width, height = term.getSize()
- for i=3, 5 do
- term.setCursorPos(22, i)
- term.write("|")
- end
- for i=1, width do
- term.setCursorPos(i, 2)
- term.write("-")
- end
- for i=1, width do
- term.setCursorPos(i, 6)
- term.write("-")
- end
- -- Draw some text
- fuelstring = "Fuel: "
- tempstring = "Temp: "
- energystring = "Producing: "
- local padding = math.max(string.len(fuelstring), string.len(tempstring),string.len(energystring))
- fuelpercentage = math.ceil(reactor.getFuelAmount()/reactor.getFuelAmountMax()*100)
- print(fuelstring,2,3)
- print(fuelpercentage.." %",padding+2,3)
- energy = reactor.getEnergyProducedLastTick()
- print(energystring,2,4)
- print(math.ceil(energy).."RF/t",padding+2,4)
- reactortemp = reactor.getTemperature()
- print(tempstring,2,5)
- print(reactortemp.." C",padding+2,5)
- -- Decrease rod button: 22X, 4Y
- -- Increase rod button: 28X, 4Y
- local rodamount = reactor.getNumberOfControlRods() - 1
- local rodtotal = 0
- for i=0, rodamount do
- rodtotal = rodtotal + reactor.getControlRodLevel(i)
- end
- rodpercentage = math.ceil(rodtotal/(rodamount+1))
- print("Control",23,3)
- print("< >",23,4)
- print(rodpercentage,25,4)
- print("percent",23,5)
- if (xClick == 22 and yClick == 4) then
- --Decrease rod level by amount
- newrodpercentage = rodpercentage - adjustamount
- if newrodpercentage < 0 then
- newrodpercentage = 0
- end
- xClick, yClick = 0,0
- reactor.setAllControlRodLevels(newrodpercentage)
- end
- if (xClick == 28 and yClick == 4) then
- --Increase rod level by amount
- newrodpercentage = rodpercentage + adjustamount
- if newrodpercentage > 100 then
- newrodpercentage = 100
- end
- xClick, yClick = 0,0
- reactor.setAllControlRodLevels(newrodpercentage)
- end
- local energystorage = reactor.getEnergyStored()
- storagepercent = math.floor(energystorage/10000000*100)
- paintutils.drawLine(2, 8, 28, 8, colors.gray)
- if storagepercent > 0 then
- paintutils.drawLine(2, 8, math.floor(27*storagepercent/100)+2, 8, colors.yellow)
- end
- term.setBackgroundColor(colors.black)
- print("Energy",2,7)
- print(storagepercent, width-(string.len(storagepercent)+3),7)
- print("%",28,7)
- term.setBackgroundColor(colors.black)
- end
- function reactorStatus()
- local width, height = term.getSize()
- local str = ""
- if reactor.getConnected() then
- if reactor.getActive() then
- str = "ONLINE"
- term.setTextColor(colors.green)
- else
- if autoStart then
- reactor.setActive(true)
- end
- str = "OFFLINE"
- term.setTextColor(colors.red)
- end
- if(xClick >= (width - string.len(str) - 1) and xClick <= (width-1)) then
- if yClick == 1 and not autoStart then
- reactor.setActive(not reactor.getActive())
- xClick, yClick = 0,0
- end
- end
- else
- str = "DISCONNECTED"
- term.setTextColor(colors.red)
- end
- print(str, width - string.len(str) - 1, 1)
- term.setTextColor(colors.white)
- end
- function main()
- while not finished do
- FC_API.clearMonitor("EZ-NUKE control")
- reactorStatus()
- if reactor.getConnected() then
- displayBars()
- sleep(loopTime)
- end
- end
- end
- function eventHandler()
- while not finished do
- event, arg1, arg2, arg3 = os.pullEvent()
- if event == "monitor_touch" then
- xClick, yClick = math.floor(arg2), math.floor(arg3)
- -- Draw debug stuff
- --print("Monitor touch X: "..xClick.." Y: "..yClick, 1, 10)
- elseif event == "mouse_click" and not monitor then
- xClick, yClick = math.floor(arg2), math.floor(arg3)
- --print("Mouse click X: "..xClick.." Y: "..yClick, 1, 11)
- elseif event == "char" and not inManualMode then
- local ch = string.lower(arg1)
- if ch == "q" then
- finished = true
- elseif ch == "r" then
- finished = true
- os.reboot()
- end
- end
- end
- end
- while not finished do
- parallel.waitForAny(eventHandler, main)
- sleep(loopTime)
- end
- term.clear()
- term.setCursorPos(1,1)
- FC_API.restoreNativeTerminal()
- term.clear()
- term.setCursorPos(1,1)
- --[[ OLD CODE USED FOR TESTING
- print("Program loaded. Scanning for reactor...");
- local reactor
- reactor = peripheral.wrap("back")
- isactive = reactor.getActive();
- if isactive == true
- print("Reactor active.");
- monitor.print("All's well!");
- else
- print("Reactor inactive.");
- end
- ]]--
Add Comment
Please, Sign In to add comment