diff --git a/Content.Shared/_CP14/Wallmount/CP14WallRequired.cs b/Content.Shared/_CP14/Wallmount/CP14WallRequired.cs new file mode 100644 index 0000000000..d912f8a87d --- /dev/null +++ b/Content.Shared/_CP14/Wallmount/CP14WallRequired.cs @@ -0,0 +1,48 @@ +using Content.Shared.Construction; +using Content.Shared.Construction.Conditions; +using Content.Shared.Tag; +using JetBrains.Annotations; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; + +namespace Content.Shared._CP14.Wallmount; + +[UsedImplicitly] +[DataDefinition] +public sealed partial class CP14WallRequired : IConstructionCondition +{ + public ConstructionGuideEntry GenerateGuideEntry() + { + return new ConstructionGuideEntry + { + Localization = "cp14-construction-step-condition-wall-required", + }; + } + + public bool Condition(EntityUid user, EntityCoordinates location, Direction direction) + { + var entityManager = IoCManager.Resolve(); + var mapSystem = entityManager.System(); + var transformSystem = entityManager.System(); + var tagSystem = entityManager.System(); + var grid = transformSystem.GetGrid(user); + + if (grid == null || !entityManager.TryGetComponent(grid, out var gridComp)) + return false; + + var offset = direction.ToAngle().ToWorldVec(); + var targetPos = location.Offset(-offset); + var anchored = mapSystem.GetAnchoredEntities(grid.Value, gridComp, targetPos); + + bool hasParent = false; + foreach (var entt in anchored) + { + if (!tagSystem.HasAnyTag(entt, CP14WallmountSystem.WallTags)) + continue; + + return true; + } + + return false; + } +} diff --git a/Content.Shared/_CP14/Wallmount/CP14WallmountComponent.cs b/Content.Shared/_CP14/Wallmount/CP14WallmountComponent.cs new file mode 100644 index 0000000000..ce13734d1c --- /dev/null +++ b/Content.Shared/_CP14/Wallmount/CP14WallmountComponent.cs @@ -0,0 +1,9 @@ +namespace Content.Shared._CP14.Wallmount; + +/// +/// Automatically attaches the entity to the wall when it appears, or removes it +/// +[RegisterComponent, Access(typeof(CP14WallmountSystem))] +public sealed partial class CP14WallmountComponent : Component +{ +} diff --git a/Content.Shared/_CP14/Wallmount/CP14WallmountSystem.cs b/Content.Shared/_CP14/Wallmount/CP14WallmountSystem.cs new file mode 100644 index 0000000000..f440b6c062 --- /dev/null +++ b/Content.Shared/_CP14/Wallmount/CP14WallmountSystem.cs @@ -0,0 +1,47 @@ +using Content.Shared.Tag; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; + +namespace Content.Shared._CP14.Wallmount; + +public sealed class CP14WallmountSystem : EntitySystem +{ + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedMapSystem _map = default!; + [Dependency] private readonly TagSystem _tag = default!; + + public static readonly ProtoId[] WallTags = {"Wall", "Window"}; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMapInit); + } + + private void OnMapInit(Entity ent, ref MapInitEvent args) + { + var grid = Transform(ent).GridUid; + if (grid == null || !TryComp(grid, out var gridComp)) + return; + + //Try found a wall in neighbour tile + var offset = Transform(ent).LocalRotation.ToWorldVec(); + var targetPos = new EntityCoordinates(grid.Value,Transform(ent).LocalPosition - offset); + var anchored = _map.GetAnchoredEntities(grid.Value, gridComp, targetPos); + + bool hasParent = false; + foreach (var entt in anchored) + { + if (!_tag.HasAnyTag(entt, WallTags)) + continue; + + _transform.SetParent(ent, entt); + hasParent = true; + break; + } + if (!hasParent) + QueueDel(ent); + } +} diff --git a/Resources/Locale/en-US/_CP14/construction/wall-required.ftl b/Resources/Locale/en-US/_CP14/construction/wall-required.ftl new file mode 100644 index 0000000000..3f7636e0a8 --- /dev/null +++ b/Resources/Locale/en-US/_CP14/construction/wall-required.ftl @@ -0,0 +1 @@ +cp14-construction-step-condition-wall-required = Wall required. \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_CP14/construction/wall-required.ftl b/Resources/Locale/ru-RU/_CP14/construction/wall-required.ftl new file mode 100644 index 0000000000..df03ee4acc --- /dev/null +++ b/Resources/Locale/ru-RU/_CP14/construction/wall-required.ftl @@ -0,0 +1 @@ +cp14-construction-step-condition-wall-required = Необходима опора. \ No newline at end of file diff --git a/Resources/Prototypes/Tiles/space.yml b/Resources/Prototypes/Tiles/space.yml index c6e38cbcc8..f579585a6b 100644 --- a/Resources/Prototypes/Tiles/space.yml +++ b/Resources/Prototypes/Tiles/space.yml @@ -1,4 +1,5 @@ - type: tile + editorHidden: false id: Space name: tiles-space friction: 0 diff --git a/Resources/Prototypes/_CP14/Entities/Structures/Furniture/wallmount.yml b/Resources/Prototypes/_CP14/Entities/Structures/Furniture/wallmount.yml index 1970c08299..a3a23960ea 100644 --- a/Resources/Prototypes/_CP14/Entities/Structures/Furniture/wallmount.yml +++ b/Resources/Prototypes/_CP14/Entities/Structures/Furniture/wallmount.yml @@ -10,6 +10,7 @@ - type: InteractionOutline - type: Sprite drawdepth: Mobs + - type: CP14Wallmount - type: entity id: CP14WallmountTorch diff --git a/Resources/Prototypes/_CP14/Recipes/Construction/furniture.yml b/Resources/Prototypes/_CP14/Recipes/Construction/furniture.yml index 80c141e4a8..b57d98581f 100644 --- a/Resources/Prototypes/_CP14/Recipes/Construction/furniture.yml +++ b/Resources/Prototypes/_CP14/Recipes/Construction/furniture.yml @@ -62,14 +62,15 @@ targetNode: CP14WallmountTorch category: construction-category-furniture icon: - sprite: _CP14/Structures/Wallmount/wallmount_32icon.rsi - state: torch + sprite: _CP14/Structures/Furniture/wallmount_torch.rsi + state: fire objectType: Structure placementMode: SnapgridCenter canBuildInImpassable: false canRotate: true conditions: - !type:TileNotBlocked + - !type:CP14WallRequired - type: construction crystallPunkAllowed: true