From 350ce8e297453df9159f7118bda6a116ca5c768d Mon Sep 17 00:00:00 2001 From: haiwwkes <49613070+rhailrake@users.noreply.github.com> Date: Tue, 22 Oct 2024 23:19:41 +0500 Subject: [PATCH] aaaaaaaaaaaaaaaaaaaaaaaaaaaaa (#743) --- Content.Shared/RCD/Systems/RCDSystem.cs | 71 +++++++++++++++---------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/Content.Shared/RCD/Systems/RCDSystem.cs b/Content.Shared/RCD/Systems/RCDSystem.cs index df1290d100..6dea49a385 100644 --- a/Content.Shared/RCD/Systems/RCDSystem.cs +++ b/Content.Shared/RCD/Systems/RCDSystem.cs @@ -400,46 +400,63 @@ public class RCDSystem : EntitySystem } // Entity specific rules - - // Check rule: The tile is unoccupied - var isWindow = component.CachedPrototype.ConstructionRules.Contains(RcdConstructionRule.IsWindow); - var isCatwalk = component.CachedPrototype.ConstructionRules.Contains(RcdConstructionRule.IsCatwalk); - - _intersectingEntities.Clear(); - _lookup.GetLocalEntitiesIntersecting(mapGridData.GridUid, mapGridData.Position, _intersectingEntities, -0.05f, LookupFlags.Uncontained); - - foreach (var ent in _intersectingEntities) + if (component.CachedPrototype.Mode == RcdMode.ConstructObject) { - if (isWindow && HasComp(ent)) - continue; + // Check for existing identical entities in the same tile + _intersectingEntities.Clear(); + _lookup.GetLocalEntitiesIntersecting(mapGridData.GridUid, mapGridData.Position, _intersectingEntities, -0.05f, LookupFlags.Uncontained); - if (isCatwalk && _tags.HasTag(ent, "Catwalk")) + if (component.CachedPrototype.Prototype != null) { - if (popMsgs) - _popup.PopupClient(Loc.GetString("rcd-component-cannot-build-on-occupied-tile-message"), uid, user); + foreach (var entity in _intersectingEntities) + { + // Check if the entity has the same prototype ID + if (MetaData(entity).EntityPrototype?.ID == component.CachedPrototype.Prototype) + { + if (popMsgs) + _popup.PopupClient("An identical object already exists in this location.", uid, user); - return false; + return false; + } + } } - if (component.CachedPrototype.CollisionMask != CollisionGroup.None && TryComp(ent, out var fixtures)) + var isWindow = component.CachedPrototype.ConstructionRules.Contains(RcdConstructionRule.IsWindow); + var isCatwalk = component.CachedPrototype.ConstructionRules.Contains(RcdConstructionRule.IsCatwalk); + + foreach (var ent in _intersectingEntities) { - foreach (var fixture in fixtures.Fixtures.Values) + if (isWindow && HasComp(ent)) + continue; + + if (isCatwalk && _tags.HasTag(ent, "Catwalk")) { - // Continue if no collision is possible - if (!fixture.Hard || fixture.CollisionLayer <= 0 || (fixture.CollisionLayer & (int) component.CachedPrototype.CollisionMask) == 0) - continue; - - // Continue if our custom collision bounds are not intersected - if (component.CachedPrototype.CollisionPolygon != null && - !DoesCustomBoundsIntersectWithFixture(component.CachedPrototype.CollisionPolygon, component.ConstructionTransform, ent, fixture)) - continue; - - // Collision was detected if (popMsgs) _popup.PopupClient(Loc.GetString("rcd-component-cannot-build-on-occupied-tile-message"), uid, user); return false; } + + if (component.CachedPrototype.CollisionMask != CollisionGroup.None && TryComp(ent, out var fixtures)) + { + foreach (var fixture in fixtures.Fixtures.Values) + { + // Continue if no collision is possible + if (!fixture.Hard || fixture.CollisionLayer <= 0 || (fixture.CollisionLayer & (int) component.CachedPrototype.CollisionMask) == 0) + continue; + + // Continue if our custom collision bounds are not intersected + if (component.CachedPrototype.CollisionPolygon != null && + !DoesCustomBoundsIntersectWithFixture(component.CachedPrototype.CollisionPolygon, component.ConstructionTransform, ent, fixture)) + continue; + + // Collision was detected + if (popMsgs) + _popup.PopupClient(Loc.GetString("rcd-component-cannot-build-on-occupied-tile-message"), uid, user); + + return false; + } + } } }