HeroManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * HeroManager.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 "../AIUtility.h"
  12. #include "../../../lib/GameConstants.h"
  13. #include "../../../lib/GameLibrary.h"
  14. namespace NKAI
  15. {
  16. class DLL_EXPORT ISecondarySkillRule
  17. {
  18. public:
  19. virtual ~ISecondarySkillRule() = default;
  20. virtual void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const = 0;
  21. };
  22. class DLL_EXPORT SecondarySkillEvaluator
  23. {
  24. private:
  25. std::vector<std::shared_ptr<ISecondarySkillRule>> evaluationRules;
  26. public:
  27. SecondarySkillEvaluator(std::vector<std::shared_ptr<ISecondarySkillRule>> evaluationRules);
  28. float evaluateSecSkills(const CGHeroInstance * hero) const;
  29. float evaluateSecSkill(const CGHeroInstance * hero, SecondarySkill skill) const;
  30. };
  31. class DLL_EXPORT HeroManager
  32. {
  33. private:
  34. static const SecondarySkillEvaluator wariorSkillsScores;
  35. static const SecondarySkillEvaluator scountSkillsScores;
  36. CCallback * cb; //this is enough, but we downcast from CCallback
  37. const Nullkiller * ai;
  38. std::map<HeroPtr, HeroRole> heroRoles;
  39. std::map<ObjectInstanceID, float> knownFightingStrength;
  40. public:
  41. HeroManager(CCallback * CB, const Nullkiller * ai) : cb(CB), ai(ai) {}
  42. const std::map<HeroPtr, HeroRole> & getHeroRoles() const;
  43. HeroRole getHeroRole(const HeroPtr & hero) const;
  44. int selectBestSkill(const HeroPtr & hero, const std::vector<SecondarySkill> & skills) const;
  45. void update();
  46. float evaluateSecSkill(SecondarySkill skill, const CGHeroInstance * hero) const;
  47. float evaluateHero(const CGHeroInstance * hero) const;
  48. bool canRecruitHero(const CGTownInstance * t = nullptr) const;
  49. bool heroCapReached(bool includeGarrisoned = true) const;
  50. const CGHeroInstance * findHeroWithGrail() const;
  51. const CGHeroInstance * findWeakHeroToDismiss(uint64_t armyLimit, const CGTownInstance * townToSpare = nullptr) const;
  52. float getMagicStrength(const CGHeroInstance * hero) const;
  53. float getFightingStrengthCached(const CGHeroInstance * hero) const;
  54. private:
  55. float evaluateFightingStrength(const CGHeroInstance * hero) const;
  56. float evaluateSpeciality(const CGHeroInstance * hero) const;
  57. const CGTownInstance * findTownWithTavern() const;
  58. };
  59. // basic skill scores. missing skills will have score of 0
  60. class DLL_EXPORT SecondarySkillScoreMap : public ISecondarySkillRule
  61. {
  62. private:
  63. std::map<SecondarySkill, float> scoreMap;
  64. public:
  65. SecondarySkillScoreMap(std::map<SecondarySkill, float> scoreMap);
  66. void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override;
  67. };
  68. // Controls when to upgrade existing skills and when get new
  69. class ExistingSkillRule : public ISecondarySkillRule
  70. {
  71. public:
  72. void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override;
  73. };
  74. // Allows to get wisdom at 12 lvl
  75. class WisdomRule : public ISecondarySkillRule
  76. {
  77. public:
  78. void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override;
  79. };
  80. // Dynamically controls scores for magic skills
  81. class AtLeastOneMagicRule : public ISecondarySkillRule
  82. {
  83. private:
  84. static const std::vector<SecondarySkill> magicSchools;
  85. public:
  86. void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override;
  87. };
  88. }