Merge pull request #13159 from pchote/return-to-ground
Force Mobile units to return to the ground layer when becoming idle.
This commit is contained in:
@@ -16,6 +16,7 @@ using System.Linq;
|
|||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Effects;
|
using OpenRA.Mods.Common.Effects;
|
||||||
|
using OpenRA.Mods.Common.Pathfinder;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -381,7 +382,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Mobile : ConditionalTrait<MobileInfo>, INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove,
|
public class Mobile : ConditionalTrait<MobileInfo>, INotifyCreated, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove,
|
||||||
IFacing, IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier
|
IFacing, IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier, INotifyBecomingIdle
|
||||||
{
|
{
|
||||||
const int AverageTicksBeforePathing = 5;
|
const int AverageTicksBeforePathing = 5;
|
||||||
const int SpreadTicksBeforePathing = 5;
|
const int SpreadTicksBeforePathing = 5;
|
||||||
@@ -987,5 +988,34 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (CanEnterCell(self.Location, self, false))
|
if (CanEnterCell(self.Location, self, false))
|
||||||
init.Add(new HuskSpeedInit(MovementSpeedForCell(self, self.Location)));
|
init.Add(new HuskSpeedInit(MovementSpeedForCell(self, self.Location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPos? ClosestGroundCell()
|
||||||
|
{
|
||||||
|
var above = new CPos(TopLeft.X, TopLeft.Y);
|
||||||
|
if (CanEnterCell(above))
|
||||||
|
return above;
|
||||||
|
|
||||||
|
var pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||||
|
List<CPos> path;
|
||||||
|
using (var search = PathSearch.Search(self.World, Info, self, true,
|
||||||
|
loc => loc.Layer == 0 && CanEnterCell(loc))
|
||||||
|
.FromPoint(self.Location))
|
||||||
|
path = pathFinder.FindPath(search);
|
||||||
|
|
||||||
|
if (path.Count > 0)
|
||||||
|
return path[0];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyBecomingIdle.OnBecomingIdle(Actor self)
|
||||||
|
{
|
||||||
|
if (TopLeft.Layer == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var moveTo = ClosestGroundCell();
|
||||||
|
if (moveTo != null)
|
||||||
|
self.QueueActivity(MoveTo(moveTo.Value, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user