diff --git a/OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs b/OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs index 9f87d16e81..07c0c74379 100644 --- a/OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs +++ b/OpenRA.Mods.Common/Activities/UndeployForGrantedCondition.cs @@ -24,8 +24,24 @@ namespace OpenRA.Mods.Common.Activities this.deploy = deploy; } + protected override void OnFirstRun(Actor self) + { + var tInfo = self.Info.TraitInfoOrDefault(); + if (tInfo != null) + QueueChild(new WaitForTurretAlignment(self, tInfo.InitialFacing)); + } + public override Activity Tick(Actor self) { + if (ChildActivity != null) + { + ActivityUtils.RunActivity(self, ChildActivity); + return this; + } + + if (IsCanceled) + return NextActivity; + IsInterruptible = false; // must DEPLOY from now. deploy.Undeploy(); diff --git a/OpenRA.Mods.Common/Activities/WaitForTurretAlignment.cs b/OpenRA.Mods.Common/Activities/WaitForTurretAlignment.cs new file mode 100644 index 0000000000..33e9ccc909 --- /dev/null +++ b/OpenRA.Mods.Common/Activities/WaitForTurretAlignment.cs @@ -0,0 +1,42 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 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.Linq; +using OpenRA.Activities; +using OpenRA.Mods.Common.Traits; + +namespace OpenRA.Mods.Common.Activities +{ + public class WaitForTurretAlignment : Activity + { + readonly Turreted turreted; + readonly int desiredAlignment; + + public WaitForTurretAlignment(Actor self, int desiredAlignment) + { + this.turreted = self.Trait(); + this.desiredAlignment = desiredAlignment; + } + + protected override void OnFirstRun(Actor self) + { + turreted.StopAiming(self); + } + + public override Activity Tick(Actor self) + { + turreted.DesiredFacing = desiredAlignment; + if (turreted.HasAchievedDesiredFacing) + return NextActivity; + return this; + } + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index e94c56c42a..99137a0dc0 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -119,6 +119,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index f77ca88b08..e04417e1f0 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -156,6 +156,12 @@ namespace OpenRA.Mods.Common.Traits return HasAchievedDesiredFacing; } + public void StopAiming(Actor self) + { + if (attack.IsAiming) + attack.OnStopOrder(self); + } + public virtual bool HasAchievedDesiredFacing { get { return DesiredFacing == null || TurretFacing == DesiredFacing.Value; }