TownPortalAction.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * TownPortalAction.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/AdventureSpellCast.h"
  12. #include "../../../../lib/mapObjects/MapObjects.h"
  13. #include "TownPortalAction.h"
  14. namespace NKAI
  15. {
  16. using namespace AIPathfinding;
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<AIGateway> ai;
  19. void TownPortalAction::execute(const CGHeroInstance * hero) const
  20. {
  21. auto goal = Goals::AdventureSpellCast(hero, SpellID::TOWN_PORTAL);
  22. goal.town = target;
  23. goal.tile = target->visitablePos();
  24. goal.accept(ai.get());
  25. }
  26. std::string TownPortalAction::toString() const
  27. {
  28. return "Town Portal to " + target->getNameTranslated();
  29. }
  30. /*
  31. bool TownPortalAction::canAct(const CGHeroInstance * hero, const AIPathNode * source) const
  32. {
  33. #ifdef VCMI_TRACE_PATHFINDER
  34. logAi->trace(
  35. "Hero %s has %d mana and needed %d and already spent %d",
  36. hero->name,
  37. hero->mana,
  38. getManaCost(hero),
  39. source->manaCost);
  40. #endif
  41. return hero->mana >= source->manaCost + getManaCost(hero);
  42. }
  43. uint32_t TownPortalAction::getManaCost(const CGHeroInstance * hero) const
  44. {
  45. SpellID summonBoat = SpellID::TOWN_PORTAL;
  46. return hero->getSpellCost(summonBoat.toSpell());
  47. }*/
  48. }