Fix units stuck on transit-only when resupplying

This commit is contained in:
Adam Mitchell
2020-04-11 17:59:30 +01:00
committed by reaperrr
parent 942dd0e5f7
commit 0a9eb1ff83
5 changed files with 23 additions and 5 deletions

View File

@@ -347,10 +347,15 @@ namespace OpenRA.Mods.Common.Activities
}
public override void Cancel(Actor self, bool keepQueue = false)
{
Cancel(self, keepQueue, false);
}
public void Cancel(Actor self, bool keepQueue, bool forceClearPath)
{
// We need to clear the path here in order to prevent MovePart queueing new instances of itself
// when the unit is making a turn.
if (path != null && mobile.CanStayInCell(mobile.ToCell))
if (path != null && (forceClearPath || mobile.CanStayInCell(mobile.ToCell)))
path.Clear();
base.Cancel(self, keepQueue);

View File

@@ -78,7 +78,8 @@ namespace OpenRA.Mods.Common.Activities
protected virtual IEnumerable<CPos> CandidateMovementCells(Actor self)
{
return Util.AdjacentCells(self.World, Target);
return Util.AdjacentCells(self.World, Target)
.Where(c => Mobile.CanStayInCell(c));
}
protected override void OnFirstRun(Actor self)

View File

@@ -33,13 +33,13 @@ namespace OpenRA.Mods.Common.Activities
{
// We are now in range. Don't move any further!
// HACK: This works around the pathfinder not returning the shortest path
return AtCorrectRange(self.CenterPosition) && Mobile.CanInteractWithGroundLayer(self);
return AtCorrectRange(self.CenterPosition) && Mobile.CanInteractWithGroundLayer(self) && Mobile.CanStayInCell(self.Location);
}
protected override bool ShouldRepath(Actor self, CPos targetLocation)
{
return lastVisibleTargetLocation != targetLocation && (!AtCorrectRange(self.CenterPosition)
|| !Mobile.CanInteractWithGroundLayer(self));
|| !Mobile.CanInteractWithGroundLayer(self) || !Mobile.CanStayInCell(self.Location));
}
protected override IEnumerable<CPos> CandidateMovementCells(Actor self)
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Activities
var minCells = minRange.Length / 1024;
return map.FindTilesInAnnulus(lastVisibleTargetLocation, minCells, maxCells)
.Where(c => AtCorrectRange(map.CenterOfSubCell(c, Mobile.FromSubCell)));
.Where(c => Mobile.CanStayInCell(c) && AtCorrectRange(map.CenterOfSubCell(c, Mobile.FromSubCell)));
}
bool AtCorrectRange(WPos origin)

View File

@@ -171,6 +171,12 @@ namespace OpenRA.Mods.Common.Activities
public override void Cancel(Actor self, bool keepQueue = false)
{
// HACK: force move activities to ignore the transit-only cells when cancelling
// The idle handler will take over and move them into a safe cell
if (ChildActivity != null)
foreach (var c in ChildActivity.ActivitiesImplementing<Move>())
c.Cancel(self, false, true);
foreach (var t in transportCallers)
t.MovementCancelled(self);