BuyArmyBehavior.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Goals.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 "BuyArmyBehavior.h"
  12. #include "../VCAI.h"
  13. #include "../AIhelper.h"
  14. #include "../AIUtility.h"
  15. #include "../Goals/BuyArmy.h"
  16. #include "../Goals/VisitTile.h"
  17. #include "lib/mapping/CMap.h" //for victory conditions
  18. #include "lib/CPathfinder.h"
  19. extern boost::thread_specific_ptr<CCallback> cb;
  20. extern boost::thread_specific_ptr<VCAI> ai;
  21. extern FuzzyHelper * fh;
  22. using namespace Goals;
  23. std::string BuyArmyBehavior::toString() const
  24. {
  25. return "Buy army";
  26. }
  27. Goals::TGoalVec BuyArmyBehavior::getTasks()
  28. {
  29. Goals::TGoalVec tasks;
  30. if(cb->getDate(Date::DAY) == 1)
  31. return tasks;
  32. auto heroes = cb->getHeroesInfo();
  33. if(heroes.size())
  34. {
  35. auto mainHero = vstd::maxElementByFun(heroes, [](const CGHeroInstance * hero) -> uint64_t
  36. {
  37. return hero->getFightingStrength();
  38. });
  39. for(auto town : cb->getTownsInfo())
  40. {
  41. const CGHeroInstance * targetHero = *mainHero;
  42. /*if(town->visitingHero)
  43. {
  44. targetHero = town->visitingHero.get();
  45. if(ai->ah->howManyReinforcementsCanGet(targetHero, town->getUpperArmy()))
  46. {
  47. tasks.push_back(sptr(VisitTile(town->visitablePos()).sethero(targetHero).setpriority(5)));
  48. continue;
  49. }
  50. }*/
  51. auto reinforcement = ai->ah->howManyReinforcementsCanBuy(targetHero, town);
  52. if(reinforcement)
  53. {
  54. tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(5)));
  55. }
  56. }
  57. }
  58. return tasks;
  59. }