Example #1
0
        public void Init(LockBitmap bmp, float sizeDelta, GeneratedTerrainMap generatedMap)
        {
            provincesDelta = sizeDelta;
            if (provincesDelta < 0.5f)
            {
                provincesDelta *= 1.8f;
            }

            LoadProvinceColors();
            Color col = FromArgb(255, 1, 0, 0);

            int   r = 1;
            int   g = 0;
            int   b = 0;
            float highmountainLevel = 0.7f;
            float DivNoise          = 1200.0f * (generatedMap.Height / 2048.0f);

            NoiseGenerator noiseH = new NoiseGenerator();

            generatedMap.Map.LockBits();
            generatedMap.MoistureMap.LockBits();
            generatedMap.HeatMap.LockBits();

            SolidBrush br = new SolidBrush(Black);

            using (Graphics gg = Graphics.FromImage(bmp.Source))
            {
                for (int x = 0; x < generatedMap.Map.Width; x++)
                {
                    for (int y = 0; y < generatedMap.Map.Height; y++)
                    {
                        float height = generatedMap.Map.GetHeight(x, y);

                        if (height >= highmountainLevel * 255)
                        {
                            gg.FillEllipse(br, new Rectangle(x - 2, y - 2, 4, 4));
                        }
                    }
                }
            }

            LockBitmap bmp2 = new LockBitmap(new Bitmap(bmp.Source));

            bmp2.LockBits();

            using (Graphics gg = Graphics.FromImage(bmp.Source))
            {
                for (int x = 0; x < generatedMap.Map.Width; x++)
                {
                    for (int y = 0; y < generatedMap.Map.Height; y++)
                    {
                        float heat     = generatedMap.HeatMap.GetHeight(x, y) / 255.0f; // + (Rand.Next(-30, 30) / 8000.0f);
                        float moisture =
                            generatedMap.MoistureMap.GetHeight(x / 4, y / 4) /
                            255.0f; // + (Rand.Next(-30, 30) / 8000.0f);

                        float no = (float)((float)((noiseH.Noise(x / DivNoise / 8, y / DivNoise / 8)) - 0.5f) * 0.2);
                        heat     += no * 1.4f;
                        moisture -= no * 0.5f;

                        float desertLevel = 0.48f;
                        float desertDry   = 0.28f;
                        bool  hot         = heat > desertLevel;
                        bool  dry         = moisture <= desertDry;

                        if (hot && dry && bmp2.GetPixel(x, y) == FromArgb(255, 130, 158, 75))
                        {
                            gg.FillEllipse(br, new Rectangle(x - 5, y - 5, 10, 10));
                        }
                    }
                }
            }

            bmp2.UnlockBits();
            generatedMap.Map.UnlockBits();
            generatedMap.MoistureMap.UnlockBits();
            generatedMap.HeatMap.UnlockBits();
            bmp.LockBits();

            var filler = new UnsafeQueueLinearFloodFiller(null)
            {
                Bitmap = bmp
            };

            Bitmap = bmp;

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    Color pix = bmp.GetPixel(x, y);
                    if (pix == FromArgb(255, 69, 91, 186) || pix == FromArgb(255, 130, 158, 75))
                    {
                        col = setColor(bmp, sizeDelta, col, filler, x, y, pix, ref r, ref g, ref b);
                    }
                }
            }

            provinces = provinces.Distinct().ToList();

            foreach (var province in provinces)
            {
                province.points.Clear();
                colorProvinceMap[province.Color] = province;
            }

            CalculateProvinceColor(bmp);

            CalculateDetails();
            bmp.UnlockDirect();
        }