Simplify MoveAdjacentTo pathfinding.
This commit is contained in:
@@ -33,9 +33,12 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
|
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
pathFinder = self.World.WorldActor.Trait<PathFinder>();
|
pathFinder = self.World.WorldActor.Trait<PathFinder>();
|
||||||
domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
|
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||||
movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet);
|
movementClass = (uint)mobile.Info.GetMovementClass(self.World.TileSet);
|
||||||
|
|
||||||
|
if (target.IsValidFor(self))
|
||||||
|
targetPosition = target.CenterPosition.ToCPos();
|
||||||
|
|
||||||
repath = true;
|
repath = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,27 +111,18 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
var loc = self.Location;
|
var loc = self.Location;
|
||||||
|
|
||||||
foreach (var cell in targetCells)
|
foreach (var cell in targetCells)
|
||||||
if (mobile.CanEnterCell(cell) && (domainIndex == null || domainIndex.IsPassable(loc, cell, movementClass)))
|
if (domainIndex.IsPassable(loc, cell, movementClass) && mobile.CanEnterCell(cell))
|
||||||
searchCells.Add(cell);
|
searchCells.Add(cell);
|
||||||
|
|
||||||
if (searchCells.Any())
|
if (!searchCells.Any())
|
||||||
{
|
return;
|
||||||
var ps1 = new PathSearch(self.World, mobile.Info, self)
|
|
||||||
{
|
|
||||||
checkForBlocked = true,
|
|
||||||
heuristic = location => 0,
|
|
||||||
inReverse = true
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var cell in searchCells)
|
var path = pathFinder.FindBidiPath(
|
||||||
ps1.AddInitialCell(cell);
|
PathSearch.FromPoints(self.World, mobile.Info, self, searchCells, loc, true),
|
||||||
|
PathSearch.FromPoint(self.World, mobile.Info, self, loc, targetPosition, true).InReverse()
|
||||||
|
);
|
||||||
|
|
||||||
ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);
|
inner = mobile.MoveTo(() => path);
|
||||||
var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, targetPosition, true);
|
|
||||||
var ret = pathFinder.FindBidiPath(ps1, ps2);
|
|
||||||
|
|
||||||
inner = mobile.MoveTo(() => ret);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
|
|||||||
Reference in New Issue
Block a user