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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -243,7 +243,6 @@ ARTY:
|
||||
LocalOffset: 624,0,208
|
||||
MuzzleSequence: muzzle
|
||||
AttackFrontal:
|
||||
AttackTargetCenter: true
|
||||
WithMuzzleOverlay:
|
||||
Explodes:
|
||||
Weapon: ArtilleryExplode
|
||||
|
||||
@@ -357,7 +357,6 @@ JUGG:
|
||||
Voice: Attack
|
||||
Armaments: deployed
|
||||
RequiresCondition: deployed
|
||||
AttackTargetCenter: true
|
||||
Armament@deployed:
|
||||
Name: deployed
|
||||
Turret: deployed
|
||||
|
||||
Reference in New Issue
Block a user