Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon.clear()
- mon.setBackgroundColor(colors.black)
- function program()
- while true do
- --Variables--
- refresh = 1
- mon = peripheral.wrap("monitor_0")
- monX, monY = mon.getSize()
- reactor = peripheral.wrap("BigReactors-Reactor_0")
- turbine = peripheral.wrap("BigReactors-Turbine_0")
- turbEnergy = round(math.floor(turbine.getEnergyStored())/100000,1)
- turbEnergyTick = round(math.floor(turbine.getEnergyProducedLastTick()),1)
- reacCaseTemp = round(math.floor(reactor.getCasingTemperature()),1)
- reacFuelTemp = round(math.floor(reactor.getFuelTemperature()),1)
- mon = peripheral.wrap("monitor_0")
- tank = peripheral.wrap("rcirontankvalvetile_0")
- lever = rs.getInput("right")
- --Energi variabler
- totEnergyLevel = 0
- totStorage = 0
- cells = {
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_2"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_3"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_4"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_5"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_6"),
- peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_7"),
- }
- ----Functions----
- --GUI--
- function drawText(x, y, text, color_txt, color_bg)
- mon.setBackgroundColor(color_bg)
- mon.setTextColor(color_txt)
- mon.setCursorPos(x, y)
- mon.write(text)
- end
- function drawLine(x, y, length, size, color_bar)
- for yPos = y, y+size-1 do
- mon.setBackgroundColor(color_bar)
- mon.setCursorPos(x, yPos)
- mon.write(string.rep(" ", length))
- end
- end
- function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
- drawLine(x, y, length, size, color_bg)
- local barSize = math.floor((minVal/maxVal)*length)
- drawLine(x, y, barSize, size, color_bar)
- local text = name.." "..math.floor((minVal/maxVal)*100).."%"
- if barSize > monX/2+#text/2 then
- drawText(monX/2-#text/2+1, y+size/2, text, colors.white, color_bar)
- elseif barSize > #text then
- drawText((x+barSize)-#text, y+size/2, text, colors.white, color_bar)
- else
- drawText(monX/2-#text/2+1, y+size/2, text, colors.white, color_bg)
- end
- end
- function refreshMon()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function refreshTerm()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- --Layout functions--
- function round(val, decimal)
- if (decimal) then
- return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
- else
- return math.floor(val+0.5)
- end
- end
- function writeStats(x, y, text, var)
- mon.setCursorPos(x, y)
- mon.setTextColor(colors.white)
- mon.write(text)
- mon.setTextColor(colors.lime)
- mon.write(var)
- end
- --Energi--
- function getEnergyStatus(t)
- for i,v in ipairs(t) do
- totStorage = totStorage + v.getMaxEnergyStored()
- end
- for i,v in ipairs(t) do
- totEnergyLevel = totEnergyLevel + v.getEnergyStored()
- end
- totPercent = (100*totEnergyLevel/totStorage)
- return totPercent, totEnergyLevel, totStorage
- end
- --Reactor+Turbine--
- function setActive(state)
- turbine.setActive(state)
- reactor.setActive(state)
- end
- --Vattentank--
- function updateTank(tankPeriph)
- local tableInfo = tankPeriph.getTankInfo("unknown") -- Local to the getTank function.
- fluidRaw = nil --for clarity
- fluidName = nil --for clarity
- fluidAmount = nil --for clarity
- fluidCapacity = tableInfo[1].capacity
- local contents = tableInfo[1].contents
- if contents then
- fluidRaw = contents.rawName
- fluidAmount = contents.amount
- fluidName = contents.name
- end
- cap = fluidCapacity / 1000
- amount = fluidAmount
- tankPercentFull = 0
- if amount == nil then
- amount = 0
- tankPercentFull = 0
- else
- -- Use math.floor to convert to integers
- amount = math.floor(amount / 1000)
- tankPercentFull = math.floor(100 * amount / cap)
- end
- return tankPercentFull
- end
- ----------Main Program----------
- updateTank(tank)
- local energyLevel = getEnergyStatus(cells)
- refreshMon()
- refreshTerm()
- print("Program is running")
- print("Press backspace to exit")
- -----Water Refill-----
- if lever == true then
- setActive(true)
- else
- setActive(false)
- end
- if tankPercentFull == 5 then
- --if lever == true then
- setActive(false)
- repeat
- drawText(10, 1, "Refilling water tank...", colors.green, colors.black)
- drawText(140, 2, "Reactor is ", colors.green, colors.black)
- mon.setTextColor(colors.red)
- mon.write("off")
- mon.setTextColor(colors.green)
- updateTank(tank)
- drawProg(2, 6, "Water level", monX-2, 3, tankPercentFull, 100, colors.blue, colors.gray)
- sleep(1)
- until (tankPercentFull > 2)
- refreshMon()
- end
- --Auto active reactor--
- if energyLevel < 10 then
- setActive(true)
- elseif energyLevel > 92 then
- setActive(false)
- end
- -----UI-----
- writeStats(1, 1, "Reac Active: ", reactor.getActive())
- writeStats(21,1, "Turb Active: ", turbine.getActive())
- writeStats(1, 2, "RF/T: ", turbEnergyTick)
- writeStats(21,2, "Turb Energy: ", turbEnergy)
- writeStats(1, 3, "Casing Heat: ", reacCaseTemp)
- writeStats(21, 3,"Fuel Heat: ", reacFuelTemp)
- --debug--
- --for i = 1, 100 do
- -- drawProg(2, 4, "Test level", monX-2, 3, i, 100, colors.red, colors.gray)
- -- sleep(0.1)
- --end
- ---------
- --Energy bar--
- drawProg(2, 5, "Energy level", monX-2, 3, energyLevel, 100, colors.red, colors.gray)
- --Watertank bar--
- drawProg(2, 9, "Water level", monX-2, 3, tankPercentFull, 100, colors.blue, colors.gray)
- ------------Endstuff---------------
- sleep(refresh)
- end
- end
- function exitProgram()
- repeat
- local ev, key = os.pullEvent('key')
- --shutdown with backspace--
- until key == keys.backspace
- end
- parallel.waitForAny(program, exitProgram)
- --The last words...--
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextColor(colors.gray)
- mon.setCursorPos((monX/2)-9, monY/2)
- mon.write("Program is offline...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement