Room.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace MazeGen
  5. {
  6. public enum RoomKind
  7. {
  8. Start,
  9. Normal,
  10. Hallway,
  11. Exit
  12. }
  13. /// <summary>
  14. /// A single node in the maze graph. Rooms are NOT tied to a grid - Position is a free
  15. /// world-space point derived from the exit direction + spacing of whichever exit spawned it.
  16. /// </summary>
  17. public class Room
  18. {
  19. public readonly int Id;
  20. public readonly RoomKind Kind;
  21. public readonly Vector2 Position;
  22. public readonly float Radius;
  23. public readonly int DepthFromStart;
  24. public readonly List<Exit> Exits = new List<Exit>();
  25. /// <summary>
  26. /// Set only on Hallway rooms created as a 90-degree elbow connector between two
  27. /// known doors (both straight extension and bend cases). World-space polyline the
  28. /// corridor should be rendered along - [doorA, corner, doorB] for a bend, or left
  29. /// null for hallway rooms whose far exit isn't resolved yet (ordinary lazy hallways).
  30. /// </summary>
  31. public Vector2[] CorridorWaypoints;
  32. /// <summary>
  33. /// Optional: monsters/encounter in this room (null if no encounter, or if the room
  34. /// hasn't been explored yet for encounter generation).
  35. /// </summary>
  36. public MonsterEncounter Encounter { get; set; }
  37. public Room(int id, RoomKind kind, Vector2 position, float radius, int depthFromStart)
  38. {
  39. Id = id;
  40. Kind = kind;
  41. Position = position;
  42. Radius = radius;
  43. DepthFromStart = depthFromStart;
  44. }
  45. public IEnumerable<Exit> UnusedExits => Exits.Where(e => !e.IsUsed);
  46. public bool HasUnusedExits => Exits.Any(e => !e.IsUsed);
  47. }
  48. }