diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index e155d1e178..90843743b3 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -80,6 +80,7 @@ + diff --git a/OpenRA.Mods.Cnc/Traits/RenderUnitFlying.cs b/OpenRA.Mods.Cnc/Traits/RenderUnitFlying.cs new file mode 100644 index 0000000000..a7ea686b2b --- /dev/null +++ b/OpenRA.Mods.Cnc/Traits/RenderUnitFlying.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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. For more information, + * see COPYING. + */ +#endregion + +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.Cnc.Traits +{ + class RenderUnitFlyingInfo : RenderUnitInfo, Requires + { + public readonly string MoveSequence = "move"; + + public override object Create(ActorInitializer init) { return new RenderUnitFlying(init, this); } + } + + class RenderUnitFlying : RenderUnit, ITick + { + readonly RenderUnitFlyingInfo info; + readonly IMove movement; + + WPos cachedPosition; + + public RenderUnitFlying(ActorInitializer init, RenderUnitFlyingInfo info) + : base(init, info) + { + this.info = info; + movement = init.Self.Trait(); + + cachedPosition = init.Self.CenterPosition; + } + + public override void Tick(Actor self) + { + base.Tick(self); + + var oldCachedPosition = cachedPosition; + cachedPosition = self.CenterPosition; + + // Flying units set IsMoving whenever they are airborne, which isn't enough for our purposes + var isMoving = movement.IsMoving && !self.IsDead && (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0; + if (isMoving ^ (DefaultAnimation.CurrentSequence.Name != info.MoveSequence)) + return; + + DefaultAnimation.ReplaceAnim(isMoving ? info.MoveSequence : info.Sequence); + } + } +} diff --git a/mods/cnc/rules/aircraft.yaml b/mods/cnc/rules/aircraft.yaml index eeaedb7db5..f7683387c1 100644 --- a/mods/cnc/rules/aircraft.yaml +++ b/mods/cnc/rules/aircraft.yaml @@ -130,7 +130,7 @@ ORCA: SelfReloads: true ReloadCount: 2 SelfReloadTicks: 100 - RenderUnit: + RenderUnitFlying: LeavesHusk: HuskActor: ORCA.Husk AutoTarget: diff --git a/mods/cnc/sequences/aircraft.yaml b/mods/cnc/sequences/aircraft.yaml index 585bbc42fa..0f6e718e4c 100644 --- a/mods/cnc/sequences/aircraft.yaml +++ b/mods/cnc/sequences/aircraft.yaml @@ -41,7 +41,7 @@ heli: orca: idle: Facings: 32 - damaged-idle: + move: Start: 32 Facings: 32 icon: orcaicnh.tem