Split out RenderInfantryProne
This commit is contained in:
@@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Move;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class RenderInfantryInfo : RenderSimpleInfo
|
||||
public class RenderInfantryInfo : RenderSimpleInfo, ITraitPrerequisite<MobileInfo>
|
||||
{
|
||||
public readonly int MinIdleWaitTicks = 30;
|
||||
public readonly int MaxIdleWaitTicks = 110;
|
||||
@@ -37,8 +37,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
};
|
||||
|
||||
public bool Panicked = false;
|
||||
public bool Prone = false;
|
||||
bool wasProne = false;
|
||||
protected bool dirty = false;
|
||||
|
||||
RenderInfantryInfo Info;
|
||||
string idleSequence;
|
||||
@@ -46,8 +45,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
|
||||
{
|
||||
var prefix = Prone ? "prone-" :
|
||||
Panicked ? "panic-" : "";
|
||||
var prefix = Panicked ? "panic-" : "";
|
||||
|
||||
if (anim.HasSequence(prefix + baseSequence))
|
||||
return prefix + baseSequence;
|
||||
@@ -57,7 +55,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
protected virtual bool AllowIdleAnimation(Actor self)
|
||||
{
|
||||
return Info.IdleAnimations.Length > 0 && !Prone && !Panicked;
|
||||
return Info.IdleAnimations.Length > 0 && !Panicked;
|
||||
}
|
||||
|
||||
public AnimationState State { get; private set; }
|
||||
@@ -84,17 +82,17 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
if ((State == AnimationState.Moving || wasProne != Prone) && !mobile.IsMoving)
|
||||
if ((State == AnimationState.Moving || dirty) && !mobile.IsMoving)
|
||||
{
|
||||
State = AnimationState.Waiting;
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||
}
|
||||
else if ((State != AnimationState.Moving || wasProne != Prone) && mobile.IsMoving)
|
||||
else if ((State != AnimationState.Moving || dirty) && mobile.IsMoving)
|
||||
{
|
||||
State = AnimationState.Moving;
|
||||
anim.PlayRepeating(NormalizeInfantrySequence(self, "run"));
|
||||
}
|
||||
wasProne = Prone;
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public void TickIdle(Actor self)
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Mods.RA.Render;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class TakeCoverInfo : ITraitInfo, ITraitPrerequisite<RenderInfantryInfo>
|
||||
public class TakeCoverInfo : ITraitInfo
|
||||
{
|
||||
public readonly int ProneTime = 100; /* ticks, =4s */
|
||||
public readonly float ProneDamage = .5f;
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
// Infantry prone behavior
|
||||
class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync
|
||||
public class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync
|
||||
{
|
||||
TakeCoverInfo Info;
|
||||
[Sync]
|
||||
@@ -38,25 +38,14 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.Damage > 0) /* Don't go prone when healed */
|
||||
{
|
||||
if (e.Warhead == null || !e.Warhead.PreventProne)
|
||||
{
|
||||
remainingProneTime = Info.ProneTime;
|
||||
self.Trait<RenderInfantry>().Prone = true;
|
||||
}
|
||||
}
|
||||
if (e.Damage > 0 && e.Warhead == null || !e.Warhead.PreventProne) /* Don't go prone when healed */
|
||||
remainingProneTime = Info.ProneTime;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!IsProne)
|
||||
return;
|
||||
|
||||
//var ri = self.Trait<RenderInfantry>();
|
||||
|
||||
if (--remainingProneTime <= 0)
|
||||
self.Trait<RenderInfantry>().Prone = false;
|
||||
if (IsProne)
|
||||
remainingProneTime--;
|
||||
}
|
||||
|
||||
public float GetDamageModifier(Actor attacker, WarheadInfo warhead )
|
||||
@@ -69,4 +58,45 @@ namespace OpenRA.Mods.RA
|
||||
return IsProne ? Info.ProneSpeed : 1m;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderInfantryProneInfo : RenderInfantryInfo, ITraitPrerequisite<TakeCoverInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderInfantryProne(init.self, this); }
|
||||
}
|
||||
|
||||
class RenderInfantryProne : RenderInfantry
|
||||
{
|
||||
readonly TakeCover tc;
|
||||
bool wasProne;
|
||||
|
||||
public RenderInfantryProne(Actor self, RenderInfantryProneInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
tc = self.Trait<TakeCover>();
|
||||
}
|
||||
|
||||
protected override string NormalizeInfantrySequence(Actor self, string baseSequence)
|
||||
{
|
||||
var prefix = tc != null && tc.IsProne ? "prone-" : "";
|
||||
|
||||
if (anim.HasSequence(prefix + baseSequence))
|
||||
return prefix + baseSequence;
|
||||
else
|
||||
return baseSequence;
|
||||
}
|
||||
|
||||
protected override bool AllowIdleAnimation(Actor self)
|
||||
{
|
||||
return base.AllowIdleAnimation(self) && !tc.IsProne;
|
||||
}
|
||||
|
||||
public override void Tick (Actor self)
|
||||
{
|
||||
if (wasProne != tc.IsProne)
|
||||
dirty = true;
|
||||
|
||||
wasProne = tc.IsProne;
|
||||
base.Tick(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user