Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wireless BigReactor Control
- -- by SparkyBearBomb
- -- Original by jaranvil aka jared314
- --
- -- feel free to use and/or modify this code
- --
- -----------------------------------------------
- -- Wireless Reactor Control - Version History
- --
- -- Version 2.0 - 11 Jul 21
- -- Upodated to work with the new transmitted message
- --
- -- Version 1.1 - 26.12.2020
- -- - original program forked from ELJptBRk
- --
- -----------------------------------------------
- --Port Number
- port = 0
- --monitor size
- local monX
- local monY
- term.clear()
- -------------------FORMATTING-------------------------------
- function clear()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- --display text text on monitor, "mon" peripheral
- function draw_text(x, y, text, text_color, bg_color)
- term.setBackgroundColor(bg_color)
- term.setTextColor(text_color)
- term.setCursorPos(x,y)
- term.write(text)
- end
- --draw line on computer terminal
- function draw_line(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- --draw line on computer terminal
- function draw_line_term(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- -- Round Decimal Numbers
- function roundNumber(num, n)
- local mult = 10^(n or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- --create progress bar
- --draws two overlapping lines
- --background line of bg_color
- --main line of bar_color as a percentage of minVal/maxVal
- 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
- --create status bar
- --draws three overlapping lines
- --background line of bg_color
- function status_bar(x, y, length, minVal, medVal, maxVal, bar_color1, bar_color2, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize1 = math.floor((medVal/maxVal) * length)
- local barSize2 = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize1, bar_color1) --progress so far
- draw_line(x, y, barSize2, bar_color2) --progress so far
- end
- --same as above but on the computer terminal
- function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line_term(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line_term(x, y, barSize, bar_color) --progress so far
- end
- --header and footer bars on monitor
- function menu_bar()
- draw_line(0, 1, monX, colors.purple)
- draw_text(1, 1, " Wireless Reactor Receiver", colors.white, colors.purple)
- draw_line(0, 20, monX, colors.purple)
- draw_text(1, 20, " Wireless Reactor Receiver", colors.white, colors.purple)
- end
- ------------------------END FORMATTING--------------------------
- function pharseMessage(message)
- local results = {}
- for pharseData in string.gmatch(message, "[^, ]+") do
- table.insert(results,pharseData)
- end
- active = results[1]
- energyQty = results[2]
- energyMax = results[3]
- energyTick = results[4]
- fuelTemp = results[5]
- caseTemp = results[6]
- fuelQty = results[7]
- wasteQty = results[8]
- fuelMax = results[9]
- fuelTick = results[10]
- rodLevel = results[11]
- isCooled = results[12]
- end
- function rfScale(number)
- if number == nil or number == 0 then
- value = "0 RF/T"
- elseif number < 1000 then
- number = (math.floor(number)/1)
- value = number.." RF/T"
- elseif number < 1000000 then
- number = (math.floor(number)/1000)
- value = number.." KRF/T"
- elseif number < 1000000000 then
- number = (math.floor(number)/1000000)
- value = number.." MF/T"
- else
- number = (math.floor(number)/1000000000)
- value = number.." GF/T"
- end
- return value
- end
- modem = peripheral.wrap("back")
- modem.closeAll()
- modem.open(port)
- monX,monY = term.getSize()
- while true do
- event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- pharseMessage(message)
- clear()
- menu_bar()
- --------POWER STAT--------------
- draw_text(2, 3, "Power:", colors.lightGray, colors.black)
- if active == "true" then
- draw_text(9, 3, " ONLINE ", colors.gray, colors.green)
- draw_text(17, 3, " OFFLINE ", colors.black, colors.gray)
- else
- draw_text(9, 3, " ONLINE ", colors.black, colors.gray)
- draw_text(17, 3, " OFFLINE ", colors.gray, colors.red)
- end
- -----------FUEL---------------------
- draw_text(2, 5, "Fuel Level:", colors.lightGray, colors.black)
- local maxVal = fuelMax
- local waste = wasteQty
- local minVal = fuelQty
- local medVal = waste + minVal
- local percent = math.floor((minVal/maxVal)*100)
- draw_text(15, 5, percent.."%", colors.white, colors.black)
- if percent < 20 then
- status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.red, colors.gray)
- elseif percent < 40 then
- status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.orange, colors.gray)
- elseif percent < 60 then
- status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.yellow, colors.gray)
- elseif percent <= 80 then
- status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.lime, colors.gray)
- elseif percent <= 100 then
- status_bar(2, 6, 24, minVal, medVal, maxVal, colors.blue, colors.green, colors.gray)
- end
- -----------ROD HEAT---------------
- draw_text(2, 8, "Fuel Temp:", colors.lightGray, colors.black)
- local maxVal = 2000
- local minVal = math.floor(fuelTemp)
- if minVal < 500 then
- progress_bar(2, 9, 24, minVal, maxVal, colors.cyan, colors.gray)
- elseif minVal < 1000 then
- progress_bar(2, 9, 24, minVal, maxVal, colors.lime, colors.gray)
- elseif minVal < 1500 then
- progress_bar(2, 9, 24, minVal, maxVal, colors.yellow, colors.gray)
- elseif minVal < 2000 then
- progress_bar(2, 9, 24, minVal, maxVal, colors.orange, colors.gray)
- elseif minVal >= 2000 then
- progress_bar(2, 9, 24, 2000, maxVal, colors.red, colors.gray)
- end
- draw_text(15, 8, math.floor(minVal).." C", colors.white, colors.black)
- -------------FUEL CONSUMPTION-------------------
- draw_text(2, 11, "Fuel/Tick:", colors.lightGray, colors.black)
- fuel_usage = fuelTick
- fuelConsumed = roundNumber(fuel_usage, 5)
- draw_text(13, 11, fuelConsumed.." mB/T", colors.white, colors.black)
- -------------OUTPUT-------------------
- if isCooled == "true" then
- draw_text(2, 12, "mB/tick:", colors.lightGray, colors.black)
- mbt = math.floor(energyTick)
- draw_text(13, 12, mbt.." mB/t", colors.white, colors.black)
- else
- draw_text(2, 12, "RF/Tick:", colors.lightGray, colors.black)
- rft = math.floor(energyTick)
- rft = rfScale(rft)
- draw_text(13, 12, rft, colors.white, colors.black)
- end
- ------------STORAGE------------
- energy_stored_percent = math.floor((energyQty/energyMax)*100)
- if isCooled == "true" then
- draw_text(2, 14, "mB Stored:", colors.lightGray, colors.black)
- else
- draw_text(2, 14, "RF Stored:", colors.lightGray, colors.black)
- end
- draw_text(13, 14, energy_stored_percent.."%", colors.white, colors.black)
- progress_bar(2, 15, 24, energy_stored_percent, 100, colors.green, colors.gray)
- ------------CONTROL RODS------------
- draw_text(2, 17, "Control Rods:", colors.lightGray, colors.black)
- draw_text(16, 17, rodLevel.."%", colors.white, colors.black)
- progress_bar(2, 18, 24, rodLevel, 100, colors.cyan, colors.gray)
- end
Add Comment
Please, Sign In to add comment