/// <summary> /// Grows the minerals on the map. /// </summary> /// <param name="map">The map where the minerals spawn</param> /// <param name="biomeMap">The biome map attached to the previous map.</param> public void GrowAll (TileType[, ] map, BiomeType[, ] biomeMap) { NoiseGenerator gen = new NoiseGenerator (); while (availableMinerals.Count > 0) { MineralInfo mineral = availableMinerals.Dequeue(); gen.Reset(); for (int x = 0; x < map.GetLength(0); x ++) { int y = (mineral.minHeight > 0 ? mineral.minHeight : 0); int maxY = (mineral.maxHeight < map.GetLength(1) ? mineral.maxHeight : map.GetLength(1)); for (; y < maxY; y ++) { if (IsTileCompatible(biomeMap, x, y, mineral.compatibleBiomes) && (mineral.rarity < (int) gen.PerlinNoise(x, y, 10, 100, 1))) PlaceMinerals(map, x, y, mineral.minerals); } } } }
public DrawabeElement(VertexPositionNormal4Texture[] vpc, BiomeType gt) { this.vpc = vpc; effect = new BasicEffect(Tools.Quick.device); setEffect(gt); vb = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, vpc.Count(), BufferUsage.WriteOnly); vb.SetData(vpc); //effect.Parameters["xTexture"].SetValue(effect.Texture); }
public Tile(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, BiomeType type) { // faire un <<c>> pour un affichage correcte this.v1 = v1; this.v2 = v2; this.v3 = v3; this.v4 = v4; gp = type; normal1 = Vector3.Cross(v3 - v2, v1 - v2); normal1.Normalize(); normal2 = Vector3.Cross(v1 - v4, v3 - v4); normal2.Normalize(); }
public BiomeData( BiomeType newType, TerrainTexture newTexture, Color newColor, string[] newBigNames, string[] newMediumNames, string[] newSmallNames ) { Type = newType; TextureID = newTexture; MinimapColor = newColor; BigNames = newBigNames; MediumNames = newMediumNames; SmallNames = newSmallNames; }
protected IEnumerator SmoothMovement(int desiredIndex) { if (Scene._grid[desiredIndex].isWalkable/* && Scene._grid[desiredIndex].ItemValue != ItemValues.MiningBlock*/) { CurrentIndexPosition = desiredIndex; CurrentPosY = CurrentIndexPosition / Scene.Height; CurrentPosX = CurrentIndexPosition - CurrentPosY * Scene.Height; Vector3 end = Scene._grid[desiredIndex].position; if(PlayerBiome != Scene._grid[desiredIndex].Biome) { PlayerBiome = Scene._grid[desiredIndex].Biome; GlobalEventText.AddMessage(string.Format("You just entered in the biome {0}", PlayerBiome.ToString())); } //Calculate the remaining distance to move based on the square magnitude of the difference between current position and end parameter. //Square magnitude is used instead of magnitude because it's computationally cheaper. float sqrRemainingDistance = (transform.position - end).sqrMagnitude; //While that distance is greater than a very small amount (Epsilon, almost zero): while (sqrRemainingDistance > float.Epsilon) { //Find a new position proportionally closer to the end, based on the moveTime Vector3 newPostion = Vector3.MoveTowards(_rb2D.position, end, 20.0f * Time.deltaTime); //Call MovePosition on attached Rigidbody2D and move it to the calculated position. _rb2D.MovePosition(newPostion); //Recalculate the remaining distance after moving. sqrRemainingDistance = (transform.position - end).sqrMagnitude; //Return and loop until sqrRemainingDistance is close enough to zero to end the function yield return null; } Fog.UpdateFog(CurrentIndexPosition, TileFogState.Active); } else { if (Scene._grid[desiredIndex].TileItem != null) { if (!Scene._grid[desiredIndex].TileItem.GetComponent<MonoDestructibleTile>().thisItem.OnDamage(50, desiredIndex)) yield return new WaitForSeconds(0.5f); //Mining time else Destroy(Scene._grid[desiredIndex].TileItem); } } _movementReady = true; }
public GroundCell(int[,] tiles, BiomeType[,] biomeMap, int xPos, int yPos) { this.xPos = xPos; this.yPos = yPos; LODIndices = new SortedDictionary<int, IndexBuffer>(); makeBiomeMap(Tools.Quick.device, biomeMap); makeBuffers(tiles, biomeMap); effect = Tools.Quick.content.Load<Effect>("Effects/MyEffect"); effect.Parameters["xWorldScale"].SetValue(new Vector2(Map.MAPSIZE, Map.MAPSIZE)); effect.Parameters["xTexturesMap"].SetValue(biomeTexture); effect.Parameters["xEnableLighting"].SetValue(true); Vector3 lightDirection = new Vector3(0.5f, -1f, 0); lightDirection.Normalize(); effect.Parameters["xLightDirection"].SetValue(lightDirection); effect.Parameters["xClipping"].SetValue(false); effect.Parameters["xTextureAtlas"].SetValue(Tools.Quick.biome3D); }
void Start() { myBiomeType = (BiomeType)Random.Range(0, (int)BiomeType.NUMBER_OF_ELEMENTS); //cull the ecoStructurePrefabs of all EcoStructures that aren't a part of my biome for(int i = 0; i < ecoStructurePrefabs.Count; i++){ if(!ecoStructurePrefabs[i].GetComponent<EcoStructure>()){ ecoStructurePrefabs.RemoveAt(i); i--; } else{ EcoStructureType structure = ecoStructurePrefabs[i].GetComponent<EcoStructure>().myType; if(!Biome.getStructuresForBiome(myBiomeType).Contains(structure)){ ecoStructurePrefabs.RemoveAt(i); i--; } } } zoneWidth = (renderer.bounds.max.x - collider.bounds.min.x) * 2f; isInitialized = true; }
private void setEffect(BiomeType gt) { Texture2D texture = Tools.Quick.groundTexture[gt]; effect.World = Matrix.Identity; effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), Tools.Quick.graphics.GraphicsDevice.Viewport.Width / (float)Tools.Quick.graphics.GraphicsDevice.Viewport.Height, 1.0f, 10000.0f); effect.Texture = texture; effect.TextureEnabled = true; //effect.World = Matrix.CreateTranslation(Vector3.Zero); //modelPosition effect.LightingEnabled = true; //effect.Parameters["xEnableLighting"].SetValue(true); Vector3 lightDirection = new Vector3(0.5f, -1f, 0); lightDirection.Normalize(); //effect.Parameters["xLightDirection"].SetValue(lightDirection); effect.DirectionalLight0.Direction = lightDirection; effect.DirectionalLight0.Enabled = true; effect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f); //effect.DiffuseColor = new Vector3(0.1f, 0.1f, 0.1f); }
public void makeBuffers(ref int[,] tile, BiomeType[,] biomeMap) { //effect = Tools.Quick.content.Load<Effect>("Effects/MyEffect"); //effect.Parameters["xWorldScale"].SetValue(new Vector2(Map.MAPSIZE, Map.MAPSIZE)); //effect.Parameters["xTexturesMap"].SetValue(biomeTexture); //effect.Parameters["xEnableLighting"].SetValue(true); //Vector3 lightDirection = new Vector3(0.5f, -1f, 0); //lightDirection.Normalize(); //effect.Parameters["xLightDirection"].SetValue(lightDirection); //effect.Parameters["xClipping"].SetValue(false); //effect.Parameters["xTextureAtlas"].SetValue(Tools.Quick.biome3D); //bigbuffer = new VertexPositionNormal4Texture[tiles.Count * 6]; //indexvertex = new int[tiles.Count * 6]; Color color = Color.AliceBlue; //int num = 0; //foreach (Tile t in tiles) //{ // if (t.v1.Y <= waterlevel) // { // num++; // } //} //bigbufferWater = new VertexPositionNormal4Texture[num * 6]; VertexPositionNormal4Texture[] buffer = new VertexPositionNormal4Texture[(CELL_SIZE + 1) * (CELL_SIZE + 1)]; int[] iBuffer1 = new int[CELL_SIZE * CELL_SIZE * 6]; for (int n = 0; n <= CELL_SIZE; n++) { buffer[n] = new VertexPositionNormal4Texture( new Vector3(n, 0, 0), new Vector3(0, 1, 0), new Vector4(1, 0, 0, 0), new Vector4((int)BiomeType.Water)); } for (int x = 0; x < CELL_SIZE; x++) for (int y = 0; y < CELL_SIZE; y++) { int n = CELL_SIZE * y + x; int h = tile[x, y]; if (x == 0) buffer[n + CELL_SIZE + y + 1] = new VertexPositionNormal4Texture( new Vector3(0, 0, y + 1), new Vector3(0, 1, 0), new Vector4(1, 0, 0, 0), new Vector4((int)BiomeType.Water)); buffer[n + CELL_SIZE + y + 2] = new VertexPositionNormal4Texture(new Vector3(x + 1, h, y + 1), new Vector3(1, 0, 0), new Vector4(1, 0, 0, 0), new Vector4((int)biomeMap[x, y])); buffer[n + y].TextureType.Y = (int)biomeMap[x, y]; buffer[n + y].TextureWeight.Y = 1; buffer[n + y].TextureWeight.Normalize(); buffer[n + CELL_SIZE + y + 1].TextureType.Z = (int)biomeMap[x, y]; buffer[n + CELL_SIZE + y + 1].TextureWeight.Z = 1; buffer[n + CELL_SIZE + y + 1].TextureWeight.Normalize(); buffer[n + CELL_SIZE + y + 2].TextureType.W = (int)biomeMap[x, y]; buffer[n + CELL_SIZE + y + 2].TextureWeight.W = 1; buffer[n + CELL_SIZE + y + 2].TextureWeight.Normalize(); iBuffer1[n * 6] = n + y; iBuffer1[n * 6 + 1] = n + CELL_SIZE + y + 1; iBuffer1[n * 6 + 2] = n + y + 1; iBuffer1[n * 6 + 3] = n + y + 1; iBuffer1[n * 6 + 4] = n + CELL_SIZE + y + 1; iBuffer1[n * 6 + 5] = n + CELL_SIZE + y + 2; } vertices = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, (Map.MAPSIZE + 1) * (Map.MAPSIZE + 1), BufferUsage.WriteOnly); vertices.SetData(buffer); IndexBuffer indices = new IndexBuffer(Tools.Quick.device, IndexElementSize.ThirtyTwoBits, (Map.MAPSIZE) * (Map.MAPSIZE) * 6, BufferUsage.WriteOnly); indices.SetData(iBuffer1); LODIndices.Add(1, indices); // for (int n = 0; n < tiles.Count; n++) // { // Tile t = tiles[n]; // Vector3 normal = Vector3.Cross(t.v2 - t.v4, t.v1 - t.v4); // normal.Normalize(); // normal = Vector3.Multiply(normal, -1); // int y = n / (Map.MAPSIZE); // int x = n % (Map.MAPSIZE); // if (x == 0) // buffer[n + (Map.MAPSIZE) + y + 1] = new VertexPositionNormal4Texture( // new Vector3(0, 0, y + 1), new Vector3(0, 1, 0), new Vector4(1, 0, 0, 0), new Vector4((int)BiomeType.Water)); // buffer[n + Map.MAPSIZE + y + 2] = new VertexPositionNormal4Texture(new Vector3(x + 1, t.v1.Y, y + 1), t.n1, new Vector4(1, 0, 0, 0), new Vector4((int)t.gp)); // buffer[n + y].TextureType.Y = (int)t.gp; // buffer[n + y].TextureWeight.Y = 1; // buffer[n + y].TextureWeight.Normalize(); // buffer[n + Map.MAPSIZE + y + 1].TextureType.Z = (int)t.gp; // buffer[n + Map.MAPSIZE + y + 1].TextureWeight.Z = 1; // buffer[n + Map.MAPSIZE + y + 1].TextureWeight.Normalize(); // buffer[n + Map.MAPSIZE + y + 2].TextureType.W = (int)t.gp; // buffer[n + Map.MAPSIZE + y + 2].TextureWeight.W = 1; // buffer[n + Map.MAPSIZE + y + 2].TextureWeight.Normalize(); // iBuffer[n * 6] = n + y; // iBuffer[n * 6 + 1] = n + Map.MAPSIZE + y + 1; // iBuffer[n * 6 + 2] = n + y + 1; // iBuffer[n * 6 + 3] = n + y + 1; // iBuffer[n * 6 + 4] = n + Map.MAPSIZE + y + 1; // iBuffer[n * 6 + 5] = n + Map.MAPSIZE + y + 2; // } // GroundVertices = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, (Map.MAPSIZE + 1) * (Map.MAPSIZE + 1), BufferUsage.WriteOnly); // GroundVertices.SetData(buffer); // GroundIndices = new IndexBuffer(Tools.Quick.device, IndexElementSize.ThirtyTwoBits, (Map.MAPSIZE) * (Map.MAPSIZE) * 6, BufferUsage.WriteOnly); // GroundIndices.SetData(iBuffer); // // verifAppliTex(bigbufferWater); }
public void GenerateSplatMapBiome(Bounds updateBounds, BiomeType biomeType, List <PolygonBiomeMask> polygonBiomeMaskList, List <TerrainTextureSettings> terrainTextureSettingsList, float heightCurveSampleHeight, float worldSpaceSeaLevel, bool clearLockedTextures) { }
void makeBiomeMap(GraphicsDevice device, BiomeType[,] biomeMap) { drawing.Bitmap img = new drawing.Bitmap(Map.MAPSIZE, Map.MAPSIZE); for (int i = 0; i < Map.MAPSIZE; i++) for (int j = 0; j < Map.MAPSIZE; j++) { BiomeType h = biomeMap[i, j]; sColor c = sColor.FromArgb((int)h * 255 / 11, 0, 0); img.SetPixel(i, j, c); } biomeTexture = new Texture2D(device, Map.MAPSIZE, Map.MAPSIZE); drawing.Imaging.BitmapData data = img.LockBits(new drawing.Rectangle(0, 0, img.Width, img.Height), drawing.Imaging.ImageLockMode.ReadOnly, img.PixelFormat); int bufferSize = data.Height * data.Stride; byte[] bytes = new byte[bufferSize]; System.Runtime.InteropServices.Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); biomeTexture.SetData(bytes); img.UnlockBits(data); }
public virtual BiomeType[,] DetermineBiomes(Vector3i chunkScale, long X, long Z) { BiomeType[,] bt = new BiomeType[chunkScale.X, chunkScale.Z]; int xo = (int)(X*chunkScale.X); int zo = (int)(Z*chunkScale.Z); double maxT = 0; for (int x = 0; x < chunkScale.X; x++) { for (int z = 0; z < chunkScale.Z; z++) { double h = HumidityNoise.Noise((double)(x + xo) / BIOME_SCALE, 0, (double)(z + zo) / BIOME_SCALE) + HumidityOffset; double t = TemperatureNoise.Noise((double)(x + xo) / BIOME_SCALE, 0, (double)(z + zo) / BIOME_SCALE) + TemperatureOffset; if (t > maxT) maxT = t; bt[x, z] = Biome.GetBiomeType(h, t); } } //Console.WriteLine("t=" + maxT.ToString()); return bt; }
public Biome(BiomeType type, NoiseSettings settings) { this.type = type; this.settings = settings; }
/// <summary> /// Initializes a new instance of <see cref="WeatherMaps"/>. /// </summary> /// <param name="planet">The planet being mapped.</param> /// <param name="elevationMap">An elevation map.</param> /// <param name="winterTemperatureMap">A winter temperature map.</param> /// <param name="summerTemperatureMap">A summer temperature map.</param> /// <param name="precipitationMap">A precipitation map.</param> /// <param name="resolution">The intended vertical resolution of the maps.</param> /// <param name="options"> /// The map projection options to use. All the map images must have been generated using /// these same options, or thew results will not be accurate. /// </param> public WeatherMaps( Planetoid planet, Image <L16> elevationMap, Image <L16> winterTemperatureMap, Image <L16> summerTemperatureMap, Image <L16> precipitationMap, int resolution, MapProjectionOptions?options = null) { var projection = options ?? MapProjectionOptions.Default; XLength = (int)Math.Floor(projection.AspectRatio * resolution); YLength = resolution; BiomeMap = new BiomeType[XLength][]; ClimateMap = new ClimateType[XLength][]; var humidityMap = new HumidityType[XLength][]; SeaIceRangeMap = new FloatRange[XLength][]; for (var x = 0; x < XLength; x++) { BiomeMap[x] = new BiomeType[YLength]; ClimateMap[x] = new ClimateType[YLength]; humidityMap[x] = new HumidityType[YLength]; SeaIceRangeMap[x] = new FloatRange[YLength]; } var scale = SurfaceMap.GetScale(resolution, projection.Range); var stretch = scale / projection.ScaleFactor; var elevationScale = SurfaceMap.GetScale(elevationMap.Height, projection.Range); var winterScale = winterTemperatureMap.Height == elevationMap.Height ? elevationScale : SurfaceMap.GetScale(winterTemperatureMap.Height, projection.Range); var summerScale = summerTemperatureMap.Height == elevationMap.Height ? elevationScale : SurfaceMap.GetScale(summerTemperatureMap.Height, projection.Range); var precipitationScale = precipitationMap.Height == elevationMap.Height ? elevationScale : SurfaceMap.GetScale(precipitationMap.Height, projection.Range); var totalElevation = 0.0; var minTemperature = 5000.0f; var maxTemperature = 0.0f; var totalTemperature = 0.0f; var totalPrecipiation = 0.0; var xToEX = new Dictionary <int, int>(); var xToWX = new Dictionary <int, int>(); var xToSX = new Dictionary <int, int>(); var xToPX = new Dictionary <int, int>(); for (var y = 0; y < YLength; y++) { var latitude = projection.EqualArea ? SurfaceMap.GetLatitudeOfCylindricalEqualAreaProjection(y, resolution, scale, projection) : SurfaceMap.GetLatitudeOfEquirectangularProjection(y, resolution, scale, projection); var elevationY = projection.EqualArea ? SurfaceMap.GetCylindricalEqualAreaYFromLatWithScale(latitude, elevationMap.Height, elevationScale, projection) : SurfaceMap.GetEquirectangularYFromLatWithScale(latitude, elevationMap.Height, elevationScale, projection); var elevationSpan = elevationMap.GetPixelRowSpan(elevationY); int winterY; if (winterTemperatureMap.Height == elevationMap.Height) { winterY = elevationY; } else if (projection.EqualArea) { winterY = SurfaceMap.GetCylindricalEqualAreaYFromLatWithScale(latitude, winterTemperatureMap.Height, winterScale, projection); } else { winterY = SurfaceMap.GetEquirectangularYFromLatWithScale(latitude, winterTemperatureMap.Height, winterScale, projection); } var winterSpan = winterTemperatureMap.GetPixelRowSpan(winterY); int summerY; if (summerTemperatureMap.Height == elevationMap.Height) { summerY = elevationY; } else if (projection.EqualArea) { summerY = SurfaceMap.GetCylindricalEqualAreaYFromLatWithScale(latitude, summerTemperatureMap.Height, summerScale, projection); } else { summerY = SurfaceMap.GetEquirectangularYFromLatWithScale(latitude, summerTemperatureMap.Height, summerScale, projection); } var summerSpan = summerTemperatureMap.GetPixelRowSpan(summerY); int precipitationY; if (precipitationMap.Height == elevationMap.Height) { precipitationY = elevationY; } else if (projection.EqualArea) { precipitationY = SurfaceMap.GetCylindricalEqualAreaYFromLatWithScale(latitude, precipitationMap.Height, precipitationScale, projection); } else { precipitationY = SurfaceMap.GetEquirectangularYFromLatWithScale(latitude, precipitationMap.Height, precipitationScale, projection); } var precipitationSpan = precipitationMap.GetPixelRowSpan(precipitationY); for (var x = 0; x < XLength; x++) { if (!xToEX.TryGetValue(x, out var elevationX)) { var longitude = projection.EqualArea ? SurfaceMap.GetLongitudeOfCylindricalEqualAreaProjection(x, XLength, scale, projection) : SurfaceMap.GetLongitudeOfEquirectangularProjection(x, XLength, stretch, projection); elevationX = projection.EqualArea ? SurfaceMap.GetCylindricalEqualAreaXFromLonWithScale(longitude, elevationMap.Width, elevationScale, projection) : SurfaceMap.GetEquirectangularXFromLonWithScale(longitude, elevationMap.Width, elevationScale, projection); int wX; if (winterTemperatureMap.Width == elevationMap.Width) { wX = elevationX; } else if (projection.EqualArea) { wX = SurfaceMap.GetCylindricalEqualAreaXFromLonWithScale(longitude, winterTemperatureMap.Width, winterScale, projection); } else { wX = SurfaceMap.GetEquirectangularXFromLonWithScale(longitude, winterTemperatureMap.Width, winterScale, projection); } int sX; if (summerTemperatureMap.Width == elevationMap.Width) { sX = elevationX; } else if (projection.EqualArea) { sX = SurfaceMap.GetCylindricalEqualAreaXFromLonWithScale(longitude, summerTemperatureMap.Width, summerScale, projection); } else { sX = SurfaceMap.GetEquirectangularXFromLonWithScale(longitude, summerTemperatureMap.Width, summerScale, projection); } int pX; if (precipitationMap.Width == elevationMap.Width) { pX = elevationX; } else if (projection.EqualArea) { pX = SurfaceMap.GetCylindricalEqualAreaXFromLonWithScale(longitude, precipitationMap.Width, precipitationScale, projection); } else { pX = SurfaceMap.GetEquirectangularXFromLonWithScale(longitude, precipitationMap.Width, precipitationScale, projection); } xToEX.Add(x, elevationX); xToWX.Add(x, wX); xToSX.Add(x, sX); xToPX.Add(x, pX); } var winterX = xToWX[x]; var summerX = xToSX[x]; var precipitationX = xToPX[x]; var normalizedElevation = elevationSpan[elevationX].GetValueFromPixel_PosNeg() - planet.NormalizedSeaLevel; totalElevation += normalizedElevation; var winterTemperature = (float)(winterSpan[winterX].GetValueFromPixel_Pos() * SurfaceMapImage.TemperatureScaleFactor); var summerTemperature = (float)(summerSpan[summerX].GetValueFromPixel_Pos() * SurfaceMapImage.TemperatureScaleFactor); minTemperature = Math.Min(minTemperature, Math.Min(winterTemperature, summerTemperature)); maxTemperature = Math.Max(maxTemperature, Math.Max(winterTemperature, summerTemperature)); totalTemperature += (minTemperature + maxTemperature) / 2; var precipValue = precipitationSpan[precipitationX].GetValueFromPixel_Pos(); var precipitation = precipValue * planet.Atmosphere.MaxPrecipitation; totalPrecipiation += precipValue; ClimateMap[x][y] = Universe.Climate.Climate.GetClimateType(new FloatRange( Math.Min(winterTemperature, summerTemperature), Math.Max(winterTemperature, summerTemperature))); humidityMap[x][y] = Universe.Climate.Climate.GetHumidityType(precipitation); BiomeMap[x][y] = Universe.Climate.Climate.GetBiomeType(ClimateMap[x][y], humidityMap[x][y], normalizedElevation); if (normalizedElevation > 0 || (summerTemperature >= Substances.All.Seawater.MeltingPoint && winterTemperature >= Substances.All.Seawater.MeltingPoint)) { continue; } if (summerTemperature < Substances.All.Seawater.MeltingPoint && winterTemperature < Substances.All.Seawater.MeltingPoint) { SeaIceRangeMap[x][y] = FloatRange.ZeroToOne; continue; } var freezeProportion = ((summerTemperature >= winterTemperature ? winterTemperature.InverseLerp(summerTemperature, (float)(Substances.All.Seawater.MeltingPoint ?? 0)) : summerTemperature.InverseLerp(winterTemperature, (float)(Substances.All.Seawater.MeltingPoint ?? 0))) * 0.8f) - 0.1f; if (freezeProportion <= 0 || float.IsNaN(freezeProportion)) { continue; } var freezeStart = 1 - (freezeProportion / 4); var iceMeltFinish = freezeProportion * 3 / 4; if (latitude < 0) { freezeStart += 0.5f; if (freezeStart > 1) { freezeStart--; } iceMeltFinish += 0.5f; if (iceMeltFinish > 1) { iceMeltFinish--; } } SeaIceRangeMap[x][y] = new FloatRange(freezeStart, iceMeltFinish); } } Climate = Universe.Climate.Climate.GetClimateType(new FloatRange(minTemperature, totalTemperature / (XLength * YLength), maxTemperature)); var humidity = Universe.Climate.Climate.GetHumidityType(totalPrecipiation / (XLength * YLength) * planet.Atmosphere.MaxPrecipitation); Biome = Universe.Climate.Climate.GetBiomeType(Climate, humidity, totalElevation / (XLength * YLength) * planet.MaxElevation); }
public TileTexture(BiomeType biomeType, TextureType textureType, TextureSide textureSide) { Biome = biomeType; Block = textureType; Side = textureSide; }
//Generates Habitat biome based on temp, alt, geography, and climate if the hex is being regenerated public void GenerateBiome() { Biome biome = Biome.Ocean; int roll; if(MapController.worldTemp < MapController.Temperature.Temperate){ if(localTemp == Temperature.Scorching){ localTemp = Temperature.Hot; } } if(MapController.worldTemp > MapController.Temperature.Temperate){ if(localTemp == Temperature.Arctic){ localTemp = Temperature.Cold; } } if(localAlt != Altitude.Deep && localAlt != Altitude.Shallow){ if(localTemp == Temperature.Cold){ if (localGeo == Geography.Mountains) { roll = Random.Range(9, 11); } else { roll = Random.Range(8, 13); if (roll == 11) { roll = 5; } } biome = (Biome)roll; } if(localTemp == Temperature.Temperate){ if(localAlt == Altitude.High || localGeo == Geography.Mountains){ roll = Random.Range(0, 6); if(roll == 0) { biome = Biome.Forest; } if (roll == 1) { biome = Biome.Grassland; } if (roll == 2) { biome = Biome.Lentic; } if (roll == 3) { biome = Biome.Lotic; } if (roll > 3) { biome = Biome.Chaparral; } if(localClimate == Climate.Wet) { biome = Biome.Rainforest;} if(localClimate > Climate.Temperate) { biome = Biome.Chaparral;} if (biome == Biome.Grassland && localClimate == Climate.Arid) { biome = Biome.Savanna;} if (biome == Biome.Grassland && localClimate == Climate.Desert) { biome = Biome.Desert; } } else if(localAlt == Altitude.Medium){ if (localClimate < Climate.Temperate) { roll = Random.Range(0, 6); if (roll < 2) { biome = Biome.Grassland; } if (roll == 2) { biome = Biome.Lentic; } if (roll == 3) { biome = Biome.Lotic; } if (roll == 4) { biome = Biome.Rainforest; } if (roll == 5) { biome = Biome.Forest; } } else if (localClimate < Climate.Temperate) { roll = Random.Range(0, 6); if (roll == 0) { biome = Biome.Chaparral; } if (roll == 1) { biome = Biome.Desert; } if (roll == 2) { biome = Biome.Lotic; } if (roll == 3) { biome = Biome.Forest; } if (roll > 3) { biome = Biome.Savanna; } } } } if(localTemp == Temperature.Hot){ if(localGeo == Geography.Mountains || localAlt == Altitude.High){ roll = Random.Range(14, 16); biome = (Biome)roll; } else if (localGeo == Geography.Flat) { roll = Random.Range(0, 6); if (roll == 0) { biome = Biome.Forest; } if (roll == 1) { biome = Biome.Grassland; } if (roll == 2) { biome = Biome.Rainforest; } if (roll == 3) { biome = Biome.Desert; } if (roll > 3) { biome = Biome.Savanna; } } else { roll = Random.Range(0, 6); if (roll == 0) { biome = Biome.Forest; } if (roll == 1) { biome = Biome.Grassland; } if (roll == 2) { biome = Biome.Savanna; } if (roll == 3) { biome = Biome.Chaparral; } if (roll == 4) { biome = Biome.Rainforest; } if (roll == 5) { biome = Biome.Desert; } } } } if(biome == Biome.Chaparral){ if(NeighborContainsAlt(Altitude.Deep) || NeighborContainsAlt(Altitude.Shallow)) {roll = Random.Range(0,3);} else {roll = Random.Range(0,1);} if(roll > 0) {biome = Biome.Lotic;} } if(localAlt == Altitude.Deep){ if(localTemp == Temperature.Temperate){ roll = Random.Range(1, 5); biome = (Biome)roll;} if(localTemp == Temperature.Hot && NeighborContainsAlt(Altitude.Shallow)){ roll = Random.Range(1, 3); biome = (Biome)roll;} else {biome = Biome.Ocean;} } if (localAlt == Altitude.Shallow) { if (!NeighborContainsGeo(Geography.SaltWater)) { roll = Random.Range(6, 8); } else { roll = Random.Range(7, 8); } if (localGeo == Geography.SaltWater) { if (localTemp >= Temperature.Temperate) { roll = Random.Range(2, 4); biome = (Biome)roll; } if (NeighborContainsAlt(Altitude.Medium)) { biome = Biome.Estuary; } else { biome = Biome.Shelf; } } if (localClimate <= Climate.Arid) { if (NeighborContainsAlt(Altitude.Low) || NeighborContainsAlt(Altitude.Medium)) { if (localTemp >= Temperature.Hot) { roll = Random.Range(13, 16); biome = (Biome)roll; } else if (localTemp <= Temperature.Cold) { roll = Random.Range(7, 10); if (roll == 7) { biome = Biome.Arctic; } else { biome = (Biome)roll; } } } } biome = (Biome)roll; } if(localGeo == Geography.SaltWater){ if(localTemp > Temperature.Cold || localTemp < Temperature.Scorching){ if(localClimate > Climate.Temperate){ roll = Random.Range(0, 4); if(roll == 0) {biome = Biome.Reef;} } } } if(localTemp == Temperature.Arctic){ if(localAlt == Altitude.Shallow){ localGeo = baseGeo; } if (localAlt == Altitude.Deep) { if (Random.Range(0, 3) == 0) { localGeo = baseGeo; } } if (localClimate > Climate.Temperate) { biome = Biome.Taiga; } else { roll = Random.Range(0, 3); if (roll == 0) { biome = Biome.Tundra; } else { biome = Biome.Arctic; } if (gridLocation.y == 2 && localClimate < Climate.Temperate) { biome = Biome.Desert; } } } if (localTemp == Temperature.Scorching) { if (localAlt == Altitude.Shallow) { localGeo = baseGeo; } if (localAlt == Altitude.Deep) { if (Random.Range(0, 3) == 0) { localGeo = baseGeo; } } else { if(localClimate < Climate.Temperate) { biome = (Biome)Random.Range(14, 16); } if(localClimate == Climate.Temperate) { biome = Biome.Savanna; } if(localClimate == Climate.Humid) { biome = Biome.Grassland; } if(localClimate == Climate.Wet) { biome = Biome.Rainforest; } } } if(biome == Biome.Desert && localGeo == Geography.Mountains){ roll = Random.Range(2, 4); localGeo = (Geography)roll; } localBiome = biome; localType = SetBiomeType(localBiome); //Corrects geo to match in salt water biomes. if (localType == BiomeType.SALTWATER) { if (localGeo != Geography.SaltWater && localGeo != Geography.Islands) { if (baseGeo == Geography.Mountains) { localGeo = Geography.Islands; } else { localGeo = Geography.SaltWater; } } } else if (localGeo == Geography.SaltWater || localGeo == Geography.Islands) { if (localType != BiomeType.SALTWATER) { localGeo = baseGeo; } } }
public void makeBuffers(int[,] tile, BiomeType[,] biomeMap) { VertexPositionNormal4Texture[] buffer = new VertexPositionNormal4Texture[(CELL_SIZE + 1) * (CELL_SIZE + 1)]; int[] iBuffer1 = new int[CELL_SIZE * CELL_SIZE * 6]; for (int n = 0; n <= CELL_SIZE; n++) { buffer[n] = new VertexPositionNormal4Texture( new Vector3(n, tile[n,0]/2, -1), new Vector3(0, 1, 0), new Vector4(1, 0, 0, 0), new Vector4((int)BiomeType.Water)); } for (int y = 0; y < CELL_SIZE; y++) for (int x = 0; x < CELL_SIZE; x++) { int n = CELL_SIZE * y + x; int h = tile[x, y]/2; if (x == 0) buffer[n + CELL_SIZE + y + 1] = new VertexPositionNormal4Texture( new Vector3(-1, tile[0,y]/2, y), new Vector3(0, 1, 0), new Vector4(1, 0, 0, 0), new Vector4((int)BiomeType.Water)); buffer[n + CELL_SIZE + y + 2] = new VertexPositionNormal4Texture(new Vector3(x, h, y), new Vector3(1, 0, 0), new Vector4(1, 0, 0, 0), new Vector4((int)biomeMap[x, y])); buffer[n + y].TextureType.Y = (int)biomeMap[x, y]; buffer[n + y].TextureWeight.Y = 1; buffer[n + y].TextureWeight.Normalize(); buffer[n + CELL_SIZE + y + 1].TextureType.Z = (int)biomeMap[x, y]; buffer[n + CELL_SIZE + y + 1].TextureWeight.Z = 1; buffer[n + CELL_SIZE + y + 1].TextureWeight.Normalize(); buffer[n + CELL_SIZE + y + 2].TextureType.W = (int)biomeMap[x, y]; buffer[n + CELL_SIZE + y + 2].TextureWeight.W = 1; buffer[n + CELL_SIZE + y + 2].TextureWeight.Normalize(); iBuffer1[n * 6] = n + y; iBuffer1[n * 6 + 1] = n + CELL_SIZE + y + 1; iBuffer1[n * 6 + 2] = n + y + 1; iBuffer1[n * 6 + 3] = n + y + 1; iBuffer1[n * 6 + 4] = n + CELL_SIZE + y + 1; iBuffer1[n * 6 + 5] = n + CELL_SIZE + y + 2; } vertices = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, (CELL_SIZE + 1) * (CELL_SIZE + 1), BufferUsage.WriteOnly); vertices.SetData(buffer); IndexBuffer indices = new IndexBuffer(Tools.Quick.device, IndexElementSize.ThirtyTwoBits, (CELL_SIZE) * (CELL_SIZE) * 6, BufferUsage.WriteOnly); indices.SetData(iBuffer1); LODIndices.Add(1, indices); }
public void SetBiome(int x, int y, BiomeType b) { biomeMap[x, y] = b; }
//checks neighbors for a given BiomeType public bool NeighborContainsBiomeType(BiomeType biome) { bool traitIsPresent = false; for (int i = 0; i < NeighborList.Count; i++) { if (NeighborList[i] != null) { Hex target = NeighborList[i].GetComponent<Hex>(); if (target.GetBiomeType() == biome) { traitIsPresent = true; } } } return traitIsPresent; }
void makeCells() { int size = GroundCell.CELL_SIZE; int[,] height = new int[size+1, size+1]; BiomeType[,] biome = new BiomeType[size+1, size+1]; int mapSize = Map.MAPSIZE; for (int x = 0; x < size + 1; x++) for (int y = 0; y < size + 1; y++) { height[y, x] = x == 0 || y == 0 ? 0 : source[x - 1, y - 1]; biome[y, x] = x == 0 || y == 0 ? BiomeType.Water : biomeMap[x - 1, y - 1]; } cells.Add(new GroundCell(height, biome, 0,0)); for (int i = 1; i < mapSize/size; i++) for (int j = 1; j < mapSize/size; j++) { for (int x = 0; x < size+1; x++) for (int y = 0; y < size+1; y++) { height[y, x] = source[i*size + x-1, j*size + y-1]; biome[y, x] = biomeMap[i*size + x-1, j*size + y-1]; } cells.Add(new GroundCell(height, biome, j*size, i*size)); } }
public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm,ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats) { int YH = b.GetLength(1) - 2; double xo = (double)(X * b.GetLength(0)); double zo = (double)(Z * b.GetLength(2)); for (int x = 0; x < b.GetLength(0); x++) { //Console.WriteLine(); for (int z = 0; z < b.GetLength(2); z++) { double hmY=(double)(System.Math.Min(hm[x, z],1d) * (b.GetLength(1) - 3)); bool HavePloppedGrass = false; bool HaveTouchedSoil = false; // Caves first if (GenerateCaves) { for (int y = 0; y < b.GetLength(1); y++) { // If we're in rock, and CavernNoise value is under a threshold value calculated by height // or CaveNoise value is over threshold value, and the block we're removing won't fall on us... if ( b[x, y, z] == 1 && ( ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1)))) || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold) ) && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13)) { // Remove it b[x, y, z] = 0; } } } for (int y = (int)b.GetLength(1) - 1; y > 0; y--) { byte supportBlock = b[x, y-1, z]; // Ensure there's going to be stuff holding us up. if (b[x, y, z] == mats.Rock && supportBlock==mats.Rock) { HaveTouchedSoil = true; if (y + depth >= YH) continue; byte ddt = b[x, y+depth, z]; switch (ddt) { case 0: // Air case 8: // Water case 9: // Water BiomeType bt = biomes[x,z]; if (bt == BiomeType.Tundra) { b[x, y, z] = mats.Sand; } else { if (y - depth <= WaterHeight && GenerateWater) { if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight) { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } else { b[x, y, z] = mats.Sand; } } else b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } if (!HavePloppedGrass) HavePloppedGrass = true; break; default: y = 0; break; } } else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mats.Water; } } } } }
internal virtual void Precipitate(ref byte[, ,] b, BiomeType[,] bt, MapGenMaterials mats, long X, long Z) { int xs = b.GetLength(0); int zs = b.GetLength(2); for (int x = 0; x < xs; x++) { for (int z = 0; z < zs; z++) { if(Biome.NeedsSnowAndIce(bt[x,z])) continue; // Fall down for (int y = b.GetLength(1) - 1; y > 0; y--) { byte block = b[x, y, z]; if (block == 0) continue; if (block == mats.Water) b[x, y, z] = mats.Ice; else b[x, y + 1, z] = mats.Snow; break; } } } }
/// <summary> /// Get the weight of the specified biome type in this pixel. /// </summary> /// <param name="biome"></param> /// <returns></returns> public float GetBiomeWeight(BiomeType biome) { return m_biomeWeights[(int)biome]; }
public Biome (BiomeType type) { this.type = type; }
public Biome(Vector2 seed, BiomeType biomeType) { this.Seed = seed; this.BiomeType = biomeType; }
private static Dictionary <int, GameObject> PickDetailLayer(BiomeType biome) { var detailChance = new Dictionary <BiomeType, int> { { BiomeType.Desert, 25 }, { BiomeType.Grassland, 28 }, { BiomeType.Ice, 40 }, { BiomeType.Swamp, 63 }, { BiomeType.Wasteland, 24 }, { BiomeType.Woodland, 100 } }; var roll = Random.Range(1, 101); if (roll <= detailChance[biome]) { int index; GameObject detail; switch (biome) { case BiomeType.Desert: index = roll % WorldData.Instance.WorldDesertDetailTiles.Length; detail = WorldData.Instance.WorldDesertDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); case BiomeType.Grassland: index = roll % WorldData.Instance.WorldGrassLandDetailTiles.Length; detail = WorldData.Instance.WorldGrassLandDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); case BiomeType.Ice: index = roll % WorldData.Instance.WorldIceDetailTiles.Length; detail = WorldData.Instance.WorldIceDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); case BiomeType.Swamp: index = roll % WorldData.Instance.WorldSwampDetailTiles.Length; detail = WorldData.Instance.WorldSwampDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); case BiomeType.Wasteland: index = roll % WorldData.Instance.WorldWasteLandDetailTiles.Length; detail = WorldData.Instance.WorldWasteLandDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); case BiomeType.SeasonalForest: case BiomeType.TropicalRainforest: case BiomeType.Woodland: index = roll % WorldData.Instance.WorldWoodLandDetailTiles.Length; detail = WorldData.Instance.WorldWoodLandDetailTiles[index]; return(new Dictionary <int, GameObject> { { index, detail } }); } } return(null); }
/// <summary> /// Set the <see cref="BiomeType" /> to the target <see cref="Chunk" /> /// </summary> /// <param name="chunk">The targeted chunk</param> /// <param name="type">The BiomeType</param> private void AssignBiomeTypeToChunk(Chunk chunk, BiomeType type) { chunk.SetBiomeType(type); //chunk.GetComponent<SpriteRenderer>().color = GetColor(chunk.GetBiomeType()); }
public Biome(BiomeType biomeType) { this.biomeType = biomeType; SetStats(); }
private void GenerateTrees() { float simplex1 = noise.GetSimplex(chunkPosX * .3f, chunkPosZ * .3f); float simplex2 = noise.GetSimplex(chunkPosX * 2f, chunkPosZ * 2f); float value = (simplex1 + simplex2) / 2; if (value > 0) { int minpos = 4; int maxpos = ChunkSizeXZ - 5; NativeList <int2> treePositions = new NativeList <int2>(MaxTreesPerChunk, Allocator.Temp); for (int i = 0; i < MaxTreesPerChunk; i++) { int x = random.NextInt(minpos, maxpos); int z = random.NextInt(minpos, maxpos); BiomeType biomeType = biomeTypes[Utils.BlockPosition2DtoIndex(x, z)]; // TODO: bool CanPlaceTree(BiomeType type) if (biomeType != BiomeType.FOREST && biomeType != BiomeType.PLAINS) { continue; } bool doContinue = false; for (int j = 0; j < treePositions.Length; j++) { int2 pos = treePositions[j]; if (math.sqrt((pos.x - x) * (pos.x - x) + (pos.y - x) * (pos.y - x)) < MinDistanceBetweenTrees) { doContinue = true; break; } } if (doContinue) { continue; } int y = ChunkSizeY - TreeHeightRange.x; if (blockData[Utils.BlockPosition3DtoIndex(x, y, z)] != BlockType.AIR) { continue; // continue if maxTerrainHeigth - minTreeHeigth hits ground } // find ground position while (y > 0 && blockData[Utils.BlockPosition3DtoIndex(x, y, z)] == BlockType.AIR) { y--; } BlockType groundBlock = blockData[Utils.BlockPosition3DtoIndex(x, y, z)]; if (!WorldData.CanPlaceTree(groundBlock)) { continue; // continue if cant place tree on ground block } // add position to position list treePositions.Add(new int2(x, z)); TreeSettings treeSettings = Trees.OakTree; // place logs int treeHeight = random.NextInt(treeSettings.TreeHeightRange.x, treeSettings.TreeHeightRange.y); for (int j = 0; j < treeHeight; j++) { if (y + j < ChunkSizeY) { blockData[Utils.BlockPosition3DtoIndex(x, y + j, z)] = BlockType.OAK_LOG; } } int treeTop = y + treeHeight - 1; int index, xrange, zrange; // <0, 1> xrange = 1; zrange = 1; for (int _y = treeTop; _y <= treeTop + 1; _y++) { for (int _x = -xrange; _x <= xrange; _x++) { for (int _z = -zrange; _z <= zrange; _z++) { index = Utils.BlockPosition3DtoIndex(x + _x, _y, z + _z); if (blockData[index] == BlockType.AIR) { blockData[index] = BlockType.OAK_LEAVES; } } } // x- z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x- z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } } // <-1, -2> xrange = 2; zrange = 2; for (int _y = treeTop - 2; _y <= treeTop - 1; _y++) { for (int _x = -xrange; _x <= xrange; _x++) { for (int _z = -zrange; _z <= zrange; _z++) { index = Utils.BlockPosition3DtoIndex(x + _x, _y, z + _z); if (blockData[index] == BlockType.AIR) { blockData[index] = BlockType.OAK_LEAVES; } } } // x- z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x- z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } } // <-3, -3> xrange = 1; zrange = 1; for (int _y = treeTop - 3; _y <= treeTop - 3; _y++) { for (int _x = -xrange; _x <= xrange; _x++) { for (int _z = -zrange; _z <= zrange; _z++) { index = Utils.BlockPosition3DtoIndex(x + _x, _y, z + _z); if (blockData[index] == BlockType.AIR) { blockData[index] = BlockType.OAK_LEAVES; } } } // x- z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x- z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x - xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z- if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z - zrange, out index)) { blockData[index] = BlockType.AIR; } // x+ z+ if (random.NextBool() && AreTypesEqual(BlockType.OAK_LEAVES, x + xrange, _y, z + zrange, out index)) { blockData[index] = BlockType.AIR; } } } } }
public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H) { int xo = (int)(X * mh.ChunkScale.X); int zo = (int)(Z * mh.ChunkScale.Z); List<Vector2i> PlantedTrees = new List<Vector2i>(); int DistanceReqd = 3; for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++) { Vector2i me = new Vector2i(rand.Next(0, 15),rand.Next(0, 15)); if (!Biome.NeedsTrees(biomes[me.X, me.Y])) continue; bool tooclose=false; foreach (Vector2i tree in PlantedTrees) { if (Vector2i.Distance(tree, me) < DistanceReqd) { tooclose = true; break; } } if (tooclose) continue; bool founddert = false; for (int y = (int)H - 10; y > 0; y--) { switch (mh.GetBlockAt(me.X+xo, y, me.Y+zo)) { case 0: // Air case 78: // Snow cover continue; // case 1: // ROCK case 2: // GRASS case 3: // DIRT //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y); mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15. /* Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8)); tree.MakeTrunk(ref mh); tree.MakeFoliage(ref mh); */ mh.SaveAll(); founddert = true; break; case 11: // SAND //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y); break; default: founddert = true; break; } if (founddert) break; } PlantedTrees.Add(me); } }
public Dictionary <GameObject, Rarities> GetBiomeTilesForAreaTileDeck(BiomeType biomeType) { var biomeTiles = new Dictionary <GameObject, Rarities>(); Dictionary <GameObject, Rarities> tilesToAdd; switch (biomeType) { case BiomeType.Desert: tilesToAdd = AddCommonTiles(AreaDesertTilesCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddUnCommonTiles(AreaDesertTilesUnCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddRareTiles(AreaDesertTilesRare); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } return(biomeTiles); case BiomeType.Grassland: case BiomeType.SeasonalForest: case BiomeType.TropicalRainforest: case BiomeType.Woodland: tilesToAdd = AddCommonTiles(AreaGrassLandTilesCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddUnCommonTiles(AreaGrassLandTilesUnCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddRareTiles(AreaGrassLandTilesRare); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } return(biomeTiles); case BiomeType.Ice: tilesToAdd = AddCommonTiles(AreaIceTilesCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddUnCommonTiles(AreaIceTilesUnCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddRareTiles(AreaIceTilesRare); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } return(biomeTiles); case BiomeType.Swamp: tilesToAdd = AddCommonTiles(AreaSwampTilesCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddUnCommonTiles(AreaSwampTilesUnCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddRareTiles(AreaSwampTilesRare); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } return(biomeTiles); case BiomeType.Wasteland: tilesToAdd = AddCommonTiles(AreaWastelandTilesCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddUnCommonTiles(AreaWastelandTilesUnCommon); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } tilesToAdd = AddRareTiles(AreaWastelandTilesRare); if (tilesToAdd != null && tilesToAdd.Count > 0) { biomeTiles = biomeTiles.Concat(tilesToAdd).ToDictionary(k => k.Key, v => v.Value); } return(biomeTiles); default: throw new ArgumentOutOfRangeException(nameof(biomeType), biomeType, null); } }
public static bool NeedsTrees(BiomeType type) { switch (type) { case BiomeType.RainForest: case BiomeType.Taiga: case BiomeType.TemperateForest: return true; default: return false; } }
public static Texture2D GenerateBiomeMapTexture(int width, int height, Tile [,] tiles, float coldest, float colder, float cold) { Texture2D texture = new Texture2D(width, height); Color [] pixels = new Color [width * height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { BiomeType value = tiles [x, y].biomeType; switch (value) { case BiomeType.Ice: pixels [x + y * width] = IceColour; break; case BiomeType.BorealForest: pixels [x + y * width] = BorealForestColour; break; case BiomeType.Desert: pixels [x + y * width] = DesertColour; break; case BiomeType.Grassland: pixels [x + y * width] = GrasslandColour; break; case BiomeType.SeasonalForest: pixels [x + y * width] = SeasonalForestColour; break; case BiomeType.Tundra: pixels [x + y * width] = TundraColour; break; case BiomeType.Savanna: pixels [x + y * width] = SavannaColour; break; case BiomeType.TemperateRainforest: pixels [x + y * width] = TemperateRainforestColour; break; case BiomeType.TropicalRainforest: pixels [x + y * width] = TropicalRainforestColour; break; case BiomeType.Woodland: pixels [x + y * width] = WoodlandColour; break; } // Water tiles if (tiles [x, y].heightType == HeightType.DeepWater) { pixels [x + y * width] = DeepColour; } else if (tiles [x, y].heightType == HeightType.ShallowWater) { pixels [x + y * width] = ShallowColour; } // draw rivers if (tiles [x, y].heightType == HeightType.River) { float heatValue = tiles [x, y].heatValue; if (tiles [x, y].heatType == HeatType.Coldest) { pixels [x + y * width] = Color.Lerp(IceWaterColour, ColdWaterColour, (heatValue) / (coldest)); } else if (tiles[x, y].heatType == HeatType.Colder) { pixels [x + y * width] = Color.Lerp(ColdWaterColour, RiverWaterColour, (heatValue - coldest) / (colder - coldest)); } else if (tiles[x, y].heatType == HeatType.Cold) { pixels [x + y * width] = Color.Lerp(RiverWaterColour, ShallowColour, (heatValue - colder) / (cold - colder)); } else { pixels [x + y * width] = ShallowColour; } } // add a outline if (tiles [x, y].heightType >= HeightType.Shore && tiles [x, y].heightType != HeightType.River) { if (tiles [x, y].biomeBitmask != 15) { pixels [x + y * width] = Color.Lerp(pixels [x + y * width], Color.black, 0.35f); } } } } texture.SetPixels(pixels); texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); return(texture); }
public static bool NeedsSnowAndIce(BiomeType biomeType) { switch (biomeType) { case BiomeType.Taiga: case BiomeType.Tundra: return true; default: return false; } }
public Texture2D GetBiomeMapTexture(int width, int height, MapData tiles) { var texture = new Texture2D(width, height); var pixels = new Color[width * height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { BiomeType value = tiles[x, y].BiomeType; switch (value) { case BiomeType.Ice: pixels[x + y * width] = Ice; break; case BiomeType.BorealForest: pixels[x + y * width] = BorealForest; break; case BiomeType.Desert: pixels[x + y * width] = Desert; break; case BiomeType.Grassland: pixels[x + y * width] = Grassland; break; case BiomeType.SeasonalForest: pixels[x + y * width] = SeasonalForest; break; case BiomeType.Tundra: pixels[x + y * width] = Tundra; break; case BiomeType.Savanna: pixels[x + y * width] = Savanna; break; case BiomeType.TemperateRainforest: pixels[x + y * width] = TemperateRainforest; break; case BiomeType.TropicalRainforest: pixels[x + y * width] = TropicalRainforest; break; case BiomeType.Woodland: pixels[x + y * width] = Woodland; break; } // Water tiles if (tiles[x, y].HeightType == HeightType.DeepWater) { pixels[x + y * width] = DeepColor; } else if (tiles[x, y].HeightType == HeightType.ShallowWater) { pixels[x + y * width] = ShallowColor; } // draw rivers /* if (tiles[x, y].HeightType == HeightType.River) * { * float heatValue = tiles[x, y].HeatValue; * * if (tiles[x, y].HeatType == HeatType.Coldest) * pixels[x + y * width] = Color.Lerp(IceWater, ColdWater, (heatValue) / (coldest)); * else if (tiles[x, y].HeatType == HeatType.Colder) * pixels[x + y * width] = Color.Lerp(ColdWater, RiverWater, (heatValue - coldest) / (colder - coldest)); * else if (tiles[x, y].HeatType == HeatType.Cold) * pixels[x + y * width] = Color.Lerp(RiverWater, ShallowColor, (heatValue - colder) / (cold - colder)); * else * pixels[x + y * width] = ShallowColor; * } * * * // add a outline * if (tiles[x, y].HeightType >= HeightType.Shore && tiles[x, y].HeightType != HeightType.River) * { * if (tiles[x, y].BiomeBitmask != 15) * pixels[x + y * width] = Color.Lerp(pixels[x + y * width], Color.black, 0.35f); * }*/ } } texture.SetPixels(pixels); texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); return(texture); }
/// <summary> /// returns a path to location of the file depending on biome type /// </summary> /// <param name="type"></param> /// <returns></returns> private static string GetBiomePathFromType(BiomeType type) { return(BIOME_FOLDER_PATH + type); }
/// <summary> /// Get an array of biome weights that allocate 100% weight to a single biome type. /// </summary> /// <param name="biome"></param> /// <returns></returns> public float[] getFullWeightBiome(BiomeType biome) { float[] biomeWeights = new float[Enum.GetValues(typeof(BiomeType)).Length]; biomeWeights[(int)biome] = 1f; return biomeWeights; }
public static Texture getBiomeMapTexture(Tile[,] tiles, float coldest, float colder, float cold) { int width = tiles.GetLength(0); int height = tiles.GetLength(1); var texture = new Texture(width, height); var pixels = new Color4[width, height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { BiomeType value = tiles[x, y].myBiomeType; switch (value) { case BiomeType.Ice: pixels[x, y] = Ice; break; case BiomeType.Tundra: pixels[x, y] = Tundra; break; case BiomeType.Desert: pixels[x, y] = Desert; break; case BiomeType.Grassland: pixels[x, y] = Grassland; break; case BiomeType.Savanna: pixels[x, y] = Savanna; break; case BiomeType.TemperateSeasonalForest: pixels[x, y] = TemperateSeasonalForest; break; case BiomeType.TropicalSeasonalForest: pixels[x, y] = TropicalSeasonalForest; break; case BiomeType.Taiga: pixels[x, y] = Taiga; break; case BiomeType.TemperateRainforest: pixels[x, y] = TemperateRainForest; break; case BiomeType.TropicalRainforest: pixels[x, y] = TropicalRainForest; break; } // Water tiles if (tiles[x, y].myHeightType == HeightType.DeepWater) { pixels[x, y] = DeepColor; } else if (tiles[x, y].myHeightType == HeightType.ShallowWater) { pixels[x, y] = ShallowColor; } // draw rivers if (tiles[x, y].myHeightType == HeightType.River) { float heatValue = tiles[x, y].myHeatValue; if (tiles[x, y].myHeatType == HeatType.Coldest) { pixels[x, y] = ColorExt.mix(IceWater, ColdWater, (heatValue) / (coldest)); } else if (tiles[x, y].myHeatType == HeatType.Colder) { pixels[x, y] = ColorExt.mix(ColdWater, RiverWater, (heatValue - coldest) / (colder - coldest)); } else if (tiles[x, y].myHeatType == HeatType.Cold) { pixels[x, y] = ColorExt.mix(RiverWater, ShallowColor, (heatValue - colder) / (cold - colder)); } else { pixels[x, y] = ShallowColor; } } // add a outline if (tiles[x, y].myHeightType >= HeightType.Shore && tiles[x, y].myHeightType != HeightType.River) { if (tiles[x, y].myBiomeBitmask != 15) { pixels[x, y] = ColorExt.mix(pixels[x, y], Color4.Black, 0.35f); } } } } texture.setPixels(ref pixels); return(texture); }
public Chunk(int chunkX, int chunkY, int width, int height, int mapWidth, int mapHeight, NoiseGenerator noiseGenerator, GraphicsDeviceManager graphics, PlanetTypes planetType) { Width = width; Height = height; this.planetType = planetType; Cells = new Cell[height, width]; ChunkX = chunkX; ChunkY = chunkY; List <List <Vector3> > positions = new List <List <Vector3> >(); List <List <Vector2> > texturePositions = new List <List <Vector2> >(); List <List <Color> > colors = new List <List <Color> >(); Biomes = new List <BiomeType>(); int biomesTotal = 0; Dictionary <int, int> biomesToPos = new Dictionary <int, int>(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Cells[y, x] = new Cell(); int _cellGlobalIndex = (y + chunkY * height) * width * mapWidth + x + chunkX * width; BiomeType biome = noiseGenerator.BiomeAtIndex(_cellGlobalIndex); int pushIndex = -1; if (!biomesToPos.TryGetValue((int)biome, out pushIndex)) { positions.Add(new List <Vector3>()); texturePositions.Add(new List <Vector2>()); colors.Add(new List <Color>()); biomesToPos.Add((int)biome, biomesTotal); pushIndex = biomesTotal; biomesTotal++; Biomes.Add(biome); } (List <Vector3> __positions, List <Vector2> __texturePositions, List <Color> __colors, List <int> __indicies) = Cells[y, x].GenerateMesh(chunkX, chunkY, width, height, mapWidth, mapHeight, x, y, noiseGenerator); positions[pushIndex].AddRange(__positions); texturePositions[pushIndex].AddRange(__texturePositions); colors[pushIndex].AddRange(__colors); } } //positions.Reverse(); //colors.Reverse(); //vertices = new VertexPositionColor[positions.Count]; Indicies = new IndexBuffer(graphics.GraphicsDevice, IndexElementSize.ThirtyTwoBits, positions.Count, BufferUsage.WriteOnly); Vertices = new VertexPositionColorTexture[biomesTotal][]; int[] indicies = new int[positions.Count]; for (int i = 0; i < positions.Count; i++) { var _vertices = new VertexPositionColorTexture[positions[i].Count]; for (int j = 0; j < positions[i].Count; j++) { _vertices[j] = new VertexPositionColorTexture(positions[i][j], colors[i][j], texturePositions[i][j]); } Vertices[i] = _vertices; //vertices[i] = new VertexPositionColor(positions[i], colors[i]); //indicies[i] = i; } Indicies.SetData(indicies); BoundingBox = new BoundingBox(new Vector3(chunkX * width * Cell.innerRadius * 2, chunkY * height * Cell.outerRadius * 3 / 2, 0), new Vector3((chunkX + 1) * width * Cell.innerRadius * 2, (chunkY + 1) * height * Cell.outerRadius * 3 / 2, 0)); testEffect = new BasicEffect(graphics.GraphicsDevice); }
public BiomeBase() { Type = BiomeType.Unknown; }
public GroundCell(ref int[,] tiles, BiomeType[,] biomeMap) { makeBiomeMap(Tools.Quick.device, biomeMap); }
public Biome() { _type = BiomeType.Plains; }
public Voxel(Vector3 position, BiomeType biome, MaterialType material) { this.position = position; this.biome = biome; this.material = material; }
public Biome(BiomeType tt) { _type = tt; }
public CellSurface GetBiomeMapTexture(int width, int height, Tile[,] tiles, float coldest, float colder, float cold) { var surface = new CellSurface(width, height); var pixels = new Color[width * height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { BiomeType value = tiles[x, y].BiomeType; switch (value) { case BiomeType.Ice: pixels[x + y * width] = Ice; break; case BiomeType.BorealForest: pixels[x + y * width] = BorealForest; break; case BiomeType.Desert: pixels[x + y * width] = Desert; break; case BiomeType.Grassland: pixels[x + y * width] = Grassland; break; case BiomeType.SeasonalForest: pixels[x + y * width] = SeasonalForest; break; case BiomeType.Tundra: pixels[x + y * width] = Tundra; break; case BiomeType.Savanna: pixels[x + y * width] = Savanna; break; case BiomeType.TemperateRainforest: pixels[x + y * width] = TemperateRainforest; break; case BiomeType.TropicalRainforest: pixels[x + y * width] = TropicalRainforest; break; case BiomeType.Woodland: pixels[x + y * width] = Woodland; break; } // Water tiles if (tiles[x, y].HeightType == HeightType.DeepWater) { pixels[x + y * width] = DeepColor; } else if (tiles[x, y].HeightType == HeightType.ShallowWater) { pixels[x + y * width] = ShallowColor; } // draw rivers if (tiles[x, y].HeightType == HeightType.River) { float heatValue = tiles[x, y].HeatValue; if (tiles[x, y].HeatType == HeatType.Coldest) { pixels[x + y * width] = Color.Lerp(IceWater, ColdWater, (heatValue) / (coldest)); } else if (tiles[x, y].HeatType == HeatType.Colder) { pixels[x + y * width] = Color.Lerp(ColdWater, RiverWater, (heatValue - coldest) / (colder - coldest)); } else if (tiles[x, y].HeatType == HeatType.Cold) { pixels[x + y * width] = Color.Lerp(RiverWater, ShallowColor, (heatValue - colder) / (cold - colder)); } else { pixels[x + y * width] = ShallowColor; } } // add a outline if (tiles[x, y].HeightType >= HeightType.Shore && tiles[x, y].HeightType != HeightType.River) { if (tiles[x, y].BiomeBitmask != 15) { pixels[x + y * width] = Color.Lerp(pixels[x + y * width], Color.Black, 0.35f); } } } } surface.SetPixels(pixels); return(surface); }
public List <Room> GetRoomsByBiomeType(BiomeType biomeType) { var results = Rooms.Where(r => r.BiomeType == biomeType).ToList(); return(results); }
public LandBrush(float x_, float z_, int chunkSize_, TerrainType terrainType_, BiomeType biomeType_) { this.x = x_; this.z = z_; this.chunksize = chunkSize_; this.terrainType = terrainType_; this.biomeType = biomeType_; }
public Biome(BiomeType type, Dictionary <byte, Func <byte, Pixel> > heightToColor) { Type = type; HeightToColor = heightToColor; }
/// <summary> /// Retrieve all the <see cref="Chunk" /> at the specific distance /// </summary> /// <param name="biomeType">The target BiomeType of the founded chunks</param> /// <param name="minDistance">The minimal distance to another biome</param> /// <returns>The list of founded chunks</returns> public List <Chunk> GetChunkFromMinDistance(BiomeType biomeType, int minDistance) { Biome targetBiome = _biomes[biomeType]; return(targetBiome.GetChunksFromMinDistance(minDistance)); }
public static Color GetBiomeColor(BiomeType biomeType) { return(Instance.biomeColors.GetBiomeColor(biomeType)); }
public static Texture2D GetBiomeMapTexture(int width, int height, Cell[,] cells, float coldest, float colder, float cold) { var texture = new Texture2D(width, height); var pixels = new Color[width * height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { BiomeType value = cells[x, y].BiomeType; switch (value) { case BiomeType.Ice: pixels[x + y * width] = Ice; break; case BiomeType.Wasteland: pixels[x + y * width] = Wasteland; break; case BiomeType.Desert: pixels[x + y * width] = Desert; break; case BiomeType.Grassland: pixels[x + y * width] = Grassland; break; case BiomeType.SeasonalForest: pixels[x + y * width] = SeasonalForest; break; case BiomeType.Swamp: pixels[x + y * width] = Swamp; break; case BiomeType.TropicalRainforest: pixels[x + y * width] = TropicalRainforest; break; case BiomeType.Woodland: pixels[x + y * width] = Woodland; break; } // Water tiles if (cells[x, y].HeightType == HeightType.DeepWater) { pixels[x + y * width] = DeepColor; } else if (cells[x, y].HeightType == HeightType.ShallowWater) { pixels[x + y * width] = ShallowColor; } // draw rivers if (cells[x, y].HeightType == HeightType.River) { float heatValue = cells[x, y].HeatValue; if (cells[x, y].HeatType == HeatType.Coldest) { pixels[x + y * width] = Color.Lerp(IceWater, ColdWater, (heatValue) / (coldest)); } else if (cells[x, y].HeatType == HeatType.Colder) { pixels[x + y * width] = Color.Lerp(ColdWater, RiverWater, (heatValue - coldest) / (colder - coldest)); } else if (cells[x, y].HeatType == HeatType.Cold) { pixels[x + y * width] = Color.Lerp(RiverWater, ShallowColor, (heatValue - colder) / (cold - colder)); } else { pixels[x + y * width] = ShallowColor; } } // add a outline if (cells[x, y].HeightType >= HeightType.Shore && cells[x, y].HeightType != HeightType.River) { if (cells[x, y].BiomeBitmask != 15) { pixels[x + y * width] = Color.Lerp(pixels[x + y * width], Color.black, 0.35f); } } } } texture.SetPixels(pixels); texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); return(texture); }
public static bool findVertIndexOfAdjenctVerts(Mesh mesh, int vertIndex, List <List <int> > triList, Dictionary <int, BiomeType> vertBiomes, BiomeType targetBiome, BiomeType secondTargetBiome) { List <int> adjecentVertIndexs = new List <int>(); for (int i = 0; i < triList.Count; i++) { for (int j = 0; j < triList[i].Count; j++) { if (triList[i].Contains(vertIndex)) { if (triList[i][j] != vertIndex) { adjecentVertIndexs.Add(triList[i][j]); } } } } return(findTransitionVerts(adjecentVertIndexs, vertBiomes, vertIndex, targetBiome, secondTargetBiome)); }
public static Vector2[] GetUVs(BiomeType biomeType, TextureType textureType, TextureSide textureSide) { return(Coordinates.GetTexture(biomeType, textureType, textureSide)); }
public Biome(BiomeType newType) { Type = newType; }
public void GenerateSplatMapBiome(Bounds updateBounds, BiomeType biomeType, List <PolygonBiomeMask> polygonBiomeMaskList, List <TerrainTextureSettings> terrainTextureSettingsList, float heightCurveSampleHeight, float worldSpaceSeaLevel, bool clearLockedTextures) { int width = _terrain.terrainData.alphamapWidth; int height = _terrain.terrainData.alphamapHeight; int layers = _terrain.terrainData.alphamapLayers; int blendMaskLength = width * height; NativeArray <float> blendMask = new NativeArray <float>(blendMaskLength, Allocator.TempJob); NativeArray <float> splatmapArray = new NativeArray <float>(width * height * layers, Allocator.TempJob); if (biomeType == BiomeType.Default) { GenerateDefaultBiomeBlendMaskJob generateDefaultBiomeBlendMaskJob = new GenerateDefaultBiomeBlendMaskJob { BlendMask = blendMask }; _splatMapHandle = generateDefaultBiomeBlendMaskJob.Schedule(blendMaskLength, 32, _splatMapHandle); } else { for (int i = 0; i <= polygonBiomeMaskList.Count - 1; i++) { GenerateBlendMaskJob generateBlendMaskJob = new GenerateBlendMaskJob { Width = width, Height = height, TerrainSize = _size, TerrainPosition = TerrainPosition, BlendMask = blendMask, PolygonArray = polygonBiomeMaskList[i].PolygonArray, SegmentArray = polygonBiomeMaskList[i].SegmentArray, CurveArray = polygonBiomeMaskList[i].TextureCurveArray, UseNoise = polygonBiomeMaskList[i].UseNoise, NoiseScale = polygonBiomeMaskList[i].NoiseScale, BlendDistance = polygonBiomeMaskList[i].BlendDistance, PolygonRect = RectExtension.CreateRectFromBounds(polygonBiomeMaskList[i].MaskBounds), Include = true }; _splatMapHandle = generateBlendMaskJob.Schedule(blendMaskLength, 32, _splatMapHandle); } } for (int i = 0; i <= terrainTextureSettingsList.Count - 1; i++) { if (i >= layers) { continue; } if (terrainTextureSettingsList[i].Enabled) { ProcessSplatMapJob processSplatMap = new ProcessSplatMapJob { Height = height, Width = width, Layers = layers, SplatMapArray = splatmapArray, BlendMask = blendMask, HeightMap = _heightMapSamples, Heights = Heights, TextureIndex = i, TextureUseNoise = terrainTextureSettingsList[i].UseNoise, TextureNoiseScale = terrainTextureSettingsList[i].NoiseScale, TextureWeight = terrainTextureSettingsList[i].TextureWeight, TextureNoiseOffset = terrainTextureSettingsList[i].NoiseOffset, InverseTextureNoise = terrainTextureSettingsList[i].InverseNoise, HeightCurve = terrainTextureSettingsList[i].HeightCurveArray, SteepnessCurve = terrainTextureSettingsList[i].SteepnessCurveArray, TerrainHeight = heightCurveSampleHeight, TerrainYPosition = TerrainPosition.y, WorldspaceSeaLevel = worldSpaceSeaLevel, HeightMapScale = _heightmapScale, HeightmapHeight = _heightmapHeight, HeightmapWidth = _heightmapWidth, ConcaveEnable = terrainTextureSettingsList[i].ConcaveEnable, ConvexEnable = terrainTextureSettingsList[i].ConvexEnable, ConcaveAverage = terrainTextureSettingsList[i].ConcaveAverage, ConcaveMinHeightDifference = terrainTextureSettingsList[i].ConcaveMinHeightDifference, ConcaveDistance = terrainTextureSettingsList[i].ConcaveDistance, ConcaveMode = (int)terrainTextureSettingsList[i].ConcaveMode }; _splatMapHandle = processSplatMap.Schedule(width * height * layers, 32, _splatMapHandle); } else { if (!clearLockedTextures && terrainTextureSettingsList[i].LockTexture) { CopyLockedDataJob copyLockedDataJobJob = new CopyLockedDataJob { Height = height, Width = width, Layers = layers, SplatMapArray = splatmapArray, CurrentSplatMapArray = _currentSplatmapArray, TextureIndex = i, }; _splatMapHandle = copyLockedDataJobJob.Schedule(width * height * layers, 32, _splatMapHandle); } } } int firstEnabledIndex = 0; for (int i = 0; i <= terrainTextureSettingsList.Count - 1; i++) { if (terrainTextureSettingsList[i].Enabled) { firstEnabledIndex = i; break; } } if (!clearLockedTextures) { NativeArray <int> lockedTextureArray = new NativeArray <int>(terrainTextureSettingsList.Count, Allocator.TempJob); NativeArray <int> automaticGenerationArray = new NativeArray <int>(terrainTextureSettingsList.Count, Allocator.TempJob); for (int i = 0; i <= terrainTextureSettingsList.Count - 1; i++) { if (terrainTextureSettingsList[i].Enabled) { automaticGenerationArray[i] = 1; } else if (terrainTextureSettingsList[i].LockTexture) { lockedTextureArray[i] = 1; } } NormalizeSplatMapKeepLockedDataJob normalizeSplatMapJob = new NormalizeSplatMapKeepLockedDataJob { SplatMapArray = splatmapArray, FirstEnabledIndex = firstEnabledIndex, AutomaticGenerationArray = automaticGenerationArray, LockedTextureArray = lockedTextureArray }; _splatMapHandle = normalizeSplatMapJob.ScheduleBatch(width * height * layers, layers, _splatMapHandle); } else { NormalizeSplatMapJob normalizeSplatMapJob = new NormalizeSplatMapJob { SplatMapArray = splatmapArray, FirstEnabledIndex = firstEnabledIndex }; _splatMapHandle = normalizeSplatMapJob.ScheduleBatch(width * height * layers, layers, _splatMapHandle); } //blend biome splatmap against current splatmap BlendSplatMapJob blendSplatMapJob = new BlendSplatMapJob { CurrentSplatMapArray = _currentSplatmapArray, SplatMapArray = splatmapArray, BlendMask = blendMask, Height = height, Width = width, Layers = layers }; _splatMapHandle = blendSplatMapJob.Schedule(width * height * layers, 32, _splatMapHandle); _nativeArrayFloatList.Add(splatmapArray); _nativeArrayFloatList.Add(blendMask); }
bool IsTileCompatible (BiomeType[, ] bMap, int x, int y, List<BiomeType> biomes) { foreach (BiomeType biome in biomes) { if (bMap[x, y] == biome) return true; } return false; }
public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm, ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats) { int YH = b.GetLength(1) - 2; double xo = (double)(X * b.GetLength(0)); double zo = (double)(Z * b.GetLength(2)); for (int x = 0; x < b.GetLength(0); x++) { //Console.WriteLine(); for (int z = 0; z < b.GetLength(2); z++) { double hmY = (double)(System.Math.Min(hm[x, z], 1d) * (b.GetLength(1) - 3)); bool HavePloppedGrass = false; bool HaveTouchedSoil = false; // Caves first if (GenerateCaves) { for (int y = 0; y < b.GetLength(1); y++) { // If we're in rock, and CavernNoise value is under a threshold value calculated by height // or CaveNoise value is over threshold value, and the block we're removing won't fall on us... if ( b[x, y, z] == 1 && ( ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1)))) || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold) ) && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13)) { // Remove it b[x, y, z] = 0; } } } for (int y = (int)b.GetLength(1) - 1; y > 0; y--) { byte supportBlock = b[x, y - 1, z]; // Ensure there's going to be stuff holding us up. if (b[x, y, z] == mats.Rock && supportBlock == mats.Rock) { HaveTouchedSoil = true; if (y + depth >= YH) { continue; } byte ddt = b[x, y + depth, z]; switch (ddt) { case 0: // Air case 8: // Water case 9: // Water BiomeType bt = biomes[x, z]; if (bt == BiomeType.Tundra) { b[x, y, z] = mats.Sand; } else { if (y - depth <= WaterHeight && GenerateWater) { if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight) { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } else { b[x, y, z] = mats.Sand; } } else { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } } if (!HavePloppedGrass) { HavePloppedGrass = true; } break; default: y = 0; break; } } else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mats.Water; } } } } }
public World SetBiomeAt(int x, int y, BiomeType type) { this.biomeMap[x, y] = type; return this; }
public static bool findTransitionVerts(List <int> adjecentVertIndexs, Dictionary <int, BiomeType> vertBiomes, int vertIndex, BiomeType targetBiome, BiomeType secondTargetBiome) { bool result = false; bool biomeOne = false; bool biomeTwo = false; for (int i = 0; i < adjecentVertIndexs.Count; i++) { if (vertBiomes[vertIndex] == targetBiome) { biomeOne = true; BiomeType temp = vertBiomes[adjecentVertIndexs[i]]; if (temp == secondTargetBiome) { biomeTwo = true; } } if (vertBiomes[vertIndex] == secondTargetBiome) { biomeTwo = true; BiomeType temp = vertBiomes[adjecentVertIndexs[i]]; if (temp == targetBiome) { biomeOne = true; } } if (biomeOne && biomeTwo) { result = true; break; } } return(result); }
public GameObject GetTileTextureByNameRarityAndBiome(string prefabName, BiomeType biomeType) { var biomeTiles = new Dictionary <string, GameObject>(); switch (biomeType) { case BiomeType.Desert: { foreach (var tile in AreaDesertTilesCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaDesertTilesUnCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaDesertTilesRare) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in DesertAsphaltRoadTiles) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } break; } case BiomeType.Grassland: case BiomeType.Woodland: { foreach (var tile in AreaGrassLandTilesCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaGrassLandTilesUnCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaGrassLandTilesRare) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in GrassDirtPathTiles) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } break; } case BiomeType.Ice: { foreach (var tile in AreaIceTilesCommon) { biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaIceTilesUnCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaIceTilesRare) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in IceAsphaltRoadTiles) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } break; } case BiomeType.Swamp: { foreach (var tile in AreaSwampTilesCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaSwampTilesUnCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaSwampTilesRare) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in SwampDirtPathTiles) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } break; } case BiomeType.Wasteland: { foreach (var tile in AreaWastelandTilesCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaWastelandTilesUnCommon) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in AreaWastelandTilesRare) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } foreach (var tile in WastelandDirtPathTiles) { if (biomeTiles.ContainsKey(tile.name)) { continue; } biomeTiles.Add(tile.name, tile); } break; } } if (!biomeTiles.ContainsKey(prefabName)) { Debug.Log($@"Could not find tile prefab by name {prefabName} for biome type {biomeType}"); return(biomeTiles.Values.ToArray()[Random.Range(0, biomeTiles.Count)]); } var texture = biomeTiles[prefabName]; return(texture); }