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

@@ -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)
{

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)

View File

@@ -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;

View File

@@ -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)

View File

@@ -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();

View File

@@ -156,7 +156,6 @@ ARTY:
LocalOffset: 624,0,208
MuzzleSequence: muzzle
AttackFrontal:
AttackTargetCenter: true
WithMuzzleOverlay:
AutoTarget:
InitialStanceAI: Defend
@@ -473,7 +472,6 @@ MSAM:
Weapon: 227mm
LocalOffset: 213,-128,0, 213,128,0
AttackFrontal:
AttackTargetCenter: true
WithSpriteTurret:
AimSequence: aim
SpawnActorOnDeath:

View File

@@ -113,7 +113,6 @@ MSUB:
LocalOffset: 0,-171,0, 0,171,0
FireDelay: 2
AttackFrontal:
AttackTargetCenter: true
SelectionDecorations:
VisualBounds: 44,44
AutoTarget:
@@ -226,7 +225,6 @@ CA:
RecoilRecovery: 34
MuzzleSequence: muzzle
AttackTurreted:
AttackTargetCenter: true
WithMuzzleOverlay:
SelectionDecorations:
VisualBounds: 44,44

View File

@@ -243,7 +243,6 @@ ARTY:
LocalOffset: 624,0,208
MuzzleSequence: muzzle
AttackFrontal:
AttackTargetCenter: true
WithMuzzleOverlay:
Explodes:
Weapon: ArtilleryExplode

View File

@@ -357,7 +357,6 @@ JUGG:
Voice: Attack
Armaments: deployed
RequiresCondition: deployed
AttackTargetCenter: true
Armament@deployed:
Name: deployed
Turret: deployed