]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix shuttle throwing (#20884)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Wed, 11 Oct 2023 03:07:21 +0000 (14:07 +1100)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 03:07:21 +0000 (23:07 -0400)
The original PR had a lot of strange and unperformant code.

Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Content.Server/Shuttles/Systems/ShuttleSystem.cs

index e9895e89aaaaa5257c83b54c078bc265d2158506..49e1b1cb84d82b7fa440a8822f078258648e9da0 100644 (file)
@@ -479,17 +479,20 @@ public sealed partial class ShuttleSystem
         // Get enumeration exceptions from people dropping things if we just paralyze as we go
         var toKnock = new ValueList<EntityUid>();
         KnockOverKids(xform, ref toKnock);
+        TryComp<MapGridComponent>(xform.GridUid, out var grid);
 
         if (TryComp<PhysicsComponent>(xform.GridUid, out var shuttleBody))
         {
-
             foreach (var child in toKnock)
             {
-                if (!_statusQuery.TryGetComponent(child, out var status)) continue;
+                if (!_statusQuery.TryGetComponent(child, out var status))
+                    continue;
+
                 _stuns.TryParalyze(child, _hyperspaceKnockdownTime, true, status);
 
                 // If the guy we knocked down is on a spaced tile, throw them too
-                TossIfSpaced(shuttleBody, child);
+                if (grid != null)
+                    TossIfSpaced(grid, shuttleBody, child);
             }
         }
     }
@@ -510,25 +513,23 @@ public sealed partial class ShuttleSystem
     /// <summary>
     /// Throws people who are standing on a spaced tile, tries to throw them towards a neighbouring space tile
     /// </summary>
-    private void TossIfSpaced(PhysicsComponent shuttleBody, EntityUid tossed)
+    private void TossIfSpaced(MapGridComponent shuttleGrid, PhysicsComponent shuttleBody, EntityUid tossed)
     {
-
-        if (!_xformQuery.TryGetComponent(tossed, out var childXform))
+        if (!_xformQuery.TryGetComponent(tossed, out var childXform) )
             return;
 
-        if (!_physicsQuery.TryGetComponent(tossed, out var phys))
+        // only toss if its on lattice/space
+        var tile = shuttleGrid.GetTileRef(childXform.Coordinates);
+
+        if (!tile.IsSpace(_tileDefManager))
             return;
 
-        // only toss if its on lattice/space
-        var tile = childXform.Coordinates.GetTileRef(EntityManager, _mapManager);
+        var throwDirection = childXform.LocalPosition - shuttleBody.LocalCenter;
 
-        if (tile != null && tile.Value.IsSpace() && _mapManager.TryGetGrid(tile.Value.GridUid, out var grid))
-        {
-            Vector2 direction = -Vector2.UnitY;
+        if (throwDirection == Vector2.Zero)
+            return;
 
-            var foo = childXform.LocalPosition - shuttleBody.LocalCenter;
-            _throwing.TryThrow(tossed, foo.Normalized() * 10.0f, 50.0f);
-        }
+        _throwing.TryThrow(tossed, throwDirection.Normalized() * 10.0f, 50.0f);
     }
 
     /// <summary>
@@ -694,10 +695,8 @@ public sealed partial class ShuttleSystem
             return;
 
         // Flatten anything not parented to a grid.
-        var xformQuery = GetEntityQuery<TransformComponent>();
-        var transform = _physics.GetPhysicsTransform(uid, xform, xformQuery);
+        var transform = _physics.GetPhysicsTransform(uid, xform, _xformQuery);
         var aabbs = new List<Box2>(manager.Fixtures.Count);
-        var mobQuery = GetEntityQuery<BodyComponent>();
         var immune = new HashSet<EntityUid>();
 
         foreach (var fixture in manager.Fixtures.Values)
@@ -717,7 +716,7 @@ public sealed partial class ShuttleSystem
                     continue;
                 }
 
-                if (mobQuery.TryGetComponent(ent, out var mob))
+                if (_bodyQuery.TryGetComponent(ent, out var mob))
                 {
                     var gibs = _bobby.GibBody(ent, body: mob);
                     immune.UnionWith(gibs);
index cc93858948d48944546ef8150b84caf8f64be02a..41e4cbc2be92431bebd0f3d9c26e1ae0aaea17a8 100644 (file)
@@ -22,8 +22,10 @@ namespace Content.Server.Shuttles.Systems;
 [UsedImplicitly]
 public sealed partial class ShuttleSystem : SharedShuttleSystem
 {
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
     [Dependency] private readonly IMapManager _mapManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
     [Dependency] private readonly BodySystem _bobby = default!;
     [Dependency] private readonly DockingSystem _dockSystem = default!;
     [Dependency] private readonly DoorSystem _doors = default!;
@@ -40,7 +42,6 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem
     [Dependency] private readonly ThrowingSystem _throwing = default!;
     [Dependency] private readonly ThrusterSystem _thruster = default!;
     [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
-    [Dependency] private readonly IConfigurationManager _cfg = default!;
 
     private ISawmill _sawmill = default!;