QuestAction.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * QuestAction.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 "QuestAction.h"
  12. #include "../../AIGateway.h"
  13. #include "../../Goals/CompleteQuest.h"
  14. #include "../../../../lib/mapping/CMap.h" //for victory conditions
  15. namespace NKAI
  16. {
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<AIGateway> ai;
  19. namespace AIPathfinding
  20. {
  21. bool QuestAction::canAct(const AIPathNode * node) const
  22. {
  23. if(questInfo.obj->ID == Obj::BORDER_GATE || questInfo.obj->ID == Obj::BORDERGUARD)
  24. {
  25. return dynamic_cast<const IQuestObject *>(questInfo.obj)->checkQuest(node->actor->hero);
  26. }
  27. return questInfo.quest->progress == CQuest::NOT_ACTIVE
  28. || questInfo.quest->checkQuest(node->actor->hero);
  29. }
  30. Goals::TSubgoal QuestAction::decompose(const CGHeroInstance * hero) const
  31. {
  32. return Goals::sptr(Goals::CompleteQuest(questInfo));
  33. }
  34. void QuestAction::execute(const CGHeroInstance * hero) const
  35. {
  36. ai->moveHeroToTile(questInfo.obj->visitablePos(), hero);
  37. }
  38. std::string QuestAction::toString() const
  39. {
  40. return "Complete Quest";
  41. }
  42. }
  43. }