RecruitHero.cpp 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * RecruitHero.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 "Goals.h"
  12. #include "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../../../lib/mapping/CMap.h" //for victory conditions
  15. #include "../../../lib/CPathfinder.h"
  16. #include "../../../lib/StringConstants.h"
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<AIGateway> ai;
  19. using namespace Goals;
  20. std::string RecruitHero::toString() const
  21. {
  22. return "Recruit hero at " + town->name;
  23. }
  24. void RecruitHero::accept(AIGateway * ai)
  25. {
  26. auto t = town;
  27. if(!t) t = ai->findTownWithTavern();
  28. if(t)
  29. {
  30. ai->recruitHero(t, true);
  31. //TODO try to free way to blocked town
  32. //TODO: adventure map tavern or prison?
  33. }
  34. else
  35. {
  36. throw cannotFulfillGoalException("No town to recruit hero!");
  37. }
  38. }