Nullkiller.h 3.2 KB

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