Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diagCode = 0
- --PERIPHERALS
- if diagCode == 1 then print("loading peripherals...") end
- local modem = peripheral.wrap("back")
- local stats = peripheral.wrap("right")
- local lights = peripheral.wrap("top")
- local cap = peripheral.wrap("tile_blockcapacitorbank_name_0")
- local reactor = peripheral.wrap("BigReactors-Reactor_2")
- if diagCode == 1 then print("done") end
- --VARIABLES
- if diagCode == 1 then print("loading varibales") end
- --USER DEFINED
- numOfCaps = 10
- fuelCutoffLimit = 2000
- capUpperLimit = .9
- capLowerLimit = .75
- includeReactor = true
- if diagCode == 1 then print("done") end
- --UTILITIES
- if diagCode == 1 then print("loading utilities") end
- function refresh()
- if diagCode == 2 then print("refreshing") end
- connected = false
- activeBool = reactor.getActive()
- fuelInNuke = reactor.getFuelAmount()
- wasteInNuke = reactor.getWasteAmount()
- oldEnergyInCap = cap.getEnergyStored()*numOfCaps
- sleep(.05)
- energyInCap = cap.getEnergyStored()*numOfCaps
- netEnergyCap = energyInCap-oldEnergyInCap
- oldEnergyInNuke = reactor.getEnergyStored()
- sleep(.05)
- energyInNuke = reactor.getEnergyStored()
- netEnergyNuke = energyInNuke-oldEnergyInNuke
- fuelTemp = reactor.getFuelTemperature()
- casingTemp = reactor.getCasingTemperature()
- fuelConsumed = reactor.getFuelConsumedLastTick()
- powerProduced = reactor.getEnergyProducedLastTick()
- end
- function colorWrite(colorVar, text, x, y)
- if x ~= nil then
- stats.setCursorPos(x,y)
- stats.clearLine()
- end
- stats.setTextColor(colorVar)
- stats.write(tostring(text))
- end
- function writeLine(x,y,label,content,colorVar)
- colorWrite(colors.white, label..": ", x, y)
- colorWrite(colorVar, content)
- end
- function percent(part,whole)
- local per = part/whole*100
- local colorVar
- if per < 20 then
- colorVar = colors.red
- elseif per < 40 then
- colorVar = colors.orange
- elseif per < 60 then
- colorVar = colors.yellow
- elseif per < 80 then
- colorVar = colors.lime
- elseif per < 100 then
- colorVar = colors.green
- elseif per == 100 then
- colorVar = colors.cyan
- end
- return colorVar
- end
- function displayPer(x,y,label,cont,max,append,invert)
- if invert then
- colorVar = percent(max-cont,max)
- else
- colorVar = percent(cont, max)
- end
- writeLine(x,y,label, math.floor(cont), colorVar)
- stats.setTextColor(colors.cyan)
- stats.write(" "..append.." ("..tostring(math.floor(cont/max*100)).."%)")
- end
- if diagCode == 1 then print("done") end
- --Statistics
- if diagCode == 1 then print("loading statistics") end
- function active(x,y)
- if diagCode == 3 then print("running active: "..tostring(activeBool)) end
- if activeBool then
- colorVar = colors.green
- else
- colorVar = colors.red
- end
- writeLine(x,y,"Active", tostring(activeBool) ,colorVar)
- end
- function nukeEnergy(x,y)
- if diagCode == 3 then print("running nukeEnergy: "..tostring(energyInNuke)) end
- displayPer(x,y,"RF in Reactor", energyInNuke, 10000000, "RF")
- end
- function capEnergy(x,y)
- if diagCode == 3 then print("running capEnergy: "..tostring(energyInCap)) end
- displayPer(x,y,"RF in Capacitor", energyInCap, maxCapEnergy, "RF")
- end
- function fuelTemperature(x,y)
- if diagCode == 3 then print("running fuelTemperature: "..tostring(fuelTemp)) end
- displayPer(x,y,"Fuel Temp", fuelTemp, 2000, "C", true)
- end
- function caseTemperature(x,y)
- if diagCode == 3 then print("running caseTemperature: "..tostring(caseTemp)) end
- displayPer(x,y,"Casing Temp", casingTemp, 2000,"C", true)
- end
- function fuelWaste(x,y)
- if diagCode == 3 then print("running fuelWaste: "..tostring(fuelInNuke)..","..tostring(wasteInNuke)) end
- writeLine(x,y,"Fuel",fuelInNuke,colors.yellow)
- colorWrite(colors.cyan, " mB")
- colorWrite(colors.white, " Waste: ")
- colorWrite(colors.blue, wasteInNuke)
- colorWrite(colors.cyan, " mB")
- end
- function efficiency(x,y)
- if diagCode == 3 then print("running efficiency: "..tostring(math.floor(powerProduced/fuelConsumed))) end
- colorWrite(colors.white, "Efficiency: ",x,y)
- colorWrite(colors.cyan, tostring(math.floor(powerProduced/fuelConsumed)).." RF/mB")
- end
- function powerProducedLast(x,y)
- if diagCode == 3 then print("running powerProducedLast: "..tostring(powerProduced)) end
- colorWrite(colors.white, "Power production: ",x,y)
- colorWrite(colors.cyan, string.format("%.5d",powerProduced).." RF/Tick")
- end
- function netPower(x,y)
- if diagCode == 3 then print("running netPower"..tostring(netEnergyCap+netEnergyNuke)) end
- colorWrite(colors.white, "Net energy change: ",x,y)
- colorWrite(colors.cyan, string.format("%.5d",netEnergyCap+netEnergyNuke).." RF/Tick")
- end
- if diagCode == 1 then print("done") end
- --MAIN LOOP
- if diagCode == 1 then print("loading final functions") end
- --The monitor is 36 across
- function draw()
- stats.clear()
- if diagCode == 2 then print("drawing") end
- active(1,1)
- nukeEnergy(1,2)
- capEnergy(1,3)
- fuelTemperature(1,4)
- caseTemperature(1,5)
- fuelWaste(1,6)
- efficiency(1,7)
- powerProducedLast(1,8)
- netPower(1,9)
- end
- function check()
- mx = maxCapEnergy
- e = energyInCap
- ul = capUpperLimit
- ll = capLowerLimit
- if diagCode == 2 then print("checking") end
- if includeReactor then
- mx = mx+10000000
- e = e+energyInNuke
- end
- if e/mx > ul then
- reactor.setActive(false)
- elseif e/mx < ll and fuelInNuke > fuelCutoffLimit then
- reactor.setActive(true)
- end
- if fuelInNuke < fuelCutoffLimit then
- reactor.setActive(false)
- end
- end
- stats.setTextScale(0.5)
- --ONLY DEFINED ONCE
- connected = false
- maxFuel = reactor.getFuelAmountMax()
- maxCapEnergy = cap.getMaxEnergyStored()*numOfCaps
- maxNukeEnergy = 10000000
- if diagCode == 1 then print("done") end
- if diagCode == 1 then print("entering main loop") end
- while true do
- if diagCode == 2 then print("iterating") end
- refresh()
- draw()
- check()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement