Remove explicit List<Actors> everywhere.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using AI.Fuzzy.Library;
|
using AI.Fuzzy.Library;
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -165,7 +166,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
"then AttackOrFlee is Flee");
|
"then AttackOrFlee is Flee");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CalculateFuzzy(List<Actor> ownUnits, List<Actor> enemyUnits)
|
public void CalculateFuzzy(IEnumerable<Actor> ownUnits, IEnumerable<Actor> enemyUnits)
|
||||||
{
|
{
|
||||||
var inputValues = new Dictionary<FuzzyVariable, double>();
|
var inputValues = new Dictionary<FuzzyVariable, double>();
|
||||||
inputValues.Add(fuzzyEngine.InputByName("OwnHealth"), (double)NormalizedHealth(ownUnits, 100));
|
inputValues.Add(fuzzyEngine.InputByName("OwnHealth"), (double)NormalizedHealth(ownUnits, 100));
|
||||||
@@ -176,7 +177,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
result = fuzzyEngine.Calculate(inputValues);
|
result = fuzzyEngine.Calculate(inputValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float NormalizedHealth(List<Actor> actors, float normalizeByValue)
|
protected float NormalizedHealth(IEnumerable<Actor> actors, float normalizeByValue)
|
||||||
{
|
{
|
||||||
var sumOfMaxHp = 0;
|
var sumOfMaxHp = 0;
|
||||||
var sumOfHp = 0;
|
var sumOfHp = 0;
|
||||||
@@ -195,7 +196,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return (sumOfHp * normalizeByValue) / sumOfMaxHp;
|
return (sumOfHp * normalizeByValue) / sumOfMaxHp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float RelativePower(List<Actor> own, List<Actor> enemy)
|
protected float RelativePower(IEnumerable<Actor> own, IEnumerable<Actor> enemy)
|
||||||
{
|
{
|
||||||
return RelativeValue(own, enemy, 100, SumOfValues<AttackBase>, (Actor a) =>
|
return RelativeValue(own, enemy, 100, SumOfValues<AttackBase>, (Actor a) =>
|
||||||
{
|
{
|
||||||
@@ -208,25 +209,25 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float RelativeSpeed(List<Actor> own, List<Actor> enemy)
|
protected float RelativeSpeed(IEnumerable<Actor> own, IEnumerable<Actor> enemy)
|
||||||
{
|
{
|
||||||
return RelativeValue(own, enemy, 100, Average<Mobile>, (Actor a) => a.Trait<Mobile>().Info.Speed);
|
return RelativeValue(own, enemy, 100, Average<Mobile>, (Actor a) => a.Trait<Mobile>().Info.Speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float RelativeValue(List<Actor> own, List<Actor> enemy, float normalizeByValue,
|
protected float RelativeValue(IEnumerable<Actor> own, IEnumerable<Actor> enemy, float normalizeByValue,
|
||||||
Func<List<Actor>, Func<Actor, int>, float> relativeFunc, Func<Actor, int> getValue)
|
Func<IEnumerable<Actor>, Func<Actor, int>, float> relativeFunc, Func<Actor, int> getValue)
|
||||||
{
|
{
|
||||||
if (enemy.Count == 0)
|
if (!enemy.Any())
|
||||||
return 999.0f;
|
return 999.0f;
|
||||||
|
|
||||||
if (own.Count == 0)
|
if (!own.Any())
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
var relative = (relativeFunc(own, getValue) / relativeFunc(enemy, getValue)) * normalizeByValue;
|
var relative = (relativeFunc(own, getValue) / relativeFunc(enemy, getValue)) * normalizeByValue;
|
||||||
return relative.Clamp(0.0f, 999.0f);
|
return relative.Clamp(0.0f, 999.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float SumOfValues<Trait>(List<Actor> actors, Func<Actor, int> getValue)
|
protected float SumOfValues<Trait>(IEnumerable<Actor> actors, Func<Actor, int> getValue)
|
||||||
{
|
{
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
foreach (var a in actors)
|
foreach (var a in actors)
|
||||||
@@ -236,7 +237,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float Average<Trait>(List<Actor> actors, Func<Actor, int> getValue)
|
protected float Average<Trait>(IEnumerable<Actor> actors, Func<Actor, int> getValue)
|
||||||
{
|
{
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
var countActors = 0;
|
var countActors = 0;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
{
|
{
|
||||||
protected const int missileUnitsMultiplier = 3;
|
protected const int missileUnitsMultiplier = 3;
|
||||||
|
|
||||||
protected static int CountAntiAirUnits(List<Actor> units)
|
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
|
||||||
{
|
{
|
||||||
int missileUnitsCount = 0;
|
int missileUnitsCount = 0;
|
||||||
foreach (var unit in units)
|
foreach (var unit in units)
|
||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return base.MayBeFlee(owner, (enemyAroundUnit) =>
|
return base.MayBeFlee(owner, (enemyAroundUnit) =>
|
||||||
{
|
{
|
||||||
int missileUnitsCount = 0;
|
int missileUnitsCount = 0;
|
||||||
if (enemyAroundUnit.Count > 0)
|
if (enemyAroundUnit.Any())
|
||||||
missileUnitsCount = CountAntiAirUnits(enemyAroundUnit);
|
missileUnitsCount = CountAntiAirUnits(enemyAroundUnit);
|
||||||
|
|
||||||
if (missileUnitsCount * missileUnitsMultiplier > owner.units.Count)
|
if (missileUnitsCount * missileUnitsMultiplier > owner.units.Count)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool MayBeFlee(Squad squad, Func<List<Actor>, bool> flee)
|
protected virtual bool MayBeFlee(Squad squad, Func<IEnumerable<Actor>, bool> flee)
|
||||||
{
|
{
|
||||||
if (!squad.IsValid)
|
if (!squad.IsValid)
|
||||||
return false;
|
return false;
|
||||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
if (!enemyAroundUnit.Any())
|
if (!enemyAroundUnit.Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return flee(enemyAroundUnit.ToList());
|
return flee(enemyAroundUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user