Shuttle flattening (#16416)

This commit is contained in:
metalgearsloth
2023-05-19 17:26:28 +10:00
committed by GitHub
parent 26bf99f2ef
commit 1192a723e6
4 changed files with 96 additions and 2 deletions

View File

@@ -1,4 +1,3 @@
using Content.Server.Doors.Systems;
using Content.Server.Shuttles.Components;
using Content.Server.Station.Systems;
using Content.Shared.Parallax;
@@ -10,10 +9,11 @@ using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Shuttles.Events;
using Content.Shared.Body.Components;
using Content.Shared.Buckle.Components;
using Content.Shared.Doors.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Shuttles.Components;
using JetBrains.Annotations;
using Robust.Shared.Map.Components;
@@ -360,6 +360,8 @@ public sealed partial class ShuttleSystem
comp.Accumulator += FTLCooldown;
_console.RefreshShuttleConsoles(uid);
_mapManager.SetMapPaused(mapId, false);
Smimsh(uid, xform: xform);
var ftlEvent = new FTLCompletedEvent(uid, _mapManager.GetMapEntityId(mapId));
RaiseLocalEvent(uid, ref ftlEvent, true);
break;
@@ -638,4 +640,51 @@ public sealed partial class ShuttleSystem
return true;
}
/// <summary>
/// Flattens / deletes everything under the grid upon FTL.
/// </summary>
private void Smimsh(EntityUid uid, FixturesComponent? manager = null, MapGridComponent? grid = null, TransformComponent? xform = null)
{
if (!Resolve(uid, ref manager, ref grid, ref xform) || xform.MapUid == null)
return;
// Flatten anything not parented to a grid.
var xformQuery = GetEntityQuery<TransformComponent>();
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)
{
if (!fixture.Hard)
continue;
var aabb = fixture.Shape.ComputeAABB(transform, 0);
// Double the polygon radius (at least while the radius exists).
aabb = aabb.Enlarged(0.02f);
aabbs.Add(aabb);
foreach (var ent in _lookup.GetEntitiesIntersecting(xform.MapUid.Value, aabb, LookupFlags.Uncontained))
{
if (ent == uid || immune.Contains(ent))
{
continue;
}
if (mobQuery.TryGetComponent(ent, out var mob))
{
var gibs = _bobby.GibBody(ent, body: mob);
immune.UnionWith(gibs);
continue;
}
QueueDel(ent);
}
}
var ev = new ShuttleFlattenEvent(xform.MapUid.Value, aabbs);
RaiseLocalEvent(ref ev);
}
}