Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Pipe stacks #1017

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions Content.Server/Atmos/EntitySystems/PipeRestrictOverlapSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using Content.Server.NodeContainer.Nodes;
using Content.Server.Popups;
using Content.Shared.Atmos;
using Content.Shared.Backmen.CCVar; // backmen: pipe stacks
using Content.Shared.Construction.Components;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using Robust.Shared.Map.Components;

namespace Content.Server.Atmos.EntitySystems;
Expand All @@ -16,18 +18,21 @@ namespace Content.Server.Atmos.EntitySystems;
/// </summary>
public sealed class PipeRestrictOverlapSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!; // backmen: pipe stacks
[Dependency] private readonly MapSystem _map = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly TransformSystem _xform = default!;

private readonly List<EntityUid> _anchoredEntities = new();
private EntityQuery<NodeContainerComponent> _nodeContainerQuery;
public bool StrictPipeStacking; // backmen: pipe stacks

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<PipeRestrictOverlapComponent, AnchorStateChangedEvent>(OnAnchorStateChanged);
SubscribeLocalEvent<PipeRestrictOverlapComponent, AnchorAttemptEvent>(OnAnchorAttempt);
Subs.CVar(_cfg, CCVars.StrictPipeStacking, (val) => {StrictPipeStacking = val;}); // backmen: pipe stacks

_nodeContainerQuery = GetEntityQuery<NodeContainerComponent>();
}
Expand Down Expand Up @@ -78,6 +83,8 @@ public bool CheckOverlap(Entity<NodeContainerComponent, TransformComponent> ent)
_anchoredEntities.Clear();
_map.GetAnchoredEntities((grid, gridComp), indices, _anchoredEntities);

var takenDirs = PipeDirection.None; // backmen: pipe stacks

foreach (var otherEnt in _anchoredEntities)
{
// this should never actually happen but just for safety
Expand All @@ -87,28 +94,46 @@ public bool CheckOverlap(Entity<NodeContainerComponent, TransformComponent> ent)
if (!_nodeContainerQuery.TryComp(otherEnt, out var otherComp))
continue;

if (PipeNodesOverlap(ent, (otherEnt, otherComp, Transform(otherEnt))))
// start-backmen: pipe stacks
var (overlapping, which) = PipeNodesOverlap(ent, (otherEnt, otherComp, Transform(otherEnt)), takenDirs);
takenDirs |= which;

if (overlapping)
return true;
// end-backmen: pipe stacks
}

return false;
}

public bool PipeNodesOverlap(Entity<NodeContainerComponent, TransformComponent> ent, Entity<NodeContainerComponent, TransformComponent> other)
// start-backmen: pipe stacks
public (bool, PipeDirection) PipeNodesOverlap(Entity<NodeContainerComponent, TransformComponent> ent, Entity<NodeContainerComponent, TransformComponent> other, PipeDirection takenDirs)
{
var entDirs = GetAllDirections(ent).ToList();
var otherDirs = GetAllDirections(other).ToList();
var entDirsCollapsed = PipeDirection.None;

foreach (var dir in entDirs)
{
entDirsCollapsed |= dir;
foreach (var otherDir in otherDirs)
{
takenDirs |= otherDir;
if (!StrictPipeStacking)
continue;

if ((dir & otherDir) != 0)
return true;
return (true, takenDirs);

if ((dir ^ otherDir) != 0)
break;
}
}

return false;
// If no strict pipe stacking, then output ("are all entDirs occupied", takenDirs)
return (!StrictPipeStacking && (takenDirs & entDirsCollapsed) == entDirsCollapsed, takenDirs);

// end-backmen: pipe stacks

IEnumerable<PipeDirection> GetAllDirections(Entity<NodeContainerComponent, TransformComponent> pipe)
{
Expand Down
10 changes: 10 additions & 0 deletions Content.Shared/Backmen/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<bool> HoldLookUp =
CVarDef.Create("white.hold_look_up", false, CVar.CLIENT | CVar.ARCHIVE);

/*
Atmos
*/
/// <summary>
/// Whether pipes will unanchor on ANY conflicting connection. May break maps.
/// If false, allows you to stack pipes as long as new directions are added (i.e. in a new pipe rotation, layer or multi-Z link), otherwise unanchoring them.
/// </summary>
public static readonly CVarDef<bool> StrictPipeStacking =
CVarDef.Create("atmos.strict_pipe_stacking", false, CVar.SERVERONLY);

#region Supermatter System

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
- type: PipeColorVisuals
- type: Rotatable
- type: GasRecycler
- type: PipeRestrictOverlap
# backmen - Allow device-on-pipe stacking
# - type: PipeRestrictOverlap
- type: NodeContainer
nodes:
inlet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
- type: Appearance
- type: PipeColorVisuals
- type: NodeContainer
- type: PipeRestrictOverlap
# backmen - Allow device-on-pipe stacking
# - type: PipeRestrictOverlap
- type: AtmosUnsafeUnanchor
- type: AtmosPipeColor
- type: AtmosMonitoringConsoleDevice
Expand All @@ -64,10 +65,19 @@
- type: StaticPrice
price: 30

# backmen - Allow device-on-pipe stacking
- type: entity
abstract: true
parent: GasPipeBase
id: GasPipeNoOverlap
components:
- type: PipeRestrictOverlap

#Note: The PipeDirection of the PipeNode should be the south-facing version, because the entity starts at an angle of 0 (south)

- type: entity
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
id: GasPipeHalf
suffix: Half
components:
Expand All @@ -86,7 +96,8 @@
node: half

- type: entity
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
id: GasPipeStraight
suffix: Straight
components:
Expand Down Expand Up @@ -119,7 +130,8 @@
collection: MetalThud # this NEEDS to changed to the metal pipe falling sound effect on april first every year

- type: entity
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
id: GasPipeBend
suffix: Bend
components:
Expand Down Expand Up @@ -159,7 +171,8 @@
Blunt: 8 # Woe, pipe be upon ye!

- type: entity
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
id: GasPipeTJunction
suffix: TJunction
components:
Expand Down Expand Up @@ -195,7 +208,8 @@
collection: MetalThud

- type: entity
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
id: GasPipeFourway
suffix: Fourway
components:
Expand Down Expand Up @@ -231,7 +245,8 @@

- type: entity
id: GasPipeBroken
parent: GasPipeBase
# backmen - Allow device-on-pipe stacking
parent: GasPipeNoOverlap
name: broken pipe
description: It used to hold gas.
components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
key: enum.ThermomachineUiKey.Key
- type: WiresPanel
- type: WiresVisuals
- type: PipeRestrictOverlap
# backmen - Allow device-on-pipe stacking
# - type: PipeRestrictOverlap
- type: NodeContainer
nodes:
pipe:
Expand Down Expand Up @@ -394,7 +395,8 @@
- type: GasCondenser
- type: AtmosPipeColor
- type: AtmosDevice
- type: PipeRestrictOverlap
# backmen - Allow device-on-pipe stacking
# - type: PipeRestrictOverlap
- type: ApcPowerReceiver
powerLoad: 10000
- type: Machine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
nodeGroupID: Teg

- type: AtmosUnsafeUnanchor
- type: PipeRestrictOverlap
# backmen - Allow device-on-pipe stacking
# - type: PipeRestrictOverlap
- type: TegCirculator
- type: StealTarget
stealGroup: Teg
Expand Down
Loading