Move IdleAnimation into RenderInfantry

This commit is contained in:
Paul Chote
2011-02-17 20:15:20 +13:00
parent 4a3d254c0c
commit 9a04a7fa9f
5 changed files with 72 additions and 111 deletions

View File

@@ -1,83 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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 OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class IdleAnimationInfo : ITraitInfo, ITraitPrerequisite<RenderInfantryInfo>
{
public readonly int MinIdleWaitTicks = 30;
public readonly int MaxIdleWaitTicks = 110;
public readonly string[] Animations = {};
public object Create(ActorInitializer init) { return new IdleAnimation(this); }
}
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;
var ri = self.TraitOrDefault<RenderInfantry>();
if (ri.anim.HasSequence(sequence))
{
ri.anim.PlayThen(sequence,
() =>
{
state = IdleState.None;
ri.anim.PlayRepeating("stand");
});
}
else
state = IdleState.None;
}
}
public void TickIdle(Actor self)
{
if (state != IdleState.None)
return;
state = IdleState.Waiting;
sequence = Info.Animations.Random(self.World.SharedRandom);
delay = self.World.SharedRandom.Next(Info.MinIdleWaitTicks, Info.MaxIdleWaitTicks);
}
}
}

View File

@@ -293,7 +293,6 @@
<Compile Include="HackyAI.cs" />
<Compile Include="RALoadScreen.cs" />
<Compile Include="NullLoadScreen.cs" />
<Compile Include="IdleAnimation.cs" />
<Compile Include="World\GotoNextBase.cs" />
<Compile Include="World\SmudgeLayer.cs" />
<Compile Include="Scripting\Media.cs" />

View File

@@ -18,15 +18,15 @@ namespace OpenRA.Mods.RA.Render
{
public class RenderInfantryInfo : RenderSimpleInfo
{
public override object Create(ActorInitializer init) { return new RenderInfantry(init.self); }
public readonly int MinIdleWaitTicks = 30;
public readonly int MaxIdleWaitTicks = 110;
public readonly string[] IdleAnimations = {};
public override object Create(ActorInitializer init) { return new RenderInfantry(init.self, this); }
}
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle
{
public bool Panicked = false;
public bool Prone = false;
bool wasProne = false;
public enum AnimationState
{
Idle,
@@ -35,6 +35,22 @@ namespace OpenRA.Mods.RA.Render
Waiting
};
enum IdleState
{
None,
Waiting,
Active
};
public bool Panicked = false;
public bool Prone = false;
bool wasProne = false;
RenderInfantryInfo Info;
string idleSequence;
int idleDelay;
IdleState idleState;
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
{
var prefix = Prone ? "prone-" :
@@ -48,9 +64,10 @@ namespace OpenRA.Mods.RA.Render
public AnimationState State { get; private set; }
Mobile mobile;
public RenderInfantry(Actor self)
public RenderInfantry(Actor self, RenderInfantryInfo info)
: base(self, () => self.Trait<IFacing>().Facing)
{
Info = info;
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
State = AnimationState.Idle;
mobile = self.Trait<Mobile>();
@@ -81,6 +98,32 @@ namespace OpenRA.Mods.RA.Render
}
wasProne = Prone;
if (!self.IsIdle)
{
idleState = IdleState.None;
return;
}
if (idleState == IdleState.Active)
return;
else if (idleDelay > 0 && --idleDelay == 0)
{
idleState = IdleState.Active;
if (anim.HasSequence(idleSequence))
{
anim.PlayThen(idleSequence,
() =>
{
idleState = IdleState.None;
anim.PlayRepeating(NormalizeInfantrySequence(self, "stand"));
});
}
else
idleState = IdleState.None;
}
}
public void TickIdle(Actor self)
@@ -90,8 +133,14 @@ namespace OpenRA.Mods.RA.Render
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
State = AnimationState.Idle;
}
if (idleState != IdleState.None || Info.IdleAnimations.Length == 0)
return;
idleState = IdleState.Waiting;
idleSequence = Info.IdleAnimations.Random(self.World.SharedRandom);
idleDelay = self.World.SharedRandom.Next(Info.MinIdleWaitTicks, Info.MaxIdleWaitTicks);
}
public void Damaged(Actor self, AttackInfo e)
{

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Render
{
class RenderSpyInfo : RenderInfantryInfo
{
public override object Create(ActorInitializer init) { return new RenderSpy(init.self); }
public override object Create(ActorInitializer init) { return new RenderSpy(init.self, this); }
}
class RenderSpy : RenderInfantry, IRenderModifier, IIssueOrder, IResolveOrder, IOrderVoice
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Render
Player disguisedAsPlayer;
string disguisedAsSprite;
public RenderSpy(Actor self) : base(self) { }
public RenderSpy(Actor self, RenderInfantryInfo info) : base(self, info) { }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{

View File

@@ -18,8 +18,8 @@ E1:
AttackFrontal:
PrimaryWeapon: M16
TakeCover:
IdleAnimation:
Animations: idle1,idle2,idle3,idle4
RenderInfantry:
IdleAnimations: idle1,idle2,idle3,idle4
E2:
Inherits: ^Infantry
Valued:
@@ -43,8 +43,8 @@ E2:
PrimaryOffset: 0,0,0,-10
FireDelay: 15
TakeCover:
IdleAnimation:
Animations: idle1,idle2
RenderInfantry:
IdleAnimations: idle1,idle2
E3:
Inherits: ^Infantry
@@ -68,8 +68,8 @@ E3:
PrimaryOffset: 0,0,0,-10
FireDelay: 5
TakeCover:
IdleAnimation:
Animations: idle1,idle2
RenderInfantry:
IdleAnimations: idle1,idle2
E4:
Inherits: ^Infantry
@@ -94,11 +94,9 @@ E4:
PrimaryOffset: 0,0,0,-5
FireDelay: 3
TakeCover:
-RenderInfantry:
RenderInfantry:
WithMuzzleFlash:
IdleAnimation:
Animations: idle1,idle2
RenderInfantry:
IdleAnimations: idle1,idle2
E5:
Inherits: ^Infantry
@@ -123,12 +121,10 @@ E5:
PrimaryOffset: 0,0,0,-5
FireDelay: 3
TakeCover:
-RenderInfantry:
RenderInfantry:
WithMuzzleFlash:
-PoisonedByTiberium:
IdleAnimation:
Animations: idle1,idle2
RenderInfantry:
IdleAnimations: idle1,idle2
E6:
Inherits: ^Infantry
@@ -155,8 +151,8 @@ E6:
-AutoTarget:
AttackMove:
JustMove: true
IdleAnimation:
Animations: idle1,idle2
RenderInfantry:
IdleAnimations: idle1,idle2
RMBO:
Inherits: ^Infantry
@@ -184,8 +180,8 @@ RMBO:
C4Delay: .03
AttackFrontal:
PrimaryWeapon: Sniper
IdleAnimation:
Animations: idle1,idle2,idle3
RenderInfantry:
IdleAnimations: idle1,idle2,idle3
VICE:
Inherits: ^Infantry