Files
Delta-v/Content.Server/Power/Nodes/CableNode.cs
T
TayrtahnandTemporalOroboros efa47d601c Update NodeHelpers and Node.GetReachableNodes to use Entity<TransformComponent> and Entity<MapGridComponent> (#37734)
* Add overloads for NodeHelpers methods, obsolete old ones

* Pass in SharedMapSystem instead of IEntityManager

* Change GetReachableNodes signature, deal with aftermath

* Allow non-grid nodes

* Change GetReachableNodes to also take Entity<TransformComponent>

* Remove vestigial ReSharper hint

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>

* Formatting

---------

Co-authored-by: TemporalOroboros <TemporalOroboros@gmail.com>
2026-06-29 12:44:03 +02:00

71 lines
2.6 KiB
C#

using Content.Server.NodeContainer.Nodes;
using Content.Shared.NodeContainer;
using Robust.Shared.Map.Components;
namespace Content.Server.Power.Nodes
{
[DataDefinition]
public sealed partial class CableNode : Node
{
public override IEnumerable<Node> GetReachableNodes(
Entity<TransformComponent> xform,
EntityQuery<NodeContainerComponent> nodeQuery,
EntityQuery<TransformComponent> xformQuery,
Entity<MapGridComponent>? grid,
IEntityManager entMan)
{
if (!xform.Comp.Anchored || grid is not { } gridEnt)
yield break;
var mapSystem = entMan.System<SharedMapSystem>();
var gridIndex = mapSystem.TileIndicesFor(gridEnt, xform.Comp.Coordinates);
// While we go over adjacent nodes, we build a list of blocked directions due to
// incoming or outgoing wire terminals.
var terminalDirs = 0;
List<(Direction, Node)> nodeDirs = new();
foreach (var (dir, node) in NodeHelpers.GetCardinalNeighborNodes(nodeQuery, gridEnt, gridIndex, mapSystem))
{
if (node is CableNode && node != this)
{
nodeDirs.Add((dir, node));
}
if (node is CableDeviceNode && dir == Direction.Invalid)
{
// device on same tile
nodeDirs.Add((Direction.Invalid, node));
}
if (node is CableTerminalNode)
{
if (dir == Direction.Invalid)
{
// On own tile, block direction it faces
terminalDirs |= 1 << (int) xformQuery.GetComponent(node.Owner).LocalRotation.GetCardinalDir();
}
else
{
var terminalDir = xformQuery.GetComponent(node.Owner).LocalRotation.GetCardinalDir();
if (terminalDir.GetOpposite() == dir)
{
// Target tile has a terminal towards us, block the direction.
terminalDirs |= 1 << (int) dir;
}
}
}
}
foreach (var (dir, node) in nodeDirs)
{
// If there is a wire terminal connecting across this direction, skip the node.
if (dir != Direction.Invalid && (terminalDirs & (1 << (int) dir)) != 0)
continue;
yield return node;
}
}
}
}