Nullkiller.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "AIMemory.h"
  14. #include "DeepDecomposer.h"
  15. #include "../Analyzers/DangerHitMapAnalyzer.h"
  16. #include "../Analyzers/BuildAnalyzer.h"
  17. #include "../Analyzers/ArmyManager.h"
  18. #include "../Analyzers/HeroManager.h"
  19. #include "../Analyzers/ObjectClusterizer.h"
  20. const float MAX_GOLD_PEASURE = 0.3f;
  21. const float MIN_PRIORITY = 0.01f;
  22. const float NEXT_SCAN_MIN_PRIORITY = 0.4f;
  23. enum class HeroLockedReason
  24. {
  25. NOT_LOCKED = 0,
  26. STARTUP = 1,
  27. DEFENCE = 2,
  28. HERO_CHAIN = 3
  29. };
  30. enum class ScanDepth
  31. {
  32. SMALL = 0,
  33. MEDIUM = 1,
  34. FULL = 2
  35. };
  36. class Nullkiller
  37. {
  38. private:
  39. const CGHeroInstance * activeHero;
  40. int3 targetTile;
  41. std::map<const CGHeroInstance *, HeroLockedReason> lockedHeroes;
  42. ScanDepth scanDepth;
  43. TResources lockedResources;
  44. bool useHeroChain;
  45. public:
  46. std::unique_ptr<DangerHitMapAnalyzer> dangerHitMap;
  47. std::unique_ptr<BuildAnalyzer> buildAnalyzer;
  48. std::unique_ptr<ObjectClusterizer> objectClusterizer;
  49. std::unique_ptr<PriorityEvaluator> priorityEvaluator;
  50. std::unique_ptr<SharedPool<PriorityEvaluator>> priorityEvaluators;
  51. std::unique_ptr<AIPathfinder> pathfinder;
  52. std::unique_ptr<HeroManager> heroManager;
  53. std::unique_ptr<ArmyManager> armyManager;
  54. std::unique_ptr<AIMemory> memory;
  55. std::unique_ptr<FuzzyHelper> dangerEvaluator;
  56. std::unique_ptr<DeepDecomposer> decomposer;
  57. PlayerColor playerID;
  58. std::shared_ptr<CCallback> cb;
  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. void setActive(const CGHeroInstance * hero, int3 tile) { activeHero = hero; targetTile = tile; }
  68. void lockHero(const CGHeroInstance * hero, HeroLockedReason lockReason) { lockedHeroes[hero] = lockReason; }
  69. void unlockHero(const CGHeroInstance * hero) { lockedHeroes.erase(hero); }
  70. bool arePathHeroesLocked(const AIPath & path) const;
  71. TResources getFreeResources() const;
  72. int32_t getFreeGold() const { return getFreeResources()[Res::GOLD]; }
  73. void lockResources(const TResources & res);
  74. const TResources & getLockedResources() const { return lockedResources; }
  75. private:
  76. void resetAiState();
  77. void updateAiState(int pass, bool fast = false);
  78. Goals::TTask choseBestTask(Goals::TSubgoal behavior, int decompositionMaxDepth) const;
  79. Goals::TTask choseBestTask(Goals::TTaskVec & tasks) const;
  80. void executeTask(Goals::TTask task);
  81. };