1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

CPathfinder: get rid of hero object usage when it's not needed

This commit is contained in:
ArseniyShestakov
2015-11-04 15:38:15 +03:00
parent 1bc335323d
commit f4dea88e3b
2 changed files with 10 additions and 5 deletions

View File

@ -172,7 +172,7 @@ void CPathfinder::addNeighbours(const int3 &coord)
std::vector<int3> tiles; std::vector<int3> tiles;
gs->getNeighbours(*ct, coord, tiles, boost::logic::indeterminate, !cp->land); gs->getNeighbours(*ct, coord, tiles, boost::logic::indeterminate, !cp->land);
sTileObj = ct->topVisitableObj(coord == CGHeroInstance::convertPosition(hero->pos, false)); sTileObj = ct->topVisitableObj(coord == out.hpos);
if(canVisitObject()) if(canVisitObject())
{ {
if(sTileObj) if(sTileObj)
@ -236,7 +236,7 @@ bool CPathfinder::isLayerTransitionPossible()
} }
else if(cp->layer == EPathfindingLayer::LAND && dp->layer == EPathfindingLayer::AIR) else if(cp->layer == EPathfindingLayer::LAND && dp->layer == EPathfindingLayer::AIR)
{ {
if(options.lightweightFlyingMode && cp->coord != hero->getPosition(false)) if(options.lightweightFlyingMode && !isSourceInitialPosition())
return false; return false;
} }
else if(cp->layer == EPathfindingLayer::SAIL && dp->layer != EPathfindingLayer::LAND) else if(cp->layer == EPathfindingLayer::SAIL && dp->layer != EPathfindingLayer::LAND)
@ -312,7 +312,7 @@ bool CPathfinder::isMovementAfterDestPossible()
case EPathfindingLayer::SAIL: case EPathfindingLayer::SAIL:
if(dp->accessible == CGPathNode::ACCESSIBLE) if(dp->accessible == CGPathNode::ACCESSIBLE)
return true; return true;
if(dp->coord == CGHeroInstance::convertPosition(hero->pos, false)) if(dp->coord == out.hpos)
return true; // This one is tricky, we can ignore fact that tile is not ACCESSIBLE in case if it's our hero block it. Though this need investigation return true; // This one is tricky, we can ignore fact that tile is not ACCESSIBLE in case if it's our hero block it. Though this need investigation
if(dp->accessible == CGPathNode::VISITABLE && CGTeleport::isTeleport(dt->topVisitableObj())) if(dp->accessible == CGPathNode::VISITABLE && CGTeleport::isTeleport(dt->topVisitableObj()))
return true; // For now we'll always allow transit for teleporters return true; // For now we'll always allow transit for teleporters
@ -332,6 +332,11 @@ bool CPathfinder::isMovementAfterDestPossible()
return false; return false;
} }
bool CPathfinder::isSourceInitialPosition()
{
return cp->coord == out.hpos;
}
int3 CPathfinder::getSourceGuardPosition() int3 CPathfinder::getSourceGuardPosition()
{ {
return gs->map->guardingCreaturePositions[cp->coord.x][cp->coord.y][cp->coord.z]; return gs->map->guardingCreaturePositions[cp->coord.x][cp->coord.y][cp->coord.z];
@ -341,8 +346,7 @@ bool CPathfinder::isSourceGuarded()
{ {
//map can start with hero on guarded tile or teleport there using dimension door //map can start with hero on guarded tile or teleport there using dimension door
//so threat tile hero standing on like it's not guarded because it's should be possible to move out of here //so threat tile hero standing on like it's not guarded because it's should be possible to move out of here
if(getSourceGuardPosition() != int3(-1, -1, -1) if(getSourceGuardPosition() != int3(-1, -1, -1) && !isSourceInitialPosition())
&& cp->coord != hero->getPosition(false))
{ {
//special case -> hero embarked a boat standing on a guarded tile -> we must allow to move away from that tile //special case -> hero embarked a boat standing on a guarded tile -> we must allow to move away from that tile
if(cp->accessible != CGPathNode::VISITABLE if(cp->accessible != CGPathNode::VISITABLE

View File

@ -114,6 +114,7 @@ private:
bool isMovementToDestPossible(); bool isMovementToDestPossible();
bool isMovementAfterDestPossible(); bool isMovementAfterDestPossible();
bool isSourceInitialPosition();
int3 getSourceGuardPosition(); int3 getSourceGuardPosition();
bool isSourceGuarded(); bool isSourceGuarded();
bool isDestinationGuarded(); bool isDestinationGuarded();