Check if weapon without self-reloading is out of ammo when deciding validity

This should prevent attacking helicopters (or other actors) staying at the range to target of a weapon that is out of ammo and needs manual reloading at a RearmBuilding or via upgrades.
This commit is contained in:
reaperrr
2016-06-17 13:14:15 +02:00
parent 2f1a6e8807
commit 4f55b088eb
3 changed files with 16 additions and 4 deletions

View File

@@ -80,13 +80,10 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
// Fly towards the target // 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))) if (!target.IsInRange(self.CenterPosition, attackHeli.GetMaximumRangeVersusTarget(target)))
helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing)); helicopter.SetPosition(self, helicopter.CenterPosition + helicopter.FlyStep(desiredFacing));
// Fly backwards from the target // Fly backwards from the target
// TODO: Same problem as with MaximumRange
if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRangeVersusTarget(target))) if (target.IsInRange(self.CenterPosition, attackHeli.GetMinimumRangeVersusTarget(target)))
{ {
// Facing 0 doesn't work with the following position change // Facing 0 doesn't work with the following position change

View File

@@ -259,6 +259,7 @@ namespace OpenRA.Mods.Common.Traits
public bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } } public bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } }
public bool ShouldExplode(Actor self) { return !IsReloading; } 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) public WVec MuzzleOffset(Actor self, Barrel b)
{ {

View File

@@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Traits
// PERF: Avoid LINQ. // PERF: Avoid LINQ.
foreach (var armament in Armaments) 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 true;
return false; return false;
@@ -203,6 +203,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
if (armament.IsTraitDisabled) if (armament.IsTraitDisabled)
continue; continue;
if (armament.OutOfAmmo)
continue;
var range = armament.Weapon.MinRange; var range = armament.Weapon.MinRange;
if (min > range) if (min > range)
min = range; min = range;
@@ -222,6 +226,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
if (armament.IsTraitDisabled) if (armament.IsTraitDisabled)
continue; continue;
if (armament.OutOfAmmo)
continue;
var range = armament.MaxRange(); var range = armament.MaxRange();
if (max < range) if (max < range)
max = range; max = range;
@@ -242,6 +250,9 @@ namespace OpenRA.Mods.Common.Traits
if (armament.IsTraitDisabled) if (armament.IsTraitDisabled)
continue; continue;
if (armament.OutOfAmmo)
continue;
if (!armament.Weapon.IsValidAgainst(target, self.World, self)) if (!armament.Weapon.IsValidAgainst(target, self.World, self))
continue; continue;
@@ -265,6 +276,9 @@ namespace OpenRA.Mods.Common.Traits
if (armament.IsTraitDisabled) if (armament.IsTraitDisabled)
continue; continue;
if (armament.OutOfAmmo)
continue;
if (!armament.Weapon.IsValidAgainst(target, self.World, self)) if (!armament.Weapon.IsValidAgainst(target, self.World, self))
continue; continue;