コード例 #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);
        }
コード例 #2
0
        public void AdjustMoistureMap()
        {
            MoistureMap.LockBits();
            Map.LockBits();
            for (int x = 0; x < MoistureMap.Width; x++)
            {
                for (int y = 0; y < MoistureMap.Height; y++)
                {
                    float orig = (float)MoistureMap.GetPixel(x, y).R / 255.0f;

                    float height = Map.GetHeight(x * 4, y * 4) / 255.0f;
                    if (height * 255.0f < 102)
                    {
                        orig = 1.0f;
                    }
                    if (orig > 1.0f)
                    {
                        orig = 1.0f;
                    }

                    height = 1.0f - height;
                    if (height > 0.54f)
                    {
                        orig = (orig + orig + 1) / 3.0f;
                    }

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

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

            //    MoistureMap.Save24(Globals.MapOutputTotalDir + "moisture.bmp");
        }
コード例 #3
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();
        }