diff --git a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs index 1cfc95144d..9f245000bf 100644 --- a/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/HeliAttack.cs @@ -80,13 +80,10 @@ namespace OpenRA.Mods.Common.Activities return this; // Fly towards the target - // TODO: Fix that the helicopter won't do anything if it has multiple weapons with different ranges - // and the weapon with the longest range is out of ammo if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRangeVersusTarget(target))) helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); // Fly backwards from the target - // TODO: Same problem as with MaximumRange if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRangeVersusTarget(target))) { // Facing 0 doesn't work with the following position change diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index a424763389..9ca212cef2 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -259,6 +259,7 @@ namespace OpenRA.Mods.Common.Traits public bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } } public bool ShouldExplode(Actor self) { return !IsReloading; } + public bool OutOfAmmo { get { return ammoPool != null && !ammoPool.Info.SelfReloads && !ammoPool.HasAmmo(); } } public WVec MuzzleOffset(Actor self, Barrel b) { diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index bbceaae98c..e570cfbbd6 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits // PERF: Avoid LINQ. foreach (var armament in Armaments) - if (armament.Weapon.IsValidAgainst(t, self.World, self)) + if (!armament.OutOfAmmo && armament.Weapon.IsValidAgainst(t, self.World, self)) return true; return false; @@ -203,6 +203,10 @@ namespace OpenRA.Mods.Common.Traits { if (armament.IsTraitDisabled) continue; + + if (armament.OutOfAmmo) + continue; + var range = armament.Weapon.MinRange; if (min > range) min = range; @@ -222,6 +226,10 @@ namespace OpenRA.Mods.Common.Traits { if (armament.IsTraitDisabled) continue; + + if (armament.OutOfAmmo) + continue; + var range = armament.MaxRange(); if (max < range) max = range; @@ -242,6 +250,9 @@ namespace OpenRA.Mods.Common.Traits if (armament.IsTraitDisabled) continue; + if (armament.OutOfAmmo) + continue; + if (!armament.Weapon.IsValidAgainst(target, self.World, self)) continue; @@ -265,6 +276,9 @@ namespace OpenRA.Mods.Common.Traits if (armament.IsTraitDisabled) continue; + if (armament.OutOfAmmo) + continue; + if (!armament.Weapon.IsValidAgainst(target, self.World, self)) continue;