QuestAction.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Nullkiller * ai, const AIPathNode * node) const
  19. {
  20. return canAct(ai, node->actor->hero);
  21. }
  22. bool QuestAction::canAct(const Nullkiller * ai, const AIPathNodeInfo & node) const
  23. {
  24. return canAct(ai, node.targetHero);
  25. }
  26. bool QuestAction::canAct(const Nullkiller * ai, const CGHeroInstance * hero) const
  27. {
  28. if(questInfo.obj->ID == Obj::BORDER_GATE || questInfo.obj->ID == Obj::BORDERGUARD)
  29. {
  30. return dynamic_cast<const IQuestObject *>(questInfo.obj)->checkQuest(hero);
  31. }
  32. auto notActivated = !questInfo.obj->wasVisited(ai->playerID)
  33. && !questInfo.quest->activeForPlayers.count(hero->getOwner());
  34. return notActivated
  35. || questInfo.quest->checkQuest(hero);
  36. }
  37. Goals::TSubgoal QuestAction::decompose(const Nullkiller * ai, const CGHeroInstance * hero) const
  38. {
  39. return Goals::sptr(Goals::CompleteQuest(questInfo));
  40. }
  41. void QuestAction::execute(AIGateway * ai, const CGHeroInstance * hero) const
  42. {
  43. ai->moveHeroToTile(questInfo.obj->visitablePos(), hero);
  44. }
  45. std::string QuestAction::toString() const
  46. {
  47. return "Complete Quest";
  48. }
  49. }
  50. }