TownPortalAction.cpp 1.3 KB

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