1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #3537 from vcmi/nkai-fix-pathfinder-commited-tiles

NKAI: avoid writing to commited tiles when calculating hero chain
This commit is contained in:
Andrii Danylchenko 2024-01-21 14:51:33 +02:00 committed by GitHub
commit bf54a6a7d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View File

@ -35,6 +35,8 @@ const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN = 5000;
const uint64_t MIN_ARMY_STRENGTH_FOR_NEXT_ACTOR = 1000;
const uint64_t CHAIN_MAX_DEPTH = 4;
const bool DO_NOT_SAVE_TO_COMMITED_TILES = false;
AISharedStorage::AISharedStorage(int3 sizes)
{
if(!shared){
@ -266,7 +268,8 @@ void AINodeStorage::commit(
EPathNodeAction action,
int turn,
int movementLeft,
float cost) const
float cost,
bool saveToCommited) const
{
destination->action = action;
destination->setCost(cost);
@ -292,7 +295,7 @@ void AINodeStorage::commit(
destination->actor->armyValue);
#endif
if(destination->turns <= heroChainTurn)
if(saveToCommited && destination->turns <= heroChainTurn)
{
commitedTiles.insert(destination->coord);
}
@ -784,7 +787,14 @@ void HeroChainCalculationTask::addHeroChain(const std::vector<ExchangeCandidate>
continue;
}
storage.commit(exchangeNode, carrier, carrier->action, chainInfo.turns, chainInfo.moveRemains, chainInfo.getCost());
storage.commit(
exchangeNode,
carrier,
carrier->action,
chainInfo.turns,
chainInfo.moveRemains,
chainInfo.getCost(),
DO_NOT_SAVE_TO_COMMITED_TILES);
if(carrier->specialAction || carrier->chainOther)
{
@ -1076,7 +1086,8 @@ struct TowmPortalFinder
EPathNodeAction::TELEPORT_NORMAL,
bestNode->turns,
bestNode->moveRemains - movementNeeded,
movementCost);
movementCost,
DO_NOT_SAVE_TO_COMMITED_TILES);
node->theNodeBefore = bestNode;
node->addSpecialAction(std::make_shared<AIPathfinding::TownPortalAction>(targetTown));

View File

@ -208,7 +208,8 @@ public:
EPathNodeAction action,
int turn,
int movementLeft,
float cost) const;
float cost,
bool saveToCommited = true) const;
inline const AIPathNode * getAINode(const CGPathNode * node) const
{