From 5c18220636d581a895791514e7aac0be9eab317b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Mar 2015 18:44:43 +0100 Subject: [PATCH] Add upgrade support to WithTurret. --- .../Traits/Render/WithTurret.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs index bd1138950a..e13708d5f0 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTurret.cs @@ -17,7 +17,8 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Renders turrets for units with the Turreted trait.")] - public class WithTurretInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires, Requires, Requires + public class WithTurretInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPreviewSpritesInfo, + Requires, Requires, Requires { [Desc("Sequence name to use")] public readonly string Sequence = "turret"; @@ -35,6 +36,9 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) { + if (UpgradeMinEnabledLevel > 0) + yield break; + var body = init.Actor.Traits.Get(); var t = init.Actor.Traits.WithInterface() .First(tt => tt.Turret == Turret); @@ -52,9 +56,8 @@ namespace OpenRA.Mods.Common.Traits } } - public class WithTurret : ITick + public class WithTurret : UpgradableTrait, ITick { - WithTurretInfo info; RenderSprites rs; IBodyOrientation body; AttackBase ab; @@ -63,8 +66,8 @@ namespace OpenRA.Mods.Common.Traits Animation anim; public WithTurret(Actor self, WithTurretInfo info) + : base(info) { - this.info = info; rs = self.Trait(); body = self.Trait(); @@ -76,8 +79,8 @@ namespace OpenRA.Mods.Common.Traits anim = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing); anim.Play(info.Sequence); - rs.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( - anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1))); + rs.Add("turret_{0}_{1}".F(info.Turret, info.Sequence), new AnimationWithOffset( + anim, () => TurretOffset(self), () => IsTraitDisabled, () => false, p => ZOffsetFromCenter(self, p, 1))); // Restrict turret facings to match the sprite t.QuantizedFacings = anim.CurrentSequence.Facings; @@ -85,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits WVec TurretOffset(Actor self) { - if (!info.Recoils) + if (!Info.Recoils) return t.Position(self); var recoil = arms.Aggregate(WRange.Zero, (a, b) => a + b.Recoil); @@ -97,10 +100,10 @@ namespace OpenRA.Mods.Common.Traits public void Tick(Actor self) { - if (info.AimSequence == null) + if (Info.AimSequence == null) return; - var sequence = ab.IsAttacking ? info.AimSequence : info.Sequence; + var sequence = ab.IsAttacking ? Info.AimSequence : Info.Sequence; anim.ReplaceAnim(sequence); }