Add two new TurfHelpers
This commit is contained in:
@@ -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.Map;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
using Robust.Shared.Interfaces.Physics;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -9,6 +12,35 @@ namespace Content.Shared.Maps
|
|||||||
{
|
{
|
||||||
public static class TurfHelpers
|
public static class TurfHelpers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to get the turf at a certain coordinates or null if no such turf is found.
|
||||||
|
/// </summary>
|
||||||
|
public static TileRef? GetTileRef(this GridCoordinates coordinates)
|
||||||
|
{
|
||||||
|
if (!coordinates.GridID.IsValid())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||||
|
|
||||||
|
if (!mapManager.TryGetGrid(coordinates.GridID, out var grid))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (!grid.TryGetTileRef(coordinates.ToMapIndices(mapManager), out var tile))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper that returns all entities in a turf.
|
||||||
|
/// </summary>
|
||||||
|
public static IEnumerable<IEntity> GetEntitiesInTile(this TileRef turf, bool approximate = false)
|
||||||
|
{
|
||||||
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
|
return entityManager.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), approximate);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if a turf has something dense on it.
|
/// Checks if a turf has something dense on it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user