Exemplo n.º 1
0
        public void GenerateWorld(int seed, int width, int height)
        {
            #if CREATE_CRASH_LOGS
               try
            #endif
            {
                GUI.MouseMode = GUISkin.MousePointer.Wait;

                PlayState.Random = new ThreadSafeRandom(Seed);
                GenerationComplete = false;

                LoadingMessage = "Init..";
                Overworld.heightNoise.Seed = Seed;
                worldMap = new Texture2D(Game.GraphicsDevice, width, height);
                worldData = new Color[width * height];
                Overworld.Map = new Overworld.MapData[width, height];

                Progress.Value = 0.01f;

                LoadingMessage = "Height Map ...";
                Overworld.GenerateHeightMap(width, height, 1.0f, false);

                Progress.Value = 0.05f;

                int numRains = (int)Settings.NumRains;
                int rainLength = 250;
                int numRainSamples = 3;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Erosion = 1.0f;
                        Overworld.Map[x, y].Weathering = 0;
                        Overworld.Map[x, y].Faults = 1.0f;
                    }
                }

                LoadingMessage = "Climate";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = ((float)(y) / (float)(height)) * Settings.TemperatureScale;
                        //Overworld.Map[x, y].Rainfall = Math.Max(Math.Min(Overworld.noise(x, y, 1000.0f, 0.01f) + Overworld.noise(x, y, 100.0f, 0.1f) * 0.05f, 1.0f), 0.0f) * RainfallScale;
                    }
                }

                //Overworld.Distort(width, height, 60.0f, 0.005f, Overworld.ScalarFieldType.Rainfall);
                Overworld.Distort(width, height, 30.0f, 0.005f, Overworld.ScalarFieldType.Temperature);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map[x, y].Temperature, 1.0f), 0.0f);
                    }
                }

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                int numVoronoiPoints = (int)Settings.NumFaults;

                Progress.Value = 0.1f;
                LoadingMessage = "Faults ...";

                #region voronoi

                Voronoi(width, height, numVoronoiPoints);

                #endregion

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.2f;

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.25f;
                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                LoadingMessage = "Erosion...";

                #region erosion

                float[,] buffer = new float[width, height];
                Erode(width, height, Settings.SeaLevel, Overworld.Map, numRains, rainLength, numRainSamples, buffer);
                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                #endregion

                Progress.Value = 0.9f;

                LoadingMessage = "Blur.";
                Overworld.Blur(Overworld.Map, width, height, Overworld.ScalarFieldType.Erosion);

                LoadingMessage = "Generate height.";
                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                LoadingMessage = "Rain";
                CalculateRain(width, height);

                LoadingMessage = "Biome";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Biome = Overworld.GetBiome(Overworld.Map[x, y].Temperature, Overworld.Map[x, y].Rainfall, Overworld.Map[x, y].Height);
                    }
                }

                LoadingMessage = "Volcanoes";

                GenerateVolcanoes(width, height);

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                LoadingMessage = "Factions";
                NativeCivilizations = new List<Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < Settings.NumCivilizations; i++)
                {
                    NativeCivilizations.Add(library.GenerateFaction(i, Settings.NumCivilizations));
                }
                SeedCivs(Overworld.Map, Settings.NumCivilizations, NativeCivilizations);
                GrowCivs(Overworld.Map, 200, NativeCivilizations);

                for (int x = 0; x < width; x++)
                {
                    Overworld.Map[x, 0] = Overworld.Map[x, 1];
                    Overworld.Map[x, height - 1] = Overworld.Map[x, height - 2];
                }

                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[0, y] = Overworld.Map[1, y];
                    Overworld.Map[width - 1, y] = Overworld.Map[width - 2, y];
                }

                GenerationComplete = true;

                MapPanel.Image = new ImageFrame(worldMap, new Rectangle(0, 0, worldMap.Width, worldMap.Height));
                MapPanel.LocalBounds = new Rectangle(300, 30, worldMap.Width, worldMap.Height);

                Progress.Value = 1.0f;
                IsGenerating = false;
                GUI.MouseMode = GUISkin.MousePointer.Pointer;
                DoneGenerating = true;
            }
            #if CREATE_CRASH_LOGS
            catch (Exception exception)
            {
                ProgramData.WriteExceptionLog(exception);
                throw;
            }
            #endif
        }
Exemplo n.º 2
0
        public void MakeDebugWorldMenu()
        {
            GuiRoot.RootItem.Clear();

            var frame = MakeMenuFrame("DEBUG WORLDS");

            MakeMenuItem(frame, "Hills", "Create a hilly world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateHillsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Cliffs", "Create a cliff-y world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateCliffsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;
                PlayState.Natives      = new List <Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < 10; i++)
                {
                    PlayState.Natives.Add(library.GenerateFaction(i, 10));
                }

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Flat", "Create a flat world.", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateUniformLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Ocean", "Create an ocean world", (sender, args) =>
            {
                MaintainState = false;
                Overworld.CreateOceanLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                //GUI.MouseMode = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            });

            MakeMenuItem(frame, "Back", "Go back to the main menu.", (sender, args) => MakeDefaultMenu());

            GuiRoot.RootItem.Layout();
        }
Exemplo n.º 3
0
        public void GenerateWorld(int seed, int width, int height)
        {
#if CREATE_CRASH_LOGS
            try
#endif
            {
                GUI.MouseMode = GUISkin.MousePointer.Wait;

                PlayState.Random   = new ThreadSafeRandom(Seed);
                GenerationComplete = false;

                LoadingMessage             = "Init..";
                Overworld.heightNoise.Seed = Seed;
                worldMap      = new Texture2D(Game.GraphicsDevice, width, height);
                worldData     = new Color[width * height];
                Overworld.Map = new Overworld.MapData[width, height];

                Progress.Value = 0.01f;

                LoadingMessage = "Height Map ...";
                Overworld.GenerateHeightMap(width, height, 1.0f, false);

                Progress.Value = 0.05f;

                int numRains       = (int)Settings.NumRains;
                int rainLength     = 250;
                int numRainSamples = 3;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Erosion    = 1.0f;
                        Overworld.Map[x, y].Weathering = 0;
                        Overworld.Map[x, y].Faults     = 1.0f;
                    }
                }

                LoadingMessage = "Climate";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = ((float)(y) / (float)(height)) * Settings.TemperatureScale;
                        //Overworld.Map[x, y].Rainfall = Math.Max(Math.Min(Overworld.noise(x, y, 1000.0f, 0.01f) + Overworld.noise(x, y, 100.0f, 0.1f) * 0.05f, 1.0f), 0.0f) * RainfallScale;
                    }
                }

                //Overworld.Distort(width, height, 60.0f, 0.005f, Overworld.ScalarFieldType.Rainfall);
                Overworld.Distort(width, height, 30.0f, 0.005f, Overworld.ScalarFieldType.Temperature);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map[x, y].Temperature, 1.0f), 0.0f);
                    }
                }

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                int numVoronoiPoints = (int)Settings.NumFaults;


                Progress.Value = 0.1f;
                LoadingMessage = "Faults ...";

                #region voronoi

                Voronoi(width, height, numVoronoiPoints);

                #endregion

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.2f;

                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                Progress.Value = 0.25f;
                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);
                LoadingMessage = "Erosion...";

                #region erosion

                float[,] buffer = new float[width, height];
                Erode(width, height, Settings.SeaLevel, Overworld.Map, numRains, rainLength, numRainSamples, buffer);
                Overworld.GenerateHeightMap(width, height, 1.0f, true);

                #endregion

                Progress.Value = 0.9f;


                LoadingMessage = "Blur.";
                Overworld.Blur(Overworld.Map, width, height, Overworld.ScalarFieldType.Erosion);

                LoadingMessage = "Generate height.";
                Overworld.GenerateHeightMap(width, height, 1.0f, true);


                LoadingMessage = "Rain";
                CalculateRain(width, height);

                LoadingMessage = "Biome";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Biome = Overworld.GetBiome(Overworld.Map[x, y].Temperature, Overworld.Map[x, y].Rainfall, Overworld.Map[x, y].Height);
                    }
                }

                LoadingMessage = "Volcanoes";

                GenerateVolcanoes(width, height);

                Overworld.TextureFromHeightMap("Height", Overworld.Map, Overworld.ScalarFieldType.Height, width, height, MapPanel.Lock, worldData, worldMap, Settings.SeaLevel);

                LoadingMessage      = "Factions";
                NativeCivilizations = new List <Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < Settings.NumCivilizations; i++)
                {
                    NativeCivilizations.Add(library.GenerateFaction(i, Settings.NumCivilizations));
                }
                SeedCivs(Overworld.Map, Settings.NumCivilizations, NativeCivilizations);
                GrowCivs(Overworld.Map, 200, NativeCivilizations);


                for (int x = 0; x < width; x++)
                {
                    Overworld.Map[x, 0]          = Overworld.Map[x, 1];
                    Overworld.Map[x, height - 1] = Overworld.Map[x, height - 2];
                }

                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[0, y]         = Overworld.Map[1, y];
                    Overworld.Map[width - 1, y] = Overworld.Map[width - 2, y];
                }

                GenerationComplete = true;

                MapPanel.Image       = new ImageFrame(worldMap, new Rectangle(0, 0, worldMap.Width, worldMap.Height));
                MapPanel.LocalBounds = new Rectangle(300, 30, worldMap.Width, worldMap.Height);


                Progress.Value = 1.0f;
                IsGenerating   = false;
                GUI.MouseMode  = GUISkin.MousePointer.Pointer;
                DoneGenerating = true;
            }
#if CREATE_CRASH_LOGS
            catch (Exception exception)
            {
                ProgramData.WriteExceptionLog(exception);
                throw;
            }
#endif
        }
Exemplo n.º 4
0
        public void GenerateWorld(int seed, int width, int height)
        {
#if CREATE_CRASH_LOGS
            try
#endif
            {
                Seed = seed;
                MathFunctions.Random       = new ThreadSafeRandom(Seed);
                Overworld.heightNoise.Seed = seed;
                CurrentState = GenerationState.Generating;

                if (Overworld.Name == null)
                {
                    Overworld.Name = WorldGenerationSettings.GetRandomWorldName();
                }

                LoadingMessage             = "Init..";
                Overworld.heightNoise.Seed = Seed;
                worldData     = new Color[width * height];
                Overworld.Map = new Overworld.MapData[width, height];

                Progress = 0.01f;

                LoadingMessage           = "Height Map ...";
                float[,] heightMapLookup = null;
                heightMapLookup          = Overworld.GenerateHeightMapLookup(width, height);
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, false);

                Progress = 0.05f;

                int numRains       = (int)Settings.NumRains;
                int rainLength     = 250;
                int numRainSamples = 3;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Erosion    = 1.0f;
                        Overworld.Map[x, y].Weathering = 0;
                        Overworld.Map[x, y].Faults     = 1.0f;
                    }
                }

                LoadingMessage = "Climate";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = ((float)(y) / (float)(height)) * Settings.TemperatureScale;
                        //Overworld.Map[x, y].Rainfall = Math.Max(Math.Min(Overworld.noise(x, y, 1000.0f, 0.01f) + Overworld.noise(x, y, 100.0f, 0.1f) * 0.05f, 1.0f), 0.0f) * RainfallScale;
                    }
                }

                //Overworld.Distort(width, height, 60.0f, 0.005f, Overworld.ScalarFieldType.Rainfall);
                Overworld.Distort(width, height, 30.0f, 0.005f, Overworld.ScalarFieldType.Temperature);
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map[x, y].Temperature, 1.0f), 0.0f);
                    }
                }

                int numVoronoiPoints = (int)Settings.NumFaults;

                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }

                Progress       = 0.1f;
                LoadingMessage = "Faults ...";

                #region voronoi

                Voronoi(width, height, numVoronoiPoints);

                #endregion

                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                Progress = 0.2f;

                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                Progress = 0.25f;
                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }
                LoadingMessage = "Erosion...";

                #region erosion

                float[,] buffer = new float[width, height];
                Erode(width, height, Settings.SeaLevel, Overworld.Map, numRains, rainLength, numRainSamples, buffer);
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);

                #endregion

                Progress = 0.9f;


                LoadingMessage = "Blur.";
                Overworld.Blur(Overworld.Map, width, height, Overworld.ScalarFieldType.Erosion);

                LoadingMessage = "Generate height.";
                Overworld.GenerateHeightMapFromLookup(heightMapLookup, width, height, 1.0f, true);


                LoadingMessage = "Rain";
                CalculateRain(width, height);

                LoadingMessage = "Biome";
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Overworld.Map[x, y].Biome = Overworld.GetBiome(Overworld.Map[x, y].Temperature, Overworld.Map[x, y].Rainfall, Overworld.Map[x, y].Height).Biome;
                    }
                }

                LoadingMessage = "Volcanoes";

                GenerateVolcanoes(width, height);

                if (UpdatePreview != null)
                {
                    UpdatePreview();
                }


                LoadingMessage = "Factions";
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, new CompanyInformation());

                if (Settings.Natives == null || Settings.Natives.Count == 0)
                {
                    NativeCivilizations = new List <Faction>();
                    for (int i = 0; i < Settings.NumCivilizations; i++)
                    {
                        NativeCivilizations.Add(library.GenerateFaction(null, i, Settings.NumCivilizations));
                    }
                    Settings.Natives = NativeCivilizations;
                }
                else
                {
                    NativeCivilizations = Settings.Natives;

                    if (Settings.NumCivilizations > Settings.Natives.Count)
                    {
                        int count = Settings.Natives.Count;
                        for (int i = count; i < Settings.NumCivilizations; i++)
                        {
                            NativeCivilizations.Add(library.GenerateFaction(null, i, Settings.NumCivilizations));
                        }
                    }
                }
                SeedCivs(Overworld.Map, Settings.NumCivilizations, NativeCivilizations);
                GrowCivs(Overworld.Map, 200, NativeCivilizations);


                for (int x = 0; x < width; x++)
                {
                    Overworld.Map[x, 0]          = Overworld.Map[x, 1];
                    Overworld.Map[x, height - 1] = Overworld.Map[x, height - 2];
                }

                for (int y = 0; y < height; y++)
                {
                    Overworld.Map[0, y]         = Overworld.Map[1, y];
                    Overworld.Map[width - 1, y] = Overworld.Map[width - 2, y];
                }

                LoadingMessage = "Selecting Spawn Point";
                AutoSelectSpawnRegion();

                CurrentState   = GenerationState.Finished;
                LoadingMessage = "";
                Progress       = 1.0f;
            }
#if CREATE_CRASH_LOGS
            catch (Exception exception)
            {
                ProgramData.WriteExceptionLog(exception);
                throw;
            }
#endif
        }
Exemplo n.º 5
0
        public void OnItemClicked(ListItem item)
        {
            switch (item.Label)
            {
            case "Continue Game":
                StateManager.PopState();
                break;

            case "New Game":
                PlayItems();
                StateManager.PushState("CompanyMakerState");
                MaintainState = true;
                break;

            case "Quit":
                Game.Exit();
                break;

            case "Generate World":
                MaintainState = true;
                StateManager.PushState("WorldGeneratorState");
                break;

            case "Options":
                MaintainState = true;
                StateManager.PushState("OptionsState");
                break;

            case "Back":
                DefaultItems();
                break;

            case "Debug World":
                DebugWorldItems();
                break;

            case "Flat World":
            {
                MaintainState = false;
                Overworld.CreateUniformLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Hills World":
            {
                MaintainState = false;
                Overworld.CreateHillsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Cliffs World":
            {
                MaintainState = false;
                Overworld.CreateCliffsLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;
                PlayState.Natives   = new List <Faction>();
                FactionLibrary library = new FactionLibrary();
                library.Initialize(null, "fake", "fake", null, Color.Blue);
                for (int i = 0; i < 10; i++)
                {
                    PlayState.Natives.Add(library.GenerateFaction(i, 10));
                }

                IsGameRunning = true;
            }
            break;

            case "Ocean World":
            {
                MaintainState = false;
                Overworld.CreateOceanLand(Game.GraphicsDevice);
                StateManager.PushState("PlayState");
                PlayState.WorldSize = new Point3(8, 1, 8);
                GUI.MouseMode       = GUISkin.MousePointer.Wait;

                IsGameRunning = true;
            }
            break;

            case "Load World":
                MaintainState = true;
                StateManager.PushState("WorldLoaderState");
                break;

            case "Load Game":
                MaintainState = true;
                StateManager.PushState("GameLoaderState");
                break;
            }
        }