Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = peripheral.wrap("BigReactors-Reactor_0")
- turbine = {peripheral.wrap("BigReactors-Turbine_0"), peripheral.wrap("BigReactors-Turbine_1")}
- mon = peripheral.wrap("left")
- -- STATIC VARS
- maxEnergy = 9000000
- minEnergy = 1000000
- minRotorSpeed = 1820
- maxRotorSpeed = 1860
- -- VARIABLE VARS
- energyStoredLastCycle = 0
- avgBlockSize = 1
- avgConsumption = 0
- numberOfContrlRods = 0
- ------------------------------------------------
- --FUNCTIONS-------------------------------------
- ------------------------------------------------
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function resetTerm()
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function resetMon()
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- end
- function nextLine()
- x,y = mon.getCursorPos()
- y = y + 1
- mon.setCursorPos(1,y)
- end
- function initAverages()
- local f = fs.open("reactor_averages", "r")
- avgConsumption = tonumber(f.readLine())
- avgBlockSize = tonumber(f.readLine())
- f.close()
- end
- function saveAveragesToFile(consumption, size)
- local f = fs.open("reactor_averages", "w")
- f.writeLine(consumption)
- f.writeLine(size)
- f.close()
- end
- ------------------------------------------------
- --OUTSIDE LOOP----------------------------------
- ------------------------------------------------
- initAverages()
- numberOfContrlRods = reactor.getNumberOfControlRods()
- ------------------------------------------------
- --LOOP------------------------------------------
- ------------------------------------------------
- while true do
- resetTerm()
- resetMon()
- enabledStatus = reactor.getActive()
- mon.write("Status: ")
- statusColor = enabledStatus and colors.green or colors.red
- mon.setTextColor(statusColor)
- mon.write(enabledStatus and "Online" or "Offline")
- mon.setTextColor(colors.white)
- nextLine()
- -- energy = reactor.getEnergyStored()
- -- print("Energy: " .. energy)
- -- mon.write("Energy: ")
- -- if energy < 1500000 then
- -- mon.setTextColor(colors.red)
- -- elseif energy > 1500000 and energy < 6500000 then
- -- mon.setTextColor(colors.yellow)
- -- elseif energy > 6500000 then
- -- mon.setTextColor(colors.green)
- -- end
- -- mon.write(energy .. " RF")
- -- mon.setTextColor(colors.white)
- -- nextLine()
- -- rfChangePerTick = (energy - energyStoredLastCycle) / 20
- -- mon.write("RF Change: ")
- -- if rfChangePerTick < 0 then
- -- mon.setTextColor(colors.red)
- -- else
- -- mon.setTextColor(colors.green)
- -- rfChangePerTick = "+" .. rfChangePerTick
- -- end
- -- mon.write(rfChangePerTick .. " RF/t")
- -- mon.setTextColor(colors.white)
- -- nextLine()
- -- energyStoredLastCycle = energy
- fuelConsumedPerTick = reactor.getFuelConsumedLastTick()
- fuelConsumedPerSecond = round(fuelConsumedPerTick * 20,2)
- print("Fuel consumption (/s): " .. fuelConsumedPerSecond .. " mb")
- mon.write("Fuel Consumption: " .. fuelConsumedPerSecond .. " mb/s")
- nextLine()
- ingotsConsumedPerSecond = fuelConsumedPerSecond / 1000
- --print("Uranium consumption (/s): " .. ingotsConsumedPerSecond .. " ingots")
- ingotConsumptionPerHour = round(ingotsConsumedPerSecond * 60 * 60,2)
- print("Uranium consumption (/h): " .. ingotConsumptionPerHour .. " ingots")
- mon.write("Uranium Consumption: " .. ingotConsumptionPerHour .. " /h")
- nextLine()
- avgConsumption = avgConsumption + (ingotConsumptionPerHour - avgConsumption) / avgBlockSize
- avgBlockSize = avgBlockSize + 1
- saveAveragesToFile(avgConsumption, avgBlockSize)
- mon.write("Average Uranium Consumption: " .. round(avgConsumption, 3) .. " /h")
- nextLine()
- nextLine()
- -- if energy > maxEnergy and enabledStatus then
- -- print("Disabling reactor..")
- -- reactor.setActive(false)
- -- elseif energy < minEnergy and not enabledStatus then
- -- print("Enabling reactor..")
- -- reactor.setActive(true)
- -- end
- local turb_EnergyStored = turbine[1].getEnergyStored() + turbine[2].getEnergyStored()
- local turb_RotorSpeed = {turbine[1].getRotorSpeed(), turbine[2].getRotorSpeed()}
- local turb_EnergyProduced = {turbine[1].getEnergyProducedLastTick(), turbine[2].getEnergyProducedLastTick()}
- local turb_EnergyProducedTotal = 0
- for i = 1, 2 do
- if turb_RotorSpeed[i] < minRotorSpeed then
- turbine[i].setInductorEngaged(false)
- elseif turb_RotorSpeed[i] > maxRotorSpeed then
- turbine[i].setInductorEngaged(true)
- end
- mon.write("Energy Produced (Turbine " .. i .. "): " .. turb_EnergyProduced[i] .. " RF/t")
- nextLine()
- turb_EnergyProducedTotal = turb_EnergyProducedTotal + turb_EnergyProduced[i]
- end
- mon.write("Energy Produced (Total): " .. turb_EnergyProducedTotal .. " RF/t")
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement