Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREDIT = "\n\nProgrammed by Brodie Giesbrecht"
- reactor = nil --The global var for the reactor peripheral
- version = "3.0" --Version
- NRG_STORAGE = 10000000 --The energy stored in a standard reactor
- fuelLev = nil --The current fuel level
- FUEL_MAX = nil --The maximum fuel level
- percentFuel = nil --The percentage fuel level
- nrg = nil --The energy stored
- --@function:: firstRun
- --@purpose:: Initialize the reactor and wrap it as well as determine wheter
- -- it is activley cooled etc.
- --@returns::
- -- boolean; whether we found a reactor,
- -- boolean; if actively cooled
- function firstRun()
- reactor = peripheral.find("BigReactors-Reactor")
- if not(reactor == nil) then --Is there a reactor?, yes
- return not(reactor == nil), not(reactor.isActivelyCooled()) --True, cooling supported(T/F)
- else --No reactor
- return not(reactor == nil), false --False, False
- end
- end --firstRun()
- --@function:: conditions
- --@purpose:: Set reactor active true or false depending on
- -- energy and fuel levels
- -- --Perhaps temperature in the future--
- function conditions()
- fuelLev = reactor.getFuelAmount()
- FUEL_MAX = reactor.getFuelAmountMax()
- percentFuel = ((fuelLev / FUEL_MAX) * 100)
- nrg = reactor.getEnergyStored()
- if percentFuel <= 10 and reactor.getActive()==true then
- reactor.setActive(false)
- end
- if nrg >= NRG_STORAGE and reactor.getActive()==true then
- reactor.setActive(false)
- elseif nrg < NRG_STORAGE and percentFuel > 10 then
- reactor.setActive(true)
- end
- end --conditions()
- --@function:: trim
- --@purpose:: trim the numbers after the decimal point of a number
- --@params::
- -- num; The number to truncate
- -- figures; how many figures we want after the decimalpoint
- --@returns::
- -- the truncated number
- function trim(num, figures)
- return math.floor(num * 10^figures) /10^figures
- end --trim()
- --@function:: toString
- --@purpose:: Get a printable version of all of the data we could
- -- possibly want to know about the reactor we are running
- --@return::
- -- string; A formatted string containing all of the information
- function toString()
- result = string.format("Reactor Control Version: %s\n",version)
- result = result .. "Reactor Status:\n"
- result = result .. string.format(" Running: %s\n", tostring(reactor.getActive()))
- result = result .. string.format(" Fuel: %3.1f %s\n", trim(percentFuel, 1), "%")
- result = result .. string.format(" Energy: %g / %g RF\n", trim(nrg, 0), trim(NRG_STORAGE, 0))
- result = result .. "\nAdditonal Info:\n"
- result = result .. string.format("Energy per tick: %.2f RF\n", trim(reactor.getEnergyProducedLastTick(), 2))
- result = result .. string.format(" Fuel per tick: %.2f mB\n", trim(reactor.getFuelConsumedLastTick(), 2))
- result = result .. string.format(" Casing temp: %g C\n", trim(reactor.getCasingTemperature(), 1))
- result = result..CREDIT
- return result
- end --toString()
- --@function:: output
- --@purpose:: print the data
- function output()
- term.clear()
- term.setCursorPos(1,1)
- print(toString())
- end
- --@function:: toggleevent
- --@purpose:: Runs a loop that keeps the reactor from
- -- (hopefully) exploding
- function toggleevent()
- found,passive = firstRun()
- if found and passive then --Make sure we have a reactor
- conditions() --Determine the reactor's status
- output()
- os.startTimer(0.5)
- while true do --Run forever
- local args = { os.pullEvent() }
- if args[1] == "key" then --If keypress
- if args[2] == 184 then --if R-ALT is pressed, exit
- print("Break break break!")
- break
- end
- elseif args[1] == "timer" then --Wait a bit and reevaluate the reactor status
- conditions()
- output()
- os.startTimer(0.5)
- end
- end
- else --Error "catching"
- if not(found) then print("No reactor found!") end --No reactor
- if not(passive) then print("Reactor unsupported, not passively cooled!") end --Don't know enough to do active
- end
- end --toggleevent()
- toggleevent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement