AIhelper.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. void AIhelper::update()
  44. {
  45. armyManager->update();
  46. heroManager->update();
  47. }
  48. bool AIhelper::getBuildingOptions(const CGTownInstance * t)
  49. {
  50. return buildingManager->getBuildingOptions(t);
  51. }
  52. BuildingID AIhelper::getMaxPossibleGoldBuilding(const CGTownInstance * t)
  53. {
  54. return buildingManager->getMaxPossibleGoldBuilding(t);
  55. }
  56. boost::optional<PotentialBuilding> AIhelper::immediateBuilding() const
  57. {
  58. return buildingManager->immediateBuilding();
  59. }
  60. boost::optional<PotentialBuilding> AIhelper::expensiveBuilding() const
  61. {
  62. return buildingManager->expensiveBuilding();
  63. }
  64. boost::optional<BuildingID> AIhelper::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const
  65. {
  66. return buildingManager->canBuildAnyStructure(t, buildList, maxDays);
  67. }
  68. Goals::TSubgoal AIhelper::whatToDo(TResources & res, Goals::TSubgoal goal)
  69. {
  70. return resourceManager->whatToDo(res, goal);
  71. }
  72. Goals::TSubgoal AIhelper::whatToDo() const
  73. {
  74. return resourceManager->whatToDo();
  75. }
  76. bool AIhelper::containsObjective(Goals::TSubgoal goal) const
  77. {
  78. return resourceManager->containsObjective(goal);
  79. }
  80. bool AIhelper::hasTasksLeft() const
  81. {
  82. return resourceManager->hasTasksLeft();
  83. }
  84. bool AIhelper::removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal&)> predicate)
  85. {
  86. return resourceManager->removeOutdatedObjectives(predicate);
  87. }
  88. bool AIhelper::canAfford(const TResources & cost) const
  89. {
  90. return resourceManager->canAfford(cost);
  91. }
  92. TResources AIhelper::reservedResources() const
  93. {
  94. return resourceManager->reservedResources();
  95. }
  96. TResources AIhelper::freeResources() const
  97. {
  98. return resourceManager->freeResources();
  99. }
  100. TResource AIhelper::freeGold() const
  101. {
  102. return resourceManager->freeGold();
  103. }
  104. TResources AIhelper::allResources() const
  105. {
  106. return resourceManager->allResources();
  107. }
  108. TResource AIhelper::allGold() const
  109. {
  110. return resourceManager->allGold();
  111. }
  112. Goals::TGoalVec AIhelper::howToVisitTile(const int3 & tile, bool allowGatherArmy) const
  113. {
  114. return pathfindingManager->howToVisitTile(tile, allowGatherArmy);
  115. }
  116. Goals::TGoalVec AIhelper::howToVisitObj(ObjectIdRef obj, bool allowGatherArmy) const
  117. {
  118. return pathfindingManager->howToVisitObj(obj, allowGatherArmy);
  119. }
  120. Goals::TGoalVec AIhelper::howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy) const
  121. {
  122. return pathfindingManager->howToVisitTile(hero, tile, allowGatherArmy);
  123. }
  124. Goals::TGoalVec AIhelper::howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy) const
  125. {
  126. return pathfindingManager->howToVisitObj(hero, obj, allowGatherArmy);
  127. }
  128. std::vector<AIPath> AIhelper::getPathsToTile(const HeroPtr & hero, const int3 & tile) const
  129. {
  130. return pathfindingManager->getPathsToTile(hero, tile);
  131. }
  132. std::vector<AIPath> AIhelper::getPathsToTile(const int3 & tile) const
  133. {
  134. return pathfindingManager->getPathsToTile(tile);
  135. }
  136. void AIhelper::updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain)
  137. {
  138. pathfindingManager->updatePaths(heroes, useHeroChain);
  139. }
  140. uint64_t AIhelper::evaluateStackPower(const CCreature * creature, int count) const
  141. {
  142. return armyManager->evaluateStackPower(creature, count);
  143. }
  144. SlotInfo AIhelper::getTotalCreaturesAvailable(CreatureID creatureID) const
  145. {
  146. return armyManager->getTotalCreaturesAvailable(creatureID);
  147. }
  148. bool AIhelper::canGetArmy(const CArmedInstance * army, const CArmedInstance * source) const
  149. {
  150. return armyManager->canGetArmy(army, source);
  151. }
  152. ui64 AIhelper::howManyReinforcementsCanBuy(const CCreatureSet * h, const CGDwelling * t) const
  153. {
  154. return armyManager->howManyReinforcementsCanBuy(h, t);
  155. }
  156. ui64 AIhelper::howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const
  157. {
  158. return armyManager->howManyReinforcementsCanGet(target, source);
  159. }
  160. std::vector<SlotInfo> AIhelper::getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const
  161. {
  162. return armyManager->getBestArmy(target, source);
  163. }
  164. std::vector<SlotInfo>::iterator AIhelper::getWeakestCreature(std::vector<SlotInfo> & army) const
  165. {
  166. return armyManager->getWeakestCreature(army);
  167. }
  168. std::vector<SlotInfo> AIhelper::getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const
  169. {
  170. return armyManager->getSortedSlots(target, source);
  171. }
  172. std::vector<creInfo> AIhelper::getArmyAvailableToBuy(const CCreatureSet * hero, const CGDwelling * dwelling) const
  173. {
  174. return armyManager->getArmyAvailableToBuy(hero, dwelling);
  175. }
  176. ArmyUpgradeInfo AIhelper::calculateCreateresUpgrade(
  177. const CCreatureSet * army,
  178. const CGObjectInstance * upgrader,
  179. const TResources & availableResources) const
  180. {
  181. return armyManager->calculateCreateresUpgrade(army, upgrader, availableResources);
  182. }
  183. int AIhelper::selectBestSkill(const HeroPtr & hero, const std::vector<SecondarySkill> & skills) const
  184. {
  185. return heroManager->selectBestSkill(hero, skills);
  186. }
  187. const std::map<HeroPtr, HeroRole> & AIhelper::getHeroRoles() const
  188. {
  189. return heroManager->getHeroRoles();
  190. }
  191. HeroRole AIhelper::getHeroRole(const HeroPtr & hero) const
  192. {
  193. return heroManager->getHeroRole(hero);
  194. }
  195. float AIhelper::evaluateSecSkill(SecondarySkill skill, const CGHeroInstance * hero) const
  196. {
  197. return heroManager->evaluateSecSkill(skill, hero);
  198. }
  199. float AIhelper::evaluateHero(const CGHeroInstance * hero) const
  200. {
  201. return heroManager->evaluateHero(hero);
  202. }