public static IEnumerable<ILivingObject> FindEnemies(IEnvironmentObject env, IntPoint3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return env.GetContents(rect) .OfType<ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length); }
public static IEnumerable <ILivingObject> FindEnemies(IEnvironmentObject env, IntVector3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return(env.GetContents(rect) .OfType <ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length)); }
public static ILivingObject FindNearestEnemy(IEnvironmentObject env, IntVector3 location, int range, LivingCategory categories) { int maxSide = 2 * range + 1; var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z); return env.GetContents(rect) .OfType<ILivingObject>() .Where(o => (o.LivingCategory & categories) != 0) .OrderBy(o => (location - o.Location).Length) .FirstOrDefault(); }