1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

CAdvMapInt: keep old path if non-accessible tile clicked. Fix issue 2380

This commit is contained in:
Arseniy Shestakov 2016-01-17 07:48:21 +03:00
parent 18b2f866c9
commit cacc811ed8

View File

@ -1421,12 +1421,12 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
bool canSelect = topBlocking && topBlocking->ID == Obj::HERO && topBlocking->tempOwner == LOCPLINT->playerID;
canSelect |= topBlocking && topBlocking->ID == Obj::TOWN && LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, topBlocking->tempOwner);
if (selection->ID != Obj::HERO) //hero is not selected (presumably town)
if(selection->ID != Obj::HERO) //hero is not selected (presumably town)
{
assert(!terrain.currentPath); //path can be active only when hero is selected
if(selection == topBlocking) //selected town clicked
LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(topBlocking));
else if ( canSelect )
else if(canSelect)
select(static_cast<const CArmedInstance*>(topBlocking), false);
return;
}
@ -1445,22 +1445,26 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
}
else //still here? we need to move hero if we clicked end of already selected path or calculate a new path otherwise
{
if (terrain.currentPath && terrain.currentPath->endPos() == mapPos)//we'll be moving
if(terrain.currentPath && terrain.currentPath->endPos() == mapPos)//we'll be moving
{
if (CGI->mh->canStartHeroMovement())
LOCPLINT->moveHero(currentHero,*terrain.currentPath);
if(CGI->mh->canStartHeroMovement())
LOCPLINT->moveHero(currentHero, *terrain.currentPath);
return;
}
else/* if(mp.z == currentHero->pos.z)*/ //remove old path and find a new one if we clicked on the map level on which hero is present
else //remove old path and find a new one if we clicked on accessible tile
{
CGPath &path = LOCPLINT->paths[currentHero];
CGPath newpath;
bool gotPath = LOCPLINT->cb->getPathsInfo(currentHero)->getPath(newpath, mapPos); //try getting path, erase if failed
if(gotPath && newpath.nodes.size())
path = newpath;
if(path.nodes.size())
terrain.currentPath = &path;
bool gotPath = LOCPLINT->cb->getPathsInfo(currentHero)->getPath(path, mapPos); //try getting path, erase if failed
updateMoveHero(currentHero);
if (!gotPath)
LOCPLINT->eraseCurrentPathOf(currentHero);
else
return;
LOCPLINT->eraseCurrentPathOf(currentHero);
updateMoveHero(currentHero);
}
}
} //end of hero is selected "case"