CPathfinder.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef __CPATHFINDER_H__
  2. #define __CPATHFINDER_H__
  3. #include "global.h"
  4. #include <queue>
  5. #include <vector>
  6. class CGHeroInstance;
  7. struct CPathNode
  8. {
  9. bool accesible; //true if a hero can be on this node
  10. int dist; //distance from the first node of searching; -1 is infinity
  11. CPathNode * theNodeBefore;
  12. int3 coord; //coordiantes
  13. bool visited;
  14. };
  15. struct CPath
  16. {
  17. std::vector<CPathNode> nodes; //just get node by node
  18. int3 startPos(); // start point
  19. int3 endPos(); //destination point
  20. };
  21. /**
  22. * main pathfinder class
  23. */
  24. class CPathfinder
  25. {
  26. private:
  27. std::vector< std::vector<CPathNode> > graph;
  28. void processNode(CPathNode & dp, const CGHeroInstance * hero, std::queue<CPathNode> & mq, const CPathNode & cp, const int3 & src, bool diagonal); //helper function for getPath
  29. bool checkForVisitableDir(const int3 & src, const int3 & dst) const;
  30. public:
  31. CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero, unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
  32. CPath * getPath(const int3 & src, const int3 & dest, const CGHeroInstance * hero, int (*getDist)(int3 & a, int3 & b), unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
  33. static void convertPath(CPath * path, unsigned int mode); //mode=0 -> from 'manifest' to 'object'
  34. };
  35. #endif // __CPATHFINDER_H__