CPathfinder.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 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. CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options);
  58. virtual ~CPathfinderHelper();
  59. void initializePatrol();
  60. bool isHeroPatrolLocked() const;
  61. bool isPatrolMovementAllowed(const int3 & dst) const;
  62. void updateTurnInfo(const int turn = 0);
  63. bool isLayerAvailable(const EPathfindingLayer & layer) const;
  64. const TurnInfo * getTurnInfo() const;
  65. bool hasBonusOfType(const BonusType type, const int subtype = -1) const;
  66. int getMaxMovePoints(const EPathfindingLayer & layer) const;
  67. std::vector<int3> getCastleGates(const PathNodeInfo & source) const;
  68. bool isAllowedTeleportEntrance(const CGTeleport * obj) const;
  69. std::vector<int3> getAllowedTeleportChannelExits(const TeleportChannelID & channelID) const;
  70. bool addTeleportTwoWay(const CGTeleport * obj) const;
  71. bool addTeleportOneWay(const CGTeleport * obj) const;
  72. bool addTeleportOneWayRandom(const CGTeleport * obj) const;
  73. bool addTeleportWhirlpool(const CGWhirlpool * obj) const;
  74. 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)
  75. std::vector<int3> getNeighbourTiles(const PathNodeInfo & source) const;
  76. std::vector<int3> getTeleportExits(const PathNodeInfo & source) const;
  77. void getNeighbours(
  78. const TerrainTile & srcTile,
  79. const int3 & srcCoord,
  80. std::vector<int3> & vec,
  81. const boost::logic::tribool & onLand,
  82. const bool limitCoastSailing) const;
  83. int getMovementCost(
  84. const int3 & src,
  85. const int3 & dst,
  86. const TerrainTile * ct,
  87. const TerrainTile * dt,
  88. const int remainingMovePoints = -1,
  89. const bool checkLast = true,
  90. boost::logic::tribool isDstSailLayer = boost::logic::indeterminate,
  91. boost::logic::tribool isDstWaterLayer = boost::logic::indeterminate) const;
  92. int getMovementCost(
  93. const PathNodeInfo & src,
  94. const PathNodeInfo & dst,
  95. const int remainingMovePoints = -1,
  96. const bool checkLast = true) const;
  97. int movementPointsAfterEmbark(int movement, int basicCost, bool disembark) const;
  98. bool passOneTurnLimitCheck(const PathNodeInfo & source) const;
  99. };
  100. VCMI_LIB_NAMESPACE_END