Calculate a new path (and possibly new target cell) if the original path is blocked.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
@@ -17,6 +18,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
{
|
{
|
||||||
public class MoveAdjacentTo : Activity
|
public class MoveAdjacentTo : Activity
|
||||||
{
|
{
|
||||||
|
static readonly List<CPos> NoPath = new List<CPos>();
|
||||||
|
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
readonly PathFinder pathFinder;
|
readonly PathFinder pathFinder;
|
||||||
readonly DomainIndex domainIndex;
|
readonly DomainIndex domainIndex;
|
||||||
@@ -52,6 +55,11 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
return targetPosition != oldTargetPosition;
|
return targetPosition != oldTargetPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
|
||||||
|
{
|
||||||
|
return Util.AdjacentCells(self.World, target);
|
||||||
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var targetIsValid = target.IsValidFor(self);
|
var targetIsValid = target.IsValidFor(self);
|
||||||
@@ -65,7 +73,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
// Target has moved, and MoveAdjacentTo is still valid.
|
// Target has moved, and MoveAdjacentTo is still valid.
|
||||||
UpdateInnerPath(self);
|
inner = mobile.MoveTo(() => CalculatePathToTarget(self));
|
||||||
repath = false;
|
repath = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +105,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
|
List<CPos> CalculatePathToTarget(Actor self)
|
||||||
{
|
|
||||||
return Util.AdjacentCells(self.World, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateInnerPath(Actor self)
|
|
||||||
{
|
{
|
||||||
var targetCells = CandidateMovementCells(self);
|
var targetCells = CandidateMovementCells(self);
|
||||||
var searchCells = new List<CPos>();
|
var searchCells = new List<CPos>();
|
||||||
@@ -113,14 +116,12 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
searchCells.Add(cell);
|
searchCells.Add(cell);
|
||||||
|
|
||||||
if (!searchCells.Any())
|
if (!searchCells.Any())
|
||||||
return;
|
return NoPath;
|
||||||
|
|
||||||
var path = pathFinder.FindBidiPath(
|
var fromSrc = PathSearch.FromPoints(self.World, mobile.Info, self, searchCells, loc, true);
|
||||||
PathSearch.FromPoints(self.World, mobile.Info, self, searchCells, loc, true),
|
var fromDest = PathSearch.FromPoint(self.World, mobile.Info, self, loc, targetPosition, true).Reverse();
|
||||||
PathSearch.FromPoint(self.World, mobile.Info, self, loc, targetPosition, true).Reverse()
|
|
||||||
);
|
|
||||||
|
|
||||||
inner = mobile.MoveTo(() => path);
|
return pathFinder.FindBidiPath(fromSrc, fromDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
|
|||||||
Reference in New Issue
Block a user