Browse Source

CPathfinder: move embark special case to isMovementToDestPossible

ArseniyShestakov 10 years ago
parent
commit
09473f6648
1 changed files with 14 additions and 11 deletions
  1. 14 11
      lib/CPathfinder.cpp

+ 14 - 11
lib/CPathfinder.cpp

@@ -327,6 +327,7 @@ bool CPathfinder::isLayerTransitionPossible() const
 		{
 		{
 			return false;
 			return false;
 		}
 		}
+
 		break;
 		break;
 
 
 	case ELayer::AIR:
 	case ELayer::AIR:
@@ -382,8 +383,12 @@ bool CPathfinder::isMovementToDestPossible() const
 	case ELayer::SAIL:
 	case ELayer::SAIL:
 		if(!canMoveBetween(cp->coord, dp->coord) || dp->accessible == CGPathNode::BLOCKED)
 		if(!canMoveBetween(cp->coord, dp->coord) || dp->accessible == CGPathNode::BLOCKED)
 			return false;
 			return false;
-		if(isSourceGuarded() && !isDestinationGuardian()) // Can step into tile of guard
-			return false;
+		if(isSourceGuarded())
+		{
+			// Hero embarked a boat standing on a guarded tile -> we must allow to move away from that tile
+			if(cp->action != CGPathNode::EMBARK && !isDestinationGuardian())
+				return false;
+		}
 
 
 		if(cp->layer == ELayer::LAND)
 		if(cp->layer == ELayer::LAND)
 		{
 		{
@@ -393,6 +398,7 @@ bool CPathfinder::isMovementToDestPossible() const
 			if(dObj->ID != Obj::BOAT && dObj->ID != Obj::HERO)
 			if(dObj->ID != Obj::BOAT && dObj->ID != Obj::HERO)
 				return false;
 				return false;
 		}
 		}
+
 		break;
 		break;
 
 
 	case ELayer::WATER:
 	case ELayer::WATER:
@@ -526,17 +532,14 @@ int3 CPathfinder::getSourceGuardPosition() const
 
 
 bool CPathfinder::isSourceGuarded() const
 bool CPathfinder::isSourceGuarded() const
 {
 {
-	//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
+	/// Hero can move from guarded tile if movement started on that tile
+	/// It's possible at least in these cases:
+	/// - Map start with hero on guarded tile
+	/// - Dimention door used
+	///  TODO: check what happen when there is several guards
 	if(getSourceGuardPosition() != int3(-1, -1, -1) && !isSourceInitialPosition())
 	if(getSourceGuardPosition() != int3(-1, -1, -1) && !isSourceInitialPosition())
 	{
 	{
-		//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 ||
-			cp->theNodeBefore->layer == ELayer::LAND ||
-			cObj->ID != Obj::BOAT)
-		{
-			return true;
-		}
+		return true;
 	}
 	}
 
 
 	return false;
 	return false;