AIhelper.cpp 4.4 KB

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