Advertisement
kaibochan

Reactor.lua

Feb 21st, 2025 (edited)
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | None | 0 0
  1. -- Skeleton code for reactor api
  2. local Reactor = {}
  3.  
  4. Reactor.Rod = function(rod)
  5.     local Rod = {
  6.         index = 1,
  7.         level = 0,
  8.         name = "",
  9.         valid = false,
  10.     }
  11.     Rod.__index = Rod
  12.  
  13.     rod = rod or {}
  14.     setmetatable(rod, Rod)
  15.  
  16.     return {
  17.         index = function()
  18.             return rod.index
  19.         end,
  20.         level = function()
  21.             return rod.level
  22.         end,
  23.         name = function()
  24.             return rod.name
  25.         end,
  26.         setLevel = function(new_level)
  27.             rod.level = new_level
  28.         end,
  29.         setName = function(new_name)
  30.             rod.name = new_name
  31.         end,
  32.         valid = function()
  33.             return rod.valid
  34.         end,
  35.     }
  36. end
  37.  
  38. Reactor.Battery = function(battery)
  39.     local Battery = {
  40.         capacity = 0,
  41.         stored = 0,
  42.     }
  43.     Battery.__index = Battery
  44.  
  45.     battery = battery or {}
  46.     setmetatable(battery, Battery)
  47.  
  48.     return {
  49.         capacity = function()
  50.             return battery.capacity
  51.         end,
  52.         producedLastTick = function()
  53.             return 0
  54.         end,
  55.         stored = function()
  56.             return battery.stored
  57.         end,
  58.     }
  59. end
  60.  
  61. Reactor.CoolantTank = function(coolant_tank)
  62.     local CoolantTank = {
  63.         capacity = 0,
  64.         cold_fluid_amount = 0,
  65.         hot_fluid_amount = 0,
  66.     }
  67.     CoolantTank.__index = CoolantTank
  68.  
  69.     coolant_tank = coolant_tank or {}
  70.     setmetatable(coolant_tank, CoolantTank)
  71.  
  72.     return {
  73.         capacity = function()
  74.             return coolant_tank.capacity
  75.         end,
  76.         coldFluidAmount = function()
  77.             return coolant_tank.cold_fluid_amount
  78.         end,
  79.         dump = function()
  80.             return
  81.         end,
  82.         hotFluidAmount = function()
  83.             return coolant_tank.hot_fluid_amount
  84.         end,
  85.         maxTransitionedLastTick = function()
  86.             return 0
  87.         end,
  88.         transitionedLastTick = function()
  89.             return 0
  90.         end,
  91.     }
  92. end
  93.  
  94. Reactor.FuelTank = function(fuel_tank)
  95.     local FuelTank = {
  96.         capacity = 0,
  97.         fuel_amount = 0,
  98.         fuel_reactivity = 0,
  99.         waste_amount = 0,
  100.     }
  101.     FuelTank.__index = FuelTank
  102.  
  103.     fuel_tank = fuel_tank or {}
  104.     setmetatable(fuel_tank, FuelTank)
  105.  
  106.     return {
  107.         burnedLastTick = function()
  108.             return 0
  109.         end,
  110.         capacity = function()
  111.             return fuel_tank.capacity
  112.         end,
  113.         ejectWaste = function()
  114.             return
  115.         end,
  116.         fuel = function()
  117.             return fuel_tank.fuel_amount
  118.         end,
  119.         fuelReactivity = function()
  120.             return fuel_tank.fuel_reactivity
  121.         end,
  122.         totalReactant = function()
  123.             return 0
  124.         end,
  125.         waste = function()
  126.             return fuel_tank.waste_amount
  127.         end,
  128.     }
  129. end
  130.  
  131. Reactor.Reactor = function(reactor)
  132.     local Reactor = {
  133.         active = false,
  134.         ambient_temp = 0,
  135.         battery = Reactor.Battery(),
  136.         casing_temp = 0,
  137.         connected = false,
  138.         control_rods = {},
  139.         coolant_tank = Reactor.CoolantTank(),
  140.         fuel_tank = Reactor.FuelTank(),
  141.         fuel_temp = 0,
  142.         stack_temp = 0,
  143.     }
  144.     Reactor.__index = Reactor
  145.  
  146.     reactor = reactor or {}
  147.     setmetatable(reactor, Reactor)
  148.  
  149.     return {
  150.         active = function()
  151.             return reactor.active
  152.         end,
  153.         ambientTemperature = function()
  154.             return reactor.ambient_temp
  155.         end,
  156.         battery = function()
  157.             return reactor.battery
  158.         end,
  159.         controlRodCount = function()
  160.             return #reactor.control_rods
  161.         end,
  162.         coolantTank = function()
  163.             return reactor.coolant_tank
  164.         end,
  165.         fuelTank = function()
  166.             return reactor.fuel_tank
  167.         end,
  168.         fuelTemperature = function()
  169.             return reactor.fuel_temp
  170.         end,
  171.         getControlRod = function(index)
  172.             return reactor.control_rods[index]
  173.         end,
  174.         setActive = function(active)
  175.             reactor.active = active
  176.         end,
  177.         setAllControlRodLevels = function(level)
  178.             for _, rod in ipairs(reactor.control_rods) do
  179.                 rod.setLevel(level)
  180.             end
  181.         end,
  182.         stackTemperature = function()
  183.             return reactor.stack_temp
  184.         end,
  185.     }
  186. end
  187.  
  188. return Reactor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement