SHOW:
|
|
- or go back to the newest paste.
| 1 | local rodLevels = 0 | |
| 2 | reactor = peripheral.wrap("back")
| |
| 3 | local numRods = reactor.getNumberOfControlRods() | |
| 4 | - | function setLevels () |
| 4 | + | barGraph = peripheral.wrap("top")
|
| 5 | - | if unexpected_condition then error() end |
| 5 | + | x,y = barGraph.getSize() |
| 6 | - | rodLevels = math.min( math.floor( ( reactor.getEnergyStored() / 10000000 ) * 80 ) + 40 , 100 ) |
| 6 | + | |
| 7 | - | if reactor.getEnergyStored() > 8000000 then |
| 7 | + | function drawGraph() |
| 8 | - | rodLevels = 100 |
| 8 | + | while true do |
| 9 | while not fs.exists("graph.dat") do
| |
| 10 | - | if reactor.getEnergyStored() < 1000000 then |
| 10 | + | sleep(.05) |
| 11 | - | rodLevels = 0 |
| 11 | + | end |
| 12 | dataFile = fs.open("graph.dat", "r")
| |
| 13 | - | if reactor.getEnergyStored() == 10000000 then |
| 13 | + | percentValue = tonumber(dataFile.readLine()) |
| 14 | dataFile.close() | |
| 15 | print("drawGraph:"..percentValue)
| |
| 16 | barGraph.clear() | |
| 17 | for j = y,1,-1 do | |
| 18 | barGraph.setCursorPos(1,j) | |
| 19 | if ( y-j ) * ( y/100 ) <= percentValue then | |
| 20 | barGraph.setBackgroundColour(colors.green) | |
| 21 | - | pcall(setLevels) |
| 21 | + | else |
| 22 | barGraph.setBackgroundColour(colors.black) | |
| 23 | - | reactor.setAllControlRodLevels(rodLevels) |
| 23 | + | end |
| 24 | barGraph.write(string.rep(" ",x))
| |
| 25 | end | |
| 26 | sleep(2) | |
| 27 | end | |
| 28 | end | |
| 29 | ||
| 30 | ||
| 31 | --backgroundGraphing = coroutine.create(drawGraph) | |
| 32 | --coroutine.resume(backgroundGraphing) | |
| 33 | local storageArray = {}
| |
| 34 | for i = 0,19 do | |
| 35 | storageArray[i] = peripheral.wrap("cofh_thermalexpansion_energycell_"..i)
| |
| 36 | end | |
| 37 | ||
| 38 | function setRods() | |
| 39 | for i = 0, numRods - 1 do | |
| 40 | reactor.setControlRodLevel(i,math.max( math.min( rodLevels - ( 100 * i ), 100 ) , 0 ) ) | |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | powerUsed = 0 | |
| 45 | function getEnergyPercent() | |
| 46 | storageMax = 0 | |
| 47 | storageTotal = 0 | |
| 48 | for i,storageCell in pairs(storageArray) do | |
| 49 | storageTotal = storageTotal + storageCell.getEnergyStored("top")
| |
| 50 | storageMax = storageMax + storageCell.getMaxEnergyStored("top")
| |
| 51 | end | |
| 52 | fs.delete("graph.dat")
| |
| 53 | dataFile = fs.open("graph.dat","w")
| |
| 54 | dataFile.write(tostring(storageTotal / storageMax * 100)) | |
| 55 | dataFile.close() | |
| 56 | print("Power Stored:"..tostring(storageTotal / storageMax * 100))
| |
| 57 | return storageTotal / storageMax * 100 | |
| 58 | end | |
| 59 | function getEnergy() | |
| 60 | storageTotal = 0 | |
| 61 | for i,storageCell in pairs(storageArray) do | |
| 62 | storageTotal = storageTotal + storageCell.getEnergyStored("top")
| |
| 63 | end | |
| 64 | return storageTotal | |
| 65 | end | |
| 66 | ||
| 67 | print("Starting reactor and collecting baselines")
| |
| 68 | reactor.setActive(true) | |
| 69 | rodLevels = 0 | |
| 70 | setRods() | |
| 71 | local maxOutput = 0 | |
| 72 | while true do | |
| 73 | if maxOutput + maxOutput / 20 < reactor.getEnergyProducedLastTick() then | |
| 74 | maxOutput = reactor.getEnergyProducedLastTick() | |
| 75 | else | |
| 76 | break | |
| 77 | end | |
| 78 | sleep(1) | |
| 79 | end | |
| 80 | rodLevels = 100 * numRods | |
| 81 | setRods() | |
| 82 | print("Max Output:"..maxOutput)
| |
| 83 | while true do | |
| 84 | lastPower = getEnergy() | |
| 85 | sleep(1) | |
| 86 | print("Power Delta:"..getEnergy() - lastPower)
| |
| 87 | print("Power Generated:"..reactor.getEnergyProducedLastTick())
| |
| 88 | powerUsed = math.abs( math.min( ( getEnergy() - lastPower ) - reactor.getEnergyProducedLastTick() ) , 0 ) | |
| 89 | rodLevels = math.floor( ( 100 - ( ( powerUsed / maxOutput ) * 100 ) ) * numRods ) | |
| 90 | if getEnergyPercent() > 40 then | |
| 91 | rodLevels = numRods * 100 | |
| 92 | end | |
| 93 | if reactor.getEnergyStored() > 9000000 then | |
| 94 | reactor.setActive(false) | |
| 95 | else | |
| 96 | reactor.setActive(true) | |
| 97 | end | |
| 98 | print("Rod Levels: "..rodLevels)
| |
| 99 | print("Power Generated:"..reactor.getEnergyProducedLastTick())
| |
| 100 | print("Power Used:"..powerUsed)
| |
| 101 | setRods() | |
| 102 | --coroutine.resume(backgroundGraphing) | |
| 103 | sleep(1) | |
| 104 | end |