DangerHitMapAnalyzer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * DangerHitMapAnalyzer.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 "../AIUtility.h"
  12. namespace NKAI
  13. {
  14. struct AIPath;
  15. struct HitMapInfo
  16. {
  17. static HitMapInfo NoTreat;
  18. uint64_t danger;
  19. uint8_t turn;
  20. HeroPtr hero;
  21. HitMapInfo()
  22. {
  23. reset();
  24. }
  25. void reset()
  26. {
  27. danger = 0;
  28. turn = 255;
  29. hero = HeroPtr();
  30. }
  31. double value() const;
  32. };
  33. struct HitMapNode
  34. {
  35. HitMapInfo maximumDanger;
  36. HitMapInfo fastestDanger;
  37. const CGTownInstance * closestTown = nullptr;
  38. HitMapNode() = default;
  39. void reset()
  40. {
  41. maximumDanger.reset();
  42. fastestDanger.reset();
  43. }
  44. };
  45. class DangerHitMapAnalyzer
  46. {
  47. private:
  48. boost::multi_array<HitMapNode, 3> hitMap;
  49. std::map<const CGHeroInstance *, std::set<const CGObjectInstance *>> enemyHeroAccessibleObjects;
  50. bool hitMapUpToDate = false;
  51. bool tileOwnersUpToDate = false;
  52. const Nullkiller * ai;
  53. std::map<ObjectInstanceID, std::vector<HitMapInfo>> townTreats;
  54. public:
  55. DangerHitMapAnalyzer(const Nullkiller * ai) :ai(ai) {}
  56. void updateHitMap();
  57. void calculateTileOwners();
  58. uint64_t enemyCanKillOurHeroesAlongThePath(const AIPath & path) const;
  59. const HitMapNode & getObjectTreat(const CGObjectInstance * obj) const;
  60. const HitMapNode & getTileTreat(const int3 & tile) const;
  61. const std::set<const CGObjectInstance *> & getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const;
  62. void reset();
  63. void resetTileOwners() { tileOwnersUpToDate = false; }
  64. PlayerColor getTileOwner(const int3 & tile) const;
  65. const CGTownInstance * getClosestTown(const int3 & tile) const;
  66. const std::vector<HitMapInfo> & getTownTreats(const CGTownInstance * town) const;
  67. };
  68. }