diff --git a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs index 4246ea5e87..28967beefd 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs @@ -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(); } @@ -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)); } }