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

@@ -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;