DangerHitMapAnalyzer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. };
  32. struct HitMapNode
  33. {
  34. HitMapInfo maximumDanger;
  35. HitMapInfo fastestDanger;
  36. HitMapNode() = default;
  37. void reset()
  38. {
  39. maximumDanger.reset();
  40. fastestDanger.reset();
  41. }
  42. };
  43. class DangerHitMapAnalyzer
  44. {
  45. private:
  46. boost::multi_array<HitMapNode, 3> hitMap;
  47. std::map<const CGHeroInstance *, std::set<const CGObjectInstance *>> enemyHeroAccessibleObjects;
  48. bool upToDate;
  49. const Nullkiller * ai;
  50. public:
  51. DangerHitMapAnalyzer(const Nullkiller * ai) :ai(ai) {}
  52. void updateHitMap();
  53. uint64_t enemyCanKillOurHeroesAlongThePath(const AIPath & path) const;
  54. const HitMapNode & getObjectTreat(const CGObjectInstance * obj) const;
  55. const HitMapNode & getTileTreat(const int3 & tile) const;
  56. const std::set<const CGObjectInstance *> & getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const;
  57. void reset();
  58. };
  59. }