Start RenderInfantry rework. TODO: fix ra sequences, split Prone/Panicked into RenderInfantry* overrides, integrate idle anims.
This commit is contained in:
@@ -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<IFacing>().Facing)
|
||||
{
|
||||
anim.Play("stand");
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||
State = AnimationState.Idle;
|
||||
mobile = self.Trait<Mobile>();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,25 @@ using OpenRA.Mods.RA.Render;
|
||||
|
||||
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
|
||||
{
|
||||
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<RenderInfantry>().Prone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,41 +53,20 @@ namespace OpenRA.Mods.RA
|
||||
if (!IsProne)
|
||||
return;
|
||||
|
||||
remainingProneTime--;
|
||||
|
||||
var ri = self.Trait<RenderInfantry>();
|
||||
|
||||
// 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<RenderInfantry>();
|
||||
|
||||
if (--remainingProneTime <= 0)
|
||||
self.Trait<RenderInfantry>().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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user