Example #1
0
        public static string[,] GetChunk()
        {
            ChunksGenerated += 1;
            Log.Write($"Generating map chunk #{ChunksGenerated} ...");
            string[,] ret = new string[ChunkSize, ChunkSize];
            int[,] water  = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 100);
            water         = water.MeanBlur(10).MeanBlur(10).MeanBlur(10);
            water         = water.ChangeVariance(110);
            Log.Write("Generated water.");

            int[,] iron = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            iron        = iron.MedianBlur(10).MedianBlur(10).MeanBlur(10);
            iron        = iron.ChangeVariance(110);
            Log.Write("Generated iron.");

            int[,] copper = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            copper        = copper.MedianBlur(10).MedianBlur(10).MeanBlur(10);
            copper        = copper.ChangeVariance(110);
            Log.Write("Generated copper.");

            int[,] stone = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            stone        = stone.MeanBlur(10).MedianBlur(10).MedianBlur(10);
            stone        = stone.ChangeVariance(110);
            Log.Write("Generated stone.");

            int[,] crystal = NoiseMap.GetNotSmoothedNoise(ChunkSize, ChunkSize, 50);
            crystal        = crystal.MeanBlur(10).MedianBlur(10).MedianBlur(10);
            crystal        = crystal.ChangeVariance(110);
            Log.Write("Generated crystal.");
            Log.Write("Writing chunk ...");
            for (int y = 0; y < ChunkSize; y++)
            {
                for (int x = 0; x < ChunkSize; x++)
                {
                    // make order:
                    // - stone
                    // - coal
                    // - iron/copper ( random if overlap )
                    // - crystal
                    // - water

                    int    w  = water[y, x];
                    int    i  = iron[y, x];
                    int    p  = copper[y, x];
                    int    s  = stone[y, x];
                    int    c  = crystal[y, x];
                    string ps = $"{x},{y}";
                    int    v  = _r.Next(MinimumRichness * ChunksGenerated, MaximumRichness * ChunksGenerated);
                    if (w >= WaterLevel)
                    {
                        ret[y, x] = "|~~~|";
                        Program.AddMapResource(ps, new Resource("Normal Water", _water, ResourceType.Water, 9999999));
                    }
                    else if (c >= CrystalLevel)
                    {
                        ret[y, x] = "|ccc|";
                        Program.AddMapResource(ps, new Resource("Crystal Vein", _crystal, ResourceType.Crystal, v));
                    }
                    else if (i >= IronLevel && _priority == 0)
                    {
                        ret[y, x] = "|iii|";
                        Program.AddMapResource(ps, new Resource("Iron Vein", _iron, ResourceType.Iron, v));
                        _priority = 1;
                    }
                    else if (p >= CopperLevel && _priority == 1)
                    {
                        ret[y, x] = "|ppp|";
                        Program.AddMapResource(ps, new Resource("Copper Vein", _copper, ResourceType.Copper, v));
                        _priority = 0;
                    }
                    else if (p >= CopperLevel && _priority == 0)
                    {
                        ret[y, x] = "|ppp|";
                        Program.AddMapResource(ps, new Resource("Copper Vein", _copper, ResourceType.Copper, v));
                        _priority = 1;
                    }
                    else if (i >= IronLevel && _priority == 1)
                    {
                        ret[y, x] = "|iii|";
                        Program.AddMapResource(ps, new Resource("Iron Vein", _iron, ResourceType.Iron, v));
                        _priority = 0;
                    }
                    else if (s >= StoneLevel)
                    {
                        ret[y, x] = "|sss|";
                        Program.AddMapResource(ps, new Resource("Stone Vein", _stone, ResourceType.Stone, v));
                    }
                    else
                    {
                        ret[y, x] = " ";
                    }
                }
            }
            Log.Write("Finished writing chunk.");
            return(ret);
        }