From 595b6c8923d432a0b1f10cf8a0c60cae219a532f Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 17 Oct 2019 18:12:25 +0200 Subject: [PATCH] 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. --- .../Traits/Render/WithInfantryBody.cs | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) 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)); } }