BoatActions.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 CGHeroInstance * hero) const
  19. {
  20. return Goals::sptr(Goals::BuildBoat(shipyard));
  21. }
  22. const ChainActor * BuildBoatAction::getActor(const ChainActor * sourceActor) const
  23. {
  24. return sourceActor->resourceActor;
  25. }
  26. Goals::TSubgoal SummonBoatAction::whatToDo(const CGHeroInstance * hero) const
  27. {
  28. return Goals::sptr(Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT));
  29. }
  30. const ChainActor * SummonBoatAction::getActor(const ChainActor * sourceActor) const
  31. {
  32. return sourceActor->castActor;
  33. }
  34. void SummonBoatAction::applyOnDestination(
  35. const CGHeroInstance * hero,
  36. CDestinationNodeInfo & destination,
  37. const PathNodeInfo & source,
  38. AIPathNode * dstMode,
  39. const AIPathNode * srcNode) const
  40. {
  41. dstMode->manaCost = srcNode->manaCost + getManaCost(hero);
  42. dstMode->theNodeBefore = source.node;
  43. }
  44. bool SummonBoatAction::isAffordableBy(const CGHeroInstance * hero, const AIPathNode * source) const
  45. {
  46. #ifdef VCMI_TRACE_PATHFINDER
  47. logAi->trace(
  48. "Hero %s has %d mana and needed %d and already spent %d",
  49. hero->name,
  50. hero->mana,
  51. getManaCost(hero),
  52. source->manaCost);
  53. #endif
  54. return hero->mana >= source->manaCost + getManaCost(hero);
  55. }
  56. uint32_t SummonBoatAction::getManaCost(const CGHeroInstance * hero) const
  57. {
  58. SpellID summonBoat = SpellID::SUMMON_BOAT;
  59. return hero->getSpellCost(summonBoat.toSpell());
  60. }
  61. }