Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Author: MJRLegends
- --Modified by: AitchCay
- --Modified, only works for 1 reactor + 2 turbine system.
- --Designed for single screen display of info, and 2nd screen for control.
- mouseX = 0
- mouseY = 0
- currentTurbine = 1
- setting = false
- control = false
- monitorFound = false
- turbines = {}
- turbinesManagement = {}
- turbine = null
- totalreactors = 0
- turbine1 = null
- turbine2 = null
- reactor1 = null
- controlrodaverage = 0
- function draw_line(x, y, length, color)
- monitor.setBackgroundColor(color)
- monitor.setCursorPos(x,y)
- monitor.write(string.rep(" ", length))
- end
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- function progress_bar_multi_line(x, y, length, minVal, maxVal, bar_color, bg_color, numberOFLine)
- local barSize = math.floor((minVal/maxVal) * length)
- y = y - 1
- for i=1,numberOFLine,1 do
- draw_line(x, y + i, length, bg_color) --background bar
- draw_line(x, y + i, barSize, bar_color) --progress so far
- end
- end
- function draw_text(x, y, text, text_color, bg_color)
- monitor.setBackgroundColor(bg_color)
- monitor.setTextColor(text_color)
- monitor.setCursorPos(x,y)
- monitor.write(text)
- end
- function terminalOutput()
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- term.setCursorPos(1,1)
- term.write("Turbine Status")
- term.setTextColor(colors.red)
- term.setCursorPos(1,3)
- term.write("Note: Monitors are optional")
- term.setTextColor(colors.cyan)
- term.setCursorPos(1,5)
- term.write("Peripheral Connected:")
- end
- function initPeripherals()
- local perList = peripheral.getNames()
- local yLevel = 6
- local turbineNumber = 1
- reactorNumber = 1
- reactors = {}
- reactorsManagement = {}
- turbines = {}
- turbinesManagement = {}
- monitorFound = false
- term.setTextColor(colors.yellow)
- for i=1,#perList,1 do
- if peripheral.getType(perList[i]) == "monitor" and monitorFound == false then
- monitor = peripheral.wrap(perList[i])
- term.setCursorPos(1,yLevel)
- term.write("Monitor Found!")
- yLevel = yLevel + 1
- monitorFound = true
- elseif peripheral.getType(perList[i]) == "BigReactors-Turbine" then
- table.insert(turbines, turbineNumber, perList[i])
- table.insert(turbinesManagement, turbineNumber, false)
- turbineNumber = turbineNumber +1
- elseif peripheral.getType(perList[i]) == "BigReactors-Reactor" then
- table.insert(reactors, reactorNumber, perList[i])
- table.insert(reactorsManagement, reactorNumber, true)
- totalreactors = totalreactors +1
- reactorNumber = reactorNumber +1
- end
- end
- term.setCursorPos(1,yLevel)
- term.write((turbineNumber - 1) .. " Turbine Found!")
- turbine = peripheral.wrap(turbines[currentTurbine])
- end
- function drawMainScreen()
- displayW,displayH=monitor.getSize()
- monitor.clear()
- monitor.setTextColour(colours.blue)
- monitor.setCursorPos(12,1)
- monitor.write("Power System Status")
- monitor.setTextColour(colours.blue)
- monitor.setCursorPos(0,2)
- monitor.write(string.rep("-", displayW))
- monitor.setTextColour(colours.white)
- turbineDisplayRows = 6
- reactorDisplayRows = 3
- numberOfActiveTurbines = 0
- totalProducedEnergy = 0
- totalBufferedEnergy = 0
- totalBufferedSteam = 0
- totalBufferedWater = 0
- for i=1,#turbines,1 do
- tempTurbine = peripheral.wrap(turbines[i])
- if tempTurbine.getActive() then
- numberOfActiveTurbines = numberOfActiveTurbines + 1
- end
- totalProducedEnergy = totalProducedEnergy + tempTurbine.getEnergyProducedLastTick()
- -- totalBufferedEnergy = totalBufferedEnergy + tempTurbine.getEnergyStored()
- -- totalBufferedSteam = totalBufferedSteam + tempTurbine.getInputAmount()
- -- totalBufferedWater = totalBufferedWater + tempTurbine.getOutputAmount()
- end
- monitor.setCursorPos(1,3)
- -- monitor.write("Number of Online Turbines: " .. numberOfActiveTurbines .. "/" .. table.getn(turbines))
- -- monitor.setTextColour(colours.blue)
- -- monitor.setCursorPos(0,5)
- -- monitor.write(string.rep("-", displayW))
- -- monitor.setTextColour(colours.white)
- monitor.setCursorPos(1,4)
- monitor.setTextColour(colours.white)
- if totalProducedEnergy < 1000000 then
- monitor.write("Total Energy Production: " .. math.floor(totalProducedEnergy / 1000) .. " KRF/T")
- else
- monitor.write("Total Energy Production: " .. math.floor(totalProducedEnergy / 1000000) .. " MRF/T")
- end
- -- monitor.write("Total Turbine Buffer: " .. totalBufferedEnergy / 1000 .. " kRF")
- -- progress_bar_multi_line(2, 5, displayW-2, totalBufferedEnergy, (1000000 * table.getn(turbines)), colors.green, colors.gray, 2)
- monitor.setBackgroundColor(colours.black)
- -- monitor.setCursorPos(1,11)
- if totalreactors > 0 then
- currentReactor = peripheral.wrap(reactors[1])
- draw_text(1, 6, "Reactor ", colors.yellow, colors.black)
- if currentReactor.getActive() then
- draw_text(15, 6, "Online", colors.green, colors.black)
- else
- draw_text(15, 6, "Offline", colors.red, colors.black)
- end
- draw_text(2, 7, "Case Temp: ", colors.yellow, colors.black, monitor)
- local maxVal = 5000
- local minVal = math.floor(currentReactor.getCasingTemperature())
- draw_text(15 , 7, minVal.." C", colors.white, colors.black, monitor)
- -- if minVal < 500 then
- -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray, monitor)
- -- elseif minVal < 1000 then
- -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.lime, colors.gray, monitor)
- -- elseif minVal < 1500 then
- -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.yellow, colors.gray, monitor)
- -- elseif minVal >= 1500 then
- -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.red, colors.gray, monitor)
- -- end
- draw_text(2, 8, "Burn Rate: ", colors.yellow, colors.black, monitor)
- draw_text(15, 8, tonumber(string.format("%.3f", currentReactor.getFuelConsumedLastTick())) .." mB/t", colors.white, colors.black, monitor)
- end
- for i=1,#turbines,1 do
- turbine = peripheral.wrap(turbines[i])
- draw_text(1, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Turbine " .. i , colors.yellow, colors.black)
- if turbine.getActive() then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Online", colors.green, colors.black)
- else
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Disabled", colors.red, colors.black)
- end
- draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 2, "Output: ", colors.yellow, colors.black)
- rft = math.floor(turbine.getEnergyProducedLastTick())
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 2, rft.." RF/T", colors.white, colors.black)
- draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 3, "Rotor Speed: ", colors.yellow, colors.black)
- local minVal = math.floor(turbine.getRotorSpeed())
- --draw_text(15, (turbineDisplayRows * i) + 3, minVal.." rpm", colors.white, colors.black)
- if minVal < 700 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.lightBlue, colors.black)
- elseif minVal < 950 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.green, colors.black)
- elseif minVal < 1750 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.lightBlue, colors.black)
- elseif minVal < 1850 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.green, colors.black)
- elseif minVal < 2000 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.yellow, colors.black)
- elseif minVal >= 2000 then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.red, colors.black)
- end
- draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 4, "Steam Flow: ", colors.yellow, colors.black)
- flow_rate = turbine.getFluidFlowRateMax()
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 4, flow_rate.." mB/t", colors.white, colors.black)
- engaged = turbine.getInductorEngaged()
- draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Coils: ", colors.yellow, colors.black)
- if engaged then
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Engaged", colors.green, colors.black)
- else
- draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Disengaged", colors.red, colors.black)
- end
- end
- monitor.setTextColour(colours.white)
- monitor.setBackgroundColor(colours.blue)
- monitor.setCursorPos(1,displayH - 1)
- monitor.write(" Control Screen ")
- monitor.setBackgroundColor(colours.black)
- end
- function drawControlScreen()
- displayW,displayH=monitor.getSize()
- monitor.clear()
- monitor.setCursorPos(13, 4)
- monitor.setTextColour(colours.blue)
- monitor.write(" Power Control ")
- monitor.setTextColour(colours.white)
- w,h=monitor.getSize()
- reactor1DrawOffset = 9
- turbine1DrawOffset = 14
- turbine2DrawOffset = 19
- -------------------------- REACTOR --------------------------
- controlrodaverage = 0
- active = reactor1.getActive()
- monitor.setCursorPos(1, reactor1DrawOffset)
- monitor.write("Reactor 1" )
- if active then
- monitor.setBackgroundColour(colours.green)
- else
- monitor.setBackgroundColour(colours.grey)
- end
- monitor.setCursorPos(12, reactor1DrawOffset)
- monitor.write("Enable")
- if active then
- monitor.setBackgroundColour(colours.grey)
- else
- monitor.setBackgroundColour(colours.green)
- end
- monitor.setCursorPos(19, reactor1DrawOffset)
- monitor.write("Disable")
- monitor.setBackgroundColour(colours.black)
- draw_text(1, reactor1DrawOffset + 2, "Control Rods", colors.white, colors.black)
- draw_text(14, reactor1DrawOffset + 2, "Insert", colors.white, colours.blue)
- draw_text(21, reactor1DrawOffset + 2, "Retract", colors.white, colours.blue)
- for i=0,(reactor1.getNumberOfControlRods() -1 ), 1 do
- controlrodaverage = controlrodaverage + reactor1.getControlRodLevel(i)
- end
- controlrodaverage = controlrodaverage / reactor1.getNumberOfControlRods()
- draw_text(30, reactor1DrawOffset + 2, math.floor(controlrodaverage) .. "%", colors.white, colours.black)
- monitor.setBackgroundColour(colours.black)
- -------------------------TURBINE 1 -------------------------------
- active = turbine1.getActive()
- monitor.setCursorPos(1, turbine1DrawOffset)
- monitor.write("Turbine 1" )
- if active then
- monitor.setBackgroundColour(colours.green)
- else
- monitor.setBackgroundColour(colours.grey)
- end
- monitor.setCursorPos(12, turbine1DrawOffset)
- monitor.write("Enable")
- if active then
- monitor.setBackgroundColour(colours.grey)
- else
- monitor.setBackgroundColour(colours.green)
- end
- monitor.setCursorPos(19, turbine1DrawOffset)
- monitor.write("Disable")
- draw_text(1, turbine1DrawOffset + 2, "Flow Rate", colors.white, colors.black)
- draw_text(17, turbine1DrawOffset + 2, "Inc+5", colors.white, colours.blue)
- draw_text(23, turbine1DrawOffset + 2, "Dec-5", colors.white, colours.blue)
- draw_text(30, turbine1DrawOffset + 2, turbine1.getFluidFlowRateMax() .. " mB/t", colors.white, colours.black)
- monitor.setBackgroundColour(colours.black)
- -------------------------TURBINE 2 -------------------------------
- active = turbine2.getActive()
- monitor.setCursorPos(1, turbine2DrawOffset )
- monitor.write("Turbine 2")
- if active then
- monitor.setBackgroundColour(colours.green)
- else
- monitor.setBackgroundColour(colours.grey)
- end
- monitor.setCursorPos(12, turbine2DrawOffset)
- monitor.write("Enable")
- if active then
- monitor.setBackgroundColour(colours.grey)
- else
- monitor.setBackgroundColour(colours.green)
- end
- monitor.setCursorPos(19, turbine2DrawOffset)
- monitor.write("Disable")
- monitor.setBackgroundColour(colours.black)
- draw_text(1, turbine2DrawOffset + 2, "Flow Rate", colors.white, colors.black)
- draw_text(17, turbine2DrawOffset + 2, "Inc+5", colors.white, colours.blue)
- draw_text(23, turbine2DrawOffset + 2, "Dec-5", colors.white, colours.blue)
- draw_text(30, turbine2DrawOffset + 2, turbine2.getFluidFlowRateMax() .. " mB/t", colors.white, colours.black)
- -----------Bottom Bar Buttons---------------------
- -- if setting then
- -- monitor.setBackgroundColour(colours.grey)
- -- else
- -- monitor.setBackgroundColour(colours.blue)
- -- end
- -- monitor.setCursorPos(displayW - 10,displayH - 1)
- -- monitor.write(" Settings ")
- -- monitor.setBackgroundColour(colours.black)
- monitor.setBackgroundColour(colours.blue)
- monitor.setCursorPos(2,displayH - 1)
- monitor.write(" Main Menu ")
- monitor.setBackgroundColour(colours.black)
- end
- function drawDisplayScreen()
- displayW,displayH=monitor.getSize()
- -----------Router speed---------------------
- draw_text(2, 5, "Rotor Speed: ", colors.yellow, colors.black)
- local maxVal = 2000
- local minVal = math.floor(turbine.getRotorSpeed())
- draw_text(19, 5, minVal.." rpm", colors.white, colors.black)
- if minVal < 700 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
- elseif minVal < 900 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
- elseif minVal < 1700 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
- elseif minVal < 1900 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
- elseif minVal < 2000 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
- elseif minVal >= 2000 then
- progress_bar(2, 6, displayW-2, minVal, maxVal, colors.red, colors.gray)
- end
- -----------Steam Level---------------------
- draw_text(2, 8, "Steam Amount: ", colors.yellow, colors.black)
- local maxVal = 4000
- local minVal = math.floor(turbine.getInputAmount())
- draw_text(19, 8, minVal.." mB", colors.white, colors.black)
- progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lightGray, colors.gray)
- -----------Water Level---------------------
- draw_text(2, 11, "Water Amount: ", colors.yellow, colors.black)
- local maxVal = 4000
- local minVal = math.floor(turbine.getOutputAmount())
- draw_text(19, 11, minVal.." mB", colors.white, colors.black)
- progress_bar(2, 12, displayW-2, minVal, maxVal, colors.blue, colors.gray)
- -------------OUTPUT-------------------
- draw_text(2, 14, "RF/tick: ", colors.yellow, colors.black)
- rft = math.floor(turbine.getEnergyProducedLastTick())
- draw_text(19, 14, rft.." RF/T", colors.white, colors.black)
- -----------RF STORAGE---------------
- -- draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
- -- local maxVal = 1000000
- -- local minVal = energy_stored
- -- local percent = math.floor((energy_stored/maxVal)*100)
- -- draw_text(19, 15, percent.."%", colors.white, colors.black)
- ------------FLOW RATE----------------
- draw_text(2, 16, "Flow Rate: ", colors.yellow, colors.black)
- flow_rate = turbine.getFluidFlowRateMax()
- draw_text(19, 16, flow_rate.." mB/t", colors.white, colors.black)
- ------------COILS---------------------------
- engaged = turbine.getInductorEngaged()
- draw_text(2, 17, "Coils: ", colors.yellow, colors.black)
- if engaged then
- draw_text(19, 17, "Engaged", colors.white, colors.black)
- else
- draw_text(19, 17, "Disengaged", colors.white, colors.black)
- end
- end
- function drawSettingScreen()
- displayW,displayH=monitor.getSize()
- -------------Title-------------------
- draw_text(16, 6, "Settings", colors.blue, colors.black)
- monitor.setTextColour(colours.blue)
- monitor.setCursorPos(0,7)
- monitor.write(string.rep("-", displayW))
- monitor.setTextColour(colours.white)
- -----------Turbine Management Enable/Disable---------------------
- monitor.setCursorPos(1,9)
- monitor.write("Turbine Management: ")
- if turbinesManagement[currentTurbine] == true then
- monitor.setBackgroundColour(colours.blue)
- else
- monitor.setBackgroundColour(colours.grey)
- end
- monitor.setCursorPos(20,9)
- monitor.write(" ON ")
- if turbinesManagement[currentTurbine] == true then
- monitor.setBackgroundColour(colours.grey)
- else
- monitor.setBackgroundColour(colours.blue)
- end
- monitor.setCursorPos(25,9)
- monitor.write(" OFF ")
- monitor.setBackgroundColour(colours.black)
- end
- function management()
- for i=1,#turbines,1 do
- if turbinesManagement[i] == true then
- tempTurbine = peripheral.wrap(turbines[i])
- active = tempTurbine.getActive()
- energy_stored = tempTurbine.getEnergyStored()
- rotorSpeed = tempTurbine.getRotorSpeed()
- local maxVal = 1000000
- local minVal = energy_stored
- local percent = math.floor((energy_stored/maxVal)*100)
- if rotorSpeed < 1801 then
- if percent > 99 then
- tempTurbine.setActive(false)
- elseif percent < 75 then
- tempTurbine.setActive(true)
- end
- else
- tempTurbine.setActive(false)
- end
- end
- end
- end
- function checkClickPosition()
- displayW,displayH=monitor.getSize()
- if control == false then
- if mouseX > 0 and mouseX < 20 and mouseY > displayH - 2 and mouseY < displayH then
- control = true
- end
- else
- if mouseX > 11 and mouseX < 18 and mouseY == 9 then
- reactor1.setActive(true)
- elseif mouseX > 18 and mouseX < 26 and mouseY == 9 then
- reactor1.setActive(false)
- elseif mouseX > 11 and mouseX < 18 and mouseY == 14 then
- turbine1.setActive(true)
- elseif mouseX > 18 and mouseX < 26 and mouseY == 14 then
- turbine1.setActive(false)
- elseif mouseX > 11 and mouseX < 18 and mouseY == 19 then
- turbine2.setActive(true)
- elseif mouseX > 18 and mouseX < 26 and mouseY == 19 then
- turbine2.setActive(false)
- elseif mouseX > 14 and mouseX < 20 and mouseY == 11 then
- reactor1.setAllControlRodLevels(controlrodaverage + 1)
- elseif mouseX > 20 and mouseX < 28 and mouseY == 11 then
- reactor1.setAllControlRodLevels(controlrodaverage - 1)
- elseif mouseX > 16 and mouseX < 22 and mouseY == 16 then
- turbine1.setFluidFlowRateMax(turbine1.getFluidFlowRateMax() + 5)
- elseif mouseX > 22 and mouseX < 28 and mouseY == 16 then
- turbine1.setFluidFlowRateMax(turbine1.getFluidFlowRateMax() - 5)
- elseif mouseX > 16 and mouseX < 22 and mouseY == 21 then
- turbine2.setFluidFlowRateMax(turbine2.getFluidFlowRateMax() + 5)
- elseif mouseX > 22 and mouseX < 28 and mouseY == 21 then
- turbine2.setFluidFlowRateMax(turbine2.getFluidFlowRateMax() - 5)
- elseif mouseX > 1 and mouseX < (displayW - 26) and mouseY == (displayH - 1) then
- control = false
- setting = false
- elseif mouseX > (displayW - 10) and mouseX < displayW and mouseY == (displayH - 1) then
- if setting then
- setting = false
- else
- setting = true
- end
- elseif mouseX > (displayW - 9) and mouseX < (displayW - 7) and mouseY == 1 then
- if currentTurbine > 1 then
- currentTurbine = currentTurbine - 1
- turbine = peripheral.wrap(turbines[currentTurbine])
- end
- elseif mouseX > (displayW - 6) and mouseX < (displayW - 4) and mouseY == 1 then
- if currentTurbine < table.getn(turbines) then
- currentTurbine = currentTurbine + 1
- turbine = peripheral.wrap(turbines[currentTurbine])
- end
- end
- if setting then
- if mouseX > 20 and mouseX < 24 and mouseY == 9 then
- turbinesManagement[currentTurbine] = true
- elseif mouseX > 24 and mouseX < 28 and mouseY == 9 then
- turbinesManagement[currentTurbine] = false
- end
- end
- end
- sleep(0.5)
- end
- function mainMenu()
- terminalOutput()
- initPeripherals()
- turbine1 = peripheral.wrap(turbines[1])
- turbine2 = peripheral.wrap(turbines[2])
- reactor1 = peripheral.wrap(reactors[1])
- if monitorFound == true then
- monitor.setTextScale(1)
- end
- while true do
- if monitorFound == true then
- displayW,displayH=monitor.getSize()
- if displayH == 26 and displayW == 39 then
- if control == true then
- drawControlScreen()
- -- if setting == true then
- -- drawSettingScreen()
- -- else
- -- drawDisplayScreen()
- -- end
- else
- drawMainScreen()
- end
- management()
- else
- print("This program is built for a 4x4 monitor only!")
- return
- end
- else
- management()
- end
- sleep(0.5)
- end
- end
- function events()
- while true do
- event,p1,p2,p3 = os.pullEvent()
- if event=="monitor_touch" then
- mouseX = p2 -- sets mouseX
- mouseY = p3 -- and mouseY
- checkClickPosition() -- this runs our function
- elseif event=="peripheral" then
- terminalOutput()
- initPeripherals()
- elseif event=="peripheral_detach" then
- terminalOutput()
- initPeripherals()
- end
- end
- end
- parallel.waitForAny(mainMenu,events)
Advertisement
Add Comment
Please, Sign In to add comment