InjectedTile.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. namespace DunGen
  2. {
  3. /// <summary>
  4. /// Contains details about where a tile should be injected into the dungeon layout
  5. /// </summary>
  6. public sealed class InjectedTile
  7. {
  8. /// <summary>
  9. /// The tile set to choose a tile from
  10. /// </summary>
  11. public TileSet TileSet;
  12. /// <summary>
  13. /// The depth of the tile in the dungeon layout, as a percentage (0.0 - 1.0) of the main path
  14. /// </summary>
  15. public float NormalizedPathDepth;
  16. /// <summary>
  17. /// The depth of the tile as a percentage (0.0 - 1.0) along the branch it is on. Ignored if <see cref="IsOnMainPath"/> is true"/>
  18. /// </summary>
  19. public float NormalizedBranchDepth;
  20. /// <summary>
  21. /// Whether the tile should be injected on the main path or not. If false, it will be injected on a branch
  22. /// </summary>
  23. public bool IsOnMainPath;
  24. /// <summary>
  25. /// Whether the tile is required to be injected. If true, DunGen will retry generating the dungeon until this tile is successfully injected
  26. /// </summary>
  27. public bool IsRequired;
  28. /// <summary>
  29. /// Should the entrance doorway to this tile be locked?
  30. /// </summary>
  31. public bool IsLocked;
  32. /// <summary>
  33. /// If the tile should be locked, which lock (from the KeyManager asset) should be used?
  34. /// </summary>
  35. public int LockID;
  36. public InjectedTile(TileSet tileSet, bool isOnMainPath, float normalizedPathDepth, float normalizedBranchDepth, bool isRequired = false)
  37. {
  38. TileSet = tileSet;
  39. IsOnMainPath = isOnMainPath;
  40. NormalizedPathDepth = normalizedPathDepth;
  41. NormalizedBranchDepth = normalizedBranchDepth;
  42. IsRequired = isRequired;
  43. }
  44. public InjectedTile(TileInjectionRule rule, bool isOnMainPath, RandomStream randomStream)
  45. {
  46. TileSet = rule.TileSet;
  47. NormalizedPathDepth = rule.NormalizedPathDepth.GetRandom(randomStream);
  48. NormalizedBranchDepth = rule.NormalizedBranchDepth.GetRandom(randomStream);
  49. IsOnMainPath = isOnMainPath;
  50. IsRequired = rule.IsRequired;
  51. IsLocked = rule.IsLocked;
  52. LockID = rule.LockID;
  53. }
  54. public bool ShouldInjectTileAtPoint(bool isOnMainPath, float pathDepth, float branchDepth)
  55. {
  56. if (IsOnMainPath != isOnMainPath)
  57. return false;
  58. if (NormalizedPathDepth > pathDepth)
  59. return false;
  60. else if (isOnMainPath)
  61. return true;
  62. return NormalizedBranchDepth <= branchDepth;
  63. }
  64. }
  65. }