Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- os.loadAPI("bar")
- os.loadAPI("label")
- --first we find the monitor, reactor, and capacitor bank
- M = peripheral.find("monitor")
- R = peripheral.find("BigReactors-Reactor")
- C = peripheral.find("tile_blockcapacitorbank_name")
- --set configs here
- ----------------------------------------------------------------------------
- --the reactor won't turn on until we are below minPercentage and will run
- --until we are above the maxPercentage
- local minPercentage = .50
- local maxPercentage = .75
- ----------------------------------------------------------------------------
- M.clear()
- local width,height = M.getSize()
- local maxPowerStorage = C.getMaxEnergyStored()
- local maxPowerDisplay
- if (maxPowerStorage<1000) then
- maxPowerDisplay = tostring(maxPowerStorage).." RF"
- elseif (maxPowerStorage<1000000) then
- maxPowerDisplay = tostring(maxPowerStorage/1000).." kRF"
- elseif (maxPowerStorage<1000000000) then
- maxPowerDisplay = tostring((math.floor(maxPowerStorage/1000))/1000).." mRF"
- else
- maxPowerDisplay = tostring((math.floor(maxPowerStorage/1000000))/1000).." bRF"
- end
- local currPower
- local currFuel
- local maxFuel = R.getFuelAmountMax()
- local rodInsertion
- local RfPerTick
- local throughput
- local isAutomatic = true
- --gets the current power stored in the capacitor. It then edits the loading bar and text information
- function updatePower()
- currPower = C.getEnergyStored()
- bar.changePercentage("power",currPower/maxPowerStorage)
- --get the RF/t change in the capacitor
- local a = C.getEnergyStored()
- sleep(0.05)
- local b = C.getEnergyStored()
- throughput = (b-a)/2
- end
- --checks to see if the reactor should be turned on/off and get reactor information
- function updateReactor()
- if (isAutomatic==true) then
- if (R.getActive()) then
- if (currPower/maxPowerStorage) >= maxPercentage then
- R.setActive(false)
- end
- else
- if (currPower/maxPowerStorage) < minPercentage then
- R.setActive(true)
- end
- end
- end
- label.changeGood("active",R.getActive())
- --check control rod levels
- rodInsertion = R.getControlRodLevel(0)
- --print("Rod insertion at"..rodInsertion)
- bar.changePercentage("rods_foreground",rodInsertion/100)
- --check fuel levels
- currFuel = R.getFuelAmount()
- bar.changePercentage("fuel",currFuel/maxFuel)
- --get energy production
- RfPerTick = R.getEnergyProducedLastTick()
- end
- --initializes the loading bars
- function initBars()
- bar.editBar("power",true,2,height,3,height-3,0,colors.gray,colors.orange)
- bar.editBar("fuel",true,width-3,height,3,height-3,0,colors.gray,colors.cyan)
- bar.editBar("rods_foreground",false,6,height,width-12,1,0,colors.yellow,colors.gray)
- end
- --initializes the labels
- function initLabels()
- label.editLabel("active","ACTIVE",1,1,colors.red,colors.black,colors.black,colors.green,false)
- end
- --initializes the buttons
- function initButtons()
- button.editButton("+100",rodIn,100,18,21,height-1,height-1)
- button.editButton("+10",rodIn,10,23,25,height-1,height-1)
- button.editButton("+1",rodIn,1,27,29,height-1,height-1)
- button.editButton("-1",rodIn,-1,31,33,height-1,height-1)
- button.editButton("-10",rodIn,-10,35,37,height-1,height-1)
- button.editButton("-100",rodIn,-100,39,42,height-1,height-1)
- button.editButton("AutoMode",toggleAuto,"",16,25,1,1)
- button.editButton("active",toggleActive,"",1,6,1,1)
- button.toggleButton("active") --defaults to on
- end
- --changes the rod insertion by the input amount. (negative values decrease the insertion)
- function rodIn(amount)
- if (rodInsertion+amount>100) then
- R.setAllControlRodLevels(100)
- elseif (rodInsertion+amount<0) then
- R.setAllControlRodLevels(0)
- else
- R.setAllControlRodLevels(rodInsertion+amount)
- end
- --flash the correct button
- if (amount==100) then
- button.flash("+100")
- elseif (amount==10) then
- button.flash("+10")
- elseif (amount==1) then
- button.flash("+1")
- elseif (amount==-1) then
- button.flash("-1")
- elseif (amount==-10) then
- button.flash("-10")
- elseif (amount==-100) then
- button.flash("-100")
- end
- end
- --toggles between manual and automatic modes
- function toggleAuto()
- isAutomatic = not isAutomatic
- button.toggleButton("AutoMode")
- end
- --toggles whether the reactor is on or off
- function toggleActive()
- R.setActive(not R.getActive())
- button.toggleButton("active")
- end
- --inits everything
- function initAll()
- initBars()
- initLabels()
- initButtons()
- end
- --writes information
- function drawInfo()
- --power percentage
- M.setCursorPos(8,1)
- val = math.floor((currPower/maxPowerStorage)*10000)/100
- val = tostring(val).."%"
- M.write(val)
- --fuel percentage
- M.setCursorPos(width-3,2)
- val = math.ceil((currFuel/maxFuel)*100)
- val = tostring(val).."%"
- M.write(val)
- --power values
- M.setCursorPos(1,2)
- if currPower<1000 then
- val = tostring(currPower).." RF/"
- elseif currPower < 1000000 then
- val = tostring(currPower/1000).." kRF/"
- elseif currPower < 1000000000 then
- val = tostring((math.floor(currPower/1000))/1000).." mRF/"
- else
- val = tostring((math.floor(currPower/1000000))/1000).." bRF/"
- end
- val = val..maxPowerDisplay
- M.write(val)
- --core rod insertion
- M.setCursorPos(6,height-1)
- val = "Rods at "..tostring(rodInsertion).."%"
- M.write(val)
- --Rf/t production
- M.setCursorPos(27,1)
- val = "RF/t Prod: "..tostring(RfPerTick)
- M.write(val)
- --Capacitor throughput
- M.setCursorPos(1,3)
- if (throughput>=0) then
- M.setTextColor(colors.green)
- else
- M.setTextColor(colors.red)
- end
- M.write("Capacitor change: "..throughput)
- M.setTextColor(colors.white)
- end
- --draws the screen
- function drawScreen()
- M.clear()
- button.screen()
- bar.drawBars()
- label.writeLabels()
- drawInfo()
- end
- --update all the information
- function updateAll()
- updatePower()
- updateReactor()
- end
- --does button things
- function doButton()
- 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 even~="timer" or timerCode==side
- if event=="monitor_touch" then
- print(x..":"..y)
- button.checkXY(x,y)
- end
- end
- --run everything
- initAll()
- while true do
- doButton()
- updateAll()
- drawScreen()
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment