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:
reaperrr
2019-10-17 18:12:25 +02:00
committed by abcdefg30
parent 9474bdba5c
commit 595b6c8923

View File

@@ -55,6 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
readonly IMove move;
protected readonly Animation DefaultAnimation;
readonly bool hasIdleSequence;
bool dirty;
string idleSequence;
@@ -74,6 +75,7 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation = new Animation(init.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
PlayStandAnimation(self);
hasIdleSequence = Info.IdleSequences.Length > 0;
move = init.Self.Trait<IMove>();
}
@@ -110,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits.Render
protected virtual bool AllowIdleAnimation(Actor self)
{
return !IsModifyingSequence;
return hasIdleSequence && !IsModifyingSequence;
}
public void Attacking(Actor self, Target target, Armament a)
@@ -162,29 +164,19 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyIdle.TickIdle(Actor self)
{
if (state != AnimationState.Idle && state != AnimationState.IdleAnimating && state != AnimationState.Attacking)
{
PlayStandAnimation(self);
state = AnimationState.Idle;
if (!AllowIdleAnimation(self))
return;
if (Info.IdleSequences.Length > 0)
{
idleSequence = Info.IdleSequences.Random(self.World.SharedRandom);
idleDelay = self.World.SharedRandom.Next(Info.MinIdleDelay, Info.MaxIdleDelay);
}
}
else if (AllowIdleAnimation(self))
if (state == AnimationState.Waiting)
{
if (idleSequence != null && DefaultAnimation.HasSequence(idleSequence))
{
if (idleDelay > 0 && --idleDelay == 0)
{
state = AnimationState.IdleAnimating;
DefaultAnimation.PlayThen(idleSequence, () => PlayStandAnimation(self));
}
}
else
PlayStandAnimation(self);
state = AnimationState.Idle;
idleSequence = Info.IdleSequences.Random(self.World.SharedRandom);
idleDelay = self.World.SharedRandom.Next(Info.MinIdleDelay, Info.MaxIdleDelay);
}
else if (state == AnimationState.Idle && idleDelay > 0 && --idleDelay == 0)
{
state = AnimationState.IdleAnimating;
DefaultAnimation.PlayThen(idleSequence, () => PlayStandAnimation(self));
}
}