]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix gas pressure pump prediction (#35865)
authorMilon <milonpl.git@proton.me>
Thu, 27 Mar 2025 23:42:16 +0000 (00:42 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Mar 2025 23:42:16 +0000 (10:42 +1100)
* ACTUALLY predict gas pumps

* generic fake

aaaaaaaaaaaaa

Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs
Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs
Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs
Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs
Content.Shared/Atmos/Components/GasPressurePumpComponent.cs
Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs

index 54e16bc86216c535c1693070f2df2ec9e853b07e..74a8166962e75d71cb0743a43322cfd7bd80ad68 100644 (file)
@@ -1,4 +1,3 @@
-using Content.Client.Atmos.UI;
 using Content.Shared.Atmos.Components;
 using Content.Shared.Atmos.EntitySystems;
 using Content.Shared.Atmos.Piping.Binary.Components;
@@ -15,7 +14,12 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem
 
     private void OnPumpUpdate(Entity<GasPressurePumpComponent> ent, ref AfterAutoHandleStateEvent args)
     {
-        if (UserInterfaceSystem.TryGetOpenUi<GasPressurePumpBoundUserInterface>(ent.Owner, GasPressurePumpUiKey.Key, out var bui))
+        UpdateUi(ent);
+    }
+
+    protected override void UpdateUi(Entity<GasPressurePumpComponent> ent)
+    {
+        if (UserInterfaceSystem.TryGetOpenUi(ent.Owner, GasPressurePumpUiKey.Key, out var bui))
         {
             bui.Update();
         }
index 0c07eec4025c351a1f3eab85b611934ef92f476b..a80959b7b4a633882667afb8985e4067fd36c109 100644 (file)
@@ -12,7 +12,7 @@ namespace Content.Client.Atmos.UI;
 /// Initializes a <see cref="GasPressurePumpWindow"/> and updates it when new server messages are received.
 /// </summary>
 [UsedImplicitly]
-public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface
+public sealed class GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
 {
     [ViewVariables]
     private const float MaxPressure = Atmospherics.MaxOutputPressure;
@@ -20,10 +20,6 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface
     [ViewVariables]
     private GasPressurePumpWindow? _window;
 
-    public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
-    {
-    }
-
     protected override void Open()
     {
         base.Open();
@@ -35,7 +31,7 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface
         Update();
     }
 
-    public void Update()
+    public override void Update()
     {
         if (_window == null)
             return;
@@ -52,7 +48,9 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface
 
     private void OnToggleStatusButtonPressed()
     {
-        if (_window is null) return;
+        if (_window is null)
+            return;
+
         SendPredictedMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus));
     }
 
index aa86a1aa03b38fe8014884947bdae927d7eaf0b4..56c07e7fac0a24e03a44c457248fbc74911aa0b6 100644 (file)
@@ -1,7 +1,6 @@
 using Content.Client.UserInterface.Controls;
 using Content.Shared.Atmos;
 using Robust.Client.AutoGenerated;
-using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
 
 namespace Content.Client.Atmos.UI
index 5f0092f3778c5a8dce39f9b922bc7c3202d4bf43..63944cd53065cd82318c67cd06f2c723e0a0bc5d 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Atmos.Piping.Components;
 using Content.Server.NodeContainer.EntitySystems;
 using Content.Server.NodeContainer.Nodes;
 using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
 using Content.Shared.Atmos;
 using Content.Shared.Atmos.Components;
 using Content.Shared.Atmos.EntitySystems;
@@ -17,6 +18,7 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem
     [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
     [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
     [Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
+    [Dependency] private readonly PowerReceiverSystem _power = default!;
 
     public override void Initialize()
     {
@@ -25,33 +27,33 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem
         SubscribeLocalEvent<GasPressurePumpComponent, AtmosDeviceUpdateEvent>(OnPumpUpdated);
     }
 
-    private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args)
+    private void OnPumpUpdated(Entity<GasPressurePumpComponent> ent, ref AtmosDeviceUpdateEvent args)
     {
-        if (!pump.Enabled
-            || (TryComp<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
-            || !_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet))
+        if (!ent.Comp.Enabled
+            || !_power.IsPowered(ent)
+            || !_nodeContainer.TryGetNodes(ent.Owner, ent.Comp.InletName, ent.Comp.OutletName, out PipeNode? inlet, out PipeNode? outlet))
         {
-            _ambientSoundSystem.SetAmbience(uid, false);
+            _ambientSoundSystem.SetAmbience(ent, false);
             return;
         }
 
         var outputStartingPressure = outlet.Air.Pressure;
 
-        if (outputStartingPressure >= pump.TargetPressure)
+        if (outputStartingPressure >= ent.Comp.TargetPressure)
         {
-            _ambientSoundSystem.SetAmbience(uid, false);
+            _ambientSoundSystem.SetAmbience(ent, false);
             return; // No need to pump gas if target has been reached.
         }
 
         if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
         {
             // We calculate the necessary moles to transfer using our good ol' friend PV=nRT.
-            var pressureDelta = pump.TargetPressure - outputStartingPressure;
+            var pressureDelta = ent.Comp.TargetPressure - outputStartingPressure;
             var transferMoles = (pressureDelta * outlet.Air.Volume) / (inlet.Air.Temperature * Atmospherics.R);
 
             var removed = inlet.Air.Remove(transferMoles);
             _atmosphereSystem.Merge(outlet.Air, removed);
-            _ambientSoundSystem.SetAmbience(uid, removed.TotalMoles > 0f);
+            _ambientSoundSystem.SetAmbience(ent, removed.TotalMoles > 0f);
         }
     }
 }
index 850a2a7a29e9f6feaf8234597c808b961ab0aa48..f0ffad0b0e8ce3bca9b63b12311d976e568666c1 100644 (file)
@@ -3,7 +3,7 @@ using Robust.Shared.GameStates;
 
 namespace Content.Shared.Atmos.Components;
 
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
 public sealed partial class GasPressurePumpComponent : Component
 {
     [DataField, AutoNetworkedField]
index 77444eb3c53fd68491c0afc595c158ee3fc8dcc3..140597971d7db54b864a14d56d49f62487808069 100644 (file)
@@ -5,18 +5,15 @@ using Content.Shared.Atmos.Piping.Binary.Components;
 using Content.Shared.Atmos.Piping.Components;
 using Content.Shared.Database;
 using Content.Shared.Examine;
-using Content.Shared.Popups;
 using Content.Shared.Power;
-using Content.Shared.Power.Components;
 using Content.Shared.Power.EntitySystems;
-using Content.Shared.UserInterface;
 
 namespace Content.Shared.Atmos.EntitySystems;
 
 public abstract class SharedGasPressurePumpSystem : EntitySystem
 {
     [Dependency] private   readonly ISharedAdminLogManager _adminLogger = default!;
-    [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
+    [Dependency] private   readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private   readonly SharedPowerReceiverSystem _receiver = default!;
     [Dependency] protected readonly SharedUserInterfaceSystem UserInterfaceSystem = default!;
 
@@ -36,62 +33,71 @@ public abstract class SharedGasPressurePumpSystem : EntitySystem
         SubscribeLocalEvent<GasPressurePumpComponent, ExaminedEvent>(OnExamined);
     }
 
-    private void OnExamined(EntityUid uid, GasPressurePumpComponent pump, ExaminedEvent args)
+    private void OnExamined(Entity<GasPressurePumpComponent> ent, ref ExaminedEvent args)
     {
-        if (!Transform(uid).Anchored)
+        if (!Transform(ent).Anchored)
             return;
 
-        if (Loc.TryGetString("gas-pressure-pump-system-examined", out var str,
+        if (Loc.TryGetString("gas-pressure-pump-system-examined",
+                out var str,
                 ("statusColor", "lightblue"), // TODO: change with pressure?
-                ("pressure", pump.TargetPressure)
+                ("pressure", ent.Comp.TargetPressure)
             ))
         {
             args.PushMarkup(str);
         }
     }
 
-    private void OnInit(EntityUid uid, GasPressurePumpComponent pump, ComponentInit args)
+    private void OnInit(Entity<GasPressurePumpComponent> ent, ref ComponentInit args)
     {
-        UpdateAppearance(uid, pump);
+        UpdateAppearance(ent);
     }
 
-    private void OnPowerChanged(EntityUid uid, GasPressurePumpComponent component, ref PowerChangedEvent args)
+    private void OnPowerChanged(Entity<GasPressurePumpComponent> ent, ref PowerChangedEvent args)
     {
-        UpdateAppearance(uid, component);
+        UpdateAppearance(ent);
     }
 
-    private void UpdateAppearance(EntityUid uid, GasPressurePumpComponent? pump = null, AppearanceComponent? appearance = null)
+    private void UpdateAppearance(Entity<GasPressurePumpComponent, AppearanceComponent?> ent)
     {
-        if (!Resolve(uid, ref pump, ref appearance, false))
+        if (!Resolve(ent, ref ent.Comp2, false))
             return;
 
-        var pumpOn = pump.Enabled && _receiver.IsPowered(uid);
-        Appearance.SetData(uid, PumpVisuals.Enabled, pumpOn, appearance);
+        var pumpOn = ent.Comp1.Enabled && _receiver.IsPowered(ent.Owner);
+        _appearance.SetData(ent, PumpVisuals.Enabled, pumpOn, ent.Comp2);
     }
 
-    private void OnToggleStatusMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage args)
+    private void OnToggleStatusMessage(Entity<GasPressurePumpComponent> ent, ref GasPressurePumpToggleStatusMessage args)
     {
-        pump.Enabled = args.Enabled;
-        _adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium,
-            $"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}");
-        Dirty(uid, pump);
-        UpdateAppearance(uid, pump);
+        ent.Comp.Enabled = args.Enabled;
+        _adminLogger.Add(LogType.AtmosPowerChanged,
+            LogImpact.Medium,
+            $"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(ent):device} to {args.Enabled}");
+        Dirty(ent);
+        UpdateAppearance(ent);
+        UpdateUi(ent);
     }
 
-    private void OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args)
+    private void OnOutputPressureChangeMessage(Entity<GasPressurePumpComponent> ent, ref GasPressurePumpChangeOutputPressureMessage args)
     {
-        pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
-        _adminLogger.Add(LogType.AtmosPressureChanged, LogImpact.Medium,
-            $"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(uid):device} to {args.Pressure}kPa");
-        Dirty(uid, pump);
+        ent.Comp.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure);
+        _adminLogger.Add(LogType.AtmosPressureChanged,
+            LogImpact.Medium,
+            $"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(ent):device} to {args.Pressure}kPa");
+        Dirty(ent);
+        UpdateUi(ent);
     }
 
-    private void OnPumpLeaveAtmosphere(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceDisabledEvent args)
+    private void OnPumpLeaveAtmosphere(Entity<GasPressurePumpComponent> ent, ref AtmosDeviceDisabledEvent args)
     {
-        pump.Enabled = false;
-        Dirty(uid, pump);
-        UpdateAppearance(uid, pump);
+        ent.Comp.Enabled = false;
+        Dirty(ent);
+        UpdateAppearance(ent);
 
-        UserInterfaceSystem.CloseUi(uid, GasPressurePumpUiKey.Key);
+        UserInterfaceSystem.CloseUi(ent.Owner, GasPressurePumpUiKey.Key);
+    }
+
+    protected virtual void UpdateUi(Entity<GasPressurePumpComponent> ent)
+    {
     }
 }