Nullkiller.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "FuzzyHelper.h"
  13. #include "Settings.h"
  14. #include "AIMemory.h"
  15. #include "DeepDecomposer.h"
  16. #include "../Analyzers/DangerHitMapAnalyzer.h"
  17. #include "../Analyzers/BuildAnalyzer.h"
  18. #include "../Analyzers/ArmyManager.h"
  19. #include "../Analyzers/HeroManager.h"
  20. #include "../Analyzers/ObjectClusterizer.h"
  21. #include "../Helpers/ArmyFormation.h"
  22. namespace NKAI
  23. {
  24. const float MIN_PRIORITY = 0.01f;
  25. enum class HeroLockedReason
  26. {
  27. NOT_LOCKED = 0,
  28. STARTUP = 1,
  29. DEFENCE = 2,
  30. HERO_CHAIN = 3
  31. };
  32. class Nullkiller
  33. {
  34. private:
  35. const CGHeroInstance * activeHero;
  36. int3 targetTile;
  37. ObjectInstanceID targetObject;
  38. std::map<const CGHeroInstance *, HeroLockedReason> lockedHeroes;
  39. TResources lockedResources;
  40. bool useHeroChain;
  41. public:
  42. static std::unique_ptr<ObjectGraph> baseGraph;
  43. std::unique_ptr<DangerHitMapAnalyzer> dangerHitMap;
  44. std::unique_ptr<BuildAnalyzer> buildAnalyzer;
  45. std::unique_ptr<ObjectClusterizer> objectClusterizer;
  46. std::unique_ptr<PriorityEvaluator> priorityEvaluator;
  47. std::unique_ptr<SharedPool<PriorityEvaluator>> priorityEvaluators;
  48. std::unique_ptr<AIPathfinder> pathfinder;
  49. std::unique_ptr<HeroManager> heroManager;
  50. std::unique_ptr<ArmyManager> armyManager;
  51. std::unique_ptr<AIMemory> memory;
  52. std::unique_ptr<FuzzyHelper> dangerEvaluator;
  53. std::unique_ptr<DeepDecomposer> decomposer;
  54. std::unique_ptr<ArmyFormation> armyFormation;
  55. std::unique_ptr<Settings> settings;
  56. PlayerColor playerID;
  57. std::shared_ptr<CCallback> cb;
  58. std::mutex aiStateMutex;
  59. Nullkiller();
  60. void init(std::shared_ptr<CCallback> cb, PlayerColor playerID);
  61. void makeTurn();
  62. bool isActive(const CGHeroInstance * hero) const { return activeHero == hero; }
  63. bool isHeroLocked(const CGHeroInstance * hero) const;
  64. HeroPtr getActiveHero() { return activeHero; }
  65. HeroLockedReason getHeroLockedReason(const CGHeroInstance * hero) const;
  66. int3 getTargetTile() const { return targetTile; }
  67. ObjectInstanceID getTargetObject() const { return targetObject; }
  68. void setTargetObject(int objid) { targetObject = ObjectInstanceID(objid); }
  69. void setActive(const CGHeroInstance * hero, int3 tile) { activeHero = hero; targetTile = tile; }
  70. void lockHero(const CGHeroInstance * hero, HeroLockedReason lockReason) { lockedHeroes[hero] = lockReason; }
  71. void unlockHero(const CGHeroInstance * hero) { lockedHeroes.erase(hero); }
  72. bool arePathHeroesLocked(const AIPath & path) const;
  73. TResources getFreeResources() const;
  74. int32_t getFreeGold() const { return getFreeResources()[EGameResID::GOLD]; }
  75. void lockResources(const TResources & res);
  76. const TResources & getLockedResources() const { return lockedResources; }
  77. private:
  78. void resetAiState();
  79. void updateAiState(int pass, bool fast = false);
  80. Goals::TTask choseBestTask(Goals::TSubgoal behavior, int decompositionMaxDepth) const;
  81. Goals::TTask choseBestTask(Goals::TTaskVec & tasks) const;
  82. void executeTask(Goals::TTask task);
  83. };
  84. }