Add support for a FallbackSequence in WithDeathAnimation

Used when the actor is killed by non-standard means, like suicide.
This commit is contained in:
abcdefg30
2016-01-22 11:02:38 +01:00
parent f21d1f52e7
commit 17e23a7adc

View File

@@ -45,6 +45,9 @@ namespace OpenRA.Mods.Common.Traits
"Is only used if UseDeathTypeSuffix is `True`.")]
public readonly Dictionary<string, int> DeathTypes = new Dictionary<string, int>();
[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<string> crushClasses)
{
crushed = true;
}
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, HashSet<string> crushClasses) { }
}
}