]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Shuttle flattening (#16416)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 19 May 2023 07:26:28 +0000 (17:26 +1000)
committerGitHub <noreply@github.com>
Fri, 19 May 2023 07:26:28 +0000 (17:26 +1000)
Content.Server/Parallax/BiomeSystem.cs
Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs [new file with mode: 0644]
Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Content.Server/Shuttles/Systems/ShuttleSystem.cs

index 2fc9a368cb0d918280a71887aaef32aaadcc25e2..edf0305e4d94cb0a818a36c1e9ab3ef030abf226 100644 (file)
@@ -54,6 +54,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
         SubscribeLocalEvent<BiomeComponent, ComponentStartup>(OnBiomeStartup);
         SubscribeLocalEvent<BiomeComponent, MapInitEvent>(OnBiomeMapInit);
         SubscribeLocalEvent<FTLStartedEvent>(OnFTLStarted);
+        SubscribeLocalEvent<ShuttleFlattenEvent>(OnShuttleFlatten);
         _configManager.OnValueChanged(CVars.NetMaxUpdateRange, SetLoadRange, true);
         InitializeCommands();
         _proto.PrototypesReloaded += ProtoReload;
@@ -198,6 +199,39 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
         Preload(targetMapUid, biome, targetArea);
     }
 
+    private void OnShuttleFlatten(ref ShuttleFlattenEvent ev)
+    {
+        if (!TryComp<BiomeComponent>(ev.MapUid, out var biome) ||
+            !TryComp<MapGridComponent>(ev.MapUid, out var grid))
+        {
+            return;
+        }
+
+        var tiles = new List<(Vector2i Index, Tile Tile)>();
+
+        foreach (var aabb in ev.AABBs)
+        {
+            for (var x = Math.Floor(aabb.Left); x <= Math.Ceiling(aabb.Right); x++)
+            {
+                for (var y = Math.Floor(aabb.Bottom); y <= Math.Ceiling(aabb.Top); y++)
+                {
+                    var index = new Vector2i((int) x, (int) y);
+                    var chunk = SharedMapSystem.GetChunkIndices(index, ChunkSize);
+
+                    var mod = biome.ModifiedTiles.GetOrNew(chunk * ChunkSize);
+
+                    if (!mod.Add(index) || !TryGetBiomeTile(index, biome.Layers, biome.Noise, grid, out var tile))
+                        continue;
+
+                    // If we flag it as modified then the tile is never set so need to do it ourselves.
+                    tiles.Add((index, tile.Value));
+                }
+            }
+        }
+
+        grid.SetTiles(tiles);
+    }
+
     /// <summary>
     /// Preloads biome for the specified area.
     /// </summary>
diff --git a/Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs b/Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs
new file mode 100644 (file)
index 0000000..b857755
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Server.Shuttles.Events;
+
+/// <summary>
+/// Raised broadcast whenever a shuttle FTLs
+/// </summary>
+[ByRefEvent]
+public readonly record struct ShuttleFlattenEvent(EntityUid MapUid, List<Box2> AABBs);
index 2187936551d08eecf31c07097ef1c1b4fa83ad75..fb3b7b79795ee85a211bf39867f04af201b1ae3f 100644 (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);
+    }
 }
index e64f9022c00f698d6fb786894fe4c91508c92e89..3238e6aa91767f8367b39bef6c03e72e32dfe19d 100644 (file)
@@ -1,7 +1,9 @@
+using Content.Server.Body.Systems;
 using Content.Server.Doors.Systems;
 using Content.Server.Shuttles.Components;
 using Content.Server.Stunnable;
 using Content.Shared.GameTicking;
+using Content.Shared.Mobs.Systems;
 using Content.Shared.Shuttles.Systems;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
@@ -21,8 +23,10 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem
     [Dependency] private readonly IMapManager _mapManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly AirlockSystem _airlock = default!;
+    [Dependency] private readonly BodySystem _bobby = default!;
     [Dependency] private readonly DockingSystem _dockSystem = default!;
     [Dependency] private readonly DoorSystem _doors = default!;
+    [Dependency] private readonly EntityLookupSystem _lookup = default!;
     [Dependency] private readonly FixtureSystem _fixtures = default!;
     [Dependency] private readonly MapLoaderSystem _loader = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;