Define nearenough parameter for aircraft so they can exit movement early when stuck.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -23,9 +24,18 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly WDist maxRange;
|
readonly WDist maxRange;
|
||||||
readonly WDist minRange;
|
readonly WDist minRange;
|
||||||
readonly Color? targetLineColor;
|
readonly Color? targetLineColor;
|
||||||
|
readonly WDist nearEnough;
|
||||||
|
|
||||||
Target target;
|
Target target;
|
||||||
Target lastVisibleTarget;
|
Target lastVisibleTarget;
|
||||||
bool useLastVisibleTarget;
|
bool useLastVisibleTarget;
|
||||||
|
readonly List<WPos> positionBuffer = new List<WPos>();
|
||||||
|
|
||||||
|
public Fly(Actor self, Target t, WDist nearEnough, WPos? initialTargetPosition = null, Color? targetLineColor = null)
|
||||||
|
: this(self, t, initialTargetPosition, targetLineColor)
|
||||||
|
{
|
||||||
|
this.nearEnough = nearEnough;
|
||||||
|
}
|
||||||
|
|
||||||
public Fly(Actor self, Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null)
|
public Fly(Actor self, Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null)
|
||||||
{
|
{
|
||||||
@@ -166,6 +176,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: Consider ourselves blocked if we have moved by less than 64 WDist in the last five ticks
|
||||||
|
// Stop if we are blocked and close enough
|
||||||
|
if (positionBuffer.Count >= 5 && (positionBuffer.Last() - positionBuffer[0]).LengthSquared < 4096 &&
|
||||||
|
delta.HorizontalLengthSquared <= nearEnough.LengthSquared)
|
||||||
|
return true;
|
||||||
|
|
||||||
// The next move would overshoot, so consider it close enough or set final position if we CanSlide
|
// The next move would overshoot, so consider it close enough or set final position if we CanSlide
|
||||||
if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared)
|
if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared)
|
||||||
{
|
{
|
||||||
@@ -213,6 +229,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
desiredFacing = aircraft.Facing;
|
desiredFacing = aircraft.Facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
positionBuffer.Add(self.CenterPosition);
|
||||||
|
if (positionBuffer.Count > 5)
|
||||||
|
positionBuffer.RemoveAt(0);
|
||||||
|
|
||||||
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
|
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public Actor ReservedActor { get; private set; }
|
public Actor ReservedActor { get; private set; }
|
||||||
public bool MayYieldReservation { get; private set; }
|
public bool MayYieldReservation { get; private set; }
|
||||||
public bool ForceLanding { get; private set; }
|
public bool ForceLanding { get; private set; }
|
||||||
|
|
||||||
IEnumerable<CPos> landingCells = Enumerable.Empty<CPos>();
|
IEnumerable<CPos> landingCells = Enumerable.Empty<CPos>();
|
||||||
bool requireForceMove;
|
bool requireForceMove;
|
||||||
int moveIntoWorldDelay;
|
int moveIntoWorldDelay;
|
||||||
@@ -829,7 +830,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public Activity MoveTo(CPos cell, int nearEnough, Color? targetLineColor = null)
|
public Activity MoveTo(CPos cell, int nearEnough, Color? targetLineColor = null)
|
||||||
{
|
{
|
||||||
return new Fly(self, Target.FromCell(self.World, cell), targetLineColor: targetLineColor);
|
return new Fly(self, Target.FromCell(self.World, cell), WDist.FromCells(nearEnough), targetLineColor: targetLineColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Activity MoveTo(CPos cell, Actor ignoreActor, Color? targetLineColor = null)
|
public Activity MoveTo(CPos cell, Actor ignoreActor, Color? targetLineColor = null)
|
||||||
@@ -1028,7 +1029,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
UnReserve();
|
UnReserve();
|
||||||
|
|
||||||
var target = Target.FromCell(self.World, cell);
|
var target = Target.FromCell(self.World, cell);
|
||||||
self.QueueActivity(order.Queued, new Fly(self, target, targetLineColor: Color.Green));
|
|
||||||
|
// TODO: this should scale with unit selection group size.
|
||||||
|
self.QueueActivity(order.Queued, new Fly(self, target, WDist.FromCells(8), targetLineColor: Color.Green));
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
else if (orderString == "Land")
|
else if (orderString == "Land")
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var targetLocation = move.NearestMoveableCell(cell);
|
var targetLocation = move.NearestMoveableCell(cell);
|
||||||
var assaultMoving = order.OrderString == "AssaultMove";
|
var assaultMoving = order.OrderString == "AssaultMove";
|
||||||
self.QueueActivity(new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 1, targetLineColor: Color.OrangeRed), assaultMoving));
|
|
||||||
|
// TODO: this should scale with unit selection group size.
|
||||||
|
self.QueueActivity(new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 8, targetLineColor: Color.OrangeRed), assaultMoving));
|
||||||
self.ShowTargetLines();
|
self.ShowTargetLines();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user