Merge pull request #10910 from RoosterDragon/turret-active-tracking

Turrets actively track targets
This commit is contained in:
Matthias Mailänder
2016-03-21 20:52:18 +01:00
4 changed files with 15 additions and 5 deletions

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Cnc.Traits
return false; return false;
} }
return turret.FaceTarget(self, target); return true;
} }
public void TickIdle(Actor self) public void TickIdle(Actor self)

View File

@@ -186,6 +186,9 @@ namespace OpenRA.Mods.Common.Traits
if (ammoPool != null && !ammoPool.HasAmmo()) if (ammoPool != null && !ammoPool.HasAmmo())
return null; return null;
if (turret != null && !turret.HasAchievedDesiredFacing)
return null;
if (!target.IsInRange(self.CenterPosition, MaxRange())) if (!target.IsInRange(self.CenterPosition, MaxRange()))
return null; return null;

View File

@@ -32,14 +32,16 @@ namespace OpenRA.Mods.Common.Traits
protected override bool CanAttack(Actor self, Target target) protected override bool CanAttack(Actor self, Target target)
{ {
if (!base.CanAttack(self, target)) if (target.Type == TargetType.Invalid)
return false; return false;
// Don't break early from this loop - we want to bring all turrets to bear!
var turretReady = false;
foreach (var t in turrets) foreach (var t in turrets)
if (t.FaceTarget(self, target)) if (t.FaceTarget(self, target))
return true; turretReady = true;
return false; return turretReady && base.CanAttack(self, target);
} }
} }
} }

View File

@@ -113,7 +113,12 @@ namespace OpenRA.Mods.Common.Traits
var delta = target.CenterPosition - self.CenterPosition; var delta = target.CenterPosition - self.CenterPosition;
DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing; DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing;
MoveTurret(); MoveTurret();
return TurretFacing == DesiredFacing.Value; return HasAchievedDesiredFacing;
}
public bool HasAchievedDesiredFacing
{
get { return DesiredFacing != null && TurretFacing == DesiredFacing.Value; }
} }
// Turret offset in world-space // Turret offset in world-space