diff --git a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs index 55ed7c7b09..d9a2aa9329 100644 --- a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs +++ b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs @@ -20,8 +20,9 @@ namespace OpenRA.Mods.Common.Activities { readonly Aircraft aircraft; readonly IMove move; - readonly Target target; + Target target; bool moveToRallyPoint; + bool assignTargetOnFirstRun; public TakeOff(Actor self, Target target) { @@ -31,16 +32,9 @@ namespace OpenRA.Mods.Common.Activities } public TakeOff(Actor self) - : this(self, Target.FromCell(self.World, self.Location)) + : this(self, Target.Invalid) { - var host = aircraft.GetActorBelow(); - var rp = host != null ? host.TraitOrDefault() : null; - - var rallyPointDestination = rp != null ? rp.Location : - (host != null ? self.World.Map.CellContaining(host.CenterPosition) : self.Location); - - this.target = Target.FromCell(self.World, rallyPointDestination); - moveToRallyPoint = NextActivity == null && rallyPointDestination != self.Location; + assignTargetOnFirstRun = true; } protected override void OnFirstRun(Actor self) @@ -48,6 +42,18 @@ namespace OpenRA.Mods.Common.Activities if (aircraft.ForceLanding) return; + if (assignTargetOnFirstRun) + { + var host = aircraft.GetActorBelow(); + var rp = host != null ? host.TraitOrDefault() : null; + + var rallyPointDestination = rp != null ? rp.Location : + (host != null ? self.World.Map.CellContaining(host.CenterPosition) : self.Location); + + target = Target.FromCell(self.World, rallyPointDestination); + moveToRallyPoint = self.CurrentActivity.NextActivity == null && rallyPointDestination != self.Location; + } + // We are taking off, so remove reservation and influence in ground cells. aircraft.UnReserve(); aircraft.RemoveInfluence(); diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index cb52c7d5e1..5f7b319fa3 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -494,7 +494,7 @@ namespace OpenRA.Mods.Common.Traits MayYieldReservation = true; } - public void UnReserve() + public void UnReserve(bool takeOff = false) { if (reservation == null) return; @@ -504,7 +504,7 @@ namespace OpenRA.Mods.Common.Traits ReservedActor = null; MayYieldReservation = false; - if (self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length) + if (takeOff && self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length) self.QueueActivity(new TakeOff(self)); } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Reservable.cs b/OpenRA.Mods.Common/Traits/Buildings/Reservable.cs index 3cfe5a5853..1b618b4867 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Reservable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Reservable.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft) { if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation) - reservedForAircraft.UnReserve(); + reservedForAircraft.UnReserve(true); reservedFor = forActor; reservedForAircraft = forAircraft; @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits private void UnReserve() { if (reservedForAircraft != null) - reservedForAircraft.UnReserve(); + reservedForAircraft.UnReserve(true); } void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); }