diff --git a/OpenRA.Mods.RA/AI/AttackOrFleeFuzzy.cs b/OpenRA.Mods.RA/AI/AttackOrFleeFuzzy.cs index 59f1ef4781..273f02739f 100644 --- a/OpenRA.Mods.RA/AI/AttackOrFleeFuzzy.cs +++ b/OpenRA.Mods.RA/AI/AttackOrFleeFuzzy.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Linq; using AI.Fuzzy.Library; using OpenRA.Mods.RA.Move; using OpenRA.Traits; @@ -165,7 +166,7 @@ namespace OpenRA.Mods.RA.AI "then AttackOrFlee is Flee"); } - public void CalculateFuzzy(List ownUnits, List enemyUnits) + public void CalculateFuzzy(IEnumerable ownUnits, IEnumerable enemyUnits) { var inputValues = new Dictionary(); inputValues.Add(fuzzyEngine.InputByName("OwnHealth"), (double)NormalizedHealth(ownUnits, 100)); @@ -176,7 +177,7 @@ namespace OpenRA.Mods.RA.AI result = fuzzyEngine.Calculate(inputValues); } - protected float NormalizedHealth(List actors, float normalizeByValue) + protected float NormalizedHealth(IEnumerable actors, float normalizeByValue) { var sumOfMaxHp = 0; var sumOfHp = 0; @@ -195,7 +196,7 @@ namespace OpenRA.Mods.RA.AI return (sumOfHp * normalizeByValue) / sumOfMaxHp; } - protected float RelativePower(List own, List enemy) + protected float RelativePower(IEnumerable own, IEnumerable enemy) { return RelativeValue(own, enemy, 100, SumOfValues, (Actor a) => { @@ -208,25 +209,25 @@ namespace OpenRA.Mods.RA.AI }); } - protected float RelativeSpeed(List own, List enemy) + protected float RelativeSpeed(IEnumerable own, IEnumerable enemy) { return RelativeValue(own, enemy, 100, Average, (Actor a) => a.Trait().Info.Speed); } - protected float RelativeValue(List own, List enemy, float normalizeByValue, - Func, Func, float> relativeFunc, Func getValue) + protected float RelativeValue(IEnumerable own, IEnumerable enemy, float normalizeByValue, + Func, Func, float> relativeFunc, Func getValue) { - if (enemy.Count == 0) + if (!enemy.Any()) return 999.0f; - if (own.Count == 0) + if (!own.Any()) return 0.0f; var relative = (relativeFunc(own, getValue) / relativeFunc(enemy, getValue)) * normalizeByValue; return relative.Clamp(0.0f, 999.0f); } - protected float SumOfValues(List actors, Func getValue) + protected float SumOfValues(IEnumerable actors, Func getValue) { var sum = 0; foreach (var a in actors) @@ -236,7 +237,7 @@ namespace OpenRA.Mods.RA.AI return sum; } - protected float Average(List actors, Func getValue) + protected float Average(IEnumerable actors, Func getValue) { var sum = 0; var countActors = 0; diff --git a/OpenRA.Mods.RA/AI/States/AirStates.cs b/OpenRA.Mods.RA/AI/States/AirStates.cs index e27dcebe52..99fa2bbb00 100644 --- a/OpenRA.Mods.RA/AI/States/AirStates.cs +++ b/OpenRA.Mods.RA/AI/States/AirStates.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.AI { protected const int missileUnitsMultiplier = 3; - protected static int CountAntiAirUnits(List units) + protected static int CountAntiAirUnits(IEnumerable units) { int missileUnitsCount = 0; foreach (var unit in units) @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.AI return base.MayBeFlee(owner, (enemyAroundUnit) => { int missileUnitsCount = 0; - if (enemyAroundUnit.Count > 0) + if (enemyAroundUnit.Any()) missileUnitsCount = CountAntiAirUnits(enemyAroundUnit); if (missileUnitsCount * missileUnitsMultiplier > owner.units.Count) diff --git a/OpenRA.Mods.RA/AI/States/StateBase.cs b/OpenRA.Mods.RA/AI/States/StateBase.cs index d6c51c91f8..4f4ebda24e 100644 --- a/OpenRA.Mods.RA/AI/States/StateBase.cs +++ b/OpenRA.Mods.RA/AI/States/StateBase.cs @@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.AI return false; } - protected virtual bool MayBeFlee(Squad squad, Func, bool> flee) + protected virtual bool MayBeFlee(Squad squad, Func, bool> flee) { if (!squad.IsValid) return false; @@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA.AI if (!enemyAroundUnit.Any()) return false; - return flee(enemyAroundUnit.ToList()); + return flee(enemyAroundUnit); } } }