QuestAction.cpp 1.2 KB

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