Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = peripheral.find("BigReactors-Reactor")
- local tempEn = 0
- local targOut = -1
- local buttonColL = colors.lightGray
- local buttonColR = colors.lightGray
- local justStarted = false
- local starter = os.startTimer(2)
- local upperBound = 10000000 * 0.95
- local lowerBound = 10000000 * 0.75
- if not r.getActive() then
- r.setActive(true)
- end
- function calibrate()
- term.clear()
- term.setCursorPos(1, 1)
- print("Sleeping 20 seconds for calibration test #1")
- r.setAllControlRodLevels(0)
- sleep(20)
- local temp = r.getEnergyProducedLastTick()
- if temp > targOut then
- if temp - targOut > 25 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Sleeping 20 seconds for calibration test #2")
- r.setAllControlRodLevels(50)
- sleep(20)
- local temp2 = r.getEnergyProducedLastTick()
- r.setAllControlRodLevels((-0.000326859908360141 * targOut^2) + (0.0181019409748607 * targOut) + 83.7118241059938)
- sleep(20)
- end
- end
- end
- function drawRect(x1, y1, x2, y2, bgCol)
- local i = 0
- local ii = 0
- term.setBackgroundColor(bgCol)
- for ii = y1, y2 do
- for i = x1, x2 do
- term.setCursorPos(i, ii)
- term.write(" ")
- end
- end
- end
- function drawBarY(x1, y1, x2, y2, max, cur, col1, col2)
- local i = 0
- local ii = 0
- term.setBackgroundColor(col1)
- for i = y1, y2 do
- term.setCursorPos(x1, i)
- term.write(" ")
- end
- if cur ~= 0 then
- term.setBackgroundColor(col2)
- local perPoint = y1 + math.ceil((y2 - y1) / (max / cur))
- for ii = y1, y2 do
- for i = x1, x2 do
- if ii <= perPoint then
- term.setCursorPos(i, ii)
- term.write(" ")
- end
- end
- end
- end
- end
- function drawBarX(x1, y1, x2, y2, max, cur, col1, col2)
- local i = 0
- local ii = 0
- term.setBackgroundColor(col1)
- for i = x1, x2 do
- term.setCursorPos(i, y1)
- term.write(" ")
- end
- term.setBackgroundColor(col2)
- local perPoint = x1 + math.ceil((x2 - x1) / (max / cur))
- for ii = y1, y2 do
- for i = x1, x2 do
- if i <= perPoint then
- term.setCursorPos(i, ii)
- term.write(" ")
- end
- end
- end
- end
- function drawFuelBar(x1, y1, x2, y2, max, fCur, wCur, bgCol, fCol, wCol)
- drawBarX(x1, y1, x2, y2, max, fCur + wCur, bgCol, fCol)
- term.setBackgroundColor(wCol)
- if wCur ~= 0 then
- local temp = x1 + math.ceil((x2 - x1) / (max / wCur))
- for ii = y1, y2 do
- for i = x1, x2 do
- if i <= temp then
- term.setCursorPos(i, ii)
- term.write(" ")
- end
- end
- end
- end
- end
- function buttons(timer)
- local doit = true
- while doit do
- local event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- if x > 18 and x < 22 and y == 10 then
- if targOut > 50 then
- targOut = targOut - 50
- else
- targOut = -1
- calibrate()
- end
- os.cancelTimer(timer)
- buttonColL = colors.gray
- doit = false
- elseif targOut ~= -1 then
- if x > 21 + string.len(" " .. tostring(targOut) .. " ") and x < 21 + string.len(" " .. tostring(targOut) .. " ") + 4 and y == 10 then
- targOut = targOut + 50
- buttonColR = colors.gray
- doit = false
- os.cancelTimer(timer)
- end
- elseif targOut == -1 then
- if x > 21 + string.len(" Unlimited ") and x < 21 + string.len(" Unlimited ") + 4 and y == 10 then
- targOut = 50
- buttonColR = colors.gray
- doit = false
- os.cancelTimer(timer)
- end
- end
- elseif event == "timer" then
- if side == "starter" then
- justStarted = false
- else
- doit = false
- os.cancelTimer(timer)
- end
- end
- end
- end
- local mon = peripheral.find("monitor")
- term.redirect(mon)
- mon.setTextScale(0.5)
- if targOut ~= -1 then
- calibrate()
- else
- r.setAllControlRodLevels(0)
- end
- local timer = os.startTimer(0.05)
- local w, h = term.getSize()
- --set control rods to uniform level
- local controlNum = r.getNumberOfControlRods()
- local rodLevel = 0
- run = true
- while run do
- term.clear()
- --gather basic information
- local isActive = r.getActive()
- local storedEn = r.getEnergyStored()
- rodLevel = r.getControlRodLevel(0)
- if tempEn == 0 then
- tempEn = r.getEnergyStored()
- end
- local fuelTemp = math.ceil(r.getFuelTemperature() * 100) * 0.01
- local caseTemp = math.ceil(r.getCasingTemperature() * 100) * 0.01
- local fuelAmnt = r.getFuelAmount()
- local fuelMax = r.getFuelAmountMax()
- local wasteAmnt = r.getWasteAmount()
- local produce = (tempEn - storedEn)
- if produce <= targOut + 25 and produce >= targOut - 25 and isActive then
- justStarted = false
- end
- local fuelUse = math.ceil(r.getFuelConsumedLastTick() * 100) * 0.01
- --top left
- drawRect(2, 2, w - 20, 2, colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos((2 + (w - 20) - string.len(" General Information ")) / 2, 2)
- term.write(" General Information ")
- drawRect(2, 2, 2, 12, colors.lightGray)
- drawRect(2, 12, w - 20, 12, colors.lightGray)
- drawRect(w - 20, 2, w - 20, 12, colors.lightGray)
- --middle left
- drawRect(2, 14, w - 20, 14, colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos((2 + (w - 20) - string.len(" Fuel Information ")) / 2, 14)
- term.write(" Fuel Information ")
- drawRect(2, 14, 2, h - 1, colors.lightGray)
- drawRect(2, h - 1, w - 20, h - 1, colors.lightGray)
- drawRect(w - 20, 14, w - 20, h - 1, colors.lightGray)
- --right
- drawRect(w - 18, 2, w - 1, 2, colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if controlNum > 1 then
- term.setCursorPos((w - 18 + (w - 1) - string.len(" Control Rods ")) / 2, 2)
- term.write(" Control Rods ")
- else
- term.setCursorPos((w - 18 + (w - 1) - string.len(" Control Rod ")) / 2, 2)
- term.write(" Control Rod ")
- end
- drawRect(w - 18, 2, w - 18, h - 1, colors.lightGray)
- drawRect(w - 18, h - 1, w - 1, h - 1, colors.lightGray)
- drawRect(w - 1, 2, w - 1, h - 1, colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(4, 4)
- write("Reactor is ")
- if isActive then
- term.setTextColor(colors.green)
- write("On")
- else
- term.setTextColor(colors.red)
- write("Off")
- end
- term.setCursorPos(4, 5)
- term.setTextColor(colors.white)
- write("Core Temperature: ")
- term.setTextColor(colors.yellow)
- write(fuelTemp)
- term.setTextColor(colors.white)
- write(" C")
- term.setCursorPos(4, 6)
- term.setTextColor(colors.white)
- write("Case Temperature: ")
- term.setTextColor(colors.yellow)
- write(caseTemp)
- term.setTextColor(colors.white)
- write(" C")
- term.setCursorPos(4, 7)
- term.setTextColor(colors.white)
- write("Stored Energy: ")
- if storedEn >= 5000000 then
- term.setTextColor(colors.green)
- elseif storedEn >= 2500000 then
- term.setTextColor(colors.orange)
- else
- term.setTextColor(colors.red)
- end
- write(storedEn)
- term.setTextColor(colors.white)
- write(" RF")
- term.setCursorPos(4, 8)
- term.setTextColor(colors.white)
- write("Energy Per Tick: ")
- if produce < 0 then
- term.setTextColor(colors.green)
- write(math.abs(produce))
- else
- if produce == 0 and storedEn >= upperBound and isActive then
- term.setTextColor(colors.green)
- write(produce)
- r.setActive(false)
- justStarted = true
- starter = os.startTimer(20)
- else
- term.setTextColor(colors.red)
- write(produce)
- end
- end
- term.setTextColor(colors.white)
- write(" RF")
- term.setCursorPos(4, 10)
- term.setTextColor(colors.white)
- write("Target Output: ")
- term.setBackgroundColor(buttonColL)
- term.setTextColor(colors.black)
- write(" < ")
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- if targOut ~= -1 then
- write(" " .. tostring(targOut) .. " ")
- else
- write(" Unlimited ")
- end
- term.setBackgroundColor(buttonColR)
- term.setTextColor(colors.black)
- write(" > ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- term.setCursorPos(4, 19)
- write("Waste: ")
- if wasteAmnt >= fuelMax / 2 then
- term.setTextColor(colors.red)
- write(wasteAmnt)
- elseif wasteAmnt >= fuelMax / 4 then
- term.setTextColor(colors.orange)
- write(wasteAmnt)
- else
- term.setTextColor(colors.green)
- write(wasteAmnt)
- end
- term.setTextColor(colors.white)
- write(" mB")
- term.setTextColor(colors.cyan)
- term.setCursorPos(4, 20)
- write("Fuel: ")
- if fuelAmnt >= fuelMax / 2 then
- term.setTextColor(colors.green)
- write(fuelAmnt)
- elseif fuelAmnt >= fuelMax / 4 then
- term.setTextColor(colors.orange)
- write(fuelAmnt)
- else
- term.setTextColor(colors.red)
- write(fuelAmnt)
- end
- term.setTextColor(colors.white)
- write(" mB")
- term.setTextColor(colors.white)
- term.setCursorPos(4, 21)
- write("Free Space: ")
- term.setTextColor(colors.yellow)
- write(fuelMax - (fuelAmnt + wasteAmnt))
- if storedEn <= lowerBound and isActive == false then
- r.setActive(true)
- end
- term.setTextColor(colors.white)
- write(" mB")
- drawFuelBar(4, 17, w - 22, 17, fuelMax, fuelAmnt, wasteAmnt, colors.white, colors.cyan, colors.blue)
- drawRect(w - 7, 4, w - 4, h - 3, colors.lightGray)
- drawBarY(w - 5, 5, w - 5, h - 4, 100, rodLevel, colors.cyan, colors.blue)
- drawBarY(w - 6, 5, w - 6, h - 4, 100, rodLevel, colors.cyan, colors.blue)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(w - 17 + (((w - 9) - (w - 17)) - string.len(tostring(rodLevel) .. "%")) / 2, h / 2)
- write(rodLevel .. "%")
- buttonColL = colors.lightGray
- buttonColR = colors.lightGray
- tempEn = r.getEnergyStored()
- if (r.getEnergyProducedLastTick() < targOut - 25 or r.getEnergyProducedLastTick() > targOut + 25) and isActive and justStarted == false and targOut ~= -1 then
- calibrate()
- timer = os.startTimer(0.05)
- end
- buttons(timer)
- timer = os.startTimer(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement