From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Thu, 23 Mar 2023 06:55:51 +0000 (+0300) Subject: allow to place tiles under directional windows (#13836) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=da7d024c37669dcbc2ee42d93684440c139def8f;p=space-station-14.git allow to place tiles under directional windows (#13836) --- diff --git a/Content.Shared/Tiles/FloorTileSystem.cs b/Content.Shared/Tiles/FloorTileSystem.cs index 1f84801e21..0e4c335476 100644 --- a/Content.Shared/Tiles/FloorTileSystem.cs +++ b/Content.Shared/Tiles/FloorTileSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Shared.Audio; using Content.Shared.Interaction; using Content.Shared.Maps; @@ -10,7 +11,7 @@ using Robust.Shared.Map.Components; using Robust.Shared.Network; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; -using Robust.Shared.Player; +using Robust.Shared.Physics.Systems; using Robust.Shared.Random; using Robust.Shared.Timing; @@ -28,6 +29,7 @@ public sealed class FloorTileSystem : EntitySystem [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedStackSystem _stackSystem = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; public override void Initialize() { @@ -48,19 +50,39 @@ public sealed class FloorTileSystem : EntitySystem // this looks a bit sussy but it might be because it needs to be able to place off of grids and expand them var location = args.ClickLocation.AlignWithClosestGridTile(); - var physics = GetEntityQuery(); - foreach (var ent in location.GetEntitiesInTile(lookupSystem: _lookup)) - { - // check that we the tile we're trying to access isn't blocked by a wall or something - if (physics.TryGetComponent(ent, out var phys) && - phys.BodyType == BodyType.Static && - phys.Hard && - (phys.CollisionLayer & (int) CollisionGroup.Impassable) != 0) - return; - } var locationMap = location.ToMap(EntityManager, _transform); if (locationMap.MapId == MapId.Nullspace) return; + + var physicQuery = GetEntityQuery(); + var transformQuery = GetEntityQuery(); + + var tilePos = location.ToMapPos(EntityManager, _transform); + var userPos = transformQuery.GetComponent(args.User).Coordinates.ToMapPos(EntityManager, _transform); + var dir = userPos - tilePos; + var canAccessCenter = false; + if (dir.LengthSquared > 0.01) + { + var ray = new CollisionRay(tilePos, dir.Normalized, (int) CollisionGroup.Impassable); + var results = _physics.IntersectRay(locationMap.MapId, ray, dir.Length, returnOnFirstHit: true); + canAccessCenter = !results.Any(); + } + + // if user can access tile center then they can place floor + // otherwise check it isn't blocked by a wall + if (!canAccessCenter) + { + foreach (var ent in location.GetEntitiesInTile(lookupSystem: _lookup)) + { + if (physicQuery.TryGetComponent(ent, out var phys) && + phys.BodyType == BodyType.Static && + phys.Hard && + (phys.CollisionLayer & (int) CollisionGroup.Impassable) != 0) + { + return; + } + } + } _mapManager.TryGetGrid(location.EntityId, out var mapGrid); foreach (var currentTile in component.OutputTiles)