From 4a3d254c0c6a6d126966ceb7574e1b56c4ec0c66 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 16 Feb 2011 12:58:38 +1300 Subject: [PATCH] Start RenderInfantry rework. TODO: fix ra sequences, split Prone/Panicked into RenderInfantry* overrides, integrate idle anims. --- OpenRA.Mods.RA/Render/RenderInfantry.cs | 38 +++++++---- OpenRA.Mods.RA/TakeCover.cs | 58 +++++++---------- mods/cnc/sequences/infantry.yaml | 85 ++++++++++++++++++++++--- 3 files changed, 126 insertions(+), 55 deletions(-) diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index abbd0628ca..2274723fd4 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -24,6 +24,9 @@ namespace OpenRA.Mods.RA.Render public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle { public bool Panicked = false; + public bool Prone = false; + bool wasProne = false; + public enum AnimationState { Idle, @@ -32,12 +35,23 @@ namespace OpenRA.Mods.RA.Render Waiting }; + protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence) + { + var prefix = Prone ? "prone-" : + Panicked ? "panic-" : ""; + + if (anim.HasSequence(prefix + baseSequence)) + return prefix + baseSequence; + else + return baseSequence; + } + public AnimationState State { get; private set; } Mobile mobile; public RenderInfantry(Actor self) : base(self, () => self.Trait().Facing) { - anim.Play("stand"); + anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0); State = AnimationState.Idle; mobile = self.Trait(); } @@ -45,35 +59,35 @@ namespace OpenRA.Mods.RA.Render public void Attacking(Actor self, Target target) { State = AnimationState.Attacking; - if (anim.HasSequence("shoot")) - anim.PlayThen("shoot", () => State = AnimationState.Idle); - else if (anim.HasSequence("heal")) - anim.PlayThen("heal", () => State = AnimationState.Idle); + if (anim.HasSequence(NormalizeInfantrySequence(self, "shoot"))) + anim.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle); + else if (anim.HasSequence(NormalizeInfantrySequence(self, "heal"))) + anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle); } public override void Tick(Actor self) { base.Tick(self); - // If path is blocked, we can have !isMoving and !idle - // Need to handle this case specially - if (!mobile.IsMoving && State == AnimationState.Moving) + if ((State == AnimationState.Moving || wasProne != Prone) && !mobile.IsMoving) { State = AnimationState.Waiting; - anim.Play("stand"); + anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0); } - else if (State != AnimationState.Moving && mobile.IsMoving) + else if ((State != AnimationState.Moving || wasProne != Prone) && mobile.IsMoving) { State = AnimationState.Moving; - anim.PlayRepeating(Panicked ? "panic-run" : "run"); + anim.PlayRepeating(NormalizeInfantrySequence(self, "run")); } + + wasProne = Prone; } public void TickIdle(Actor self) { if (State != AnimationState.Idle) { - anim.Play("stand"); + anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0); State = AnimationState.Idle; } } diff --git a/OpenRA.Mods.RA/TakeCover.cs b/OpenRA.Mods.RA/TakeCover.cs index d38905eabe..29f88506b5 100644 --- a/OpenRA.Mods.RA/TakeCover.cs +++ b/OpenRA.Mods.RA/TakeCover.cs @@ -14,17 +14,25 @@ using OpenRA.Mods.RA.Render; namespace OpenRA.Mods.RA { - class TakeCoverInfo : TraitInfo, ITraitPrerequisite { } + class TakeCoverInfo : ITraitInfo, ITraitPrerequisite + { + public readonly int ProneTime = 100; /* ticks, =4s */ + public readonly float ProneDamage = .5f; + public readonly decimal ProneSpeed = .5m; + public object Create(ActorInitializer init) { return new TakeCover(this); } + } - // infantry prone behavior + // Infantry prone behavior class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync { - const int defaultProneTime = 100; /* ticks, =4s */ - const float proneDamage = .5f; - const decimal proneSpeed = .5m; - + TakeCoverInfo Info; [Sync] int remainingProneTime = 0; + + public TakeCover(TakeCoverInfo info) + { + Info = info; + } public bool IsProne { get { return remainingProneTime > 0; } } @@ -33,7 +41,10 @@ namespace OpenRA.Mods.RA if (e.Damage > 0) /* Don't go prone when healed */ { if (e.Warhead == null || !e.Warhead.PreventProne) - remainingProneTime = defaultProneTime; + { + remainingProneTime = Info.ProneTime; + self.Trait().Prone = true; + } } } @@ -42,41 +53,20 @@ namespace OpenRA.Mods.RA if (!IsProne) return; - remainingProneTime--; - - var ri = self.Trait(); - - // Mobile.IsMoving isn't set to true until after the first move tick - // so we need a hack here to prevent a single frame of stand state - - if (IsProne && (ri.State == RenderInfantry.AnimationState.Idle || - ri.State == RenderInfantry.AnimationState.Waiting || - ri.anim.CurrentSequence.Name == "stand")) - ri.anim.PlayFetchIndex("crawl", () => 0); - else if (!IsProne && (ri.State == RenderInfantry.AnimationState.Idle || - ri.State == RenderInfantry.AnimationState.Waiting || - ri.anim.CurrentSequence.Name == "stand")) - ri.anim.Play("stand"); - - if (ri.anim.CurrentSequence.Name == "run" && IsProne) - ri.anim.ReplaceAnim("crawl"); - else if (ri.anim.CurrentSequence.Name == "crawl" && !IsProne) - ri.anim.ReplaceAnim("run"); - - if (ri.anim.CurrentSequence.Name == "shoot" && IsProne) - ri.anim.ReplaceAnim("prone-shoot"); - else if (ri.anim.CurrentSequence.Name == "prone-shoot" && !IsProne) - ri.anim.ReplaceAnim("shoot"); + //var ri = self.Trait(); + + if (--remainingProneTime <= 0) + self.Trait().Prone = false; } public float GetDamageModifier(Actor attacker, WarheadInfo warhead ) { - return IsProne ? proneDamage : 1f; + return IsProne ? Info.ProneDamage : 1f; } public decimal GetSpeedModifier() { - return IsProne ? proneSpeed : 1m; + return IsProne ? Info.ProneSpeed : 1m; } } } diff --git a/mods/cnc/sequences/infantry.yaml b/mods/cnc/sequences/infantry.yaml index 1cba15114e..24ab47508c 100644 --- a/mods/cnc/sequences/infantry.yaml +++ b/mods/cnc/sequences/infantry.yaml @@ -21,7 +21,11 @@ e1: Start: 64 Length: 8 Facings: 8 - crawl: + prone-stand: + Start: 144 + Length: 4 + Facings: 8 + prone-run: Start: 144 Length: 4 Facings: 8 @@ -116,7 +120,11 @@ e2: Start: 272 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 240 + Length: 4 + Facings: 8 + prone-run: Start: 240 Length: 4 Facings: 8 @@ -192,7 +200,11 @@ e3: Start: 176 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 144 + Length: 4 + Facings: 8 + prone-run: Start: 144 Length: 4 Facings: 8 @@ -268,7 +280,11 @@ e4: Start: 240 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 208 + Length: 4 + Facings: 8 + prone-run: Start: 208 Length: 4 Facings: 8 @@ -349,7 +365,11 @@ e5: Start: 240 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 208 + Length: 4 + Facings: 8 + prone-run: Start: 208 Length: 4 Facings: 8 @@ -426,7 +446,11 @@ e6: Start: 114 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 82 + Length: 4 + Facings: 8 + prone-run: Start: 82 Length: 4 Facings: 8 @@ -500,7 +524,11 @@ rmbo: Start: 144 Length: 2 Facings: 8 - crawl: + prone-stand: + Start: 112 + Length: 4 + Facings: 8 + prone-run: Start: 112 Length: 4 Facings: 8 @@ -556,11 +584,14 @@ rmbo: Length: 4 Tick: 80 - c1: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -606,6 +637,10 @@ c2: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -652,6 +687,10 @@ c3: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -698,6 +737,10 @@ c4: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -744,6 +787,10 @@ c5: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -790,7 +837,11 @@ c6: stand: Start: 0 Facings: 8 - crawl: + panic-stand: + Start: 8 + Length: 6 + Facings: 8 + prone-run: Start: 8 Length: 6 Facings: 8 @@ -836,6 +887,10 @@ c7: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -882,6 +937,10 @@ c8: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -928,6 +987,10 @@ c9: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6 @@ -974,6 +1037,10 @@ c10: stand: Start: 0 Facings: 8 + panic-stand: + Start: 8 + Length: 6 + Facings: 8 panic-run: Start: 8 Length: 6