Nullkiller.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Nullkiller.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 "PriorityEvaluator.h"
  12. #include "DangerHitMapAnalyzer.h"
  13. #include "../Goals/AbstractGoal.h"
  14. #include "../Behaviors/Behavior.h"
  15. enum class HeroLockedReason
  16. {
  17. NOT_LOCKED = 0,
  18. STARTUP = 1,
  19. DEFENCE = 2,
  20. HERO_CHAIN = 3
  21. };
  22. class Nullkiller
  23. {
  24. private:
  25. std::unique_ptr<PriorityEvaluator> priorityEvaluator;
  26. const CGHeroInstance * activeHero;
  27. std::map<const CGHeroInstance *, HeroLockedReason> lockedHeroes;
  28. public:
  29. std::unique_ptr<DangerHitMapAnalyzer> dangerHitMap;
  30. Nullkiller();
  31. void makeTurn();
  32. bool isActive(const CGHeroInstance * hero) const { return activeHero == hero; }
  33. bool isHeroLocked(const CGHeroInstance * hero) const { return vstd::contains(lockedHeroes, hero); }
  34. HeroLockedReason getHeroLockedReason(const CGHeroInstance * hero) const { return isHeroLocked(hero) ? lockedHeroes.at(hero) : HeroLockedReason::NOT_LOCKED; }
  35. void setActive(const CGHeroInstance * hero) { activeHero = hero; }
  36. void lockHero(const CGHeroInstance * hero, HeroLockedReason lockReason) { lockedHeroes[hero] = lockReason; }
  37. void unlockHero(const CGHeroInstance * hero) { lockedHeroes.erase(hero); }
  38. bool arePathHeroesLocked(const AIPath & path) const;
  39. private:
  40. void resetAiState();
  41. void updateAiState();
  42. Goals::TSubgoal choseBestTask(std::shared_ptr<Behavior> behavior) const;
  43. Goals::TSubgoal choseBestTask(Goals::TGoalVec & tasks) const;
  44. };