diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 0feb272ac3..c335b2d834 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -387,6 +387,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs new file mode 100644 index 0000000000..b6c9958969 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs @@ -0,0 +1,73 @@ +#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 System.Linq; +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Traits +{ + public class WithAttackAnimationInfo : ITraitInfo, Requires, Requires, Requires + { + [Desc("Armament name")] + public readonly string Armament = "primary"; + + [Desc("Displayed while attacking.")] + public readonly string AttackSequence = null; + + [Desc("Displayed while targeting.")] + public readonly string AimSequence = null; + + [Desc("Shown while reloading.")] + public readonly string ReloadPrefix = null; + + public object Create(ActorInitializer init) { return new WithAttackAnimation(init, this); } + } + + public class WithAttackAnimation : ITick, INotifyAttack + { + readonly WithAttackAnimationInfo info; + readonly AttackBase attack; + readonly Armament armament; + readonly WithFacingSpriteBody wfsb; + + public WithAttackAnimation(ActorInitializer init, WithAttackAnimationInfo info) + { + this.info = info; + attack = init.Self.Trait(); + armament = init.Self.TraitsImplementing() + .Single(a => a.Info.Name == info.Armament); + wfsb = init.Self.Trait(); + } + + public void Attacking(Actor self, Target target, Armament a, Barrel barrel) + { + if (!string.IsNullOrEmpty(info.AttackSequence)) + wfsb.PlayCustomAnimation(self, info.AttackSequence); + } + + public void Tick(Actor self) + { + if (string.IsNullOrEmpty(info.AimSequence) && string.IsNullOrEmpty(info.ReloadPrefix)) + return; + + var sequence = wfsb.Info.Sequence; + if (!string.IsNullOrEmpty(info.AimSequence) && attack.IsAttacking) + sequence = info.AimSequence; + + var prefix = (armament.IsReloading && !string.IsNullOrEmpty(info.ReloadPrefix)) ? info.ReloadPrefix : ""; + + if (!string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence)) + sequence = prefix + sequence; + + wfsb.DefaultAnimation.ReplaceAnim(sequence); + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 59fb134a0e..9d0d30114c 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -1045,6 +1045,27 @@ namespace OpenRA.Mods.Common.UtilityCommands if (rru != null) rru.Key = "-WithFacingSpriteBody"; } + + // For RenderUnitReload + var rur = node.Value.Nodes.Where(x => x.Key == "RenderUnitReload"); + if (rur.Any()) + { + rur.Do(x => x.Key = "RenderSprites"); + node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", "")); + node.Value.Nodes.Add(new MiniYamlNode("WithFacingSpriteBody", "", new List + { + new MiniYamlNode("Sequence", "idle") + })); + node.Value.Nodes.Add(new MiniYamlNode("WithAttackAnimation", "", new List + { + new MiniYamlNode("AimSequence", "aim"), + new MiniYamlNode("ReloadPrefix", "empty-") + })); + + var rrur = node.Value.Nodes.FirstOrDefault(n => n.Key == "-RenderUnitReload"); + if (rrur != null) + rrur.Key = "-WithFacingSpriteBody"; + } } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index afd27135f0..d4c2fb794c 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -88,7 +88,6 @@ - diff --git a/OpenRA.Mods.RA/Traits/Render/RenderUnitReload.cs b/OpenRA.Mods.RA/Traits/Render/RenderUnitReload.cs deleted file mode 100644 index c26235c294..0000000000 --- a/OpenRA.Mods.RA/Traits/Render/RenderUnitReload.cs +++ /dev/null @@ -1,55 +0,0 @@ -#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 System.Linq; -using OpenRA.Mods.Common.Traits; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA.Traits -{ - class RenderUnitReloadInfo : RenderUnitInfo, Requires, Requires - { - [Desc("Armament name")] - public readonly string Armament = "primary"; - - [Desc("Displayed while targeting.")] - public readonly string AimSequence = "aim"; - - [Desc("Shown while reloading.")] - public readonly string EmptyPrefix = "empty-"; - - public override object Create(ActorInitializer init) { return new RenderUnitReload(init, this); } - } - - class RenderUnitReload : RenderUnit - { - readonly AttackBase attack; - readonly Armament armament; - readonly RenderUnitReloadInfo info; - - public RenderUnitReload(ActorInitializer init, RenderUnitReloadInfo info) - : base(init, info) - { - this.info = info; - attack = init.Self.Trait(); - armament = init.Self.TraitsImplementing() - .Single(a => a.Info.Name == info.Armament); - } - - public override void Tick(Actor self) - { - var sequence = (armament.IsReloading ? info.EmptyPrefix : "") + (attack.IsAttacking ? info.AimSequence : info.Sequence); - if (sequence != DefaultAnimation.CurrentSequence.Name) - DefaultAnimation.ReplaceAnim(sequence); - - base.Tick(self); - } - } -} diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 07d661a39b..6667b33e64 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -20,11 +20,17 @@ V2RL: Armament: Weapon: SCUD AttackFrontal: - RenderUnitReload: + RenderSprites: AutoTarget: Explodes: Weapon: SCUD EmptyWeapon: UnitExplodeSmall + AutoSelectionSize: + WithFacingSpriteBody: + Sequence: idle + WithAttackAnimation: + AimSequence: aim + ReloadPrefix: empty- 1TNK: Inherits: ^Tank