DungeonJob.PostGenCorridorDecalSkirting.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System.Threading.Tasks;
  2. using Content.Shared.Doors.Components;
  3. using Content.Shared.Procedural;
  4. using Content.Shared.Procedural.PostGeneration;
  5. using Robust.Shared.Collections;
  6. using Robust.Shared.Physics.Components;
  7. using Robust.Shared.Utility;
  8. namespace Content.Server.Procedural.DungeonJob;
  9. public sealed partial class DungeonJob
  10. {
  11. /// <summary>
  12. /// <see cref="CorridorDecalSkirtingDunGen"/>
  13. /// </summary>
  14. private async Task PostGen(CorridorDecalSkirtingDunGen decks, DungeonData data, Dungeon dungeon, HashSet<Vector2i> reservedTiles, Random random)
  15. {
  16. if (!data.Colors.TryGetValue(DungeonDataKey.Decals, out var color))
  17. {
  18. _sawmill.Error(Environment.StackTrace);
  19. }
  20. var directions = new ValueList<DirectionFlag>(4);
  21. var pocketDirections = new ValueList<Direction>(4);
  22. var doorQuery = _entManager.GetEntityQuery<DoorComponent>();
  23. var physicsQuery = _entManager.GetEntityQuery<PhysicsComponent>();
  24. var offset = -_grid.TileSizeHalfVector;
  25. foreach (var tile in dungeon.CorridorTiles)
  26. {
  27. DebugTools.Assert(!dungeon.RoomTiles.Contains(tile));
  28. directions.Clear();
  29. // Do cardinals 1 step
  30. // Do corners the other step
  31. for (var i = 0; i < 4; i++)
  32. {
  33. var dir = (DirectionFlag) Math.Pow(2, i);
  34. var neighbor = tile + dir.AsDir().ToIntVec();
  35. var anc = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, neighbor);
  36. while (anc.MoveNext(out var ent))
  37. {
  38. if (!physicsQuery.TryGetComponent(ent, out var physics) ||
  39. !physics.CanCollide ||
  40. !physics.Hard ||
  41. doorQuery.HasComponent(ent.Value))
  42. {
  43. continue;
  44. }
  45. directions.Add(dir);
  46. break;
  47. }
  48. }
  49. // Pockets
  50. if (directions.Count == 0)
  51. {
  52. pocketDirections.Clear();
  53. for (var i = 1; i < 5; i++)
  54. {
  55. var dir = (Direction) (i * 2 - 1);
  56. var neighbor = tile + dir.ToIntVec();
  57. var anc = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, neighbor);
  58. while (anc.MoveNext(out var ent))
  59. {
  60. if (!physicsQuery.TryGetComponent(ent, out var physics) ||
  61. !physics.CanCollide ||
  62. !physics.Hard ||
  63. doorQuery.HasComponent(ent.Value))
  64. {
  65. continue;
  66. }
  67. pocketDirections.Add(dir);
  68. break;
  69. }
  70. }
  71. if (pocketDirections.Count == 1)
  72. {
  73. if (decks.PocketDecals.TryGetValue(pocketDirections[0], out var cDir))
  74. {
  75. // Decals not being centered biting my ass again
  76. var gridPos = _maps.GridTileToLocal(_gridUid, _grid, tile).Offset(offset);
  77. _decals.TryAddDecal(cDir, gridPos, out _, color: color);
  78. }
  79. }
  80. continue;
  81. }
  82. if (directions.Count == 1)
  83. {
  84. if (decks.CardinalDecals.TryGetValue(directions[0], out var cDir))
  85. {
  86. // Decals not being centered biting my ass again
  87. var gridPos = _maps.GridTileToLocal(_gridUid, _grid, tile).Offset(offset);
  88. _decals.TryAddDecal(cDir, gridPos, out _, color: color);
  89. }
  90. continue;
  91. }
  92. // Corners
  93. if (directions.Count == 2)
  94. {
  95. // Auehghegueugegegeheh help me
  96. var dirFlag = directions[0] | directions[1];
  97. if (decks.CornerDecals.TryGetValue(dirFlag, out var cDir))
  98. {
  99. var gridPos = _maps.GridTileToLocal(_gridUid, _grid, tile).Offset(offset);
  100. _decals.TryAddDecal(cDir, gridPos, out _, color: color);
  101. }
  102. }
  103. }
  104. }
  105. }