Ejemplo n.º 1
0
        private void floodFill(Point startPoint, Biome parentBiome)
        {
            Queue<Point> queue = new Queue<Point>();
            HashSet<Point> queuedPoints = new HashSet<Point>();
            queue.Enqueue(startPoint);
            queuedPoints.Add(startPoint);

            Point currentPoint;
            BiomeMapPixel currentPixel;
            while (queue.Count > 0)
            {
                currentPoint = queue.Dequeue();
                currentPixel = m_data[currentPoint.y, currentPoint.x];
                if (currentPixel.GetPrimaryBiome() == parentBiome.Type)
                {
                    currentPixel.ParentBiome = parentBiome;
                    ++parentBiome.Size;
                    foreach (Point neighbour in currentPoint.Neighbours)
                    {
                        if (neighbour.IsInBounds(0, 0, Size, Size) && GetPixelAtPoint(neighbour).ParentBiome == null && !queuedPoints.Contains(neighbour))
                        {
                            queue.Enqueue(neighbour);
                            queuedPoints.Add(neighbour);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public BiomeMap(TerrainGenerator newTerrainData)
        {
            m_terrainData = newTerrainData;
            m_data = new BiomeMapPixel[Size, Size];

            //Set biome weights for all pixels
            Point position;
            for (int x = 0; x < Size; ++x)
            {
                for (int y = 0; y < Size; ++y)
                {
                    position = new Point(x, y);

                    float heightAboveSeaLevel = m_terrainData.GetHeightAboveSeaLevelAt(position);
                    float latitude = Mathf.Clamp(position.y / (float)m_terrainData.Heightmap.size, 0f, 1f);
                    float precipitation = m_terrainData.Rainmap.GetValueAt(position);

                    m_data[y, x] = new BiomeMapPixel(latitude, heightAboveSeaLevel, precipitation);
                }
            }

            //Iterate through all pixels, setting their parent Biome
            for (int x = 0; x < Size; ++x)
            {
                for (int y = 0; y < Size; ++y)
                {
                    //Ignore pixels that have already had their parent biome set.
                    if (m_data[y, x].ParentBiome != null)
                    {
                        continue;
                    }

                    //Generate a new Biome object from the primary biome type of this pixel.
                    Biome biome = new Biome(m_data[y, x].GetPrimaryBiome());

                    //Flood fill the map with that biome.
                    floodFill(new Point(x, y), biome);

                    //Generate a name for that biome, now that it knows how big it is.
                    biome.GenerateName();
                }
            }
        }
Ejemplo n.º 3
0
        private string generateBiomeTypeName(Biome biome, BiomeData biomeData)
        {
            string[] names;
            if (biome.Size > 10000)
            {
                //Large biome
                names = biomeData.BigNames;
            }
            else if (biome.Size > 1000)
            {
                //Medium biome
                names = biomeData.MediumNames;
            }
            else
            {
                //Small biome
                names = biomeData.SmallNames;
            }

            int nameIndex = UnityEngine.Random.Range(0, names.Length);
            return names[nameIndex];
        }
Ejemplo n.º 4
0
        public string GenerateName(Biome biome)
        {
            BiomeData biomeData = BiomeDatabase.Instance.Get(biome.Type);

            return "The " + firstCharToUpper(generateRandomString()) + " " + generateBiomeTypeName(biome, biomeData);
        }