From fa4c6f63f8aa92f330218e8c3b30cf4f21da5ba0 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:14:35 +1200 Subject: [PATCH] Nullable grid Uid (#8798) --- .../AI/ClientPathfindingDebugSystem.cs | 9 +++-- .../UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs | 2 +- .../UI/Tabs/AtmosTab/AddGasWindow.xaml.cs | 2 +- .../UI/Tabs/AtmosTab/FillGasWindow.xaml.cs | 2 +- .../AtmosTab/SetTemperatureWindow.xaml.cs | 2 +- Content.Client/Audio/BackgroundAudioSystem.cs | 2 +- Content.Client/Eye/EyeLerpingSystem.cs | 2 +- .../IconSmoothing/IconSmoothComponent.cs | 2 +- .../IconSmoothing/IconSmoothSystem.cs | 12 +++--- .../NodeContainer/NodeVisualizationOverlay.cs | 7 ++-- .../Physics/Controllers/MoverController.cs | 2 +- Content.Client/Shuttles/UI/RadarControl.cs | 8 ++-- .../Shuttles/UI/ShuttleConsoleWindow.xaml.cs | 11 +++--- .../Tests/SaveLoadSaveTest.cs | 2 +- Content.MapRenderer/Painters/GridPainter.cs | 4 +- .../Inventory/InteractWithEntityOperator.cs | 2 +- .../Accessible/AiReachableSystem.cs | 12 +++--- .../AI/Pathfinding/PathfindingSystem.Grid.cs | 18 +++++---- .../AI/Steering/AiSteeringSystem.cs | 38 ++++++++++++++----- .../AI/Utility/Actions/Idle/WanderAndWait.cs | 14 ++++--- .../Movement/TargetDistanceCon.cs | 2 +- Content.Server/AI/Utils/Visibility.cs | 2 +- Content.Server/AME/AntimatterEngineSystem.cs | 2 +- .../Administration/Commands/WarpCommand.cs | 8 ++-- .../Atmos/Commands/DeleteGasCommand.cs | 16 ++++---- .../Atmos/EntitySystems/AirtightSystem.cs | 19 +++++----- .../EntitySystems/AtmosphereSystem.Grid.cs | 8 ++-- .../AtmosphereSystem.HighPressureDelta.cs | 1 - .../AtmosPipeAppearanceSystem.cs | 2 +- .../Unary/EntitySystems/GasPortableSystem.cs | 8 ++-- .../Components/SolutionAreaEffectComponent.cs | 17 ++++++--- .../Chemistry/EntitySystems/VaporSystem.cs | 9 +++-- .../Commands/FixRotationsCommand.cs | 4 +- .../Commands/TileReplaceCommand.cs | 4 +- .../Construction/Commands/TileWallsCommand.cs | 4 +- .../Conditions/ComponentInTile.cs | 5 ++- .../Coordinates/Helpers/SnapgridHelper.cs | 2 +- Content.Server/Decals/DecalSystem.cs | 22 ++++++----- .../Systems/WiredNetworkSystem.cs | 2 +- .../Disposal/Tube/DisposalTubeSystem.cs | 7 +++- .../Unit/EntitySystems/DisposableSystem.cs | 2 +- .../Unit/EntitySystems/DisposalUnitSystem.cs | 11 ++++-- .../EntitySystems/SpawnAfterInteractSystem.cs | 2 +- .../EntitySystems/ExplosionSystem.Airtight.cs | 2 +- .../EntitySystems/FluidSpreaderSystem.cs | 2 +- .../Fluids/EntitySystems/MoppingSystem.cs | 2 +- .../Fluids/EntitySystems/SpillableSystem.cs | 2 +- .../Fluids/EntitySystems/SpraySystem.cs | 2 +- .../EntitySystems/GravityGeneratorSystem.cs | 9 ++--- .../EntitySystems/GravityShakeSystem.cs | 2 +- .../Gravity/EntitySystems/GravitySystem.cs | 28 +++++++++----- .../Gravity/EntitySystems/WeightlessSystem.cs | 11 ++++-- Content.Server/Interaction/TilePryCommand.cs | 10 +++-- Content.Server/Kudzu/SpreaderSystem.cs | 4 +- .../CrewMonitoringConsoleSystem.cs | 2 +- Content.Server/Mind/MindSystem.cs | 2 +- .../EntitySystems/NodeGroupSystem.cs | 4 +- .../NodeContainer/NodeGroups/BaseNodeGroup.cs | 11 ++++-- .../NodeContainer/NodeGroups/PipeNet.cs | 4 +- .../ParticleAcceleratorControlBoxComponent.cs | 12 ++++-- .../Physics/Controllers/ConveyorController.cs | 2 +- .../Physics/Controllers/MoverController.cs | 2 +- .../Power/EntitySystems/CableSystem.Placer.cs | 2 +- .../Power/EntitySystems/CableVisSystem.cs | 2 +- .../EntitySystems/ExtensionCableSystem.cs | 6 +-- Content.Server/Power/NodeGroups/ApcNet.cs | 4 +- Content.Server/Power/NodeGroups/PowerNet.cs | 4 +- .../Shuttles/Systems/DockingSystem.cs | 22 ++++++----- .../Shuttles/Systems/ShuttleConsoleSystem.cs | 2 +- .../Shuttles/Systems/SpaceGarbageSystem.cs | 2 +- .../Shuttles/Systems/ThrusterSystem.cs | 15 +++++--- Content.Server/Sound/EmitSoundSystem.cs | 2 +- .../Station/Systems/StationSystem.cs | 4 +- .../StationEvents/Events/GasLeak.cs | 12 +++--- Content.Server/SubFloor/SubFloorHideSystem.cs | 2 +- Content.Server/Tools/ToolSystem.TilePrying.cs | 12 +++++- .../Friction/SharedTileFrictionController.cs | 2 +- Content.Shared/Maps/TurfHelpers.cs | 14 +------ .../MovementIgnoreGravityComponent.cs | 6 +-- .../Movement/SharedMoverController.cs | 18 ++++----- .../SubFloor/SharedSubFloorHideSystem.cs | 2 +- Content.Shared/SubFloor/TrayScannerSystem.cs | 2 +- 82 files changed, 318 insertions(+), 242 deletions(-) diff --git a/Content.Client/AI/ClientPathfindingDebugSystem.cs b/Content.Client/AI/ClientPathfindingDebugSystem.cs index e7f59e95bb..2c42189087 100644 --- a/Content.Client/AI/ClientPathfindingDebugSystem.cs +++ b/Content.Client/AI/ClientPathfindingDebugSystem.cs @@ -294,7 +294,7 @@ namespace Content.Client.AI private void DrawCachedRegions(DrawingHandleScreen screenHandle, Box2 viewport) { var transform = _entities.GetComponentOrNull(_playerManager.LocalPlayer?.ControlledEntity); - if (transform == null || !CachedRegions.TryGetValue(transform.GridEntityId, out var entityRegions)) + if (transform == null || transform.GridUid == null || !CachedRegions.TryGetValue(transform.GridUid.Value, out var entityRegions)) { return; } @@ -312,7 +312,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _cachedRegionColors[transform.GridEntityId][region]); + screenHandle.DrawRect(box, _cachedRegionColors[transform.GridUid.Value][region]); } } } @@ -344,7 +344,8 @@ namespace Content.Client.AI { var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity; if (!_entities.TryGetComponent(attachedEntity, out TransformComponent? transform) || - !Regions.TryGetValue(transform.GridEntityId, out var entityRegions)) + transform.GridUid == null || + !Regions.TryGetValue(transform.GridUid.Value, out var entityRegions)) { return; } @@ -364,7 +365,7 @@ namespace Content.Client.AI screenTile.X + 15.0f, screenTile.Y + 15.0f); - screenHandle.DrawRect(box, _regionColors[_entities.GetComponent(attachedEntity.Value).GridEntityId][chunk][region]); + screenHandle.DrawRect(box, _regionColors[transform.GridUid.Value][chunk][region]); } } } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs index d4f69e14e4..644ef8af35 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/AddAtmosWindow.xaml.cs @@ -24,7 +24,7 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab foreach (var grid in _data) { var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridEntityId; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridUid; GridOptions.AddItem($"{grid.GridEntityId} {(playerGrid == grid.GridEntityId ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs index d8333eefb9..92c079f6b4 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs @@ -28,7 +28,7 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab foreach (var grid in _gridData) { var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridEntityId; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridUid; GridOptions.AddItem($"{grid.GridEntityId} {(playerGrid == grid.GridEntityId ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs index f9577ea763..35a0ea99db 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/FillGasWindow.xaml.cs @@ -28,7 +28,7 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab foreach (var grid in _gridData) { var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridEntityId; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridUid; GridOptions.AddItem($"{grid.GridEntityId} {(playerGrid == grid.GridEntityId ? " (Current)" : "")}"); } diff --git a/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs index 69f3ed362c..6ff73c979b 100644 --- a/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AtmosTab/SetTemperatureWindow.xaml.cs @@ -24,7 +24,7 @@ namespace Content.Client.Administration.UI.Tabs.AtmosTab foreach (var grid in _data) { var player = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridEntityId; + var playerGrid = IoCManager.Resolve().GetComponentOrNull(player)?.GridUid; GridOptions.AddItem($"{grid.GridEntityId} {(playerGrid == grid.GridEntityId ? " (Current)" : "")}"); } diff --git a/Content.Client/Audio/BackgroundAudioSystem.cs b/Content.Client/Audio/BackgroundAudioSystem.cs index e1890b5698..c09a684236 100644 --- a/Content.Client/Audio/BackgroundAudioSystem.cs +++ b/Content.Client/Audio/BackgroundAudioSystem.cs @@ -89,7 +89,7 @@ namespace Content.Client.Audio { if(_playMan.LocalPlayer is null || _playMan.LocalPlayer.ControlledEntity != message.Entity) return; if (!TryComp(message.Entity, out var xform) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) return; + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; var tileDef = (ContentTileDefinition) _tileDefMan[grid.GetTileRef(xform.Coordinates).Tile.TypeId]; diff --git a/Content.Client/Eye/EyeLerpingSystem.cs b/Content.Client/Eye/EyeLerpingSystem.cs index 70deb4d5b5..f687005f46 100644 --- a/Content.Client/Eye/EyeLerpingSystem.cs +++ b/Content.Client/Eye/EyeLerpingSystem.cs @@ -105,7 +105,7 @@ public sealed class EyeLerpingSystem : EntitySystem if (!TryComp(uid, out TransformComponent? transform) || !TryComp(uid, out EyeComponent? eye) || eye.Eye == null - || !_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) + || !_mapManager.TryGetGrid(transform.GridUid, out var grid)) { _toRemove.Add(uid); return; diff --git a/Content.Client/IconSmoothing/IconSmoothComponent.cs b/Content.Client/IconSmoothing/IconSmoothComponent.cs index f497cbf60a..c4b6e25ec6 100644 --- a/Content.Client/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/IconSmoothing/IconSmoothComponent.cs @@ -13,7 +13,7 @@ namespace Content.Client.IconSmoothing [RegisterComponent] public sealed class IconSmoothComponent : Component { - public (EntityUid, Vector2i)? LastPosition; + public (EntityUid?, Vector2i)? LastPosition; /// /// We will smooth with other objects with the same key. diff --git a/Content.Client/IconSmoothing/IconSmoothSystem.cs b/Content.Client/IconSmoothing/IconSmoothSystem.cs index 9322ff3cdf..f37a5a8bb6 100644 --- a/Content.Client/IconSmoothing/IconSmoothSystem.cs +++ b/Content.Client/IconSmoothing/IconSmoothSystem.cs @@ -33,9 +33,9 @@ namespace Content.Client.IconSmoothing var xform = Transform(uid); if (xform.Anchored) { - component.LastPosition = _mapManager.TryGetGrid(xform.GridEntityId, out var grid) - ? (xform.GridEntityId, grid.TileIndicesFor(xform.Coordinates)) - : (EntityUid.Invalid, new Vector2i(0, 0)); + component.LastPosition = _mapManager.TryGetGrid(xform.GridUid, out var grid) + ? (xform.GridUid.Value, grid.TileIndicesFor(xform.Coordinates)) + : (null, new Vector2i(0, 0)); DirtyNeighbours(uid, component); } @@ -111,7 +111,7 @@ namespace Content.Client.IconSmoothing Vector2i pos; - if (transform.Anchored && _mapManager.TryGetGrid(transform.GridEntityId, out var grid)) + if (transform.Anchored && _mapManager.TryGetGrid(transform.GridUid, out var grid)) { pos = grid.CoordinatesToTile(transform.Coordinates); } @@ -191,9 +191,9 @@ namespace Content.Client.IconSmoothing if (xform.Anchored) { - if (!_mapManager.TryGetGrid(xform.GridEntityId, out grid)) + if (!_mapManager.TryGetGrid(xform.GridUid, out grid)) { - Logger.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridEntityId} was missing."); + Logger.Error($"Failed to calculate IconSmoothComponent sprite in {uid} because grid {xform.GridUid} was missing."); return; } } diff --git a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs index 2b0cba6b88..7b4aa55707 100644 --- a/Content.Client/NodeContainer/NodeVisualizationOverlay.cs +++ b/Content.Client/NodeContainer/NodeVisualizationOverlay.cs @@ -76,9 +76,10 @@ namespace Content.Client.NodeContainer var node = _system.NodeLookup[(groupId, nodeId)]; - var gridId = _entityManager.GetComponent(node.Entity).GridEntityId; - var grid = _mapManager.GetGrid(gridId); - var gridTile = grid.TileIndicesFor(_entityManager.GetComponent(node.Entity).Coordinates); + var xform = _entityManager.GetComponent(node.Entity); + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) + return; + var gridTile = grid.TileIndicesFor(xform.Coordinates); var sb = new StringBuilder(); sb.Append($"entity: {node.Entity}\n"); diff --git a/Content.Client/Physics/Controllers/MoverController.cs b/Content.Client/Physics/Controllers/MoverController.cs index 39d5517811..bac19334fc 100644 --- a/Content.Client/Physics/Controllers/MoverController.cs +++ b/Content.Client/Physics/Controllers/MoverController.cs @@ -27,7 +27,7 @@ namespace Content.Client.Physics.Controllers return; } - if (xform.GridEntityId != EntityUid.Invalid) + if (xform.GridUid != null) mover.LastGridAngle = GetParentGridAngle(xform, mover); // Essentially we only want to set our mob to predicted so every other entity we just interpolate diff --git a/Content.Client/Shuttles/UI/RadarControl.cs b/Content.Client/Shuttles/UI/RadarControl.cs index f8d2f8c6e8..eda8fb08d8 100644 --- a/Content.Client/Shuttles/UI/RadarControl.cs +++ b/Content.Client/Shuttles/UI/RadarControl.cs @@ -150,15 +150,15 @@ public sealed class RadarControl : Control Matrix3 matrix; // Draw our grid in detail - var ourGridId = xform.GridID; - if (ourGridId != GridId.Invalid) + var ourGridId = xform.GridUid; + if (ourGridId != null) { matrix = xform.InvWorldMatrix; - var ourGridFixtures = fixturesQuery.GetComponent(ourGridId); + var ourGridFixtures = fixturesQuery.GetComponent(ourGridId.Value); // Draw our grid; use non-filled boxes so it doesn't look awful. DrawGrid(handle, offsetMatrix, ourGridFixtures, Color.Yellow); - DrawDocks(handle, xform.GridEntityId, offsetMatrix); + DrawDocks(handle, ourGridId.Value, offsetMatrix); } else { diff --git a/Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs b/Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs index 3d2c4b1a80..4a2d945889 100644 --- a/Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs +++ b/Content.Client/Shuttles/UI/ShuttleConsoleWindow.xaml.cs @@ -110,13 +110,14 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow, DockPorts.DisposeAllChildren(); DockingScreen.Docks = _docks; - if (!_entManager.TryGetComponent(_entity, out var xform)) + if (!_entManager.TryGetComponent(_entity, out var xform) + || !xform.GridUid.HasValue) { // TODO: Show Placeholder return; } - if (_docks.TryGetValue(xform.GridEntityId, out var gridDocks)) + if (_docks.TryGetValue(xform.GridUid.Value, out var gridDocks)) { var index = 1; @@ -194,7 +195,7 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow, DockingScreen.Visible = true; DockingScreen.ViewedDock = ent; StartAutodockPressed?.Invoke(ent); - DockingScreen.GridEntity = xform?.GridEntityId; + DockingScreen.GridEntity = xform?.GridUid; _selectedDock = obj.Button; } } @@ -215,8 +216,8 @@ public sealed partial class ShuttleConsoleWindow : FancyWindow, base.Draw(handle); if (!_entManager.TryGetComponent(_entity, out var entXform) || - !_entManager.TryGetComponent(entXform.GridEntityId, out var gridBody) || - !_entManager.TryGetComponent(entXform.GridEntityId, out var gridXform)) + !_entManager.TryGetComponent(entXform.GridUid, out var gridBody) || + !_entManager.TryGetComponent(entXform.GridUid, out var gridXform)) { return; } diff --git a/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs b/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs index a9ff9fe7fc..1563ab60ed 100644 --- a/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs +++ b/Content.IntegrationTests/Tests/SaveLoadSaveTest.cs @@ -27,7 +27,7 @@ namespace Content.IntegrationTests.Tests { // TODO: Properly find the "main" station grid. var grid0 = mapManager.GetAllGrids().First(); - mapLoader.SaveBlueprint(grid0.GridEntityId, "save load save 1.yml"); + mapLoader.SaveBlueprint(grid0.Index, "save load save 1.yml"); var mapId = mapManager.CreateMap(); var grid = mapLoader.LoadBlueprint(mapId, "save load save 1.yml").gridId; mapLoader.SaveBlueprint(grid!.Value, "save load save 2.yml"); diff --git a/Content.MapRenderer/Painters/GridPainter.cs b/Content.MapRenderer/Painters/GridPainter.cs index bb355f28ad..7cd9999639 100644 --- a/Content.MapRenderer/Painters/GridPainter.cs +++ b/Content.MapRenderer/Painters/GridPainter.cs @@ -90,14 +90,14 @@ namespace Content.MapRenderer.Painters } var transform = _sEntityManager.GetComponent(entity); - if (_cMapManager.TryGetGrid(transform.GridEntityId, out var grid)) + if (_cMapManager.TryGetGrid(transform.GridUid, out var grid)) { var position = transform.LocalPosition; var (x, y) = TransformLocalPosition(position, grid); var data = new EntityData(sprite, x, y); - components.GetOrAdd(transform.GridEntityId, _ => new List()).Add(data); + components.GetOrAdd(transform.GridUid.Value, _ => new List()).Add(data); } } diff --git a/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs b/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs index 435d14462d..0a1bc09fdc 100644 --- a/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs +++ b/Content.Server/AI/Operators/Inventory/InteractWithEntityOperator.cs @@ -26,7 +26,7 @@ namespace Content.Server.AI.Operators.Inventory { var targetTransform = _entMan.GetComponent(_useTarget); - if (targetTransform.GridEntityId != _entMan.GetComponent(_owner).GridEntityId) + if (targetTransform.GridUid != _entMan.GetComponent(_owner).GridUid) { return Outcome.Failed; } diff --git a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs index a5ae55d95a..823c2f0d94 100644 --- a/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs +++ b/Content.Server/AI/Pathfinding/Accessible/AiReachableSystem.cs @@ -168,10 +168,10 @@ namespace Content.Server.AI.Pathfinding.Accessible { var xform = EntityManager.GetComponent(target); // TODO: Handle this gracefully instead of just failing. - if (!xform.GridEntityId.IsValid()) + if (xform.GridUid == null) return false; - var targetTile = _mapManager.GetGrid(xform.GridEntityId).GetTileRef(xform.Coordinates); + var targetTile = _mapManager.GetGrid(xform.GridUid.Value).GetTileRef(xform.Coordinates); var targetNode = _pathfindingSystem.GetNode(targetTile); var collisionMask = 0; @@ -206,10 +206,10 @@ namespace Content.Server.AI.Pathfinding.Accessible { var xform = EntityManager.GetComponent(entity); - if (xform.GridEntityId != targetNode.TileRef.GridUid) + if (xform.GridUid != targetNode.TileRef.GridUid || xform.GridUid == null) return false; - var entityTile = _mapManager.GetGrid(xform.GridEntityId).GetTileRef(xform.Coordinates); + var entityTile = _mapManager.GetGrid(xform.GridUid.Value).GetTileRef(xform.Coordinates); var entityNode = _pathfindingSystem.GetNode(entityTile); var entityRegion = GetRegion(entityNode); var targetRegion = GetRegion(targetNode); @@ -421,12 +421,12 @@ namespace Content.Server.AI.Pathfinding.Accessible { var xform = EntityManager.GetComponent(entity); - if (!xform.GridEntityId.IsValid()) + if (xform.GridUid == null) { return null; } - var entityTile = _mapManager.GetGrid(xform.GridEntityId).GetTileRef(xform.Coordinates); + var entityTile = _mapManager.GetGrid(xform.GridUid.Value).GetTileRef(xform.Coordinates); var entityNode = _pathfindingSystem.GetNode(entityTile); return GetRegion(entityNode); } diff --git a/Content.Server/AI/Pathfinding/PathfindingSystem.Grid.cs b/Content.Server/AI/Pathfinding/PathfindingSystem.Grid.cs index c69fa730b6..b56250f36f 100644 --- a/Content.Server/AI/Pathfinding/PathfindingSystem.Grid.cs +++ b/Content.Server/AI/Pathfinding/PathfindingSystem.Grid.cs @@ -129,7 +129,7 @@ public sealed partial class PathfindingSystem private bool IsRelevant(TransformComponent xform, PhysicsComponent physics) { - return xform.GridEntityId != EntityUid.Invalid && (TrackedCollisionLayers & physics.CollisionLayer) != 0; + return xform.GridUid != null && (TrackedCollisionLayers & physics.CollisionLayer) != 0; } /// @@ -143,7 +143,7 @@ public sealed partial class PathfindingSystem !Resolve(entity, ref physics, false)) return; if (!IsRelevant(xform, physics) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) { return; } @@ -158,7 +158,7 @@ public sealed partial class PathfindingSystem private void OnEntityRemove(EntityUid entity, TransformComponent? xform = null) { if (!Resolve(entity, ref xform, false) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) return; + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; var node = GetNode(grid.GetTileRef(xform.Coordinates)); node.RemoveEntity(entity); @@ -166,7 +166,7 @@ public sealed partial class PathfindingSystem private void OnEntityRemove(EntityUid entity, EntityCoordinates coordinates) { - var gridId = coordinates.GetGridEntityId(EntityManager); + var gridId = coordinates.GetGridUid(EntityManager); if (!_mapManager.TryGetGrid(gridId, out var grid)) return; var node = GetNode(grid.GetTileRef(coordinates)); @@ -175,13 +175,13 @@ public sealed partial class PathfindingSystem private PathfindingNode? GetNode(TransformComponent xform) { - if (!_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) return null; + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) return null; return GetNode(grid.GetTileRef(xform.Coordinates)); } private PathfindingNode? GetNode(EntityCoordinates coordinates) { - if (!_mapManager.TryGetGrid(coordinates.GetGridEntityId(EntityManager), out var grid)) return null; + if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var grid)) return null; return GetNode(grid.GetTileRef(coordinates)); } @@ -215,8 +215,10 @@ public sealed partial class PathfindingSystem // Also look at increasing tile cost the more physics entities are on it public bool CanTraverse(EntityUid entity, EntityCoordinates coordinates) { - var gridId = coordinates.GetGridEntityId(EntityManager); - var tile = _mapManager.GetGrid(gridId).GetTileRef(coordinates); + var gridId = coordinates.GetGridUid(EntityManager); + if (gridId == null) + return false; + var tile = _mapManager.GetGrid(gridId.Value).GetTileRef(coordinates); var node = GetNode(tile); return CanTraverse(entity, node); } diff --git a/Content.Server/AI/Steering/AiSteeringSystem.cs b/Content.Server/AI/Steering/AiSteeringSystem.cs index 14f5a2c974..10552efa6a 100644 --- a/Content.Server/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/AI/Steering/AiSteeringSystem.cs @@ -242,7 +242,8 @@ namespace Content.Server.AI.Steering if (Deleted(entity) || !EntityManager.TryGetComponent(entity, out AiControllerComponent? controller) || !controller.CanMove || - !EntityManager.GetComponent(entity).GridEntityId.IsValid()) + !TryComp(entity, out TransformComponent? xform) || + xform.GridUid == null) { return SteeringStatus.NoPath; } @@ -255,7 +256,7 @@ namespace Content.Server.AI.Steering return SteeringStatus.NoPath; } - if (_mapManager.IsGridPaused(EntityManager.GetComponent(entity).GridEntityId)) + if (_mapManager.IsGridPaused(xform.GridUid.Value)) { controller.VelocityDir = Vector2.Zero; return SteeringStatus.Pending; @@ -263,14 +264,14 @@ namespace Content.Server.AI.Steering // Validation // Check if we can even arrive -> Currently only samegrid movement supported - if (EntityManager.GetComponent(entity).GridEntityId != steeringRequest.TargetGrid.GetGridEntityId(EntityManager)) + if (xform.GridUid != steeringRequest.TargetGrid.GetGridUid(EntityManager)) { controller.VelocityDir = Vector2.Zero; return SteeringStatus.NoPath; } // Check if we have arrived - var targetDistance = (EntityManager.GetComponent(entity).MapPosition.Position - steeringRequest.TargetMap.Position).Length; + var targetDistance = (xform.MapPosition.Position - steeringRequest.TargetMap.Position).Length; steeringRequest.TimeUntilInteractionCheck -= frameTime; if (targetDistance <= steeringRequest.ArrivalDistance && steeringRequest.TimeUntilInteractionCheck <= 0.0f) @@ -407,9 +408,13 @@ namespace Content.Server.AI.Steering return; } + var xform = EntityManager.GetComponent(entity); + if (xform.GridUid == null) + return; + var cancelToken = new CancellationTokenSource(); - var gridManager = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridEntityId); - var startTile = gridManager.GetTileRef(EntityManager.GetComponent(entity).Coordinates); + var gridManager = _mapManager.GetGrid(xform.GridUid.Value); + var startTile = gridManager.GetTileRef(xform.Coordinates); var endTile = gridManager.GetTileRef(steeringRequest.TargetGrid); var collisionMask = 0; if (EntityManager.TryGetComponent(entity, out IPhysBody? physics)) @@ -439,7 +444,10 @@ namespace Content.Server.AI.Steering { _pathfindingRequests.Remove(entity); - var entityTile = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridEntityId).GetTileRef(EntityManager.GetComponent(entity).Coordinates); + var xform = EntityManager.GetComponent(entity); + if (xform.GridUid == null) + return; + var entityTile = _mapManager.GetGrid(xform.GridUid.Value).GetTileRef(xform.Coordinates); var tile = path.Dequeue(); var closestDistance = PathfindingHelpers.OctileDistance(entityTile, tile); @@ -508,7 +516,12 @@ namespace Content.Server.AI.Steering { if (_paths[entity].Count == 0) return; var nextTile = dequeue ? _paths[entity].Dequeue() : _paths[entity].Peek(); - var nextGrid = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridEntityId).GridTileToLocal(nextTile.GridIndices); + + var xform = EntityManager.GetComponent(entity); + if (xform.GridUid == null) + return; + + var nextGrid = _mapManager.GetGrid(xform.GridUid.Value).GridTileToLocal(nextTile.GridIndices); _nextGrid[entity] = nextGrid; } @@ -630,8 +643,13 @@ namespace Content.Server.AI.Steering var avoidanceVector = Vector2.Zero; var checkTiles = new HashSet(); var avoidTiles = new HashSet(); - var entityGridCoords = EntityManager.GetComponent(entity).Coordinates; - var grid = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridEntityId); + + var xform = EntityManager.GetComponent(entity); + if (xform.GridUid == null) + return default; + + var entityGridCoords = xform.Coordinates; + var grid = _mapManager.GetGrid(xform.GridUid.Value); var currentTile = grid.GetTileRef(entityGridCoords); var halfwayTile = grid.GetTileRef(entityGridCoords.Offset(direction / 2)); var nextTile = grid.GetTileRef(entityGridCoords.Offset(direction)); diff --git a/Content.Server/AI/Utility/Actions/Idle/WanderAndWait.cs b/Content.Server/AI/Utility/Actions/Idle/WanderAndWait.cs index 9dbfd0c1f0..6eac412f02 100644 --- a/Content.Server/AI/Utility/Actions/Idle/WanderAndWait.cs +++ b/Content.Server/AI/Utility/Actions/Idle/WanderAndWait.cs @@ -51,10 +51,12 @@ namespace Content.Server.AI.Utility.Actions.Idle }; } - private EntityCoordinates FindRandomGrid(IRobustRandom robustRandom) + private EntityCoordinates FindRandomGrid(IRobustRandom robustRandom, IEntityManager? entMan = null) { + IoCManager.Resolve(ref entMan); + // Very inefficient (should weight each region by its node count) but better than the old system - var reachableSystem = EntitySystem.Get(); + var reachableSystem = entMan.EntitySysManager.GetEntitySystem(); var reachableArgs = ReachableArgs.GetArgs(Owner); var entityRegion = reachableSystem.GetRegion(Owner); var reachableRegions = reachableSystem.GetReachableRegions(reachableArgs, entityRegion); @@ -76,9 +78,11 @@ namespace Content.Server.AI.Utility.Actions.Idle } var targetNode = robustRandom.Pick(reachableNodes); - var mapManager = IoCManager.Resolve(); - var grid = mapManager.GetGrid(IoCManager.Resolve().GetComponent(Owner).GridEntityId); - var targetGrid = grid.GridTileToLocal(targetNode.TileRef.GridIndices); + + if (!entMan.TryGetComponent(entMan.GetComponent(Owner).GridUid, out IMapGridComponent? grid)) + return default; + + var targetGrid = grid.Grid.GridTileToLocal(targetNode.TileRef.GridIndices); return targetGrid; } diff --git a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs index 43f1a6bb26..38dc8736f6 100644 --- a/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs +++ b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs @@ -11,7 +11,7 @@ namespace Content.Server.AI.Utility.Considerations.Movement var entities = IoCManager.Resolve(); if (context.GetState().GetValue() is not {Valid: true} target || entities.Deleted(target) || - entities.GetComponent(target).GridEntityId != entities.GetComponent(self).GridEntityId) + entities.GetComponent(target).GridUid != entities.GetComponent(self).GridUid) { return 0.0f; } diff --git a/Content.Server/AI/Utils/Visibility.cs b/Content.Server/AI/Utils/Visibility.cs index 1fa18ed7ee..7f833efd3a 100644 --- a/Content.Server/AI/Utils/Visibility.cs +++ b/Content.Server/AI/Utils/Visibility.cs @@ -22,7 +22,7 @@ namespace Content.Server.AI.Utils { var transform = entityManager.GetComponent(entity); - if (transform.Coordinates.GetGridEntityId(entityManager) != grid.GetGridEntityId(entityManager)) + if (transform.Coordinates.GetGridUid(entityManager) != grid.GetGridUid(entityManager)) { continue; } diff --git a/Content.Server/AME/AntimatterEngineSystem.cs b/Content.Server/AME/AntimatterEngineSystem.cs index 7ee3aa7a4f..29e1761987 100644 --- a/Content.Server/AME/AntimatterEngineSystem.cs +++ b/Content.Server/AME/AntimatterEngineSystem.cs @@ -90,7 +90,7 @@ namespace Content.Server.AME if (!_toolSystem.HasQuality(args.Used, component.QualityNeeded)) return; - if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridEntityId(EntityManager), out var mapGrid)) + if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridUid(EntityManager), out var mapGrid)) return; // No AME in space. var snapPos = mapGrid.TileIndicesFor(args.ClickLocation); diff --git a/Content.Server/Administration/Commands/WarpCommand.cs b/Content.Server/Administration/Commands/WarpCommand.cs index 5d2d02725b..49d62e2e4a 100644 --- a/Content.Server/Administration/Commands/WarpCommand.cs +++ b/Content.Server/Administration/Commands/WarpCommand.cs @@ -52,7 +52,7 @@ namespace Content.Server.Administration.Commands var mapManager = IoCManager.Resolve(); var currentMap = entMan.GetComponent(playerEntity).MapID; - var currentGrid = entMan.GetComponent(playerEntity).GridEntityId; + var currentGrid = entMan.GetComponent(playerEntity).GridUid; var found = entMan.EntityQuery(true) .Where(p => p.Location == location) @@ -62,8 +62,8 @@ namespace Content.Server.Administration.Commands // Sort so that warp points on the same grid/map are first. // So if you have two maps loaded with the same warp points, // it will prefer the warp points on the map you're currently on. - var aGrid = a.GetGridEntityId(entMan); - var bGrid = b.GetGridEntityId(entMan); + var aGrid = a.GetGridUid(entMan); + var bGrid = b.GetGridUid(entMan); if (aGrid == bGrid) { @@ -102,7 +102,7 @@ namespace Content.Server.Administration.Commands })) .FirstOrDefault(); - var entityUid = found.GetGridEntityId(entMan); + var entityUid = found.GetGridUid(entMan); if (entityUid != EntityUid.Invalid) { entMan.GetComponent(playerEntity).Coordinates = found; diff --git a/Content.Server/Atmos/Commands/DeleteGasCommand.cs b/Content.Server/Atmos/Commands/DeleteGasCommand.cs index 4678a86fc6..01c6a81639 100644 --- a/Content.Server/Atmos/Commands/DeleteGasCommand.cs +++ b/Content.Server/Atmos/Commands/DeleteGasCommand.cs @@ -18,7 +18,7 @@ namespace Content.Server.Atmos.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { var player = shell.Player as IPlayerSession; - EntityUid gridId; + EntityUid? gridId; Gas? gas = null; var entMan = IoCManager.Resolve(); @@ -39,9 +39,9 @@ namespace Content.Server.Atmos.Commands return; } - gridId = entMan.GetComponent(playerEntity).GridEntityId; + gridId = entMan.GetComponent(playerEntity).GridUid; - if (gridId == EntityUid.Invalid) + if (gridId == null) { shell.WriteLine("You aren't on a grid to delete gas from."); return; @@ -66,9 +66,9 @@ namespace Content.Server.Atmos.Commands return; } - gridId = entMan.GetComponent(playerEntity).GridEntityId; + gridId = entMan.GetComponent(playerEntity).GridUid; - if (gridId == EntityUid.Invalid) + if (gridId == null) { shell.WriteLine("You aren't on a grid to delete gas from."); return; @@ -98,7 +98,7 @@ namespace Content.Server.Atmos.Commands gridId = first; - if (gridId == EntityUid.Invalid) + if (gridId.Value.IsValid()) { shell.WriteLine($"{gridId} is not a valid grid id."); return; @@ -134,7 +134,7 @@ namespace Content.Server.Atmos.Commands if (gas == null) { - foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId, true)) + foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId.Value, true)) { if (tile.Immutable) continue; @@ -146,7 +146,7 @@ namespace Content.Server.Atmos.Commands } else { - foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId, true)) + foreach (var tile in atmosphereSystem.GetAllTileMixtures(gridId.Value, true)) { if (tile.Immutable) continue; diff --git a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs index 7fd0078416..f2190d2305 100644 --- a/Content.Server/Atmos/EntitySystems/AirtightSystem.cs +++ b/Content.Server/Atmos/EntitySystems/AirtightSystem.cs @@ -44,7 +44,7 @@ namespace Content.Server.Atmos.EntitySystems var xform = Transform(uid); // If the grid is deleting no point updating atmos. - if (_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (_mapManager.TryGetGrid(xform.GridUid, out var grid)) { if (MetaData(grid.GridEntityId).EntityLifeStage > EntityLifeStage.MapInitialized) return; } @@ -56,15 +56,17 @@ namespace Content.Server.Atmos.EntitySystems { var xform = Transform(uid); - var gridId = xform.GridEntityId; + if (!TryComp(xform.GridUid, out IMapGridComponent? grid)) + return; + + var gridId = xform.GridUid; var coords = xform.Coordinates; - var grid = _mapManager.GetGrid(gridId); - var tilePos = grid.TileIndicesFor(coords); + var tilePos = grid.Grid.TileIndicesFor(coords); // Update and invalidate new position. - airtight.LastPosition = (gridId, tilePos); - InvalidatePosition(gridId, tilePos); + airtight.LastPosition = (gridId.Value, tilePos); + InvalidatePosition(gridId.Value, tilePos); } private void OnAirtightReAnchor(EntityUid uid, AirtightComponent airtight, ref ReAnchorEvent args) @@ -100,11 +102,10 @@ namespace Content.Server.Atmos.EntitySystems { if (!Resolve(airtight.Owner, ref xform)) return; - if (!xform.Anchored || !xform.GridEntityId.IsValid()) + if (!xform.Anchored || !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; - var grid = _mapManager.GetGrid(xform.GridEntityId); - airtight.LastPosition = (xform.GridEntityId, grid.TileIndicesFor(xform.Coordinates)); + airtight.LastPosition = (xform.GridUid.Value, grid.TileIndicesFor(xform.Coordinates)); InvalidatePosition(airtight.LastPosition.Item1, airtight.LastPosition.Item2, airtight.FixVacuum && !airtight.AirBlocked); } diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Grid.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Grid.cs index 0dc23e8a13..f2aef8d9bc 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Grid.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.Grid.cs @@ -125,7 +125,7 @@ namespace Content.Server.Atmos.EntitySystems /// /// Grid to be checked. /// Whether the grid has a simulated atmosphere. - public bool IsSimulatedGrid(EntityUid grid) + public bool IsSimulatedGrid(EntityUid? grid) { if (!_mapManager.TryGetGrid(grid, out var mapGrid)) return false; @@ -1376,7 +1376,7 @@ namespace Content.Server.Atmos.EntitySystems public bool AddAtmosDevice(AtmosDeviceComponent atmosDevice) { - var grid = Comp(atmosDevice.Owner).GridEntityId; + var grid = Comp(atmosDevice.Owner).GridUid; if (!_mapManager.TryGetGrid(grid, out var mapGrid)) return false; @@ -1578,7 +1578,7 @@ namespace Content.Server.Atmos.EntitySystems return false; } - var gridId = coordinates.GetGridEntityId(EntityManager); + var gridId = coordinates.GetGridUid(EntityManager); if (!_mapManager.TryGetGrid(gridId, out var grid)) { @@ -1586,7 +1586,7 @@ namespace Content.Server.Atmos.EntitySystems return false; } - tuple = (gridId, grid.TileIndicesFor(coordinates)); + tuple = (gridId.Value, grid.TileIndicesFor(coordinates)); return true; } diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs index 03cc055da0..1ce6ee0002 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs @@ -161,7 +161,6 @@ namespace Content.Server.Atmos.EntitySystems xforms.GetComponent(entity), body); } - } } diff --git a/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeAppearanceSystem.cs b/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeAppearanceSystem.cs index 0bcce94996..824683e380 100644 --- a/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeAppearanceSystem.cs +++ b/Content.Server/Atmos/Piping/EntitySystems/AtmosPipeAppearanceSystem.cs @@ -29,7 +29,7 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem if (!Resolve(uid, ref appearance, ref container, ref xform, false)) return; - if (!_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; // get connected entities diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasPortableSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasPortableSystem.cs index d2e45051b8..b46dfa213c 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasPortableSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasPortableSystem.cs @@ -30,7 +30,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems return; // If we can't find any ports, cancel the anchoring. - if(!FindGasPortIn(transform.GridEntityId, transform.Coordinates, out _)) + if(!FindGasPortIn(transform.GridUid, transform.Coordinates, out _)) args.Cancel(); } @@ -50,15 +50,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems } } - private bool FindGasPortIn(EntityUid gridId, EntityCoordinates coordinates, [NotNullWhen(true)] out GasPortComponent? port) + private bool FindGasPortIn(EntityUid? gridId, EntityCoordinates coordinates, [NotNullWhen(true)] out GasPortComponent? port) { port = null; - if (!gridId.IsValid()) + if (!_mapManager.TryGetGrid(gridId, out var grid)) return false; - var grid = _mapManager.GetGrid(gridId); - foreach (var entityUid in grid.GetLocal(coordinates)) { if (EntityManager.TryGetComponent(entityUid, out port)) diff --git a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs index 7fd670a2b0..ab231d5418 100644 --- a/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionAreaEffectComponent.cs @@ -69,7 +69,11 @@ namespace Content.Server.Chemistry.Components var xform = _entities.GetComponent(Owner); var solSys = _systems.GetEntitySystem(); - var grid = MapManager.GetGrid(xform.GridEntityId); + + if (!_entities.TryGetComponent(xform.GridUid, out IMapGridComponent? gridComp)) + return; + + var grid = gridComp.Grid; var origin = grid.TileIndicesFor(xform.Coordinates); DebugTools.Assert(xform.Anchored, "Area effect entity prototypes must be anchored."); @@ -141,14 +145,17 @@ namespace Content.Server.Chemistry.Components /// with the other area effects from the inception. public void React(float averageExposures) { - if (!EntitySystem.Get().TryGetSolution(Owner, SolutionName, out var solution)) + + if (!_entities.EntitySysManager.GetEntitySystem().TryGetSolution(Owner, SolutionName, out var solution)) return; - var chemistry = EntitySystem.Get(); var xform = _entities.GetComponent(Owner); - var mapGrid = MapManager.GetGrid(xform.GridEntityId); + if (!MapManager.TryGetGrid(xform.GridUid, out var mapGrid)) + return; + var tile = mapGrid.GetTileRef(xform.Coordinates.ToVector2i(_entities, MapManager)); - var lookup = EntitySystem.Get(); + var chemistry = _entities.EntitySysManager.GetEntitySystem(); + var lookup = _entities.EntitySysManager.GetEntitySystem(); var solutionFraction = 1 / Math.Floor(averageExposures); diff --git a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs index f4faec5764..c217c647e2 100644 --- a/Content.Server/Chemistry/EntitySystems/VaporSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/VaporSystem.cs @@ -90,16 +90,17 @@ namespace Content.Server.Chemistry.EntitySystems return; var entity = vapor.Owner; + var xform = Transform(entity); vapor.Timer += frameTime; vapor.ReactTimer += frameTime; - if (vapor.ReactTimer >= ReactTime && EntityManager.GetComponent(vapor.Owner).GridEntityId.IsValid()) + if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out IMapGridComponent? gridComp)) { vapor.ReactTimer = 0; - var mapGrid = _mapManager.GetGrid(EntityManager.GetComponent(entity).GridEntityId); - var tile = mapGrid.GetTileRef(EntityManager.GetComponent(entity).Coordinates.ToVector2i(EntityManager, _mapManager)); + + var tile = gridComp.Grid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager)); foreach (var reagentQuantity in contents.Contents.ToArray()) { if (reagentQuantity.Quantity == FixedPoint2.Zero) continue; @@ -111,7 +112,7 @@ namespace Content.Server.Chemistry.EntitySystems // Check if we've reached our target. if (!vapor.Reached && - vapor.Target.TryDistance(EntityManager, EntityManager.GetComponent(entity).Coordinates, out var distance) && + vapor.Target.TryDistance(EntityManager, xform.Coordinates, out var distance) && distance <= 0.5f) { vapor.Reached = true; diff --git a/Content.Server/Construction/Commands/FixRotationsCommand.cs b/Content.Server/Construction/Commands/FixRotationsCommand.cs index dceda7d23a..1bacaf3f8f 100644 --- a/Content.Server/Construction/Commands/FixRotationsCommand.cs +++ b/Content.Server/Construction/Commands/FixRotationsCommand.cs @@ -21,7 +21,7 @@ namespace Content.Server.Construction.Commands { var player = shell.Player as IPlayerSession; var entityManager = IoCManager.Resolve(); - EntityUid gridId; + EntityUid? gridId; var xformQuery = entityManager.GetEntityQuery(); switch (args.Length) @@ -33,7 +33,7 @@ namespace Content.Server.Construction.Commands return; } - gridId = xformQuery.GetComponent(playerEntity).GridEntityId; + gridId = xformQuery.GetComponent(playerEntity).GridUid; break; case 1: if (!EntityUid.TryParse(args[0], out var id)) diff --git a/Content.Server/Construction/Commands/TileReplaceCommand.cs b/Content.Server/Construction/Commands/TileReplaceCommand.cs index 6995475fc4..82d27f10e3 100644 --- a/Content.Server/Construction/Commands/TileReplaceCommand.cs +++ b/Content.Server/Construction/Commands/TileReplaceCommand.cs @@ -21,7 +21,7 @@ sealed class TileReplaceCommand : IConsoleCommand { var player = shell.Player as IPlayerSession; var entityManager = IoCManager.Resolve(); - EntityUid gridId; + EntityUid? gridId; string tileIdA = ""; string tileIdB = ""; @@ -34,7 +34,7 @@ sealed class TileReplaceCommand : IConsoleCommand return; } - gridId = entityManager.GetComponent(playerEntity).GridEntityId; + gridId = entityManager.GetComponent(playerEntity).GridUid; tileIdA = args[0]; tileIdB = args[1]; break; diff --git a/Content.Server/Construction/Commands/TileWallsCommand.cs b/Content.Server/Construction/Commands/TileWallsCommand.cs index 57a23aa569..06ef40d24c 100644 --- a/Content.Server/Construction/Commands/TileWallsCommand.cs +++ b/Content.Server/Construction/Commands/TileWallsCommand.cs @@ -24,7 +24,7 @@ namespace Content.Server.Construction.Commands { var player = shell.Player as IPlayerSession; var entityManager = IoCManager.Resolve(); - EntityUid gridId; + EntityUid? gridId; switch (args.Length) { @@ -35,7 +35,7 @@ namespace Content.Server.Construction.Commands return; } - gridId = entityManager.GetComponent(playerEntity).GridEntityId; + gridId = entityManager.GetComponent(playerEntity).GridUid; break; case 1: if (!EntityUid.TryParse(args[0], out var id)) diff --git a/Content.Server/Construction/Conditions/ComponentInTile.cs b/Content.Server/Construction/Conditions/ComponentInTile.cs index 3b4010f69f..5479c33081 100644 --- a/Content.Server/Construction/Conditions/ComponentInTile.cs +++ b/Content.Server/Construction/Conditions/ComponentInTile.cs @@ -43,8 +43,11 @@ namespace Content.Server.Construction.Conditions var type = IoCManager.Resolve().GetRegistration(Component).Type; var transform = entityManager.GetComponent(uid); + if (transform.GridUid == null) + return false; + var indices = transform.Coordinates.ToVector2i(entityManager, IoCManager.Resolve()); - var entities = indices.GetEntitiesInTile(transform.GridEntityId, LookupFlags.Approximate | LookupFlags.Anchored, EntitySystem.Get()); + var entities = indices.GetEntitiesInTile(transform.GridUid.Value, LookupFlags.Approximate | LookupFlags.Anchored, EntitySystem.Get()); foreach (var ent in entities) { diff --git a/Content.Server/Coordinates/Helpers/SnapgridHelper.cs b/Content.Server/Coordinates/Helpers/SnapgridHelper.cs index 520af9ba20..7790794d9f 100644 --- a/Content.Server/Coordinates/Helpers/SnapgridHelper.cs +++ b/Content.Server/Coordinates/Helpers/SnapgridHelper.cs @@ -15,7 +15,7 @@ namespace Content.Server.Coordinates.Helpers { IoCManager.Resolve(ref entMan, ref mapManager); - var gridId = coordinates.GetGridEntityId(entMan); + var gridId = coordinates.GetGridId(entMan); var tileSize = 1f; diff --git a/Content.Server/Decals/DecalSystem.cs b/Content.Server/Decals/DecalSystem.cs index b0b9b8d61a..a6d27172ff 100644 --- a/Content.Server/Decals/DecalSystem.cs +++ b/Content.Server/Decals/DecalSystem.cs @@ -168,16 +168,16 @@ namespace Content.Server.Decals if (!ev.Coordinates.IsValid(EntityManager)) return; - var gridId = ev.Coordinates.GetGridEntityId(EntityManager); + var gridId = ev.Coordinates.GetGridUid(EntityManager); - if (!gridId.IsValid()) + if (gridId == null) return; // remove all decals on the same tile - foreach (var (uid, decal) in GetDecalsInRange(gridId, ev.Coordinates.Position)) + foreach (var (uid, decal) in GetDecalsInRange(gridId.Value, ev.Coordinates.Position)) { var chunkIndices = GetChunkIndices(decal.Coordinates); - RemoveDecal(gridId, uid); + RemoveDecal(gridId.Value, uid); } } @@ -205,21 +205,21 @@ namespace Content.Server.Decals if (!PrototypeManager.HasIndex(decal.Id)) return false; - var gridId = coordinates.GetGridEntityId(EntityManager); + var gridId = coordinates.GetGridUid(EntityManager); if (!MapManager.TryGetGrid(gridId, out var grid)) return false; if (grid.GetTileRef(coordinates).IsSpace(_tileDefMan)) return false; - var chunkCollection = DecalGridChunkCollection(gridId); + var chunkCollection = DecalGridChunkCollection(gridId.Value); uid = chunkCollection.NextUid++; var chunkIndices = GetChunkIndices(decal.Coordinates); if(!chunkCollection.ChunkCollection.ContainsKey(chunkIndices)) chunkCollection.ChunkCollection[chunkIndices] = new(); chunkCollection.ChunkCollection[chunkIndices][uid.Value] = decal; - ChunkIndex[gridId][uid.Value] = chunkIndices; - DirtyChunk(gridId, chunkIndices); + ChunkIndex[gridId.Value][uid.Value] = chunkIndices; + DirtyChunk(gridId.Value, chunkIndices); return true; } @@ -250,7 +250,11 @@ namespace Content.Server.Decals public bool SetDecalPosition(EntityUid gridId, uint uid, EntityCoordinates coordinates) { - return SetDecalPosition(gridId, uid, coordinates.GetGridEntityId(EntityManager), coordinates.Position); + var newGridId = coordinates.GetGridUid(EntityManager); + if (newGridId == null) + return false; + + return SetDecalPosition(gridId, uid, newGridId.Value, coordinates.Position); } public bool SetDecalPosition(EntityUid gridId, uint uid, EntityUid newGridId, Vector2 position) diff --git a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs index 15e127717c..384e701d24 100644 --- a/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/WiredNetworkSystem.cs @@ -17,7 +17,7 @@ namespace Content.Server.DeviceNetwork.Systems /// private void OnBeforePacketSent(EntityUid uid, WiredNetworkComponent component, BeforePacketSentEvent args) { - if (EntityManager.GetComponent(uid).GridEntityId != args.SenderTransform.GridEntityId) + if (EntityManager.GetComponent(uid).GridUid != args.SenderTransform.GridUid) { args.Cancel(); } diff --git a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs index 57f1b84ef9..eedea8fa55 100644 --- a/Content.Server/Disposal/Tube/DisposalTubeSystem.cs +++ b/Content.Server/Disposal/Tube/DisposalTubeSystem.cs @@ -125,8 +125,11 @@ namespace Content.Server.Disposal.Tube return null; var oppositeDirection = nextDirection.GetOpposite(); - var grid = _mapManager.GetGrid(EntityManager.GetComponent(targetTube.Owner).GridEntityId); - var position = EntityManager.GetComponent(targetTube.Owner).Coordinates; + var xform = Transform(targetTube.Owner); + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) + return null; + + var position = xform.Coordinates; foreach (var entity in grid.GetInDir(position, nextDirection)) { if (!EntityManager.TryGetComponent(entity, out IDisposalTubeComponent? tube)) diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs index 9ee06d17cd..0f95229679 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposableSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems // *This is on purpose.* DisposalUnitComponent? duc = null; - if (_mapManager.TryGetGrid(holderTransform.GridEntityId, out var grid)) + if (_mapManager.TryGetGrid(holderTransform.GridUid, out var grid)) { foreach (var contentUid in grid.GetLocal(holderTransform.Coordinates)) { diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index edcfd16b3d..4636a79693 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -477,9 +477,12 @@ namespace Content.Server.Disposal.Unit.EntitySystems return false; } - var grid = _mapManager.GetGrid(EntityManager.GetComponent(component.Owner).GridEntityId); - var coords = EntityManager.GetComponent(component.Owner).Coordinates; - var entry = grid.GetLocal(coords) + var xform = Transform(component.Owner); + if (!TryComp(xform.GridUid, out IMapGridComponent? grid)) + return false; + + var coords = xform.Coordinates; + var entry = grid.Grid.GetLocal(coords) .FirstOrDefault(entity => EntityManager.HasComponent(entity)); if (entry == default) @@ -490,7 +493,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems var air = component.Air; var entryComponent = EntityManager.GetComponent(entry); - if (_atmosSystem.GetTileMixture(EntityManager.GetComponent(component.Owner).Coordinates, true) is {Temperature: > 0} environment) + if (_atmosSystem.GetTileMixture(xform.Coordinates, true) is {Temperature: > 0} environment) { var transferMoles = 0.1f * (0.25f * Atmospherics.OneAtmosphere * 1.01f - air.Pressure) * air.Volume / (environment.Temperature * Atmospherics.R); diff --git a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs index 6c7b5f1cd5..e5dc1c13f4 100644 --- a/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs +++ b/Content.Server/Engineering/EntitySystems/SpawnAfterInteractSystem.cs @@ -30,7 +30,7 @@ namespace Content.Server.Engineering.EntitySystems return; if (string.IsNullOrEmpty(component.Prototype)) return; - if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridEntityId(EntityManager), out var grid)) + if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridUid(EntityManager), out var grid)) return; if (!grid.TryGetTileRef(args.ClickLocation, out var tileRef)) return; diff --git a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Airtight.cs b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Airtight.cs index 2df8362762..a69a36002e 100644 --- a/Content.Server/Explosion/EntitySystems/ExplosionSystem.Airtight.cs +++ b/Content.Server/Explosion/EntitySystems/ExplosionSystem.Airtight.cs @@ -100,7 +100,7 @@ public sealed partial class ExplosionSystem : EntitySystem if (!EntityManager.TryGetComponent(uid, out TransformComponent? transform) || !transform.Anchored) return; - if (!_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) return; UpdateAirtightMap(grid, grid.CoordinatesToTile(transform.Coordinates)); diff --git a/Content.Server/Fluids/EntitySystems/FluidSpreaderSystem.cs b/Content.Server/Fluids/EntitySystems/FluidSpreaderSystem.cs index 5f3ca56753..681cb78de6 100644 --- a/Content.Server/Fluids/EntitySystems/FluidSpreaderSystem.cs +++ b/Content.Server/Fluids/EntitySystems/FluidSpreaderSystem.cs @@ -103,7 +103,7 @@ public sealed class FluidSpreaderSystem : EntitySystem var prototypeName = metadataOriginal.EntityPrototype!.ID; var visitedTiles = new HashSet(); - if (!_mapManager.TryGetGrid(transformOrig.GridEntityId, out var mapGrid)) + if (!_mapManager.TryGetGrid(transformOrig.GridUid, out var mapGrid)) return; // skip origin puddle diff --git a/Content.Server/Fluids/EntitySystems/MoppingSystem.cs b/Content.Server/Fluids/EntitySystems/MoppingSystem.cs index 2e15f827a9..56f3dfb79a 100644 --- a/Content.Server/Fluids/EntitySystems/MoppingSystem.cs +++ b/Content.Server/Fluids/EntitySystems/MoppingSystem.cs @@ -76,7 +76,7 @@ public sealed class MoppingSystem : EntitySystem private void ReleaseToFloor(EntityCoordinates clickLocation, AbsorbentComponent absorbent, Solution? absorbedSolution) { - if ((_mapManager.TryGetGrid(clickLocation.GetGridEntityId(EntityManager), out var mapGrid)) // needs valid grid + if ((_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid)) // needs valid grid && absorbedSolution is not null) // needs a solution to place on the tile { TileRef tile = mapGrid.GetTileRef(clickLocation); diff --git a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs index 76e5082990..487b6aa98c 100644 --- a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs @@ -132,7 +132,7 @@ public sealed class SpillableSystem : EntitySystem if (solution.TotalVolume == 0) return null; - if (!_mapManager.TryGetGrid(coordinates.GetGridEntityId(EntityManager), out var mapGrid)) + if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid)) return null; // Let's not spill to space. return SpillAt(mapGrid.GetTileRef(coordinates), solution, prototype, overflow, sound, diff --git a/Content.Server/Fluids/EntitySystems/SpraySystem.cs b/Content.Server/Fluids/EntitySystems/SpraySystem.cs index cc786bc186..cd2024a8de 100644 --- a/Content.Server/Fluids/EntitySystems/SpraySystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpraySystem.cs @@ -59,7 +59,7 @@ public sealed class SpraySystem : EntitySystem var playerPos = Transform(args.User).Coordinates; - if (args.ClickLocation.GetGridEntityId(EntityManager) != playerPos.GetGridEntityId(EntityManager)) + if (args.ClickLocation.GetGridUid(EntityManager) != playerPos.GetGridUid(EntityManager)) return; var direction = (args.ClickLocation.Position - playerPos.Position).Normalized; diff --git a/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs b/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs index 4eb8caa909..8c9832ae62 100644 --- a/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs +++ b/Content.Server/Gravity/EntitySystems/GravityGeneratorSystem.cs @@ -187,12 +187,11 @@ namespace Content.Server.Gravity.EntitySystems private void UpdateGravityActive(GravityGeneratorComponent grav, bool shake) { - var gridId = EntityManager.GetComponent(grav.Owner).GridEntityId; - if (gridId == EntityUid.Invalid) + var gridId = EntityManager.GetComponent(grav.Owner).GridUid; + if (!_mapManager.TryGetGrid(gridId, out var grid)) return; - var grid = _mapManager.GetGrid(gridId); - var gravity = EntityManager.GetComponent(grid.GridEntityId); + var gravity = EntityManager.GetComponent(gridId.Value); if (grav.GravityActive) _gravitySystem.EnableGravity(gravity); @@ -200,7 +199,7 @@ namespace Content.Server.Gravity.EntitySystems _gravitySystem.DisableGravity(gravity); if (shake) - _gravityShakeSystem.ShakeGrid(gridId, gravity); + _gravityShakeSystem.ShakeGrid(gridId.Value, gravity); } private void OnInteractHand(EntityUid uid, GravityGeneratorComponent component, InteractHandEvent args) diff --git a/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs b/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs index cd03ff714f..d867ab2050 100644 --- a/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs +++ b/Content.Server/Gravity/EntitySystems/GravityShakeSystem.cs @@ -76,7 +76,7 @@ namespace Content.Server.Gravity.EntitySystems foreach (var player in _playerManager.Sessions) { if (player.AttachedEntity is not {Valid: true} attached - || EntityManager.GetComponent(attached).GridEntityId != gridId + || EntityManager.GetComponent(attached).GridUid != gridId || !EntityManager.HasComponent(attached)) { continue; diff --git a/Content.Server/Gravity/EntitySystems/GravitySystem.cs b/Content.Server/Gravity/EntitySystems/GravitySystem.cs index c1d9e6f604..786b09e69b 100644 --- a/Content.Server/Gravity/EntitySystems/GravitySystem.cs +++ b/Content.Server/Gravity/EntitySystems/GravitySystem.cs @@ -16,22 +16,26 @@ namespace Content.Server.Gravity.EntitySystems private void HandleGravityInitialize(EntityUid uid, GravityComponent component, ComponentInit args) { // Incase there's already a generator on the grid we'll just set it now. - var gridId = EntityManager.GetComponent(component.Owner).GridEntityId; + var gridId = Transform(component.Owner).GridUid; + + if (gridId == null) + return; + GravityChangedMessage message; foreach (var generator in EntityManager.EntityQuery()) { - if (EntityManager.GetComponent(generator.Owner).GridEntityId == gridId && generator.GravityActive) + if (Transform(generator.Owner).GridUid == gridId && generator.GravityActive) { component.Enabled = true; - message = new GravityChangedMessage(gridId, true); + message = new GravityChangedMessage(gridId.Value, true); RaiseLocalEvent(message); return; } } component.Enabled = false; - message = new GravityChangedMessage(gridId, false); + message = new GravityChangedMessage(gridId.Value, false); RaiseLocalEvent(message); } @@ -43,10 +47,13 @@ namespace Content.Server.Gravity.EntitySystems public void EnableGravity(GravityComponent comp) { if (comp.Enabled) return; - comp.Enabled = true; - var gridId = EntityManager.GetComponent(comp.Owner).GridEntityId; - var message = new GravityChangedMessage(gridId, true); + var gridId = Transform(comp.Owner).GridUid; + if (gridId == null) + return; + + comp.Enabled = true; + var message = new GravityChangedMessage(gridId.Value, true); RaiseLocalEvent(message); } @@ -55,8 +62,11 @@ namespace Content.Server.Gravity.EntitySystems if (!comp.Enabled) return; comp.Enabled = false; - var gridId = EntityManager.GetComponent(comp.Owner).GridEntityId; - var message = new GravityChangedMessage(gridId, false); + var gridId = Transform(comp.Owner).GridUid; + if (gridId == null) + return; + + var message = new GravityChangedMessage(gridId.Value, false); RaiseLocalEvent(message); } } diff --git a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs index eae135be62..7d7e549cba 100644 --- a/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs +++ b/Content.Server/Gravity/EntitySystems/WeightlessSystem.cs @@ -34,11 +34,11 @@ namespace Content.Server.Gravity.EntitySystems public void AddAlert(AlertsComponent status) { var xform = Transform(status.Owner); - var alerts = _alerts.GetOrNew(xform.GridEntityId); + var alerts = _alerts.GetOrNew(xform.GridID); alerts.Add(status); - if (_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (_mapManager.TryGetGrid(xform.GridUid, out var grid)) { if (EntityManager.GetComponent(grid.GridEntityId).Enabled) { @@ -53,7 +53,7 @@ namespace Content.Server.Gravity.EntitySystems public void RemoveAlert(AlertsComponent status) { - var grid = EntityManager.GetComponent(status.Owner).GridEntityId; + var grid = EntityManager.GetComponent(status.Owner).GridID; if (!_alerts.TryGetValue(grid, out var statuses)) { return; @@ -109,7 +109,10 @@ namespace Content.Server.Gravity.EntitySystems } } - var newGrid = ev.Transform.GridEntityId; + if (ev.Transform.MapID == MapId.Nullspace) + return; + + var newGrid = ev.Transform.GridID; var newStatuses = _alerts.GetOrNew(newGrid); newStatuses.Add(status); diff --git a/Content.Server/Interaction/TilePryCommand.cs b/Content.Server/Interaction/TilePryCommand.cs index 186c1bdadd..77072ff4a6 100644 --- a/Content.Server/Interaction/TilePryCommand.cs +++ b/Content.Server/Interaction/TilePryCommand.cs @@ -47,9 +47,13 @@ namespace Content.Server.Interaction } var mapManager = IoCManager.Resolve(); - var playerGrid = _entities.GetComponent(attached).GridEntityId; - var mapGrid = mapManager.GetGrid(playerGrid); - var playerPosition = _entities.GetComponent(attached).Coordinates; + var xform = _entities.GetComponent(attached); + var playerGrid = xform.GridUid; + + if (!mapManager.TryGetGrid(playerGrid, out var mapGrid)) + return; + + var playerPosition = xform.Coordinates; var tileDefinitionManager = IoCManager.Resolve(); for (var i = -radius; i <= radius; i++) diff --git a/Content.Server/Kudzu/SpreaderSystem.cs b/Content.Server/Kudzu/SpreaderSystem.cs index 786db00cec..38faff41c7 100644 --- a/Content.Server/Kudzu/SpreaderSystem.cs +++ b/Content.Server/Kudzu/SpreaderSystem.cs @@ -44,7 +44,7 @@ public sealed class SpreaderSystem : EntitySystem if (!EntityManager.TryGetComponent(blocker, out var transform)) return; // how did we get here? - if (!_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) return; + if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) return; for (var i = 0; i < Atmospherics.Directions; i++) { @@ -89,7 +89,7 @@ public sealed class SpreaderSystem : EntitySystem if (spreader.Enabled == false) return false; - if (!_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) return false; + if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) return false; var didGrow = false; diff --git a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs index 4ae9df6836..7c80d3e8ef 100644 --- a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs +++ b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs @@ -77,7 +77,7 @@ namespace Content.Server.Medical.CrewMonitoring // should work well enough? if (TryComp(uid, out IMoverComponent? mover)) worldRot = mover.LastGridAngle; - else if (_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + else if (_mapManager.TryGetGrid(xform.GridUid, out var grid)) worldRot = grid.WorldRotation; // update all sensors info diff --git a/Content.Server/Mind/MindSystem.cs b/Content.Server/Mind/MindSystem.cs index f2f3fcbed1..400aaf14c3 100644 --- a/Content.Server/Mind/MindSystem.cs +++ b/Content.Server/Mind/MindSystem.cs @@ -90,7 +90,7 @@ public sealed class MindSystem : EntitySystem return; // Async this so that we don't throw if the grid we're on is being deleted. - var gridId = spawnPosition.GetGridEntityId(EntityManager); + var gridId = spawnPosition.GetGridUid(EntityManager); if (!spawnPosition.IsValid(EntityManager) || gridId == EntityUid.Invalid || !_mapManager.GridExists(gridId)) { spawnPosition = _gameTicker.GetObserverSpawnPoint(); diff --git a/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs b/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs index ec3c431aa0..ff0fa20810 100644 --- a/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs +++ b/Content.Server/NodeContainer/EntitySystems/NodeGroupSystem.cs @@ -286,7 +286,7 @@ namespace Content.Server.NodeContainer.EntitySystems private BaseNodeGroup InitGroup(Node node, List groupNodes) { var newGroup = (BaseNodeGroup) _nodeGroupFactory.MakeNodeGroup(node.NodeGroupID); - newGroup.Initialize(node); + newGroup.Initialize(node, EntityManager); newGroup.NetId = _groupNetIdCounter++; var netIdCounter = 0; @@ -335,7 +335,7 @@ namespace Content.Server.NodeContainer.EntitySystems private IEnumerable GetCompatibleNodes(Node node, EntityQuery xformQuery, EntityQuery nodeQuery) { var xform = xformQuery.GetComponent(node.Owner); - _mapManager.TryGetGrid(xform.GridEntityId, out var grid); + _mapManager.TryGetGrid(xform.GridUid, out var grid); if (!node.Connectable(EntityManager, xform)) yield break; diff --git a/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs b/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs index 076dae9a00..cc95bf0eaf 100644 --- a/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs +++ b/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs @@ -1,6 +1,7 @@ using System.Linq; using Content.Server.NodeContainer.Nodes; using Robust.Shared.Map; +using Robust.Shared.Utility; namespace Content.Server.NodeContainer.NodeGroups { @@ -19,7 +20,7 @@ namespace Content.Server.NodeContainer.NodeGroups void Create(NodeGroupID groupId); - void Initialize(Node sourceNode); + void Initialize(Node sourceNode, IEntityManager? entMan = null); void RemoveNode(Node node); @@ -72,10 +73,14 @@ namespace Content.Server.NodeContainer.NodeGroups GroupId = groupId; } - public virtual void Initialize(Node sourceNode) + public virtual void Initialize(Node sourceNode, IEntityManager? entMan = null) { // TODO: Can we get rid of this GridId? - GridId = IoCManager.Resolve().GetComponent(sourceNode.Owner).GridEntityId; + IoCManager.Resolve(ref entMan); + + var xform = entMan.GetComponent(sourceNode.Owner); + DebugTools.AssertNotNull(xform.GridUid); + GridId = xform.GridUid!.Value; } /// diff --git a/Content.Server/NodeContainer/NodeGroups/PipeNet.cs b/Content.Server/NodeContainer/NodeGroups/PipeNet.cs index 4931923240..3be3c73205 100644 --- a/Content.Server/NodeContainer/NodeGroups/PipeNet.cs +++ b/Content.Server/NodeContainer/NodeGroups/PipeNet.cs @@ -24,9 +24,9 @@ namespace Content.Server.NodeContainer.NodeGroups public EntityUid Grid => GridId; - public override void Initialize(Node sourceNode) + public override void Initialize(Node sourceNode, IEntityManager? entMan = null) { - base.Initialize(sourceNode); + base.Initialize(sourceNode, entMan); _atmosphereSystem = EntitySystem.Get(); _atmosphereSystem.AddPipeNet(this); diff --git a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs index bfbff3fe11..b8d51a5363 100644 --- a/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs +++ b/Content.Server/ParticleAccelerator/Components/ParticleAcceleratorControlBoxComponent.cs @@ -329,7 +329,7 @@ namespace Content.Server.ParticleAccelerator.Components // Find fuel chamber first by scanning cardinals. if (_entMan.GetComponent(Owner).Anchored) { - var grid = _mapManager.GetGrid(_entMan.GetComponent(Owner).GridEntityId); + var grid = _mapManager.GetGrid(_entMan.GetComponent(Owner).GridUid!.Value); var coords = _entMan.GetComponent(Owner).Coordinates; foreach (var maybeFuel in grid.GetCardinalNeighborCells(coords)) { @@ -403,8 +403,14 @@ namespace Content.Server.ParticleAccelerator.Components private bool ScanPart(Vector2i offset, [NotNullWhen(true)] out T? part) where T : ParticleAcceleratorPartComponent { - var grid = _mapManager.GetGrid(_entMan.GetComponent(Owner).GridEntityId); - var coords = _entMan.GetComponent(Owner).Coordinates; + var xform = _entMan.GetComponent(Owner); + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) + { + part = default; + return false; + } + + var coords = xform.Coordinates; foreach (var ent in grid.GetOffset(coords, offset)) { if (_entMan.TryGetComponent(ent, out part) && !part.Deleted) diff --git a/Content.Server/Physics/Controllers/ConveyorController.cs b/Content.Server/Physics/Controllers/ConveyorController.cs index 29374f010d..38d89914ec 100644 --- a/Content.Server/Physics/Controllers/ConveyorController.cs +++ b/Content.Server/Physics/Controllers/ConveyorController.cs @@ -104,7 +104,7 @@ namespace Content.Server.Physics.Controllers public IEnumerable<(EntityUid, TransformComponent)> GetEntitiesToMove(ConveyorComponent comp, TransformComponent xform) { - if (!_mapManager.TryGetGrid(xform.GridEntityId, out var grid) || + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid) || !grid.TryGetTileRef(xform.Coordinates, out var tile)) yield break; var tileAABB = _lookup.GetLocalBounds(tile, grid.TileSize).Enlarged(0.01f); diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index 208534dcdd..4b2c7c6212 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -66,7 +66,7 @@ namespace Content.Server.Physics.Controllers if (pilot.Console == null) continue; _excludedMobs.Add(mover.Owner); - var gridId = xform.GridEntityId; + var gridId = xform.GridUid; // This tries to see if the grid is a shuttle if (!_mapManager.TryGetGrid(gridId, out var grid) || !EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttleComponent)) continue; diff --git a/Content.Server/Power/EntitySystems/CableSystem.Placer.cs b/Content.Server/Power/EntitySystems/CableSystem.Placer.cs index 36d685892d..eaa4140cbc 100644 --- a/Content.Server/Power/EntitySystems/CableSystem.Placer.cs +++ b/Content.Server/Power/EntitySystems/CableSystem.Placer.cs @@ -19,7 +19,7 @@ public sealed partial class CableSystem if (component.CablePrototypeId == null) return; - if(!_mapManager.TryGetGrid(args.ClickLocation.GetGridEntityId(EntityManager), out var grid)) + if(!_mapManager.TryGetGrid(args.ClickLocation.GetGridUid(EntityManager), out var grid)) return; var snapPos = grid.TileIndicesFor(args.ClickLocation); diff --git a/Content.Server/Power/EntitySystems/CableVisSystem.cs b/Content.Server/Power/EntitySystems/CableVisSystem.cs index 4d5e109bec..e720a86f82 100644 --- a/Content.Server/Power/EntitySystems/CableVisSystem.cs +++ b/Content.Server/Power/EntitySystems/CableVisSystem.cs @@ -29,7 +29,7 @@ namespace Content.Server.Power.EntitySystems return; var transform = Transform(uid); - if (!_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(transform.GridUid, out var grid)) return; var mask = WireVisDirFlags.None; diff --git a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs index 3235ebd48f..b9518ca244 100644 --- a/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs +++ b/Content.Server/Power/EntitySystems/ExtensionCableSystem.cs @@ -48,7 +48,7 @@ namespace Content.Server.Power.EntitySystems var xform = Transform(uid); // If grid deleting no need to update power. - if (_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (_mapManager.TryGetGrid(xform.GridUid, out var grid)) { if (MetaData(grid.GridEntityId).EntityLifeStage > EntityLifeStage.MapInitialized) return; } @@ -120,7 +120,7 @@ namespace Content.Server.Power.EntitySystems var xform = Transform(owner); var coordinates = xform.Coordinates; - if (!_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) yield break; var nearbyEntities = grid.GetCellsInSquareArea(coordinates, (int) Math.Ceiling(range / grid.TileSize)); @@ -238,7 +238,7 @@ namespace Content.Server.Power.EntitySystems private bool TryFindAvailableProvider(EntityUid owner, float range, [NotNullWhen(true)] out ExtensionCableProviderComponent? foundProvider, TransformComponent? xform = null) { - if (!Resolve(owner, ref xform) || !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (!Resolve(owner, ref xform) || !_mapManager.TryGetGrid(xform.GridUid, out var grid)) { foundProvider = null; return false; diff --git a/Content.Server/Power/NodeGroups/ApcNet.cs b/Content.Server/Power/NodeGroups/ApcNet.cs index ef2cadaf16..6bb4bf57d7 100644 --- a/Content.Server/Power/NodeGroups/ApcNet.cs +++ b/Content.Server/Power/NodeGroups/ApcNet.cs @@ -46,9 +46,9 @@ namespace Content.Server.Power.NodeGroups [ViewVariables] public PowerState.Network NetworkNode { get; } = new(); - public override void Initialize(Node sourceNode) + public override void Initialize(Node sourceNode, IEntityManager? entMan = null) { - base.Initialize(sourceNode); + base.Initialize(sourceNode, entMan); _powerNetSystem.InitApcNet(this); } diff --git a/Content.Server/Power/NodeGroups/PowerNet.cs b/Content.Server/Power/NodeGroups/PowerNet.cs index f49ee584fe..d5c86e2946 100644 --- a/Content.Server/Power/NodeGroups/PowerNet.cs +++ b/Content.Server/Power/NodeGroups/PowerNet.cs @@ -37,9 +37,9 @@ namespace Content.Server.Power.NodeGroups [ViewVariables] public PowerState.Network NetworkNode { get; } = new(); - public override void Initialize(Node sourceNode) + public override void Initialize(Node sourceNode, IEntityManager? entMan = null) { - base.Initialize(sourceNode); + base.Initialize(sourceNode, entMan); _powerNetSystem.InitPowerNet(this); } diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index a88eeb4254..d1d738bfc4 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -67,7 +67,7 @@ namespace Content.Server.Shuttles.Systems // Assume the docking port itself (and its body) is valid - if (!_mapManager.TryGetGrid(dockingXform.GridEntityId, out var grid) || + if (!_mapManager.TryGetGrid(dockingXform.GridUid, out var grid) || !HasComp(grid.GridEntityId)) return null; var transform = body.GetTransform(); @@ -93,7 +93,7 @@ namespace Content.Server.Shuttles.Systems while (enumerator.MoveNext(out var otherGrid)) { - if (otherGrid.GridEntityId == dockingXform.GridEntityId) continue; + if (otherGrid.GridEntityId == dockingXform.GridUid) continue; foreach (var ent in otherGrid.GetAnchoredEntities(enlargedAABB)) { @@ -164,16 +164,18 @@ namespace Content.Server.Shuttles.Systems dockA.DockJoint = null; dockA.DockedWith = null; - // If these grids are ever invalid then need to look at fixing ordering for unanchored events elsewhere. - var gridAUid = _mapManager.GetGrid(EntityManager.GetComponent(dockA.Owner).GridEntityId).GridEntityId; - var gridBUid = _mapManager.GetGrid(EntityManager.GetComponent(dockB.Owner).GridEntityId).GridEntityId; + // If these grids are ever null then need to look at fixing ordering for unanchored events elsewhere. + var gridAUid = EntityManager.GetComponent(dockA.Owner).GridUid; + var gridBUid = EntityManager.GetComponent(dockB.Owner).GridUid; + DebugTools.Assert(gridAUid != null); + DebugTools.Assert(gridBUid != null); var msg = new UndockEvent { DockA = dockA, DockB = dockB, - GridAUid = gridAUid, - GridBUid = gridBUid, + GridAUid = gridAUid!.Value, + GridBUid = gridBUid!.Value, }; EntityManager.EventBus.RaiseLocalEvent(dockA.Owner, msg, false); @@ -305,8 +307,10 @@ namespace Content.Server.Shuttles.Systems var dockAXform = EntityManager.GetComponent(dockA.Owner); var dockBXform = EntityManager.GetComponent(dockB.Owner); - var gridA = _mapManager.GetGrid(dockAXform.GridEntityId).GridEntityId; - var gridB = _mapManager.GetGrid(dockBXform.GridEntityId).GridEntityId; + DebugTools.Assert(dockAXform.GridUid != null); + DebugTools.Assert(dockBXform.GridUid != null); + var gridA = dockAXform.GridUid!.Value; + var gridB = dockBXform.GridUid!.Value; SharedJointSystem.LinearStiffness( 2f, diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 2249f357af..6eb8649509 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -142,7 +142,7 @@ namespace Content.Server.Shuttles.Systems pilot.Console is not ShuttleConsoleComponent console) return; if (!console.SubscribedPilots.Contains(pilot) || - !TryComp(xform.GridEntityId, out var shuttle)) return; + !TryComp(xform.GridUid, out var shuttle)) return; SetShuttleMode(args.Mode, console, shuttle); } diff --git a/Content.Server/Shuttles/Systems/SpaceGarbageSystem.cs b/Content.Server/Shuttles/Systems/SpaceGarbageSystem.cs index dc1b5478df..8f25c490ab 100644 --- a/Content.Server/Shuttles/Systems/SpaceGarbageSystem.cs +++ b/Content.Server/Shuttles/Systems/SpaceGarbageSystem.cs @@ -20,7 +20,7 @@ public sealed class SpaceGarbageSystem : EntitySystem var ourXform = Transform(args.OurFixture.Body.Owner); var otherXform = Transform(args.OtherFixture.Body.Owner); - if (ourXform.GridEntityId == otherXform.GridEntityId || + if (ourXform.GridUid == otherXform.GridUid || args.OtherFixture.Body.BodyType != BodyType.Static) return; QueueDel(uid); diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index b2cab2c9a0..6f9948e36a 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -126,7 +126,7 @@ namespace Content.Server.Shuttles.Systems if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y)) continue; - DisableThruster(ent.Value, thruster, xform.GridEntityId); + DisableThruster(ent.Value, thruster, xform.GridUid); } } } @@ -147,7 +147,7 @@ namespace Content.Server.Shuttles.Systems if (!component.Enabled || component.Type != ThrusterType.Linear || !EntityManager.TryGetComponent(uid, out TransformComponent? xform) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid) || + !_mapManager.TryGetGrid(xform.GridUid, out var grid) || !EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttleComponent)) { return; @@ -243,7 +243,7 @@ namespace Content.Server.Shuttles.Systems { if (component.IsOn || !Resolve(uid, ref xform) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) return; + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; component.IsOn = true; @@ -304,13 +304,13 @@ namespace Content.Server.Shuttles.Systems public void DisableThruster(EntityUid uid, ThrusterComponent component, TransformComponent? xform = null, Angle? angle = null) { if (!Resolve(uid, ref xform)) return; - DisableThruster(uid, component, xform.GridEntityId, xform); + DisableThruster(uid, component, xform.GridUid, xform); } /// /// Tries to disable the thruster. /// - public void DisableThruster(EntityUid uid, ThrusterComponent component, EntityUid gridId, TransformComponent? xform = null, Angle? angle = null) + public void DisableThruster(EntityUid uid, ThrusterComponent component, EntityUid? gridId, TransformComponent? xform = null, Angle? angle = null) { if (!component.IsOn || !Resolve(uid, ref xform) || @@ -382,8 +382,11 @@ namespace Content.Server.Shuttles.Systems private bool NozzleExposed(TransformComponent xform) { + if (xform.GridUid == null) + return true; + var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec(); - var tile = _mapManager.GetGrid(xform.GridEntityId).GetTileRef(new Vector2i((int) Math.Floor(x), (int) Math.Floor(y))); + var tile = _mapManager.GetGrid(xform.GridUid.Value).GetTileRef(new Vector2i((int) Math.Floor(x), (int) Math.Floor(y))); return tile.Tile.IsSpace(); } diff --git a/Content.Server/Sound/EmitSoundSystem.cs b/Content.Server/Sound/EmitSoundSystem.cs index aed10d427b..7f423e0e2f 100644 --- a/Content.Server/Sound/EmitSoundSystem.cs +++ b/Content.Server/Sound/EmitSoundSystem.cs @@ -46,7 +46,7 @@ namespace Content.Server.Sound private void HandleEmitSoundOnLand(EntityUid eUI, BaseEmitSoundComponent component, LandEvent arg) { if (!TryComp(eUI, out var xform) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) return; + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return; var tile = grid.GetTileRef(xform.Coordinates); diff --git a/Content.Server/Station/Systems/StationSystem.cs b/Content.Server/Station/Systems/StationSystem.cs index 8a72b9826c..af4b5cd2c7 100644 --- a/Content.Server/Station/Systems/StationSystem.cs +++ b/Content.Server/Station/Systems/StationSystem.cs @@ -317,13 +317,13 @@ public sealed class StationSystem : EntitySystem return CompOrNull(entity)?.Station; } - if (xform.GridEntityId == EntityUid.Invalid) + if (xform.GridUid == EntityUid.Invalid) { Logger.Debug("A"); return null; } - return CompOrNull(xform.GridEntityId)?.Station; + return CompOrNull(xform.GridUid)?.Station; } } diff --git a/Content.Server/StationEvents/Events/GasLeak.cs b/Content.Server/StationEvents/Events/GasLeak.cs index cfe80c6711..ceef8af090 100644 --- a/Content.Server/StationEvents/Events/GasLeak.cs +++ b/Content.Server/StationEvents/Events/GasLeak.cs @@ -114,18 +114,18 @@ namespace Content.Server.StationEvents.Events if (_timeUntilLeak > 0f) return; _timeUntilLeak += LeakCooldown; - var atmosphereSystem = EntitySystem.Get(); - + var atmosphereSystem = _entityManager.EntitySysManager.GetEntitySystem(); + if (!_foundTile || _targetGrid == default || _entityManager.Deleted(_targetGrid) || - !atmosphereSystem.IsSimulatedGrid(_entityManager.GetComponent(_targetGrid).GridEntityId)) + !atmosphereSystem.IsSimulatedGrid(_targetGrid)) { Running = false; return; } - var environment = atmosphereSystem.GetTileMixture(_entityManager.GetComponent(_targetGrid).GridEntityId, _targetTile, true); + var environment = atmosphereSystem.GetTileMixture(_targetGrid, _targetTile, true); environment?.AdjustMoles(_leakGas, LeakCooldown * _molesPerSecond); } @@ -152,14 +152,14 @@ namespace Content.Server.StationEvents.Events if (!_foundTile || _targetGrid == default || (!_entityManager.EntityExists(_targetGrid) ? EntityLifeStage.Deleted : _entityManager.GetComponent(_targetGrid).EntityLifeStage) >= EntityLifeStage.Deleted || - !atmosphereSystem.IsSimulatedGrid(_entityManager.GetComponent(_targetGrid).GridEntityId)) + !atmosphereSystem.IsSimulatedGrid(_targetGrid)) { return; } // Don't want it to be so obnoxious as to instantly murder anyone in the area but enough that // it COULD start potentially start a bigger fire. - atmosphereSystem.HotspotExpose(_entityManager.GetComponent(_targetGrid).GridID, _targetTile, 700f, 50f, true); + atmosphereSystem.HotspotExpose(_targetGrid, _targetTile, 700f, 50f, true); SoundSystem.Play("/Audio/Effects/sparks4.ogg", Filter.Pvs(_targetCoords), _targetCoords); } } diff --git a/Content.Server/SubFloor/SubFloorHideSystem.cs b/Content.Server/SubFloor/SubFloorHideSystem.cs index 00162d6698..7820badceb 100644 --- a/Content.Server/SubFloor/SubFloorHideSystem.cs +++ b/Content.Server/SubFloor/SubFloorHideSystem.cs @@ -17,7 +17,7 @@ public sealed class SubFloorHideSystem : SharedSubFloorHideSystem // No teleporting entities through floor tiles when anchoring them. var xform = Transform(uid); - if (MapManager.TryGetGrid(xform.GridEntityId, out var grid) + if (MapManager.TryGetGrid(xform.GridUid, out var grid) && HasFloorCover(grid, grid.TileIndicesFor(xform.Coordinates))) { args.Cancel(); diff --git a/Content.Server/Tools/ToolSystem.TilePrying.cs b/Content.Server/Tools/ToolSystem.TilePrying.cs index 7e939125f9..9a9624f3ef 100644 --- a/Content.Server/Tools/ToolSystem.TilePrying.cs +++ b/Content.Server/Tools/ToolSystem.TilePrying.cs @@ -4,6 +4,7 @@ using Content.Shared.Interaction; using Content.Shared.Maps; using Content.Shared.Tools.Components; using Robust.Shared.Map; +using Robust.Shared.Utility; namespace Content.Server.Tools; @@ -26,7 +27,14 @@ public sealed partial class ToolSystem private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingCompleteEvent args) { component.CancelToken = null; - args.Coordinates.PryTile(EntityManager, _mapManager); + var gridUid = args.Coordinates.GetGridUid(EntityManager); + if (!_mapManager.TryGetGrid(gridUid, out var grid)) + { + Logger.Error("Attempted to pry from a non-existent grid?"); + return; + } + + grid.GetTileRef(args.Coordinates).PryTile(_mapManager, _tileDefinitionManager, EntityManager); } private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args) @@ -47,7 +55,7 @@ public sealed partial class ToolSystem if (!TryComp(component.Owner, out var tool) && component.ToolComponentNeeded) return false; - if (!_mapManager.TryGetGrid(clickLocation.GetGridEntityId(EntityManager), out var mapGrid)) + if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid)) return false; var tile = mapGrid.GetTileRef(clickLocation); diff --git a/Content.Shared/Friction/SharedTileFrictionController.cs b/Content.Shared/Friction/SharedTileFrictionController.cs index 44bf49bd28..122df273a9 100644 --- a/Content.Shared/Friction/SharedTileFrictionController.cs +++ b/Content.Shared/Friction/SharedTileFrictionController.cs @@ -161,7 +161,7 @@ namespace Content.Shared.Friction // TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events if (body.Owner.IsWeightless(body, coords, _mapManager) || - !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + !_mapManager.TryGetGrid(xform.GridUid, out var grid)) return 0.0f; if (!coords.IsValid(EntityManager)) return 0.0f; diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index cd1c45e2ea..48d2cf8583 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -14,9 +14,6 @@ namespace Content.Shared.Maps /// public static TileRef GetTileRef(this Vector2i vector2i, EntityUid gridId, IMapManager? mapManager = null) { - if (!gridId.IsValid()) - return default; - mapManager ??= IoCManager.Resolve(); if (!mapManager.TryGetGrid(gridId, out var grid)) @@ -41,7 +38,7 @@ namespace Content.Shared.Maps mapManager ??= IoCManager.Resolve(); - if (!mapManager.TryGetGrid(coordinates.GetGridEntityId(entityManager), out var grid)) + if (!mapManager.TryGetGrid(coordinates.GetGridUid(entityManager), out var grid)) return null; @@ -89,15 +86,6 @@ namespace Content.Shared.Maps return tile.Tile.IsSpace(tileDefinitionManager); } - public static bool PryTile(this EntityCoordinates coordinates, IEntityManager? entityManager = null, - IMapManager? mapManager = null) - { - entityManager ??= IoCManager.Resolve(); - mapManager ??= IoCManager.Resolve(); - - return coordinates.ToVector2i(entityManager, mapManager).PryTile(coordinates.GetGridEntityId(entityManager)); - } - public static bool PryTile(this Vector2i indices, EntityUid gridId, IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null) { diff --git a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs index 1c40b0a90f..53d68ed25c 100644 --- a/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs +++ b/Content.Shared/Movement/Components/MovementIgnoreGravityComponent.cs @@ -45,9 +45,9 @@ namespace Content.Shared.Movement.Components return ignoreGravityComponent.Weightless; var transform = entityManager.GetComponent(entity); - var gridId = transform.GridEntityId; + var gridId = transform.GridUid; - if (!gridId.IsValid()) + if (gridId == null) { // Not on a grid = no gravity for now. // In the future, may want to allow maps to override to always have gravity instead. @@ -55,7 +55,7 @@ namespace Content.Shared.Movement.Components } mapManager ??= IoCManager.Resolve(); - var grid = mapManager.GetGrid(gridId); + var grid = mapManager.GetGrid(gridId.Value); var invSys = EntitySystem.Get(); if (invSys.TryGetSlotEntity(entity, "shoes", out var ent)) diff --git a/Content.Shared/Movement/SharedMoverController.cs b/Content.Shared/Movement/SharedMoverController.cs index 9c5cd383eb..9829c05183 100644 --- a/Content.Shared/Movement/SharedMoverController.cs +++ b/Content.Shared/Movement/SharedMoverController.cs @@ -68,7 +68,7 @@ namespace Content.Shared.Movement protected Angle GetParentGridAngle(TransformComponent xform, IMoverComponent mover) { - if (xform.GridEntityId == EntityUid.Invalid || !_mapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (!_mapManager.TryGetGrid(xform.GridUid, out var grid)) return mover.LastGridAngle; return grid.WorldRotation; @@ -90,11 +90,11 @@ namespace Content.Shared.Movement var worldTotal = _relativeMovement ? parentRotation.RotateVec(total) : total; - if (transform.GridEntityId != EntityUid.Invalid) + if (transform.GridUid != null) mover.LastGridAngle = parentRotation; if (worldTotal != Vector2.Zero) - transform.LocalRotation = transform.GridEntityId != EntityUid.Invalid + transform.LocalRotation = transform.GridUid != null ? total.ToWorldAngle() : worldTotal.ToWorldAngle(); @@ -130,7 +130,7 @@ namespace Content.Shared.Movement if (!touching) { - if (xform.GridEntityId != EntityUid.Invalid) + if (xform.GridUid != EntityUid.Invalid) mover.LastGridAngle = GetParentGridAngle(xform, mover); xform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle(); @@ -152,14 +152,14 @@ namespace Content.Shared.Movement if (weightless) worldTotal *= mobMover.WeightlessStrength; - if (xform.GridEntityId != EntityUid.Invalid) + if (xform.GridUid != EntityUid.Invalid) mover.LastGridAngle = parentRotation; if (worldTotal != Vector2.Zero) { // This should have its event run during island solver soooo xform.DeferUpdates = true; - xform.LocalRotation = xform.GridEntityId != EntityUid.Invalid + xform.LocalRotation = xform.GridUid != EntityUid.Invalid ? total.ToWorldAngle() : worldTotal.ToWorldAngle(); xform.DeferUpdates = false; @@ -229,7 +229,7 @@ namespace Content.Shared.Movement if (!CanSound() || !_tags.HasTag(mover.Owner, "FootstepSound")) return false; var coordinates = xform.Coordinates; - var gridId = coordinates.GetGridEntityId(EntityManager); + var gridId = coordinates.GetGridUid(EntityManager); var distanceNeeded = mover.Sprinting ? StepSoundMoveDistanceRunning : StepSoundMoveDistanceWalking; // Handle footsteps. @@ -252,7 +252,7 @@ namespace Content.Shared.Movement return false; } - DebugTools.Assert(gridId != EntityUid.Invalid); + DebugTools.Assert(gridId != null); mobMover.LastPosition = coordinates; if (mobMover.StepSoundDistance < distanceNeeded) return false; @@ -267,7 +267,7 @@ namespace Content.Shared.Movement return true; } - return TryGetFootstepSound(gridId, coordinates, out variation, out sound); + return TryGetFootstepSound(gridId!.Value, coordinates, out variation, out sound); } private bool TryGetFootstepSound(EntityUid gridId, EntityCoordinates coordinates, out float variation, [NotNullWhen(true)] out string? sound) diff --git a/Content.Shared/SubFloor/SharedSubFloorHideSystem.cs b/Content.Shared/SubFloor/SharedSubFloorHideSystem.cs index 40bfdc6b3c..527e7b8ad4 100644 --- a/Content.Shared/SubFloor/SharedSubFloorHideSystem.cs +++ b/Content.Shared/SubFloor/SharedSubFloorHideSystem.cs @@ -98,7 +98,7 @@ namespace Content.Shared.SubFloor if (!Resolve(uid, ref component, ref xform)) return; - if (xform.Anchored && MapManager.TryGetGrid(xform.GridEntityId, out var grid)) + if (xform.Anchored && MapManager.TryGetGrid(xform.GridUid, out var grid)) component.IsUnderCover = HasFloorCover(grid, grid.TileIndicesFor(xform.Coordinates)); else component.IsUnderCover = false; diff --git a/Content.Shared/SubFloor/TrayScannerSystem.cs b/Content.Shared/SubFloor/TrayScannerSystem.cs index c9441f3662..bab124c462 100644 --- a/Content.Shared/SubFloor/TrayScannerSystem.cs +++ b/Content.Shared/SubFloor/TrayScannerSystem.cs @@ -208,7 +208,7 @@ public sealed class TrayScannerSystem : EntitySystem // For now, limiting to the scanner's own grid. We could do a grid-lookup, but then what do we do if one grid // flies away, while the scanner's local-position remains unchanged? - if (_mapManager.TryGetGrid(transform.GridEntityId, out var grid)) + if (_mapManager.TryGetGrid(transform.GridUid, out var grid)) { foreach (var entity in grid.GetAnchoredEntities(worldBox)) {