Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local storage
- local reactors = {}
- local reactor_count = 0
- for _, n in pairs(peripheral.getNames()) do
- if n:match "^Induction Matrix" then
- storage = peripheral.wrap(n)
- end
- if n:match "^Reactor Logic Adapter" then
- reactors[n] = peripheral.wrap(n)
- reactor_count = reactor_count + 1
- end
- end
- local integrators = {
- ["redstone_integrator_16"] = "north",
- ["redstone_integrator_17"] = "south",
- }
- local min_rate = 2
- local max_rate = 98
- local energy_crit_threshold = 0.2
- local energy_scaling_range = 1 - energy_crit_threshold
- local range_rate = max_rate - min_rate
- local fuel_threshold = 900
- local power_per_injection_rate = 250000 * reactor_count -- in MJ (mekanism joules or something), not RF
- local function rnd2(f)
- return math.ceil(f / 2) * 2
- end
- local function log(...)
- print(os.date "%H:%M:%S", ...)
- end
- local function calc_injection_rate(target, reactor, name)
- if reactor.getTritium() < fuel_threshold then
- log(name, "tritium critical! Injection rate reduced to", min_rate)
- return min_rate
- elseif reactor.getDeuterium() < fuel_threshold then
- log(name, "deuterium critical! Injection rate reduced to", min_rate)
- return min_rate
- end
- return target
- end
- while true do
- local energy = storage.getEnergy() / storage.getMaxEnergy()
- local output = storage.getOutput()
- local input = storage.getInput()
- local target_level = 1 - ((energy - energy_crit_threshold) / energy_scaling_range)
- local target_1 = min_rate + math.floor(range_rate * math.min(1, math.max(0, target_level)))
- local target_2 = math.ceil(math.min(max_rate, math.max(min_rate, output / power_per_injection_rate)))
- log("Stored energy IR target:", target_1)
- log("Current output IR target:", target_2)
- local target = math.max(target_1, target_2)
- for name, reactor in pairs(reactors) do
- reactor.setInjectionRate(rnd2(calc_injection_rate(target, reactor, name)))
- end
- local d_t = energy < energy_crit_threshold or (target_2 >= 96 and input < output)
- if d_t then
- log("D-T injection activated.")
- end
- for periph, side in pairs(integrators) do
- peripheral.call(periph, "setOutput", side, d_t)
- end
- sleep(1)
- end
Add Comment
Please, Sign In to add comment