From a11e403084c10bd9f1b10a408b35bb5e64c238f1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 24 May 2013 18:18:47 +1200 Subject: [PATCH] Draw turrets, spinners, rotors at ZOffset +1 relative to the body. --- OpenRA.Game/Graphics/AnimationWithOffset.cs | 12 ++++++++---- OpenRA.Mods.RA/Render/WithRotor.cs | 2 +- OpenRA.Mods.RA/Render/WithSpinner.cs | 2 +- OpenRA.Mods.RA/Render/WithTurret.cs | 8 +++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs index 6e259cb1ec..338fbcf956 100644 --- a/OpenRA.Game/Graphics/AnimationWithOffset.cs +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -18,12 +18,15 @@ namespace OpenRA.Graphics public readonly Animation Animation; public readonly Func OffsetFunc; public readonly Func DisableFunc; - public readonly int ZOffset; + public readonly Func ZOffset; public AnimationWithOffset(Animation a, Func offset, Func disable) - : this(a, offset, disable, 0) { } + : this(a, offset, disable, null) { } public AnimationWithOffset(Animation a, Func offset, Func disable, int zOffset) + : this(a, offset, disable, _ => zOffset) { } + + public AnimationWithOffset(Animation a, Func offset, Func disable, Func zOffset) { this.Animation = a; this.OffsetFunc = offset; @@ -42,12 +45,13 @@ namespace OpenRA.Graphics if (OffsetFunc != null) p += OffsetFunc(); - return new SpriteRenderable(Animation.Image, p, ZOffset, pal, scale); + var z = (ZOffset != null) ? ZOffset(p) : 0; + return new SpriteRenderable(Animation.Image, p, z, pal, scale); } public static implicit operator AnimationWithOffset(Animation a) { - return new AnimationWithOffset(a, null, null, 0); + return new AnimationWithOffset(a, null, null, null); } } } diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index 671a5d2f21..eea9c0dd77 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render rotorAnim.PlayRepeating("rotor"); rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, () => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))), - null, 1)); + null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/WithSpinner.cs b/OpenRA.Mods.RA/Render/WithSpinner.cs index 2940a88b56..c9a1eaf44e 100755 --- a/OpenRA.Mods.RA/Render/WithSpinner.cs +++ b/OpenRA.Mods.RA/Render/WithSpinner.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render spinner.PlayRepeating(info.Sequence); rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner, () => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))), - null, 1)); + null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } } } diff --git a/OpenRA.Mods.RA/Render/WithTurret.cs b/OpenRA.Mods.RA/Render/WithTurret.cs index 50b55ab1a9..b0981325ce 100755 --- a/OpenRA.Mods.RA/Render/WithTurret.cs +++ b/OpenRA.Mods.RA/Render/WithTurret.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Render anim = new Animation(rs.GetImage(self), () => t.turretFacing); anim.Play(info.Sequence); rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( - anim, () => TurretOffset(self), null, t.Offset.Length)); + anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1))); } WVec TurretOffset(Actor self) @@ -73,5 +73,11 @@ namespace OpenRA.Mods.RA.Render var sequence = ab.IsAttacking ? info.AimSequence : info.Sequence; rs.anims["turret_{0}".F(info.Turret)].Animation.ReplaceAnim(sequence); } + + static public int ZOffsetFromCenter(Actor self, WPos pos, int offset) + { + var delta = self.CenterPosition - pos; + return delta.Y + delta.Z + offset; + } } }