BoatActions.cpp 1.5 KB

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