Units heading in generally opposite directions are now considered blockers; this fixes pathing deadlocks.
This commit is contained in:
@@ -77,7 +77,25 @@ namespace OpenRA.Mods.RA.Move
|
||||
{SubCell.FullCell, new PVecInt(0,0)},
|
||||
};
|
||||
|
||||
public bool CanEnterCell(World world, Player owner, CPos cell, Actor ignoreActor, bool checkTransientActors, bool blockedByMovers)
|
||||
static bool IsMovingInMyDirection(Actor self, Actor other)
|
||||
{
|
||||
if (!other.IsMoving()) return false;
|
||||
if (self == null) return true;
|
||||
|
||||
var selfMobile = self.TraitOrDefault<Mobile>();
|
||||
if (selfMobile == null) return false;
|
||||
|
||||
var otherMobile = other.TraitOrDefault<Mobile>();
|
||||
if (otherMobile == null) return false;
|
||||
|
||||
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
|
||||
var dp = CVec.Dot((selfMobile.toCell - self.Location), (otherMobile.toCell - other.Location));
|
||||
if (dp <= 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor, bool checkTransientActors, bool blockedByMovers)
|
||||
{
|
||||
if (MovementCostForCell(world, cell) == int.MaxValue)
|
||||
return false;
|
||||
@@ -88,7 +106,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var blockingActors = world.ActorMap.GetUnitsAt(cell)
|
||||
.Where(x => x != ignoreActor)
|
||||
// Neutral/enemy units are blockers. Allied units that are moving are not blockers.
|
||||
.Where(x => blockedByMovers || ((owner.Stances[x.Owner] != Stance.Ally) || !x.IsMoving()))
|
||||
.Where(x => blockedByMovers || ((self.Owner.Stances[x.Owner] != Stance.Ally) || !IsMovingInMyDirection(self, x)))
|
||||
.ToList();
|
||||
|
||||
if (checkTransientActors && blockingActors.Count > 0)
|
||||
@@ -98,7 +116,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
return false;
|
||||
|
||||
if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() &&
|
||||
a.TraitsImplementing<ICrushable>().Any(b => b.CrushableBy(Crushes, owner)))))
|
||||
a.TraitsImplementing<ICrushable>().Any(b => b.CrushableBy(Crushes, self.Owner)))))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -347,7 +365,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors, true);
|
||||
return Info.CanEnterCell(self.World, self, cell, ignoreActor, checkTransientActors, true);
|
||||
}
|
||||
|
||||
public void EnteringCell(Actor self)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
this.getPath = (self,mobile) =>
|
||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||
PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, destination, false )
|
||||
PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, destination, false )
|
||||
.WithoutLaneBias());
|
||||
this.destination = destination;
|
||||
this.nearEnough = 0;
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
this.getPath = (self,mobile) =>
|
||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||
PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, destination, false )
|
||||
PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, destination, false )
|
||||
.WithIgnoredBuilding( ignoreBuilding ));
|
||||
|
||||
this.destination = destination;
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
|
||||
var pb = FindBidiPath(
|
||||
PathSearch.FromPoint(world, mi, self.Owner, target, from, true),
|
||||
PathSearch.FromPoint(world, mi, self.Owner, from, target, true).InReverse()
|
||||
PathSearch.FromPoint(world, mi, self, target, from, true),
|
||||
PathSearch.FromPoint(world, mi, self, from, target, true).InReverse()
|
||||
);
|
||||
|
||||
CheckSanePath2(pb, from, target);
|
||||
@@ -73,11 +73,11 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
var tilesInRange = world.FindTilesInCircle(target, range)
|
||||
.Where(t => mi.CanEnterCell(self.World, self.Owner, t, null, true, true));
|
||||
.Where(t => mi.CanEnterCell(self.World, self, t, null, true, true));
|
||||
|
||||
var path = FindBidiPath(
|
||||
PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true),
|
||||
PathSearch.FromPoint(world, mi, self.Owner, src, target, true).InReverse()
|
||||
PathSearch.FromPoints(world, mi, self, tilesInRange, src, true),
|
||||
PathSearch.FromPoint(world, mi, self, src, target, true).InReverse()
|
||||
);
|
||||
|
||||
return path;
|
||||
|
||||
@@ -28,14 +28,15 @@ namespace OpenRA.Mods.RA.Move
|
||||
public bool inReverse;
|
||||
|
||||
MobileInfo mobileInfo;
|
||||
Player owner;
|
||||
Actor self;
|
||||
public Player owner { get { return self.Owner; } }
|
||||
|
||||
public PathSearch(World world, MobileInfo mobileInfo, Player owner)
|
||||
public PathSearch(World world, MobileInfo mobileInfo, Actor self)
|
||||
{
|
||||
this.world = world;
|
||||
cellInfo = InitCellInfo();
|
||||
this.mobileInfo = mobileInfo;
|
||||
this.owner = owner;
|
||||
this.self = self;
|
||||
customCost = null;
|
||||
queue = new PriorityQueue<PathDistance>();
|
||||
}
|
||||
@@ -120,7 +121,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
if (costHere == int.MaxValue)
|
||||
continue;
|
||||
|
||||
if (!mobileInfo.CanEnterCell(world, owner, newHere, ignoreBuilding, checkForBlocked, false))
|
||||
if (!mobileInfo.CanEnterCell(world, self, newHere, ignoreBuilding, checkForBlocked, false))
|
||||
continue;
|
||||
|
||||
if (customBlock != null && customBlock(newHere))
|
||||
@@ -182,18 +183,18 @@ namespace OpenRA.Mods.RA.Move
|
||||
queue.Add(new PathDistance(heuristic(location), location));
|
||||
}
|
||||
|
||||
public static PathSearch Search(World world, MobileInfo mi, Player owner, bool checkForBlocked)
|
||||
public static PathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked)
|
||||
{
|
||||
var search = new PathSearch(world, mi, owner)
|
||||
var search = new PathSearch(world, mi, self)
|
||||
{
|
||||
checkForBlocked = checkForBlocked
|
||||
};
|
||||
return search;
|
||||
}
|
||||
|
||||
public static PathSearch FromPoint(World world, MobileInfo mi, Player owner, CPos from, CPos target, bool checkForBlocked)
|
||||
public static PathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
|
||||
{
|
||||
var search = new PathSearch(world, mi, owner)
|
||||
var search = new PathSearch(world, mi, self)
|
||||
{
|
||||
heuristic = DefaultEstimator(target),
|
||||
checkForBlocked = checkForBlocked
|
||||
@@ -203,9 +204,9 @@ namespace OpenRA.Mods.RA.Move
|
||||
return search;
|
||||
}
|
||||
|
||||
public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
|
||||
public static PathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
|
||||
{
|
||||
var search = new PathSearch(world, mi, owner)
|
||||
var search = new PathSearch(world, mi, self)
|
||||
{
|
||||
heuristic = DefaultEstimator(target),
|
||||
checkForBlocked = checkForBlocked
|
||||
|
||||
Reference in New Issue
Block a user