QuestAction.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. namespace NKAI
  15. {
  16. namespace AIPathfinding
  17. {
  18. bool QuestAction::canAct(const AIPathNode * node) const
  19. {
  20. return canAct(node->actor->hero);
  21. }
  22. bool QuestAction::canAct(const CGHeroInstance * hero) const
  23. {
  24. if(questInfo.obj->ID == Obj::BORDER_GATE || questInfo.obj->ID == Obj::BORDERGUARD)
  25. {
  26. return dynamic_cast<const IQuestObject *>(questInfo.obj)->checkQuest(hero);
  27. }
  28. return questInfo.quest->activeForPlayers.count(hero->getOwner())
  29. || questInfo.quest->checkQuest(hero);
  30. }
  31. Goals::TSubgoal QuestAction::decompose(const CGHeroInstance * hero) const
  32. {
  33. return Goals::sptr(Goals::CompleteQuest(questInfo));
  34. }
  35. void QuestAction::execute(const CGHeroInstance * hero) const
  36. {
  37. ai->moveHeroToTile(questInfo.obj->visitablePos(), hero);
  38. }
  39. std::string QuestAction::toString() const
  40. {
  41. return "Complete Quest";
  42. }
  43. }
  44. }