Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local progVer = "1.06"
- local progName = "IC_SimpleNuke"
- local loopTime = 0.5 -- Time between program loops, in seconds. Increase this value if program somehow causes a lot of lag. Which should not happen on any computers made this century
- local baseControlRodLevel = 0 -- Put this as close to what you guess the optimum control rod level will be for your reactor, plus a little more
- local minStoredEnergyPercent = 20 -- Min energy % to store before activating, probably keep it at default (20)
- local maxStoredEnergyPercent = 94 -- Max energy % to store before shutdown, probably keep it at default (70)
- -- This program doesn't care about heat anymore, only tried to maintain the internal power buffer, following 2 lines only included for legacy
- local minReactorTemp = 20 -- Minimum reactor temperature (^C) to maintain
- local maxReactorTemp = 1400 -- Maximum reactor temperature (^C) to maintain
- ----------
- -- Basic side determination for wrapping
- function getDeviceSide(deviceType)
- deviceType = deviceType:lower()
- for i, side in pairs(rs.getSides()) do
- if (peripheral.isPresent(side)) then
- if (string.lower(peripheral.getType(side)) == deviceType) then
- return side;
- end
- end
- end
- return nil;
- end
- -- Peripheral wrapping function
- function wrapThis(thing, f)
- local wrapped = nil
- 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
- print("Initializing program...",1,1);
- -- Initialize the monitor
- -- If it can't find a monitor, will wait 5 seconds then reboot
- -- This is needed for server restarts when the computer starts up before the modem does
- local monitor = wrapThis("monitor", 0)
- if monitor == nil then
- sleep(5)
- finished = true
- os.reboot()
- end
- -- local monitorx, monitory = monitor.getSize()
- -- if monitorx ~= 29 or monitory ~= 12 then
- -- print("Monitor is the wrong size! Needs to be 3x2.")
- -- sleep(5)
- -- finished = true
- -- os.reboot()
- -- end
- monitor.setTextScale(2)
- -- Connect to the big reactor peripheral
- -- If it can't find a reactor, will wait 5 seconds then reboot
- -- This is needed for server restarts when the computer starts up before the modem does
- local reactor = wrapThis("BigReactors-Reactor", 0)
- if reactor == nil then
- sleep(5)
- finished = true
- os.reboot()
- end
- -- Easyprint, saves program space elsewhere
- local function print(str, x, y)
- term.setCursorPos(x, y)
- term.write(str)
- end
- -- Move stuff to monitor
- if monitor then
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- term.write("Display redirected to Monitor. Type r to reboot, or")
- term.setCursorPos(1,2)
- term.write("q to quit and return control to this terminal.")
- term.redirect(monitor)
- end
- -- Restore functions to computer terminal
- function restoreNativeTerminal()
- repeat
- term.restore()
- local w, h = term.getSize()
- until w == 51 and h == 19
- end
- -- Draw some decorative lines
- function drawLines()
- term.setBackgroundColor(colors.black)
- paintutils.drawLine(1, 1, 29, 1, colors.lightBlue)
- paintutils.drawLine(1, 8, 29, 8, colors.lightBlue)
- term.setBackgroundColor(colors.black)
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- -- Just to make sure they're relatively high before the control program starts
- if reactor then
- sleep(1)
- reactor.setAllControlRodLevels(0)
- else
- sleep(5)
- finished = true
- os.reboot()
- end
- -- Draw stuff on the monitor
- local function drawInfo()
- statusstring = "Reactor status: "
- tempstring = "Temperature: "
- tempstring2 = "deg. C"
- powerstring = "Power Output: "
- powerstring2 = "RF/t"
- rodstring = "Control Rods: "
- rodstring2 = "%"
- fuelstring = "Fuel Consume:"
- fuelstring2 = "mB/t"
- levelstring = "Fuel:"
- levelstring2 = "mB"
- monitor.setTextColor(colors.white)
- print(statusstring,1,2)
- if reactor.getActive() then
- monitor.setTextColor(colors.green)
- print(" online",23,2)
- else
- monitor.setTextColor(colors.red)
- print("offline",23,2)
- end
- monitor.setTextColor(colors.white)
- reactortemp = math.floor(reactor.getFuelTemperature())
- print(tempstring,1,3)
- print(reactortemp,16,3)
- print(tempstring2,24,3)
- power = math.floor(reactor.getEnergyProducedLastTick())
- print(powerstring,1,4)
- print(power,16,4)
- print(powerstring2,26,4)
- rods = reactor.getControlRodLevel(0)
- print(rodstring,1,5)
- print(rods,16,5)
- print(rodstring2,29,5)
- fuel = round(reactor.getFuelConsumedLastTick(),4)
- if reactor.getActive() == false then
- fuel = "0.0000"
- end
- print(fuelstring,1,6)
- print(fuel,16,6)
- print(fuelstring2,26,6)
- print("F:",1,7)
- print(reactor.getFuelAmount(),4,7)
- print("mB / W:",12,7)
- print(reactor.getWasteAmount(),22,7)
- print(levelstring2,28,7)
- end
- -- Draw stuff on the bottom part of the monitor, power bar etc
- function drawBottomPart()
- reactivity = math.floor(reactor.getFuelReactivity())
- paintutils.drawLine(2, 10, 28, 10, colors.gray)
- if reactivity > 400 then
- paintutils.drawLine(2, 10, math.floor(26*reactivity/500)+1, 10, colors.red)
- elseif reactivity > 320 then
- paintutils.drawLine(2, 10, math.floor(26*reactivity/500)+1, 10, colors.orange)
- elseif reactivity > 240 then
- paintutils.drawLine(2, 10, math.floor(26*reactivity/500)+1, 10, colors.yellow)
- elseif reactivity > 160 then
- paintutils.drawLine(2, 10, math.floor(26*reactivity/500)+1, 10, colors.green)
- elseif reactivity > 0 then
- paintutils.drawLine(2, 10, math.floor(26*reactivity/500)+1, 10, colors.blue)
- end
- term.setBackgroundColor(colors.black)
- print("Fuel Reactivity:",1,9)
- print(reactivity,24,9)
- print("%",29,9)
- term.setBackgroundColor(colors.black)
- energystorage = reactor.getEnergyStored()
- storagepercent = math.floor(energystorage/10000000*100)
- paintutils.drawLine(2, 12, 28, 12, colors.gray)
- if storagepercent > 4 then
- paintutils.drawLine(2, 12, math.floor(26*storagepercent/100)+2, 12, colors.yellow)
- elseif storagepercent > 0 then
- paintutils.drawPixel(2,12,colors.yellow)
- end
- term.setBackgroundColor(colors.black)
- print("Internal buffer: ",1,11)
- print(storagepercent,24,11)
- print("%",29,11)
- end
- -- Controls the reactor, keeping it between configured temps and power storage
- function control()
- energystorage = reactor.getEnergyStored()
- reactortemp = math.floor(reactor.getFuelTemperature())
- ediff = (maxStoredEnergyPercent - minStoredEnergyPercent)*100000
- ediffper = ediff / 100
- if energystorage > maxStoredEnergyPercent*100000 then
- reactor.setActive(false)
- reactor.setAllControlRodLevels(95)
- elseif energystorage < minStoredEnergyPercent*100000 then
- reactor.setActive(true)
- reactor.setAllControlRodLevels(baseControlRodLevel)
- end
- end
- -- Main program
- function main()
- while not finished do
- if reactor.getConnected() then
- drawLines()
- drawInfo()
- drawBottomPart()
- control()
- sleep(loopTime)
- end
- end
- end
- -- Event handler for exiting, editting and debugging
- function eventHandler()
- while not finished do
- event, arg1, arg2, arg3 = os.pullEvent()
- if 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
- -- Returns control to the terminal if the program has an error or whatever
- term.clear()
- term.setCursorPos(1,1)
- restoreNativeTerminal()
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement