Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactorName = "BigReactors-Reactor_0"
- local monitorName = "monitor_0"
- -- util
- function percentage(value, max)
- return math.ceil(value / max * 10000) * 0.01
- end
- function convertTimeToTick(time)
- return (os.time() * 1000 + 18000) % 24000
- end
- function getDeltaTicks(lastTick)
- local now = os.time()
- now = convertTimeToTick(now)
- if now < lastTick then lastTick = lastTick - 24000 end
- return now - lastTick
- end
- -- formatting
- function format_int(number)
- if number == nil then number = 0 end
- local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
- -- reverse the int-string and append a comma to all blocks of 3 digits
- int = int:reverse():gsub("(%d%d%d)", "%1,")
- -- reverse the int-string back remove an optional comma and put the
- -- optional minus and fractional part back
- return minus .. int:reverse():gsub("^,", "") .. fraction
- end
- -- monitor related
- --display text text on monitor, "mon" peripheral
- function draw_text(mon, x, y, text, text_color, bg_color)
- mon.monitor.setBackgroundColor(bg_color)
- mon.monitor.setTextColor(text_color)
- mon.monitor.setCursorPos(x,y)
- mon.monitor.write(text)
- end
- function draw_text_right(mon, offset, y, text, text_color, bg_color)
- mon.monitor.setBackgroundColor(bg_color)
- mon.monitor.setTextColor(text_color)
- mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
- mon.monitor.write(text)
- end
- function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color)
- draw_text(mon, x, y, text1, text1_color, bg_color)
- draw_text_right(mon, offset, y, text2, text2_color, bg_color)
- end
- --draw line on computer terminal
- function draw_line(mon, x, y, length, color)
- if length < 0 then
- length = 0
- end
- mon.monitor.setBackgroundColor(color)
- mon.monitor.setCursorPos(x,y)
- mon.monitor.write(string.rep(" ", length))
- 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(mon, x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(mon, x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(mon, x, y, barSize, bar_color) --progress so far
- end
- function clear(mon)
- term.clear()
- term.setCursorPos(1,1)
- mon.monitor.setBackgroundColor(colors.black)
- mon.monitor.clear()
- mon.monitor.setCursorPos(1,1)
- end
- -- monitor
- local mon, monitor, monX, monY
- monitor = peripheral.wrap(monitorName)
- monX, monY = monitor.getSize()
- mon = {}
- mon.monitor, mon.X, mon.Y = monitor, monX, monY
- -- reactor
- local reactor = peripheral.wrap(reactorName)
- local maxHeat = 2000
- local maxEnergy = 10000000
- function update()
- local lastTick = convertTimeToTick(os.time())
- local previousEnergy = 0
- while true do
- print("clearing")
- clear(mon)
- print("working")
- if reactor == nil or not reactor.getConnected() then
- draw_text(mon, 1, 1, "No reactor found", colors.red, colors.black)
- return
- end
- -- local castingTemperature = reactor.getCasingTemperature()
- -- local fuelAmount = reactor.getFuelAmount()
- -- local wasteAmount = reactor.getWasteAmount()
- -- local maxFuelAmount = reactor.getFuelAmountMax()
- -- local energyProduced = reactor.getEnergyProducedLastTick()
- -- local fuelConsumed = reactor.getFuelConsumedLastTick()
- -- Reactor status
- local status = "INACTIVE"
- local statusColor = colors.red
- local active = reactor.getActive()
- if active then
- status = "ACTIVE"
- statusColor = colors.lime
- end
- draw_text_lr(mon, 2, 2, 1, "Reactor Status", status, colors.white, statusColor, colors.black)
- -- Power generation
- local energy = reactor.getEnergyStored()
- if energy >= maxEnergy - maxEnergy * 0.001 then
- draw_text_lr(mon, 2, 4, 1, "Delta power", "max", colors.white, colors.green, colors.black)
- elseif energy <= maxEnergy * 0.0001 then
- draw_text_lr(mon, 2, 4, 1, "Delta power", "empty", colors.white, colors.red, colors.black)
- else
- local deltaTicks = getDeltaTicks(lastTick)
- local deltaEnergy = (energy - previousEnergy) / deltaTicks
- local energyColor = colors.red
- if deltaEnergy >= 0 then energyColor = colors.green end
- draw_text_lr(mon, 2, 4, 1, "Delta power", format_int(deltaEnergy) .. " rf/t", colors.white, energyColor, colors.black)
- end
- previousEnergy = energy
- lastTick = convertTimeToTick(os.time())
- -- Reactivity
- local reactivity = reactor.getFuelReactivity()
- draw_text_lr(mon, 2, 6, 1, "Reactivity", reactivity .. "%", colors.white, colors.lightBlue, colors.black)
- -- Fuel to waste ratio
- -- Fuel temperature
- local fuelTemperature = reactor.getFuelTemperature()
- local fuelColor = colors.red
- if fuelTemperature < 1200 then fuelColor = colors.orange end
- if fuelTemperature < 1000 then fuelColor = colors.yellow end
- if fuelTemperature < 750 then fuelColor = colors.lime end
- -- Casing temperature
- sleep(0.1)
- end
- end
- update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement