From 00a21e4ee70b22df2cae0894feb891ee5778e2ae Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 25 Aug 2024 07:48:29 +0300 Subject: [PATCH] Fix dungeon spawn + ftl overlap (#31413) * Fix dungeon spawn + ftl overlap * Better fixes --- Content.Server/Procedural/DungeonJob/DungeonJob.cs | 11 +++++++++++ Content.Server/Procedural/DungeonSystem.cs | 9 ++++++++- .../Shuttles/Systems/ShuttleSystem.GridFill.cs | 11 ++++++----- Content.Server/Shuttles/Systems/ShuttleSystem.cs | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Content.Server/Procedural/DungeonJob/DungeonJob.cs b/Content.Server/Procedural/DungeonJob/DungeonJob.cs index 5a6a8510ff..cdf1f00205 100644 --- a/Content.Server/Procedural/DungeonJob/DungeonJob.cs +++ b/Content.Server/Procedural/DungeonJob/DungeonJob.cs @@ -4,6 +4,7 @@ using Content.Server.Decals; using Content.Server.NPC.Components; using Content.Server.NPC.HTN; using Content.Server.NPC.Systems; +using Content.Server.Shuttles.Systems; using Content.Shared.Construction.EntitySystems; using Content.Shared.Maps; using Content.Shared.Procedural; @@ -51,6 +52,8 @@ public sealed partial class DungeonJob : Job> private readonly EntityUid _gridUid; private readonly MapGridComponent _grid; + private readonly EntityCoordinates? _targetCoordinates; + private readonly ISawmill _sawmill; public DungeonJob( @@ -70,6 +73,7 @@ public sealed partial class DungeonJob : Job> EntityUid gridUid, int seed, Vector2i position, + EntityCoordinates? targetCoordinates = null, CancellationToken cancellation = default) : base(maxTime, cancellation) { _sawmill = sawmill; @@ -94,6 +98,7 @@ public sealed partial class DungeonJob : Job> _gridUid = gridUid; _seed = seed; _position = position; + _targetCoordinates = targetCoordinates; } /// @@ -151,6 +156,12 @@ public sealed partial class DungeonJob : Job> // To make it slightly more deterministic treat this RNG as separate ig. // Post-processing after finishing loading. + if (_targetCoordinates != null) + { + var oldMap = _xformQuery.Comp(_gridUid).MapUid; + _entManager.System().TryFTLProximity(_gridUid, _targetCoordinates.Value); + _entManager.DeleteEntity(oldMap); + } // Defer splitting so they don't get spammed and so we don't have to worry about tracking the grid along the way. _grid.CanSplit = true; diff --git a/Content.Server/Procedural/DungeonSystem.cs b/Content.Server/Procedural/DungeonSystem.cs index 264c2ae860..db306eff32 100644 --- a/Content.Server/Procedural/DungeonSystem.cs +++ b/Content.Server/Procedural/DungeonSystem.cs @@ -188,11 +188,16 @@ public sealed partial class DungeonSystem : SharedDungeonSystem return mapId; } + /// + /// Generates a dungeon in the background with the specified config. + /// + /// Coordinates to move the dungeon to afterwards. Will delete the original map public void GenerateDungeon(DungeonConfig gen, EntityUid gridUid, MapGridComponent grid, Vector2i position, - int seed) + int seed, + EntityCoordinates? coordinates = null) { var cancelToken = new CancellationTokenSource(); var job = new DungeonJob.DungeonJob( @@ -212,6 +217,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem gridUid, seed, position, + coordinates, cancelToken.Token); _dungeonJobs.Add(job, cancelToken); @@ -243,6 +249,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem gridUid, seed, position, + null, cancelToken.Token); _dungeonJobs.Add(job, cancelToken); diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs index c0eff11931..4760e92e21 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.GridFill.cs @@ -85,7 +85,7 @@ public sealed partial class ShuttleSystem _mapManager.DeleteMap(mapId); } - private bool TryDungeonSpawn(Entity targetGrid, MapId mapId, DungeonSpawnGroup group, out EntityUid spawned) + private bool TryDungeonSpawn(Entity targetGrid, DungeonSpawnGroup group, out EntityUid spawned) { spawned = EntityUid.Invalid; @@ -110,11 +110,12 @@ public sealed partial class ShuttleSystem spawnCoords = spawnCoords.Offset(_random.NextVector2(distancePadding + group.MinimumDistance, distancePadding + group.MaximumDistance)); } - var spawnMapCoords = _transform.ToMapCoordinates(spawnCoords); + _maps.CreateMap(out var mapId); + var spawnedGrid = _mapManager.CreateGridEntity(mapId); - _transform.SetMapCoordinates(spawnedGrid, spawnMapCoords); - _dungeon.GenerateDungeon(dungeonProto, spawnedGrid.Owner, spawnedGrid.Comp, Vector2i.Zero, _random.Next()); + _transform.SetMapCoordinates(spawnedGrid, new MapCoordinates(Vector2.Zero, mapId)); + _dungeon.GenerateDungeon(dungeonProto, spawnedGrid.Owner, spawnedGrid.Comp, Vector2i.Zero, _random.Next(), spawnCoords); spawned = spawnedGrid.Owner; return true; @@ -192,7 +193,7 @@ public sealed partial class ShuttleSystem switch (group) { case DungeonSpawnGroup dungeon: - if (!TryDungeonSpawn(targetGrid.Value, mapId, dungeon, out spawned)) + if (!TryDungeonSpawn(targetGrid.Value, dungeon, out spawned)) continue; break; diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 0166a45c5b..cca4c066f6 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -51,7 +51,7 @@ public sealed partial class ShuttleSystem : SharedShuttleSystem [Dependency] private readonly MetaDataSystem _metadata = default!; [Dependency] private readonly PvsOverrideSystem _pvs = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SharedMapSystem _mapSystem = default!; + [Dependency] private readonly SharedMapSystem _maps = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly ShuttleConsoleSystem _console = default!;