From 4f8f8cfb9d741dda7857a0b79a254ec8f66b4f6e Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 1 May 2019 15:45:10 +0200 Subject: [PATCH] Merge HeliFly into Fly --- OpenRA.Mods.Common/Activities/Air/Fly.cs | 116 +++++++++++--- .../Activities/Air/FlyCircle.cs | 6 +- .../Activities/Air/FlyFollow.cs | 2 +- .../Activities/Air/FlyOffMap.cs | 2 +- OpenRA.Mods.Common/Activities/Air/FlyTimed.cs | 2 +- .../Activities/Air/HeliAttack.cs | 20 +-- OpenRA.Mods.Common/Activities/Air/HeliFly.cs | 148 ------------------ OpenRA.Mods.Common/Activities/Air/Land.cs | 4 +- .../Activities/Air/ReturnToBase.cs | 6 +- OpenRA.Mods.Common/Activities/DeliverUnit.cs | 8 +- OpenRA.Mods.Common/Activities/PickupUnit.cs | 2 +- .../Properties/AircraftProperties.cs | 5 +- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 49 ++---- .../Traits/Buildings/FreeActorWithDelivery.cs | 2 +- 14 files changed, 129 insertions(+), 243 deletions(-) delete mode 100644 OpenRA.Mods.Common/Activities/Air/HeliFly.cs diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index 91b20c1fc3..ac1884f1b4 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -51,26 +51,56 @@ namespace OpenRA.Mods.Common.Activities this.minRange = minRange; } - public static void FlyToward(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1) + public static void FlyTick(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, WVec moveOverride, int turnSpeedOverride = -1) { - desiredAltitude = new WDist(aircraft.CenterPosition.Z) + desiredAltitude - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); - - var move = aircraft.FlyStep(aircraft.Facing); - var altitude = aircraft.CenterPosition.Z; + var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); + var move = aircraft.Info.CanHover ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing); + if (moveOverride != WVec.Zero) + move = moveOverride; var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed); - if (altitude != desiredAltitude.Length) + // Note: we assume that if move.Z is not zero, it's intentional and we want to move in that vertical direction instead of towards desiredAltitude. + // If that is not desired, the place that calls this should make sure moveOverride.Z is zero. + if (dat != desiredAltitude || move.Z != 0) { - var delta = move.HorizontalLength * aircraft.Info.MaximumPitch.Tan() / 1024; - var dz = (desiredAltitude.Length - altitude).Clamp(-delta, delta); - move += new WVec(0, 0, dz); + var maxDelta = move.HorizontalLength * aircraft.Info.MaximumPitch.Tan() / 1024; + var moveZ = move.Z != 0 ? move.Z : (desiredAltitude.Length - dat.Length); + var deltaZ = moveZ.Clamp(-maxDelta, maxDelta); + move = new WVec(move.X, move.Y, deltaZ); } aircraft.SetPosition(self, aircraft.CenterPosition + move); } + public static void FlyTick(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1) + { + FlyTick(self, aircraft, desiredFacing, desiredAltitude, WVec.Zero, turnSpeedOverride); + } + + // Should only be used for vertical-only movement, usually VTOL take-off or land. Terrain-induced altitude changes should always be handled by FlyTick. + public static bool VerticalTakeOffOrLandTick(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, int turnSpeedOverride = -1) + { + var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); + var move = WVec.Zero; + + var turnSpeed = turnSpeedOverride > -1 ? turnSpeedOverride : aircraft.TurnSpeed; + aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, turnSpeed); + + if (dat != desiredAltitude) + { + var maxDelta = aircraft.Info.AltitudeVelocity.Length; + var deltaZ = (desiredAltitude.Length - dat.Length).Clamp(-maxDelta, maxDelta); + move += new WVec(0, 0, deltaZ); + } + else + return false; + + aircraft.SetPosition(self, aircraft.CenterPosition + move); + return true; + } + public override Activity Tick(Actor self) { // Refuse to take off if it would land immediately again. @@ -96,18 +126,28 @@ namespace OpenRA.Mods.Common.Activities if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) return NextActivity; - var pos = self.CenterPosition; - var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; - - if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0 && self.IsAtGroundLevel()) - { - Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition); - soundPlayed = true; - } + var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); // We are taking off, so remove influence in ground cells. - if (self.IsAtGroundLevel()) + if (dat <= aircraft.LandAltitude) + { + if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0) + { + Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition); + soundPlayed = true; + } + aircraft.RemoveInfluence(); + } + + // If we're a VTOL, rise before flying forward + if (aircraft.Info.VTOL) + if (VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude)) + return this; + + var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; + var delta = checkTarget.CenterPosition - self.CenterPosition; + 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); @@ -115,19 +155,43 @@ namespace OpenRA.Mods.Common.Activities if (insideMaxRange && !insideMinRange) return NextActivity; - var delta = checkTarget.CenterPosition - self.CenterPosition; + var move = aircraft.Info.CanHover ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing); - // The next move would overshoot, so consider it close enough - var move = aircraft.FlyStep(aircraft.Facing); + // Inside the minimum range, so reverse if CanHover + if (aircraft.Info.CanHover && insideMinRange) + { + FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move); + return this; + } + + // The next move would overshoot, so consider it close enough or set final position if CanHover if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared) + { + if (aircraft.Info.CanHover) + { + // Set final (horizontal) position + if (delta.HorizontalLengthSquared != 0) + { + // Ensure we don't include a non-zero vertical component here that would move us away from CruiseAltitude + var deltaMove = new WVec(delta.X, delta.Y, 0); + FlyTick(self, aircraft, desiredFacing, dat, deltaMove); + } + + // Move to CruiseAltitude, if not already there + if (dat != aircraft.Info.CruiseAltitude) + { + Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); + return this; + } + } + return NextActivity; + } // Don't turn until we've reached the cruise altitude - var desiredFacing = delta.Yaw.Facing; - var targetAltitude = aircraft.CenterPosition.Z + aircraft.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length; - if (aircraft.CenterPosition.Z < targetAltitude) + if (dat < aircraft.Info.CruiseAltitude) desiredFacing = aircraft.Facing; - else + else if (!aircraft.Info.CanHover) { // Using the turn rate, compute a hypothetical circle traced by a continuous turn. // If it contains the destination point, it's unreachable without more complex manuvering. @@ -148,7 +212,7 @@ namespace OpenRA.Mods.Common.Activities desiredFacing = aircraft.Facing; } - FlyToward(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); + FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs b/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs index f55324d614..2834940df7 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyCircle.cs @@ -47,7 +47,11 @@ namespace OpenRA.Mods.Common.Activities // We can't possibly turn this fast var desiredFacing = aircraft.Facing + 64; - Fly.FlyToward(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, turnSpeedOverride); + + // This override is necessary, otherwise CanHover aircraft would circle sideways + var move = aircraft.FlyStep(aircraft.Facing); + + Fly.FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move, turnSpeedOverride); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs index d41b7dee3e..b1ab5c0570 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Activities // otherwise if it is hidden or dead we give up if (checkTarget.IsInRange(pos, maxRange) && !checkTarget.IsInRange(pos, minRange)) { - Fly.FlyToward(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); + Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return useLastVisibleTarget ? NextActivity : this; } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs b/OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs index 8645ca50af..2c9ee85d14 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyOffMap.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceling || !self.World.Map.Contains(self.Location)) return NextActivity; - Fly.FlyToward(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); + Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); return this; } } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyTimed.cs b/OpenRA.Mods.Common/Activities/Air/FlyTimed.cs index 62dcffcdca..951ac31565 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyTimed.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyTimed.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities if (IsCanceling || remainingTicks-- == 0) return NextActivity; - Fly.FlyToward(self, aircraft, aircraft.Facing, cruiseAltitude); + Fly.FlyTick(self, aircraft, aircraft.Facing, cruiseAltitude); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index 2371828af2..a324653b54 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -133,13 +133,15 @@ namespace OpenRA.Mods.Common.Activities var pos = self.CenterPosition; var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; - // Update facing + // Update facing and altitude var delta = attackAircraft.GetTargetPosition(pos, checkTarget) - pos; var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); - if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) + if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude)) return this; + var move = aircraft.FlyStep(desiredFacing); + // We don't know where the target actually is, so move to where we last saw it if (useLastVisibleTarget) { @@ -151,16 +153,14 @@ namespace OpenRA.Mods.Common.Activities } // Fly towards the last known position - aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(desiredFacing)); + Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude, move); return this; } - // Fly towards the target + // Fly towards the target if outside max range and backwards if within min range if (!target.IsInRange(pos, attackAircraft.GetMaximumRangeVersusTarget(target))) - aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(desiredFacing)); - - // Fly backwards from the target - if (target.IsInRange(pos, attackAircraft.GetMinimumRangeVersusTarget(target))) + Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude, move); + else if (target.IsInRange(pos, attackAircraft.GetMinimumRangeVersusTarget(target))) { // Facing 0 doesn't work with the following position change var facing = 1; @@ -168,7 +168,9 @@ namespace OpenRA.Mods.Common.Activities facing = desiredFacing; else if (aircraft.Facing != 0) facing = aircraft.Facing; - aircraft.SetPosition(self, aircraft.CenterPosition + aircraft.FlyStep(-facing)); + + move = aircraft.FlyStep(-facing); + Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude, move); } return this; diff --git a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs deleted file mode 100644 index d466e6a7d3..0000000000 --- a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs +++ /dev/null @@ -1,148 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System.Collections.Generic; -using OpenRA.Activities; -using OpenRA.Mods.Common.Traits; -using OpenRA.Primitives; -using OpenRA.Traits; - -namespace OpenRA.Mods.Common.Activities -{ - public class HeliFly : Activity - { - readonly Aircraft aircraft; - readonly WDist maxRange; - readonly WDist minRange; - readonly Color? targetLineColor; - bool soundPlayed; - - Target target; - Target lastVisibleTarget; - bool useLastVisibleTarget; - - public HeliFly(Actor self, Target t, WPos? initialTargetPosition = null, Color? targetLineColor = null) - { - aircraft = self.Trait(); - target = t; - this.targetLineColor = targetLineColor; - - // The target may become hidden between the initial order request and the first tick (e.g. if queued) - // Moving to any position (even if quite stale) is still better than immediately giving up - if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner)) - || target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain) - lastVisibleTarget = Target.FromPos(target.CenterPosition); - else if (initialTargetPosition.HasValue) - lastVisibleTarget = Target.FromPos(initialTargetPosition.Value); - } - - public HeliFly(Actor self, Target t, WDist minRange, WDist maxRange, - WPos? initialTargetPosition = null, Color? targetLineColor = null) - : this(self, t, initialTargetPosition, targetLineColor) - { - this.maxRange = maxRange; - this.minRange = minRange; - } - - public static bool AdjustAltitude(Actor self, Aircraft aircraft, WDist targetAltitude) - { - targetAltitude = new WDist(aircraft.CenterPosition.Z) + targetAltitude - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); - - var altitude = aircraft.CenterPosition.Z; - if (altitude == targetAltitude.Length) - return false; - - var delta = aircraft.Info.AltitudeVelocity.Length; - var dz = (targetAltitude.Length - altitude).Clamp(-delta, delta); - aircraft.SetPosition(self, aircraft.CenterPosition + new WVec(0, 0, dz)); - - return true; - } - - public override Activity Tick(Actor self) - { - // Refuse to take off if it would land immediately again. - if (aircraft.ForceLanding) - Cancel(self); - - if (IsCanceling) - return NextActivity; - - bool targetIsHiddenActor; - target = target.Recalculate(self.Owner, out targetIsHiddenActor); - if (!targetIsHiddenActor && target.Type == TargetType.Actor) - lastVisibleTarget = Target.FromTargetPositions(target); - - var oldUseLastVisibleTarget = useLastVisibleTarget; - useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self); - - // Update target lines if required - if (useLastVisibleTarget != oldUseLastVisibleTarget && targetLineColor.HasValue) - self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value, false); - - // Target is hidden or dead, and we don't have a fallback position to move towards - if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self)) - return NextActivity; - - if (!soundPlayed && aircraft.Info.TakeoffSounds.Length > 0 && self.IsAtGroundLevel()) - { - Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition); - soundPlayed = true; - } - - // We are taking off, so remove influence in ground cells. - if (self.IsAtGroundLevel()) - aircraft.RemoveInfluence(); - - if (AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) - return this; - - var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target; - - // Update facing - var delta = checkTarget.CenterPosition - aircraft.CenterPosition; - var desiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : aircraft.Facing; - aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed); - if (AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude)) - return this; - - var move = aircraft.FlyStep(desiredFacing); - - // Inside the minimum range, so reverse - if (minRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, minRange)) - { - aircraft.SetPosition(self, aircraft.CenterPosition - move); - return this; - } - - // Inside the maximum range, so we're done - if (maxRange.Length > 0 && checkTarget.IsInRange(aircraft.CenterPosition, maxRange)) - return NextActivity; - - // The next move would overshoot, so just set the final position - if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared) - { - var targetAltitude = aircraft.CenterPosition.Z + aircraft.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length; - aircraft.SetPosition(self, checkTarget.CenterPosition + new WVec(0, 0, targetAltitude - checkTarget.CenterPosition.Z)); - return NextActivity; - } - - aircraft.SetPosition(self, aircraft.CenterPosition + move); - - return this; - } - - public override IEnumerable GetTargets(Actor self) - { - yield return target; - } - } -} diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index a71b9b76f5..45c3277c71 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities // For VTOLs we assume we've already arrived at the target location and just need to move downward if (aircraft.Info.VTOL) { - if (HeliFly.AdjustAltitude(self, aircraft, landAltitude)) + if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, landAltitude)) return this; return NextActivity; @@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Activities } var landingAlt = self.World.Map.DistanceAboveTerrain(target.CenterPosition + offset) + aircraft.LandAltitude; - Fly.FlyToward(self, aircraft, d.Yaw.Facing, landingAlt); + Fly.FlyTick(self, aircraft, d.Yaw.Facing, landingAlt); return this; } diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index 1a971e57fc..a48292ce41 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -170,7 +170,7 @@ namespace OpenRA.Mods.Common.Activities var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024; var target = Target.FromPos(nearestResupplier.CenterPosition + randomPosition); - QueueChild(self, new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green), true); + QueueChild(self, new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green), true); } return this; @@ -206,9 +206,7 @@ namespace OpenRA.Mods.Common.Activities var exit = dest.FirstExitOrDefault(null); var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero; - if (aircraft.Info.CanHover) - QueueChild(self, new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)), true); - else if (aircraft.Info.VTOL) + if (aircraft.Info.VTOL || aircraft.Info.CanHover) QueueChild(self, new Fly(self, Target.FromPos(dest.CenterPosition + offset)), true); else { diff --git a/OpenRA.Mods.Common/Activities/DeliverUnit.cs b/OpenRA.Mods.Common/Activities/DeliverUnit.cs index 2d133fc444..98c1cfa918 100644 --- a/OpenRA.Mods.Common/Activities/DeliverUnit.cs +++ b/OpenRA.Mods.Common/Activities/DeliverUnit.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities // Can't land, so wait at the target until something changes if (target.Type == TargetType.Invalid) { - QueueChild(self, new HeliFly(self, destination), true); + QueueChild(self, new Fly(self, destination), true); QueueChild(self, new Wait(25)); return this; } @@ -98,12 +98,12 @@ namespace OpenRA.Mods.Common.Activities { var dropFacing = (target.CenterPosition - self.CenterPosition).Yaw.Facing; localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(dropFacing))); - QueueChild(self, new HeliFly(self, Target.FromPos(target.CenterPosition - body.LocalToWorld(localOffset))), true); + QueueChild(self, new Fly(self, Target.FromPos(target.CenterPosition - body.LocalToWorld(localOffset))), true); QueueChild(self, new Turn(self, dropFacing)); return this; } - QueueChild(self, new HeliFly(self, target), true); + QueueChild(self, new Fly(self, target), true); return this; } @@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Activities // Release carried actor QueueChild(self, new ReleaseUnit(self)); - QueueChild(self, new HeliFly(self, Target.FromPos(self.CenterPosition))); + QueueChild(self, new Fly(self, Target.FromPos(self.CenterPosition))); return this; } diff --git a/OpenRA.Mods.Common/Activities/PickupUnit.cs b/OpenRA.Mods.Common/Activities/PickupUnit.cs index 42029419b4..f21d537849 100644 --- a/OpenRA.Mods.Common/Activities/PickupUnit.cs +++ b/OpenRA.Mods.Common/Activities/PickupUnit.cs @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Activities var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset); if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0) { - QueueChild(self, new HeliFly(self, Target.FromPos(targetPosition)), true); + QueueChild(self, new Fly(self, Target.FromPos(targetPosition)), true); return this; } diff --git a/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs index f887936587..5c773ab507 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs @@ -31,10 +31,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Fly within the cell grid.")] public void Move(CPos cell) { - if (!aircraft.Info.CanHover) - Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell))); - else - Self.QueueActivity(new HeliFly(Self, Target.FromCell(Self.World, cell))); + Self.QueueActivity(new Fly(Self, Target.FromCell(Self.World, cell))); } [ScriptActorPropertyActivity] diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 09f6095564..70da646160 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -755,37 +755,24 @@ namespace OpenRA.Mods.Common.Traits public Activity MoveTo(CPos cell, int nearEnough) { - if (!Info.CanHover) - return new Fly(self, Target.FromCell(self.World, cell)); - - return new HeliFly(self, Target.FromCell(self.World, cell)); + return new Fly(self, Target.FromCell(self.World, cell)); } public Activity MoveTo(CPos cell, Actor ignoreActor) { - if (!Info.CanHover) - return new Fly(self, Target.FromCell(self.World, cell)); - - return new HeliFly(self, Target.FromCell(self.World, cell)); + return new Fly(self, Target.FromCell(self.World, cell)); } public Activity MoveWithinRange(Target target, WDist range, WPos? initialTargetPosition = null, Color? targetLineColor = null) { - if (!Info.CanHover) - return new Fly(self, target, WDist.Zero, range, initialTargetPosition, targetLineColor); - - return new HeliFly(self, target, WDist.Zero, range, initialTargetPosition, targetLineColor); + return new Fly(self, target, WDist.Zero, range, initialTargetPosition, targetLineColor); } public Activity MoveWithinRange(Target target, WDist minRange, WDist maxRange, WPos? initialTargetPosition = null, Color? targetLineColor = null) { - if (!Info.CanHover) - return new Fly(self, target, minRange, maxRange, - initialTargetPosition, targetLineColor); - - return new HeliFly(self, target, minRange, maxRange, + return new Fly(self, target, minRange, maxRange, initialTargetPosition, targetLineColor); } @@ -802,10 +789,7 @@ namespace OpenRA.Mods.Common.Traits public Activity MoveIntoWorld(Actor self, CPos cell, SubCell subCell = SubCell.Any) { - if (!Info.CanHover) - return new Fly(self, Target.FromCell(self.World, cell)); - - return new HeliFly(self, Target.FromCell(self.World, cell, subCell)); + return new Fly(self, Target.FromCell(self.World, cell, subCell)); } public Activity MoveToTarget(Actor self, Target target, @@ -816,7 +800,7 @@ namespace OpenRA.Mods.Common.Traits initialTargetPosition, targetLineColor); return ActivityUtils.SequenceActivities(self, - new HeliFly(self, target, initialTargetPosition, targetLineColor), + new Fly(self, target, initialTargetPosition, targetLineColor), new Turn(self, Info.InitialFacing)); } @@ -828,14 +812,9 @@ namespace OpenRA.Mods.Common.Traits public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { // TODO: Ignore repulsion when moving - if (!Info.CanHover) - return ActivityUtils.SequenceActivities(self, - new CallFunc(() => SetVisualPosition(self, fromPos)), - new Fly(self, Target.FromPos(toPos))); - return ActivityUtils.SequenceActivities(self, new CallFunc(() => SetVisualPosition(self, fromPos)), - new HeliFly(self, Target.FromPos(toPos))); + new Fly(self, Target.FromPos(toPos))); } public int EstimatedMoveDuration(Actor self, WPos fromPos, WPos toPos) @@ -940,13 +919,8 @@ namespace OpenRA.Mods.Common.Traits UnReserve(); var target = Target.FromCell(self.World, cell); - self.SetTargetLine(target, Color.Green); - - if (!Info.CanHover) - self.QueueActivity(order.Queued, new Fly(self, target)); - else - self.QueueActivity(order.Queued, new HeliFly(self, target)); + self.QueueActivity(order.Queued, new Fly(self, target)); } else if (order.OrderString == "Enter" || order.OrderString == "Repair") { @@ -1008,12 +982,7 @@ namespace OpenRA.Mods.Common.Traits self.CancelActivity(); self.SetTargetLine(target, Color.Green, false); - - if (!Info.CanHover) - self.QueueActivity(new Fly(self, target)); - else - self.QueueActivity(new HeliFly(self, target)); - + self.QueueActivity(new Fly(self, target)); UnReserve(); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs index b2792f9f95..0ad01d9c2f 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActorWithDelivery.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits carrier.Trait().AttachCarryable(carrier, cargo); carrier.QueueActivity(new DeliverUnit(carrier, location)); - carrier.QueueActivity(new HeliFly(carrier, Target.FromCell(self.World, self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom)))); + carrier.QueueActivity(new Fly(carrier, Target.FromCell(self.World, self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom)))); carrier.QueueActivity(new RemoveSelf()); self.World.AddFrameEndTask(w => self.World.Add(carrier));