Ejemplo n.º 1
0
        public void CreateMoistureMap()
        {
            NoiseGenerator noise = new NoiseGenerator();

            MoistureMap.LockBits();
            for (int x = 0; x < MoistureMap.Width; x++)
            {
                for (int y = 0; y < MoistureMap.Height; y++)
                {
                    float orig = (float)noise.Noise(x / DivNoise / 4, y / DivNoise / 4);
                    orig *= orig;
                    float ydel = y / (float)MoistureMap.Height;
                    if (ydel > 0.5f)
                    {
                        ydel -= 0.5f;
                        ydel *= 2.0f;
                    }
                    else
                    {
                        ydel = (0.5f - ydel) * 2.0f;
                    }

                    orig = (orig + orig + ydel) / 3.0f;

                    MoistureMap.SetPixel(x, y, Color.FromArgb(255, (int)(255 * orig), (int)(255 * orig), (int)(255 * orig)));
                }
            }

            MoistureMap.UnlockBits();
            MoistureMap.ResizeImage(Map.Source.Width / 32, Map.Source.Height / 32);
            MoistureMap.ResizeImage(Width, Height);
        }
Ejemplo n.º 2
0
        public void CreateHeatMap()
        {
            NoiseGenerator noise = new NoiseGenerator();

            HeatMap.LockBits();
            for (int x = 0; x < HeatMap.Width; x++)
            {
                for (int y = 0; y < HeatMap.Height; y++)
                {
                    float orig = (float)noise.Noise(x / DivNoise / 4, y / DivNoise / 4);

                    float ydel = y / (float)(HeatMap.Height);

                    if (Globals.Climate == 0)
                    {
                        if (ydel > 0.5f)
                        {
                            ydel -= 0.5f;
                            ydel *= 2.0f;
                        }
                        else
                        {
                            ydel = (0.5f - ydel) * 2.0f;
                        }

                        ydel = 1.0f - ydel;
                    }
                    if (Globals.Climate == 1)
                    {
                        ydel *= 1.3f;
                        if (ydel > 1)
                        {
                            ydel = 1;
                        }
                    }
                    if (Globals.Climate == 2)
                    {
                        ydel *= 1.3f;
                        if (ydel > 1)
                        {
                            ydel = 1;
                        }

                        ydel = 1.0f - ydel;
                    }
                    if (Globals.Climate == 3)
                    {
                        ydel = 0.4f;
                    }
                    if (Globals.Climate == 4)
                    {
                        ydel = 1f;
                    }

                    float o = orig;
                    orig *= ydel;
                    //  ydel *= ydel;

                    orig *= ydel;
                    orig  = (orig + orig + ydel) / 3.0f;


                    orig  = (orig + orig + o) / 3.0f;
                    orig *= orig;
                    if (Globals.Climate == 0)
                    {
                        orig = (orig + orig + orig + orig + orig + ydel) / 6.0f;
                    }
                    if (orig > 1)
                    {
                        orig = 1;
                    }
                    HeatMap.SetPixel(x, y, Color.FromArgb(255, (int)(255 * orig), (int)(255 * orig), (int)(255 * orig)));
                }
            }

            HeatMap.UnlockBits();
            HeatMap.ResizeImage(Map.Source.Width / 16, Map.Source.Height / 16);
            HeatMap.ResizeImage(Map.Source.Width, Map.Source.Height);

            HeatMap.Save24(Globals.MapOutputTotalDir + "heatmap.bmp");
        }
Ejemplo n.º 3
0
        public void Init(LockBitmap bmp, float sizeDelta, GeneratedTerrainMap generatedMap)
        {
            provincesDelta = sizeDelta;
            if (provincesDelta < 0.5f)
            {
                provincesDelta *= 1.8f;
            }

            LoadProvinceColors();
            Color col = Color.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();
            NoiseGenerator noiseM = new NoiseGenerator();

            generatedMap.Map.LockBits();
            generatedMap.MoistureMap.LockBits();
            generatedMap.HeatMap.LockBits();
            SolidBrush br = new SolidBrush(Color.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) == Color.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.Save24(Globals.MapOutputTotalDir + "testprovinces.bmp");
            bmp.LockBits();
            UnsafeQueueLinearFloodFiller filler = new UnsafeQueueLinearFloodFiller(null);

            filler.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 == Color.FromArgb(255, 69, 91, 186) || pix == Color.FromArgb(255, 130, 158, 75))
                    {
                        areaColors.Add(col);
                        filler.FillColor = col;
                        filler.FloodFill(new Point(x, y));

                        bool valid = false;
                        foreach (var point in filler.pts)
                        {
                            for (int yy = -1; yy <= 1; yy++)
                            {
                                for (int xx = -1; xx <= 1; xx++)
                                {
                                    if (xx == 0 && yy == 0)
                                    {
                                        continue;
                                    }
                                    if (point.X + xx < 0 || point.Y + yy < 0 || point.X + xx >= bmp.Width || point.Y + yy >= bmp.Height)
                                    {
                                        continue;
                                    }

                                    var ccc = bmp.GetPixel(xx + point.X, yy + point.Y);
                                    if (col.R == ccc.R && ccc.G == col.G && ccc.B == col.B)
                                    {
                                        continue;
                                    }
                                    if (ccc.R > 0 || ccc.G > 0 || ccc.B > 0)
                                    {
                                        valid = true;
                                    }
                                }
                            }
                        }

                        if (!valid)
                        {
                            filler.FillColor = Color.Black;
                            filler.FloodFill(new Point(x, y));
                            continue;
                        }

                        {
                            int numProvinces = (int)(filler.pts.Count / (3000));
                            if (pix == Color.FromArgb(255, 130, 158, 75))
                            {
                                numProvinces = (int)(numProvinces * sizeDelta);
                            }
                            if (numProvinces == 0)
                            {
                                numProvinces = 1;
                            }
                            if (pix != Color.FromArgb(255, 130, 158, 75))
                            {
                                numProvinces /= 6;
                                if (numProvinces < 1)
                                {
                                    numProvinces = 1;
                                }
                            }
                            CreateProvinces(numProvinces, col, filler.pts, bmp.Width, bmp.Height, bmp, pix != Color.FromArgb(255, 130, 158, 75));
                            FixupProvinces(col, filler, bmp);
                        }
                        r += 1;
                        if (r > 255)
                        {
                            r  = 0;
                            g += 1;
                        }
                        if (g > 255)
                        {
                            g  = 0;
                            b += 1;
                        }
                        col = Color.FromArgb(255, r, g, b);
                    }
                }
            }
            provinces = provinces.Distinct().ToList();
            foreach (var province in provinces)
            {
                province.points.Clear();
                colorProvinceMap[province.Color] = province;
            }
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    Color pix = bmp.GetPixel(x, y);
                    if (colorProvinceMap.ContainsKey(pix))
                    {
                        colorProvinceMap[pix].points.Add(new Point(x, y));
                    }
                    else
                    {
                    }
                }
            }

            CalculateDetails();

            bmp.UnlockDirect();


            //    bmp.Save24("C:\\Users\\LEMMY\\Documents\\terrainNew.bmp");
        }
Ejemplo n.º 4
0
        private void CreateTerrainMap()
        {
            MoistureMap.ResizeImage(Map.Width, Map.Height);
            HeatMap.LockBits();
            MoistureMap.LockBits();
            Map.LockBits();
            Trees.LockBits();
            TerrainMap.LockBits();
            MapGenManager.instance.ProvinceMap.LockBits();
            NoiseGenerator noiseH = new NoiseGenerator();
            NoiseGenerator noiseM = new NoiseGenerator();

            noiseM.Octaves = 4;
            for (int x = 0; x < Map.Width; x++)
            {
                for (int y = 0; y < Map.Height; y++)
                {
                    Color col      = Color.AliceBlue;
                    float heat     = GetHeat(x, y);             // + (Rand.Next(-30, 30) / 8000.0f);
                    float moisture = GetMoisture(x * 4, y * 4); // + (Rand.Next(-30, 30) / 8000.0f);
                    float no       = (float)((float)((noiseH.Noise(x / DivNoise / 8, y / DivNoise / 8)) - 0.5f) * 0.2);
                    float tree     = (float)((float)((noiseM.Noise(x / DivNoise, y / DivNoise)) - 0.5f));

                    tree     += no * 12.0f;
                    heat     += no * 3.0f;
                    moisture -= no * 3.0f;

                    float height = Map.GetHeight(x, y) / 255.0f;

                    float desertLevel        = 0.48f;
                    float shyDesertLevel     = 0.43f;
                    float desertDry          = 0.6f;
                    float shyDry             = 0.62f;
                    float coastalDesertLevel = 0.7f;
                    float tundraWetLevel     = 0.25f;

                    float jungleLevel = 0.8f;
                    float arcticLevel = 0.13f;

                    float hillLevel         = 0.55f;
                    float mountainLevel     = 0.60f;
                    float highmountainLevel = 0.8f;

                    heat     += height / 8.0f;
                    moisture -= height / 8.0f;
                    float sealevel = (98 / 255.0f);
                    tree += (height - sealevel) * 2.3f;
                    tree += moisture * 1.9f;

                    bool hot         = heat > desertLevel;
                    bool slightlyHot = !hot && heat > shyDesertLevel;
                    bool cold        = heat < arcticLevel;
                    bool wet         = moisture > coastalDesertLevel;
                    bool dry         = moisture < desertDry;
                    bool nearlyDry   = moisture < desertDry;
                    bool wetCold     = moisture > tundraWetLevel;
                    bool sea         = Color.FromArgb(255, 69, 91, 186) == TerrainMap.GetPixel(x, y);
                    bool trees       = tree > 0.99f;
                    bool temptrees   = tree > 0.99f;
                    if (sea)
                    {
                        col = SeaColor;
                    }
                    else
                    {
                        if (hot || slightlyHot)
                        {
                            if (wet)
                            {
                                col = Color.FromArgb(255, 40, 180, 149);

                                if (trees && wet)
                                {
                                    float dx = x / (float)Width;
                                    float dy = y / (float)Height;
                                    int   tx = (int)(Trees.Width * dx);
                                    int   ty = (int)(Trees.Height * dy);
                                    if (Rand.Next(2) == 0)
                                    {
                                        if (height > 107 / 255.0f)
                                        {
                                            Trees.SetPixel(tx, ty, Color.FromArgb(255, 154, 156, 51));
                                        }
                                    }
                                }
                            }
                            else if (hot && dry)
                            {
                                col = DesertSandColor;
                            }
                            else if (slightlyHot && dry)
                            {
                                col = SandyGrassColor;
                            }
                            else
                            {
                                if (nearlyDry)
                                {
                                    col = DesertSandColor;
                                }
                                else
                                {
                                    col = TemperateGrassColor;
                                }
                            }
                        }
                        else if (cold)
                        {
                            col = NorthernGrassColor;

                            if (temptrees)
                            {
                                col = Color.FromArgb(255, 0, 86, 6);

                                float dx = x / (float)Width;
                                float dy = y / (float)Height;
                                int   tx = (int)(Trees.Width * dx);
                                int   ty = (int)(Trees.Height * dy);
                                if (Rand.Next(4) == 0)
                                {
                                    if (height > 107 / 255.0f)
                                    {
                                        Trees.SetPixel(tx, ty, Color.FromArgb(255, 30, 139, 109));
                                    }
                                }
                            }
                            else
                            {
                                if (Rand.Next(18) == 0)
                                {
                                    float dx = x / (float)Width;
                                    float dy = y / (float)Height;
                                    int   tx = (int)(Trees.Width * dx);
                                    int   ty = (int)(Trees.Height * dy);
                                    if (height > 107 / 255.0f)
                                    {
                                        Trees.SetPixel(tx, ty, Color.FromArgb(255, 30, 139, 109));
                                    }
                                }
                            }
                        }
                        else
                        {
                            col = TemperateGrassColor;

                            if (temptrees)
                            {
                                col = TemperateForestColor;
                                float dx = x / (float)Width;
                                float dy = y / (float)(Height);
                                int   tx = (int)(Trees.Width * dx);
                                int   ty = (int)(Trees.Height * dy);
                                if (Rand.Next(4) == 0)
                                {
                                    if (height > 107 / 255.0f)
                                    {
                                        Trees.SetPixel(tx, ty, Color.FromArgb(255, 76, 156, 51));
                                    }
                                }
                            }
                            else
                            {
                                if (Rand.Next(18) == 0)
                                {
                                    float dx = x / (float)Width;
                                    float dy = y / (float)Height;
                                    int   tx = (int)(Trees.Width * dx);
                                    int   ty = (int)(Trees.Height * dy);
                                    if (height > 107 / 255.0f)
                                    {
                                        Trees.SetPixel(tx, ty, Color.FromArgb(255, 76, 156, 51));
                                    }
                                }
                            }
                        }


                        //   height += no * 2.0f;
                        //     height -= sealevel;

                        if (height > highmountainLevel)
                        {
                            if (hot)
                            {
                                col = SandMountainColor;
                            }
                            else
                            {
                                col = SnowMountainTopColor;
                            }
                        }

                        else if (height > mountainLevel)
                        {
                            if (hot)
                            {
                                col = HillsDesertColor;
                            }
                            else
                            {
                                col = MountainRockColor;
                            }
                        }
                        else if (height > hillLevel)
                        {
                            if (hot)
                            {
                            }
                            else
                            {
                                col = SteppesColor;
                            }
                        }
                        else
                        {
                            var ccol = MapGenManager.instance.ProvinceMap.GetPixel(x, y);

                            if (ccol.R == 0 && ccol.G == 0 && ccol.B == 0)
                            {
                                if (!hot && !slightlyHot)
                                {
                                    col = SteppesColor;
                                }
                                else
                                {
                                    col = DesertSandColor;
                                    float dx = x / (float)Width;
                                    float dy = y / (float)(Height);
                                    int   tx = (int)(Trees.Width * dx);
                                    int   ty = (int)(Trees.Height * dy);
                                    Trees.SetPixel(tx, ty, Color.FromArgb(255, 0, 0, 0));
                                }
                            }
                        }
                    }

                    TerrainMap.SetPixel(x, y, col);
                }
            }

            MapGenManager.instance.ProvinceMap.UnlockBits();
            TerrainMap.UnlockBits();
            HeatMap.UnlockBits();
            MoistureMap.UnlockBits();

            MoistureMap.Source.Dispose();
            //  HeatMap.Source.Dispose();
            //  HeatMap = null;
            MoistureMap = null;
            HeatMap.Source.Dispose();
            HeatMap = null;
            Map.UnlockBits();
            Trees.UnlockBits();
        }
Ejemplo n.º 5
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();
        }