diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index 94df1d1af8..8d164ee376 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -76,9 +76,13 @@ namespace OpenRA.Mods.Common.Activities minRange = armaments.Max(a => a.Weapon.MinRange); maxRange = armaments.Min(a => a.MaxRange()); - // Try to move within range - if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange))) + if (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)) + { + // Try to move within range, drop the target otherwise + if (move == null) + return NextActivity; return ActivityUtils.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this); + } var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing; if (facing.Facing != desiredFacing) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 39957d4f0f..c9686ff459 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -58,16 +58,20 @@ namespace OpenRA.Mods.Common.Traits readonly IMove move; readonly Target target; readonly bool forceAttack; + readonly bool onRailsHack; public AttackActivity(Actor self, Target target, bool allowMove, bool forceAttack) { attack = self.Trait(); move = allowMove ? self.TraitOrDefault() : null; - // HACK: Mobile.OnRails is horrible + // HACK: Mobile.OnRails is horrible. Blergh. var mobile = move as Mobile; if (mobile != null && mobile.Info.OnRails) + { move = null; + onRailsHack = true; + } this.target = target; this.forceAttack = forceAttack; @@ -96,8 +100,15 @@ namespace OpenRA.Mods.Common.Traits if (move != null) return ActivityUtils.SequenceActivities(move.MoveFollow(self, target, weapon.Weapon.MinRange, maxRange), this); + if (!onRailsHack && + target.IsInRange(self.CenterPosition, weapon.MaxRange()) && + !target.IsInRange(self.CenterPosition, weapon.Weapon.MinRange)) + return this; } + if (!onRailsHack) + attack.Target = Target.Invalid; + return NextActivity; } }