RecruitHeroBehavior.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * RecruitHeroBehavior.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 "RecruitHeroBehavior.h"
  12. #include "../VCAI.h"
  13. #include "../AIhelper.h"
  14. #include "../AIUtility.h"
  15. #include "../Goals/RecruitHero.h"
  16. #include "../Goals/ExecuteHeroChain.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 RecruitHeroBehavior::toString() const
  24. {
  25. return "Recruit hero";
  26. }
  27. Goals::TGoalVec RecruitHeroBehavior::getTasks()
  28. {
  29. Goals::TGoalVec tasks;
  30. auto towns = cb->getTownsInfo();
  31. for(auto town : towns)
  32. {
  33. if(!town->garrisonHero && ai->canRecruitAnyHero(town))
  34. {
  35. if(cb->getHeroesInfo().size() < cb->getTownsInfo().size() + 1
  36. || cb->getResourceAmount(Res::GOLD) > 10000)
  37. {
  38. tasks.push_back(Goals::sptr(Goals::RecruitHero().settown(town)));
  39. }
  40. }
  41. }
  42. return tasks;
  43. }