Streamline Land activity
Removed some redundant parameters, some redundant overloads and made Land always consider LandAltitude relative to target.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user