Implement IRenderInfantrySequenceModifier for ScaredyCat and TakeCover
This commit is contained in:
@@ -9,16 +9,14 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("This actor goes prone in an attempt to reduce damage.")]
|
||||
[Desc("Make the unit go prone when under attack, in an attempt to reduce damage.")]
|
||||
public class TakeCoverInfo : TurretedInfo
|
||||
{
|
||||
[Desc("How long should we remain in the prone position?" +
|
||||
"Measured in game ticks. Default is 4 seconds.")]
|
||||
[Desc("How long (in ticks) the actor remains prone.")]
|
||||
public readonly int ProneTime = 100;
|
||||
|
||||
[Desc("Prone movement speed as a percentage of the normal speed.")]
|
||||
@@ -29,87 +27,48 @@ namespace OpenRA.Mods.RA
|
||||
public override object Create(ActorInitializer init) { return new TakeCover(init, this); }
|
||||
}
|
||||
|
||||
// Infantry prone behavior
|
||||
public class TakeCover : Turreted, ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync
|
||||
public class TakeCover : Turreted, INotifyDamage, IDamageModifier, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
||||
{
|
||||
TakeCoverInfo Info;
|
||||
readonly TakeCoverInfo info;
|
||||
[Sync] int remainingProneTime = 0;
|
||||
bool isProne { get { return remainingProneTime > 0; } }
|
||||
|
||||
public bool IsModifyingSequence { get { return isProne; } }
|
||||
public string SequencePrefix { get { return "prone-"; } }
|
||||
|
||||
public TakeCover(ActorInitializer init, TakeCoverInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
Info = info;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public bool IsProne { get { return remainingProneTime > 0; } }
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.Damage > 0 && (e.Warhead == null || !e.Warhead.PreventProne)) /* Don't go prone when healed */
|
||||
{
|
||||
if (!IsProne)
|
||||
LocalOffset = Info.ProneOffset;
|
||||
if (!isProne)
|
||||
LocalOffset = info.ProneOffset;
|
||||
|
||||
remainingProneTime = Info.ProneTime;
|
||||
remainingProneTime = info.ProneTime;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
if (IsProne && --remainingProneTime == 0)
|
||||
|
||||
if (isProne && --remainingProneTime == 0)
|
||||
LocalOffset = WVec.Zero;
|
||||
}
|
||||
|
||||
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
|
||||
{
|
||||
return IsProne && warhead != null ? warhead.ProneModifier : 100;
|
||||
return isProne && warhead != null ? warhead.ProneModifier : 100;
|
||||
}
|
||||
|
||||
public int GetSpeedModifier()
|
||||
{
|
||||
return IsProne ? Info.SpeedModifier : 100;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderInfantryProneInfo : RenderInfantryInfo, Requires<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 (DefaultAnimation.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);
|
||||
return isProne ? info.SpeedModifier : 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user