From 17e23a7adc0669852105708c4625683792ecc025 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Fri, 22 Jan 2016 11:02:38 +0100 Subject: [PATCH] Add support for a FallbackSequence in WithDeathAnimation Used when the actor is killed by non-standard means, like suicide. --- .../Traits/Render/WithDeathAnimation.cs | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs index de39214c40..9298f1bd85 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs @@ -45,6 +45,9 @@ namespace OpenRA.Mods.Common.Traits "Is only used if UseDeathTypeSuffix is `True`.")] public readonly Dictionary DeathTypes = new Dictionary(); + [Desc("Sequence to use when the actor is killed by some non-standard means (e.g. suicide).")] + [SequenceReference] public readonly string FallbackSequence = null; + public static object LoadDeathTypes(MiniYaml yaml) { var md = yaml.ToDictionary(); @@ -57,10 +60,11 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); } } - public class WithDeathAnimation : INotifyKilled + public class WithDeathAnimation : INotifyKilled, INotifyCrushed { public readonly WithDeathAnimationInfo Info; readonly RenderSprites rs; + bool crushed; public WithDeathAnimation(Actor self, WithDeathAnimationInfo info) { @@ -70,11 +74,23 @@ namespace OpenRA.Mods.Common.Traits public void Killed(Actor self, AttackInfo e) { - // Killed by some non-standard means. This includes being crushed - // by a vehicle (Actors with Crushable trait will spawn CrushedSequence instead). - if (e.Warhead == null || !(e.Warhead is DamageWarhead)) + // Actors with Crushable trait will spawn CrushedSequence. + if (crushed) return; + var palette = Info.DeathSequencePalette; + if (Info.DeathPaletteIsPlayerPalette) + palette += self.Owner.InternalName; + + // Killed by some non-standard means + if (e.Warhead == null || !(e.Warhead is DamageWarhead)) + { + if (Info.FallbackSequence != null) + SpawnDeathAnimation(self, Info.FallbackSequence, palette); + + return; + } + var sequence = Info.DeathSequence; if (Info.UseDeathTypeSuffix) { @@ -86,10 +102,6 @@ namespace OpenRA.Mods.Common.Traits sequence += Info.DeathTypes[damageType]; } - var palette = Info.DeathSequencePalette; - if (Info.DeathPaletteIsPlayerPalette) - palette += self.Owner.InternalName; - SpawnDeathAnimation(self, sequence, palette); } @@ -101,5 +113,12 @@ namespace OpenRA.Mods.Common.Traits w.Add(new Corpse(w, self.CenterPosition, rs.GetImage(self), sequence, palette)); }); } + + void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet crushClasses) + { + crushed = true; + } + + void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet crushClasses) { } } }