2
0

ExploreNeighbourTile.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ExploreNeighbourTile.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 "ExploreNeighbourTile.h"
  12. #include "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../Helpers/ExplorationHelper.h"
  15. namespace NKAI
  16. {
  17. using namespace Goals;
  18. bool ExploreNeighbourTile::operator==(const ExploreNeighbourTile & other) const
  19. {
  20. return false;
  21. }
  22. void ExploreNeighbourTile::accept(AIGateway * ai)
  23. {
  24. ExplorationHelper h(hero, ai->nullkiller.get(), true);
  25. for(int i = 0; i < tilesToExplore && ai->myCb->getObj(hero->id, false) && hero->movementPointsRemaining() > 0; i++)
  26. {
  27. int3 pos = hero->visitablePos();
  28. float value = 0;
  29. int3 target = int3(-1);
  30. foreach_neighbour(pos, [&](int3 tile)
  31. {
  32. auto pathInfo = ai->nullkiller->getPathsInfo(hero)->getPathInfo(tile);
  33. if(pathInfo->turns > 0)
  34. return;
  35. if(pathInfo->accessible == EPathAccessibility::ACCESSIBLE)
  36. {
  37. float newValue = h.howManyTilesWillBeDiscovered(tile);
  38. newValue /= std::min(0.1f, pathInfo->getCost());
  39. if(newValue > value)
  40. {
  41. value = newValue;
  42. target = tile;
  43. }
  44. }
  45. });
  46. if(!target.isValid())
  47. {
  48. return;
  49. }
  50. auto danger = ai->nullkiller->dangerEvaluator->evaluateDanger(target, hero, true);
  51. if(danger > 0 || !ai->moveHeroToTile(target, hero))
  52. {
  53. return;
  54. }
  55. }
  56. }
  57. std::string ExploreNeighbourTile::toString() const
  58. {
  59. return "Explore neighbour tiles by " + hero->getNameTranslated();
  60. }
  61. }