public void GenerateWorld() { #if !DEBUG try #endif { CurrentState = GenerationState.Generating; LoadingMessage = "Init.."; OverworldMap.heightNoise.Seed = Overworld.Seed; Overworld.Map.Map = new OverworldCell[Overworld.Width, Overworld.Height]; Progress = 0.01f; LoadingMessage = "Height Map ..."; float[,] heightMapLookup = null; heightMapLookup = OverworldMap.GenerateHeightMapLookup(Overworld.Width, Overworld.Height); Overworld.Map.CreateHeightFromLookup(heightMapLookup); Progress = 0.05f; int numRains = (int)Overworld.GenerationSettings.NumRains; int rainLength = 250; int numRainSamples = 3; for (int x = 0; x < Overworld.Width; x++) { for (int y = 0; y < Overworld.Height; y++) { Overworld.Map.Map[x, y].Erosion = 1.0f; Overworld.Map.Map[x, y].Weathering = 0; Overworld.Map.Map[x, y].Faults = 1.0f; } } LoadingMessage = "Climate"; for (int x = 0; x < Overworld.Width; x++) { for (int y = 0; y < Overworld.Height; y++) { Overworld.Map.Map[x, y].Temperature = ((float)(y) / (float)(Overworld.Height)) * Overworld.GenerationSettings.TemperatureScale; } } OverworldImageOperations.Distort(Overworld.Map.Map, Overworld.Width, Overworld.Height, 30.0f, 0.005f, OverworldField.Temperature); for (int x = 0; x < Overworld.Width; x++) { for (int y = 0; y < Overworld.Height; y++) { Overworld.Map.Map[x, y].Temperature = Math.Max(Math.Min(Overworld.Map.Map[x, y].Temperature, 1.0f), 0.0f); } } int numVoronoiPoints = (int)Overworld.GenerationSettings.NumFaults; Progress = 0.1f; LoadingMessage = "Faults ..."; Voronoi(Overworld.Width, Overworld.Height, numVoronoiPoints); Overworld.Map.CreateHeightFromLookupWithErosion(heightMapLookup); Progress = 0.2f; Overworld.Map.CreateHeightFromLookupWithErosion(heightMapLookup); Progress = 0.25f; LoadingMessage = "Erosion..."; var buffer = new float[Overworld.Width, Overworld.Height]; Erode(Overworld.Width, Overworld.Height, Overworld.GenerationSettings.SeaLevel, Overworld.Map.Map, numRains, rainLength, numRainSamples, buffer); Overworld.Map.CreateHeightFromLookupWithErosion(heightMapLookup); Progress = 0.9f; LoadingMessage = "Blur."; OverworldImageOperations.Blur(Overworld.Map.Map, Overworld.Width, Overworld.Height, OverworldField.Erosion); LoadingMessage = "Generate height."; Overworld.Map.CreateHeightFromLookupWithErosion(heightMapLookup); LoadingMessage = "Rain"; CalculateRain(Overworld.Width, Overworld.Height); LoadingMessage = "Biome"; for (int x = 0; x < Overworld.Width; x++) { for (int y = 0; y < Overworld.Height; y++) { Overworld.Map.Map[x, y].Biome = Library.GetBiomeForConditions(Overworld.Map.Map[x, y].Temperature, Overworld.Map.Map[x, y].Rainfall, Overworld.Map.Map[x, y].Height).Biome; } } LoadingMessage = "Volcanoes"; GenerateVolcanoes(Overworld.Width, Overworld.Height); LoadingMessage = "Factions"; FactionSet library = new FactionSet(); library.Initialize(null, new CompanyInformation()); Overworld.Natives = new List <OverworldFaction>(); foreach (var fact in library.Factions) { Overworld.Natives.Add(fact.Value.ParentFaction); // Todo: Don't create a whole faction just to grab the overworldfactions from them. } for (int i = 0; i < Overworld.GenerationSettings.NumCivilizations; i++) { Overworld.Natives.Add(library.GenerateOverworldFaction(Overworld, i, Overworld.GenerationSettings.NumCivilizations)); } Politics.Initialize(Overworld); Overworld.ColonyCells = new CellSet("World\\colonies"); Overworld.InstanceSettings = new InstanceSettings(Overworld.ColonyCells.GetCellAt(16, 0)); SeedCivs(); GrowCivs(); for (int x = 0; x < Overworld.Width; x++) { Overworld.Map.Map[x, 0] = Overworld.Map.Map[x, 1]; Overworld.Map.Map[x, Overworld.Height - 1] = Overworld.Map.Map[x, Overworld.Height - 2]; } for (int y = 0; y < Overworld.Height; y++) { Overworld.Map.Map[0, y] = Overworld.Map.Map[1, y]; Overworld.Map.Map[Overworld.Width - 1, y] = Overworld.Map.Map[Overworld.Width - 2, y]; } CurrentState = GenerationState.Finished; LoadingMessage = ""; Progress = 1.0f; } #if !DEBUG catch (Exception exception) { ProgramData.WriteExceptionLog(exception); throw; } #endif }