CPathfinder.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * CPathfinder.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 "CPathfinder.h"
  12. #include "INodeStorage.h"
  13. #include "PathfinderOptions.h"
  14. #include "PathfindingRules.h"
  15. #include "TurnInfo.h"
  16. #include "../gameState/CGameState.h"
  17. #include "../CPlayerState.h"
  18. #include "../TerrainHandler.h"
  19. #include "../mapObjects/CGHeroInstance.h"
  20. #include "../mapping/CMap.h"
  21. VCMI_LIB_NAMESPACE_BEGIN
  22. std::vector<int3> CPathfinderHelper::getNeighbourTiles(const PathNodeInfo & source) const
  23. {
  24. std::vector<int3> neighbourTiles;
  25. neighbourTiles.reserve(8);
  26. getNeighbours(
  27. *source.tile,
  28. source.node->coord,
  29. neighbourTiles,
  30. boost::logic::indeterminate,
  31. source.node->layer == EPathfindingLayer::SAIL);
  32. if(source.isNodeObjectVisitable())
  33. {
  34. vstd::erase_if(neighbourTiles, [&](const int3 & tile) -> bool
  35. {
  36. return !canMoveBetween(tile, source.nodeObject->visitablePos());
  37. });
  38. }
  39. return neighbourTiles;
  40. }
  41. CPathfinder::CPathfinder(CGameState * _gs, std::shared_ptr<PathfinderConfig> config):
  42. gamestate(_gs),
  43. config(std::move(config))
  44. {
  45. initializeGraph();
  46. }
  47. void CPathfinder::push(CGPathNode * node)
  48. {
  49. if(node && !node->inPQ)
  50. {
  51. node->inPQ = true;
  52. node->pq = &this->pq;
  53. auto handle = pq.push(node);
  54. node->pqHandle = handle;
  55. }
  56. }
  57. CGPathNode * CPathfinder::topAndPop()
  58. {
  59. auto * node = pq.top();
  60. pq.pop();
  61. node->inPQ = false;
  62. node->pq = nullptr;
  63. return node;
  64. }
  65. void CPathfinder::calculatePaths()
  66. {
  67. //logGlobal->info("Calculating paths for hero %s (adress %d) of player %d", hero->name, hero , hero->tempOwner);
  68. //initial tile - set cost on 0 and add to the queue
  69. std::vector<CGPathNode *> initialNodes = config->nodeStorage->getInitialNodes();
  70. int counter = 0;
  71. for(auto * initialNode : initialNodes)
  72. {
  73. if(!gamestate->isInTheMap(initialNode->coord)/* || !gs->map->isInTheMap(dest)*/) //check input
  74. {
  75. logGlobal->error("CGameState::calculatePaths: Hero outside the gs->map? How dare you...");
  76. throw std::runtime_error("Wrong checksum");
  77. }
  78. source.setNode(gamestate, initialNode);
  79. auto * hlp = config->getOrCreatePathfinderHelper(source, gamestate);
  80. if(hlp->isHeroPatrolLocked())
  81. continue;
  82. pq.push(initialNode);
  83. }
  84. while(!pq.empty())
  85. {
  86. counter++;
  87. auto * node = topAndPop();
  88. source.setNode(gamestate, node);
  89. source.node->locked = true;
  90. int movement = source.node->moveRemains;
  91. uint8_t turn = source.node->turns;
  92. float cost = source.node->getCost();
  93. auto * hlp = config->getOrCreatePathfinderHelper(source, gamestate);
  94. hlp->updateTurnInfo(turn);
  95. if(!movement)
  96. {
  97. hlp->updateTurnInfo(++turn);
  98. movement = hlp->getMaxMovePoints(source.node->layer);
  99. if(!hlp->passOneTurnLimitCheck(source))
  100. continue;
  101. if(turn >= hlp->options.turnLimit)
  102. continue;
  103. }
  104. source.isInitialPosition = source.nodeHero == hlp->hero;
  105. source.updateInfo(hlp, gamestate);
  106. //add accessible neighbouring nodes to the queue
  107. auto neighbourNodes = config->nodeStorage->calculateNeighbours(source, config.get(), hlp);
  108. for(CGPathNode * neighbour : neighbourNodes)
  109. {
  110. if(neighbour->locked)
  111. continue;
  112. if(!hlp->isLayerAvailable(neighbour->layer))
  113. continue;
  114. destination.setNode(gamestate, neighbour);
  115. hlp = config->getOrCreatePathfinderHelper(destination, gamestate);
  116. if(!hlp->isPatrolMovementAllowed(neighbour->coord))
  117. continue;
  118. /// Check transition without tile accessability rules
  119. if(source.node->layer != neighbour->layer && !isLayerTransitionPossible())
  120. continue;
  121. destination.turn = turn;
  122. destination.movementLeft = movement;
  123. destination.cost = cost;
  124. destination.updateInfo(hlp, gamestate);
  125. destination.isGuardianTile = destination.guarded && isDestinationGuardian();
  126. for(const auto & rule : config->rules)
  127. {
  128. rule->process(source, destination, config.get(), hlp);
  129. if(destination.blocked)
  130. break;
  131. }
  132. if(!destination.blocked)
  133. push(destination.node);
  134. } //neighbours loop
  135. //just add all passable teleport exits
  136. hlp = config->getOrCreatePathfinderHelper(source, gamestate);
  137. /// For now we disable teleports usage for patrol movement
  138. /// VCAI not aware about patrol and may stuck while attempt to use teleport
  139. if(hlp->patrolState == CPathfinderHelper::PATROL_RADIUS)
  140. continue;
  141. auto teleportationNodes = config->nodeStorage->calculateTeleportations(source, config.get(), hlp);
  142. for(CGPathNode * teleportNode : teleportationNodes)
  143. {
  144. if(teleportNode->locked)
  145. continue;
  146. /// TODO: We may consider use invisible exits on FoW border in future
  147. /// Useful for AI when at least one tile around exit is visible and passable
  148. /// Objects are usually visible on FoW border anyway so it's not cheating.
  149. ///
  150. /// For now it's disabled as it's will cause crashes in movement code.
  151. if(teleportNode->accessible == EPathAccessibility::BLOCKED)
  152. continue;
  153. destination.setNode(gamestate, teleportNode);
  154. destination.turn = turn;
  155. destination.movementLeft = movement;
  156. destination.cost = cost;
  157. if(destination.isBetterWay())
  158. {
  159. destination.action = getTeleportDestAction();
  160. config->nodeStorage->commit(destination, source);
  161. if(destination.node->action == EPathNodeAction::TELEPORT_NORMAL)
  162. push(destination.node);
  163. }
  164. }
  165. } //queue loop
  166. logAi->trace("CPathfinder finished with %s iterations", std::to_string(counter));
  167. }
  168. std::vector<int3> CPathfinderHelper::getAllowedTeleportChannelExits(const TeleportChannelID & channelID) const
  169. {
  170. std::vector<int3> allowedExits;
  171. for(const auto & objId : getTeleportChannelExits(channelID, hero->tempOwner))
  172. {
  173. const auto * obj = getObj(objId);
  174. if(dynamic_cast<const CGWhirlpool *>(obj))
  175. {
  176. auto pos = obj->getBlockedPos();
  177. for(const auto & p : pos)
  178. {
  179. if(gs->map->getTile(p).topVisitableId() == obj->ID)
  180. allowedExits.push_back(p);
  181. }
  182. }
  183. else if(obj && CGTeleport::isExitPassable(gs, hero, obj))
  184. allowedExits.push_back(obj->visitablePos());
  185. }
  186. return allowedExits;
  187. }
  188. std::vector<int3> CPathfinderHelper::getCastleGates(const PathNodeInfo & source) const
  189. {
  190. std::vector<int3> allowedExits;
  191. auto towns = getPlayerState(hero->tempOwner)->towns;
  192. for(const auto & town : towns)
  193. {
  194. if(town->id != source.nodeObject->id && town->visitingHero == nullptr
  195. && town->hasBuilt(BuildingID::CASTLE_GATE, ETownType::INFERNO))
  196. {
  197. allowedExits.push_back(town->visitablePos());
  198. }
  199. }
  200. return allowedExits;
  201. }
  202. std::vector<int3> CPathfinderHelper::getTeleportExits(const PathNodeInfo & source) const
  203. {
  204. std::vector<int3> teleportationExits;
  205. const auto * objTeleport = dynamic_cast<const CGTeleport *>(source.nodeObject);
  206. if(isAllowedTeleportEntrance(objTeleport))
  207. {
  208. for(const auto & exit : getAllowedTeleportChannelExits(objTeleport->channel))
  209. {
  210. teleportationExits.push_back(exit);
  211. }
  212. }
  213. else if(options.useCastleGate
  214. && (source.nodeObject->ID == Obj::TOWN && source.nodeObject->subID == ETownType::INFERNO
  215. && source.objectRelations != PlayerRelations::ENEMIES))
  216. {
  217. /// TODO: Find way to reuse CPlayerSpecificInfoCallback::getTownsInfo
  218. /// This may be handy if we allow to use teleportation to friendly towns
  219. for(const auto & exit : getCastleGates(source))
  220. {
  221. teleportationExits.push_back(exit);
  222. }
  223. }
  224. return teleportationExits;
  225. }
  226. bool CPathfinderHelper::isHeroPatrolLocked() const
  227. {
  228. return patrolState == PATROL_LOCKED;
  229. }
  230. bool CPathfinderHelper::isPatrolMovementAllowed(const int3 & dst) const
  231. {
  232. if(patrolState == PATROL_RADIUS)
  233. {
  234. if(!vstd::contains(patrolTiles, dst))
  235. return false;
  236. }
  237. return true;
  238. }
  239. bool CPathfinder::isLayerTransitionPossible() const
  240. {
  241. ELayer destLayer = destination.node->layer;
  242. /// No layer transition allowed when previous node action is BATTLE
  243. if(source.node->action == EPathNodeAction::BATTLE)
  244. return false;
  245. switch(source.node->layer)
  246. {
  247. case ELayer::LAND:
  248. if(destLayer == ELayer::AIR)
  249. {
  250. if(!config->options.lightweightFlyingMode || source.isInitialPosition)
  251. return true;
  252. }
  253. else if(destLayer == ELayer::SAIL)
  254. {
  255. if(destination.tile->isWater())
  256. return true;
  257. }
  258. else
  259. return true;
  260. break;
  261. case ELayer::SAIL:
  262. if(destLayer == ELayer::LAND && !destination.tile->isWater())
  263. return true;
  264. break;
  265. case ELayer::AIR:
  266. if(destLayer == ELayer::LAND)
  267. return true;
  268. break;
  269. case ELayer::WATER:
  270. if(destLayer == ELayer::LAND)
  271. return true;
  272. break;
  273. }
  274. return false;
  275. }
  276. EPathNodeAction CPathfinder::getTeleportDestAction() const
  277. {
  278. EPathNodeAction action = EPathNodeAction::TELEPORT_NORMAL;
  279. if(destination.isNodeObjectVisitable() && destination.nodeHero)
  280. {
  281. if(destination.heroRelations == PlayerRelations::ENEMIES)
  282. action = EPathNodeAction::TELEPORT_BATTLE;
  283. else
  284. action = EPathNodeAction::TELEPORT_BLOCKING_VISIT;
  285. }
  286. return action;
  287. }
  288. bool CPathfinder::isDestinationGuardian() const
  289. {
  290. return gamestate->guardingCreaturePosition(destination.node->coord) == destination.node->coord;
  291. }
  292. void CPathfinderHelper::initializePatrol()
  293. {
  294. auto state = PATROL_NONE;
  295. if(hero->patrol.patrolling && !getPlayerState(hero->tempOwner)->human)
  296. {
  297. if(hero->patrol.patrolRadius)
  298. {
  299. state = PATROL_RADIUS;
  300. gs->getTilesInRange(patrolTiles, hero->patrol.initialPos, hero->patrol.patrolRadius, std::optional<PlayerColor>(), 0, int3::DIST_MANHATTAN);
  301. }
  302. else
  303. state = PATROL_LOCKED;
  304. }
  305. patrolState = state;
  306. }
  307. void CPathfinder::initializeGraph()
  308. {
  309. INodeStorage * nodeStorage = config->nodeStorage.get();
  310. nodeStorage->initialize(config->options, gamestate);
  311. }
  312. bool CPathfinderHelper::canMoveBetween(const int3 & a, const int3 & b) const
  313. {
  314. return gs->checkForVisitableDir(a, b);
  315. }
  316. bool CPathfinderHelper::isAllowedTeleportEntrance(const CGTeleport * obj) const
  317. {
  318. if(!obj || !isTeleportEntrancePassable(obj, hero->tempOwner))
  319. return false;
  320. const auto * whirlpool = dynamic_cast<const CGWhirlpool *>(obj);
  321. if(whirlpool)
  322. {
  323. if(addTeleportWhirlpool(whirlpool))
  324. return true;
  325. }
  326. else if(addTeleportTwoWay(obj) || addTeleportOneWay(obj) || addTeleportOneWayRandom(obj))
  327. return true;
  328. return false;
  329. }
  330. bool CPathfinderHelper::addTeleportTwoWay(const CGTeleport * obj) const
  331. {
  332. return options.useTeleportTwoWay && isTeleportChannelBidirectional(obj->channel, hero->tempOwner);
  333. }
  334. bool CPathfinderHelper::addTeleportOneWay(const CGTeleport * obj) const
  335. {
  336. if(options.useTeleportOneWay && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
  337. {
  338. auto passableExits = CGTeleport::getPassableExits(gs, hero, getTeleportChannelExits(obj->channel, hero->tempOwner));
  339. if(passableExits.size() == 1)
  340. return true;
  341. }
  342. return false;
  343. }
  344. bool CPathfinderHelper::addTeleportOneWayRandom(const CGTeleport * obj) const
  345. {
  346. if(options.useTeleportOneWayRandom && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
  347. {
  348. auto passableExits = CGTeleport::getPassableExits(gs, hero, getTeleportChannelExits(obj->channel, hero->tempOwner));
  349. if(passableExits.size() > 1)
  350. return true;
  351. }
  352. return false;
  353. }
  354. bool CPathfinderHelper::addTeleportWhirlpool(const CGWhirlpool * obj) const
  355. {
  356. return options.useTeleportWhirlpool && hasBonusOfType(BonusType::WHIRLPOOL_PROTECTION) && obj;
  357. }
  358. int CPathfinderHelper::movementPointsAfterEmbark(int movement, int basicCost, bool disembark) const
  359. {
  360. return hero->movementPointsAfterEmbark(movement, basicCost, disembark, getTurnInfo());
  361. }
  362. bool CPathfinderHelper::passOneTurnLimitCheck(const PathNodeInfo & source) const
  363. {
  364. if(!options.oneTurnSpecialLayersLimit)
  365. return true;
  366. if(source.node->layer == EPathfindingLayer::WATER)
  367. return false;
  368. if(source.node->layer == EPathfindingLayer::AIR)
  369. {
  370. return options.originalMovementRules && source.node->accessible == EPathAccessibility::ACCESSIBLE;
  371. }
  372. return true;
  373. }
  374. int CPathfinderHelper::getGuardiansCount(int3 tile) const
  375. {
  376. return getGuardingCreatures(tile).size();
  377. }
  378. CPathfinderHelper::CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options):
  379. CGameInfoCallback(gs),
  380. turn(-1),
  381. hero(Hero),
  382. options(Options),
  383. owner(Hero->tempOwner)
  384. {
  385. turnsInfo.reserve(16);
  386. updateTurnInfo();
  387. initializePatrol();
  388. }
  389. CPathfinderHelper::~CPathfinderHelper()
  390. {
  391. for(auto * ti : turnsInfo)
  392. delete ti;
  393. }
  394. void CPathfinderHelper::updateTurnInfo(const int Turn)
  395. {
  396. if(turn != Turn)
  397. {
  398. turn = Turn;
  399. if(turn >= turnsInfo.size())
  400. {
  401. auto * ti = new TurnInfo(hero, turn);
  402. turnsInfo.push_back(ti);
  403. }
  404. }
  405. }
  406. bool CPathfinderHelper::isLayerAvailable(const EPathfindingLayer & layer) const
  407. {
  408. switch(layer)
  409. {
  410. case EPathfindingLayer::AIR:
  411. if(!options.useFlying)
  412. return false;
  413. break;
  414. case EPathfindingLayer::WATER:
  415. if(!options.useWaterWalking)
  416. return false;
  417. break;
  418. }
  419. return turnsInfo[turn]->isLayerAvailable(layer);
  420. }
  421. const TurnInfo * CPathfinderHelper::getTurnInfo() const
  422. {
  423. return turnsInfo[turn];
  424. }
  425. bool CPathfinderHelper::hasBonusOfType(const BonusType type, const int subtype) const
  426. {
  427. return turnsInfo[turn]->hasBonusOfType(type, subtype);
  428. }
  429. int CPathfinderHelper::getMaxMovePoints(const EPathfindingLayer & layer) const
  430. {
  431. return turnsInfo[turn]->getMaxMovePoints(layer);
  432. }
  433. void CPathfinderHelper::getNeighbours(
  434. const TerrainTile & srcTile,
  435. const int3 & srcCoord,
  436. std::vector<int3> & vec,
  437. const boost::logic::tribool & onLand,
  438. const bool limitCoastSailing) const
  439. {
  440. CMap * map = gs->map;
  441. static const int3 dirs[] = {
  442. int3(-1, +1, +0), int3(0, +1, +0), int3(+1, +1, +0),
  443. int3(-1, +0, +0), /* source pos */ int3(+1, +0, +0),
  444. int3(-1, -1, +0), int3(0, -1, +0), int3(+1, -1, +0)
  445. };
  446. for(const auto & dir : dirs)
  447. {
  448. const int3 destCoord = srcCoord + dir;
  449. if(!map->isInTheMap(destCoord))
  450. continue;
  451. const TerrainTile & destTile = map->getTile(destCoord);
  452. if(!destTile.terType->isPassable())
  453. continue;
  454. // //we cannot visit things from blocked tiles
  455. // if(srcTile.blocked && !srcTile.visitable && destTile.visitable && srcTile.blockingObjects.front()->ID != HEROI_TYPE)
  456. // {
  457. // continue;
  458. // }
  459. /// Following condition let us avoid diagonal movement over coast when sailing
  460. if(srcTile.terType->isWater() && limitCoastSailing && destTile.terType->isWater() && dir.x && dir.y) //diagonal move through water
  461. {
  462. const int3 horizontalNeighbour = srcCoord + int3{dir.x, 0, 0};
  463. const int3 verticalNeighbour = srcCoord + int3{0, dir.y, 0};
  464. if(map->getTile(horizontalNeighbour).terType->isLand() || map->getTile(verticalNeighbour).terType->isLand())
  465. continue;
  466. }
  467. if(indeterminate(onLand) || onLand == destTile.terType->isLand())
  468. {
  469. vec.push_back(destCoord);
  470. }
  471. }
  472. }
  473. int CPathfinderHelper::getMovementCost(
  474. const PathNodeInfo & src,
  475. const PathNodeInfo & dst,
  476. const int remainingMovePoints,
  477. const bool checkLast) const
  478. {
  479. return getMovementCost(
  480. src.coord,
  481. dst.coord,
  482. src.tile,
  483. dst.tile,
  484. remainingMovePoints,
  485. checkLast,
  486. dst.node->layer == EPathfindingLayer::SAIL,
  487. dst.node->layer == EPathfindingLayer::WATER
  488. );
  489. }
  490. int CPathfinderHelper::getMovementCost(
  491. const int3 & src,
  492. const int3 & dst,
  493. const TerrainTile * ct,
  494. const TerrainTile * dt,
  495. const int remainingMovePoints,
  496. const bool checkLast,
  497. boost::logic::tribool isDstSailLayer,
  498. boost::logic::tribool isDstWaterLayer) const
  499. {
  500. if(src == dst) //same tile
  501. return 0;
  502. const auto * ti = getTurnInfo();
  503. if(ct == nullptr || dt == nullptr)
  504. {
  505. ct = hero->cb->getTile(src);
  506. dt = hero->cb->getTile(dst);
  507. }
  508. bool isSailLayer;
  509. if(indeterminate(isDstSailLayer))
  510. isSailLayer = hero->boat && hero->boat->layer == EPathfindingLayer::SAIL && dt->terType->isWater();
  511. else
  512. isSailLayer = static_cast<bool>(isDstSailLayer);
  513. bool isWaterLayer;
  514. if(indeterminate(isDstWaterLayer))
  515. isWaterLayer = ((hero->boat && hero->boat->layer == EPathfindingLayer::WATER) || ti->hasBonusOfType(BonusType::WATER_WALKING)) && dt->terType->isWater();
  516. else
  517. isWaterLayer = static_cast<bool>(isDstWaterLayer);
  518. bool isAirLayer = (hero->boat && hero->boat->layer == EPathfindingLayer::AIR) || ti->hasBonusOfType(BonusType::FLYING_MOVEMENT);
  519. int ret = hero->getTileMovementCost(*dt, *ct, ti);
  520. if(isSailLayer)
  521. {
  522. if(ct->hasFavorableWinds())
  523. ret = static_cast<int>(ret * 2.0 / 3);
  524. }
  525. else if(isAirLayer)
  526. vstd::amin(ret, GameConstants::BASE_MOVEMENT_COST + ti->valOfBonuses(BonusType::FLYING_MOVEMENT));
  527. else if(isWaterLayer && ti->hasBonusOfType(BonusType::WATER_WALKING))
  528. ret = static_cast<int>(ret * (100.0 + ti->valOfBonuses(BonusType::WATER_WALKING)) / 100.0);
  529. if(src.x != dst.x && src.y != dst.y) //it's diagonal move
  530. {
  531. int old = ret;
  532. ret = static_cast<int>(ret * M_SQRT2);
  533. //diagonal move costs too much but normal move is possible - allow diagonal move for remaining move points
  534. // https://heroes.thelazy.net/index.php/Movement#Diagonal_move_exception
  535. if(ret > remainingMovePoints && remainingMovePoints >= old)
  536. {
  537. return remainingMovePoints;
  538. }
  539. }
  540. const int left = remainingMovePoints - ret;
  541. constexpr auto maxCostOfOneStep = static_cast<int>(175 * M_SQRT2); // diagonal move on Swamp - 247 MP
  542. if(checkLast && left > 0 && left <= maxCostOfOneStep) //it might be the last tile - if no further move possible we take all move points
  543. {
  544. std::vector<int3> vec;
  545. vec.reserve(8); //optimization
  546. getNeighbours(*dt, dst, vec, ct->terType->isLand(), true);
  547. for(const auto & elem : vec)
  548. {
  549. int fcost = getMovementCost(dst, elem, nullptr, nullptr, left, false);
  550. if(fcost <= left)
  551. {
  552. return ret;
  553. }
  554. }
  555. ret = remainingMovePoints;
  556. }
  557. return ret;
  558. }
  559. VCMI_LIB_NAMESPACE_END