CPathfinder.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * CPathfinder.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. #include "CGPathNode.h"
  12. #include "../IGameCallback.h"
  13. #include "../bonuses/BonusEnum.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGWhirlpool;
  16. struct TurnInfo;
  17. struct PathfinderOptions;
  18. class DLL_LINKAGE CPathfinder
  19. {
  20. public:
  21. friend class CPathfinderHelper;
  22. CPathfinder(
  23. CGameState * _gs,
  24. std::shared_ptr<PathfinderConfig> config);
  25. void calculatePaths(); //calculates possible paths for hero, uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists
  26. private:
  27. CGameState * gamestate;
  28. using ELayer = EPathfindingLayer;
  29. std::shared_ptr<PathfinderConfig> config;
  30. boost::heap::fibonacci_heap<CGPathNode *, boost::heap::compare<NodeComparer<CGPathNode>> > pq;
  31. PathNodeInfo source; //current (source) path node -> we took it from the queue
  32. CDestinationNodeInfo destination; //destination node -> it's a neighbour of source that we consider
  33. bool isLayerTransitionPossible() const;
  34. EPathNodeAction getTeleportDestAction() const;
  35. bool isDestinationGuardian() const;
  36. void initializeGraph();
  37. STRONG_INLINE
  38. void push(CGPathNode * node);
  39. STRONG_INLINE
  40. CGPathNode * topAndPop();
  41. };
  42. class DLL_LINKAGE CPathfinderHelper : private CGameInfoCallback
  43. {
  44. public:
  45. enum EPatrolState
  46. {
  47. PATROL_NONE = 0,
  48. PATROL_LOCKED = 1,
  49. PATROL_RADIUS
  50. } patrolState;
  51. std::unordered_set<int3> patrolTiles;
  52. int turn;
  53. PlayerColor owner;
  54. const CGHeroInstance * hero;
  55. std::vector<TurnInfo *> turnsInfo;
  56. const PathfinderOptions & options;
  57. bool canCastFly;
  58. bool canCastWaterWalk;
  59. CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options);
  60. virtual ~CPathfinderHelper();
  61. void initializePatrol();
  62. bool isHeroPatrolLocked() const;
  63. bool canMoveFromNode(const PathNodeInfo & source) const;
  64. bool isPatrolMovementAllowed(const int3 & dst) const;
  65. void updateTurnInfo(const int turn = 0);
  66. bool isLayerAvailable(const EPathfindingLayer & layer) const;
  67. const TurnInfo * getTurnInfo() const;
  68. bool hasBonusOfType(BonusType type) const;
  69. int getMaxMovePoints(const EPathfindingLayer & layer) const;
  70. std::vector<int3> getCastleGates(const PathNodeInfo & source) const;
  71. bool isAllowedTeleportEntrance(const CGTeleport * obj) const;
  72. std::vector<int3> getAllowedTeleportChannelExits(const TeleportChannelID & channelID) const;
  73. bool addTeleportTwoWay(const CGTeleport * obj) const;
  74. bool addTeleportOneWay(const CGTeleport * obj) const;
  75. bool addTeleportOneWayRandom(const CGTeleport * obj) const;
  76. bool addTeleportWhirlpool(const CGWhirlpool * obj) const;
  77. bool canMoveBetween(const int3 & a, const int3 & b) const; //checks only for visitable objects that may make moving between tiles impossible, not other conditions (like tiles itself accessibility)
  78. void calculateNeighbourTiles(std::vector<int3> & result, const PathNodeInfo & source) const;
  79. std::vector<int3> getTeleportExits(const PathNodeInfo & source) const;
  80. void getNeighbours(
  81. const TerrainTile & srcTile,
  82. const int3 & srcCoord,
  83. std::vector<int3> & vec,
  84. const boost::logic::tribool & onLand,
  85. const bool limitCoastSailing) const;
  86. int getMovementCost(
  87. const int3 & src,
  88. const int3 & dst,
  89. const TerrainTile * ct,
  90. const TerrainTile * dt,
  91. const int remainingMovePoints = -1,
  92. const bool checkLast = true,
  93. boost::logic::tribool isDstSailLayer = boost::logic::indeterminate,
  94. boost::logic::tribool isDstWaterLayer = boost::logic::indeterminate) const;
  95. int getMovementCost(
  96. const PathNodeInfo & src,
  97. const PathNodeInfo & dst,
  98. const int remainingMovePoints = -1,
  99. const bool checkLast = true) const;
  100. int movementPointsAfterEmbark(int movement, int basicCost, bool disembark) const;
  101. bool passOneTurnLimitCheck(const PathNodeInfo & source) const;
  102. int getGuardiansCount(int3 tile) const;
  103. };
  104. VCMI_LIB_NAMESPACE_END