Move IdleAnimation into RenderInfantry
This commit is contained in:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -293,7 +293,6 @@
|
|||||||
<Compile Include="HackyAI.cs" />
|
<Compile Include="HackyAI.cs" />
|
||||||
<Compile Include="RALoadScreen.cs" />
|
<Compile Include="RALoadScreen.cs" />
|
||||||
<Compile Include="NullLoadScreen.cs" />
|
<Compile Include="NullLoadScreen.cs" />
|
||||||
<Compile Include="IdleAnimation.cs" />
|
|
||||||
<Compile Include="World\GotoNextBase.cs" />
|
<Compile Include="World\GotoNextBase.cs" />
|
||||||
<Compile Include="World\SmudgeLayer.cs" />
|
<Compile Include="World\SmudgeLayer.cs" />
|
||||||
<Compile Include="Scripting\Media.cs" />
|
<Compile Include="Scripting\Media.cs" />
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
public class RenderInfantryInfo : RenderSimpleInfo
|
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 class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle
|
||||||
{
|
{
|
||||||
public bool Panicked = false;
|
|
||||||
public bool Prone = false;
|
|
||||||
bool wasProne = false;
|
|
||||||
|
|
||||||
public enum AnimationState
|
public enum AnimationState
|
||||||
{
|
{
|
||||||
Idle,
|
Idle,
|
||||||
@@ -35,6 +35,22 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
Waiting
|
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)
|
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
|
||||||
{
|
{
|
||||||
var prefix = Prone ? "prone-" :
|
var prefix = Prone ? "prone-" :
|
||||||
@@ -48,9 +64,10 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
|
|
||||||
public AnimationState State { get; private set; }
|
public AnimationState State { get; private set; }
|
||||||
Mobile mobile;
|
Mobile mobile;
|
||||||
public RenderInfantry(Actor self)
|
public RenderInfantry(Actor self, RenderInfantryInfo info)
|
||||||
: base(self, () => self.Trait<IFacing>().Facing)
|
: base(self, () => self.Trait<IFacing>().Facing)
|
||||||
{
|
{
|
||||||
|
Info = info;
|
||||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||||
State = AnimationState.Idle;
|
State = AnimationState.Idle;
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
@@ -81,6 +98,32 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
}
|
}
|
||||||
|
|
||||||
wasProne = Prone;
|
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)
|
public void TickIdle(Actor self)
|
||||||
@@ -90,8 +133,14 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||||
State = AnimationState.Idle;
|
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)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
class RenderSpyInfo : RenderInfantryInfo
|
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
|
class RenderSpy : RenderInfantry, IRenderModifier, IIssueOrder, IResolveOrder, IOrderVoice
|
||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
Player disguisedAsPlayer;
|
Player disguisedAsPlayer;
|
||||||
string disguisedAsSprite;
|
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)
|
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ E1:
|
|||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
PrimaryWeapon: M16
|
PrimaryWeapon: M16
|
||||||
TakeCover:
|
TakeCover:
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2,idle3,idle4
|
IdleAnimations: idle1,idle2,idle3,idle4
|
||||||
E2:
|
E2:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
Valued:
|
Valued:
|
||||||
@@ -43,8 +43,8 @@ E2:
|
|||||||
PrimaryOffset: 0,0,0,-10
|
PrimaryOffset: 0,0,0,-10
|
||||||
FireDelay: 15
|
FireDelay: 15
|
||||||
TakeCover:
|
TakeCover:
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2
|
IdleAnimations: idle1,idle2
|
||||||
|
|
||||||
E3:
|
E3:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -68,8 +68,8 @@ E3:
|
|||||||
PrimaryOffset: 0,0,0,-10
|
PrimaryOffset: 0,0,0,-10
|
||||||
FireDelay: 5
|
FireDelay: 5
|
||||||
TakeCover:
|
TakeCover:
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2
|
IdleAnimations: idle1,idle2
|
||||||
|
|
||||||
E4:
|
E4:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -94,11 +94,9 @@ E4:
|
|||||||
PrimaryOffset: 0,0,0,-5
|
PrimaryOffset: 0,0,0,-5
|
||||||
FireDelay: 3
|
FireDelay: 3
|
||||||
TakeCover:
|
TakeCover:
|
||||||
-RenderInfantry:
|
|
||||||
RenderInfantry:
|
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash:
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2
|
IdleAnimations: idle1,idle2
|
||||||
|
|
||||||
E5:
|
E5:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -123,12 +121,10 @@ E5:
|
|||||||
PrimaryOffset: 0,0,0,-5
|
PrimaryOffset: 0,0,0,-5
|
||||||
FireDelay: 3
|
FireDelay: 3
|
||||||
TakeCover:
|
TakeCover:
|
||||||
-RenderInfantry:
|
|
||||||
RenderInfantry:
|
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash:
|
||||||
-PoisonedByTiberium:
|
-PoisonedByTiberium:
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2
|
IdleAnimations: idle1,idle2
|
||||||
|
|
||||||
E6:
|
E6:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -155,8 +151,8 @@ E6:
|
|||||||
-AutoTarget:
|
-AutoTarget:
|
||||||
AttackMove:
|
AttackMove:
|
||||||
JustMove: true
|
JustMove: true
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2
|
IdleAnimations: idle1,idle2
|
||||||
|
|
||||||
RMBO:
|
RMBO:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -184,8 +180,8 @@ RMBO:
|
|||||||
C4Delay: .03
|
C4Delay: .03
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
PrimaryWeapon: Sniper
|
PrimaryWeapon: Sniper
|
||||||
IdleAnimation:
|
RenderInfantry:
|
||||||
Animations: idle1,idle2,idle3
|
IdleAnimations: idle1,idle2,idle3
|
||||||
|
|
||||||
VICE:
|
VICE:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
|
|||||||
Reference in New Issue
Block a user