diff --git a/Content.IntegrationTests/Tests/Atmos/AtmosHelpersTest.cs b/Content.IntegrationTests/Tests/Atmos/AtmosHelpersTest.cs deleted file mode 100644 index 773ce8b3c2..0000000000 --- a/Content.IntegrationTests/Tests/Atmos/AtmosHelpersTest.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System.Threading.Tasks; -using Content.Server.Atmos; -using NUnit.Framework; -using Robust.Shared.GameObjects; -using Robust.Shared.Map; -using Robust.Shared.Maths; - -namespace Content.IntegrationTests.Tests.Atmos -{ - [TestFixture] - [TestOf(typeof(AtmosHelpersTest))] - public class AtmosHelpersTest : ContentIntegrationTest - { - [Test] - public async Task GetTileAtmosphereEntityCoordinatesNotNullTest() - { - var server = StartServerDummyTicker(); - - await server.WaitIdleAsync(); - - var entityManager = server.ResolveDependency(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var atmosphere1 = default(EntityCoordinates).GetTileAtmosphere(); - var atmosphere2 = default(EntityCoordinates).GetTileAtmosphere(entityManager); - - Assert.NotNull(atmosphere1); - Assert.NotNull(atmosphere2); - }); - }); - - await server.WaitIdleAsync(); - } - - [Test] - public async Task GetTileAirEntityCoordinatesNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var air = default(EntityCoordinates).GetTileAir(); - - Assert.NotNull(air); - }); - }); - - await server.WaitIdleAsync(); - } - - [Test] - public async Task TryGetTileAtmosphereEntityCoordinatesNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var hasAtmosphere = default(EntityCoordinates).TryGetTileAtmosphere(out var atmosphere); - - Assert.True(hasAtmosphere); - Assert.NotNull(atmosphere); - }); - }); - - await server.WaitIdleAsync(); - } - - [Test] - public async Task TryGetTileTileAirEntityCoordinatesNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var hasAir = default(EntityCoordinates).TryGetTileAir(out var air); - - Assert.True(hasAir); - Assert.NotNull(air); - }); - }); - - await server.WaitIdleAsync(); - } - - // ReSharper disable once InconsistentNaming - [Test] - public async Task GetTileAtmosphereVector2iNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var atmosphere = default(Vector2i).GetTileAtmosphere(default); - - Assert.NotNull(atmosphere); - }); - }); - - await server.WaitIdleAsync(); - } - - // ReSharper disable once InconsistentNaming - [Test] - public async Task GetTileAirVector2iNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var air = default(Vector2i).GetTileAir(default); - - Assert.NotNull(air); - }); - }); - - await server.WaitIdleAsync(); - } - - // ReSharper disable once InconsistentNaming - [Test] - public async Task TryGetTileAtmosphereVector2iNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var hasAtmosphere = default(Vector2i).TryGetTileAtmosphere(default, out var atmosphere); - - Assert.True(hasAtmosphere); - Assert.NotNull(atmosphere); - }); - }); - - await server.WaitIdleAsync(); - } - - // ReSharper disable once InconsistentNaming - [Test] - public async Task TryGetTileAirVector2iNotNullTest() - { - var server = StartServerDummyTicker(); - - server.Assert(() => - { - Assert.DoesNotThrow(() => - { - var hasAir = default(Vector2i).TryGetTileAir(default, out var air); - - Assert.True(hasAir); - Assert.NotNull(air); - }); - }); - - await server.WaitIdleAsync(); - } - } -} diff --git a/Content.IntegrationTests/Tests/Body/LegTest.cs b/Content.IntegrationTests/Tests/Body/LegTest.cs index c934148172..25c2d586d0 100644 --- a/Content.IntegrationTests/Tests/Body/LegTest.cs +++ b/Content.IntegrationTests/Tests/Body/LegTest.cs @@ -8,6 +8,7 @@ using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; +using Robust.Shared.Maths; namespace Content.IntegrationTests.Tests.Body { @@ -40,11 +41,10 @@ namespace Content.IntegrationTests.Tests.Body { var mapManager = IoCManager.Resolve(); - var mapId = new MapId(0); - mapManager.CreateNewMapEntity(mapId); + var mapId = mapManager.CreateMap(); var entityManager = IoCManager.Resolve(); - var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", MapCoordinates.Nullspace); + var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", new MapCoordinates(Vector2.Zero, mapId)); Assert.That(human.TryGetComponent(out IBody body)); Assert.That(human.TryGetComponent(out appearance)); diff --git a/Content.IntegrationTests/Tests/Body/LungTest.cs b/Content.IntegrationTests/Tests/Body/LungTest.cs index de734f1997..d63a41ce63 100644 --- a/Content.IntegrationTests/Tests/Body/LungTest.cs +++ b/Content.IntegrationTests/Tests/Body/LungTest.cs @@ -57,11 +57,11 @@ namespace Content.IntegrationTests.Tests.Body { var mapManager = IoCManager.Resolve(); - mapManager.CreateNewMapEntity(MapId.Nullspace); + var mapId = mapManager.CreateMap(); var entityManager = IoCManager.Resolve(); - var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", MapCoordinates.Nullspace); + var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", new MapCoordinates(Vector2.Zero, mapId)); Assert.That(human.TryGetComponent(out IBody body)); Assert.That(body.TryGetMechanismBehaviors(out List lungs)); diff --git a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs b/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs index e25c6e7af2..1d7884db11 100644 --- a/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs +++ b/Content.IntegrationTests/Tests/Body/MechanismBehaviorEventsTest.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; +using Robust.Shared.Maths; namespace Content.IntegrationTests.Tests.Body { @@ -122,11 +123,10 @@ namespace Content.IntegrationTests.Tests.Body { var mapManager = IoCManager.Resolve(); - var mapId = new MapId(0); - mapManager.CreateNewMapEntity(mapId); + var mapId = mapManager.CreateMap(); var entityManager = IoCManager.Resolve(); - var human = entityManager.SpawnEntity("HumanBodyDummy", MapCoordinates.Nullspace); + var human = entityManager.SpawnEntity("HumanBodyDummy", new MapCoordinates(Vector2.Zero, mapId)); Assert.That(human.TryGetComponent(out IBody? body)); Assert.NotNull(body); diff --git a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs index 3343380a5e..cdbb3bbc02 100644 --- a/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs +++ b/Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs @@ -10,6 +10,7 @@ using Robust.Server.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; +using Robust.Shared.Maths; namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking { @@ -52,15 +53,16 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking server.Assert(() => { var mapManager = IoCManager.Resolve(); - mapManager.CreateNewMapEntity(MapId.Nullspace); + var mapId = mapManager.CreateMap(); + var coordinates = new MapCoordinates(Vector2.Zero, mapId); var entityManager = IoCManager.Resolve(); // Spawn the entities - human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); - otherHuman = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace); - cuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); - secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace); + human = entityManager.SpawnEntity("HumanDummy", coordinates); + otherHuman = entityManager.SpawnEntity("HumanDummy", coordinates); + cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); + secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates); human.Transform.WorldPosition = otherHuman.Transform.WorldPosition; diff --git a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs index 7e5c49cc65..f0d4232075 100644 --- a/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs +++ b/Content.IntegrationTests/Tests/Interaction/InRangeUnobstructed.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.Map; +using Robust.Shared.Maths; namespace Content.IntegrationTests.Tests.Interaction { @@ -44,8 +45,8 @@ namespace Content.IntegrationTests.Tests.Interaction server.Assert(() => { - mapManager.CreateNewMapEntity(MapId.Nullspace); - var coordinates = MapCoordinates.Nullspace; + var mapId = mapManager.CreateMap(); + var coordinates = new MapCoordinates(Vector2.Zero, mapId); origin = entityManager.SpawnEntity(HumanId, coordinates); other = entityManager.SpawnEntity(HumanId, coordinates); diff --git a/Content.Server/Atmos/AtmosHelpers.cs b/Content.Server/Atmos/AtmosHelpers.cs index 02c51839c3..c29f712b54 100644 --- a/Content.Server/Atmos/AtmosHelpers.cs +++ b/Content.Server/Atmos/AtmosHelpers.cs @@ -3,26 +3,20 @@ using System.Diagnostics.CodeAnalysis; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Atmos; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; using Robust.Shared.Map; -using Robust.Shared.Maths; namespace Content.Server.Atmos { public static class AtmosHelpers { - public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) + public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates) { - entityManager ??= IoCManager.Resolve(); - - var gridAtmos = EntitySystem.Get().GetGridAtmosphere(coordinates.GetGridId(entityManager)); - - return gridAtmos.GetTile(coordinates); + return EntitySystem.Get().GetGridAtmosphere(coordinates).GetTile(coordinates); } public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null) { - return coordinates.GetTileAtmosphere(entityManager)?.Air; + return coordinates.GetTileAtmosphere()?.Air; } public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere) @@ -54,36 +48,6 @@ namespace Content.Server.Atmos return true; } - public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId) - { - var gridAtmos = EntitySystem.Get().GetGridAtmosphere(gridId); - - return gridAtmos.GetTile(indices); - } - - public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId) - { - return indices.GetTileAtmosphere(gridId)?.Air; - } - - public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId, - [NotNullWhen(true)] out TileAtmosphere? atmosphere) - { - // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default); - } - - public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air) - { - // ReSharper disable once ConditionIsAlwaysTrueOrFalse - return !Equals(air = indices.GetTileAir(gridId), default); - } - - public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null) - { - return InvalidateTileAir(transform.Coordinates); - } - public static bool InvalidateTileAir(this EntityCoordinates coordinates) { if (!coordinates.TryGetTileAtmosphere(out var tileAtmos)) diff --git a/Content.Server/Atmos/IGridAtmosphereComponent.cs b/Content.Server/Atmos/IGridAtmosphereComponent.cs index 6b6ffdb3d5..90201c0bf6 100644 --- a/Content.Server/Atmos/IGridAtmosphereComponent.cs +++ b/Content.Server/Atmos/IGridAtmosphereComponent.cs @@ -157,6 +157,11 @@ namespace Content.Server.Atmos void RepopulateTiles(); + /// + /// Returns a dictionary of adjacent TileAtmospheres. + /// + Dictionary GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false); + /// /// Returns a dictionary of adjacent TileAtmospheres. /// diff --git a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs index 8801f4ffb4..c865af2eda 100644 --- a/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/ExtinguishTileReaction.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos; using Content.Shared.Atmos; using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; +using Content.Shared.Maps; using JetBrains.Annotations; using Robust.Shared.Map; using Robust.Shared.Serialization.Manager.Attributes; @@ -18,7 +19,7 @@ namespace Content.Server.Chemistry.TileReactions public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero; - var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex); + var tileAtmos = tile.GridPosition().GetTileAtmosphere(); if (tileAtmos == null || !tileAtmos.Hotspot.Valid || tileAtmos.Air == null) return ReagentUnit.Zero; tileAtmos.Air.Temperature = MathF.Max(MathF.Min(tileAtmos.Air.Temperature - (_coolingTemperature * 1000f), diff --git a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs index 4ec75728c9..57c331516d 100644 --- a/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs +++ b/Content.Server/Chemistry/TileReactions/FlammableTileReaction.cs @@ -2,6 +2,7 @@ using Content.Server.Atmos; using Content.Shared.Chemistry; using Content.Shared.Interfaces.Chemistry; +using Content.Shared.Maps; using JetBrains.Annotations; using Robust.Shared.Map; using Robust.Shared.Serialization.Manager.Attributes; @@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.TileReactions public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume) { if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero; - var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex); + var tileAtmos = tile.GridPosition().GetTileAtmosphere(); if (tileAtmos?.Air == null || !tileAtmos.Hotspot.Valid) return ReagentUnit.Zero; tileAtmos.Air.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f); tileAtmos.Air.React(tileAtmos); diff --git a/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs b/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs index e9d39b8c2f..0d3a351348 100644 --- a/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs @@ -141,7 +141,9 @@ namespace Content.Server.GameObjects.Components.Atmos UpdatePosition(_lastPosition.Item1, _lastPosition.Item2); if (_fixVacuum) - _atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1).FixVacuum(_lastPosition.Item2); + { + _atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2); + } } private void OnTransformMove() @@ -165,8 +167,8 @@ namespace Content.Server.GameObjects.Components.Atmos { var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId); - gridAtmos.UpdateAdjacentBits(pos); - gridAtmos.Invalidate(pos); + gridAtmos?.UpdateAdjacentBits(pos); + gridAtmos?.Invalidate(pos); } } } diff --git a/Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs b/Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs index d8db0fa309..1f1ee3ede6 100644 --- a/Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs @@ -61,7 +61,7 @@ namespace Content.Server.GameObjects.Components.Atmos { return; } - + if (IsHoldingPressure()) { Owner.PopupMessage(eventArgs.User, Loc.GetString("A gush of air blows in your face... Maybe you should reconsider.")); @@ -76,15 +76,12 @@ namespace Content.Server.GameObjects.Components.Atmos { var atmosphereSystem = EntitySystem.Get(); - if (!Owner.Transform.Coordinates.TryGetTileAtmosphere(out var tileAtmos)) - return false; - - var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID); + var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates); var minMoles = float.MaxValue; var maxMoles = 0f; - foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices)) + foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(Owner.Transform.Coordinates)) { // includeAirBlocked remains false, and therefore Air must be present var moles = adjacent.Air!.TotalMoles; @@ -107,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Atmos if (tileAtmos.Hotspot.Valid) return true; - var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID); + var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates); foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices)) { diff --git a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 6f57f06001..9bec209c6c 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Atmos { // Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth var pressure = 0f; - var gam = EntitySystem.Get().GetGridAtmosphere(Owner.Transform.GridID); + var gam = EntitySystem.Get().GetGridAtmosphere(Owner.Transform.Coordinates); var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air; if (tile != null) { @@ -185,7 +185,7 @@ namespace Content.Server.GameObjects.Components.Atmos } var atmosSystem = EntitySystem.Get(); - var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager)); + var gam = atmosSystem.GetGridAtmosphere(pos); var tile = gam.GetTile(pos)?.Air; if (tile == null) { diff --git a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs index d6890e402f..bc9984e716 100644 --- a/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs @@ -514,6 +514,11 @@ namespace Content.Server.GameObjects.Components.Atmos return _mapGridComponent.Grid.GetTileRef(indices).IsSpace(); } + public Dictionary GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false) + { + return GetAdjacentTiles(coordinates.ToVector2i(_serverEntityManager, _mapManager), includeAirBlocked); + } + public Dictionary GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false) { var sides = new Dictionary(); diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/PipeNetDeviceComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/PipeNetDeviceComponent.cs index 52b3b10bc7..bb54fab26d 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/PipeNetDeviceComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/PipeNetDeviceComponent.cs @@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping private void JoinGridAtmos() { var gridAtmos = EntitySystem.Get() - .GetGridAtmosphere(Owner.Transform.GridID); + .GetGridAtmosphere(Owner.Transform.Coordinates); JoinedGridAtmos = gridAtmos; JoinedGridAtmos.AddPipeNetDevice(this); } diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/BaseSiphonComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/BaseSiphonComponent.cs index eb3527e6a6..1ac02cec53 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/BaseSiphonComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Scrubbers/BaseSiphonComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers if (!SiphonEnabled) return; - var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager); + var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(); if (_scrubberOutlet == null || tileAtmos == null || tileAtmos.Air == null) return; diff --git a/Content.Server/GameObjects/Components/Atmos/Piping/Vents/BaseVentComponent.cs b/Content.Server/GameObjects/Components/Atmos/Piping/Vents/BaseVentComponent.cs index 6215f1dc17..976100b8c5 100644 --- a/Content.Server/GameObjects/Components/Atmos/Piping/Vents/BaseVentComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/Piping/Vents/BaseVentComponent.cs @@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents if (!VentEnabled) return; - var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager); + var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(); if (_ventInlet == null || tileAtmos == null || tileAtmos.Air == null) return; diff --git a/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs index 69edf093d7..60a8f6ec95 100644 --- a/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using System.Linq; using Content.Server.Atmos; +using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; namespace Content.Server.GameObjects.Components.Atmos { + [RegisterComponent] + [ComponentReference(typeof(IGridAtmosphereComponent))] public class SpaceGridAtmosphereComponent : UnsimulatedGridAtmosphereComponent { public override string Name => "SpaceGridAtmosphere"; diff --git a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs index 3e63cda197..b0fbafa4e4 100644 --- a/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs +++ b/Content.Server/GameObjects/Components/Disposal/DisposalUnitComponent.cs @@ -283,7 +283,7 @@ namespace Content.Server.GameObjects.Components.Disposal var atmosSystem = EntitySystem.Get(); atmosSystem - .GetGridAtmosphere(Owner.Transform.GridID)? + .GetGridAtmosphere(Owner.Transform.Coordinates)? .Invalidate(tileAtmos.GridIndices); } diff --git a/Content.Server/GameObjects/EntitySystems/AtmosExposedSystem.cs b/Content.Server/GameObjects/EntitySystems/AtmosExposedSystem.cs index 92c5ace6f2..3bce1680f9 100644 --- a/Content.Server/GameObjects/EntitySystems/AtmosExposedSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AtmosExposedSystem.cs @@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.EntitySystems // creadth: everything exposable by atmos should be updated as well foreach (var atmosExposedComponent in EntityManager.ComponentManager.EntityQuery(true)) { - var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere(EntityManager); + var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere(); if (tile == null) continue; atmosExposedComponent.Update(tile, _lastUpdate); } diff --git a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs index c7f549bfa6..b6f88e7436 100644 --- a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs @@ -5,6 +5,7 @@ using System.Linq; using Content.Server.Atmos; using Content.Server.Atmos.Reactions; using Content.Server.GameObjects.Components.Atmos; +using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Content.Shared; using Content.Shared.Atmos; using Content.Shared.GameObjects.EntitySystems.Atmos; @@ -31,7 +32,6 @@ namespace Content.Server.GameObjects.EntitySystems private GasReactionPrototype[] _gasReactions = Array.Empty(); - private SpaceGridAtmosphereComponent _spaceAtmos = default!; private GridTileLookupSystem? _gridTileLookup = null; /// @@ -51,10 +51,7 @@ namespace Content.Server.GameObjects.EntitySystems _gasReactions = _protoMan.EnumeratePrototypes().ToArray(); Array.Sort(_gasReactions, (a, b) => b.Priority.CompareTo(a.Priority)); - _spaceAtmos = new SpaceGridAtmosphereComponent(); - _spaceAtmos.Initialize(); - IoCManager.InjectDependencies(_spaceAtmos); - + _mapManager.MapCreated += OnMapCreated; _mapManager.TileChanged += OnTileChanged; Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4)); @@ -116,6 +113,8 @@ namespace Content.Server.GameObjects.EntitySystems { base.Shutdown(); + _mapManager.MapCreated -= OnMapCreated; + EntityManager.EventBus.UnsubscribeEvent(EventSource.Local, this); } @@ -127,18 +126,39 @@ namespace Content.Server.GameObjects.EntitySystems } } - public IGridAtmosphereComponent GetGridAtmosphere(GridId gridId) + public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId) { if (!gridId.IsValid()) + return null; + + if (!_mapManager.TryGetGrid(gridId, out var grid)) + return null; + + return ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? gridAtmosphere) + ? gridAtmosphere : null; + } + + public IGridAtmosphereComponent GetGridAtmosphere(EntityCoordinates coordinates) + { + return GetGridAtmosphere(coordinates.ToMap(EntityManager)); + } + + public IGridAtmosphereComponent GetGridAtmosphere(MapCoordinates coordinates) + { + if (coordinates.MapId == MapId.Nullspace) { - return _spaceAtmos; + throw new ArgumentException($"Coordinates cannot be in nullspace!", nameof(coordinates)); } - var grid = _mapManager.GetGrid(gridId); + if (_mapManager.TryFindGridAt(coordinates, out var grid)) + { + if (ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? atmos)) + { + return atmos; + } + } - if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return _spaceAtmos; - - return gridEnt.TryGetComponent(out IGridAtmosphereComponent? atmos) ? atmos : _spaceAtmos; + return _mapManager.GetMapEntity(coordinates.MapId).GetComponent(); } public override void Update(float frameTime) @@ -164,7 +184,18 @@ namespace Content.Server.GameObjects.EntitySystems return; } - GetGridAtmosphere(eventArgs.NewTile.GridIndex)?.Invalidate(eventArgs.NewTile.GridIndices); + GetGridAtmosphere(eventArgs.NewTile.GridPosition(_mapManager))?.Invalidate(eventArgs.NewTile.GridIndices); + } + + private void OnMapCreated(object? sender, MapEventArgs e) + { + if (e.Map == MapId.Nullspace) + return; + + var map = _mapManager.GetMapEntity(e.Map); + + if (!map.HasComponent()) + map.AddComponent(); } } }