From 1b0c493848467a3c0240992b18dfea7ff3bfc2da Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 31 Dec 2009 08:43:10 +1300 Subject: [PATCH] split frontal attack w/ tolerance behavior out of AttackPlane/AttackHeli --- OpenRa.Game/OpenRa.Game.csproj | 1 + OpenRa.Game/Traits/AttackFrontal.cs | 28 ++++++++++++++++++++++++++++ OpenRa.Game/Traits/AttackHeli.cs | 18 ++---------------- OpenRa.Game/Traits/AttackPlane.cs | 23 ++--------------------- 4 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 OpenRa.Game/Traits/AttackFrontal.cs 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) {