Fix Service Depot Rally point path finding (+rename ignoredActor)

This commit is contained in:
rob-v
2017-04-09 19:14:25 +02:00
parent 669cf01d80
commit fb1d8d780f
8 changed files with 19 additions and 37 deletions

View File

@@ -285,7 +285,7 @@ namespace OpenRA.Traits
public interface IMove public interface IMove
{ {
Activity MoveTo(CPos cell, int nearEnough); Activity MoveTo(CPos cell, int nearEnough);
Activity MoveTo(CPos cell, Actor ignoredActor); Activity MoveTo(CPos cell, Actor ignoreActor);
Activity MoveWithinRange(Target target, WDist range); Activity MoveWithinRange(Target target, WDist range);
Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange); Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange);
Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange); Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange);

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Mobile mobile; readonly Mobile mobile;
readonly WDist nearEnough; readonly WDist nearEnough;
readonly Func<List<CPos>> getPath; readonly Func<List<CPos>> getPath;
readonly Actor ignoredActor; readonly Actor ignoreActor;
List<CPos> path; List<CPos> path;
CPos? destination; CPos? destination;
@@ -57,14 +57,15 @@ namespace OpenRA.Mods.Common.Activities
nearEnough = WDist.Zero; nearEnough = WDist.Zero;
} }
public Move(Actor self, CPos destination, WDist nearEnough) public Move(Actor self, CPos destination, WDist nearEnough, Actor ignoreActor = null)
{ {
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
getPath = () => self.World.WorldActor.Trait<IPathFinder>() getPath = () => self.World.WorldActor.Trait<IPathFinder>()
.FindUnitPath(mobile.ToCell, destination, self); .FindUnitPath(mobile.ToCell, destination, self, ignoreActor);
this.destination = destination; this.destination = destination;
this.nearEnough = nearEnough; this.nearEnough = nearEnough;
this.ignoreActor = ignoreActor;
} }
public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough) public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough)
@@ -77,25 +78,6 @@ namespace OpenRA.Mods.Common.Activities
this.nearEnough = nearEnough; this.nearEnough = nearEnough;
} }
public Move(Actor self, CPos destination, Actor ignoredActor)
{
mobile = self.Trait<Mobile>();
getPath = () =>
{
List<CPos> path;
using (var search =
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.ToCell, destination, false)
.WithIgnoredActor(ignoredActor))
path = self.World.WorldActor.Trait<IPathFinder>().FindPath(search);
return path;
};
this.destination = destination;
nearEnough = WDist.Zero;
this.ignoredActor = ignoredActor;
}
public Move(Actor self, Target target, WDist range) public Move(Actor self, Target target, WDist range)
{ {
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
@@ -227,7 +209,7 @@ namespace OpenRA.Mods.Common.Activities
var containsTemporaryBlocker = WorldUtils.ContainsTemporaryBlocker(self.World, nextCell, self); var containsTemporaryBlocker = WorldUtils.ContainsTemporaryBlocker(self.World, nextCell, self);
// Next cell in the move is blocked by another actor // Next cell in the move is blocked by another actor
if (containsTemporaryBlocker || !mobile.CanEnterCell(nextCell, ignoredActor, true)) if (containsTemporaryBlocker || !mobile.CanEnterCell(nextCell, ignoreActor, true))
{ {
// Are we close enough? // Are we close enough?
var cellRange = nearEnough.Length / 1024; var cellRange = nearEnough.Length / 1024;
@@ -275,7 +257,7 @@ namespace OpenRA.Mods.Common.Activities
hasWaited = false; hasWaited = false;
path.RemoveAt(path.Count - 1); path.RemoveAt(path.Count - 1);
var subCell = mobile.GetAvailableSubCell(nextCell, SubCell.Any, ignoredActor); var subCell = mobile.GetAvailableSubCell(nextCell, SubCell.Any, ignoreActor);
return Pair.New(nextCell, subCell); return Pair.New(nextCell, subCell);
} }

View File

@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public IPathSearch WithIgnoredActor(Actor b) public IPathSearch WithIgnoredActor(Actor b)
{ {
Graph.IgnoredActor = b; Graph.IgnoreActor = b;
return this; return this;
} }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Pathfinder
this.cacheStorage = cacheStorage; this.cacheStorage = cacheStorage;
} }
public List<CPos> FindUnitPath(CPos source, CPos target, Actor self) public List<CPos> FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor)
{ {
using (new PerfSample("Pathfinder")) using (new PerfSample("Pathfinder"))
{ {
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Pathfinder
if (cachedPath != null) if (cachedPath != null)
return cachedPath; return cachedPath;
var pb = pathFinder.FindUnitPath(source, target, self); var pb = pathFinder.FindUnitPath(source, target, self, ignoreActor);
cacheStorage.Store(key, pb); cacheStorage.Store(key, pb);

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Pathfinder
bool InReverse { get; set; } bool InReverse { get; set; }
Actor IgnoredActor { get; set; } Actor IgnoreActor { get; set; }
World World { get; } World World { get; }
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Pathfinder
public Func<CPos, int> CustomCost { get; set; } public Func<CPos, int> CustomCost { get; set; }
public int LaneBias { get; set; } public int LaneBias { get; set; }
public bool InReverse { get; set; } public bool InReverse { get; set; }
public Actor IgnoredActor { get; set; } public Actor IgnoreActor { get; set; }
readonly CellConditions checkConditions; readonly CellConditions checkConditions;
readonly MobileInfo mobileInfo; readonly MobileInfo mobileInfo;
@@ -171,7 +171,7 @@ namespace OpenRA.Mods.Common.Pathfinder
int GetCostToNode(CPos destNode, CVec direction) int GetCostToNode(CPos destNode, CVec direction)
{ {
var movementCost = mobileInfo.MovementCostToEnterCell(worldMovementInfo, Actor, destNode, IgnoredActor, checkConditions); var movementCost = mobileInfo.MovementCostToEnterCell(worldMovementInfo, Actor, destNode, IgnoreActor, checkConditions);
if (movementCost != int.MaxValue && !(CustomBlock != null && CustomBlock(destNode))) if (movementCost != int.MaxValue && !(CustomBlock != null && CustomBlock(destNode)))
return CalculateCellCost(destNode, direction, movementCost); return CalculateCellCost(destNode, direction, movementCost);

View File

@@ -453,7 +453,7 @@ namespace OpenRA.Mods.Common.Traits
return new HeliFly(self, Target.FromCell(self.World, cell)); return new HeliFly(self, Target.FromCell(self.World, cell));
} }
public Activity MoveTo(CPos cell, Actor ignoredActor) public Activity MoveTo(CPos cell, Actor ignoreActor)
{ {
if (IsPlane) if (IsPlane)
return new FlyAndContinueWithCirclesWhenIdle(self, Target.FromCell(self.World, cell)); return new FlyAndContinueWithCirclesWhenIdle(self, Target.FromCell(self.World, cell));

View File

@@ -914,7 +914,7 @@ namespace OpenRA.Mods.Common.Traits
public Activity ScriptedMove(CPos cell) { return new Move(self, cell); } public Activity ScriptedMove(CPos cell) { return new Move(self, cell); }
public Activity MoveTo(CPos cell, int nearEnough) { return new Move(self, cell, WDist.FromCells(nearEnough)); } public Activity MoveTo(CPos cell, int nearEnough) { return new Move(self, cell, WDist.FromCells(nearEnough)); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(self, cell, ignoredActor); } public Activity MoveTo(CPos cell, Actor ignoreActor) { return new Move(self, cell, WDist.Zero, ignoreActor); }
public Activity MoveWithinRange(Target target, WDist range) { return new MoveWithinRange(self, target, WDist.Zero, range); } public Activity MoveWithinRange(Target target, WDist range) { return new MoveWithinRange(self, target, WDist.Zero, range); }
public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange) { return new MoveWithinRange(self, target, minRange, maxRange); } public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange) { return new MoveWithinRange(self, target, minRange, maxRange); }
public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange) { return new Follow(self, target, minRange, maxRange); } public Activity MoveFollow(Actor self, Target target, WDist minRange, WDist maxRange) { return new Follow(self, target, minRange, maxRange); }

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
/// Calculates a path for the actor from source to destination /// Calculates a path for the actor from source to destination
/// </summary> /// </summary>
/// <returns>A path from start to target</returns> /// <returns>A path from start to target</returns>
List<CPos> FindUnitPath(CPos source, CPos target, Actor self); List<CPos> FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor);
List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WDist range, Actor self); List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WDist range, Actor self);
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
this.world = world; this.world = world;
} }
public List<CPos> FindUnitPath(CPos source, CPos target, Actor self) public List<CPos> FindUnitPath(CPos source, CPos target, Actor self, Actor ignoreActor)
{ {
var mi = self.Info.TraitInfo<MobileInfo>(); var mi = self.Info.TraitInfo<MobileInfo>();
@@ -74,8 +74,8 @@ namespace OpenRA.Mods.Common.Traits
} }
List<CPos> pb; List<CPos> pb;
using (var fromSrc = PathSearch.FromPoint(world, mi, self, target, source, true)) using (var fromSrc = PathSearch.FromPoint(world, mi, self, target, source, true).WithIgnoredActor(ignoreActor))
using (var fromDest = PathSearch.FromPoint(world, mi, self, source, target, true).Reverse()) using (var fromDest = PathSearch.FromPoint(world, mi, self, source, target, true).WithIgnoredActor(ignoreActor).Reverse())
pb = FindBidiPath(fromSrc, fromDest); pb = FindBidiPath(fromSrc, fromDest);
CheckSanePath2(pb, source, target); CheckSanePath2(pb, source, target);