diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index b44d3f37a6..e376014eeb 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -18,14 +18,14 @@ namespace OpenRA.Mods.Common.Activities { public class Fly : Activity { - readonly Aircraft plane; + readonly Aircraft aircraft; readonly Target target; readonly WDist maxRange; readonly WDist minRange; public Fly(Actor self, Target t) { - plane = self.Trait(); + aircraft = self.Trait(); target = t; } @@ -36,29 +36,29 @@ namespace OpenRA.Mods.Common.Activities this.minRange = minRange; } - public static void FlyToward(Actor self, Aircraft plane, int desiredFacing, WDist desiredAltitude) + public static void FlyToward(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude) { - desiredAltitude = new WDist(plane.CenterPosition.Z) + desiredAltitude - self.World.Map.DistanceAboveTerrain(plane.CenterPosition); + desiredAltitude = new WDist(aircraft.CenterPosition.Z) + desiredAltitude - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); - var move = plane.FlyStep(plane.Facing); - var altitude = plane.CenterPosition.Z; + var move = aircraft.FlyStep(aircraft.Facing); + var altitude = aircraft.CenterPosition.Z; - plane.Facing = Util.TickFacing(plane.Facing, desiredFacing, plane.TurnSpeed); + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); if (altitude != desiredAltitude.Length) { - var delta = move.HorizontalLength * plane.Info.MaximumPitch.Tan() / 1024; + var delta = move.HorizontalLength * aircraft.Info.MaximumPitch.Tan() / 1024; var dz = (desiredAltitude.Length - altitude).Clamp(-delta, delta); move += new WVec(0, 0, dz); } - plane.SetPosition(self, plane.CenterPosition + move); + aircraft.SetPosition(self, aircraft.CenterPosition + move); } public override Activity Tick(Actor self) { // Refuse to take off if it would land immediately again. - if (plane.ForceLanding) + if (aircraft.ForceLanding) { Cancel(self); return NextActivity; @@ -68,25 +68,25 @@ namespace OpenRA.Mods.Common.Activities return NextActivity; // Inside the target annulus, so we're done - var insideMaxRange = maxRange.Length > 0 && target.IsInRange(plane.CenterPosition, maxRange); - var insideMinRange = minRange.Length > 0 && target.IsInRange(plane.CenterPosition, minRange); + var insideMaxRange = maxRange.Length > 0 && target.IsInRange(aircraft.CenterPosition, maxRange); + var insideMinRange = minRange.Length > 0 && target.IsInRange(aircraft.CenterPosition, minRange); if (insideMaxRange && !insideMinRange) return NextActivity; var d = target.CenterPosition - self.CenterPosition; // The next move would overshoot, so consider it close enough - var move = plane.FlyStep(plane.Facing); + var move = aircraft.FlyStep(aircraft.Facing); if (d.HorizontalLengthSquared < move.HorizontalLengthSquared) return NextActivity; // Don't turn until we've reached the cruise altitude var desiredFacing = d.Yaw.Facing; - var targetAltitude = plane.CenterPosition.Z + plane.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(plane.CenterPosition).Length; - if (plane.CenterPosition.Z < targetAltitude) - desiredFacing = plane.Facing; + var targetAltitude = aircraft.CenterPosition.Z + aircraft.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length; + if (aircraft.CenterPosition.Z < targetAltitude) + desiredFacing = aircraft.Facing; - FlyToward(self, plane, desiredFacing, plane.Info.CruiseAltitude); + FlyToward(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs index ccde3edf48..60fdebd80b 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Activities { public class HeliFly : Activity { - readonly Aircraft helicopter; + readonly Aircraft aircraft; readonly Target target; readonly WDist maxRange; readonly WDist minRange; @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities public HeliFly(Actor self, Target t) { - helicopter = self.Trait(); + aircraft = self.Trait(); target = t; } @@ -37,17 +37,17 @@ namespace OpenRA.Mods.Common.Activities this.minRange = minRange; } - public static bool AdjustAltitude(Actor self, Aircraft helicopter, WDist targetAltitude) + public static bool AdjustAltitude(Actor self, Aircraft aircraft, WDist targetAltitude) { - targetAltitude = new WDist(helicopter.CenterPosition.Z) + targetAltitude - self.World.Map.DistanceAboveTerrain(helicopter.CenterPosition); + targetAltitude = new WDist(aircraft.CenterPosition.Z) + targetAltitude - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); - var altitude = helicopter.CenterPosition.Z; + var altitude = aircraft.CenterPosition.Z; if (altitude == targetAltitude.Length) return false; - var delta = helicopter.Info.AltitudeVelocity.Length; + var delta = aircraft.Info.AltitudeVelocity.Length; var dz = (targetAltitude.Length - altitude).Clamp(-delta, delta); - helicopter.SetPosition(self, helicopter.CenterPosition + new WVec(0, 0, dz)); + aircraft.SetPosition(self, aircraft.CenterPosition + new WVec(0, 0, dz)); return true; } @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities public override Activity Tick(Actor self) { // Refuse to take off if it would land immediately again. - if (helicopter.ForceLanding) + if (aircraft.ForceLanding) { Cancel(self); return NextActivity; @@ -64,43 +64,43 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceled || !target.IsValidFor(self)) return NextActivity; - if (!playedSound && helicopter.Info.TakeoffSound != null && self.IsAtGroundLevel()) + if (!playedSound && aircraft.Info.TakeoffSound != null && self.IsAtGroundLevel()) { - Game.Sound.Play(SoundType.World, helicopter.Info.TakeoffSound); + Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSound); playedSound = true; } - if (AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude)) + if (AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) return this; var pos = target.CenterPosition; // Rotate towards the target var dist = pos - self.CenterPosition; - var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing; - helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.TurnSpeed); - var move = helicopter.FlyStep(desiredFacing); + var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : aircraft.Facing; + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); + var move = aircraft.FlyStep(desiredFacing); // Inside the minimum range, so reverse - if (minRange.Length > 0 && target.IsInRange(helicopter.CenterPosition, minRange)) + if (minRange.Length > 0 && target.IsInRange(aircraft.CenterPosition, minRange)) { - helicopter.SetPosition(self, helicopter.CenterPosition - move); + aircraft.SetPosition(self, aircraft.CenterPosition - move); return this; } // Inside the maximum range, so we're done - if (maxRange.Length > 0 && target.IsInRange(helicopter.CenterPosition, maxRange)) + if (maxRange.Length > 0 && target.IsInRange(aircraft.CenterPosition, maxRange)) return NextActivity; // The next move would overshoot, so just set the final position if (dist.HorizontalLengthSquared < move.HorizontalLengthSquared) { - var targetAltitude = helicopter.CenterPosition.Z + helicopter.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(helicopter.CenterPosition).Length; - helicopter.SetPosition(self, pos + new WVec(0, 0, targetAltitude - pos.Z)); + var targetAltitude = aircraft.CenterPosition.Z + aircraft.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length; + aircraft.SetPosition(self, pos + new WVec(0, 0, targetAltitude - pos.Z)); return NextActivity; } - helicopter.SetPosition(self, helicopter.CenterPosition + move); + aircraft.SetPosition(self, aircraft.CenterPosition + move); return this; }