Advertisement
npick001

Control.lua

Feb 16th, 2025 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- Control.lua
  2. ---------------------------------------------------------------
  3. --- Written 2025
  4. --- This file is part of the Nuclear Reactor Control System I&C
  5. --- For Bigger Reactors on the ATM9TTS 1.1.3 Server
  6. --- Created by NP
  7. ---------------------------------------------------------------
  8.  
  9. function ControlReactor(reactor, status)
  10.     -- control reactor based on passed status
  11.     -- designed to be run each tick, make minor control adjustments
  12.     -- print("Reactor Status[Active, Fuel Lvl, Waste Lvl, Stored Power]: " .. (status.activity and "Active" or "Not Active")
  13.     print("Reactor Status: " .. (status.activity and "Active" or "Not Active")
  14.         .. ", " .. status.fuel .. " mB"
  15.         .. ", " .. status.waste .. " mB"
  16.         .. ", " .. status.power_stored .. " RF")
  17.  
  18.     -- if power is too high, deactivate reactor
  19.     local power_capacity = reactor.battery().capacity()
  20.     local power_upper_threshold = power_capacity * 0.95
  21.     local power_lower_threshold = power_capacity * 0.05
  22.     if status.power_stored >= power_upper_threshold then
  23.         reactor.setActive(false)
  24.         return
  25.     end
  26.  
  27.     -- if power is too low, activate reactor
  28.     if status.power_stored <= power_lower_threshold then
  29.         reactor.setActive(true)
  30.         return
  31.     end
  32.  
  33.     -- if reactor is active, control rods
  34.     if status.activity then
  35.         -- if heat is too high, step the rods in
  36.         if status.fuel_heat >= 1500 then
  37.             StepRodsInsert(reactor)
  38.             return
  39.         end
  40.  
  41.         -- if heat is too low, step the rods out
  42.         if status.fuel_heat <= 1000 then
  43.             StepRodsExtract(reactor)
  44.             return
  45.         end        
  46.     end
  47. end
  48.  
  49. function StepRodsInsert(reactor)
  50.     -- step rods
  51.     num_rods = reactor.controlRodCount()
  52.  
  53.     for i = 0, num_rods - 1 do
  54.         rod_depth = reactor.getControlRod(i).level()
  55.         if rod_depth < 100 then
  56.             reactor.getControlRod(i).setLevel(rod_depth + 1)
  57.             print("Stepped rod " .. i .. " to depth " .. (rod_depth + 1))
  58.         end
  59.     end
  60. end
  61.  
  62. function StepRodsExtract(reactor)
  63.     -- step rods
  64.     num_rods = reactor.controlRodCount()
  65.  
  66.     for i = 0, num_rods - 1 do
  67.         rod_depth = reactor.getControlRod(i).level()
  68.         if rod_depth > 0 then
  69.             reactor.getControlRod(i).setLevel(rod_depth - 1)
  70.             print("Stepped rod " .. i .. " to depth " .. (rod_depth - 1))
  71.         end
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement