BoatActions.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * BoatActions.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 "../../Goals/BuildBoat.h"
  13. #include "../../../../lib/mapping/CMap.h"
  14. #include "../../../../lib/mapObjects/MapObjects.h"
  15. #include "BoatActions.h"
  16. namespace AIPathfinding
  17. {
  18. Goals::TSubgoal BuildBoatAction::whatToDo(const HeroPtr & hero) const
  19. {
  20. return Goals::sptr(Goals::BuildBoat(shipyard));
  21. }
  22. Goals::TSubgoal SummonBoatAction::whatToDo(const HeroPtr & hero) const
  23. {
  24. return Goals::sptr(Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT));
  25. }
  26. void SummonBoatAction::applyOnDestination(
  27. const CGHeroInstance * hero,
  28. CDestinationNodeInfo & destination,
  29. const PathNodeInfo & source,
  30. AIPathNode * dstMode,
  31. const AIPathNode * srcNode) const
  32. {
  33. dstMode->manaCost = srcNode->manaCost + getManaCost(hero);
  34. dstMode->theNodeBefore = source.node;
  35. }
  36. bool SummonBoatAction::isAffordableBy(const CGHeroInstance * hero, const AIPathNode * source) const
  37. {
  38. #ifdef VCMI_TRACE_PATHFINDER
  39. logAi->trace(
  40. "Hero %s has %d mana and needed %d and already spent %d",
  41. hero->name,
  42. hero->mana,
  43. getManaCost(hero),
  44. source->manaCost);
  45. #endif
  46. return hero->mana >= (si32)(source->manaCost + getManaCost(hero));
  47. }
  48. uint32_t SummonBoatAction::getManaCost(const CGHeroInstance * hero) const
  49. {
  50. SpellID summonBoat = SpellID::SUMMON_BOAT;
  51. return hero->getSpellCost(summonBoat.toSpell());
  52. }
  53. }