AIhelper.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "Pathfinding/PathfindingManager.h"
  18. class ResourceManager;
  19. class BuildingManager;
  20. //indirection interface for various modules
  21. class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, public IPathfindingManager, public IArmyManager
  22. {
  23. friend class VCAI;
  24. friend struct SetGlobalState; //mess?
  25. std::shared_ptr<ResourceManager> resourceManager;
  26. std::shared_ptr<BuildingManager> buildingManager;
  27. std::shared_ptr<PathfindingManager> pathfindingManager;
  28. std::shared_ptr<ArmyManager> armyManager;
  29. //TODO: vector<IAbstractManager>
  30. public:
  31. AIhelper();
  32. bool canAfford(const TResources & cost) const;
  33. TResources reservedResources() const override;
  34. TResources freeResources() const override;
  35. TResource freeGold() const override;
  36. TResources allResources() const override;
  37. TResource allGold() const override;
  38. Goals::TSubgoal whatToDo(TResources &res, Goals::TSubgoal goal) override;
  39. Goals::TSubgoal whatToDo() const override;
  40. bool containsObjective(Goals::TSubgoal goal) const override;
  41. bool hasTasksLeft() const override;
  42. bool removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal &)> predicate) override;
  43. bool getBuildingOptions(const CGTownInstance * t) override;
  44. BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
  45. std::optional<PotentialBuilding> immediateBuilding() const override;
  46. std::optional<PotentialBuilding> expensiveBuilding() const override;
  47. std::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
  48. Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
  49. Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;
  50. Goals::TGoalVec howToVisitTile(const int3 & tile) const override;
  51. Goals::TGoalVec howToVisitObj(ObjectIdRef obj) const override;
  52. std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
  53. void updatePaths(std::vector<HeroPtr> heroes) override;
  54. STRONG_INLINE
  55. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
  56. {
  57. return pathfindingManager->isTileAccessible(hero, tile);
  58. }
  59. bool canGetArmy(const CArmedInstance * target, const CArmedInstance * source) const override;
  60. ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
  61. ui64 howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const override;
  62. std::vector<SlotInfo> getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const override;
  63. std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
  64. std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
  65. private:
  66. bool notifyGoalCompleted(Goals::TSubgoal goal) override;
  67. void init(CPlayerSpecificInfoCallback * CB) override;
  68. void setAI(VCAI * AI) override;
  69. };