Rewrite Enter and related activities.

The unit will now path to the nearest adjacent cell, drag inside, do the inner activity, then (if still alive) drag back to its original
location.

This fixes:
 - Mismatch in logic between Enter and MoveAdjacentTo,
   which causes an infinite loop.
 - Building capturing failing from certain directions.
 - Being unable to enter buildings on unpathable tiles.
 - Units being stranded inside a building if the requirements
   for the inner order aren't met.
This commit is contained in:
Paul Chote
2013-04-15 01:50:19 +12:00
parent 8676562d47
commit e76c746b61
10 changed files with 87 additions and 82 deletions

View File

@@ -17,33 +17,34 @@ namespace OpenRA.Mods.RA.Activities
{
readonly Target target;
public MoveAdjacentTo( Target target ) { this.target = target; }
public MoveAdjacentTo(Target target) { this.target = target; }
public override Activity Tick( Actor self )
public override Activity Tick(Actor self)
{
if( IsCanceled || !target.IsValid) return NextActivity;
if (IsCanceled || !target.IsValid)
return NextActivity;
var mobile = self.Trait<Mobile>();
var ps1 = new PathSearch( self.World, mobile.Info, self )
var ps1 = new PathSearch(self.World, mobile.Info, self)
{
checkForBlocked = true,
heuristic = location => 0,
inReverse = true
};
foreach( var cell in Util.AdjacentCells(target) )
foreach (var cell in Util.AdjacentCells(target))
{
if (cell == self.Location)
return NextActivity;
else
ps1.AddInitialCell( cell );
ps1.AddInitialCell(cell);
}
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);
var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, target.CenterLocation.ToCPos(), true);
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath(ps1, ps2);
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, target.CenterLocation.ToCPos(), true );
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );
return Util.SequenceActivities(mobile.MoveTo(() => ret), this);
}
}
}