Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- all credit goes to Hexicube @ http://www.computercraft.info/forums2/index.php?/topic/2038-nuclear-reactor-control-system/ for this code.
- -- the purpose of this paste is to make it easier to import into your world.
- -- this setup uses 1 bundled cable
- --[[START OF CONFIG]]--
- --[[POSSIBLE CABLE COLOURS]]--
- --white orange magneta lightBlue
- --yellow lime pink gray
- --lightGray cyan purple blue
- --brown green red black
- --[[BUNDLED CABLE SIDE]]--
- local cableSide = "back" --side of computer the bundled cable is on
- --[[REQUIRED CABLES]]--
- local coolDownCol = colors.white --input from heat sensor (temp should be lower than heatUp one)
- local heatUpCol = colors.red --input from heat sensor (temp should be higher than coolDown one)
- local controlCol = colors.black --output to control the reactor
- --[[OPTIONAL CABLES]]--
- local storageStateCol = colors.green --input from EU storage set to "Emit if partially full"
- local onCol = colors.pink --output to show the reactor is online
- local offCol = colors.purple --output to show the reactor is offline
- local emptyCol = colors.lime --output to show the reactor needs uranium [requires storageStateCol]
- local storageFullCol = colors.orange --output to show the EU storage is full [requires storageStateCol]
- --[[OTHER SETTINGS]]--
- local companyName = "HexCorp Industries" --name of your company
- --[[END OF CONFIG]]--
- os.pullEvent = os.pullEventRaw --Prevent Ctrl+T from closing the program
- --Initialise reactor state variables
- local reactorEnabled = true
- local reactorEmpty = false
- local storageFull = false
- local timeSinceActive = 0
- local timeSinceFull = 0
- local timeSinceNotFull = 0
- local width, height = term.getSize() --Store the size of the screen
- local function clearScreen()
- term.clear() --Clear the screen
- --Print the program and company names
- term.setCursorPos(1, 1)
- term.write("Nuclear Reactor Control Unit")
- term.setCursorPos(width-#companyName+1, height)
- term.write(companyName)
- end
- local function doTick()
- --Increment reactor active timer and check inputs
- timeSinceActive = timeSinceActive + 1
- local hot = rs.testBundledInput(cableSide, heatUpCol)
- local cold = rs.testBundledInput(cableSide, coolDownCol)
- local full = rs.testBundledInput(cableSide, storageStateCol)
- if full then --The EU storage is giving a signal, increment its variable
- timeSinceFull = timeSinceFull + 1
- timeSinceNotFull = 0
- else --The EU storage is not giving a signal, increment its other variable
- timeSinceNotFull = timeSinceNotFull + 1
- timeSinceFull = 0
- storageFull = false
- end
- if timeSinceFull >= 20 then --There has been an EU signal for 20 ticks, the EU storage may be full
- hot = true
- timeSinceFull = 20
- storageFull = true
- else storageFull = false end
- if timeSinceNotFull >= 20 then --There has not been an EU signal for 20 ticks, the reactor may be out of uranium
- timeSinceNotFull = 20
- reactorEmpty = true
- else reactorEmpty = false end
- if reactorEnabled then
- if hot then --Disable the reactor, because it is too hot
- reactorEnabled = false
- reactorEmpty = false
- end
- else
- reactorEmpty = false
- if not cold then --Enable the reactor, because it has cooled down
- reactorEnabled = true
- timeSinceActive = 0
- end
- end
- clearScreen()
- term.setCursorPos(1, 3)
- term.write("Current status: ")
- if reactorEmpty then
- term.write("Cells Depleted")
- rs.setBundledOutput(cableSide, emptyCol + onCol)
- elseif storageFull then
- term.write("Energy Storage Full")
- rs.setBundledOutput(cableSide, storageFullCol + offCol + controlCol)
- elseif reactorEnabled then
- term.write("Active")
- rs.setBundledOutput(cableSide, onCol)
- else
- term.write("Inactive")
- rs.setBundledOutput(cableSide, offCol + controlCol)
- end
- term.setCursorPos(1, 4)
- term.write("Temperature: ")
- if hot then term.write("|Cold |Warm >Hot")
- elseif cold then term.write("|Cold >Warm |Hot")
- else term.write(">Cold |Warm |Hot") end
- sleep(0.25) --Four ticks to the second
- end
- while true do doTick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement