----------------- Lejoni Edition ------------------
--- This is a Extreme Reactors control program ---
--- for Minecraft mod ComputerCraft ---
--- ---
--- Original by Direwolf20 from: ---
--- pastebin get R4kXR7RU reactor ---
--- and it also uses the widgets API: ---
--- pastebin get u2By4g18 widgets ---
--- a modified version of button ---
--- ---
--- Edited by Lejoni to adapt it for use with ---
--- Draconic Evolution Energy Storage Core. ---
--- As well as some minor tweaks. ---
--- Edits are commented in code. ---
---------------------------------------------------
local widgets = require("widgets")
--- Lejoni Edit ---
p = peripheral.find("draconic_rf_storage")
-------------------
m = peripheral.find("monitor")
r = peripheral.find("BigReactors-Reactor")
t = peripheral.find("BigReactors-Turbine")
-- Lejonis Edits --
local txtScale = 1
local colum2 = 28
local fname = "ssccrc"
local steamReactor = r.isActivelyCooled()
if steamReactor then
local menuType = "Turbine"
else
local menuType = "Reactor"
end
-------------------
local numCapacitors = 1
local turnOnAt = 50
local turnOffAt = 90
local energy = 0
local energyStored = 0
local energyMax = 0
local energyStoredPercent = 0
local timerCode
local mode = "Automatic"
local RFProduction = 0
local fuelUse = 0
local coreTemp = 0
local reactorOnline = false
local rodLevel = 0
local turbineOnline = false
local turbineRotorSpeed = 0
local turbineRFGen = 0
local turbineFluidRate = 0
local turbineInductor = false
local OptFuelRodLevel = 0
-- Lejonis Edits --
function loadSettingsFromFile()
if (fs.exists(fname..".txt") == false) then
file = io.open(fname..".txt","w")
file:write(OptFuelRodLevel .. "\n")
file:close()
else
file = fs.open(fname..".txt","r")
OptFuelRodLevel = tonumber(file.readLine())
file.close()
end
end
function saveSettingsToFile()
file = io.open(fname..".txt","w")
file:write(OptFuelRodLevel .. "\n")
file:flush()
file:close()
end
-------------------
function autoMenu()
m.setTextScale(txtScale) --- Lejoni Edit ---
widgets.clearTable()
widgets.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
widgets.setTable("Manual", manualMode, "", 15, 25, 6, 6)
if steamReactor then
widgets.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
widgets.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
end
widgets.screen()
checkMode()
menuMode()
end
function manualMenu()
m.setTextScale(txtScale) --- Lejoni Edit ---
widgets.clearTable()
widgets.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
widgets.setTable("Manual", manualMode, "", 15, 25, 6, 6)
widgets.setTable("Online", online, "", 3, 13, 8, 8)
widgets.setTable("Offline", offline, "", 15, 25, 8, 8)
widgets.setTable("0", setRods, 0, 11,14, 10, 10)
widgets.setTable("10", setRods, 10, 5,8, 12, 12)
widgets.setTable("20", setRods, 20, 11,14, 12, 12)
widgets.setTable("30", setRods, 30, 17,20, 12, 12)
widgets.setTable("40", setRods, 40, 5,8, 14, 14)
widgets.setTable("50", setRods, 50, 11,14, 14, 14)
widgets.setTable("60", setRods, 60, 17,20, 14, 14)
widgets.setTable("70", setRods, 70, 5,8, 16, 16)
widgets.setTable("80", setRods, 80, 11,14, 16, 16)
widgets.setTable("90", setRods, 90, 17,20, 16, 16)
widgets.setTable("+", rodPlus, "", 23, 25, 12, 12)
widgets.setTable("-", rodMinus, "", 23, 25, 16, 16)
if steamReactor then
widgets.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
widgets.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
end
widgets.screen()
checkMode()
reactorOnOff()
menuMode()
end
function turbineAutoMenu()
m.setTextScale(txtScale) --- Lejoni Edit ---
widgets.clearTable()
widgets.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
widgets.setTable("Manual", manualMode, "", 15, 25, 6, 6)
widgets.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
widgets.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
widgets.screen()
checkMode()
menuMode()
end
function turbineManualMenu()
m.setTextScale(txtScale) --- Lejoni Edit ---
widgets.clearTable()
widgets.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
widgets.setTable("Manual", manualMode, "", 15, 25, 6, 6)
widgets.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
widgets.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
widgets.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8)
widgets.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8)
widgets.setTable("Coils On", coilsOn, "", 3, 13, 10, 10)
widgets.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10)
widgets.screen()
checkMode()
turbineOnOff()
coilsOnOff()
menuMode()
end
function reactorMenu()
menuType = "Reactor"
displayScreen()
end
function turbineMenu()
menuType = "Turbine"
displayScreen()
end
function online()
r.setActive(true)
--widgets.flash("Online")
end
function offline()
r.setActive(false)
--widgets.flash("Offline")
end
function setTurbineOnline()
t.setActive(true)
--widgets.flash("Online")
end
function setTurbineOffline()
t.setActive(false)
--widgets.flash("Offline")
end
function reactorOnOff()
widgets.setButton("Online", r.getActive())
widgets.setButton("Offline", not r.getActive())
end
function turbineOnOff()
widgets.setButton("Online", t.getActive())
widgets.setButton("Offline", not t.getActive())
end
function coilsOnOff()
widgets.setButton("Coils On", t.getInductorEngaged())
widgets.setButton("Coils Off", not t.getInductorEngaged())
end
function coilsOn()
t.setInductorEngaged(true)
end
function coilsOff()
t.setInductorEngaged(false)
end
function menuMode()
if steamReactor then
if menuType == "Reactor" then
widgets.setButton("Reactor", true)
widgets.setButton("Turbine", false)
else
widgets.setButton("Reactor", false)
widgets.setButton("Turbine", true)
end
end
end
function setRods(setLevel)
print("Setting Rod Level: "..setLevel)
widgets.flash(tostring(setLevel))
r.setAllControlRodLevels(setLevel)
fuelRodLevel()
end
function rodPlus()
widgets.flash("+")
r.setAllControlRodLevels(rodLevel+1)
fuelRodLevel()
end
function rodMinus()
widgets.flash("-")
r.setAllControlRodLevels(rodLevel-1)
fuelRodLevel()
end
function checkMode()
widgets.toggleButton(mode)
end
function manualMode()
mode = "Manual"
manualMenu()
end
function autoMode()
mode = "Automatic"
displayScreen()
end
function comma_value(amount)
local formatted = amount
local swap = false
if formatted < 0 then
formatted = formatted*-1
swap = true
end
while true do
formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
if k == 0 then
break
end
end
if swap then
formatted = "-"..formatted
end
return formatted
end
function displayEn()
m.clear()
m.setCursorPos(1,1)
--print("Energy Use: "..energy)
m.write("Energy Use: ")
if energy < 0 then
m.setTextColor(colors.red)
else
m.setTextColor(colors.green)
end
m.write(comma_value(math.floor(energy)).. "RF/t")
m.setTextColor(colors.white)
m.setCursorPos(1,2)
m.write("Energy Stored: "..energyStoredPercent.."%")
if menuType == "Reactor" then
m.setCursorPos(1,3)
m.write("Reactor is: ")
if reactorOnline then
m.setTextColor(colors.green)
m.write("Online")
else
m.setTextColor(colors.red)
m.write("Offline")
end
m.setTextColor(colors.white)
m.setCursorPos(colum2,1) --- Lejoni Edit ---
if steamReactor then
m.write("Steam: ")
m.setTextColor(colors.green)
m.write(comma_value(math.floor(RFProduction)).."MB/t")
else
m.write("RF Gen: ")
m.setTextColor(colors.green)
m.write(comma_value(math.floor(RFProduction)).."RF/t")
end
m.setTextColor(colors.white)
m.setCursorPos(colum2,2) --- Lejoni Edit ---
m.write("Core Temp: "..math.floor(coreTemp).."c")
m.setCursorPos(colum2,3) --- Lejoni Edit ---
m.write("Fuel Use: "..fuelUse.."MB/t")
else
m.setCursorPos(1,3)
m.write("Turbine is: ")
if turbineOnline then
m.setTextColor(colors.green)
m.write("Online")
else
m.setTextColor(colors.red)
m.write("Offline")
end
m.setCursorPos(1,4)
m.setTextColor(colors.white)
m.write("Reactor is: ")
if reactorOnline then
m.setTextColor(colors.green)
m.write("Online")
else
m.setTextColor(colors.red)
m.write("Offline")
end
m.setTextColor(colors.white)
m.setCursorPos(colum2,1) --- Lejoni Edit ---
m.write("RFGen: ")
m.setTextColor(colors.green)
m.write(comma_value(math.floor(turbineRFGen)).."RF/t")
m.setTextColor(colors.white)
m.setCursorPos(colum2,2) --- Lejoni Edit ---
m.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM")
m.setCursorPos(colum2,3) --- Lejoni Edit ---
m.write("Steam: "..comma_value(turbineFluidRate).."MB/t")
m.setCursorPos(colum2,4) --- Lejoni Edit ---
m.write("Fuel Use: "..fuelUse.."MB/t")
end
end
function checkEn()
local tempEnergy = 0
energyStored = p.getEnergyStored()
energyMax = p.getMaxEnergyStored()
energyStoredPercent = math.floor((energyStored/energyMax)*100)
--- Lejoni Edit ---
if steamReactor then
RFProduction = t.getEnergyProducedLastTick()
else
RFProduction = r.getEnergyProducedLastTick()
end
-------------------
fuelUse = r.getFuelConsumedLastTick()
fuelUse = math.floor(fuelUse*100)
fuelUse = fuelUse/100
coreTemp = r.getFuelTemperature()
reactorOnline = r.getActive()
tempEnergy = p.getEnergyStored()
sleep(0.1)
--- Lejoni Edit ---
energy = RFProduction - ((p.getEnergyStored()-tempEnergy)/2)
-------------------
energy = energy*numCapacitors
if steamReactor then
turbineOnline = t.getActive()
turbineRotorSpeed = t.getRotorSpeed()
turbineRFGen = t.getEnergyProducedLastTick()
turbineFluidRate = t.getFluidFlowRate()
end
end
function fuelRodLevel()
rodLevel = r.getControlRodLevel(0)
--print(rodLevel)
m.setCursorPos(30,5)
m.write(tostring(rodLevel).."%")
m.setBackgroundColor(colors.white)
m.setCursorPos(28,6)
m.write(" ")
for i = 1,10 do
m.setCursorPos(28,i+6)
m.setBackgroundColor(colors.white)
m.write(" ")
m.setBackgroundColor(colors.yellow)
m.write(" ")
if rodLevel/10 >= i then
m.setBackgroundColor(colors.red)
else
m.setBackgroundColor(colors.yellow)
end
m.write(" ")
m.setBackgroundColor(colors.yellow)
m.write(" ")
m.setBackgroundColor(colors.white)
m.write(" ")
end
m.setCursorPos(28,17)
m.write(" ")
m.setBackgroundColor(colors.black)
end
function turbineInductorDisplay()
turbineInductor = t.getInductorEngaged()
m.setCursorPos(39,5)
if turbineInductor then
m.write("On")
else
m.write("Off")
end
m.setBackgroundColor(colors.gray)
m.setCursorPos(37,6)
m.write(" ")
for i = 1,7 do
m.setCursorPos(37,i+6)
m.setBackgroundColor(colors.gray)
m.write(" ")
m.setBackgroundColor(colors.lightGray)
m.write(" ")
if i % 2 == 0 then
m.setBackgroundColor(colors.gray)
end
m.write(" ")
m.setBackgroundColor(colors.gray)
m.write(" ")
if i % 2 ~= 0 then
m.setBackgroundColor(colors.lightGray)
end
m.write(" ")
m.setBackgroundColor(colors.lightGray)
m.write(" ")
m.setBackgroundColor(colors.gray)
m.write(" ")
end
for i = 8,10 do
m.setCursorPos(37,i+6)
m.setBackgroundColor(colors.gray)
m.write(" ")
m.setBackgroundColor(colors.lightGray)
m.write(" ")
if turbineInductor then
m.setBackgroundColor(colors.red)
else
m.setBackgroundColor(colors.blue)
end
m.write(" ")
m.setBackgroundColor(colors.gray)
m.write(" ")
if turbineInductor then
m.setBackgroundColor(colors.red)
else
m.setBackgroundColor(colors.blue)
end
m.write(" ")
m.setBackgroundColor(colors.lightGray)
m.write(" ")
m.setBackgroundColor(colors.gray)
m.write(" ")
end
m.setCursorPos(37,17)
m.write(" ")
m.setBackgroundColor(colors.black)
end
function getClick()
local event, side, x, y = os.pullEvent("monitor_touch")
widgets.checkxy(x,y)
end
function findOptFuelRods()
m.clear()
r.setActive(false)
checkEn()
displayEn()
fuelRodLevel()
while r.getFuelTemperature() > 99 do
for i= 1,3 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Finding Optimal Rod Level")
m.setCursorPos(3,7)
m.write("Core Temp: "..r.getFuelTemperature())
m.setCursorPos(3,8)
m.write("Waiting for 99c")
sleep(1)
end
end
while r.getHotFluidAmount() > 10000 do
for i = 1,3 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Finding Optimal Rod Level, please wait....")
m.setCursorPos(3,7)
m.write("Fluid Amount: "..comma_value(r.getHotFluidAmount()).."mb")
m.setCursorPos(3,8)
m.write("Waiting for 10,000mb")
sleep(1)
end
end
r.setAllControlRodLevels(99)
r.setActive(true)
while r.getFuelTemperature() < 100 do
for i = 1,5 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Set all rod levels to 99")
m.setCursorPos(3,7)
m.write("Waiting 5 seconds...")
sleep(1)
end
end
for i = 1,5 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Set all rod levels to 99")
m.setCursorPos(3,7)
m.write("Waiting 5 seconds...")
sleep(1)
end
local tempMB = r.getEnergyProducedLastTick()
print(tempMB.."MB/t of steam")
local tempRodLevels = math.floor(2000/tempMB)
print("2000/"..tempMB.." = "..tempRodLevels)
tempRodLevels = 100-tempRodLevels+5
print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels))
r.setAllControlRodLevels(math.floor(tempRodLevels))
print("Waiting 10 seconds to confirm...")
for i = 1,10 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Estimated Level: "..tempRodLevels)
m.setCursorPos(3,7)
m.write("Waiting 10 seconds...")
sleep(1)
end
tempMB = r.getEnergyProducedLastTick()
while tempMB > 2000 do
tempRodLevels = tempRodLevels+1
r.setAllControlRodLevels(math.floor(tempRodLevels))
print("Setting Rod Levels to: "..tempRodLevels)
for i = 1,5 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Getting below 2000mb/t")
m.setCursorPos(3,7)
m.write("Currently at: "..tempMB)
sleep(1)
end
tempMB = r.getEnergyProducedLastTick()
end
while tempMB < 2000 do
tempRodLevels = tempRodLevels -1
r.setAllControlRodLevels(math.floor(tempRodLevels))
print("Setting Rod Levels to: "..tempRodLevels)
for i = 1,5 do
checkEn()
displayEn()
fuelRodLevel()
m.setCursorPos(3,6)
m.write("Getting Above 2000mb/t")
m.setCursorPos(3,7)
m.write("Currently at: "..tempMB)
sleep(1)
end
tempMB = r.getEnergyProducedLastTick()
end
OptFuelRodLevel = tempRodLevels
saveSettingsToFile()
end
function autoReactor()
if not steamReactor then
r.setAllControlRodLevels(0)
if energyStoredPercent < turnOnAt then
if not reactorOnline then
online()
end
end
if energyStoredPercent > turnOffAt then
if reactorOnline then
offline()
end
end
else
r.setAllControlRodLevels(OptFuelRodLevel)
if energyStoredPercent < turnOnAt then
--online()
setTurbineOnline()
coilsOn()
end
if energyStoredPercent > turnOffAt then
--if turbineRotorSpeed > 1800 then
-- offline()
--else
-- online()
--end
setTurbineOnline()
coilsOff()
end
if turbineRotorSpeed > 1810 then
offline()
else
online()
end
end
end
function displayScreen()
-- repeat
checkEn()
displayEn()
if menuType == "Reactor" then
fuelRodLevel()
if mode == "Automatic" then
autoMenu()
autoReactor()
else
manualMenu()
end
else
fuelRodLevel()
turbineInductorDisplay()
if mode == "Automatic" then
turbineAutoMenu()
autoReactor()
else
turbineManualMenu()
end
end
timerCode = os.startTimer(1)
local event, side, x, y
repeat
event, side, x, y = os.pullEvent()
print(event)
if event == "timer" then
print(timerCode..":"..side)
if timerCode ~= side then
print("Wrong Code")
else
print("Right Code")
end
end
until event~= "timer" or timerCode == side
if event == "monitor_touch" then
print(x..":"..y)
widgets.checkxy(x,y)
end
-- until event ~= "timer"
end
loadSettingsFromFile()
if steamReactor then
if OptFuelRodLevel == 0 then
findOptFuelRods()
else
m.setBackgroundColor(colours.black)
m.clear()
m.setCursorPos(3,6)
m.write("Loading Settings:")
m.setCursorPos(3,7)
sleep(1)
m.write("Optimal FuelRodLevel: "..OptFuelRodLevel)
sleep(2)
end
end
while true do
displayScreen()
end
Comments