Nullkiller.h 3.0 KB

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