split frontal attack w/ tolerance behavior out of AttackPlane/AttackHeli
This commit is contained in:
@@ -176,6 +176,7 @@
|
||||
<Compile Include="Traits\APMine.cs" />
|
||||
<Compile Include="Traits\ATMine.cs" />
|
||||
<Compile Include="Traits\AttackBase.cs" />
|
||||
<Compile Include="Traits\AttackFrontal.cs" />
|
||||
<Compile Include="Traits\AttackHeli.cs" />
|
||||
<Compile Include="Traits\AttackInfo.cs" />
|
||||
<Compile Include="Traits\AttackPlane.cs" />
|
||||
|
||||
28
OpenRa.Game/Traits/AttackFrontal.cs
Normal file
28
OpenRa.Game/Traits/AttackFrontal.cs
Normal file
@@ -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<Unit>();
|
||||
var facingToTarget = Util.GetFacing(target.CenterLocation - self.CenterLocation, unit.Facing);
|
||||
|
||||
if (Math.Abs(facingToTarget - unit.Facing) % 256 < FacingTolerance)
|
||||
DoAttack(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Unit>();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<Unit>();
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user