From 801c48fba87234d512bd155c56f08e6f8f382938 Mon Sep 17 00:00:00 2001 From: Acruid Date: Thu, 6 Aug 2020 22:02:13 -0700 Subject: [PATCH] Added a turf helper function IsBlockedTurf() for Ike. --- Content.Shared/Maps/TurfHelpers.cs | 56 ++++++++++++++++++++++++++++++ RobustToolbox | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Content.Shared/Maps/TurfHelpers.cs diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs new file mode 100644 index 0000000000..549a1517dd --- /dev/null +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -0,0 +1,56 @@ +using Content.Shared.Physics; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.Interfaces.Physics; +using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Maths; + +namespace Content.Shared.Maps +{ + public static class TurfHelpers + { + /// + /// Checks if a turf has something dense on it. + /// + public static bool IsBlockedTurf(this TileRef turf, bool filterMobs) + { + var physics = IoCManager.Resolve(); + + var worldBox = GetWorldTileBox(turf); + + var query = physics.GetCollidingEntities(turf.MapIndex, in worldBox); + + foreach (var body in query) + { + if (body.CanCollide && body.Hard && (body.CollisionLayer & (int) CollisionGroup.Impassable) != 0) + return false; + + if (filterMobs && (body.CollisionLayer & (int) CollisionGroup.MobMask) != 0) + return false; + } + + return true; + } + + /// + /// Creates a box the size of a tile, at the same position in the world as the tile. + /// + private static Box2 GetWorldTileBox(TileRef turf) + { + var map = IoCManager.Resolve(); + var tileGrid = map.GetGrid(turf.GridIndex); + var tileBox = Box2.UnitCentered.Scale(tileGrid.TileSize); + return tileBox.Translated(tileGrid.GridTileToWorldPos(turf.GridIndices)); + } + + /// + /// Creates a box the size of a tile. + /// + private static Box2 GetTileBox(this TileRef turf) + { + var map = IoCManager.Resolve(); + var tileGrid = map.GetGrid(turf.GridIndex); + return Box2.UnitCentered.Scale(tileGrid.TileSize); + } + } +} diff --git a/RobustToolbox b/RobustToolbox index e5ae2182b0..5d2e3a4c61 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit e5ae2182b0c31cc065c60b1ebc540dca0c73adf5 +Subproject commit 5d2e3a4c6158e1960d1ac25669385937932e68b8