Make attacking actors/turrets face the targeted position

This commit is contained in:
reaperrr
2017-05-05 14:16:28 +02:00
committed by Oliver Brakmann
parent 7acc6dacbc
commit 6a212eea53
4 changed files with 11 additions and 5 deletions

View File

@@ -100,8 +100,9 @@ namespace OpenRA.Mods.Common.Activities
minRange = armaments.Max(a => a.Weapon.MinRange);
maxRange = armaments.Min(a => a.MaxRange());
var pos = self.CenterPosition;
var mobile = move as Mobile;
if (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)
if (!Target.IsInRange(pos, maxRange) || Target.IsInRange(pos, minRange)
|| (mobile != null && !mobile.CanInteractWithGroundLayer(self)))
{
// Try to move within range, drop the target otherwise
@@ -113,7 +114,8 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
var targetedPosition = Target.Positions.PositionClosestTo(pos);
var desiredFacing = (targetedPosition - pos).Yaw.Facing;
if (facing.Facing != desiredFacing)
{
attackStatus |= AttackStatus.NeedsToTurn;

View File

@@ -39,7 +39,9 @@ namespace OpenRA.Mods.Common.Traits
return false;
var f = facing.Facing;
var delta = target.CenterPosition - self.CenterPosition;
var pos = self.CenterPosition;
var targetedPosition = target.Positions.PositionClosestTo(pos);
var delta = targetedPosition - pos;
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;
if (Math.Abs(facingToTarget - f) % 256 > info.FacingTolerance)

View File

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

View File

@@ -130,7 +130,8 @@ namespace OpenRA.Mods.Common.Traits
if (self.IsDisabled())
return false;
var delta = target.CenterPosition - self.CenterPosition;
var pos = self.CenterPosition;
var delta = target.Positions.PositionClosestTo(pos) - pos;
DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing;
MoveTurret();
return HasAchievedDesiredFacing;