Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitors = {peripheral.find("monitor")}
- local mon = monitors[1]
- local reactors = {peripheral.find("BigReactors-Reactor")}
- local refresh = true
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setTextScale(1)
- mon.clear()
- local currentRfTotal = 1
- local currentRfTick = 1
- local currentFuelConsumedLastTick = 0.00001
- local rfPerTickMax = 1
- local minPowerRod = 60
- local maxPowerRod = 80
- local currentRodLevel = 1
- function synDraw()
- term.redirect(mon)
- paintutils.drawBox(2, 2, 60, 18, colors.lightGray)
- paintutils.drawLine(3, 10, 59, 10, colors.lightGray)
- paintutils.drawLine(30, 3, 30, 17, colors.lightGray)
- paintutils.drawPixel(1, 1, colors.black)
- mon.setCursorPos(10, 2)
- mon.write(" Reactor 1: ")
- mon.setCursorPos(10, 10)
- mon.write(" Reactor 2: ")
- mon.setCursorPos(39, 2)
- mon.write(" Reactor 3: ")
- mon.setCursorPos(38, 10)
- mon.write(" All Reactors: ")
- refreshSingleReactor()
- end
- -- Power up the reactor
- function powerUp(m,n,reactorNum)
- local reactor = reactors[reactorNum]
- reactor.setActive(true)
- end
- -- Power down the reactor
- function powerDown(m,n,reactorNum)
- local reactor = reactors[reactorNum]
- reactor.setActive(false)
- end
- -- Calculate and adjusts the level of the rods
- function adjustRodsLevel(reactorNum)
- local reactor = reactors[reactorNum]
- local rfTotalMax = 10000000
- local currentRfTotal = reactor.getEnergyStored()
- differenceMinMax = maxPowerRod - minPowerRod
- maxPower = (rfTotalMax/100) * maxPowerRod
- minPower = (rfTotalMax/100) * minPowerRod
- if currentRfTotal >= maxPower then
- currentRfTotal = maxPower
- end
- if currentRfTotal <= minPower then
- currentRfTotal = minPower
- end
- currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod
- local rfInBetween = (rfTotalMax/100) * differenceMinMax
- local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100)
- reactor.setAllControlRodLevels(rodLevel)
- end
- -- Makes and Handles the Draw Function
- function refreshSingleReactor()
- local rfPerTick = 0
- local rfTotal = 0
- local rfTotalMax = 10000000
- local rfPerTickTotal = 0
- local reactorsTotal = 3
- repeat
- local reactor = reactors[reactorsTotal]
- local reactorTick = reactor
- rfTotal = reactor.getEnergyStored()
- rfPerTick = math.floor(reactor.getEnergyProducedLastTick())
- rodLevel = math.floor(reactor.getControlRodLevel(0))
- fuelPerTick = reactor.getFuelConsumedLastTick();
- if reactorsTotal == 1 then
- startX = 5
- startY = 4
- elseif reactorsTotal == 2 then
- startX = 5
- startY = 12
- elseif reactorsTotal == 3 then
- startX = 33
- startY = 4
- end
- rfPerTickTotal = math.floor(reactorTick.getEnergyProducedLastTick())
- currentRfTick = rfPerTick
- rfPerTickMax = rfPerTick
- rfPerTick = tonumber(rfPerTick)
- mon.setCursorPos(startX,startY)
- mon.write("RF/TICK: "..comma_value(rfPerTick).." RF ")
- currentRfTotal = rfTotal
- rfTotal = tonumber(rfTotal)
- mon.setCursorPos(startX,startY+1)
- mon.write("RF STORED: "..comma_value(rfTotal).." RF ")
- currentRodLevel = rodLevel
- mon.setCursorPos(startX,startY+2)
- mon.write("CONTROL ROD LEVEL: "..rodLevel.. "% ")
- currentFuelConsumedLastTick = fuelPerTick
- mon.setCursorPos(startX,startY+3)
- mon.write("FUEL USAGE: "..format_num(tonumber(fuelPerTick)).." mb/t ")
- adjustRodsLevel(reactorsTotal)
- if reactorsTotal == 1 then
- rfTick1 = rfPerTickTotal
- rfStored1 = rfTotal
- fuelTick1 = fuelPerTick
- elseif reactorsTotal == 2 then
- rfTick2 = rfPerTickTotal
- rfStored2 = rfTotal
- fuelTick2 = fuelPerTick
- elseif reactorsTotal == 3 then
- rfTick3 = rfPerTickTotal
- rfStored3 = rfTotal
- fuelTick3 = fuelPerTick
- end
- sleep(0.01)
- reactorsTotal = reactorsTotal - 1
- until reactorsTotal == 0
- rfPerTickTotalAll = rfTick1 + rfTick2 + rfTick3
- totalRFStoredAll = rfStored1 + rfStored2 + rfStored3
- totalFuelUsageAll = fuelTick1 + fuelTick2 + fuelTick3
- mon.setCursorPos(33,13)
- mon.write("RF PER TICK: "..comma_value(rfPerTickTotalAll).." RF ")
- mon.setCursorPos(33,14)
- mon.write("RF STORED: "..comma_value(totalRFStoredAll).." RF ")
- mon.setCursorPos(33,15)
- mon.write("FUEL USAGE: "..comma_value(totalFuelUsageAll).." mb/t ")
- end
- --Add Commas and Round Decimals
- function comma_value(amount)
- local formatted = amount
- while true do
- formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
- if (k==0) then
- break
- end
- end
- return formatted
- end
- 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 format_num(amount, decimal, prefix, neg_prefix)
- local str_amount, formatted, famount, remain
- decimal = decimal or 2
- neg_prefix = neg_prefix or "-"
- famount = math.abs(round(amount,decimal))
- famount = math.floor(famount)
- remain = round(math.abs(amount) - famount, decimal)
- formatted = comma_value(famount)
- if (decimal > 0) then
- remain = string.sub(tostring(remain),3)
- formatted = formatted .. "." .. remain ..
- string.rep("0", decimal - string.len(remain))
- end
- formatted = (prefix or "") .. formatted
- if (amount<0) then
- if (neg_prefix=="()") then
- formatted = "("..formatted ..")"
- else
- formatted = neg_prefix .. formatted
- end
- end
- return formatted
- end
- -- Starts the Loop
- refresh = true
- while refresh do
- synDraw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement