diff --git a/OpenRa.Game/PathFinder.cs b/OpenRa.Game/PathFinder.cs index b1e812746d..0e95effab9 100644 --- a/OpenRa.Game/PathFinder.cs +++ b/OpenRa.Game/PathFinder.cs @@ -102,10 +102,12 @@ namespace OpenRa.Game var otherQueue = new PriorityQueue(); otherQueue.Add(new PathDistance(h2(from), from)); - var ret = FindBidiPath(cellInfo, InitCellInfo(), queue, otherQueue, estimator, h2, umt, true); + var otherCellInfo = InitCellInfo(); + otherCellInfo[from.X, from.Y] = new CellInfo( 0, from, false ); + var ret = FindBidiPath(cellInfo, otherCellInfo, queue, otherQueue, estimator, h2, umt, true); //var ret = FindPath(cellInfo, queue, estimator, umt, true); - ret.Reverse(); + //ret.Reverse(); return ret; } } @@ -262,27 +264,41 @@ namespace OpenRa.Game static List MakeBidiPath(CellInfo[,] ca, CellInfo[,] cb, int2 p) { var a = new List(); - var b = new List(); var q = p; while (ca[q.X, q.Y].Path != q) { - q = ca[q.X, q.Y].Path; - a.Add(q); + a.Add( q ); + q = ca[ q.X, q.Y ].Path; } + a.Reverse(); + q = p; while (cb[q.X, q.Y].Path != q) { q = cb[q.X, q.Y].Path; - b.Add(q); + a.Add(q); } - a.Add(p); - for (var v = b.Count - 1; v >= 0; v--) a.Add(b[v]); - + CheckSanePath( a ); return a; } + + [System.Diagnostics.Conditional( "SANITY_CHECKS" )] + static void CheckSanePath( List path ) + { + if( path.Count == 0 ) + return; + var prev = path[ 0 ]; + for( int i = 0 ; i < path.Count ; i++ ) + { + var d = path[ i ] - prev; + if( Math.Abs( d.X ) > 1 || Math.Abs( d.Y ) > 1 ) + throw new InvalidOperationException( "(PathFinder) path sanity check failed" ); + prev = path[ i ]; + } + } } struct CellInfo diff --git a/OpenRa.Game/Traits/Activities/Move.cs b/OpenRa.Game/Traits/Activities/Move.cs index fd70f536e5..d724d2f526 100755 --- a/OpenRa.Game/Traits/Activities/Move.cs +++ b/OpenRa.Game/Traits/Activities/Move.cs @@ -121,10 +121,10 @@ namespace OpenRa.Game.Traits.Activities if( newPath.Count == 0 ) return null; - while( path[ path.Count - 1 ] != newPath[ 0 ] ) - path.RemoveAt( path.Count - 1 ); + while( path.Count != 0 && path[ path.Count - 1 ] != newPath[ 0 ] ) + path.RemoveAt( path.Count - 1 ); for( int i = 1 ; i < newPath.Count ; i++ ) - path.Add( newPath[ i ] ); + path.Add( newPath[ i ] ); if( path.Count == 0 ) return null;