NavMapComponent.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Linq;
  2. using Content.Shared.Atmos;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Serialization;
  5. using Robust.Shared.Timing;
  6. namespace Content.Shared.Pinpointer;
  7. /// <summary>
  8. /// Used to store grid data to be used for UIs.
  9. /// </summary>
  10. [RegisterComponent, NetworkedComponent]
  11. public sealed partial class NavMapComponent : Component
  12. {
  13. /*
  14. * Don't need DataFields as this can be reconstructed
  15. */
  16. /// <summary>
  17. /// Bitmasks that represent chunked tiles.
  18. /// </summary>
  19. [ViewVariables]
  20. public Dictionary<Vector2i, NavMapChunk> Chunks = new();
  21. /// <summary>
  22. /// List of station beacons.
  23. /// </summary>
  24. [ViewVariables]
  25. public Dictionary<NetEntity, SharedNavMapSystem.NavMapBeacon> Beacons = new();
  26. /// <summary>
  27. /// Describes the properties of a region on the station.
  28. /// It is indexed by the entity assigned as the region owner.
  29. /// </summary>
  30. [ViewVariables(VVAccess.ReadOnly)]
  31. public Dictionary<NetEntity, SharedNavMapSystem.NavMapRegionProperties> RegionProperties = new();
  32. /// <summary>
  33. /// All flood filled regions, ready for display on a NavMapControl.
  34. /// It is indexed by the entity assigned as the region owner.
  35. /// </summary>
  36. /// <remarks>
  37. /// For client use only
  38. /// </remarks>
  39. [ViewVariables(VVAccess.ReadOnly)]
  40. public Dictionary<NetEntity, NavMapRegionOverlay> RegionOverlays = new();
  41. /// <summary>
  42. /// A queue of all region owners that are waiting their associated regions to be floodfilled.
  43. /// </summary>
  44. /// <remarks>
  45. /// For client use only
  46. /// </remarks>
  47. [ViewVariables(VVAccess.ReadOnly)]
  48. public Queue<NetEntity> QueuedRegionsToFlood = new();
  49. /// <summary>
  50. /// A look up table to get a list of region owners associated with a flood filled chunk.
  51. /// </summary>
  52. /// <remarks>
  53. /// For client use only
  54. /// </remarks>
  55. [ViewVariables(VVAccess.ReadOnly)]
  56. public Dictionary<Vector2i, HashSet<NetEntity>> ChunkToRegionOwnerTable = new();
  57. /// <summary>
  58. /// A look up table to find flood filled chunks associated with a given region owner.
  59. /// </summary>
  60. /// <remarks>
  61. /// For client use only
  62. /// </remarks>
  63. [ViewVariables(VVAccess.ReadOnly)]
  64. public Dictionary<NetEntity, HashSet<Vector2i>> RegionOwnerToChunkTable = new();
  65. }
  66. [Serializable, NetSerializable]
  67. public sealed class NavMapChunk(Vector2i origin)
  68. {
  69. /// <summary>
  70. /// The chunk origin
  71. /// </summary>
  72. [ViewVariables]
  73. public readonly Vector2i Origin = origin;
  74. /// <summary>
  75. /// Array containing the chunk's data. The
  76. /// </summary>
  77. [ViewVariables]
  78. public int[] TileData = new int[SharedNavMapSystem.ArraySize];
  79. /// <summary>
  80. /// The last game tick that the chunk was updated
  81. /// </summary>
  82. [NonSerialized]
  83. public GameTick LastUpdate;
  84. }
  85. [Serializable, NetSerializable]
  86. public sealed class NavMapRegionOverlay(Enum uiKey, List<(Vector2i, Vector2i)> gridCoords)
  87. {
  88. /// <summary>
  89. /// The key to the UI that will be displaying this region on its navmap
  90. /// </summary>
  91. public Enum UiKey = uiKey;
  92. /// <summary>
  93. /// The local grid coordinates of the rectangles that make up the region
  94. /// Item1 is the top left corner, Item2 is the bottom right corner
  95. /// </summary>
  96. public List<(Vector2i, Vector2i)> GridCoords = gridCoords;
  97. /// <summary>
  98. /// Color of the region
  99. /// </summary>
  100. public Color Color = Color.White;
  101. }
  102. public enum NavMapChunkType : byte
  103. {
  104. // Values represent bit shift offsets when retrieving data in the tile array.
  105. Invalid = byte.MaxValue,
  106. Floor = 0, // I believe floors have directional information for diagonal tiles?
  107. Wall = SharedNavMapSystem.Directions,
  108. Airlock = 2 * SharedNavMapSystem.Directions,
  109. }