AIhelper.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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::map<HeroPtr, HeroRole> getHeroRoles() const override;
  70. int selectBestSkill(const HeroPtr & hero, const std::vector<SecondarySkill> & skills) const override;
  71. private:
  72. bool notifyGoalCompleted(Goals::TSubgoal goal) override;
  73. void init(CPlayerSpecificInfoCallback * CB) override;
  74. void setAI(VCAI * AI) override;
  75. };