diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj
index 75a5864a8e..862d08208e 100644
--- a/OpenRa.Game/OpenRa.Game.csproj
+++ b/OpenRa.Game/OpenRa.Game.csproj
@@ -176,6 +176,7 @@
+
diff --git a/OpenRa.Game/Traits/AttackFrontal.cs b/OpenRa.Game/Traits/AttackFrontal.cs
new file mode 100644
index 0000000000..eac62bafd5
--- /dev/null
+++ b/OpenRa.Game/Traits/AttackFrontal.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenRa.Game.Traits
+{
+ abstract class AttackFrontal : AttackBase
+ {
+ public AttackFrontal(Actor self, int facingTolerance)
+ : base(self) { FacingTolerance = facingTolerance; }
+
+ int FacingTolerance;
+
+ public override void Tick(Actor self)
+ {
+ base.Tick(self);
+
+ if (target == null) return;
+
+ var unit = self.traits.Get();
+ var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing);
+
+ if (Math.Abs(facingToTarget - unit.Facing) % 256 < FacingTolerance)
+ DoAttack(self);
+ }
+ }
+}
diff --git a/OpenRa.Game/Traits/AttackHeli.cs b/OpenRa.Game/Traits/AttackHeli.cs
index 093870a0dd..4865e6d877 100644
--- a/OpenRa.Game/Traits/AttackHeli.cs
+++ b/OpenRa.Game/Traits/AttackHeli.cs
@@ -6,23 +6,9 @@ using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
- class AttackHeli : AttackBase
+ class AttackHeli : AttackFrontal
{
- public AttackHeli(Actor self) : base(self) { }
-
- const int facingTolerance = 20;
- public override void Tick(Actor self)
- {
- base.Tick(self);
-
- if (target == null) return;
-
- var unit = self.traits.Get();
- var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing);
-
- if (Math.Abs(facingToTarget - unit.Facing) % 256 < facingTolerance)
- DoAttack(self);
- }
+ public AttackHeli(Actor self) : base(self, 20) { }
protected override void QueueAttack(Actor self, Order order)
{
diff --git a/OpenRa.Game/Traits/AttackPlane.cs b/OpenRa.Game/Traits/AttackPlane.cs
index 427096b62b..9ccdffd513 100644
--- a/OpenRa.Game/Traits/AttackPlane.cs
+++ b/OpenRa.Game/Traits/AttackPlane.cs
@@ -6,28 +6,9 @@ using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
- // yet another ugly trait that does two things:
- // - plane-specific attack order dispatch
- // - forward-facing attack with a tolerance
-
- class AttackPlane : AttackBase
+ class AttackPlane : AttackFrontal
{
- const int facingTolerance = 20;
-
- public AttackPlane(Actor self) : base(self) { }
-
- public override void Tick(Actor self)
- {
- base.Tick(self);
-
- if (target == null) return;
-
- var unit = self.traits.Get();
- var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing);
-
- if (Math.Abs(facingToTarget - unit.Facing) % 256 < facingTolerance)
- DoAttack(self);
- }
+ public AttackPlane(Actor self) : base(self, 20) { }
protected override void QueueAttack(Actor self, Order order)
{