diff --git a/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs index 1bfbc9b678..fc98b1bfeb 100644 --- a/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs @@ -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) diff --git a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs index 1af53306f2..0858204a70 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliFly.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliFly.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index 1ac4a7ee9b..a71b9b76f5 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -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(); - 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; - } } } diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index d79e88860f..1a971e57fc 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/DeliverUnit.cs b/OpenRA.Mods.Common/Activities/DeliverUnit.cs index f86a358fd3..2d133fc444 100644 --- a/OpenRA.Mods.Common/Activities/DeliverUnit.cs +++ b/OpenRA.Mods.Common/Activities/DeliverUnit.cs @@ -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) diff --git a/OpenRA.Mods.Common/Activities/PickupUnit.cs b/OpenRA.Mods.Common/Activities/PickupUnit.cs index 8a4fb5ee36..42029419b4 100644 --- a/OpenRA.Mods.Common/Activities/PickupUnit.cs +++ b/OpenRA.Mods.Common/Activities/PickupUnit.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/Transform.cs b/OpenRA.Mods.Common/Activities/Transform.cs index 33ad62235d..15e5738c67 100644 --- a/OpenRA.Mods.Common/Activities/Transform.cs +++ b/OpenRA.Mods.Common/Activities/Transform.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities QueueChild(self, new Turn(self, Facing)); if (self.Info.HasTraitInfo()) - QueueChild(self, new Land(self, true)); + QueueChild(self, new Land(self)); } public override Activity Tick(Actor self) diff --git a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs index f896287798..bca8dadb00 100644 --- a/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/ReinforcementsGlobal.cs @@ -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)); diff --git a/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs index 7f6a40be40..f887936587 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/AircraftProperties.cs @@ -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] diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index e42b18537f..0b1f02021b 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -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) diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index cfbabc2c69..6480832dc3 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -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)); } }