Adapt Attack logic to Weapon.TargetActorCenter
This commit is contained in:
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
var targetedPosition = attack.Info.AttackTargetCenter ? Target.CenterPosition : Target.Positions.PositionClosestTo(pos);
|
||||
var targetedPosition = attack.GetTargetPosition(pos, Target);
|
||||
var desiredFacing = (targetedPosition - pos).Yaw.Facing;
|
||||
if (facing.Facing != desiredFacing)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var f = facing.Facing;
|
||||
var pos = self.CenterPosition;
|
||||
var targetedPosition = Info.AttackTargetCenter ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
|
||||
var targetedPosition = GetTargetPosition(pos, target);
|
||||
var delta = targetedPosition - pos;
|
||||
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
var pos = self.CenterPosition;
|
||||
var targetedPosition = Info.AttackTargetCenter ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
|
||||
var targetedPosition = GetTargetPosition(pos, target);
|
||||
var targetYaw = (targetedPosition - pos).Yaw;
|
||||
|
||||
foreach (var a in Armaments)
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
var pos = self.CenterPosition;
|
||||
var targetPos = attack != null && attack.Info.AttackTargetCenter ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
|
||||
var targetPos = attack != null ? attack.GetTargetPosition(pos, target) : target.CenterPosition;
|
||||
var delta = targetPos - pos;
|
||||
DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing;
|
||||
MoveTurret();
|
||||
|
||||
Reference in New Issue
Block a user