/// <summary> /// Enumerates all cells within a given distance from cellId /// </summary> /// <param name="cellId"></param> /// <param name="distanceMax"></param> /// <returns></returns> public int[] FindCellsAround(int cellId, int distanceMax, bool WalkableOnly, bool LOSNeeded = false) { List <int> result = new List <int>(); if (LOSNeeded && ((_map == null))) { throw new TypeAccessException("IMap is not a Map"); } int x = _cells[cellId].X; int y = _cells[cellId].Y; for (int px = x - distanceMax; px <= x + distanceMax; px++) { for (int py = y - distanceMax; py <= y + distanceMax; py++) { //if (px >= 0 && py >= 0 && px <= CellInfo.MAP_SIZE && py <= CellInfo.MAP_SIZE) // Within map if ((Math.Abs(x - px) + Math.Abs(y - py)) <= distanceMax) // Close enough { int newCell = CellInfo.CellIdFromPos(px, py); if (newCell != CellInfo.CELL_ERROR) { if (!WalkableOnly || _cells[newCell].IsWalkable) { if (!LOSNeeded || _map.CanBeSeen(_cells[cellId].Cell, _cells[newCell].Cell)) { result.Add(newCell); } } } } } } return(result.ToArray()); }