]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix sinks and toilets not draining (#33691)
authorPartmedia <kevinz5000@gmail.com>
Wed, 4 Dec 2024 02:42:16 +0000 (18:42 -0800)
committerGitHub <noreply@github.com>
Wed, 4 Dec 2024 02:42:16 +0000 (03:42 +0100)
* Fix AutoDrain

Per the system comments, AutoDrain is designed to automatically move
puddles into the drain (like a floor drain). Drains without AutoDrain
are still supposed to gradually empty the buffer, but not remove puddles
(like sinks and toilets).

However, a logic error in the original implementation causes drains with
AutoDrain set to false to simply not work. Hence sinks never emptied.

* Update documentation

Content.Server/Fluids/EntitySystems/DrainSystem.cs
Content.Shared/Fluids/Components/DrainComponent.cs

index 69d15b8d008bd3ef3d8f4dde4b1c3ae6fbe7e9be..215c58804e338d7758d20f55d1b5bb155cfad9df 100644 (file)
@@ -134,13 +134,6 @@ public sealed class DrainSystem : SharedDrainSystem
             }
             drain.Accumulator -= drain.DrainFrequency;
 
-            // Disable ambient sound from emptying manually
-            if (!drain.AutoDrain)
-            {
-                _ambientSoundSystem.SetAmbience(uid, false);
-                continue;
-            }
-
             if (!managerQuery.TryGetComponent(uid, out var manager))
                 continue;
 
@@ -160,41 +153,44 @@ public sealed class DrainSystem : SharedDrainSystem
             // This will ensure that UnitsPerSecond is per second...
             var amount = drain.UnitsPerSecond * drain.DrainFrequency;
 
-            _puddles.Clear();
-            _lookup.GetEntitiesInRange(Transform(uid).Coordinates, drain.Range, _puddles);
-
-            if (_puddles.Count == 0)
+            if (drain.AutoDrain)
             {
-                _ambientSoundSystem.SetAmbience(uid, false);
-                continue;
-            }
+                _puddles.Clear();
+                _lookup.GetEntitiesInRange(Transform(uid).Coordinates, drain.Range, _puddles);
 
-            _ambientSoundSystem.SetAmbience(uid, true);
-
-            amount /= _puddles.Count;
-
-            foreach (var puddle in _puddles)
-            {
-                // Queue the solution deletion if it's empty. EvaporationSystem might also do this
-                // but queuedelete should be pretty safe.
-                if (!_solutionContainerSystem.ResolveSolution(puddle.Owner, puddle.Comp.SolutionName, ref puddle.Comp.Solution, out var puddleSolution))
+                if (_puddles.Count == 0)
                 {
-                    EntityManager.QueueDeleteEntity(puddle);
+                    _ambientSoundSystem.SetAmbience(uid, false);
                     continue;
                 }
 
-                // Removes the lowest of:
-                // the drain component's units per second adjusted for # of puddles
-                // the puddle's remaining volume (making it cleanly zero)
-                // the drain's remaining volume in its buffer.
-                var transferSolution = _solutionContainerSystem.SplitSolution(puddle.Comp.Solution.Value,
-                    FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.Volume, drainSolution.AvailableVolume));
+                _ambientSoundSystem.SetAmbience(uid, true);
 
-                drainSolution.AddSolution(transferSolution, _prototypeManager);
+                amount /= _puddles.Count;
 
-                if (puddleSolution.Volume <= 0)
+                foreach (var puddle in _puddles)
                 {
-                    QueueDel(puddle);
+                    // Queue the solution deletion if it's empty. EvaporationSystem might also do this
+                    // but queuedelete should be pretty safe.
+                    if (!_solutionContainerSystem.ResolveSolution(puddle.Owner, puddle.Comp.SolutionName, ref puddle.Comp.Solution, out var puddleSolution))
+                    {
+                        EntityManager.QueueDeleteEntity(puddle);
+                        continue;
+                    }
+
+                    // Removes the lowest of:
+                    // the drain component's units per second adjusted for # of puddles
+                    // the puddle's remaining volume (making it cleanly zero)
+                    // the drain's remaining volume in its buffer.
+                    var transferSolution = _solutionContainerSystem.SplitSolution(puddle.Comp.Solution.Value,
+                        FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.Volume, drainSolution.AvailableVolume));
+
+                    drainSolution.AddSolution(transferSolution, _prototypeManager);
+
+                    if (puddleSolution.Volume <= 0)
+                    {
+                        QueueDel(puddle);
+                    }
                 }
             }
 
index 3064721bf3c58e6b9bd82d2ea4d83b01aa8138e0..ef0277d214f989e3fa505e812c0c5f737c6ca463 100644 (file)
@@ -27,8 +27,8 @@ public sealed partial class DrainComponent : Component
     public float Accumulator = 0f;
 
     /// <summary>
-    /// Does this drain automatically absorb surrouding puddles? Or is it a drain designed to empty
-    /// solutions in it manually? 
+    /// If true, automatically transfers solutions from nearby puddles and drains them. True for floor drains;
+    /// false for things like toilets and sinks.
     /// </summary>
     [DataField]
     public bool AutoDrain = true;