RecruitHeroBehavior.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../Goals/RecruitHero.h"
  15. #include "../Goals/ExecuteHeroChain.h"
  16. #include "lib/mapping/CMap.h" //for victory conditions
  17. #include "lib/CPathfinder.h"
  18. namespace NKAI
  19. {
  20. extern boost::thread_specific_ptr<CCallback> cb;
  21. extern boost::thread_specific_ptr<AIGateway> ai;
  22. using namespace Goals;
  23. std::string RecruitHeroBehavior::toString() const
  24. {
  25. return "Recruit hero";
  26. }
  27. Goals::TGoalVec RecruitHeroBehavior::decompose() const
  28. {
  29. Goals::TGoalVec tasks;
  30. auto towns = cb->getTownsInfo();
  31. for(auto town : towns)
  32. {
  33. if(!town->garrisonHero && !town->visitingHero && ai->canRecruitAnyHero(town))
  34. {
  35. if(cb->getHeroesInfo().size() < cb->getTownsInfo().size() + 1
  36. || (ai->nullkiller->getFreeResources()[Res::GOLD] > 10000
  37. && ai->nullkiller->buildAnalyzer->getGoldPreasure() < MAX_GOLD_PEASURE))
  38. {
  39. tasks.push_back(Goals::sptr(Goals::RecruitHero(town).setpriority(3)));
  40. }
  41. }
  42. }
  43. return tasks;
  44. }
  45. }