StayAtTown.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * ArmyUpgrade.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 "StayAtTown.h"
  12. #include "../AIGateway.h"
  13. #include "../Engine/Nullkiller.h"
  14. #include "../AIUtility.h"
  15. namespace NKAI
  16. {
  17. using namespace Goals;
  18. StayAtTown::StayAtTown(const CGTownInstance * town, AIPath & path)
  19. : ElementarGoal(Goals::STAY_AT_TOWN)
  20. {
  21. sethero(path.targetHero);
  22. settown(town);
  23. movementWasted = static_cast<float>(hero->movementPointsRemaining()) / hero->movementPointsLimit(!hero->inBoat()) - path.movementCost();
  24. vstd::amax(movementWasted, 0);
  25. }
  26. bool StayAtTown::operator==(const StayAtTown & other) const
  27. {
  28. return hero == other.hero && town == other.town;
  29. }
  30. std::string StayAtTown::toString() const
  31. {
  32. return "Stay at town " + town->getNameTranslated()
  33. + " hero " + hero->getNameTranslated()
  34. + ", mana: " + std::to_string(hero->mana)
  35. + " / " + std::to_string(hero->manaLimit());
  36. }
  37. void StayAtTown::accept(AIGateway * ai)
  38. {
  39. ai->nullkiller->lockHero(hero, HeroLockedReason::DEFENCE);
  40. }
  41. }