diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index 549a1517dd..1f81bc6f8f 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -1,4 +1,7 @@ -using Content.Shared.Physics; +#nullable enable +using System.Collections.Generic; +using Content.Shared.Physics; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Physics; using Robust.Shared.IoC; @@ -9,6 +12,35 @@ namespace Content.Shared.Maps { public static class TurfHelpers { + /// + /// Attempts to get the turf at a certain coordinates or null if no such turf is found. + /// + public static TileRef? GetTileRef(this GridCoordinates coordinates) + { + if (!coordinates.GridID.IsValid()) + return null; + + var mapManager = IoCManager.Resolve(); + + if (!mapManager.TryGetGrid(coordinates.GridID, out var grid)) + return null; + + if (!grid.TryGetTileRef(coordinates.ToMapIndices(mapManager), out var tile)) + return null; + + return tile; + } + + /// + /// Helper that returns all entities in a turf. + /// + public static IEnumerable GetEntitiesInTile(this TileRef turf, bool approximate = false) + { + var entityManager = IoCManager.Resolve(); + + return entityManager.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), approximate); + } + /// /// Checks if a turf has something dense on it. ///