Merge pull request #6396 from reaperrr/with-deathanim

Added WithDeathAnimation
This commit is contained in:
Paul Chote
2014-09-14 10:37:07 +12:00
18 changed files with 369 additions and 202 deletions

View File

@@ -0,0 +1,74 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
[Desc("This actor is crushable.")]
class CrushableInfo : ITraitInfo
{
[Desc("Sound to play when being crushed.")]
public readonly string CrushSound = null;
[Desc("Which crush classes does this actor belong to.")]
public readonly string[] CrushClasses = { "infantry" };
[Desc("Probability of mobile actors noticing and evading a crush attempt.")]
public readonly int WarnProbability = 75;
[Desc("Will friendly units just crush me instead of pathing around.")]
public readonly bool CrushedByFriendlies = false;
public object Create(ActorInitializer init) { return new Crushable(init.self, this); }
}
class Crushable : ICrushable
{
readonly Actor self;
readonly CrushableInfo info;
public Crushable(Actor self, CrushableInfo info)
{
this.self = self;
this.info = info;
}
public void WarnCrush(Actor crusher)
{
var mobile = self.TraitOrDefault<Mobile>();
if (mobile != null && self.World.SharedRandom.Next(100) <= info.WarnProbability)
mobile.Nudge(self, crusher, true);
}
public void OnCrush(Actor crusher)
{
Sound.Play(info.CrushSound, crusher.CenterPosition);
var wda = self.TraitOrDefault<WithDeathAnimation>();
if (wda != null)
{
var palette = wda.Info.DeathSequencePalette;
if (wda.Info.DeathPaletteIsPlayerPalette)
palette += self.Owner.InternalName;
wda.SpawnDeathAnimation(self, wda.Info.CrushedSequence, palette);
}
self.Kill(crusher);
}
public bool CrushableBy(string[] crushClasses, Player crushOwner)
{
if (!info.CrushedByFriendlies && crushOwner.IsAlliedWith(self.Owner))
return false;
return info.CrushClasses.Intersect(crushClasses).Any();
}
}
}

View File

@@ -1,61 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class CrushableInfantryInfo : ITraitInfo, Requires<MobileInfo>, Requires<RenderInfantryInfo>
{
public readonly string CrushSound = null;
public readonly string CorpseSequence = "die-crushed";
public readonly string[] CrushClasses = { "infantry" };
public readonly int WarnProbability = 75;
public object Create(ActorInitializer init) { return new CrushableInfantry(init.self, this); }
}
class CrushableInfantry : ICrushable
{
readonly Actor self;
readonly CrushableInfantryInfo Info;
readonly RenderInfantry ri;
public CrushableInfantry(Actor self, CrushableInfantryInfo info)
{
this.self = self;
this.Info = info;
ri = self.Trait<RenderInfantry>();
}
public void WarnCrush(Actor crusher)
{
if (self.World.SharedRandom.Next(100) <= Info.WarnProbability)
self.Trait<Mobile>().Nudge(self, crusher, true);
}
public void OnCrush(Actor crusher)
{
Sound.Play(Info.CrushSound, crusher.CenterPosition);
ri.SpawnCorpse(self, Info.CorpseSequence);
self.Kill(crusher);
}
public bool CrushableBy(string[] crushClasses, Player crushOwner)
{
if (crushOwner.Stances[self.Owner] == Stance.Ally)
return false;
return Info.CrushClasses.Intersect(crushClasses).Any();
}
}
}

View File

@@ -209,7 +209,7 @@
<Compile Include="Crates\RevealMapCrateAction.cs" />
<Compile Include="Crates\SupportPowerCrateAction.cs" />
<Compile Include="CreateMPPlayers.cs" />
<Compile Include="CrushableInfantry.cs" />
<Compile Include="Crushable.cs" />
<Compile Include="DeathSounds.cs" />
<Compile Include="DemoTruck.cs" />
<Compile Include="DetectCloaked.cs" />
@@ -331,6 +331,7 @@
<Compile Include="Render\RenderUnit.cs" />
<Compile Include="Render\RenderUnitReload.cs" />
<Compile Include="Render\WithBuildingExplosion.cs" />
<Compile Include="Render\WithDeathAnimation.cs" />
<Compile Include="Render\WithMuzzleFlash.cs" />
<Compile Include="Render\RenderNameTag.cs" />
<Compile Include="Render\WithRotor.cs" />

View File

@@ -21,10 +21,8 @@ namespace OpenRA.Mods.RA.Render
{
public readonly int MinIdleWaitTicks = 30;
public readonly int MaxIdleWaitTicks = 110;
public readonly bool SpawnsCorpse = true;
public readonly string MoveAnimation = "run";
public readonly string AttackAnimation = "shoot";
public readonly string DeathAnimationPrefix = "die";
public readonly string[] IdleAnimations = { };
public readonly string[] StandAnimations = { "stand" };
@@ -48,7 +46,7 @@ namespace OpenRA.Mods.RA.Render
}
}
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyKilled, INotifyIdle
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyIdle
{
readonly RenderInfantryInfo info;
readonly IMove move;
@@ -151,29 +149,6 @@ namespace OpenRA.Mods.RA.Render
}
}
// TODO: Possibly move this into a separate trait
public void Killed(Actor self, AttackInfo e)
{
// Killed by some non-standard means
if (e.Warhead == null)
return;
if (info.SpawnsCorpse)
{
SpawnCorpse(self, info.DeathAnimationPrefix + (e.Warhead.DeathType));
}
}
public void SpawnCorpse(Actor self, string sequence)
{
self.World.AddFrameEndTask(w =>
{
if (!self.Destroyed)
w.Add(new Corpse(w, self.CenterPosition, GetImage(self),
sequence, info.PlayerPalette + self.Owner.InternalName));
});
}
enum AnimationState
{
Idle,

View File

@@ -0,0 +1,75 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
[Desc("This actor has a death animation.")]
public class WithDeathAnimationInfo : ITraitInfo, Requires<RenderSimpleInfo>
{
[Desc("Sequence to play when this actor is killed by a warhead.")]
public readonly string DeathSequence = "die";
public readonly string DeathSequencePalette = "player";
[Desc("Custom death animation palette is a player palette BaseName")]
public readonly bool DeathPaletteIsPlayerPalette = true;
[Desc("Should DeathType-specific sequences be used (sequence name = DeathSequence + DeathType).")]
public readonly bool UseDeathTypeSuffix = true;
[Desc("Sequence to play when this actor is crushed.")]
public readonly string CrushedSequence = "die-crushed";
public readonly string CrushedSequencePalette = "effect";
[Desc("Custom crushed animation palette is a player palette BaseName")]
public readonly bool CrushedPaletteIsPlayerPalette = false;
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.self, this); }
}
public class WithDeathAnimation : INotifyKilled
{
public readonly WithDeathAnimationInfo Info;
readonly RenderSimple renderSimple;
public WithDeathAnimation(Actor self, WithDeathAnimationInfo info)
{
Info = info;
renderSimple = self.Trait<RenderSimple>();
}
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)
return;
var sequence = Info.DeathSequence;
if (Info.UseDeathTypeSuffix)
sequence += e.Warhead.DeathType;
var palette = Info.DeathSequencePalette;
if (Info.DeathPaletteIsPlayerPalette)
palette += self.Owner.InternalName;
SpawnDeathAnimation(self, sequence, palette);
}
public void SpawnDeathAnimation(Actor self, string sequence, string palette)
{
self.World.AddFrameEndTask(w =>
{
if (!self.Destroyed)
w.Add(new Corpse(w, self.CenterPosition, renderSimple.GetImage(self), sequence, palette));
});
}
}
}