28 lines
815 B
C#
28 lines
815 B
C#
using System.Collections.Generic;
|
|
using Gameplay.AI;
|
|
using Gameplay.Unit;
|
|
|
|
public static class AITargetFinder
|
|
{
|
|
public static Dictionary<GameUnit, int> FindUnits(GameUnit owner, List<GameUnit> candidates, IAITargetFilter filter)
|
|
{
|
|
var results = new Dictionary<GameUnit, int>(candidates.Count);
|
|
|
|
var ownerCell = owner.transData?.cellIndex;
|
|
if (!ownerCell.HasValue) return results;
|
|
|
|
foreach (var unit in candidates)
|
|
{
|
|
var cell = unit.transData?.cellIndex;
|
|
if (!cell.HasValue) continue;
|
|
|
|
if (filter.IsValid(unit))
|
|
{
|
|
int distance = AIUtils.GetDistance(ownerCell.Value, cell.Value);
|
|
results[unit] = distance;
|
|
}
|
|
}
|
|
|
|
return results;
|
|
}
|
|
} |