From 89fff7dab2d75e3d4bc33ce69765d45c19bd65d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= Date: Tue, 11 Aug 2020 03:45:40 +0200 Subject: [PATCH] Add two new TurfHelpers --- Content.Shared/Maps/TurfHelpers.cs | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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. ///