1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

CPathfinder: cleanup checks for source node visitable object

This commit is contained in:
ArseniyShestakov 2015-11-16 17:36:58 +03:00
parent aa59ad05ed
commit 6dd9572644
2 changed files with 27 additions and 35 deletions

View File

@ -102,7 +102,7 @@ void CPathfinder::calculatePaths()
pq.pop();
cp->locked = true;
ct = &gs->map->getTile(cp->coord);
cObj = ct->topVisitableObj(cp->coord == out.hpos);
cObj = ct->topVisitableObj(isSourceInitialPosition());
int movement = cp->moveRemains, turn = cp->turns;
hlp->updateTurnInfo(turn);
@ -173,23 +173,20 @@ void CPathfinder::calculatePaths()
} //neighbours loop
//just add all passable teleport exits
if(cObj && canVisitObject())
addTeleportExits();
for(auto & neighbour : neighbours)
{
addTeleportExits();
for(auto & neighbour : neighbours)
{
dp = out.getNode(neighbour, cp->layer);
if(dp->locked)
continue;
dp = out.getNode(neighbour, cp->layer);
if(dp->locked)
continue;
if(isBetterWay(movement, turn))
{
dp->moveRemains = movement;
dp->turns = turn;
dp->theNodeBefore = cp;
dp->action = CGPathNode::NORMAL;
pq.push(dp);
}
if(isBetterWay(movement, turn))
{
dp->moveRemains = movement;
dp->turns = turn;
dp->theNodeBefore = cp;
dp->action = CGPathNode::NORMAL;
pq.push(dp);
}
}
} //queue loop
@ -200,18 +197,13 @@ void CPathfinder::addNeighbours(const int3 & coord)
neighbours.clear();
std::vector<int3> tiles;
CPathfinderHelper::getNeighbours(gs, *ct, coord, tiles, boost::logic::indeterminate, cp->layer == ELayer::SAIL); // TODO: find out if we still need "limitCoastSailing" option
if(canVisitObject())
if(isSourceVisitableObj())
{
if(cObj)
for(int3 tile: tiles)
{
for(int3 tile: tiles)
{
if(canMoveBetween(tile, cObj->visitablePos()))
neighbours.push_back(tile);
}
if(canMoveBetween(tile, cObj->visitablePos()))
neighbours.push_back(tile);
}
else
vstd::concatenate(neighbours, tiles);
}
else
vstd::concatenate(neighbours, tiles);
@ -219,9 +211,10 @@ void CPathfinder::addNeighbours(const int3 & coord)
void CPathfinder::addTeleportExits(bool noTeleportExcludes)
{
assert(cObj);
neighbours.clear();
if(!isSourceVisitableObj())
return;
auto isAllowedTeleportEntrance = [&](const CGTeleport * obj) -> bool
{
if(!gs->isTeleportEntrancePassable(obj, hero->tempOwner))
@ -519,6 +512,12 @@ bool CPathfinder::isSourceInitialPosition() const
return cp->coord == out.hpos;
}
bool CPathfinder::isSourceVisitableObj() const
{
/// Hero can't visit objects while walking on water or flying
return cObj != nullptr && (cp->layer == ELayer::LAND || cp->layer == ELayer::SAIL);
}
bool CPathfinder::isSourceGuarded() const
{
/// Hero can move from guarded tile if movement started on that tile
@ -674,12 +673,6 @@ bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
return options.useTeleportWhirlpool && obj;
}
bool CPathfinder::canVisitObject() const
{
//hero can't visit objects while walking on water or flying
return cp->layer == ELayer::LAND || cp->layer == ELayer::SAIL;
}
TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn)
: hero(Hero), maxMovePointsLand(-1), maxMovePointsWater(-1)
{

View File

@ -172,6 +172,7 @@ private:
CGPathNode::ENodeAction getDestAction() const;
bool isSourceInitialPosition() const;
bool isSourceVisitableObj() const;
bool isSourceGuarded() const;
bool isDestinationGuarded(const bool ignoreAccessibility = true) const;
bool isDestinationGuardian() const;
@ -186,8 +187,6 @@ private:
bool addTeleportOneWayRandom(const CGTeleport * obj) const;
bool addTeleportWhirlpool(const CGWhirlpool * obj) const;
bool canVisitObject() const;
};
struct DLL_LINKAGE TurnInfo