repath just by pathing again; more sanity checking of simple paths

This commit is contained in:
Chris Forbes
2009-11-08 20:54:24 +13:00
parent f22170800a
commit 55adc19aa9
3 changed files with 50 additions and 36 deletions

View File

@@ -49,10 +49,13 @@ namespace OpenRa.Game
PathSearch.FromPoint(target, from, umt, false),
PathSearch.FromPoint(from, target, umt, false));
CheckSanePath2(pb, from, target);
return pb;
}
}
public List<int2> FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range )
{
using( new PerfSample( "find_unit_path_multiple_src" ) )
@@ -71,14 +74,12 @@ namespace OpenRa.Game
if( IsBlocked( from, umt ) )
return new List<int2>();
using( new PerfSample( "find_path_to_path" ) )
using (new PerfSample("find_path_to_path"))
return FindBidiPath(
PathSearch.FromPath( path, from, umt, true ),
PathSearch.FromPoint( from, path[ 0 ], umt, true ) );
PathSearch.FromPath(path, from, umt, true),
PathSearch.FromPoint(from, path[0], umt, true));
}
public List<int2> FindPath( PathSearch search )
{
int nodesExpanded = 0;
@@ -153,6 +154,7 @@ namespace OpenRa.Game
ret.Add( q );
q = ca[ q.X, q.Y ].Path;
}
ret.Add(q);
ret.Reverse();
@@ -183,6 +185,18 @@ namespace OpenRa.Game
prev = path[ i ];
}
}
[System.Diagnostics.Conditional("SANITY_CHECKS")]
static void CheckSanePath2(List<int2> path, int2 src, int2 dest)
{
if (path.Count == 0)
return;
if (path[0] != dest)
throw new InvalidOperationException("(PathFinder) sanity check failed: doesn't go to dest");
if (path[path.Count - 1] != src)
throw new InvalidOperationException("(PathFinder) sanity check failed: doesn't come from src");
}
}
struct CellInfo