AIhelper.cpp 5.4 KB

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