Start RenderInfantry rework. TODO: fix ra sequences, split Prone/Panicked into RenderInfantry* overrides, integrate idle anims.

This commit is contained in:
Paul Chote
2011-02-16 12:58:38 +13:00
parent 437caf9c12
commit 4a3d254c0c
3 changed files with 126 additions and 55 deletions

View File

@@ -24,6 +24,9 @@ namespace OpenRA.Mods.RA.Render
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle
{ {
public bool Panicked = false; public bool Panicked = false;
public bool Prone = false;
bool wasProne = false;
public enum AnimationState public enum AnimationState
{ {
Idle, Idle,
@@ -32,12 +35,23 @@ namespace OpenRA.Mods.RA.Render
Waiting 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; } public AnimationState State { get; private set; }
Mobile mobile; Mobile mobile;
public RenderInfantry(Actor self) public RenderInfantry(Actor self)
: base(self, () => self.Trait<IFacing>().Facing) : base(self, () => self.Trait<IFacing>().Facing)
{ {
anim.Play("stand"); anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
State = AnimationState.Idle; State = AnimationState.Idle;
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
} }
@@ -45,35 +59,35 @@ namespace OpenRA.Mods.RA.Render
public void Attacking(Actor self, Target target) public void Attacking(Actor self, Target target)
{ {
State = AnimationState.Attacking; State = AnimationState.Attacking;
if (anim.HasSequence("shoot")) if (anim.HasSequence(NormalizeInfantrySequence(self, "shoot")))
anim.PlayThen("shoot", () => State = AnimationState.Idle); anim.PlayThen(NormalizeInfantrySequence(self, "shoot"), () => State = AnimationState.Idle);
else if (anim.HasSequence("heal")) else if (anim.HasSequence(NormalizeInfantrySequence(self, "heal")))
anim.PlayThen("heal", () => State = AnimationState.Idle); anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle);
} }
public override void Tick(Actor self) public override void Tick(Actor self)
{ {
base.Tick(self); base.Tick(self);
// If path is blocked, we can have !isMoving and !idle if ((State == AnimationState.Moving || wasProne != Prone) && !mobile.IsMoving)
// Need to handle this case specially
if (!mobile.IsMoving && State == AnimationState.Moving)
{ {
State = AnimationState.Waiting; 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; State = AnimationState.Moving;
anim.PlayRepeating(Panicked ? "panic-run" : "run"); anim.PlayRepeating(NormalizeInfantrySequence(self, "run"));
} }
wasProne = Prone;
} }
public void TickIdle(Actor self) public void TickIdle(Actor self)
{ {
if (State != AnimationState.Idle) if (State != AnimationState.Idle)
{ {
anim.Play("stand"); anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
State = AnimationState.Idle; State = AnimationState.Idle;
} }
} }

View File

@@ -14,17 +14,25 @@ using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class TakeCoverInfo : TraitInfo<TakeCover>, ITraitPrerequisite<RenderInfantryInfo> { } class TakeCoverInfo : ITraitInfo, ITraitPrerequisite<RenderInfantryInfo>
{
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 class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync
{ {
const int defaultProneTime = 100; /* ticks, =4s */ TakeCoverInfo Info;
const float proneDamage = .5f;
const decimal proneSpeed = .5m;
[Sync] [Sync]
int remainingProneTime = 0; int remainingProneTime = 0;
public TakeCover(TakeCoverInfo info)
{
Info = info;
}
public bool IsProne { get { return remainingProneTime > 0; } } 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.Damage > 0) /* Don't go prone when healed */
{ {
if (e.Warhead == null || !e.Warhead.PreventProne) if (e.Warhead == null || !e.Warhead.PreventProne)
remainingProneTime = defaultProneTime; {
remainingProneTime = Info.ProneTime;
self.Trait<RenderInfantry>().Prone = true;
}
} }
} }
@@ -42,41 +53,20 @@ namespace OpenRA.Mods.RA
if (!IsProne) if (!IsProne)
return; return;
remainingProneTime--; //var ri = self.Trait<RenderInfantry>();
var ri = self.Trait<RenderInfantry>(); if (--remainingProneTime <= 0)
self.Trait<RenderInfantry>().Prone = false;
// 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");
} }
public float GetDamageModifier(Actor attacker, WarheadInfo warhead ) public float GetDamageModifier(Actor attacker, WarheadInfo warhead )
{ {
return IsProne ? proneDamage : 1f; return IsProne ? Info.ProneDamage : 1f;
} }
public decimal GetSpeedModifier() public decimal GetSpeedModifier()
{ {
return IsProne ? proneSpeed : 1m; return IsProne ? Info.ProneSpeed : 1m;
} }
} }
} }

View File

@@ -21,7 +21,11 @@ e1:
Start: 64 Start: 64
Length: 8 Length: 8
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 144
Length: 4
Facings: 8
prone-run:
Start: 144 Start: 144
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -116,7 +120,11 @@ e2:
Start: 272 Start: 272
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 240
Length: 4
Facings: 8
prone-run:
Start: 240 Start: 240
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -192,7 +200,11 @@ e3:
Start: 176 Start: 176
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 144
Length: 4
Facings: 8
prone-run:
Start: 144 Start: 144
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -268,7 +280,11 @@ e4:
Start: 240 Start: 240
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 208
Length: 4
Facings: 8
prone-run:
Start: 208 Start: 208
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -349,7 +365,11 @@ e5:
Start: 240 Start: 240
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 208
Length: 4
Facings: 8
prone-run:
Start: 208 Start: 208
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -426,7 +446,11 @@ e6:
Start: 114 Start: 114
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 82
Length: 4
Facings: 8
prone-run:
Start: 82 Start: 82
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -500,7 +524,11 @@ rmbo:
Start: 144 Start: 144
Length: 2 Length: 2
Facings: 8 Facings: 8
crawl: prone-stand:
Start: 112
Length: 4
Facings: 8
prone-run:
Start: 112 Start: 112
Length: 4 Length: 4
Facings: 8 Facings: 8
@@ -556,11 +584,14 @@ rmbo:
Length: 4 Length: 4
Tick: 80 Tick: 80
c1: c1:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -606,6 +637,10 @@ c2:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -652,6 +687,10 @@ c3:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -698,6 +737,10 @@ c4:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -744,6 +787,10 @@ c5:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -790,7 +837,11 @@ c6:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
crawl: panic-stand:
Start: 8
Length: 6
Facings: 8
prone-run:
Start: 8 Start: 8
Length: 6 Length: 6
Facings: 8 Facings: 8
@@ -836,6 +887,10 @@ c7:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -882,6 +937,10 @@ c8:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -928,6 +987,10 @@ c9:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6
@@ -974,6 +1037,10 @@ c10:
stand: stand:
Start: 0 Start: 0
Facings: 8 Facings: 8
panic-stand:
Start: 8
Length: 6
Facings: 8
panic-run: panic-run:
Start: 8 Start: 8
Length: 6 Length: 6