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:
RoosterDragon
2015-03-30 23:24:56 +01:00
parent 5ac648600d
commit ab2ef0ba03
4 changed files with 33 additions and 15 deletions

View File

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

View File

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