void Start() { //Overworld Generation #region Biome Generation //Biome Generation //Calculates each tiles biome values for the entire world //Options: // World can be re-created using seeds only on load // The big float map could be saved and then manually loaded? - not sure how much more effective this will be than doing simple math of perlin noise maps // ? //Value 1: HEIGHT GenerateOverworldBlock(); float[,] height = NoiseMap.GeneratePerlinNoiseMap(WorldSize, WorldSize, levelScale, 0, 0, heightWaves); //Value 2: HEAT float[,] temperature = NoiseMap.GenerateUniformNoiseMap(WorldSize, WorldSize, WorldSize / 2, WorldSize / 2, 0); float[,] randomTemperature = NoiseMap.GeneratePerlinNoiseMap(WorldSize, WorldSize, levelScale, WorldSize, 0, temperatureWaves); float[,] heatMap = new float[WorldSize, WorldSize]; for (int yIndex = 0; yIndex < WorldSize; yIndex++) { for (int xIndex = 0; xIndex < WorldSize; xIndex++) { heatMap[xIndex, yIndex] = temperature[xIndex, yIndex] * randomTemperature[xIndex, yIndex]; heatMap[xIndex, yIndex] += temperatureCurve.Evaluate(height[xIndex, yIndex]) * heatMap[xIndex, yIndex]; heatMap[xIndex, yIndex] = Mathf.Clamp(heatMap[xIndex, yIndex], 0f, 1f); } } //Value 3: MOISTURE float[,] moistureMap = NoiseMap.GeneratePerlinNoiseMap(WorldSize, WorldSize, levelScale, 0, 0, moistureWaves); for (int yIndex = 0; yIndex < WorldSize; yIndex++) { for (int xIndex = 0; xIndex < WorldSize; xIndex++) { moistureMap[xIndex, yIndex] -= this.moistureCurve.Evaluate(height[xIndex, yIndex]) * moistureMap[xIndex, yIndex]; moistureMap[xIndex, yIndex] = Mathf.Clamp(moistureMap[xIndex, yIndex], 0f, 1f); } } //Fill placeholder tile map GenTile[,] generatedtiles = new GenTile[WorldSize, WorldSize]; for (int i = 0; i < WorldSize; i++) { for (int j = 0; j < WorldSize; j++) { Biome chosenBio = BiomeData.Instance.GetBiome(height[i, j], heatMap[i, j], moistureMap[i, j]); generatedtiles[i, j] = new GenTile(i, j, chosenBio); } } #endregion #region Feature Generation //Feature Generation //TODO: this feature generation will need to be chunk related //Tree generation float[,] trees = NoiseMap.GeneratePerlinNoiseMap(WorldSize, WorldSize, 1.1f, 0, 0, NoiseMap.DefaultWaves); for (int i = 0; i < WorldSize; i++) { for (int j = 0; j < WorldSize; j++) { if (generatedtiles[i, j].tileBiome.SpawnTrees) { if (trees[i, j] >= 0.8) { ObjectManager.Instance.AddObjectToGrid(generatedtiles[i, j].tileBiome.Treefab, new Vector3(i, j, 0)); } } } } //Apply features to biome tiles // e.g. village, well, etc. #endregion //TODO: add functionality for a second layer (i.e. a cave layer) with different generation //float[,] caveMap = GenerateCaveBlock(); //Generate for (int i = 0; i < numChunks; i++) { for (int j = 0; j < numChunks; j++) { //gen chunk GenTile[,] chunkMap = new GenTile[Chunk.size, Chunk.size]; for (int k = 0; k < Chunk.size; k++) { for (int z = 0; z < Chunk.size; z++) { chunkMap[k, z] = generatedtiles[k + i * Chunk.size, z + j * Chunk.size]; } } fullchunkmap.Add(new System.Tuple <int, int>(i, j), chunkMap); } } //Save all chunks to disk? i.e. out of ram? //Load current nearby chunks LoadAllChunks(); }