Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RD CC Reactor Control
- -- v 0.0.2
- -- Dependancies:
- -- rdCore
- -- Thank you for choosing this Big Reactors reactor
- -- control program for automating it with CC.
- -- User Settings
- -- Stored Power Threshold
- -- Set a custom stored power threshold to lower the
- -- reactor cores to in order to save power.
- local reacStTh = 100 -- 1/100 Default: 100
- -- Reactor Shutdown Threshold
- -- Should the reactor shut down after a particular
- -- point to conserve fuel. Must be set equal or
- -- higher then Stored Power Threshold.
- local reacOf = false -- true/false Default: false
- local reacOfTh = 100 -- 5/100 Default: 100
- -- Reactor Name
- -- If a monitor is found, a name may be displayed
- -- for the reactor.
- local reacName = ""
- -- Debug Feedback
- -- For double-checking numbers through the monitor.
- -- Should not be needed unless issues or discrepancies
- -- arrise.
- local debugF = true -- true/false Default: false
- --====== DO NOT EDIT BELOW THIS POINT ======--
- -- Reactor Variables
- local function reUpdate()
- reEn = tonumber(reactor.getEnergyStored())
- dBR("Reactor Stored Energy: "..reEn.." rf")
- reOn = reactor.getActive()
- dBR("Reactor State: "..reOn)
- reFuel = tonumber(reactor.getFuelAmount())
- dBR("Reactor Fuel: "..reFuel.." mB")
- reEnPr = tonumber(reactor.getEnergyProducedLastTick())
- dBR("Reactor Energy Produced: "..reEnPr.." rf/t")
- reWa = tonumber(reactor.getWasteAmount())
- dBR("Reactor Waste: "..eWa.." mB")
- reFuWa = tonumber(reactor.getFuelAmountMax())
- dBR("Reactor Fuel/Waste Contained: "..reFuWa.." mB")
- reEnPerc = math.floor((reEn/10000000)*100)
- dBR("Reactor Energy Filled Percentage: "..reEnPerc.."%")
- reFTemp = tonumber(reactor.getFuelTemp)
- dBR("Reactor Fuel Temp: "..reFTemp.." ° C")
- reCTemp = tonumber(reactor.getCasingTemp)
- dBR("Reactor Casing Temp: "..reFTemp.." ° C")
- reTemp = ((reCTemp+reFTemp)/2)
- dBR("Reactor Avg Temp: "..reTemp.." ° C")
- end
- -- Debug readout function
- function dBR(var)
- if debugF == true then
- print(var)
- end
- end
- -- Control Rod Controls
- local function reCtrlRod()
- reUpdate()
- print(reEnPerc.."%.")
- if reEnPerc <= reacStTh then
- dBR("Changing Ctrl Rod Levels to "..reEnPerc.."%.")
- reactor.setAllControlRodLevels(reEnPerc)
- end
- end
- -- Power Threshold
- local function rePowThr()
- reUpdate()
- if reEnPerc > reacOfTh then
- reactor.setActive = false
- elseif reEnPerc < (reacOfTh-5) then
- reactor.setActive = true
- end
- end
- -- Adv Monitor Functionality
- -- monitor variables
- maxX, maxY = term.getSize()
- -- monitor functions
- local function updateScreen()
- if monTest ~= nil then
- reUpdate()
- mon.clear()
- reacTitle()
- reacEnergy()
- reacReadout()
- end
- end
- local function reacTitle()
- local progTitle = "RD Reactor Control ver "..progVer
- local reacTitle = reacName
- mon.setCursorPos(maxX/2-string.len(progTitle)/2,2)
- mon.setTextColor(colors.purple)
- mon.write(progTitle)
- if reacName ~= nil then
- mon.setCursorPos(maxX/2-string.len(reacTitle)/2,3)
- mon.setTextColor(colors.purple)
- mon.write(reacTitle)
- end
- end
- local function put(text,x,y,color)
- term.setCursorPos(x,y)
- term.setTextColor(color or 1)
- term.write(text)
- end
- local function reacEnergy()
- local enTitle = "Reactor RF Stored"
- local enAmt = reEn.." RF"
- local enPerc = reEnPerc.." %"
- put(enTitle,maxX/2-string.len(enTitle), 5, colors.blue)
- put(enTitle,maxX/2-string.len(enAmt.." / "..enPerc), 7, colors.blue)
- paintutils.drawLine(8,9,28,9,colors.white)
- paintutils.drawLine(8,9,(20*(reEnPerc/100))+8,9,colors.red)
- mon.setBackgroundColor(colors.black)
- end
- local function reacReadout()
- end
- -- Find Reactor & Monitor Peripherals
- local function getPeripherals()
- reactor = peripheral.wrap(pSearch("BigReactors-Reactor"))
- monTest = peripheral.find("monitor")
- if reactor.getConnected() == true then
- dBR("Reactor Connected")
- else
- print("Reactor Not Found")
- term.setTextColor(colors.red)
- print("Please relocate this computer next to the reactor's computer port!")
- term.setTextColor(colors.white)
- --break
- end
- if monTest ~= nil then
- mon = peripheral.wrap(pSearch("monitor"))
- dBR("Monitor Found")
- else
- dBR("Monitor Not Found")
- end
- end
- -- Main Program
- local rdCTest = fs.exists("rdCore")
- local rdCPB = "vKDJH93Y"
- progVer = "0.0.2"
- local req = 0
- local runs = 0
- local reactor
- local mon
- if rdCTest == false then
- print("rdCore Api Not Found. Installing embedded version.")
- shell.run("pastebin", "get", "rdCPB", "rdCore")
- shell.run("rdCore")
- rdCTest = fs.exists("rdCore")
- if rdCTest == true then
- add2start("reactorControl")
- print("rdCore Api ver "..rdCV.." Installed Successfully")
- req = 1
- else
- print("rdCore Api Unavailable. RD Reactor Control Unable to Start")
- --break
- end
- else
- print("rdCore Api Found")
- req = 1
- end
- getPeripherals()
- local temp = ("RD Reactor Control ver: "..progVer.." Initialized Successfully")
- while true do
- if runs == 0 then
- if req == 0 then
- break
- else
- print(temp)
- end
- elseif runs == 5 then
- updateScreen()
- runs = 1
- else
- runs = runs + 1
- end
- reCtrlRod()
- if reacOf == true then
- rePowThr()
- end
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement