From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 19 May 2023 07:26:28 +0000 (+1000) Subject: Shuttle flattening (#16416) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=1192a723e6218415f0e1630e65f0833579e88613;p=space-station-14.git Shuttle flattening (#16416) --- diff --git a/Content.Server/Parallax/BiomeSystem.cs b/Content.Server/Parallax/BiomeSystem.cs index 2fc9a368cb..edf0305e4d 100644 --- a/Content.Server/Parallax/BiomeSystem.cs +++ b/Content.Server/Parallax/BiomeSystem.cs @@ -54,6 +54,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem SubscribeLocalEvent(OnBiomeStartup); SubscribeLocalEvent(OnBiomeMapInit); SubscribeLocalEvent(OnFTLStarted); + SubscribeLocalEvent(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(ev.MapUid, out var biome) || + !TryComp(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); + } + /// /// Preloads biome for the specified area. /// diff --git a/Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs b/Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs new file mode 100644 index 0000000000..b857755880 --- /dev/null +++ b/Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs @@ -0,0 +1,7 @@ +namespace Content.Server.Shuttles.Events; + +/// +/// Raised broadcast whenever a shuttle FTLs +/// +[ByRefEvent] +public readonly record struct ShuttleFlattenEvent(EntityUid MapUid, List AABBs); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index 2187936551..fb3b7b7979 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -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; } + + /// + /// Flattens / deletes everything under the grid upon FTL. + /// + 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(); + var transform = _physics.GetPhysicsTransform(uid, xform, xformQuery); + var aabbs = new List(manager.Fixtures.Count); + var mobQuery = GetEntityQuery(); + var immune = new HashSet(); + + 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); + } } diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index e64f9022c0..3238e6aa91 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -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!;