function sortByEnergy(x, y)
return x.energy > y.energy
end
function check (level, heat)
reactor.setAllControlRodLevels(level)
while (reactor.getFuelTemperature() < heat) do
energy()
if (percentage<5) then
rs.setOutput("left", true)
sleep(1)
rs.setOutput("left",false)
elseif(percentage>99) then
heat=0
else
sleep(1)
end
end
print (reactor.getFuelTemperature())
reactor.setAllControlRodLevels(100)
end
function percentageColor(percent)
monitor.setBackgroundColor(colors.green)
if (percent<50) then
monitor.setBackgroundColor(colors.orange)
if (percent<25) then
monitor.setBackgroundColor(colors.red)
end
end
end
function spaceadder(oldString,desiredLength)
lengthToAdd = desiredLength-string.len(oldString)
return oldString..string.rep(" ",lengthToAdd)
end
function spaceadderBefore(oldString,desiredLength)
lengthToAdd = desiredLength-string.len(oldString)
return string.rep(" ",lengthToAdd)..oldString
end
function monitorlinemaker(outstringpart2,outstringpart3)
return spaceadderBefore(outstringpart2,3).."%"..spaceadderBefore(outstringpart3,32)
end
function shift(value)
for var = 0,numberOfCells-2,1 do
oldPower[var] = oldPower[var+1]
end
oldPower[numberOfCells-1] = value
end
function energy ()
totalEnergy = 0
for var = 1, tablesize, 1 do
Table[var].energy = Table[var].getEnergyStored("RF")
Table[var].percentage = math.floor(Table[var].energy/energyPerCell*100+0,5)
totalEnergy = totalEnergy + Table[var].energy
sleep(0,05)
end
table.sort(Table, sortByEnergy)
for var = 1, tablesize, 1 do
write(var)
end
updateTotal()
end
function write(var)
monitorPos = var
outstringpart1 = tostring(monitorPos)
outstringpart2 = tostring(Table[var].percentage)
outstringpart3 = tostring(Table[var].energy)
outstring = monitorlinemaker(outstringpart2,outstringpart3)
monitor.setCursorPos(1,monitorPos)
percentageColor(Table[var].percentage)
monitor.write(outstring)
end
function updateTotal()
percentage = totalEnergy*100/numberOfCells/energyPerCell
outstringpart1="ALL"
outstringpart2=math.floor(percentage+0,5)
outstringpart3=tostring(totalEnergy)
outstring = monitorlinemaker(outstringpart2,outstringpart3)
monitor.setCursorPos(1,51)
percentageColor(percentage)
monitor.write(outstring)
print(outstringpart3)
monitor.setBackgroundColor(colors.black)
end
function makeTable()
periList = peripheral.getNames()
numberOfCells=0
for i = 1, #periList do
if ((peripheral.getType(periList[i]) == "cofh_thermalexpansion_energycell")) then
numberOfCells = numberOfCells+1
Table[numberOfCells] = peripheral.wrap(periList[i])
end
end
tablesize = #Table
energyPerCell = Table[1].getMaxEnergyStored("RF")
print(numberOfCells.." cells detected")
sleep(0.05)
end
function reactorLineMaker(bool)
if bool then
status ="ON "
else
status ="OFF"
end
return ("Reactor :"..string.rep(" ",24)..status)
end
function monitorReactorOff()
monitor.setCursorPos(1 ,52)
monitor.setBackgroundColor(colors.black)
reactorOutString = reactorLineMaker(false)
monitor.write(reactorOutString)
end
function monitorReactorOn()
monitor.setCursorPos(1,52)
monitor.setBackgroundColor(colors.magenta)
reactorOutString = reactorLineMaker(true)
monitor.write(reactorOutString)
end
function startReactor()
monitorReactorOn()
check(0,1000)
monitorReactorOff()
end
rs.setOutput("left", true)
monitor = peripheral.wrap("monitor_0")
monitor.setTextScale(0.5)
Table = {}
numberOfCells = 0
makeTable()
reactor = peripheral.wrap('back')
reactor.setAllControlRodLevels(100)
monitorReactorOff()
t=0
rs.setOutput("left",false)
while true do
energy()
if(percentage < 25) then
startReactor()
end
sleep(1)
end