Shuttle flattening (#16416)
This commit is contained in:
@@ -54,6 +54,7 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
|||||||
SubscribeLocalEvent<BiomeComponent, ComponentStartup>(OnBiomeStartup);
|
SubscribeLocalEvent<BiomeComponent, ComponentStartup>(OnBiomeStartup);
|
||||||
SubscribeLocalEvent<BiomeComponent, MapInitEvent>(OnBiomeMapInit);
|
SubscribeLocalEvent<BiomeComponent, MapInitEvent>(OnBiomeMapInit);
|
||||||
SubscribeLocalEvent<FTLStartedEvent>(OnFTLStarted);
|
SubscribeLocalEvent<FTLStartedEvent>(OnFTLStarted);
|
||||||
|
SubscribeLocalEvent<ShuttleFlattenEvent>(OnShuttleFlatten);
|
||||||
_configManager.OnValueChanged(CVars.NetMaxUpdateRange, SetLoadRange, true);
|
_configManager.OnValueChanged(CVars.NetMaxUpdateRange, SetLoadRange, true);
|
||||||
InitializeCommands();
|
InitializeCommands();
|
||||||
_proto.PrototypesReloaded += ProtoReload;
|
_proto.PrototypesReloaded += ProtoReload;
|
||||||
@@ -198,6 +199,39 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
|||||||
Preload(targetMapUid, biome, targetArea);
|
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>
|
/// <summary>
|
||||||
/// Preloads biome for the specified area.
|
/// Preloads biome for the specified area.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
7
Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs
Normal file
7
Content.Server/Shuttles/Events/ShuttleFlattenEvent.cs
Normal file
@@ -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);
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using Content.Server.Doors.Systems;
|
|
||||||
using Content.Server.Shuttles.Components;
|
using Content.Server.Shuttles.Components;
|
||||||
using Content.Server.Station.Systems;
|
using Content.Server.Station.Systems;
|
||||||
using Content.Shared.Parallax;
|
using Content.Shared.Parallax;
|
||||||
@@ -10,10 +9,11 @@ using Robust.Shared.Map;
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using Content.Server.Shuttles.Events;
|
using Content.Server.Shuttles.Events;
|
||||||
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Buckle.Components;
|
using Content.Shared.Buckle.Components;
|
||||||
using Content.Shared.Doors.Components;
|
using Content.Shared.Doors.Components;
|
||||||
|
using Content.Shared.Mobs.Components;
|
||||||
using Content.Shared.Shuttles.Components;
|
using Content.Shared.Shuttles.Components;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
@@ -360,6 +360,8 @@ public sealed partial class ShuttleSystem
|
|||||||
comp.Accumulator += FTLCooldown;
|
comp.Accumulator += FTLCooldown;
|
||||||
_console.RefreshShuttleConsoles(uid);
|
_console.RefreshShuttleConsoles(uid);
|
||||||
_mapManager.SetMapPaused(mapId, false);
|
_mapManager.SetMapPaused(mapId, false);
|
||||||
|
Smimsh(uid, xform: xform);
|
||||||
|
|
||||||
var ftlEvent = new FTLCompletedEvent(uid, _mapManager.GetMapEntityId(mapId));
|
var ftlEvent = new FTLCompletedEvent(uid, _mapManager.GetMapEntityId(mapId));
|
||||||
RaiseLocalEvent(uid, ref ftlEvent, true);
|
RaiseLocalEvent(uid, ref ftlEvent, true);
|
||||||
break;
|
break;
|
||||||
@@ -638,4 +640,51 @@ public sealed partial class ShuttleSystem
|
|||||||
|
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using Content.Server.Body.Systems;
|
||||||
using Content.Server.Doors.Systems;
|
using Content.Server.Doors.Systems;
|
||||||
using Content.Server.Shuttles.Components;
|
using Content.Server.Shuttles.Components;
|
||||||
using Content.Server.Stunnable;
|
using Content.Server.Stunnable;
|
||||||
using Content.Shared.GameTicking;
|
using Content.Shared.GameTicking;
|
||||||
|
using Content.Shared.Mobs.Systems;
|
||||||
using Content.Shared.Shuttles.Systems;
|
using Content.Shared.Shuttles.Systems;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
@@ -21,8 +23,10 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem
|
|||||||
[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 AirlockSystem _airlock = default!;
|
[Dependency] private readonly AirlockSystem _airlock = 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!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||||
[Dependency] private readonly MapLoaderSystem _loader = default!;
|
[Dependency] private readonly MapLoaderSystem _loader = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
|||||||
Reference in New Issue
Block a user