Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- component = require("component")
- string = require("string")
- table = require("table")
- -- Utilities
- function toBoolean(str)
- if type(str) == 'boolean' then
- return str
- elseif str ~= nil then
- return string.lower(str)
- else
- return false
- end
- end
- function removeValues(tab)
- result={}
- for k, _ in pairs(tab) do
- table.insert(result, k)
- end
- return result
- end
- function applyToAll(tab, func)
- for _, v in ipairs(tab) do
- func(v)
- end
- end
- -- Main code
- function applyConfig(config)
- function getWithDefault(key, default)
- if config[key] ~= nil then
- return config[key]
- else
- return default
- end
- end
- function addrsToProxy(t)
- result = {}
- for _, v in ipairs(t) do
- table.insert(result, component.proxy(v))
- end
- return result
- end
- -- Set default values if they aren't presented
- config.orate = getWithDefault('orate', 50000000)
- config.omode = getWithDefault('omode', 'above')
- config.elevel = getWithDefault('elevel', 60000)
- config.stab = getWithDefault('stab', 100)
- config.on = toBoolean(getWithDefault('on', true))
- cores = addrsToProxy(removeValues(component.list('warpdriveEnanReactorCore')))
- function applyToCores(func)
- applyToAll(cores, func)
- end
- -- Set the rate/threshold
- applyToCores(
- function(core)
- if config.omode == 'rate' then
- core.releaseRate(config.orate)
- else
- core.releaseAbove(config.orate)
- end
- end
- )
- applyToCores(
- function(core)
- core.stabilizerEnergy(config.elevel)
- end
- )
- applyToCores(
- function(core)
- core.instabilityTarget(100 - config.stab)
- end
- )
- applyToCores(
- function(core)
- core.enable(config.on)
- end
- )
- end
- settings = {
- orate = 50000000, --reactor output rate
- omode = 'above', --reactor output mode
- elevel = 10000, --laser energy level
- stab = 2, --reactor target stability
- on = true --on/off
- }
- applyConfig(settings)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement