Files
OpenRA/OpenRA.Mods.RA/IdleAnimation.cs
2010-11-30 12:51:25 +13:00

72 lines
1.5 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA
{
class IdleAnimationInfo : ITraitInfo, ITraitPrerequisite<RenderInfantryInfo>
{
public readonly int IdleWaitTicks = 50;
public readonly string[] Animations = {};
public object Create(ActorInitializer init) { return new IdleAnimation(this); }
}
// infantry prone behavior
class IdleAnimation : ITick, INotifyIdle
{
enum IdleState
{
None,
Waiting,
Active
};
IdleAnimationInfo Info;
string sequence;
int delay;
IdleState state;
public IdleAnimation(IdleAnimationInfo info)
{
Info = info;
}
public void Tick(Actor self)
{
if (!self.IsIdle)
{
state = IdleState.None;
return;
}
if (state == IdleState.Active)
return;
else if (delay > 0 && --delay == 0)
{
state = IdleState.Active;
self.Trait<RenderInfantry>().anim.PlayThen(sequence, () => state = IdleState.None);
}
}
public void TickIdle(Actor self)
{
if (state != IdleState.None)
return;
state = IdleState.Waiting;
sequence = Info.Animations.Random(self.World.SharedRandom);
delay = Info.IdleWaitTicks;
}
}
}