From 4598b0de4372897aac520602cd41eb93ea04930a Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 11 Mar 2016 19:26:44 +0000 Subject: [PATCH 1/2] Have turrets actively track targets, even when not ready to attack. --- OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs | 2 +- OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs index ea0fe29d67..ea8a4482d3 100644 --- a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs +++ b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.Cnc.Traits return false; } - return turret.FaceTarget(self, target); + return true; } public void TickIdle(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs index bfd26e0620..be6092e318 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackTurreted.cs @@ -32,14 +32,16 @@ namespace OpenRA.Mods.Common.Traits protected override bool CanAttack(Actor self, Target target) { - if (!base.CanAttack(self, target)) + if (target.Type == TargetType.Invalid) 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) if (t.FaceTarget(self, target)) - return true; + turretReady = true; - return false; + return turretReady && base.CanAttack(self, target); } } } From 163688fc397f9d873fcb38243a40bd12e86f74f2 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 12 Mar 2016 20:41:35 +0000 Subject: [PATCH 2/2] Prevent turrets from firing until they are aligned with the target. --- OpenRA.Mods.Common/Traits/Armament.cs | 3 +++ OpenRA.Mods.Common/Traits/Turreted.cs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index 1fc2298d50..45fd8d3a2a 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -186,6 +186,9 @@ namespace OpenRA.Mods.Common.Traits if (ammoPool != null && !ammoPool.HasAmmo()) return null; + if (turret != null && !turret.HasAchievedDesiredFacing) + return null; + if (!target.IsInRange(self.CenterPosition, MaxRange())) return null; diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index ab477a653b..6d14a6eacd 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -113,7 +113,12 @@ namespace OpenRA.Mods.Common.Traits var delta = target.CenterPosition - self.CenterPosition; DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing; MoveTurret(); - return TurretFacing == DesiredFacing.Value; + return HasAchievedDesiredFacing; + } + + public bool HasAchievedDesiredFacing + { + get { return DesiredFacing != null && TurretFacing == DesiredFacing.Value; } } // Turret offset in world-space