Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bank = peripheral.wrap("back")
- local reac = peripheral.wrap("BigReactors-Reactor_0")
- local minEnergyStoragePercent = 50
- local maxEnergyStoragePercent = 90
- local stepSize = 2
- local brakeTime = 5
- local action = "none"
- local defaultColor = colors.white
- local monitors = {
- peripheral.wrap("top");
- peripheral.wrap("monitor_1");
- peripheral.wrap("monitor_2");
- }
- --TODO low fuel warning
- --clears all monitors
- function clear()
- for i=1, #monitors do
- monitors[i].clear()
- monitors[i].setTextColor(defaultColor)
- monitors[i].setCursorPos(1,1)
- end
- end
- --goes to the next line for all monitors
- function nextline()
- for i=1, #monitors do
- local x,y = monitors[i].getCursorPos()
- local y = y + 1
- monitors[i].setTextColor(defaultColor)
- monitors[i].setCursorPos(1,y)
- end
- end
- --writes text on all monitors
- function writeText(text)
- for i=1, #monitors do
- monitors[i].write(text)
- end
- end
- --sets text color for all monitors
- function textColor(color)
- for i=1, #monitors do
- monitors[i].setTextColor(color)
- end
- end
- --prints the statistics of the capacitor bank
- function printCapacitorStats()
- --get the Percentage how full the capacitor is
- local filledPercent = bank.getEnergyStored()/bank.getMaxEnergyStored()*100
- filledPercent = math.floor(filledPercent*10)/10
- writeText("Capacitor Status: ")
- --if filled less then minimum, set color to red
- if filledPercent < minEnergyStoragePercent then
- --sets color to red
- textColor(colors.orange)
- elseif filledPercent > minEnergyStoragePercent then
- --filled at least to minimum percent
- if filledPercent < maxEnergyStoragePercent then
- --filled within limits, set color to green
- textColor(colors.green)
- else
- --filled to much, set color to orange
- textColor(colors.purple)
- end
- end
- writeText(filledPercent)
- textColor(defaultColor)
- writeText(" %")
- nextline()
- end
- function printReactorOnlineStats()
- writeText("Reactor Status: ")
- if reac.getConnected() then
- --reactor valid and connected
- if reac.getActive() then
- --reactor online
- textColor(colors.green)
- writeText("online")
- else
- --reactor offline
- textColor(colors.orange)
- writeText("offline")
- end
- else
- --reactor unvalid or disconnected
- textColor(colors.blue)
- writeText("invalid")
- end
- textColor(colors.white)
- nextline()
- end
- function printFuelRodStatus()
- writeText("Fuel Rod dampening: "..reac.getControlRodLevel(0).." %")
- nextline()
- end
- function printEnergyOutput()
- local output = math.floor(reac.getEnergyProducedLastTick()*10)/10
- writeText("Reactor Output: ")
- if bank.getAverageOutputPerTick() > output then
- textColor(colors.blue)
- else
- textColor(colors.green)
- end
- writeText(output)
- textColor(defaultColor)
- writeText(" Rf/t")
- nextline()
- end
- function printCurrentAction()
- writeText("Action: "..action)
- nextline()
- end
- function printEfficiencyEstimate()
- eff = reac.getFuelConsumedLastTick()*20*60*60
- eff = math.floor(eff/1000)
- writeText("Efficiency: ~ "..eff.." b/h")
- nextline()
- end
- function printDivider()
- local divider = "+"
- for i=1,27,1 do
- divider = divider .. "-"
- end
- divider = divider .. "+"
- writeText(divider)
- nextline()
- end
- function printEnergyIO()
- local io = bank.getAverageChangePerTick()
- writeText("Current IO: ")
- if io == 0 then
- textColor(colors.blue)
- elseif io < 0 then
- textColor(colors.orange)
- elseif io > 0 then
- textColor(colors.green)
- end
- io = math.floor(io*10)/10
- writeText(io)
- textColor(defaultColor)
- writeText(" RF/t")
- nextline()
- end
- function printEnergyDuration()
- local duration = 0
- if bank.getAverageChangePerTick() < 0 then
- local duration = bank.getMaxEnergyStored() / bank.getAverageChangePerTick()
- duration = math.floor((duration/20/60/60)*10)/10
- writeText("Sustainable for: ~ ")
- textColor(colors.orange)
- duration = duration * (-1)
- writeText(duration)
- textColor(defaultColor)
- writeText(" h")
- else
- textColor(colors.green)
- writeText("Sustainable")
- end
- nextline()
- end
- function control()
- if reac.getActive then
- --reactor is active
- local current = bank.getEnergyStored() / bank.getMaxEnergyStored()*100
- current = math.floor(current*10)/10
- if current < minEnergyStoragePercent then
- --lack of energy, produce
- reac.setAllControlRodLevels(0)
- action = "Increasing output"
- elseif current > (maxEnergyStoragePercent - brakeTime) then
- --starting to get near energy limit, start stopping
- local newRod = reac.getControlRodLevel(0) + stepSize
- if newRod > 100 then
- newRod = 100
- end
- reac.setAllControlRodLevels(newRod)
- action = "Throtteling output"
- elseif current > maxEnergyStoragePercent then
- --energy limit overshoot, shutting down
- reac.setAllControlRodLevels(100)
- action = "Stopping Output"
- end
- else
- --reactor is inactive
- mon.setBackgroundColor(colors.red)
- mon.clear()
- end
- end
- while true do
- clear()
- control()
- printCapacitorStats()
- printReactorOnlineStats()
- printFuelRodStatus()
- printEnergyOutput()
- printEfficiencyEstimate()
- printCurrentAction()
- printDivider()
- printEnergyIO()
- printEnergyDuration()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement