示例#1
0
        public virtual void RegenerateCells()
        {
            if (pool == null)
            {
                pool = new NoisePool();
            }

            Clear();
            CreateCells();
        }
示例#2
0
        public override void RegenerateCells()
        {
            config = GetComponent <HexGenConfig>();

            Clear();

            if (pool == null)
            {
                pool = new NoisePool();
            }

            cells = new HexCell[height * width];

            InitializeNoise();

            for (int z = 0, i = 0; z < height; z++)
            {
                for (int x = 0; x < width; x++)
                {
                    int elevation = (int)(noises[i] * 9) % 9 - 2;
                    // force top create inpassable tile
                    if (elevation >= 5)
                    {
                        elevation += pool.Next() > .5 ? 1 : 2;
                    }

                    CreateCell(x, z, i, elevation);
                    SetHexCellColor(cells[i]);
                    SetGrass(cells[i]);

                    i++;
                }
            }

            if (config.generateTribe)
            {
                InitializeTribeNoise();

                foreach (HexCell cell in cells)
                {
                    SetTribe(cell);
                }

                foreach (HexCell cell in cells)
                {
                    SetWall(cell);
                }
            }

            SetWaterSurface();
        }
示例#3
0
        protected void InitializeTribeNoise()
        {
            float layerWeight = NoisePool.NoiseLayerInitialWeight(config.noiseLayers);

            tribeNoise = new float[width * height];

            for (int layer = 1; layer <= config.noiseLayers; layer++)
            {
                float scale  = config.noiseScale * layer * layer;
                float weight = layerWeight * Mathf.Pow(.25f, layer - 1);

                float[] layered;
                float   seed = pool.Next() * 1000;

                layered = NoisePool.Cellular(width, height, scale, seed);

                for (int i = 0; i < noises.Length; i++)
                {
                    tribeNoise[i] += layered[i] * weight;
                }
            }
        }
示例#4
0
        protected void InitializeNoise()
        {
            noises = new float[width * height];

            float layerWeight = NoisePool.NoiseLayerInitialWeight(config.noiseLayers);

            for (int layer = 1; layer <= config.noiseLayers; layer++)
            {
                float scale  = config.noiseScale * layer * layer;
                float weight = layerWeight * Mathf.Pow(.25f, layer - 1);

                float[] layered;
                float   seed = pool.Next() * 1000;

                switch (config.noiseType)
                {
                case NoiseType.Perlin:
                    layered = NoisePool.Perlin(width, height, scale, seed);
                    break;

                case NoiseType.Simplex:
                    layered = NoisePool.Simplex(width, height, scale, seed);
                    break;

                case NoiseType.Cellular:
                    layered = NoisePool.Cellular(width, height, scale, seed);
                    break;

                default:
                    layered = NoisePool.Perlin(width, height, scale, seed);
                    break;
                }

                for (int i = 0; i < noises.Length; i++)
                {
                    noises[i] += layered[i] * weight;
                }
            }
        }