Nullkiller.h 1.7 KB

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