PathPoly.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Content.Shared.NPC;
  2. using Robust.Shared.Map;
  3. namespace Content.Server.NPC.Pathfinding;
  4. public sealed class PathPoly : IEquatable<PathPoly>
  5. {
  6. [ViewVariables]
  7. public readonly EntityUid GraphUid;
  8. [ViewVariables]
  9. public readonly Vector2i ChunkOrigin;
  10. [ViewVariables]
  11. public readonly byte TileIndex;
  12. [ViewVariables]
  13. public readonly Box2 Box;
  14. [ViewVariables]
  15. public PathfindingData Data;
  16. [ViewVariables]
  17. public readonly HashSet<PathPoly> Neighbors;
  18. public PathPoly(EntityUid graphUid, Vector2i chunkOrigin, byte tileIndex, Box2 vertices, PathfindingData data, HashSet<PathPoly> neighbors)
  19. {
  20. GraphUid = graphUid;
  21. ChunkOrigin = chunkOrigin;
  22. TileIndex = tileIndex;
  23. Box = vertices;
  24. Data = data;
  25. Neighbors = neighbors;
  26. }
  27. public bool IsValid()
  28. {
  29. return (Data.Flags & PathfindingBreadcrumbFlag.Invalid) == 0x0;
  30. }
  31. [ViewVariables]
  32. public EntityCoordinates Coordinates => new(GraphUid, Box.Center);
  33. // Explicitly don't check neighbors.
  34. public bool IsEquivalent(PathPoly other)
  35. {
  36. return GraphUid.Equals(other.GraphUid) &&
  37. ChunkOrigin.Equals(other.ChunkOrigin) &&
  38. TileIndex == other.TileIndex &&
  39. Data.IsEquivalent(other.Data) &&
  40. Box.Equals(other.Box);
  41. }
  42. public bool Equals(PathPoly? other)
  43. {
  44. return other != null &&
  45. GraphUid.Equals(other.GraphUid) &&
  46. ChunkOrigin.Equals(other.ChunkOrigin) &&
  47. TileIndex == other.TileIndex &&
  48. Data.Equals(other.Data) &&
  49. Box.Equals(other.Box);
  50. }
  51. public override bool Equals(object? obj)
  52. {
  53. return ReferenceEquals(this, obj) || obj is PathPoly other && Equals(other);
  54. }
  55. public override int GetHashCode()
  56. {
  57. return HashCode.Combine(GraphUid, ChunkOrigin, TileIndex, Box);
  58. }
  59. }