diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 7cd81fde78..53000d511f 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -71,7 +71,6 @@ - diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithReloadingSpriteTurret.cs b/OpenRA.Mods.Cnc/Traits/Render/WithReloadingSpriteTurret.cs deleted file mode 100644 index f7f48a3e28..0000000000 --- a/OpenRA.Mods.Cnc/Traits/Render/WithReloadingSpriteTurret.cs +++ /dev/null @@ -1,76 +0,0 @@ -#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; -using System.Linq; -using OpenRA.Mods.Common.Traits; -using OpenRA.Mods.Common.Traits.Render; -using OpenRA.Traits; - -namespace OpenRA.Mods.Cnc.Traits.Render -{ - [Desc("Renders ammo-dependent turret graphics for units with the Turreted trait.")] - public class WithReloadingSpriteTurretInfo : WithSpriteTurretInfo, Requires, Requires - { - [Desc("AmmoPool to use for ammo-dependent sequences.")] - public readonly string AmmoPoolName = null; - - [Desc("How many reload stages does this turret have. Defaults to AmmoPool's Ammo.", - "Adds current reload stage to Sequence as suffix when a matching AmmoPool is present.")] - public readonly int ReloadStages = -1; - - public override object Create(ActorInitializer init) { return new WithReloadingSpriteTurret(init.Self, this); } - } - - public class WithReloadingSpriteTurret : WithSpriteTurret - { - readonly int reloadStages; - readonly AmmoPool ammoPool; - string sequence; - string ammoSuffix; - - public WithReloadingSpriteTurret(Actor self, WithReloadingSpriteTurretInfo info) - : base(self, info) - { - ammoPool = self.TraitsImplementing().FirstOrDefault(a => a.Info.Name == info.AmmoPoolName); - if (ammoPool == null) - throw new InvalidOperationException("Actor type '" + self.Info.Name + "' does not define a valid ammo pool for its reloading turret."); - - sequence = Info.Sequence; - reloadStages = info.ReloadStages; - - var initialAmmo = ammoPool.Info.InitialAmmo; - var ammo = ammoPool.Info.Ammo; - var initialAmmoStage = initialAmmo >= 0 && initialAmmo != ammo ? initialAmmo : ammo; - - if (ammoPool != null && reloadStages < 0) - ammoSuffix = initialAmmoStage.ToString(); - if (ammoPool != null && reloadStages >= 0) - ammoSuffix = (initialAmmoStage * reloadStages / ammo).ToString(); - } - - protected override void Tick(Actor self) - { - if (Info.AimSequence != null) - sequence = Attack.IsAiming ? Info.AimSequence : Info.Sequence; - - var currentAmmo = ammoPool.GetAmmoCount(); - if (reloadStages < 0) - ammoSuffix = currentAmmo.ToString(); - if (reloadStages >= 0) - ammoSuffix = (currentAmmo * reloadStages / ammoPool.Info.Ammo).ToString(); - - var newSequence = NormalizeSequence(self, sequence + ammoSuffix); - if (DefaultAnimation.CurrentSequence.Name != newSequence) - DefaultAnimation.ReplaceAnim(newSequence); - } - } -} diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 8d9c2156bb..985dcfed65 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -1650,6 +1650,30 @@ namespace OpenRA.Mods.Common.UtilityCommands } } + // Removed WithReloadingSpriteTurret + if (engineVersion < 20180223) + { + var reloadingTurret = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("WithReloadingSpriteTurret", StringComparison.Ordinal)); + if (reloadingTurret != null) + { + var ammoPool = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AmmoPool", StringComparison.Ordinal)); + if (ammoPool != null) + ammoPool.Value.Nodes.Add(new MiniYamlNode("AmmoCondition", "ammo")); + + RenameNodeKey(reloadingTurret, "WithSpriteTurret"); + var noAmmoTurret = new MiniYamlNode("WithSpriteTurret@NoAmmo", ""); + var reqAmmoCondition = new MiniYamlNode("RequiresCondition", "ammo"); + var reqNoAmmoCondition = new MiniYamlNode("RequiresCondition", "!ammo"); + + reloadingTurret.Value.Nodes.Add(reqAmmoCondition); + noAmmoTurret.Value.Nodes.Add(reqNoAmmoCondition); + node.Value.Nodes.Add(noAmmoTurret); + + Console.WriteLine("WithReloadingSpriteTurret has been removed in favor of using stacked AmmoPool.AmmoConditions."); + Console.WriteLine("Check if your affected actors need further changes."); + } + } + UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); } diff --git a/mods/cnc/rules/vehicles.yaml b/mods/cnc/rules/vehicles.yaml index 6d21a70662..577a7827e3 100644 --- a/mods/cnc/rules/vehicles.yaml +++ b/mods/cnc/rules/vehicles.yaml @@ -539,9 +539,16 @@ MLRS: AmmoPool: Ammo: 2 PipCount: 0 + AmmoCondition: ammo AttackTurreted: - WithReloadingSpriteTurret: - AmmoPoolName: primary + WithSpriteTurret: + RequiresCondition: ammo > 1 + WithSpriteTurret@OneMissile: + RequiresCondition: ammo == 1 + Sequence: turret1 + WithSpriteTurret@NoMissiles: + RequiresCondition: !ammo + Sequence: turret0 AutoTarget: InitialStanceAI: Defend RenderRangeCircle: diff --git a/mods/cnc/sequences/vehicles.yaml b/mods/cnc/sequences/vehicles.yaml index c354858fac..c8602cc9a8 100644 --- a/mods/cnc/sequences/vehicles.yaml +++ b/mods/cnc/sequences/vehicles.yaml @@ -256,10 +256,6 @@ mlrs: Start: 32 Facings: 32 UseClassicFacingFudge: True - turret2: - Start: 32 - Facings: 32 - UseClassicFacingFudge: True turret1: Start: 64 Facings: 32