Streamline Land activity

Removed some redundant parameters, some redundant overloads
and made Land always consider LandAltitude relative to target.
This commit is contained in:
reaperrr
2019-04-26 01:30:49 +02:00
committed by Paul Chote
parent 14bd5ada1a
commit 0c2666b97e
11 changed files with 47 additions and 70 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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)