// Creates the Spawn Zone and populates its traversable zone tile list // by checking all the tiles within its radius SpawnZone CreateSpawnZone(Pos candidate, float spawnZoneRadius) { SpawnZone spawnZone = new SpawnZone(candidate, spawnZoneRadius, mapManager.GetTileRegion(candidate)); List <Pos> zoneTiles = new List <Pos>(); int cellX = candidate.x; int cellY = candidate.y; int numOfCellsToScan = Mathf.CeilToInt(spawnZoneRadius); int searchStartX = Mathf.Max(0, cellX - numOfCellsToScan); int searchEndX = Mathf.Min(cellX + numOfCellsToScan, width - 1); int searchStartY = Mathf.Max(0, cellY - numOfCellsToScan); int searchEndY = Mathf.Min(cellY + numOfCellsToScan, height - 1); for (int x = searchStartX; x <= searchEndX; x++) { for (int y = searchStartY; y <= searchEndY; y++) { Pos tile = new Pos(x, y); if (mapManager.IsTraversable(tile) && !mapManager.IsOccupied(tile)) { int a = cellX - x; int b = cellY - y; if (Mathf.Sqrt(a * a + b * b) <= spawnZoneRadius) { zoneTiles.Add(tile); } } } } spawnZone.SetZoneTiles(zoneTiles); return(spawnZone); }