From d6fcaafd785509ea370c4784b384f152fe8a4c20 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 24 Feb 2013 14:00:25 +1300 Subject: [PATCH] Let parachute cargo render themselves. This allows for tanks and other multi-sprite actors to render correctly while dropping. --- OpenRA.Mods.RA/Air/EjectOnDeath.cs | 6 ++---- OpenRA.Mods.RA/Effects/Parachute.cs | 31 ++++++++++++----------------- OpenRA.Mods.RA/ParaDrop.cs | 6 ++---- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/OpenRA.Mods.RA/Air/EjectOnDeath.cs b/OpenRA.Mods.RA/Air/EjectOnDeath.cs index 20463555c9..d1ed8c28da 100644 --- a/OpenRA.Mods.RA/Air/EjectOnDeath.cs +++ b/OpenRA.Mods.RA/Air/EjectOnDeath.cs @@ -35,10 +35,8 @@ namespace OpenRA.Mods.RA if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10 && self.Owner.WinState != WinState.Lost) { - self.World.AddFrameEndTask(w => w.Add( - new Parachute(pilot.Owner, - Util.CenterOfCell(self.CenterLocation.ToCPos()), - aircraft.Altitude, pilot))); + self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, + Util.CenterOfCell(self.CenterLocation.ToCPos()), aircraft.Altitude))); Sound.Play(info.ChuteSound, self.CenterLocation); } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 45772abb15..9fdb71b549 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.Effects; using OpenRA.Graphics; using OpenRA.Traits; @@ -17,8 +18,6 @@ namespace OpenRA.Mods.RA.Effects { public class Parachute : IEffect { - readonly Animation anim; - readonly PaletteReference palette; readonly Animation paraAnim; readonly PPos location; @@ -28,29 +27,19 @@ namespace OpenRA.Mods.RA.Effects float altitude; const float fallRate = .3f; - public Parachute(Player owner, PPos location, int altitude, Actor cargo) + public Parachute(Actor cargo, PPos location, int altitude) { this.location = location; this.altitude = altitude; this.cargo = cargo; - var rs = cargo.Trait(); - var image = rs.anim.Name; - palette = rs.Palette(owner); - - anim = new Animation(image); - if (anim.HasSequence("idle")) - anim.PlayFetchIndex("idle", () => 0); - else - anim.PlayFetchIndex("stand", () => 0); - anim.Tick(); - var pai = cargo.Info.Traits.GetOrDefault(); - paraAnim = new Animation(pai != null ? pai.ParachuteSprite : "parach"); paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle")); if (pai != null) offset = pai.Offset; + + cargo.Trait().SetPxPosition(cargo, location); } public void Tick(World world) @@ -75,10 +64,16 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render(WorldRenderer wr) { + var rc = cargo.Render(wr).Select(a => a.WithPos(a.Pos - new float2(0, altitude)) + .WithZOffset(a.ZOffset + (int)altitude)); + foreach (var c in rc) + { + yield return c.WithPos(location.ToFloat2() - .5f * c.Sprite.size).WithPalette(wr.Palette("shadow")).WithZOffset(0); + yield return c.WithZOffset(2); + } + var pos = location.ToFloat2() - new float2(0, altitude); - yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, wr.Palette("shadow"), 0); - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2); - yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3); + yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, rc.First().Palette, 3); } } } diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 1759c12cab..07788b529a 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -55,11 +55,9 @@ namespace OpenRA.Mods.RA var aircraft = self.Trait(); self.World.AddFrameEndTask(w => w.Add( - new Parachute( - self.Owner, + new Parachute(a, Util.CenterOfCell(self.CenterLocation.ToCPos()), - aircraft.Altitude, a - ) + aircraft.Altitude) )); Sound.Play(info.ChuteSound, self.CenterLocation);