SubscribeLocalEvent<BiomeComponent, ComponentStartup>(OnBiomeStartup);
SubscribeLocalEvent<BiomeComponent, MapInitEvent>(OnBiomeMapInit);
SubscribeLocalEvent<FTLStartedEvent>(OnFTLStarted);
+ SubscribeLocalEvent<ShuttleFlattenEvent>(OnShuttleFlatten);
_configManager.OnValueChanged(CVars.NetMaxUpdateRange, SetLoadRange, true);
InitializeCommands();
_proto.PrototypesReloaded += ProtoReload;
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>
--- /dev/null
+namespace Content.Server.Shuttles.Events;
+
+/// <summary>
+/// Raised broadcast whenever a shuttle FTLs
+/// </summary>
+[ByRefEvent]
+public readonly record struct ShuttleFlattenEvent(EntityUid MapUid, List<Box2> AABBs);
-using Content.Server.Doors.Systems;
using Content.Server.Shuttles.Components;
using Content.Server.Station.Systems;
using Content.Shared.Parallax;
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;
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;
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);
+ }
}
+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;
[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!;