2
0

TownPortalAction.cpp 1.4 KB

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