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(target, from, umt, false),
|
||||||
PathSearch.FromPoint(from, target, umt, false));
|
PathSearch.FromPoint(from, target, umt, false));
|
||||||
|
|
||||||
|
CheckSanePath2(pb, from, target);
|
||||||
return pb;
|
return pb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<int2> FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range )
|
public List<int2> FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range )
|
||||||
{
|
{
|
||||||
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
using( new PerfSample( "find_unit_path_multiple_src" ) )
|
||||||
@@ -71,14 +74,12 @@ namespace OpenRa.Game
|
|||||||
if( IsBlocked( from, umt ) )
|
if( IsBlocked( from, umt ) )
|
||||||
return new List<int2>();
|
return new List<int2>();
|
||||||
|
|
||||||
using( new PerfSample( "find_path_to_path" ) )
|
using (new PerfSample("find_path_to_path"))
|
||||||
return FindBidiPath(
|
return FindBidiPath(
|
||||||
PathSearch.FromPath( path, from, umt, true ),
|
PathSearch.FromPath(path, from, umt, true),
|
||||||
PathSearch.FromPoint( from, path[ 0 ], umt, true ) );
|
PathSearch.FromPoint(from, path[0], umt, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<int2> FindPath( PathSearch search )
|
public List<int2> FindPath( PathSearch search )
|
||||||
{
|
{
|
||||||
int nodesExpanded = 0;
|
int nodesExpanded = 0;
|
||||||
@@ -153,6 +154,7 @@ namespace OpenRa.Game
|
|||||||
ret.Add( q );
|
ret.Add( q );
|
||||||
q = ca[ q.X, q.Y ].Path;
|
q = ca[ q.X, q.Y ].Path;
|
||||||
}
|
}
|
||||||
|
ret.Add(q);
|
||||||
|
|
||||||
ret.Reverse();
|
ret.Reverse();
|
||||||
|
|
||||||
@@ -183,6 +185,18 @@ namespace OpenRa.Game
|
|||||||
prev = path[ i ];
|
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
|
struct CellInfo
|
||||||
|
|||||||
@@ -72,26 +72,19 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
|
|
||||||
void PlanMoreHarvesting(Actor self, Mobile mobile)
|
void PlanMoreHarvesting(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
/* find a nearby patch */
|
mobile.QueueActivity(new Move(
|
||||||
/* todo: add the queries we need to support this! */
|
() =>
|
||||||
|
{
|
||||||
var search = new PathSearch
|
var search = new PathSearch
|
||||||
{
|
{
|
||||||
heuristic = loc => ( Game.map.ContainsResource( loc ) ? 0 : 1 ),
|
heuristic = loc => (Game.map.ContainsResource(loc) ? 0 : 1),
|
||||||
umt = UnitMovementType.Wheel,
|
umt = UnitMovementType.Wheel,
|
||||||
checkForBlocked = true
|
checkForBlocked = true
|
||||||
};
|
};
|
||||||
search.AddInitialCell( self.Location );
|
search.AddInitialCell(self.Location);
|
||||||
|
return Game.PathFinder.FindPath(search);
|
||||||
var path = Game.PathFinder.FindPath( search )
|
}));
|
||||||
.TakeWhile( a => a != self.Location )
|
mobile.QueueActivity(new Harvest());
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if( path.Count != 0 )
|
|
||||||
{
|
|
||||||
mobile.QueueActivity( new Move( path ) );
|
|
||||||
mobile.QueueActivity( new Harvest() );
|
|
||||||
}
|
|
||||||
|
|
||||||
mobile.InternalSetActivity( NextActivity );
|
mobile.InternalSetActivity( NextActivity );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,11 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
this.nearEnough = range;
|
this.nearEnough = range;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Move( List<int2> path )
|
public Move(Func<List<int2>> getPath)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.getPath = (_, _2) => getPath();
|
||||||
this.destination = path[ 0 ];
|
this.destination = null;
|
||||||
|
this.nearEnough = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool CanEnterCell( int2 c, Actor self )
|
static bool CanEnterCell( int2 c, Actor self )
|
||||||
@@ -114,17 +115,23 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
}
|
}
|
||||||
|
|
||||||
Game.UnitInfluence.Remove( mobile );
|
Game.UnitInfluence.Remove( mobile );
|
||||||
var newPath = Game.PathFinder.FindPathToPath( self.Location, path, mobile.GetMovementType() )
|
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
|
||||||
.TakeWhile( a => a != self.Location )
|
//var newPath = Game.PathFinder.FindPathToPath( self.Location, path, mobile.GetMovementType() )
|
||||||
.ToList();
|
// .TakeWhile( a => a != self.Location )
|
||||||
|
// .ToList();
|
||||||
Game.UnitInfluence.Add( mobile );
|
Game.UnitInfluence.Add( mobile );
|
||||||
if( newPath.Count == 0 )
|
if (newPath.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path = newPath;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
while( path.Count != 0 && path[ path.Count - 1 ] != newPath[ 0 ] )
|
//while( path.Count != 0 && path[ path.Count - 1 ] != newPath[ 0 ] )
|
||||||
path.RemoveAt( path.Count - 1 );
|
// path.RemoveAt( path.Count - 1 );
|
||||||
for( int i = 1 ; i < newPath.Count ; i++ )
|
//for( int i = 1 ; i < newPath.Count ; i++ )
|
||||||
path.Add( newPath[ i ] );
|
// path.Add( newPath[ i ] );
|
||||||
|
|
||||||
if( path.Count == 0 )
|
if( path.Count == 0 )
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user