Adapt Attack logic to Weapon.TargetActorCenter

This commit is contained in:
reaperrr
2017-06-22 12:39:40 +02:00
committed by Paul Chote
parent edffaa4987
commit 33e8bf9928
9 changed files with 29 additions and 13 deletions

View File

@@ -24,9 +24,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Armament names")]
public readonly string[] Armaments = { "primary", "secondary" };
[Desc("Attack the target's center, instead of the closest targetable offset.")]
public readonly bool AttackTargetCenter = false;
public readonly string Cursor = null;
public readonly string OutsideRangeCursor = null;
@@ -211,12 +208,37 @@ namespace OpenRA.Mods.Common.Traits
// PERF: Avoid LINQ.
foreach (var armament in Armaments)
{
if (!armament.OutOfAmmo && armament.Weapon.IsValidAgainst(t, self.World, self))
return true;
}
return false;
}
public bool HasAnyValidCenterTargetingWeapons(Target t)
{
if (IsTraitDisabled)
return false;
if (Info.AttackRequiresEnteringCell && (positionable == null || !positionable.CanEnterCell(t.Actor.Location, null, false)))
return false;
// PERF: Avoid LINQ.
foreach (var armament in Armaments)
{
if (armament.Weapon.TargetActorCenter && armament.Weapon.IsValidAgainst(t, self.World, self))
return true;
}
return false;
}
public virtual WPos GetTargetPosition(WPos pos, Target target)
{
return HasAnyValidCenterTargetingWeapons(target) ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
}
public WDist GetMinimumRange()
{
if (IsTraitDisabled)