1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

CPathfinder: split isLayerTransitionPossible into two functions

This way we can avoid usage of getNode for layers that clearly can't be used.
This commit is contained in:
ArseniyShestakov 2015-11-22 06:16:16 +03:00
parent 649ebfad2f
commit 8217eb3a82
2 changed files with 44 additions and 25 deletions

View File

@ -115,6 +115,12 @@ void CPathfinder::calculatePaths()
dtObj = dt->topVisitableObj(); dtObj = dt->topVisitableObj();
for(ELayer i = ELayer::LAND; i <= ELayer::AIR; i.advance(1)) for(ELayer i = ELayer::LAND; i <= ELayer::AIR; i.advance(1))
{ {
if(!hlp->isLayerAvailable(i))
continue;
if(cp->layer != i && !isLayerTransitionPossible(i))
continue;
dp = out.getNode(neighbour, i); dp = out.getNode(neighbour, i);
if(dp->accessible == CGPathNode::NOT_SET) if(dp->accessible == CGPathNode::NOT_SET)
continue; continue;
@ -125,9 +131,6 @@ void CPathfinder::calculatePaths()
if(!passOneTurnLimitCheck(cp->turns != turn)) if(!passOneTurnLimitCheck(cp->turns != turn))
continue; continue;
if(!hlp->isLayerAvailable(i))
continue;
if(cp->layer != i && !isLayerTransitionPossible()) if(cp->layer != i && !isLayerTransitionPossible())
continue; continue;
@ -249,7 +252,7 @@ void CPathfinder::addTeleportExits()
} }
} }
bool CPathfinder::isLayerTransitionPossible() const bool CPathfinder::isLayerTransitionPossible(const ELayer destLayer) const
{ {
/// No layer transition allowed when previous node action is BATTLE /// No layer transition allowed when previous node action is BATTLE
if(cp->action == CGPathNode::BATTLE) if(cp->action == CGPathNode::BATTLE)
@ -258,12 +261,42 @@ bool CPathfinder::isLayerTransitionPossible() const
switch(cp->layer) switch(cp->layer)
{ {
case ELayer::LAND: case ELayer::LAND:
if(options.lightweightFlyingMode && dp->layer == ELayer::AIR) if(destLayer != ELayer::AIR)
{ return true;
if(!isSourceInitialPosition())
return false; if(!options.lightweightFlyingMode || isSourceInitialPosition())
} return true;
else if(dp->layer == ELayer::SAIL)
break;
case ELayer::SAIL:
if(destLayer == ELayer::LAND && dt->isCoastal())
return true;
break;
case ELayer::AIR:
if(destLayer == ELayer::LAND)
return true;
break;
case ELayer::WATER:
if(destLayer == ELayer::LAND)
return true;
break;
}
return false;
}
bool CPathfinder::isLayerTransitionPossible() const
{
switch(cp->layer)
{
case ELayer::LAND:
if(dp->layer == ELayer::SAIL)
{ {
/// Cannot enter empty water tile from land -> it has to be visitable /// Cannot enter empty water tile from land -> it has to be visitable
if(dp->accessible == CGPathNode::ACCESSIBLE) if(dp->accessible == CGPathNode::ACCESSIBLE)
@ -273,12 +306,6 @@ bool CPathfinder::isLayerTransitionPossible() const
break; break;
case ELayer::SAIL: case ELayer::SAIL:
if(dp->layer != ELayer::LAND)
return false;
if(!dt->isCoastal())
return false;
//tile must be accessible -> exception: unblocked blockvis tiles -> clear but guarded by nearby monster coast //tile must be accessible -> exception: unblocked blockvis tiles -> clear but guarded by nearby monster coast
if((dp->accessible != CGPathNode::ACCESSIBLE && (dp->accessible != CGPathNode::BLOCKVIS || dt->blocked)) if((dp->accessible != CGPathNode::ACCESSIBLE && (dp->accessible != CGPathNode::BLOCKVIS || dt->blocked))
|| dt->visitable) //TODO: passableness problem -> town says it's passable (thus accessible) but we obviously can't disembark onto town gate || dt->visitable) //TODO: passableness problem -> town says it's passable (thus accessible) but we obviously can't disembark onto town gate
@ -289,9 +316,6 @@ bool CPathfinder::isLayerTransitionPossible() const
break; break;
case ELayer::AIR: case ELayer::AIR:
if(dp->layer != ELayer::LAND)
return false;
if(options.originalMovementRules) if(options.originalMovementRules)
{ {
if((cp->accessible != CGPathNode::ACCESSIBLE && if((cp->accessible != CGPathNode::ACCESSIBLE &&
@ -309,12 +333,6 @@ bool CPathfinder::isLayerTransitionPossible() const
} }
break; break;
case ELayer::WATER:
if(dp->layer != ELayer::LAND)
return false;
break;
} }
return true; return true;

View File

@ -180,6 +180,7 @@ private:
void addNeighbours(); void addNeighbours();
void addTeleportExits(); void addTeleportExits();
bool isLayerTransitionPossible(const ELayer dstLayer) const;
bool isLayerTransitionPossible() const; bool isLayerTransitionPossible() const;
bool isMovementToDestPossible() const; bool isMovementToDestPossible() const;
bool isMovementAfterDestPossible() const; bool isMovementAfterDestPossible() const;