AIhelper.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * AIhelper.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. /*
  12. !!! Note: Include THIS file at the end of include list to avoid "undefined base class" error
  13. */
  14. #include "ResourceManager.h"
  15. #include "BuildingManager.h"
  16. #include "ArmyManager.h"
  17. #include "HeroManager.h"
  18. #include "Pathfinding/PathfindingManager.h"
  19. class ResourceManager;
  20. class BuildingManager;
  21. //indirection interface for various modules
  22. class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, public IPathfindingManager, public IArmyManager, public IHeroManager
  23. {
  24. friend class VCAI;
  25. friend struct SetGlobalState; //mess?
  26. std::shared_ptr<ResourceManager> resourceManager;
  27. std::shared_ptr<BuildingManager> buildingManager;
  28. std::shared_ptr<PathfindingManager> pathfindingManager;
  29. std::shared_ptr<ArmyManager> armyManager;
  30. std::shared_ptr<HeroManager> heroManager;
  31. //TODO: vector<IAbstractManager>
  32. public:
  33. AIhelper();
  34. ~AIhelper();
  35. bool canAfford(const TResources & cost) const;
  36. TResources reservedResources() const override;
  37. TResources freeResources() const override;
  38. TResource freeGold() const override;
  39. TResources allResources() const override;
  40. TResource allGold() const override;
  41. Goals::TSubgoal whatToDo(TResources &res, Goals::TSubgoal goal) override;
  42. Goals::TSubgoal whatToDo() const override;
  43. bool containsObjective(Goals::TSubgoal goal) const override;
  44. bool hasTasksLeft() const override;
  45. bool removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal &)> predicate) override;
  46. bool getBuildingOptions(const CGTownInstance * t) override;
  47. BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
  48. boost::optional<PotentialBuilding> immediateBuilding() const override;
  49. boost::optional<PotentialBuilding> expensiveBuilding() const override;
  50. boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
  51. Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
  52. Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;
  53. Goals::TGoalVec howToVisitTile(const int3 & tile, bool allowGatherArmy = true) const override;
  54. Goals::TGoalVec howToVisitObj(ObjectIdRef obj, bool allowGatherArmy = true) const override;
  55. std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
  56. std::vector<AIPath> getPathsToTile(const int3 & tile) const override;
  57. void updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain = false) override;
  58. STRONG_INLINE
  59. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
  60. {
  61. return pathfindingManager->isTileAccessible(hero, tile);
  62. }
  63. bool canGetArmy(const CArmedInstance * target, const CArmedInstance * source) const override;
  64. ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
  65. ui64 howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const override;
  66. std::vector<SlotInfo> getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const override;
  67. std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
  68. std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
  69. std::vector<creInfo> getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const override;
  70. uint64_t evaluateStackPower(const CCreature * creature, int count) const override;
  71. SlotInfo getTotalCreaturesAvailable(CreatureID creatureID) const override;
  72. ArmyUpgradeInfo calculateCreateresUpgrade(
  73. const CCreatureSet * army,
  74. const CGObjectInstance * upgrader,
  75. const TResources & availableResources) const override;
  76. const std::map<HeroPtr, HeroRole> & getHeroRoles() const override;
  77. HeroRole getHeroRole(const HeroPtr & hero) const override;
  78. int selectBestSkill(const HeroPtr & hero, const std::vector<SecondarySkill> & skills) const override;
  79. float evaluateSecSkill(SecondarySkill skill, const CGHeroInstance * hero) const override;
  80. float evaluateHero(const CGHeroInstance * hero) const override;
  81. void update() override;
  82. private:
  83. bool notifyGoalCompleted(Goals::TSubgoal goal) override;
  84. void init(CPlayerSpecificInfoCallback * CB) override;
  85. void setAI(VCAI * AI) override;
  86. };