Пример #1
0
 private static void InitializePreviewRenderTypes()
 {
     if (PreviewRenderTypes != null)
     {
         return;
     }
     PreviewRenderTypes = new Dictionary <string, PreviewRenderType>();
     PreviewRenderTypes.Add("Height",
                            new PreviewRenderType("Height", Overworld.ScalarFieldType.Height,
                                                  (g) => Overworld.HeightColors));
     PreviewRenderTypes.Add("Biomes",
                            new PreviewRenderType("Biomes", Overworld.ScalarFieldType.Height,
                                                  (g) => BiomeLibrary.CreateBiomeColors()));
     PreviewRenderTypes.Add("Temperature",
                            new PreviewRenderType("Gray", Overworld.ScalarFieldType.Temperature,
                                                  (g) => Overworld.JetColors));
     PreviewRenderTypes.Add("Rain",
                            new PreviewRenderType("Gray", Overworld.ScalarFieldType.Rainfall,
                                                  (g) => Overworld.JetColors));
     PreviewRenderTypes.Add("Erosion",
                            new PreviewRenderType("Gray", Overworld.ScalarFieldType.Erosion,
                                                  (g) => Overworld.JetColors));
     PreviewRenderTypes.Add("Faults",
                            new PreviewRenderType("Gray", Overworld.ScalarFieldType.Faults,
                                                  (g) => Overworld.JetColors));
     PreviewRenderTypes.Add("Factions",
                            new PreviewRenderType("Factions", Overworld.ScalarFieldType.Factions,
                                                  (g) =>
     {
         Overworld.NativeFactions = g.NativeCivilizations;
         return(g.GenerateFactionColors());
     }));
 }
Пример #2
0
        public void GenerateVolcanoes(int width, int height)
        {
            int   volcanoSamples = 4;
            float volcanoSize    = 11;

            for (int i = 0; i < (int)Settings.NumVolcanoes; i++)
            {
                Vector2 randomPos = new Vector2((float)(MathFunctions.Random.NextDouble() * width), (float)(MathFunctions.Random.NextDouble() * height));
                float   maxFaults = Overworld.Map[(int)randomPos.X, (int)randomPos.Y].Height;
                for (int j = 0; j < volcanoSamples; j++)
                {
                    Vector2 randomPos2 = new Vector2((float)(MathFunctions.Random.NextDouble() * width), (float)(MathFunctions.Random.NextDouble() * height));
                    float   faults     = Overworld.Map[(int)randomPos2.X, (int)randomPos2.Y].Height;

                    if (faults > maxFaults)
                    {
                        randomPos = randomPos2;
                        maxFaults = faults;
                    }
                }

                Overworld.Volcanoes.Add(randomPos);


                for (int dx = -(int)volcanoSize; dx <= (int)volcanoSize; dx++)
                {
                    for (int dy = -(int)volcanoSize; dy <= (int)volcanoSize; dy++)
                    {
                        int x = (int)MathFunctions.Clamp(randomPos.X + dx, 0, width - 1);
                        int y = (int)MathFunctions.Clamp(randomPos.Y + dy, 0, height - 1);

                        float dist  = (float)Math.Sqrt(dx * dx + dy * dy);
                        float fDist = (float)Math.Sqrt((dx / 3.0f) * (dx / 3.0f) + (dy / 3.0f) * (dy / 3.0f));

                        //Overworld.Map[x, y].Erosion = MathFunctions.Clamp(dist, 0.0f, 0.5f);
                        float f = (float)(Math.Pow(Math.Sin(fDist), 3.0f) + 1.0f) * 0.2f;
                        Overworld.Map[x, y].Height += f;

                        if (dist <= 2)
                        {
                            Overworld.Map[x, y].Water = Overworld.WaterType.Volcano;
                        }

                        if (dist < volcanoSize)
                        {
                            Overworld.Map[x, y].Biome = BiomeLibrary.GetBiome("Waste").Biome;
                        }
                    }
                }
            }
        }
Пример #3
0
        public void DisplayModeModified(string type)
        {
            if (!GenerationComplete)
            {
                return;
            }

            switch (type)
            {
            case "Height":
                ColorKeys.ColorEntries = Overworld.HeightColors;
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Height, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Biomes":
                ColorKeys.ColorEntries = BiomeLibrary.CreateBiomeColors();
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Height, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Temp.":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Temperature, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Rain":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Rainfall, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Erosion":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Erosion, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Faults":
                ColorKeys.ColorEntries = Overworld.JetColors;
                Overworld.TextureFromHeightMap("Gray", Overworld.Map, Overworld.ScalarFieldType.Faults, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;

            case "Factions":
                ColorKeys.ColorEntries   = GenerateFactionColors();
                Overworld.NativeFactions = NativeCivilizations;
                Overworld.TextureFromHeightMap(type, Overworld.Map, Overworld.ScalarFieldType.Factions, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                break;
            }
        }
Пример #4
0
        public void GrowCivs(Overworld.MapData[,] map, int iters, List <Faction> civs)
        {
            int width  = map.GetLength(0);
            int height = map.GetLength(1);

            byte[]  neighbors       = new byte[] { 0, 0, 0, 0 };
            float[] neighborheights = new float[] { 0, 0, 0, 0 };
            Point[] deltas          = new Point[] { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(1, -1) };
            for (int i = 0; i < iters; i++)
            {
                for (int x = 1; x < width - 1; x++)
                {
                    for (int y = 1; y < height - 1; y++)
                    {
                        bool isUnclaimed = map[x, y].Faction == 0;
                        bool isWater     = map[x, y].Height < Settings.SeaLevel;
                        if (!isUnclaimed && !isWater)
                        {
                            neighbors[0]       = map[x + 1, y].Faction;
                            neighbors[1]       = map[x, y + 1].Faction;
                            neighbors[2]       = map[x - 1, y].Faction;
                            neighbors[3]       = map[x, y - 1].Faction;
                            neighborheights[0] = map[x + 1, y].Height;
                            neighborheights[1] = map[x, y + 1].Height;
                            neighborheights[2] = map[x - 1, y].Height;
                            neighborheights[3] = map[x, y - 1].Height;

                            int   minNeighbor = -1;
                            float minHeight   = float.MaxValue;

                            for (int k = 0; k < 4; k++)
                            {
                                if (neighbors[k] == 0 && neighborheights[k] < minHeight && neighborheights[k] > Settings.SeaLevel)
                                {
                                    minHeight   = neighborheights[k];
                                    minNeighbor = k;
                                }
                            }

                            if (minNeighbor >= 0 && MathFunctions.RandEvent(0.25f / (neighborheights[minNeighbor] + 1e-2f)))
                            {
                                var faction = map[x, y].Faction;
                                map[x + deltas[minNeighbor].X, y + deltas[minNeighbor].Y].Faction = faction;
                                var biome     = map[x + deltas[minNeighbor].X, y + deltas[minNeighbor].Y].Biome;
                                var biomeName = BiomeLibrary.Biomes[biome].Name;
                                var myFaction = civs[faction - 1];
                                if (myFaction.Race.Biomes.ContainsKey(biomeName))
                                {
                                    map[x + deltas[minNeighbor].X, y + deltas[minNeighbor].Y].Biome =
                                        BiomeLibrary.GetBiome(myFaction.Race.Biomes[biomeName]).Biome;
                                }
                            }
                        }
                    }
                }
            }

            foreach (var civ in NativeCivilizations)
            {
                civ.Center = new Point(0, 0);
            }

            for (int x = 1; x < width - 1; x++)
            {
                for (int y = 1; y < height - 1; y++)
                {
                    byte f = map[x, y].Faction;
                    if (f > 0)
                    {
                        civs[f - 1].Center = new Point(x + civs[f - 1].Center.X, y + civs[f - 1].Center.Y);
                        civs[f - 1].TerritorySize++;
                    }
                }
            }

            foreach (Faction f in civs)
            {
                if (f.TerritorySize > 0)
                {
                    f.Center = new Point(f.Center.X / f.TerritorySize, f.Center.Y / f.TerritorySize);
                }
            }
        }