Improve Carryall behaviour and integration with Aircraft.
This commit is contained in:
@@ -157,12 +157,13 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return NextActivity;
|
||||
|
||||
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
|
||||
var delta = checkTarget.CenterPosition - self.CenterPosition;
|
||||
var pos = aircraft.GetPosition();
|
||||
var delta = checkTarget.CenterPosition - pos;
|
||||
var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing;
|
||||
|
||||
// Inside the target annulus, so we're done
|
||||
var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, maxRange);
|
||||
var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, minRange);
|
||||
var insideMaxRange = maxRange.Length > 0 && checkTarget.IsInRange(pos, maxRange);
|
||||
var insideMinRange = minRange.Length > 0 && checkTarget.IsInRange(pos, minRange);
|
||||
if (insideMaxRange && !insideMinRange)
|
||||
return NextActivity;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
var pos = aircraft.CenterPosition;
|
||||
var pos = aircraft.GetPosition();
|
||||
|
||||
// Reevaluate target position in case the target has moved.
|
||||
targetPosition = target.CenterPosition + offset;
|
||||
|
||||
@@ -17,48 +17,37 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class DeliverUnit : Activity
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly Carryall carryall;
|
||||
readonly BodyOrientation body;
|
||||
readonly bool assignTargetOnFirstRun;
|
||||
readonly WDist deliverRange;
|
||||
|
||||
Target destination;
|
||||
|
||||
public DeliverUnit(Actor self, CPos destination)
|
||||
: this(self, Target.FromCell(self.World, destination)) { }
|
||||
|
||||
public DeliverUnit(Actor self)
|
||||
: this(self, Target.Invalid) { }
|
||||
|
||||
DeliverUnit(Actor self, Target destination)
|
||||
public DeliverUnit(Actor self, WDist deliverRange)
|
||||
: this(self, Target.Invalid, deliverRange)
|
||||
{
|
||||
assignTargetOnFirstRun = true;
|
||||
}
|
||||
|
||||
public DeliverUnit(Actor self, Target destination, WDist deliverRange)
|
||||
{
|
||||
this.self = self;
|
||||
this.destination = destination;
|
||||
this.deliverRange = deliverRange;
|
||||
|
||||
carryall = self.Trait<Carryall>();
|
||||
body = self.Trait<BodyOrientation>();
|
||||
}
|
||||
|
||||
Target FindDropLocation(Target requested, WDist maxSearchDistance)
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
var positionable = carryall.Carryable.Trait<IPositionable>();
|
||||
var centerPosition = requested.CenterPosition;
|
||||
var targetCell = self.World.Map.CellContaining(centerPosition);
|
||||
if (assignTargetOnFirstRun)
|
||||
destination = Target.FromCell(self.World, self.Location);
|
||||
|
||||
// The easy case
|
||||
if (positionable.CanEnterCell(targetCell, self))
|
||||
return requested;
|
||||
|
||||
var cellRange = (maxSearchDistance.Length + 1023) / 1024;
|
||||
foreach (var c in self.World.Map.FindTilesInCircle(targetCell, cellRange))
|
||||
{
|
||||
if (!positionable.CanEnterCell(c, self))
|
||||
continue;
|
||||
|
||||
var delta = self.World.Map.CenterOfCell(c) - centerPosition;
|
||||
if (delta.LengthSquared < maxSearchDistance.LengthSquared)
|
||||
return Target.FromCell(self.World, c);
|
||||
}
|
||||
|
||||
return Target.Invalid;
|
||||
QueueChild(self, new Land(self, destination, deliverRange), true);
|
||||
QueueChild(self, new Wait(carryall.Info.UnloadingDelay, false), true);
|
||||
QueueChild(self, new ReleaseUnit(self));
|
||||
QueueChild(self, new TakeOff(self));
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -70,55 +59,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
if (IsCanceling || carryall.State != Carryall.CarryallState.Carrying || carryall.Carryable.IsDead)
|
||||
return NextActivity;
|
||||
|
||||
// Drop the actor at the current position
|
||||
if (destination.Type == TargetType.Invalid)
|
||||
destination = Target.FromCell(self.World, self.Location);
|
||||
|
||||
var target = FindDropLocation(destination, carryall.Info.DropRange);
|
||||
|
||||
// Can't land, so wait at the target until something changes
|
||||
if (target.Type == TargetType.Invalid)
|
||||
{
|
||||
QueueChild(self, new Fly(self, destination), true);
|
||||
QueueChild(self, new Wait(25));
|
||||
return this;
|
||||
}
|
||||
|
||||
// Move to drop-off location
|
||||
var localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self, self.Orientation));
|
||||
var carryablePosition = self.CenterPosition + body.LocalToWorld(localOffset);
|
||||
if ((carryablePosition - target.CenterPosition).HorizontalLengthSquared != 0)
|
||||
{
|
||||
// For non-zero offsets the drop position depends on the carryall facing
|
||||
// We therefore need to predict/correct for the facing *at the drop point*
|
||||
if (carryall.CarryableOffset.HorizontalLengthSquared != 0)
|
||||
{
|
||||
var dropFacing = (target.CenterPosition - self.CenterPosition).Yaw.Facing;
|
||||
localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(dropFacing)));
|
||||
QueueChild(self, new Fly(self, Target.FromPos(target.CenterPosition - body.LocalToWorld(localOffset))), true);
|
||||
QueueChild(self, new Turn(self, dropFacing));
|
||||
return this;
|
||||
}
|
||||
|
||||
QueueChild(self, new Fly(self, target), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Make sure that the carried actor is on the ground before releasing it
|
||||
if (self.World.Map.DistanceAboveTerrain(carryablePosition) != WDist.Zero)
|
||||
QueueChild(self, new Land(self), true);
|
||||
|
||||
// Pause briefly before releasing for visual effect
|
||||
if (carryall.Info.UnloadingDelay > 0)
|
||||
QueueChild(self, new Wait(carryall.Info.UnloadingDelay, false), true);
|
||||
|
||||
// Release carried actor
|
||||
QueueChild(self, new ReleaseUnit(self));
|
||||
QueueChild(self, new Fly(self, Target.FromPos(self.CenterPosition)));
|
||||
return this;
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
class ReleaseUnit : Activity
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
readonly int delay;
|
||||
|
||||
enum PickupState { Intercept, LockCarryable, MoveToCarryable, Turn, Land, Wait, Pickup }
|
||||
enum PickupState { Intercept, LockCarryable, Pickup }
|
||||
|
||||
PickupState state;
|
||||
|
||||
@@ -86,63 +86,23 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (!carryable.LockForPickup(cargo, self))
|
||||
Cancel(self);
|
||||
|
||||
state = PickupState.MoveToCarryable;
|
||||
return this;
|
||||
|
||||
case PickupState.MoveToCarryable:
|
||||
{
|
||||
// Line up with the attachment point
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
|
||||
if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0)
|
||||
{
|
||||
QueueChild(self, new Fly(self, Target.FromPos(targetPosition)), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
state = PickupState.Turn;
|
||||
return this;
|
||||
}
|
||||
|
||||
case PickupState.Turn:
|
||||
if (carryallFacing.Facing != carryableFacing.Facing)
|
||||
{
|
||||
QueueChild(self, new Turn(self, carryableFacing.Facing), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
state = PickupState.Land;
|
||||
return this;
|
||||
|
||||
case PickupState.Land:
|
||||
{
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
|
||||
if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing)
|
||||
{
|
||||
state = PickupState.MoveToCarryable;
|
||||
return this;
|
||||
}
|
||||
|
||||
if (targetPosition.Z != self.CenterPosition.Z)
|
||||
{
|
||||
QueueChild(self, new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset)));
|
||||
return this;
|
||||
}
|
||||
|
||||
state = delay > 0 ? PickupState.Wait : PickupState.Pickup;
|
||||
return this;
|
||||
}
|
||||
|
||||
case PickupState.Wait:
|
||||
QueueChild(self, new Wait(delay, false), true);
|
||||
state = PickupState.Pickup;
|
||||
return this;
|
||||
|
||||
case PickupState.Pickup:
|
||||
{
|
||||
// Land at the target location
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
QueueChild(self, new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));
|
||||
|
||||
// Pause briefly before attachment for visual effect
|
||||
if (delay > 0)
|
||||
QueueChild(self, new Wait(delay, false), true);
|
||||
|
||||
// Remove our carryable from world
|
||||
Attach(self);
|
||||
QueueChild(self, new CallFunc(() => Attach(self)));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
return NextActivity;
|
||||
|
||||
Reference in New Issue
Block a user