1
0

Node.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Content.Server.NodeContainer.EntitySystems;
  2. using Content.Server.NodeContainer.NodeGroups;
  3. using Robust.Shared.Map;
  4. using Robust.Shared.Map.Components;
  5. namespace Content.Server.NodeContainer.Nodes
  6. {
  7. /// <summary>
  8. /// Organizes themselves into distinct <see cref="INodeGroup"/>s with other <see cref="Node"/>s
  9. /// that they can "reach" and have the same <see cref="Node.NodeGroupID"/>.
  10. /// </summary>
  11. [ImplicitDataDefinitionForInheritors]
  12. public abstract partial class Node
  13. {
  14. /// <summary>
  15. /// An ID used as a criteria for combining into groups. Determines which <see cref="INodeGroup"/>
  16. /// implementation is used as a group, detailed in <see cref="INodeGroupFactory"/>.
  17. /// </summary>
  18. [DataField("nodeGroupID")]
  19. public NodeGroupID NodeGroupID { get; private set; } = NodeGroupID.Default;
  20. /// <summary>
  21. /// The node group this node is a part of.
  22. /// </summary>
  23. [ViewVariables] public INodeGroup? NodeGroup;
  24. /// <summary>
  25. /// The entity that owns this node via its <see cref="NodeContainerComponent"/>.
  26. /// </summary>
  27. [ViewVariables] public EntityUid Owner { get; private set; } = default!;
  28. /// <summary>
  29. /// If this node should be considered for connection by other nodes.
  30. /// </summary>
  31. public virtual bool Connectable(IEntityManager entMan, TransformComponent? xform = null)
  32. {
  33. if (Deleting)
  34. return false;
  35. if (entMan.IsQueuedForDeletion(Owner))
  36. return false;
  37. if (!NeedAnchored)
  38. return true;
  39. xform ??= entMan.GetComponent<TransformComponent>(Owner);
  40. return xform.Anchored;
  41. }
  42. [ViewVariables(VVAccess.ReadWrite)]
  43. [DataField("needAnchored")]
  44. public bool NeedAnchored { get; private set; } = true;
  45. public virtual void OnAnchorStateChanged(IEntityManager entityManager, bool anchored) { }
  46. /// <summary>
  47. /// Prevents a node from being used by other nodes while midway through removal.
  48. /// </summary>
  49. public bool Deleting;
  50. /// <summary>
  51. /// All compatible nodes that are reachable by this node.
  52. /// Effectively, active connections out of this node.
  53. /// </summary>
  54. public readonly HashSet<Node> ReachableNodes = new();
  55. internal int FloodGen;
  56. internal int UndirectGen;
  57. internal bool FlaggedForFlood;
  58. internal int NetId;
  59. /// <summary>
  60. /// Name of this node on the owning <see cref="NodeContainerComponent"/>.
  61. /// </summary>
  62. public string Name = default!;
  63. /// <summary>
  64. /// Invoked when the owning <see cref="NodeContainerComponent"/> is initialized.
  65. /// </summary>
  66. /// <param name="owner">The owning entity.</param>
  67. public virtual void Initialize(EntityUid owner, IEntityManager entMan)
  68. {
  69. Owner = owner;
  70. }
  71. /// <summary>
  72. /// How this node will attempt to find other reachable <see cref="Node"/>s to group with.
  73. /// Returns a set of <see cref="Node"/>s to consider grouping with. Should not return this current <see cref="Node"/>.
  74. /// </summary>
  75. /// <remarks>
  76. /// <para>
  77. /// The set of nodes returned can be asymmetrical
  78. /// (meaning that it can return other nodes whose <see cref="GetReachableNodes"/> does not return this node).
  79. /// If this is used, creation of a new node may not correctly merge networks unless both sides
  80. /// of this asymmetric relation are made to manually update with <see cref="NodeGroupSystem.QueueReflood"/>.
  81. /// </para>
  82. /// </remarks>
  83. public abstract IEnumerable<Node> GetReachableNodes(TransformComponent xform,
  84. EntityQuery<NodeContainerComponent> nodeQuery,
  85. EntityQuery<TransformComponent> xformQuery,
  86. MapGridComponent? grid,
  87. IEntityManager entMan);
  88. }
  89. }