Units that have turrets while deployed now move their turrets back to their initial positions before undeploying

- Tested in TS with all deployable units and did a quick check for obvious issues in TD and RA.
This commit is contained in:
BGluth
2018-08-04 15:39:39 -06:00
committed by Paul Chote
parent 00dc161628
commit b88b84c05a
4 changed files with 65 additions and 0 deletions

View File

@@ -24,8 +24,24 @@ namespace OpenRA.Mods.Common.Activities
this.deploy = deploy; this.deploy = deploy;
} }
protected override void OnFirstRun(Actor self)
{
var tInfo = self.Info.TraitInfoOrDefault<TurretedInfo>();
if (tInfo != null)
QueueChild(new WaitForTurretAlignment(self, tInfo.InitialFacing));
}
public override Activity Tick(Actor self) 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. IsInterruptible = false; // must DEPLOY from now.
deploy.Undeploy(); deploy.Undeploy();

View File

@@ -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<Turreted>();
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;
}
}
}

View File

@@ -119,6 +119,7 @@
<Compile Include="Activities\UnloadCargo.cs" /> <Compile Include="Activities\UnloadCargo.cs" />
<Compile Include="Activities\Wait.cs" /> <Compile Include="Activities\Wait.cs" />
<Compile Include="Activities\WaitForTransport.cs" /> <Compile Include="Activities\WaitForTransport.cs" />
<Compile Include="Activities\WaitForTurretAlignment.cs" />
<Compile Include="ActorExts.cs" /> <Compile Include="ActorExts.cs" />
<Compile Include="AI\AIUtils.cs" /> <Compile Include="AI\AIUtils.cs" />
<Compile Include="AI\AttackOrFleeFuzzy.cs" /> <Compile Include="AI\AttackOrFleeFuzzy.cs" />

View File

@@ -156,6 +156,12 @@ namespace OpenRA.Mods.Common.Traits
return HasAchievedDesiredFacing; return HasAchievedDesiredFacing;
} }
public void StopAiming(Actor self)
{
if (attack.IsAiming)
attack.OnStopOrder(self);
}
public virtual bool HasAchievedDesiredFacing public virtual bool HasAchievedDesiredFacing
{ {
get { return DesiredFacing == null || TurretFacing == DesiredFacing.Value; } get { return DesiredFacing == null || TurretFacing == DesiredFacing.Value; }