Greatly simplified WithInfantryBody TickIdle code
There was a lot of redundancy and unnecessary complexity in several checks. This now also prevents infantry from randomly restarting and potentially switching between stand sequences if there are no idle sequences. Old behavior can still be replicated by listing stand sequences as IdleSequences.
This commit is contained in:
@@ -55,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
{
|
{
|
||||||
readonly IMove move;
|
readonly IMove move;
|
||||||
protected readonly Animation DefaultAnimation;
|
protected readonly Animation DefaultAnimation;
|
||||||
|
readonly bool hasIdleSequence;
|
||||||
|
|
||||||
bool dirty;
|
bool dirty;
|
||||||
string idleSequence;
|
string idleSequence;
|
||||||
@@ -74,6 +75,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
|
DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
|
||||||
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
|
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
|
||||||
PlayStandAnimation(self);
|
PlayStandAnimation(self);
|
||||||
|
hasIdleSequence = Info.IdleSequences.Length > 0;
|
||||||
|
|
||||||
move = init.Self.Trait<IMove>();
|
move = init.Self.Trait<IMove>();
|
||||||
}
|
}
|
||||||
@@ -110,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
protected virtual bool AllowIdleAnimation(Actor self)
|
protected virtual bool AllowIdleAnimation(Actor self)
|
||||||
{
|
{
|
||||||
return !IsModifyingSequence;
|
return hasIdleSequence && !IsModifyingSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target, Armament a)
|
public void Attacking(Actor self, Target target, Armament a)
|
||||||
@@ -162,29 +164,19 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
void INotifyIdle.TickIdle(Actor self)
|
void INotifyIdle.TickIdle(Actor self)
|
||||||
{
|
{
|
||||||
if (state != AnimationState.Idle && state != AnimationState.IdleAnimating && state != AnimationState.Attacking)
|
if (!AllowIdleAnimation(self))
|
||||||
{
|
return;
|
||||||
PlayStandAnimation(self);
|
|
||||||
state = AnimationState.Idle;
|
|
||||||
|
|
||||||
if (Info.IdleSequences.Length > 0)
|
if (state == AnimationState.Waiting)
|
||||||
{
|
|
||||||
idleSequence = Info.IdleSequences.Random(self.World.SharedRandom);
|
|
||||||
idleDelay = self.World.SharedRandom.Next(Info.MinIdleDelay, Info.MaxIdleDelay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (AllowIdleAnimation(self))
|
|
||||||
{
|
{
|
||||||
if (idleSequence != null && DefaultAnimation.HasSequence(idleSequence))
|
state = AnimationState.Idle;
|
||||||
{
|
idleSequence = Info.IdleSequences.Random(self.World.SharedRandom);
|
||||||
if (idleDelay > 0 && --idleDelay == 0)
|
idleDelay = self.World.SharedRandom.Next(Info.MinIdleDelay, Info.MaxIdleDelay);
|
||||||
{
|
}
|
||||||
state = AnimationState.IdleAnimating;
|
else if (state == AnimationState.Idle && idleDelay > 0 && --idleDelay == 0)
|
||||||
DefaultAnimation.PlayThen(idleSequence, () => PlayStandAnimation(self));
|
{
|
||||||
}
|
state = AnimationState.IdleAnimating;
|
||||||
}
|
DefaultAnimation.PlayThen(idleSequence, () => PlayStandAnimation(self));
|
||||||
else
|
|
||||||
PlayStandAnimation(self);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user