AINodeStorage.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * AIhelper.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 "../../../lib/CPathfinder.h"
  12. #include "../../../lib/mapObjects/CGHeroInstance.h"
  13. #include "AIUtility.h"
  14. class IVirtualObject
  15. {
  16. public:
  17. virtual void materialize();
  18. };
  19. struct AIPathNode : public CGPathNode
  20. {
  21. uint32_t chainMask;
  22. uint64_t danger;
  23. };
  24. struct AIPathNodeInfo
  25. {
  26. uint32_t movementPointsLeft;
  27. uint32_t movementPointsUsed;
  28. int turns;
  29. int3 coord;
  30. uint64_t danger;
  31. };
  32. struct AIPath
  33. {
  34. std::vector<AIPathNodeInfo> nodes;
  35. AIPath();
  36. /// Gets danger of path excluding danger of visiting the target object like creature bank
  37. uint64_t getPathDanger() const;
  38. /// Gets danger of path including danger of visiting the target object like creature bank
  39. uint64_t getTotalDanger(HeroPtr hero) const;
  40. int3 firstTileToGet() const;
  41. uint32_t movementCost() const;
  42. };
  43. class AINodeStorage : public INodeStorage
  44. {
  45. private:
  46. int3 sizes;
  47. /// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations)
  48. boost::multi_array<AIPathNode, 5> nodes;
  49. const CGHeroInstance * hero;
  50. public:
  51. /// more than 1 chain layer allows us to have more than 1 path to each tile so we can chose more optimal one.
  52. static const int NUM_CHAINS = 2;
  53. static const int NORMAL_CHAIN = 0;
  54. static const int BATTLE_CHAIN = 1;
  55. AINodeStorage(const int3 & sizes);
  56. ~AINodeStorage();
  57. virtual CGPathNode * getInitialNode() override;
  58. virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) override;
  59. virtual std::vector<CGPathNode *> calculateNeighbours(
  60. CPathNodeInfo & source,
  61. CPathfinderConfig * pathfinderConfig,
  62. CPathfinderHelper * pathfinderHelper) override;
  63. virtual std::vector<CGPathNode *> calculateTeleportations(
  64. CPathNodeInfo & source,
  65. CPathfinderConfig * pathfinderConfig,
  66. CPathfinderHelper * pathfinderHelper) override;
  67. virtual void commit(CDestinationNodeInfo & destination, CPathNodeInfo & source) override;
  68. AIPathNode * getAINode(CPathNodeInfo & nodeInfo) const;
  69. AIPathNode * getAINode(CGPathNode * node) const;
  70. bool isBattleNode(CGPathNode * node) const;
  71. bool hasBetterChain(CPathNodeInfo & source, CDestinationNodeInfo & destination) const;
  72. AIPathNode * getNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
  73. std::vector<AIPath> getChainInfo(int3 pos);
  74. void setHero(HeroPtr heroPtr)
  75. {
  76. hero = heroPtr.get();
  77. }
  78. const CGHeroInstance * getHero() const
  79. {
  80. return hero;
  81. }
  82. };