private Dictionary<Vector2, Tile> GetTilesInRadiusGeneric(
Vector2 center, int distance
, Func<Vector2, Dictionary<Vector2, Tile>> neighborsFunc
, Func<Vector2, Vector2, int> distanceFunc
)
{
var ret = new Dictionary<Vector2, Tile>();
if (distance <= 0) return ret;
var frontier = new List<Vector2>();
frontier.Add(center);
while (frontier.Count > 0)
{
var current = frontier[0];
frontier.RemoveAt(0);
if (!ret.ContainsKey(current))
{
ret.Add(current, mapModel.tiles[current]);
}
var neighbors = neighborsFunc(current);
foreach (var neighbor in neighbors)
{
//add the neighbor to explore if it's not already being returned
//or in the queue or too far away
if (
!ret.ContainsKey(neighbor.Key)
&& !frontier.Contains(neighbor.Key)
&& distanceFunc(neighbor.Key, center) <= distance
)
{
frontier.Add(neighbor.Key);
}
}
}
return ret;
}