]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make radiation collector a power supplier (#24978)
authorKevin Zheng <kevinz5000@gmail.com>
Tue, 6 Feb 2024 16:32:39 +0000 (08:32 -0800)
committerGitHub <noreply@github.com>
Tue, 6 Feb 2024 16:32:39 +0000 (11:32 -0500)
Content.Server/Singularity/Components/RadiationCollectorComponent.cs
Content.Server/Singularity/EntitySystems/RadiationCollectorSystem.cs
Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/collector.yml

index 30522c28f3a65f2fb89822d545d1fbee31f7ef91..7870234aab68b5cfa464b9da694f42f6626301e9 100644 (file)
@@ -11,12 +11,22 @@ namespace Content.Server.Singularity.Components;
 public sealed partial class RadiationCollectorComponent : Component
 {
     /// <summary>
-    ///     How much joules will collector generate for each rad.
+    ///     Power output (in Watts) per unit of radiation collected.
     /// </summary>
     [DataField]
     [ViewVariables(VVAccess.ReadWrite)]
     public float ChargeModifier = 30000f;
 
+    /// <summary>
+    ///     Number of power ticks that the power supply can remain active for. This is needed since
+    ///     power and radiation don't update at the same tickrate, and since radiation does not provide
+    ///     an update when radiation is removed. When this goes to zero, zero out the power supplier
+    ///     to model the radiation source going away.
+    /// </summary>
+    [DataField]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public int PowerTicksLeft = 0;
+
     /// <summary>
     ///     Is the machine enabled.
     /// </summary>
index 83666776a05d8aaf63e6794783da2e0a42ef9f1c..92b963e2017d186aa1b571ef78cba9745564fd63 100644 (file)
@@ -38,6 +38,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
         SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
         SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
         SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
+        SubscribeLocalEvent<NetworkBatteryPostSync>(PostSync);
     }
 
     private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
@@ -107,20 +108,34 @@ public sealed class RadiationCollectorSystem : EntitySystem
             }
         }
 
-        // No idea if this is even vaguely accurate to the previous logic.
-        // The maths is copied from that logic even though it works differently.
-        // But the previous logic would also make the radiation collectors never ever stop providing energy.
-        // And since frameTime was used there, I'm assuming that this is what the intent was.
-        // This still won't stop things being potentially hilariously unbalanced though.
-        if (TryComp<BatteryComponent>(uid, out var batteryComponent))
+        if (TryComp<PowerSupplierComponent>(uid, out var comp))
         {
-            _batterySystem.SetCharge(uid, charge, batteryComponent);
+            int powerHoldoverTicks = _gameTiming.TickRate * 2; // number of ticks to hold radiation
+            component.PowerTicksLeft = powerHoldoverTicks;
+            comp.MaxSupply = component.Enabled ? charge : 0;
         }
 
         // Update appearance
         UpdatePressureIndicatorAppearance(uid, component, gasTankComponent);
     }
 
+    private void PostSync(NetworkBatteryPostSync ev)
+    {
+        // This is run every power tick. Used to decrement the PowerTicksLeft counter.
+        var query = EntityQueryEnumerator<RadiationCollectorComponent>();
+        while (query.MoveNext(out var uid, out var component))
+        {
+            if (component.PowerTicksLeft > 0)
+            {
+                component.PowerTicksLeft -= 1;
+            }
+            else if (TryComp<PowerSupplierComponent>(uid, out var comp))
+            {
+                comp.MaxSupply = 0;
+            }
+        }
+    }
+
     private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
     {
         if (!TryGetLoadedGasTank(uid, out var gasTank))
index 73ce22178788fcbabdde7aa432c3205938f8ef3e..3742c037ff502679c57f56521258d3a68edfe8ca 100644 (file)
       - reactantPrototype: Plasma
         powerGenerationEfficiency: 1
         reactantBreakdownRate: 0.0001
-    # Note that this doesn't matter too much (see next comment)
-    # However it does act as a cap on power receivable via the collector.
-  - type: Battery
-    maxCharge: 100000
-    startingCharge: 0
-  - type: BatteryDischarger
-    # This is JUST a default. It has to be dynamically adjusted to ensure that the battery doesn't discharge "too fast" & run out immediately, while still scaling by input power.
-    activeSupplyRate: 100000
   - type: RadiationReceiver
+  - type: PowerSupplier
   - type: Anchorable
   - type: Rotatable
   - type: Pullable
-  - type: PowerNetworkBattery
-    maxSupply: 1000000000
-    supplyRampTolerance: 1000000000
   - type: GuideHelp
     guides: [ Singularity, Power ]
   - type: ContainerContainer