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; 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; var desiredFacing = (targetedPosition - pos).Yaw.Facing;
if (facing.Facing != desiredFacing) if (facing.Facing != desiredFacing)
{ {

View File

@@ -24,9 +24,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Armament names")] [Desc("Armament names")]
public readonly string[] Armaments = { "primary", "secondary" }; 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 Cursor = null;
public readonly string OutsideRangeCursor = null; public readonly string OutsideRangeCursor = null;
@@ -211,12 +208,37 @@ namespace OpenRA.Mods.Common.Traits
// PERF: Avoid LINQ. // PERF: Avoid LINQ.
foreach (var armament in Armaments) foreach (var armament in Armaments)
{
if (!armament.OutOfAmmo && armament.Weapon.IsValidAgainst(t, self.World, self)) if (!armament.OutOfAmmo && armament.Weapon.IsValidAgainst(t, self.World, self))
return true; return true;
}
return false; 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() public WDist GetMinimumRange()
{ {
if (IsTraitDisabled) if (IsTraitDisabled)

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
var f = facing.Facing; var f = facing.Facing;
var pos = self.CenterPosition; var pos = self.CenterPosition;
var targetedPosition = Info.AttackTargetCenter ? target.CenterPosition : target.Positions.PositionClosestTo(pos); var targetedPosition = GetTargetPosition(pos, target);
var delta = targetedPosition - pos; var delta = targetedPosition - pos;
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f; var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;

View File

@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
var pos = self.CenterPosition; var pos = self.CenterPosition;
var targetedPosition = Info.AttackTargetCenter ? target.CenterPosition : target.Positions.PositionClosestTo(pos); var targetedPosition = GetTargetPosition(pos, target);
var targetYaw = (targetedPosition - pos).Yaw; var targetYaw = (targetedPosition - pos).Yaw;
foreach (var a in Armaments) foreach (var a in Armaments)

View File

@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits
return false; return false;
var pos = self.CenterPosition; 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; var delta = targetPos - pos;
DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing; DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing;
MoveTurret(); MoveTurret();

View File

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

View File

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

View File

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

View File

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