PathfindingBreadcrumb.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Robust.Shared.Serialization;
  2. namespace Content.Shared.NPC;
  3. [Serializable, NetSerializable]
  4. public struct PathfindingBreadcrumb : IEquatable<PathfindingBreadcrumb>
  5. {
  6. /// <summary>
  7. /// The X and Y index in the point grid.
  8. /// The actual coordinates require using <see cref="SharedPathfindingSystem.ChunkSize"/> and <see cref="SharedPathfindingSystem.SubStep"/>
  9. /// </summary>
  10. public Vector2i Coordinates;
  11. public PathfindingData Data;
  12. public static readonly PathfindingBreadcrumb Invalid = new()
  13. {
  14. Data = new PathfindingData(PathfindingBreadcrumbFlag.None, -1, -1, 0f),
  15. };
  16. public PathfindingBreadcrumb(Vector2i coordinates, int layer, int mask, float damage, PathfindingBreadcrumbFlag flags = PathfindingBreadcrumbFlag.None)
  17. {
  18. Coordinates = coordinates;
  19. Data = new PathfindingData(flags, layer, mask, damage);
  20. }
  21. /// <summary>
  22. /// Is this crumb equal for pathfinding region purposes.
  23. /// </summary>
  24. public bool Equivalent(PathfindingBreadcrumb other)
  25. {
  26. return Data.Equals(other.Data);
  27. }
  28. public bool Equals(PathfindingBreadcrumb other)
  29. {
  30. return Coordinates.Equals(other.Coordinates) && Data.Equals(other.Data);
  31. }
  32. public override bool Equals(object? obj)
  33. {
  34. return obj is PathfindingBreadcrumb other && Equals(other);
  35. }
  36. public override int GetHashCode()
  37. {
  38. return HashCode.Combine(Coordinates, Data);
  39. }
  40. }
  41. /// <summary>
  42. /// The data relevant for pathfinding.
  43. /// </summary>
  44. [Serializable, NetSerializable]
  45. public struct PathfindingData : IEquatable<PathfindingData>
  46. {
  47. public PathfindingBreadcrumbFlag Flags;
  48. public int CollisionLayer;
  49. public int CollisionMask;
  50. public float Damage;
  51. public bool IsFreeSpace => (Flags == PathfindingBreadcrumbFlag.None && Damage.Equals(0f));
  52. public PathfindingData(PathfindingBreadcrumbFlag flag, int layer, int mask, float damage)
  53. {
  54. Flags = flag;
  55. CollisionLayer = layer;
  56. CollisionMask = mask;
  57. Damage = damage;
  58. }
  59. public bool IsEquivalent(PathfindingData other)
  60. {
  61. return CollisionLayer.Equals(other.CollisionLayer) &&
  62. CollisionMask.Equals(other.CollisionMask) &&
  63. Flags.Equals(other.Flags);
  64. }
  65. public bool Equals(PathfindingData other)
  66. {
  67. return CollisionLayer.Equals(other.CollisionLayer) &&
  68. CollisionMask.Equals(other.CollisionMask) &&
  69. Flags.Equals(other.Flags) &&
  70. Damage.Equals(other.Damage);
  71. }
  72. public override bool Equals(object? obj)
  73. {
  74. return obj is PathfindingData other && Equals(other);
  75. }
  76. public override int GetHashCode()
  77. {
  78. return HashCode.Combine((int) Flags, CollisionLayer, CollisionMask);
  79. }
  80. }
  81. [Flags]
  82. public enum PathfindingBreadcrumbFlag : ushort
  83. {
  84. None = 0,
  85. /// <summary>
  86. /// Has this poly been replaced and is it no longer valid.
  87. /// </summary>
  88. Invalid = 1 << 0,
  89. Space = 1 << 1,
  90. /// <summary>
  91. /// Is there a door that is potentially pryable
  92. /// </summary>
  93. Door = 1 << 2,
  94. /// <summary>
  95. /// Is there access required
  96. /// </summary>
  97. Access = 1 << 3,
  98. /// <summary>
  99. /// Is there climbing involved
  100. /// </summary>
  101. Climb = 1 << 4,
  102. }