diff --git a/Content.IntegrationTests/Tests/Atmos/GetAirflowDirectionsTest.cs b/Content.IntegrationTests/Tests/Atmos/GetAirflowDirectionsTest.cs new file mode 100644 index 00000000000..4677cc5f7ee --- /dev/null +++ b/Content.IntegrationTests/Tests/Atmos/GetAirflowDirectionsTest.cs @@ -0,0 +1,50 @@ +using Content.Server.Atmos.EntitySystems; +using Content.Shared.Atmos; +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Maths; +using Robust.Shared.Utility; + +namespace Content.IntegrationTests.Tests.Atmos; + +/// +/// Class for testing some airflow retrieval API methods. +/// +public sealed class GetAirflowDirectionsTest : AtmosTest +{ + // i will keep using this test map until it has been drained + // of all use + protected override ResPath? TestMapPath => new("Maps/Test/Atmospherics/DeltaPressure/deltapressuretest.yml"); + + [Test] + [TestCase(0, 0, AtmosDirection.All)] + [TestCase(0, 1, AtmosDirection.South)] + [TestCase(0, -1, AtmosDirection.North)] + [TestCase(1, 0, AtmosDirection.West)] + [TestCase(-1, 0, AtmosDirection.East)] + [TestCase(1, 1, AtmosDirection.Invalid)] + [TestCase(100, 100, AtmosDirection.Invalid)] + public async Task TestLookup(int x, int y, AtmosDirection expectedDirections) + { + await Server.WaitPost(delegate + { + // yea + var coords = new Vector2i(x, y); + var directions = SAtmos.GetAirflowDirections(RelevantAtmos, coords); + Assert.That(directions, Is.EqualTo(expectedDirections)); + }); + } + + /// + /// Tests that a grident with no atmosphere will return . + /// + [Test] + public async Task TestLookup_BadEnt() + { + await Server.WaitPost(delegate + { + var directions = SAtmos.GetAirflowDirections(EntityUid.Invalid, Vector2i.Zero); + Assert.That(directions, Is.EqualTo(AtmosDirection.Invalid)); + }); + } +} diff --git a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs index e2e39abdda9..8c28fe0bcf0 100644 --- a/Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs +++ b/Content.Server/Atmos/EntitySystems/AtmosphereSystem.API.cs @@ -350,6 +350,29 @@ public partial class AtmosphereSystem return atmosTile.AirtightData.BlockedDirections.IsFlagSet(directions); } + /// + /// Returns the for a tile on a grid. + /// This represents the directions that the air can currently flow to. + /// + /// The grid entity that the tile belongs to. + /// The coordinates to check. + /// The of the tile, + /// if the grid or tile couldn't be found. + /// Note that this data is cached and is updated at the beginning of every atmostick. + /// As such, any airtight changes that were made may not be reflected in this value until + /// the cache is refreshed in the next processing tick. + [PublicAPI] + public AtmosDirection GetAirflowDirections(Entity grid, Vector2i tile) + { + if (!_atmosQuery.Resolve(grid, ref grid.Comp, false)) + return AtmosDirection.Invalid; + + if (!grid.Comp.Tiles.TryGetValue(tile, out var atmosTile)) + return AtmosDirection.Invalid; + + return atmosTile.AdjacentBits; + } + /// /// Checks if a tile on a grid or map is space as defined by a tile's definition of space. /// Some tiles can hold back space and others cannot - for example, plating can hold