AIhelper.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #include "StdInc.h"
  11. #include "AIhelper.h"
  12. AIhelper::AIhelper()
  13. {
  14. resourceManager.reset(new ResourceManager());
  15. buildingManager.reset(new BuildingManager());
  16. pathfindingManager.reset(new PathfindingManager());
  17. armyManager.reset(new ArmyManager());
  18. }
  19. AIhelper::~AIhelper()
  20. {
  21. }
  22. bool AIhelper::notifyGoalCompleted(Goals::TSubgoal goal)
  23. {
  24. return resourceManager->notifyGoalCompleted(goal);
  25. }
  26. void AIhelper::init(CPlayerSpecificInfoCallback * CB)
  27. {
  28. resourceManager->init(CB);
  29. buildingManager->init(CB);
  30. pathfindingManager->init(CB);
  31. armyManager->init(CB);
  32. }
  33. void AIhelper::setAI(VCAI * AI)
  34. {
  35. resourceManager->setAI(AI);
  36. buildingManager->setAI(AI);
  37. pathfindingManager->setAI(AI);
  38. armyManager->setAI(AI);
  39. }
  40. bool AIhelper::getBuildingOptions(const CGTownInstance * t)
  41. {
  42. return buildingManager->getBuildingOptions(t);
  43. }
  44. BuildingID AIhelper::getMaxPossibleGoldBuilding(const CGTownInstance * t)
  45. {
  46. return buildingManager->getMaxPossibleGoldBuilding(t);
  47. }
  48. boost::optional<PotentialBuilding> AIhelper::immediateBuilding() const
  49. {
  50. return buildingManager->immediateBuilding();
  51. }
  52. boost::optional<PotentialBuilding> AIhelper::expensiveBuilding() const
  53. {
  54. return buildingManager->expensiveBuilding();
  55. }
  56. boost::optional<BuildingID> AIhelper::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const
  57. {
  58. return buildingManager->canBuildAnyStructure(t, buildList, maxDays);
  59. }
  60. Goals::TSubgoal AIhelper::whatToDo(TResources & res, Goals::TSubgoal goal)
  61. {
  62. return resourceManager->whatToDo(res, goal);
  63. }
  64. Goals::TSubgoal AIhelper::whatToDo() const
  65. {
  66. return resourceManager->whatToDo();
  67. }
  68. bool AIhelper::containsObjective(Goals::TSubgoal goal) const
  69. {
  70. return resourceManager->containsObjective(goal);
  71. }
  72. bool AIhelper::hasTasksLeft() const
  73. {
  74. return resourceManager->hasTasksLeft();
  75. }
  76. bool AIhelper::removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal&)> predicate)
  77. {
  78. return resourceManager->removeOutdatedObjectives(predicate);
  79. }
  80. bool AIhelper::canAfford(const TResources & cost) const
  81. {
  82. return resourceManager->canAfford(cost);
  83. }
  84. TResources AIhelper::reservedResources() const
  85. {
  86. return resourceManager->reservedResources();
  87. }
  88. TResources AIhelper::freeResources() const
  89. {
  90. return resourceManager->freeResources();
  91. }
  92. TResource AIhelper::freeGold() const
  93. {
  94. return resourceManager->freeGold();
  95. }
  96. TResources AIhelper::allResources() const
  97. {
  98. return resourceManager->allResources();
  99. }
  100. TResource AIhelper::allGold() const
  101. {
  102. return resourceManager->allGold();
  103. }
  104. Goals::TGoalVec AIhelper::howToVisitTile(const int3 & tile, bool allowGatherArmy) const
  105. {
  106. return pathfindingManager->howToVisitTile(tile, allowGatherArmy);
  107. }
  108. Goals::TGoalVec AIhelper::howToVisitObj(ObjectIdRef obj, bool allowGatherArmy) const
  109. {
  110. return pathfindingManager->howToVisitObj(obj, allowGatherArmy);
  111. }
  112. Goals::TGoalVec AIhelper::howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy) const
  113. {
  114. return pathfindingManager->howToVisitTile(hero, tile, allowGatherArmy);
  115. }
  116. Goals::TGoalVec AIhelper::howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy) const
  117. {
  118. return pathfindingManager->howToVisitObj(hero, obj, allowGatherArmy);
  119. }
  120. std::vector<AIPath> AIhelper::getPathsToTile(const HeroPtr & hero, const int3 & tile) const
  121. {
  122. return pathfindingManager->getPathsToTile(hero, tile);
  123. }
  124. std::vector<AIPath> AIhelper::getPathsToTile(const int3 & tile) const
  125. {
  126. return pathfindingManager->getPathsToTile(tile);
  127. }
  128. void AIhelper::updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain)
  129. {
  130. pathfindingManager->updatePaths(heroes, useHeroChain);
  131. }
  132. bool AIhelper::canGetArmy(const CArmedInstance * army, const CArmedInstance * source) const
  133. {
  134. return armyManager->canGetArmy(army, source);
  135. }
  136. ui64 AIhelper::howManyReinforcementsCanBuy(const CCreatureSet * h, const CGDwelling * t) const
  137. {
  138. return armyManager->howManyReinforcementsCanBuy(h, t);
  139. }
  140. ui64 AIhelper::howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const
  141. {
  142. return armyManager->howManyReinforcementsCanGet(target, source);
  143. }
  144. std::vector<SlotInfo> AIhelper::getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const
  145. {
  146. return armyManager->getBestArmy(target, source);
  147. }
  148. std::vector<SlotInfo>::iterator AIhelper::getWeakestCreature(std::vector<SlotInfo> & army) const
  149. {
  150. return armyManager->getWeakestCreature(army);
  151. }
  152. std::vector<SlotInfo> AIhelper::getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const
  153. {
  154. return armyManager->getSortedSlots(target, source);
  155. }