private void SmoothBiom(Vector2Int pos) { int countOfSameBiom = 0; List <Vector2Int> neighbours = new List <Vector2Int>(); Vector2Int last; if (map.IsOnMap(last = new Vector2Int(pos.X - 1, pos.Y))) { if (map[pos.Y, pos.X].Biom == map[pos.Y, pos.X - 1].Biom) { countOfSameBiom++; } neighbours.Add(last); } if (map.IsOnMap(last = new Vector2Int(pos.X, pos.Y - 1))) { if (map[pos.Y, pos.X].Biom == map[pos.Y - 1, pos.X].Biom) { countOfSameBiom++; } neighbours.Add(last); } if (map.IsOnMap(last = new Vector2Int(pos.X + 1, pos.Y))) { if (map[pos.Y, pos.X].Biom == map[pos.Y, pos.X + 1].Biom) { countOfSameBiom++; } neighbours.Add(last); } if (map.IsOnMap(last = new Vector2Int(pos.X, pos.Y + 1))) { if (map[pos.Y, pos.X].Biom == map[pos.Y + 1, pos.X].Biom) { countOfSameBiom++; } neighbours.Add(last); } if (countOfSameBiom < 2) { BiomModel mostFrequentBiom = neighbours.GroupBy(x => map[x.Y, x.X].Biom) .Select(x => new { biom = x, cnt = x.Count() }) .OrderByDescending(g => g.cnt) .Select(g => g.biom).First().Key; map[pos.Y, pos.X].Biom = mostFrequentBiom; neighbours.ForEach(x => positionToCheck.Push(x)); } }
private void SmoothWater(Vector2Int pos) { List <Vector2Int> neighbourPos = new List <Vector2Int>(); int countOfNeighbourBlock = 0; int countOfNeighbourEmpty = 0; int countOfNeighbour = 0; for (int i = pos.Y - 1; i <= pos.Y + 1; ++i) { for (int j = pos.X - 1; j <= pos.X + 1; ++j) { if (i != pos.Y || j != pos.X) { if (map.IsOnMap(new Vector2Int(j, i))) { if (map[i, j].HasWaterBiom) { countOfNeighbourBlock++; if ((i - pos.Y + 1 == j - pos.X) || (j - pos.X + 1 == i - pos.Y)) { countOfNeighbour++; } } else { countOfNeighbourEmpty++; } neighbourPos.Add(new Vector2Int(j, i)); } } } } if (countOfNeighbourEmpty == 5 && map[pos.Y, pos.X].HasWaterBiom) //Delete corner block { map[pos.Y, pos.X].WaterBiom = null; neighbourPos.ForEach(x => positionToCheck.Push(x)); } else if (countOfNeighbourBlock == 5 && !map[pos.Y, pos.X].HasWaterBiom) //Add corner block { map[pos.Y, pos.X].WaterBiom = GetWaterBiom(map[pos.Y, pos.X].WaterDeepness); neighbourPos.ForEach(x => positionToCheck.Push(x)); } else if (countOfNeighbour < 2 && map[pos.Y, pos.X].HasWaterBiom) { map[pos.Y, pos.X].WaterBiom = null; neighbourPos.ForEach(x => positionToCheck.Push(x)); } else if (countOfNeighbour > 2 && !map[pos.Y, pos.X].HasWaterBiom) { map[pos.Y, pos.X].WaterBiom = GetWaterBiom(map[pos.Y, pos.X].WaterDeepness); neighbourPos.ForEach(x => positionToCheck.Push(x)); } }