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.
This commit is contained in:
reaperrr
2016-06-23 14:46:37 +02:00
parent 40e5dfbedb
commit 27993729be

View File

@@ -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;