PathfindingRules.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * PathfindingRules.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. struct CDestinationNodeInfo;
  13. struct PathNodeInfo;
  14. class CPathfinderHelper;
  15. class PathfinderConfig;
  16. class IPathfindingRule
  17. {
  18. public:
  19. virtual ~IPathfindingRule() = default;
  20. virtual void process(
  21. const PathNodeInfo & source,
  22. CDestinationNodeInfo & destination,
  23. const PathfinderConfig * pathfinderConfig,
  24. CPathfinderHelper * pathfinderHelper) const = 0;
  25. };
  26. class DLL_LINKAGE MovementCostRule : public IPathfindingRule
  27. {
  28. public:
  29. void process(
  30. const PathNodeInfo & source,
  31. CDestinationNodeInfo & destination,
  32. const PathfinderConfig * pathfinderConfig,
  33. CPathfinderHelper * pathfinderHelper) const override;
  34. };
  35. class DLL_LINKAGE LayerTransitionRule : public IPathfindingRule
  36. {
  37. public:
  38. void process(
  39. const PathNodeInfo & source,
  40. CDestinationNodeInfo & destination,
  41. const PathfinderConfig * pathfinderConfig,
  42. CPathfinderHelper * pathfinderHelper) const override;
  43. };
  44. class DLL_LINKAGE DestinationActionRule : public IPathfindingRule
  45. {
  46. public:
  47. void process(
  48. const PathNodeInfo & source,
  49. CDestinationNodeInfo & destination,
  50. const PathfinderConfig * pathfinderConfig,
  51. CPathfinderHelper * pathfinderHelper) const override;
  52. };
  53. class DLL_LINKAGE PathfinderBlockingRule : public IPathfindingRule
  54. {
  55. public:
  56. void process(
  57. const PathNodeInfo & source,
  58. CDestinationNodeInfo & destination,
  59. const PathfinderConfig * pathfinderConfig,
  60. CPathfinderHelper * pathfinderHelper) const override;
  61. protected:
  62. enum class BlockingReason
  63. {
  64. NONE = 0,
  65. SOURCE_GUARDED = 1,
  66. DESTINATION_GUARDED = 2,
  67. SOURCE_BLOCKED = 3,
  68. DESTINATION_BLOCKED = 4,
  69. DESTINATION_BLOCKVIS = 5,
  70. DESTINATION_VISIT = 6
  71. };
  72. virtual BlockingReason getBlockingReason(
  73. const PathNodeInfo & source,
  74. const CDestinationNodeInfo & destination,
  75. const PathfinderConfig * pathfinderConfig,
  76. const CPathfinderHelper * pathfinderHelper) const = 0;
  77. };
  78. class DLL_LINKAGE MovementAfterDestinationRule : public PathfinderBlockingRule
  79. {
  80. public:
  81. void process(
  82. const PathNodeInfo & source,
  83. CDestinationNodeInfo & destination,
  84. const PathfinderConfig * pathfinderConfig,
  85. CPathfinderHelper * pathfinderHelper) const override;
  86. protected:
  87. BlockingReason getBlockingReason(
  88. const PathNodeInfo & source,
  89. const CDestinationNodeInfo & destination,
  90. const PathfinderConfig * pathfinderConfig,
  91. const CPathfinderHelper * pathfinderHelper) const override;
  92. };
  93. class DLL_LINKAGE MovementToDestinationRule : public PathfinderBlockingRule
  94. {
  95. protected:
  96. BlockingReason getBlockingReason(
  97. const PathNodeInfo & source,
  98. const CDestinationNodeInfo & destination,
  99. const PathfinderConfig * pathfinderConfig,
  100. const CPathfinderHelper * pathfinderHelper) const override;
  101. };
  102. VCMI_LIB_NAMESPACE_END