From 27993729be2fe9ff80578337d97ef3e43bead559 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Thu, 23 Jun 2016 14:46:37 +0200 Subject: [PATCH] Make attack cursor smarter Rather than simply taking the first valid armament, regardless of available ammo and regardless of which valid armament has the highest range, the attack cursor is now chosen a) by whether the armament has ammo and b) by which valid armament has the highest range. --- .../Traits/Attack/AttackBase.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index e570cfbbd6..924f74f89a 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -387,10 +387,17 @@ namespace OpenRA.Mods.Common.Traits modifiers |= TargetModifiers.ForceAttack; var forceAttack = modifiers.HasModifier(TargetModifiers.ForceAttack); - var a = ab.ChooseArmamentsForTarget(target, forceAttack).FirstOrDefault(); - if (a == null) + var armaments = ab.ChooseArmamentsForTarget(target, forceAttack); + if (!armaments.Any()) return false; + // Use valid armament with highest range out of those that have ammo + // If all are out of ammo, just use valid armament with highest range + armaments = armaments.OrderByDescending(x => x.MaxRange()); + var a = armaments.FirstOrDefault(x => !x.OutOfAmmo); + if (a == null) + a = armaments.First(); + cursor = !target.IsInRange(self.CenterPosition, a.MaxRange()) ? ab.Info.OutsideRangeCursor ?? a.Info.OutsideRangeCursor : ab.Info.Cursor ?? a.Info.Cursor; @@ -414,10 +421,17 @@ namespace OpenRA.Mods.Common.Traits return false; var target = Target.FromCell(self.World, location); - var a = ab.ChooseArmamentsForTarget(target, true).FirstOrDefault(); - if (a == null) + var armaments = ab.ChooseArmamentsForTarget(target, true); + if (!armaments.Any()) return false; + // Use valid armament with highest range out of those that have ammo + // If all are out of ammo, just use valid armament with highest range + armaments = armaments.OrderByDescending(x => x.MaxRange()); + var a = armaments.FirstOrDefault(x => !x.OutOfAmmo); + if (a == null) + a = armaments.First(); + cursor = !target.IsInRange(self.CenterPosition, a.MaxRange()) ? ab.Info.OutsideRangeCursor ?? a.Info.OutsideRangeCursor : ab.Info.Cursor ?? a.Info.Cursor;