Nullkiller.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. public:
  45. std::unique_ptr<DangerHitMapAnalyzer> dangerHitMap;
  46. std::unique_ptr<BuildAnalyzer> buildAnalyzer;
  47. std::unique_ptr<ObjectClusterizer> objectClusterizer;
  48. std::unique_ptr<PriorityEvaluator> priorityEvaluator;
  49. std::unique_ptr<SharedPool<PriorityEvaluator>> priorityEvaluators;
  50. std::unique_ptr<AIPathfinder> pathfinder;
  51. std::unique_ptr<HeroManager> heroManager;
  52. std::unique_ptr<ArmyManager> armyManager;
  53. std::unique_ptr<AIMemory> memory;
  54. std::unique_ptr<FuzzyHelper> dangerEvaluator;
  55. std::unique_ptr<DeepDecomposer> decomposer;
  56. PlayerColor playerID;
  57. std::shared_ptr<CCallback> cb;
  58. Nullkiller();
  59. void init(std::shared_ptr<CCallback> cb, PlayerColor playerID);
  60. void makeTurn();
  61. bool isActive(const CGHeroInstance * hero) const { return activeHero == hero; }
  62. bool isHeroLocked(const CGHeroInstance * hero) const;
  63. HeroPtr getActiveHero() { return activeHero; }
  64. HeroLockedReason getHeroLockedReason(const CGHeroInstance * hero) const;
  65. int3 getTargetTile() const { return targetTile; }
  66. void setActive(const CGHeroInstance * hero, int3 tile) { activeHero = hero; targetTile = tile; }
  67. void lockHero(const CGHeroInstance * hero, HeroLockedReason lockReason) { lockedHeroes[hero] = lockReason; }
  68. void unlockHero(const CGHeroInstance * hero) { lockedHeroes.erase(hero); }
  69. bool arePathHeroesLocked(const AIPath & path) const;
  70. TResources getFreeResources() const;
  71. int32_t getFreeGold() const { return getFreeResources()[Res::GOLD]; }
  72. void lockResources(const TResources & res);
  73. const TResources & getLockedResources() const { return lockedResources; }
  74. private:
  75. void resetAiState();
  76. void updateAiState(int pass);
  77. Goals::TTask choseBestTask(Goals::TSubgoal behavior, int decompositionMaxDepth) const;
  78. Goals::TTask choseBestTask(Goals::TTaskVec & tasks) const;
  79. };