repath just by pathing again; more sanity checking of simple paths
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -72,26 +72,19 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
void PlanMoreHarvesting(Actor self, Mobile mobile)
|
||||
{
|
||||
/* find a nearby patch */
|
||||
/* todo: add the queries we need to support this! */
|
||||
|
||||
var search = new PathSearch
|
||||
{
|
||||
heuristic = loc => ( Game.map.ContainsResource( loc ) ? 0 : 1 ),
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
search.AddInitialCell( self.Location );
|
||||
|
||||
var path = Game.PathFinder.FindPath( search )
|
||||
.TakeWhile( a => a != self.Location )
|
||||
.ToList();
|
||||
|
||||
if( path.Count != 0 )
|
||||
{
|
||||
mobile.QueueActivity( new Move( path ) );
|
||||
mobile.QueueActivity( new Harvest() );
|
||||
}
|
||||
mobile.QueueActivity(new Move(
|
||||
() =>
|
||||
{
|
||||
var search = new PathSearch
|
||||
{
|
||||
heuristic = loc => (Game.map.ContainsResource(loc) ? 0 : 1),
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
search.AddInitialCell(self.Location);
|
||||
return Game.PathFinder.FindPath(search);
|
||||
}));
|
||||
mobile.QueueActivity(new Harvest());
|
||||
|
||||
mobile.InternalSetActivity( NextActivity );
|
||||
}
|
||||
|
||||
@@ -34,10 +34,11 @@ namespace OpenRa.Game.Traits.Activities
|
||||
this.nearEnough = range;
|
||||
}
|
||||
|
||||
public Move( List<int2> path )
|
||||
public Move(Func<List<int2>> getPath)
|
||||
{
|
||||
this.path = path;
|
||||
this.destination = path[ 0 ];
|
||||
this.getPath = (_, _2) => getPath();
|
||||
this.destination = null;
|
||||
this.nearEnough = 0;
|
||||
}
|
||||
|
||||
static bool CanEnterCell( int2 c, Actor self )
|
||||
@@ -114,17 +115,23 @@ namespace OpenRa.Game.Traits.Activities
|
||||
}
|
||||
|
||||
Game.UnitInfluence.Remove( mobile );
|
||||
var newPath = Game.PathFinder.FindPathToPath( self.Location, path, mobile.GetMovementType() )
|
||||
.TakeWhile( a => a != self.Location )
|
||||
.ToList();
|
||||
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
||||
//var newPath = Game.PathFinder.FindPathToPath( self.Location, path, mobile.GetMovementType() )
|
||||
// .TakeWhile( a => a != self.Location )
|
||||
// .ToList();
|
||||
Game.UnitInfluence.Add( mobile );
|
||||
if( newPath.Count == 0 )
|
||||
if (newPath.Count == 0)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
path = newPath;
|
||||
return null;
|
||||
}
|
||||
|
||||
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 ] );
|
||||
//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 ] );
|
||||
|
||||
if( path.Count == 0 )
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user