Improve performance of target validation.
The Warhead and WeaponInfo classes now maintain preconstructed sets of valid and invalid targets to speed up validation checks since LINQ Intersect no longer has to be called (which recreates the sets internally each time). Fixed minor bugs in the AI where it was repeating the validation logic but failing to account for invalid targets.
This commit is contained in:
@@ -18,6 +18,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
abstract class AirStateBase : StateBase
|
||||
{
|
||||
static readonly string[] AirTargetTypes = new[] { "Air" };
|
||||
|
||||
protected const int MissileUnitMultiplier = 3;
|
||||
|
||||
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
|
||||
@@ -34,7 +36,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
var arms = unit.TraitsImplementing<Armament>();
|
||||
foreach (var a in arms)
|
||||
{
|
||||
if (a.Weapon.ValidTargets.Contains("Air"))
|
||||
if (a.Weapon.IsValidTarget(AirTargetTypes))
|
||||
{
|
||||
missileUnitsCount++;
|
||||
break;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
var arms = a.TraitsImplementing<Armament>();
|
||||
foreach (var arm in arms)
|
||||
if (arm.Weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||
if (arm.Weapon.IsValidTarget(targetable.TargetTypes))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user