Fix shuttle throwing (#20884)

The original PR had a lot of strange and unperformant code.
This commit is contained in:
metalgearsloth
2023-10-11 14:07:21 +11:00
committed by GitHub
parent 9bcf67753a
commit d99d85500c
2 changed files with 21 additions and 21 deletions

View File

@@ -479,17 +479,20 @@ public sealed partial class ShuttleSystem
// Get enumeration exceptions from people dropping things if we just paralyze as we go // Get enumeration exceptions from people dropping things if we just paralyze as we go
var toKnock = new ValueList<EntityUid>(); var toKnock = new ValueList<EntityUid>();
KnockOverKids(xform, ref toKnock); KnockOverKids(xform, ref toKnock);
TryComp<MapGridComponent>(xform.GridUid, out var grid);
if (TryComp<PhysicsComponent>(xform.GridUid, out var shuttleBody)) if (TryComp<PhysicsComponent>(xform.GridUid, out var shuttleBody))
{ {
foreach (var child in toKnock) 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); _stuns.TryParalyze(child, _hyperspaceKnockdownTime, true, status);
// If the guy we knocked down is on a spaced tile, throw them too // 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> /// <summary>
/// Throws people who are standing on a spaced tile, tries to throw them towards a neighbouring space tile /// Throws people who are standing on a spaced tile, tries to throw them towards a neighbouring space tile
/// </summary> /// </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))
return; return;
// only toss if its on lattice/space // only toss if its on lattice/space
var tile = childXform.Coordinates.GetTileRef(EntityManager, _mapManager); var tile = shuttleGrid.GetTileRef(childXform.Coordinates);
if (tile != null && tile.Value.IsSpace() && _mapManager.TryGetGrid(tile.Value.GridUid, out var grid)) if (!tile.IsSpace(_tileDefManager))
{ return;
Vector2 direction = -Vector2.UnitY;
var foo = childXform.LocalPosition - shuttleBody.LocalCenter; var throwDirection = childXform.LocalPosition - shuttleBody.LocalCenter;
_throwing.TryThrow(tossed, foo.Normalized() * 10.0f, 50.0f);
} if (throwDirection == Vector2.Zero)
return;
_throwing.TryThrow(tossed, throwDirection.Normalized() * 10.0f, 50.0f);
} }
/// <summary> /// <summary>
@@ -694,10 +695,8 @@ public sealed partial class ShuttleSystem
return; return;
// Flatten anything not parented to a grid. // 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 aabbs = new List<Box2>(manager.Fixtures.Count);
var mobQuery = GetEntityQuery<BodyComponent>();
var immune = new HashSet<EntityUid>(); var immune = new HashSet<EntityUid>();
foreach (var fixture in manager.Fixtures.Values) foreach (var fixture in manager.Fixtures.Values)
@@ -717,7 +716,7 @@ public sealed partial class ShuttleSystem
continue; continue;
} }
if (mobQuery.TryGetComponent(ent, out var mob)) if (_bodyQuery.TryGetComponent(ent, out var mob))
{ {
var gibs = _bobby.GibBody(ent, body: mob); var gibs = _bobby.GibBody(ent, body: mob);
immune.UnionWith(gibs); immune.UnionWith(gibs);

View File

@@ -22,8 +22,10 @@ namespace Content.Server.Shuttles.Systems;
[UsedImplicitly] [UsedImplicitly]
public sealed partial class ShuttleSystem : SharedShuttleSystem public sealed partial class ShuttleSystem : SharedShuttleSystem
{ {
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly BodySystem _bobby = default!; [Dependency] private readonly BodySystem _bobby = default!;
[Dependency] private readonly DockingSystem _dockSystem = default!; [Dependency] private readonly DockingSystem _dockSystem = default!;
[Dependency] private readonly DoorSystem _doors = 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 ThrowingSystem _throwing = default!;
[Dependency] private readonly ThrusterSystem _thruster = default!; [Dependency] private readonly ThrusterSystem _thruster = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private ISawmill _sawmill = default!; private ISawmill _sawmill = default!;