AIhelper.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ~AIhelper();
  33. bool canAfford(const TResources & cost) const;
  34. TResources reservedResources() const override;
  35. TResources freeResources() const override;
  36. TResource freeGold() const override;
  37. TResources allResources() const override;
  38. TResource allGold() const override;
  39. Goals::TSubgoal whatToDo(TResources &res, Goals::TSubgoal goal) override;
  40. Goals::TSubgoal whatToDo() const override;
  41. bool containsObjective(Goals::TSubgoal goal) const override;
  42. bool hasTasksLeft() const override;
  43. bool removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal &)> predicate) override;
  44. bool getBuildingOptions(const CGTownInstance * t) override;
  45. BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
  46. boost::optional<PotentialBuilding> immediateBuilding() const override;
  47. boost::optional<PotentialBuilding> expensiveBuilding() const override;
  48. boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
  49. Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
  50. Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;
  51. Goals::TGoalVec howToVisitTile(const int3 & tile) const override;
  52. Goals::TGoalVec howToVisitObj(ObjectIdRef obj) const override;
  53. std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
  54. void updatePaths(std::vector<HeroPtr> heroes) override;
  55. STRONG_INLINE
  56. bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
  57. {
  58. return pathfindingManager->isTileAccessible(hero, tile);
  59. }
  60. bool canGetArmy(const CArmedInstance * target, const CArmedInstance * source) const override;
  61. ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
  62. ui64 howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const override;
  63. std::vector<SlotInfo> getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const override;
  64. std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
  65. std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
  66. private:
  67. bool notifyGoalCompleted(Goals::TSubgoal goal) override;
  68. void init(CPlayerSpecificInfoCallback * CB) override;
  69. void setAI(VCAI * AI) override;
  70. };