Streamline Land activity
Removed some redundant parameters, some redundant overloads and made Land always consider LandAltitude relative to target.
This commit is contained in:
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
});
|
||||
|
||||
actor.QueueActivity(new Fly(actor, Target.FromPos(self.CenterPosition + new WVec(landDistance, 0, 0))));
|
||||
actor.QueueActivity(new Land(actor, Target.FromActor(self), false));
|
||||
actor.QueueActivity(new Land(actor, Target.FromActor(self)));
|
||||
actor.QueueActivity(new CallFunc(() =>
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (info.TurnToLand)
|
||||
self.QueueActivity(new Turn(self, info.InitialFacing));
|
||||
self.QueueActivity(new Land(self, true));
|
||||
self.QueueActivity(new Land(self));
|
||||
activity = NextActivity;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,34 +19,23 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly Target target;
|
||||
readonly Aircraft aircraft;
|
||||
readonly bool requireSpace;
|
||||
readonly Actor ignoreActor;
|
||||
readonly WDist landAltitude;
|
||||
readonly bool ignoreTarget;
|
||||
readonly WVec offset;
|
||||
|
||||
bool landingInitiated;
|
||||
bool soundPlayed;
|
||||
|
||||
public Land(Actor self, Target t, bool requireSpace, WDist landAltitude, Actor ignoreActor = null)
|
||||
public Land(Actor self, Target t, WVec offset)
|
||||
{
|
||||
target = t;
|
||||
aircraft = self.Trait<Aircraft>();
|
||||
this.requireSpace = requireSpace;
|
||||
this.ignoreActor = ignoreActor;
|
||||
this.landAltitude = landAltitude != WDist.Zero ? landAltitude : aircraft.Info.LandAltitude;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Land(Actor self, Target t, bool requireSpace, Actor ignoreActor = null)
|
||||
: this(self, t, requireSpace, WDist.Zero, ignoreActor) { }
|
||||
public Land(Actor self, Target t)
|
||||
: this(self, t, WVec.Zero) { }
|
||||
|
||||
public Land(Actor self, bool requireSpace, WDist landAltitude, Actor ignoreActor = null)
|
||||
: this(self, Target.FromPos(self.CenterPosition), requireSpace, landAltitude, ignoreActor)
|
||||
{
|
||||
ignoreTarget = true;
|
||||
}
|
||||
|
||||
public Land(Actor self, bool requireSpace, Actor ignoreActor = null)
|
||||
: this(self, requireSpace, WDist.Zero, ignoreActor) { }
|
||||
public Land(Actor self)
|
||||
: this(self, Target.FromPos(Aircraft.GroundPosition(self)), WVec.Zero) { }
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
@@ -57,22 +46,16 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!ignoreTarget && !target.IsValidFor(self))
|
||||
{
|
||||
Cancel(self);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
if (IsCanceling)
|
||||
if (IsCanceling || target.Type == TargetType.Invalid)
|
||||
{
|
||||
aircraft.RemoveInfluence();
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
if (requireSpace && !landingInitiated)
|
||||
if (!landingInitiated)
|
||||
{
|
||||
var landingCell = !aircraft.Info.VTOL ? self.World.Map.CellContaining(target.CenterPosition) : self.Location;
|
||||
if (!aircraft.CanLand(landingCell, ignoreActor))
|
||||
var landingCell = !aircraft.Info.VTOL ? self.World.Map.CellContaining(target.CenterPosition + offset) : self.Location;
|
||||
if (!aircraft.CanLand(landingCell, target.Actor))
|
||||
{
|
||||
// Maintain holding pattern.
|
||||
if (!aircraft.Info.CanHover)
|
||||
@@ -88,41 +71,38 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
|
||||
var altitude = self.World.Map.DistanceAboveTerrain(self.CenterPosition);
|
||||
var landAltitude = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude;
|
||||
|
||||
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && altitude != landAltitude)
|
||||
{
|
||||
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition);
|
||||
soundPlayed = true;
|
||||
}
|
||||
|
||||
// For VTOLs we assume we've already arrived at the target location and just need to move downward
|
||||
if (aircraft.Info.VTOL)
|
||||
{
|
||||
var landAlt = !ignoreTarget ? self.World.Map.DistanceAboveTerrain(target.CenterPosition) : landAltitude;
|
||||
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && altitude != landAlt)
|
||||
PlayLandingSound(self);
|
||||
|
||||
if (HeliFly.AdjustAltitude(self, aircraft, landAlt))
|
||||
if (HeliFly.AdjustAltitude(self, aircraft, landAltitude))
|
||||
return this;
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && altitude != landAltitude)
|
||||
PlayLandingSound(self);
|
||||
|
||||
var d = target.CenterPosition - self.CenterPosition;
|
||||
var d = (target.CenterPosition + offset) - self.CenterPosition;
|
||||
|
||||
// The next move would overshoot, so just set the final position
|
||||
var move = aircraft.FlyStep(aircraft.Facing);
|
||||
if (d.HorizontalLengthSquared < move.HorizontalLengthSquared)
|
||||
{
|
||||
aircraft.SetPosition(self, target.CenterPosition);
|
||||
var landingAltVec = new WVec(WDist.Zero, WDist.Zero, aircraft.LandAltitude);
|
||||
aircraft.SetPosition(self, target.CenterPosition + offset + landingAltVec);
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
var landingAlt = self.World.Map.DistanceAboveTerrain(target.CenterPosition);
|
||||
var landingAlt = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude;
|
||||
Fly.FlyToward(self, aircraft, d.Yaw.Facing, landingAlt);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void PlayLandingSound(Actor self)
|
||||
{
|
||||
Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition);
|
||||
soundPlayed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (aircraft.Info.TurnToLand)
|
||||
Queue(self, new Turn(self, aircraft.Info.InitialFacing));
|
||||
|
||||
Queue(self, new Land(self, true));
|
||||
Queue(self, new Land(self));
|
||||
return NextActivity;
|
||||
}
|
||||
else
|
||||
@@ -225,16 +225,10 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
aircraft.MakeReservation(dest);
|
||||
|
||||
if (aircraft.Info.VTOL)
|
||||
{
|
||||
if (aircraft.Info.TurnToDock)
|
||||
QueueChild(self, new Turn(self, aircraft.Info.InitialFacing), true);
|
||||
|
||||
QueueChild(self, new Land(self, true, dest), true);
|
||||
}
|
||||
else
|
||||
QueueChild(self, new Land(self, Target.FromPos(dest.CenterPosition + offset), true, dest), true);
|
||||
if (aircraft.Info.VTOL && aircraft.Info.TurnToDock)
|
||||
QueueChild(self, new Turn(self, aircraft.Info.InitialFacing), true);
|
||||
|
||||
QueueChild(self, new Land(self, Target.FromActor(dest), offset), true);
|
||||
QueueChild(self, new Resupply(self, dest, WDist.Zero), true);
|
||||
resupplied = true;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
// 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), true);
|
||||
QueueChild(self, new Land(self), true);
|
||||
|
||||
// Pause briefly before releasing for visual effect
|
||||
if (carryall.Info.UnloadingDelay > 0)
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (targetPosition.Z != self.CenterPosition.Z)
|
||||
{
|
||||
QueueChild(self, new Land(self, false, self.World.Map.DistanceAboveTerrain(targetPosition)), true);
|
||||
QueueChild(self, new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset)));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
QueueChild(self, new Turn(self, Facing));
|
||||
|
||||
if (self.Info.HasTraitInfo<AircraftInfo>())
|
||||
QueueChild(self, new Land(self, true));
|
||||
QueueChild(self, new Land(self));
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
|
||||
@@ -183,11 +183,11 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
Move(transport, destination);
|
||||
|
||||
transport.QueueActivity(new Turn(transport, aircraft.Info.InitialFacing));
|
||||
transport.QueueActivity(new Land(transport, true));
|
||||
transport.QueueActivity(new Land(transport));
|
||||
}
|
||||
else
|
||||
{
|
||||
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, destination), true));
|
||||
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, destination)));
|
||||
}
|
||||
|
||||
transport.QueueActivity(new Wait(15));
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[Desc("Queues a landing activity on the specififed actor.")]
|
||||
public void Land(Actor landOn)
|
||||
{
|
||||
Self.QueueActivity(new Land(Self, Target.FromActor(landOn), true, landOn));
|
||||
Self.QueueActivity(new Land(Self, Target.FromActor(landOn)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
|
||||
@@ -195,6 +195,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public WDist LandAltitude { get; private set; }
|
||||
|
||||
public static WPos GroundPosition(Actor self)
|
||||
{
|
||||
return self.CenterPosition - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition));
|
||||
}
|
||||
|
||||
bool airborne;
|
||||
bool cruising;
|
||||
bool firstTick = true;
|
||||
@@ -321,7 +326,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Info.TurnToLand)
|
||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||
|
||||
self.QueueActivity(new Land(self, true));
|
||||
self.QueueActivity(new Land(self));
|
||||
|
||||
ForceLanding = true;
|
||||
}
|
||||
@@ -625,7 +630,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Info.TurnToLand)
|
||||
self.QueueActivity(new Turn(self, Info.InitialFacing));
|
||||
|
||||
self.QueueActivity(new Land(self, true));
|
||||
self.QueueActivity(new Land(self));
|
||||
}
|
||||
else if (!Info.CanHover && !atLandAltitude)
|
||||
self.QueueActivity(new FlyCircle(self, -1, Info.IdleTurnSpeed > -1 ? Info.IdleTurnSpeed : TurnSpeed));
|
||||
@@ -812,10 +817,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public Activity MoveIntoTarget(Actor self, Target target)
|
||||
{
|
||||
if (!Info.VTOL)
|
||||
return new Land(self, target, false);
|
||||
|
||||
return new Land(self, false);
|
||||
return new Land(self, target);
|
||||
}
|
||||
|
||||
public Activity VisualMove(Actor self, WPos fromPos, WPos toPos)
|
||||
|
||||
@@ -193,7 +193,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
Unloading = true;
|
||||
if (aircraft != null)
|
||||
self.QueueActivity(new Land(self, true));
|
||||
self.QueueActivity(new Land(self));
|
||||
|
||||
self.QueueActivity(new UnloadCargo(self, true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user