added infantry taking cover behavior
This commit is contained in:
@@ -111,10 +111,13 @@ namespace OpenRa.Game
|
||||
public void InflictDamage(Actor attacker, int damage, WarheadInfo warhead)
|
||||
{
|
||||
/* todo: auto-retaliate, etc */
|
||||
/* todo: death sequence for infantry based on inflictor */
|
||||
|
||||
if (IsDead) return; /* overkill! don't count extra hits as more kills! */
|
||||
|
||||
/* apply the damage modifiers, if we have any. */
|
||||
damage = (int)traits.WithInterface<IDamageModifier>().Aggregate(
|
||||
(float)damage, (a, t) => t.GetDamageModifier() * a);
|
||||
|
||||
Health -= damage;
|
||||
if (Health <= 0)
|
||||
{
|
||||
|
||||
@@ -183,6 +183,7 @@
|
||||
<Compile Include="Traits\RenderUnitSpinner.cs" />
|
||||
<Compile Include="Traits\RenderUnitTurreted.cs" />
|
||||
<Compile Include="Traits\SeedsOre.cs" />
|
||||
<Compile Include="Traits\TakeCover.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
<Compile Include="Traits\Tree.cs" />
|
||||
<Compile Include="Traits\Turreted.cs" />
|
||||
|
||||
@@ -168,7 +168,11 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var oldFraction = moveFraction;
|
||||
var oldTotal = moveFractionTotal;
|
||||
|
||||
moveFraction += ( self.Info as MobileInfo ).Speed;
|
||||
var actualSpeed = (int)self.traits.WithInterface<ISpeedModifier>().Aggregate(
|
||||
(float)(self.Info as MobileInfo).Speed,
|
||||
(a, t) => t.GetSpeedModifier() * a);
|
||||
|
||||
moveFraction += actualSpeed;
|
||||
UpdateCenterLocation( self, mobile );
|
||||
if( moveFraction >= moveFractionTotal )
|
||||
{
|
||||
|
||||
@@ -48,8 +48,12 @@ namespace OpenRa.Game.Traits
|
||||
Util.TickFacing(ref unit.Facing, desiredFacing,
|
||||
self.Info.ROT);
|
||||
|
||||
var actualSpeed = self.traits.WithInterface<ISpeedModifier>().Aggregate(
|
||||
(float)(self.Info as MobileInfo).Speed,
|
||||
(a, t) => t.GetSpeedModifier() * a);
|
||||
|
||||
// .6f going the wrong way; .8f going sideways, 1f going forward.
|
||||
var rawSpeed = .2f * (self.Info as VehicleInfo).Speed;
|
||||
var rawSpeed = .2f * actualSpeed;
|
||||
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
|
||||
var scale = .4f + .6f * (float)Math.Cos(angle);
|
||||
|
||||
|
||||
@@ -26,10 +26,13 @@ namespace OpenRa.Game.Traits
|
||||
if (float2.WithinEpsilon(self.CenterLocation, Util.CenterOfCell(mobile.toCell), 2)) return false;
|
||||
var dir = Util.QuantizeFacing(self.traits.Get<Unit>().Facing, 8);
|
||||
|
||||
if (anim.CurrentSequence.Name.StartsWith("run-"))
|
||||
anim.ReplaceAnim("run-" + dir);
|
||||
var takeCover = self.traits.GetOrDefault<TakeCover>();
|
||||
var prefix = (takeCover != null && takeCover.IsProne) ? "crawl-" : "run-";
|
||||
|
||||
if (anim.CurrentSequence.Name.StartsWith(prefix))
|
||||
anim.ReplaceAnim(prefix + dir);
|
||||
else
|
||||
anim.PlayRepeating("run-" + dir);
|
||||
anim.PlayRepeating(prefix + dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -40,7 +43,11 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
var dir = Util.QuantizeFacing(self.traits.Get<Unit>().Facing, 8);
|
||||
inAttack = true;
|
||||
anim.PlayThen("shoot-" + dir, () => inAttack = false);
|
||||
|
||||
var takeCover = self.traits.GetOrDefault<TakeCover>();
|
||||
var prefix = (takeCover != null && takeCover.IsProne) ? "prone-shoot-" : "shoot-";
|
||||
|
||||
anim.PlayThen(prefix + dir, () => inAttack = false);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
|
||||
43
OpenRa.Game/Traits/TakeCover.cs
Normal file
43
OpenRa.Game/Traits/TakeCover.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
// infantry prone behavior
|
||||
class TakeCover : ITick, INotifyDamageEx, IDamageModifier, ISpeedModifier
|
||||
{
|
||||
const int defaultProneTime = 100; /* ticks, =4s */
|
||||
const float proneDamage = .5f;
|
||||
const float proneSpeed = .5f;
|
||||
|
||||
int remainingProneTime = 0;
|
||||
|
||||
public bool IsProne { get { return remainingProneTime > 0; } }
|
||||
|
||||
public TakeCover(Actor self) {}
|
||||
|
||||
public void Damaged(Actor self, int damage, WarheadInfo warhead)
|
||||
{
|
||||
remainingProneTime = defaultProneTime;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (IsProne)
|
||||
--remainingProneTime;
|
||||
}
|
||||
|
||||
public float GetDamageModifier()
|
||||
{
|
||||
return IsProne ? proneDamage : 1f;
|
||||
}
|
||||
|
||||
public float GetSpeedModifier()
|
||||
{
|
||||
return IsProne ? proneSpeed : 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,6 @@ namespace OpenRa.Game.Traits
|
||||
interface INotifyAttack { void Attacking(Actor self); }
|
||||
interface IRenderModifier { IEnumerable<Tuple<Sprite, float2, int>>
|
||||
ModifyRender( Actor self, IEnumerable<Tuple<Sprite, float2, int>> r ); }
|
||||
interface IDamageModifier { float GetDamageModifier(); }
|
||||
interface ISpeedModifier { float GetSpeedModifier(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user