using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.NodeGroups;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Server.NodeContainer.Nodes
{
///
/// Organizes themselves into distinct s with other s
/// that they can "reach" and have the same .
///
[ImplicitDataDefinitionForInheritors]
public abstract class Node
{
///
/// An ID used as a criteria for combining into groups. Determines which
/// implementation is used as a group, detailed in .
///
[DataField("nodeGroupID")]
public NodeGroupID NodeGroupID { get; private set; } = NodeGroupID.Default;
///
/// The node group this node is a part of.
///
[ViewVariables] public INodeGroup? NodeGroup;
///
/// The entity that owns this node via its .
///
[ViewVariables] public EntityUid Owner { get; private set; } = default!;
///
/// If this node should be considered for connection by other nodes.
///
public virtual bool Connectable(IEntityManager entMan, TransformComponent? xform = null)
{
if (Deleting)
return false;
if (entMan.IsQueuedForDeletion(Owner))
return false;
if (!NeedAnchored)
return true;
xform ??= entMan.GetComponent(Owner);
return xform.Anchored;
}
[ViewVariables(VVAccess.ReadWrite)]
[DataField("needAnchored")]
public bool NeedAnchored { get; } = true;
public virtual void OnAnchorStateChanged(IEntityManager entityManager, bool anchored) { }
///
/// Prevents a node from being used by other nodes while midway through removal.
///
public bool Deleting;
///
/// All compatible nodes that are reachable by this node.
/// Effectively, active connections out of this node.
///
public readonly HashSet ReachableNodes = new();
internal int FloodGen;
internal int UndirectGen;
internal bool FlaggedForFlood;
internal int NetId;
///
/// Name of this node on the owning .
///
public string Name = default!;
///
/// Invoked when the owning is initialized.
///
/// The owning entity.
public virtual void Initialize(EntityUid owner, IEntityManager entMan)
{
Owner = owner;
}
///
/// How this node will attempt to find other reachable s to group with.
/// Returns a set of s to consider grouping with. Should not return this current .
///
///
///
/// The set of nodes returned can be asymmetrical
/// (meaning that it can return other nodes whose does not return this node).
/// If this is used, creation of a new node may not correctly merge networks unless both sides
/// of this asymmetric relation are made to manually update with .
///
///
public abstract IEnumerable GetReachableNodes(TransformComponent xform,
EntityQuery nodeQuery,
EntityQuery xformQuery,
MapGridComponent? grid,
IEntityManager entMan);
}
}