public Biome(Biome biome) { this.iD = biome.ID; this.spawnConfiguration = biome.spawnConfiguration; this.grass = biome.Grass; this.rock = biome.Rock; }
// TODO: Clean, reduce to only what's necessary. Every entry in this list makes things that much more expensive. /*public static Vector3i[] Rels = new Vector3i[] { new Vector3i(-10, 10, 0), new Vector3i(-10, -10, 0), new Vector3i(10, 10, 0), new Vector3i(10, -10, 0), new Vector3i(-15, 15, 0), new Vector3i(-15, -15, 0), new Vector3i(15, 15, 0), new Vector3i(15, -15, 0), new Vector3i(-20, 20, 0), new Vector3i(-20, -20, 0), new Vector3i(20, 20, 0), new Vector3i(20, -20, 0), new Vector3i(-5, 5, 0), new Vector3i(-5, -5, 0), new Vector3i(5, 5, 0), new Vector3i(5, -5, 0), new Vector3i(-10, 0, 0), new Vector3i(0, -10, 0), new Vector3i(10, 0, 0), new Vector3i(0, 10, 0), new Vector3i(-20, 0, 0), new Vector3i(0, -20, 0), new Vector3i(20, 0, 0), new Vector3i(0, 20, 0), new Vector3i(-15, 0, 0), new Vector3i(0, -15, 0), new Vector3i(15, 0, 0), new Vector3i(0, 15, 0), new Vector3i(-5, 0, 0), new Vector3i(0, -5, 0), new Vector3i(5, 0, 0), new Vector3i(0, 5, 0)}; double relmod = 1f;*/ public override double GetHeight(int Seed, int seed2, int seed3, int seed4, int seed5, double x, double y, double z, out Biome biome) { #if TIMINGS Stopwatch sw = new Stopwatch(); sw.Start(); try #endif { double valBasic = GetHeightQuick(Seed, seed2, x, y); //if (z < -50 || z > 50) { biome = Biomes.BiomeFor(seed2, seed3, seed4, x, y, z, valBasic); return valBasic; } /*Biome b = Biomes.BiomeFor(seed2, seed3, seed4, x, y, z, valBasic); double total = valBasic; * ((SimpleBiome)b).HeightMod(); foreach (Vector3i vecer in Rels) { double valt = GetHeightQuick(Seed, seed2, x + vecer.X * relmod, y + vecer.Y * relmod); Biome bt = Biomes.BiomeFor(seed2, seed3, seed4, x + vecer.X * relmod, y + vecer.Y * relmod, z, valt); total += valt * ((SimpleBiome)bt).HeightMod(); } biome = b; return total / (Rels.Length + 1); */ } #if TIMINGS finally { sw.Stop(); Timings_Height += sw.ElapsedTicks / (double)Stopwatch.Frequency; } #endif }
public GTile(int index_x, int index_y) { this.index_x = index_x; this.index_y = index_y; biome = BiomeData.tropical_forest; Contained_Objects = new GObject_Tile_RefList (new Vector2(index_x, index_y)); }
public Chunk(Chunk chunk) : base(chunk) { this.bridge = chunk.bridge; this.b = chunk.B; this.isPrisme = chunk.IsPrisme; this.step = 0; this.posSave = 0; }
// Constructor public Chunk() : base() { this.bridge = Bridges.None; this.b = BiomeDatabase.Default; this.isPrisme = false; this.step = 0; this.posSave = 0; }
public Tile(short x, short y, Biome biome, short width, short height) { X = x; Y = y; Biome = biome; Width = width; Height = height; TileContents = new List<IEntity>(); Illuminators = new List<IIlluminator>(); }
public TileType(string name="", Texture2D texture = null, double movementCost=1.0, Biome biome=Biome.Plain, List<UnitType.MovementType> allowedMovementTypes=null, ResourceType resourceType=ResourceType.None, float rotation=0.0f) { this.name = name; this.texture = texture; this.movementCost = movementCost; this.biome = biome; this.allowedMovementTypes = allowedMovementTypes ?? new List<UnitType.MovementType>(); this.resourceType = resourceType; this.rotation = rotation; // In radians clockwise }
// Set tile biome public void SetTileBiome() { tilePos = transform.position; float biomeNoiseAmpl = 20; float tempNoise = (biomeNoiseAmpl *(Mathf.PerlinNoise (tilePos.x / scale + translate_x + random, tilePos.z / scale + translate_z + random))) - biomeNoiseAmpl / 2; float humidNoise = (biomeNoiseAmpl * (Mathf.PerlinNoise (tilePos.x / scale + translate_x + random, tilePos.z / scale + translate_z + random))) - biomeNoiseAmpl / 2; if (tempNoise > 3 && humidNoise < 3) { value = Biome.desert; } else { value = Biome.forest; } PaintTile (); }
private void CreateLayers() { var parts = GeneratorOptions.Split(';'); var layers = parts[1].Split(','); Layers = new List<GeneratorLayer>(); double y = 0; foreach (var layer in layers) { var generatorLayer = new GeneratorLayer(layer); y += generatorLayer.Height; Layers.Add(generatorLayer); } Biome = (Biome)byte.Parse(parts[2]); }
private void HandleChunkSpawns(Biome biome) { GD.Print("Number of chunks in this patch = ", biome.Chunks.Count); foreach (var entry in biome.Chunks) { HandleSpawnHelper(chunkSpawners, entry.Value.Name, entry.Value.Density, () => { var spawner = new CreatedSpawner(entry.Value.Name); spawner.Spawner = Spawners.MakeChunkSpawner(entry.Value, compoundCloudSystem); spawnSystem.AddSpawnType(spawner.Spawner, (int)entry.Value.Density, Constants.MICROBE_SPAWN_RADIUS); return(spawner); }); } }
public GameObject instanciatePlantimal(Animal animal, Biome biome) { Debug.Log("INSTANCIATE A PLANTIMAL"); var newPlantimal = Instantiate(plantimal, Vector3.zero, Quaternion.identity); string name = names[Random.Range(0, names.Length)]; var attributes = new Attributes(animal, biome, Food.Normal); SwapSprites swapSprites = newPlantimal.GetComponent <SwapSprites>(); swapSprites.SpriteSheetName = getFirstPlantimal(animal); var sprite = swapSprites.getFirstSprite(); newPlantimal.GetComponent <Plantimal>().instanciate(attributes, sprite, name); swapSprites.SpriteSheetName = animal.ToString(); return(newPlantimal); }
// Start is called before the first frame update void Start() { activeTiles = new List <GameObject>(); spawnTransform = transform; h = spawnTransform.position.x + tileLength; h -= tileOnScreenAmount * tileLength - 1; for (int i = 0; i < tileOnScreenAmount; i++) { SpawnTileStart(new Vector3(h, 0.01f, 0)); h += tileLength; } currentBiome = biomes[0]; tileNumber = 0; curBiomeTile = 0; curBiomeSize = Mathf.RoundToInt(Random.Range(currentBiome.biomeSize.x, currentBiome.biomeSize.y)); }
public static Cube.Type TypeOverlay(int x, int z, int y, Biome biome) { foreach (TypeLayer layer in biome.typeOverlays) { if (y > layer.minHeight && y < layer.maxHeight) { float accumulation = 0; foreach (Perlinlayer perlinLayer in layer.perlinLayers) { accumulation += fn.GetSimplex(x * perlinLayer.stretch + 1000, z * perlinLayer.stretch - 4253); if (accumulation / layer.perlinLayers.Count > layer.thresHold) { return(layer.type); } } } } return(Cube.Type.None); }
public void EditBiome(Biome b, double uk, double lk, double up, double lp, double humidity, string name, double startYear, double endYear, string description, string keys) { try { TempatureRange t = new TempatureRange(uk, lk); PressureRange p = new PressureRange(up, lp); Year sy = new Year(startYear); Year ey = new Year(endYear); List <string> keywords = keys.ToUpper().Split(' ').ToList(); b.Edit(b.Biomes, t, p, humidity, name, sy, ey, description, keywords); Logger.AddLog($"Edited the biome: {b.Name}"); BiomesChanged.Invoke(this, null); } catch { Logger.AddLog($"Unable to add the biome: {b.Name}"); } }
public TerrainChunk(Vector2 relativeCoord, int size, levelOfDetailLimit[] LODLimits, Material material, Biome biome) { this.LODLimits = LODLimits; this.relativeCoord = relativeCoord; this.material = material; this.biome = biome; scaledWorldPosition = new Vector3(relativeCoord.x * size, 0, relativeCoord.y * size); scaledWorldPosition *= _meshChunkScale; worldBounds = new Bounds(relativeCoord * size, Vector2.one * size); //Bounds calculations will only take X and Z world axes into consideration, hence the 2D position levelOfDetailMeshes = new LODMesh[LODLimits.Length]; for (int i = 0; i < levelOfDetailMeshes.Length; i++) { levelOfDetailMeshes[i] = new LODMesh(LODLimits[i].levelOfDetail, UpdateVisibilityOrLOD); } generator.GenerateMapDataAsync(new Vector2(relativeCoord.x * size, relativeCoord.y * size), OnMapDataReceived); }
public void ResetForBiome(Biome biome) { Clear(); SetupRooms(); if (Run.Type == RunType.BossRush) { return; } if (biome is JungleBiome || biome is CaveBiome) { Add(new PatchWall(), 5f); } else if (biome is LibraryBiome) { Add(new TeleportSplitWall(), 5f); } }
public void SetupMap() { // Checks if there's already a world instance if (world) { Destroy(world); } // Random Selection of biome, border layout and size int biomeIndex = 0; if (biomes.Length > 1) { biomeIndex = Random.Range(0, biomes.Length - 1); } Biome biomeSelected = biomes[biomeIndex]; int borderIndex = Random.Range(0, biomeSelected.borderPrefabs.Length - 1); worldSize = Random.Range(SizeOfTheWorldRange.x, SizeOfTheWorldRange.y); if (worldSize % 2 != 0) { worldSize -= 1; } // Creation of the grid gridGen.CreateGrid(); // Creates the World GO with selected border world = Instantiate(new GameObject(), Vector3.zero, Quaternion.identity, this.transform); world.name = "World"; GameObject map = Instantiate(biomeSelected.borderPrefabs[borderIndex], new Vector3(gridGen.gridData.nodeRadius, gridGen.gridData.nodeRadius, 0f), Quaternion.identity, world.transform); map.GetComponent <SpriteRenderer>().size = new Vector2(worldSize + 1f, worldSize + 1f); map.name = "Map"; // Generates obstacles and the ground GenerateObstacles(biomeIndex); GenerateGround(biomeIndex); GenerateFood(true); }
private static void GenTerrain() { //gen int ptr = 0; int h = MathUtil.RandInt(rand, minlandheight, minlandheight + 20); int biomeSizeMin = 10, biomeSizeMax = 20; while (ptr < size / widthfactor) { int biomeSize = MathUtil.RandInt(rand, biomeSizeMin, biomeSizeMax); Biome b = (Biome)MathUtil.RandInt(rand, (int)Biome.Plains, (int)Biome.Ocean); h = GenBiome(ptr * widthfactor, h, biomeSize, b); for (int i = ptr; i < ptr + biomeSize; i++) { Terrain.TerrainBiomes[i] = b; } ptr += biomeSize; } }
//Generate Decorations based on Perlin noise public void Generate(float[,] heightMap, Vector3 position) { Tile tile = WorldBuilder.GetTile(position); bool placeTree = true; float scale = 0.17777f; for (int y = 0; y < 11; y = y + interval) { for (int x = 0; x < 11; x = x + interval) { double sampleX = (x + position.x) / scale; double sampleY = (y + position.z) / scale; float noiseHeight = (float)(perlin.GetValue(sampleY, 0, sampleX) + 1) / 2; Biome biome = terrainGenerator.GetBiomeByCoordinates(new Vector2(position.x + x, position.z + y)); if (biome.BiomeType is DefaultBiomeType || biome.BiomeType is ForestBiomeType || biome.BiomeType is PlainsBiomeType || biome.BiomeType is ShrublandBiomeType) { if (noiseHeight >= PlantThreshold && noiseHeight <= PlantThreshold + MarginThreshold) { Vector3 pos = new Vector3((position.x + x), heightMap[x, y], (position.z + y)); tile.AddDecoration(fractalTree.GeneratePlants(pos, biome.BiomeType)); } if (noiseHeight >= TreeThreshold && placeTree && noiseHeight <= TreeThreshold + MarginThreshold) { int jitterValue = Mathf.RoundToInt((float)(perlin.GetValue(sampleY + terrainGenerator.RandomNumbers[x], 0, sampleX + terrainGenerator.RandomNumbers[y])) * 5); // Prevent jitterValue to exceed index elemends if (jitterValue > 5 || jitterValue < -5) { jitterValue = 5; } Vector3 pos = new Vector3(position.x + 5 + jitterValue, heightMap[5 + jitterValue, 5 + jitterValue], position.z + 5 + jitterValue); // Check Biome again for Tree Placement Biome biome2 = terrainGenerator.GetBiomeByCoordinates(new Vector2(pos.x, pos.z)); if (biome2.BiomeType is DefaultBiomeType || biome2.BiomeType is ForestBiomeType || biome2.BiomeType is PlainsBiomeType || biome2.BiomeType is ShrublandBiomeType) { tile.AddDecoration(fractalTree.GenerateTree(pos, biome.BiomeType)); placeTree = false; } } } } } }
/// <summary> /// Computes the process efficiency numbers for given organelles /// given the active biome data. /// </summary> public static Dictionary <string, OrganelleEfficiency> ComputeOrganelleProcessEfficiencies( IEnumerable <OrganelleDefinition> organelles, Biome biome) { var result = new Dictionary <string, OrganelleEfficiency>(); foreach (var organelle in organelles) { var info = new OrganelleEfficiency(organelle); foreach (var process in organelle.RunnableProcesses) { info.Processes.Add(CalculateProcessMaximumSpeed(process, biome)); } result[organelle.InternalName] = info; } return(result); }
public void Save(ref WorldSerialization blob) { if (!HasValidTerrain()) { return; } blob.world.size = (uint)Terrain.terrainData.size.x; byte[] byteArray = ArrayUtils.FloatToByteArray(Terrain.terrainData.GetHeights(0, 0, Terrain.terrainData.heightmapWidth, Terrain.terrainData.heightmapHeight)); blob.AddMap("terrain", byteArray); blob.AddMap("height", byteArray); blob.AddMap("water", Water.GetBytes()); blob.AddMap("splat", Splat.GetBytes()); blob.AddMap("alpha", Alpha.GetBytes()); blob.AddMap("biome", Biome.GetBytes()); blob.AddMap("topology", Topology.GetBytes()); }
void SwitchBiome(Biome biome) { switch (biome) { case Biome.GRASS: light.intensity = 0.9f; light.color = Color.white; break; case Biome.DUNGEON: light.intensity = 0.4f; light.color = dungeonColor; break; default: Debug.LogWarning("No light data for biome: " + biome); break; } }
public static int GetHeight(int x, int z, Biome biome, int[,] heightGrid) { int count = 0; //count = GetRiverHeights(x, z, count,biome); foreach (Perlinlayer layer in biome.perlinLayers) { count += Mathf.FloorToInt(fn.GetSimplexFractal(x * layer.stretch, z * layer.stretch) * layer.layerMaxHeight + biome.baseHeight); } if (count > biome.maxHeight) { count = biome.maxHeight; } if (count < biome.minHeight) { count = biome.minHeight; } return(count); }
private Biome getBiome(float xChunkIndex, float yChunkIndex) { float biomeIndex = Mathf.PerlinNoise(xChunkIndex / 13f + seed * 3, yChunkIndex / 13f + seed * 3); biomeIndex *= 4; Biome BelowBiome = biomes[(int)biomeIndex]; Biome AboveBiome = biomes[(int)biomeIndex + 1]; biomeIndex %= 1; float newHeight = Mathf.Abs(BelowBiome.heightMultiplier - AboveBiome.heightMultiplier) * biomeIndex + Mathf.Min(BelowBiome.heightMultiplier, AboveBiome.heightMultiplier); float newValley = Mathf.Abs(BelowBiome.valleyMultiplier - AboveBiome.valleyMultiplier) * biomeIndex + Mathf.Min(BelowBiome.valleyMultiplier, AboveBiome.valleyMultiplier); Biome betweenBiome = new Biome(-1, "test", newHeight, newValley); return(betweenBiome); }
private Biome GetAverageBiome(int xIndex, int yIndex) { Biome leftBiome = getBiome(xIndex - 1, yIndex); Biome rightBiome = getBiome(xIndex + 1, yIndex); Biome topBiome = getBiome(xIndex, yIndex + 1); Biome bottomBiome = getBiome(xIndex, yIndex - 1); float averageHeight = leftBiome.heightMultiplier + rightBiome.heightMultiplier + topBiome.heightMultiplier + bottomBiome.heightMultiplier; averageHeight /= 4; float averageValley = leftBiome.valleyMultiplier + rightBiome.valleyMultiplier + topBiome.valleyMultiplier + bottomBiome.valleyMultiplier; averageValley /= 4; leftBiome = new Biome(-1, "combine", averageHeight, averageValley); return(leftBiome); }
public void AddBiomeRelPresence(Biome biome, float relPresence) { PresentBiomeIds.Add(biome.Id); BiomePresences.Add(relPresence); if (biome.TerrainType == BiomeTerrainType.Water) { PresentWaterBiomeIds.Add(biome.Id); WaterBiomePresence += relPresence; } _biomePresences[biome.Id] = relPresence; if (MostBiomePresence < relPresence) { MostBiomePresence = relPresence; BiomeWithMostPresence = biome.Id; } }
void DrawBiomeClouds(BoardNode[,] board, float[,] heightMap) { int width = board.GetLength(0); int height = board.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { BoardNode node = board[x, y]; Biome biome = BiomeGenerator.GetBiome(node); if (biome.moisture == MoistureBiome.Dry || biome.moisture == MoistureBiome.Moist) { continue; } Vector3 scale; if (biome.moisture == MoistureBiome.Wet) { scale = new Vector3(.75f, .25f, .75f); } else { scale = new Vector3(1f, .5f, 1f); } float nodeHeight = heightMap[x, y]; Vector3 position = new Vector3(x - width / 2 + .5f, nodeHeight / 2 + 5, y - width / 2 + .5f); GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); MeshRenderer meshRenderer = obj.GetComponent <MeshRenderer> (); meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.receiveShadows = false; obj.transform.localScale = scale; obj.transform.localPosition = position; obj.transform.parent = transform; obj.GetComponent <MeshRenderer> ().sharedMaterial = cloudMaterial; doodads.Add(obj); } } }
private Texture2D BuildBiomeTexture(TerrainType[,] heightTerrainTypes, TerrainType[,] heatTerrainTypes, TerrainType[,] moistureTerrainTypes) { int tileDepth = heatTerrainTypes.GetLength(0); int tileWidth = heatTerrainTypes.GetLength(1); Color[] colorMap = new Color[tileDepth * tileWidth]; for (int zIndex = 0; zIndex < tileDepth; zIndex++) { for (int xIndex = 0; xIndex < tileWidth; xIndex++) { int colorIndex = zIndex * tileWidth + xIndex; TerrainType heightTerrainType = heightTerrainTypes [zIndex, xIndex]; // check if the current coordinate is a water region if (heightTerrainType.name != "water") { // if a coordinate is not water, its biome will be defined by the heat and moisture values TerrainType heatTerrainType = heatTerrainTypes [zIndex, xIndex]; TerrainType moistureTerrainType = moistureTerrainTypes [zIndex, xIndex]; // terrain type index is used to access the biomes table Biome biome = this.biomes [moistureTerrainType.index].biomes [heatTerrainType.index]; // assign the color according to the selected biome colorMap [colorIndex] = biome.color; } else { // water regions don't have biomes, they always have the same color colorMap [colorIndex] = this.waterColor; } } } // create a new texture and set its pixel colors Texture2D tileTexture = new Texture2D(tileWidth, tileDepth); tileTexture.wrapMode = TextureWrapMode.Clamp; tileTexture.SetPixels(colorMap); tileTexture.Apply(); return(tileTexture); }
public void RegenerateMap(float seed, Biome biome) { float maxHeight = biome.maxHeight; for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { float noise = Mathf.PerlinNoise((seed + x) / biome.scale, (seed + y) / biome.scale); if (noise < 0) { noise = 0; } if (noise > 1) { noise = 1; } int height = (int)(noise * maxHeight); Tile tile = world.GetTileAt(x, y, height); //tile.height = noise*height; tile.height = 0; TileType tileType = biome.GetTileForHeight(noise); tile.SetTileType(tileType, false); for (int i = height - 1; i >= 0; i--) { Tile belowTile = world.GetTileAt(x, y, i); tileType = biome.biomes.GetTileTypeWithTag(tileType.BelowTileTag); belowTile.SetTileType(tileType, false); //belowTile.SetTileType(TileType.Empty, false); } for (int i = height + 1; i < maxHeight; i++) { world.GetTileAt(x, y, i).SetTileType(TileType.Empty, false); Tile belowTile = world.GetTileAt(x, y, i); //belowTile.SetTileType(biome.biomes.GetTileWithTag(tileType.BelowTileTag), false); } } } }
public RandomIsland(SceneNode node, Vector2 size, Biome islandBiome, API.Geo.World currentWorld) : base(node, size, currentWorld) { this.mBiome = islandBiome; ELEVATION.setFrequency(0.2); ELEVATION.setLacunarity(1); ELEVATION.setNoiseQuality(NoiseQuality.STANDARD); ELEVATION.setPersistence(0.7); ELEVATION.setOctaveCount(1); DETAIL.setFrequency(0.7); DETAIL.setLacunarity(1); DETAIL.setNoiseQuality(NoiseQuality.STANDARD); DETAIL.setPersistence(0.7); DETAIL.setOctaveCount(1); Multiply multiply = new Multiply(); multiply.SetSourceModule(0, ROUGHNESS); multiply.SetSourceModule(1, DETAIL); Add add = new Add(); add.SetSourceModule(0, multiply); add.SetSourceModule(1, ELEVATION); SCALE.SetSourceModule(0, add); SCALE.setxScale(0.03); SCALE.setyScale(0.06); SCALE.setzScale(0.03); TURBULENCE.SetSourceModule(0, SCALE); TURBULENCE.setFrequency(0.01); TURBULENCE.setPower(6); TURBULENCE.setRoughness(1); FINAL.SetSourceModule(0, SCALE); FINAL.setLowerBound(-1); FINAL.setUpperBound(1); this.generate(42); }
private static Mesh GenerateMesh(float[,] noiseMap, Biome biome) { TerrainData terrainData = new TerrainData(biome, noiseMap); terrainData.Generate(); Mesh mesh = new Mesh(); mesh.name = "Terrain"; mesh.vertices = terrainData.vertices.ToArray(); mesh.triangles = terrainData.triangles.ToArray(); mesh.colors = biome.GetColours(terrainData.vertices.ToArray()); mesh.RecalculateBounds(); mesh.RecalculateNormals(); return(mesh); }
// Generates the tile textures to be applied to the chunk texture void GenerateChunkTileTextures() { // NEEDS TO CHECK WHETHER THE STORAGE HAS ANYTHING STORED FOR THIS CHUNK float[,] chunkHeightMap = world.heightGenerator.GenerateHeightMap(world.chunkSize, world.chunkSize, chunkPos); float[,] chunkClimateMap = world.climateGenerator.GenerateClimateNoiseMap(world.chunkSize, world.chunkSize, chunkPos); float[,] chunkBiomeMap = world.biomeGenerator.GenerateBiomeNoiseMap(world.chunkSize, world.chunkSize, chunkPos); for (int chunkTileY = 0; chunkTileY < world.chunkSize; chunkTileY++) { for (int chunkTileX = 0; chunkTileX < world.chunkSize; chunkTileX++) { Biome biome = world.biomeGenerator.getBiome(chunkBiomeMap[chunkTileX, chunkTileY], chunkHeightMap[chunkTileX, chunkTileY], chunkClimateMap[chunkTileX, chunkTileY]); BiomeLayer biomeLayer = world.biomeGenerator.getBiomeLayer(biome, chunkHeightMap[chunkTileX, chunkTileY], chunkClimateMap[chunkTileX, chunkTileY]); chunkBiomeLayers[chunkTileX, chunkTileY] = biomeLayer; chunkTileTextures[chunkTileX, chunkTileY] = biomeLayer.groundTile.texture; } } }
public List <SpawnInfo> SpawnOnChunk(int detailType, int levelOfDetail, Biome biome, HeightMap heightMap, MeshData meshData, MeshSettings meshSettings, Vector2 chunkPosition, Vector2 chunkCoord) { if (_occupiedGrid == null) { _occupiedGrid = new bool[meshSettings.ChunkSize - 1, meshSettings.ChunkSize - 1]; } biome.Setup(chunkPosition, detailType); switch (detailType) { case (0): { return(SpawnFromSpawnables(detailType, levelOfDetail, biome, biome.HighLODSpawnable, heightMap, meshData, meshSettings, chunkPosition, chunkCoord, false)); } case (1): { return(SpawnFromSpawnables(detailType, levelOfDetail, biome, biome.MediumLODSpawnable, heightMap, meshData, meshSettings, chunkPosition, chunkCoord, false)); } case (2): { return(SpawnFromSpawnables(detailType, levelOfDetail, biome, biome.LowLODSpawnable, heightMap, meshData, meshSettings, chunkPosition, chunkCoord, true)); } default: throw new System.Exception("There should be no levelOfDetail of " + detailType); } }
void PlaceBiomes() { Biome biome = new Biome(); biome.biomeType = biomeTypes[0]; biome.area = new Rect(0, 0, width - 1, height - 1); biomes.Add(biome); biome = new Biome(); biome.biomeType = biomeTypes[1]; float w = UnityEngine.Random.Range(3, 5); float h = UnityEngine.Random.Range(3, 5); float x = UnityEngine.Random.Range(0, width - w - 1); float y = UnityEngine.Random.Range(0, height - h - 1); biome.area = new Rect(x, y, w, h); biomes.Add(biome); }
private Biome CalculateBiome(Vector2Int pos) { int x = pos.x; int y = pos.y; double shortestDistanceSq = double.MaxValue; Biome currentBiome = Biome.Grass; foreach (KeyValuePair <Vector2Int, Biome> entry in biomes) { int compX = entry.Key.x; int compY = entry.Key.y; double distanceSq = Mathf.Pow(x - compX, 2) + Mathf.Pow(y - compY, 2); if (distanceSq < shortestDistanceSq) { shortestDistanceSq = distanceSq; currentBiome = entry.Value; } } return(currentBiome); }
public override void SetPrivates(int id, int day, Biome biome, Character character, Instantiator instantiator) { base.SetPrivates(id, day, biome, character, instantiator); _cacheSpriteRenderer.sprite = Helper.GetSpriteFromSpriteSheet("Sprites/SwipeCardCache_" + biome.MapType.GetHashCode()); _innId = Random.Range(0, BiomesData.InnNames.Length); _innFee = Random.Range(5, 20 + 1) * character.Level; _alignmentInn = AlignmentInn.Classic; if (Random.Range(0, 100) < biome.MediocreInnPercentage) { _alignmentInn = AlignmentInn.Mediocre; } else if (Random.Range(0, 100) < biome.GoodInnPercentage) { _alignmentInn = AlignmentInn.Good; } _minutesNeededAvoid = 60; _minutesNeededVenturePositive = (character.SleepHoursNeeded * 60) + (int)(character.SleepHoursNeeded * 60 * Helper.MultiplierFromPercent(0.0f, BiomesData.InnSleepBonusPercent) * _alignmentInn.GetHashCode()); _hpRecovered = (int)(_character.HpMax * Helper.MultiplierFromPercent(0, _character.SleepRestorationPercent)); DisplayStats(); }
/// <summary> /// Specialy created to render quickly the landscape in order to be used by LandscapeItem Manager /// </summary> /// <param name="chunkBytes"></param> /// <param name="chunkPosition"></param> public void GenerateMacroLandscape(Vector3I chunkPosition, out Biome biome, out byte[] chunkBytes, out FastRandom chunkRnd, out ChunkColumnInfo[] columnsInfo) { Range3I chunkWorldRange = new Range3I() { Position = new Vector3I(chunkPosition.X * AbstractChunk.ChunkSize.X, 0, chunkPosition.Z * AbstractChunk.ChunkSize.Z), Size = AbstractChunk.ChunkSize }; chunkBytes = new byte[AbstractChunk.ChunkBlocksByteLength]; columnsInfo = new ChunkColumnInfo[AbstractChunk.ChunkSize.X * AbstractChunk.ChunkSize.Z]; chunkRnd = new FastRandom(_worldParameters.Seed + chunkPosition.GetHashCode()); double[,] biomeMap; GenerateLandscape(chunkBytes, ref chunkWorldRange, out biomeMap); TerraForming(chunkBytes, columnsInfo, ref chunkWorldRange, biomeMap, chunkRnd); var metaData = CreateChunkMetaData(columnsInfo); biome = _config.ProcessorParam.Biomes[metaData.ChunkMasterBiomeType]; }
private void HandleCloudSpawns(Biome biome) { GD.Print("Number of clouds in this patch = ", biome.Compounds.Count); foreach (var entry in biome.Compounds) { HandleSpawnHelper(chunkSpawners, entry.Key, entry.Value.Density, () => { var spawner = new CreatedSpawner(entry.Key); spawner.Spawner = Spawners.MakeCompoundSpawner( SimulationParameters.Instance.GetCompound(entry.Key), compoundCloudSystem, entry.Value.Amount); spawnSystem.AddSpawnType(spawner.Spawner, entry.Value.Density, Constants.CLOUD_SPAWN_RADIUS); return(spawner); }); } }
private static MeshData FacesMiddle(int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, int LODLevel, bool slopedTop, float steepness) { int hieghtOtherSpot = Chance.GetHeight(x, z + LODLevel, biome, heightGrid); hieghtOtherSpot = RoundToLodFrequency(hieghtOtherSpot, LODLevel); for (int i = hieghtOtherSpot - LODLevel; i < y - LODLevel; i += LODLevel) { if (i != y || !slopedTop) { meshData = NorthFace(x, i, z, meshData, biome, heightGrid, steepness, LODLevel); } } hieghtOtherSpot = Chance.GetHeight(x, z - LODLevel, biome, heightGrid); for (int i = hieghtOtherSpot - LODLevel; i < y - LODLevel; i += LODLevel) { if (i != y || !slopedTop) { meshData = SouthFace(x, i, z, meshData, biome, heightGrid, steepness, LODLevel); } } hieghtOtherSpot = Chance.GetHeight(x + LODLevel, z, biome, heightGrid); for (int i = hieghtOtherSpot - LODLevel; i < y - LODLevel; i += LODLevel) { if (i != y || !slopedTop) { meshData = EastFace(x, i, z, meshData, biome, heightGrid, steepness, LODLevel); } } hieghtOtherSpot = Chance.GetHeight(x - LODLevel, z, biome, heightGrid); for (int i = hieghtOtherSpot - LODLevel; i < y - LODLevel; i += LODLevel) { if (i != y || !slopedTop) { meshData = WestFace(x, i, z, meshData, biome, heightGrid, steepness, LODLevel); } } return(meshData); }
//Template enemy constructor public Enemy(JObject data, string ID) : base(Vector2.Zero, null) { JObject stats = (JObject)data["Stats"]; loadTextures((JObject)data["Animations"]); id = ID; health = (float)stats["Health"]; var speedList = stats["Speed"]; speeds = new[] { (float)speedList["Forest"], (float)speedList["Desert"], (float)speedList["Cold"], (float)speedList["Solid"] }; speedDeviation = (double)stats["SpeedDeviation"]; size = new Vector2((float)stats["Width"], (float)stats["Height"]); damage = (float)stats["Damage"]; hitForce = (float)stats["HitForce"]; spawnBiome = (Biome)Enum.Parse(typeof(Biome), (string)stats["Biome"]); state = (int)States.STANDING; dir = Dir.DOWN; barOffset = new Vector2((size.X - barSize.X) * 0.5f, size.Y + barDistance); }
public void Initialization() { TheListener = new Listener(); startStorage(); //initialize population object population = new Population(); population.center = this; witchLink = WitchHut.Instance; witchLink.linkToVillageCenter = this; //need to initialize population & houses currentHouses = Globals.startHouses; //need to fill biome array biomes = new Biome[Globals.numberOfBiomes]; for (int counter = 0; counter < biomes.Length; counter++) { //Debug.Log ("Biome Initialized: " + counter); biomes[counter] = new Biome(counter); biomes[counter].center = this; } wasConstructed = true; }
public void Generate() { int numBiomes = Random.Range(4 , 15 ); Biome[] biomes = new Biome[ numBiomes ]; GenerateBiomes( ref biomes , numBiomes ); ExpandBiomes( ref biomes , numBiomes ); RepeatBlendBiomes( 30 ); SmoothBiomes(); //RepeatBlendBiomes( 1 ); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); // BlendBiomes(); }
protected override string GetParameterTitle() { string output = null; if (string.IsNullOrEmpty(title)) { output = "Collect science"; if (state == ParameterState.Complete) { output += ": " + (experiment.Count > 1 ? "Various experiments" : ExperimentName(experiment[0])) + " from "; if (!string.IsNullOrEmpty(biome)) { output += new Biome(targetBody, biome).ToString(); } else { output += targetBody.theName; } if (situation != null) { output += " while " + situation.Value.Print().ToLower(); } else if (location != null) { output += location.Value == BodyLocation.Surface ? " while on the surface" : " while in space"; } } } else { output = title; } return output; }
protected void CreateDelegates() { // Filter for celestial bodies if (targetBody != null && string.IsNullOrEmpty(biome)) { AddParameter(new ParameterDelegate<Vessel>("Destination: " + targetBody.theName, subj => FlightGlobals.currentMainBody == targetBody, true)); } // Filter for biome if (!string.IsNullOrEmpty(biome)) { Biome b = new Biome(targetBody, biome); string title = b.IsKSC() ? "Location: " : "Biome: "; AddParameter(new ParameterDelegate<Vessel>(title + b, subj => CheckBiome(FlightGlobals.ActiveVessel))); } // Filter for situation if (situation != null) { AddParameter(new ParameterDelegate<Vessel>("Situation: " + situation.Value.Print(), subj => FlightGlobals.ActiveVessel != null && ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel) == situation)); } // Filter for location if (location != null) { AddParameter(new ParameterDelegate<Vessel>("Location: " + location, subj => FlightGlobals.ActiveVessel != null && ((location != BodyLocation.Surface) ^ FlightGlobals.ActiveVessel.LandedOrSplashed))); } // Add the experiments foreach (string exp in experiment) { string experimentStr = string.IsNullOrEmpty(exp) ? "Any" : ExperimentName(exp); ContractParameter experimentParam = AddParameter(new ParameterDelegate<Vessel>("Experiment: " + experimentStr, subj => recoveryDone.ContainsKey(exp))); // Add the subject ContractParameter subjectParam = new ParameterDelegate<Vessel>("", subj => true); subjectParam.ID = exp + "Subject"; experimentParam.AddParameter(subjectParam); // Filter for recovery if (recoveryMethod != ScienceRecoveryMethod.None) { ContractParameter recoveryParam = experimentParam.AddParameter(new ParameterDelegate<Vessel>("Recovery: " + RecoveryMethod(exp).Print(), subj => false)); } } }
} // Update void CreateWorld () { // Update action currentAction = LoadingActions.CreatingTerrain; UpdateLoadingScreen (); // Calculate width and assign world 2D array int width = worldWidth * chunkSize; worldBlocks = new Block[width, worldHeight * chunkSize]; // Set all blocks in world to air at start for (int y = 0; y < worldHeight * chunkSize; y++) { for (int x = 0; x < width; x++) { worldBlocks[x, y] = (Block)blocks[0].Clone(); worldBlocks[x, y].position = new Vector2(x, y); } } // Set biomes worldBiomes = new Biome[worldWidth]; int wantedLength = 0; Biome biomeType = new Biome(); for (int b = 0; b < worldBiomes.Length; b++) { // Set random biome length if (wantedLength == 0) { wantedLength = UnityEngine.Random.Range (3, 5); biomeType = biomes[UnityEngine.Random.Range(0, biomes.Length)]; } // Set data worldBiomes[b] = biomeType; wantedLength--; } // Create chunks { // Animation curves AnimationCurve worldGenGrass = new AnimationCurve(); AnimationCurve worldGenDirt = new AnimationCurve(); // Add keyframes in the animationcurve and generate height for (int i = 0; i < worldWidth * chunkSize; i += chunkSize) { // Create animationcurve for grass { // Get current biome Biome currentBiome = worldBiomes[i / chunkSize]; // Determine height int height = 0; if (UnityEngine.Random.Range(0, 1) == 0) height = currentBiome.averageHeight + UnityEngine.Random.Range(currentBiome.minHeightDiff, currentBiome.maxHeightDiff + 1); else height = -currentBiome.averageHeight + UnityEngine.Random.Range(currentBiome.minHeightDiff, currentBiome.maxHeightDiff + 1); // Insert the key worldGenGrass.AddKey(i, height); } // Create animationcurve for dirt layer thickness { // Insert the key worldGenDirt.AddKey(i, worldGenGrass.Evaluate(i) - UnityEngine.Random.Range(5, 8)); } } // Use keyframe data to insert blocks into world array for (int l = 0; l < chunkSize * worldWidth; l++) { // Grass worldBlocks [l, (int)worldGenGrass.Evaluate(l)] = (Block)blocks[1].Clone (); // Dirt for (int d = 0; d < (int)worldGenGrass.Evaluate (l); d++) { worldBlocks [l, d] = (Block)blocks [2].Clone(); worldBlocks [l, d].position = new Vector2(l, d); } // Stone for (int s = 0; s < (int)worldGenDirt.Evaluate (l); s++) { worldBlocks [l, s] = (Block)blocks [3].Clone(); } } // Insert some trees for (int i = 0; i < worldWidth; i++) { if (worldBiomes[i].forest) { int posX = UnityEngine.Random.Range(3, 4) + (i * chunkSize); int posY = (int)worldGenGrass.Evaluate(posX) + 1; InsertTree(posX, posY); } } // Insert caves int next = 5; for (int _x = 5; _x < worldWidth * chunkSize - 16; _x++) { if (_x == next) { // Calculate next cave location next += UnityEngine.Random.Range(caveChance - caveDifference, caveChance + caveDifference); // Create cave Block[,] temp = GenerateCave(); int height = UnityEngine.Random.Range(1, 64); // Check if cave does not touch dirt, if yes, cancel placement bool invalid = false; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { if (worldBlocks[x + _x, y + height].id != 0 && worldBlocks[x + _x, y + height].id != 3) invalid = true; } } // Insert cave if (!invalid) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { if (temp[x, y].id == 0) worldBlocks[x + _x, y + height] = temp[x, y]; } } } } } } // Loop to create chunks currentAction = LoadingActions.CreatingChunks; UpdateLoadingScreen (); for (int x = 0; x < worldWidth; x++) { for (int y = 0; y < worldHeight; y++) { CalculateChunkMeshData(x, y, false); } } } // CreateWorld
/* CONSTRUCTOR METHOD */ /// <summary> /// Initializes variables needed for terrain generation. /// </summary> /// <param name="gameEngine">An instance of the <see cref="Tesseract"/> game engine.</param> /// <param name="startingHeight">The height value at which to start the chunk.</param> public ProceduralMesh(Tesseract gameEngine, Biome biome) : base(gameEngine) { // Initialize the vertex array & height map with the proper number of elements VertexArray = new Vertex[NumHorizontal * NumVertical * 6]; QuadArray = new Vertex[NumVertical, NumHorizontal, 6]; // Initialize the random number generator Seed = RandomNumber.Next((int)1e9); RandomNumber = new Random(Seed); // Initialize the array of quads that will draw the map chunk Biome = biome; for (int a = 0; a < NumVertical; a++) { for (int b = 0; b < NumHorizontal; b++) { // Create a quad at the current map grid location Vertex[] currentQuad = Vertex.UnitQuadXZ(b, 0f, -a, Color.White); Vertex.Scale(ref currentQuad, (1f / TessellationFactor)); // Set each vertex's texture coordinates currentQuad[0].TexCoords = new Vector2(0f, 1f); currentQuad[1].TexCoords = new Vector2(0f, 0f); currentQuad[2].TexCoords = new Vector2(1f, 0f); currentQuad[3].TexCoords = new Vector2(0f, 1f); currentQuad[4].TexCoords = new Vector2(1f, 0f); currentQuad[5].TexCoords = new Vector2(1f, 1f); // Store each set of quads in the quad array for (int c = 0; c < currentQuad.Length; c++) { QuadArray[a, b, c] = currentQuad[c]; } } } // Broadcast that this chunk has been initialized IsInitialized = true; }
public void SetBaseValues() { baseBiome = localBiome; baseAlt = localAlt; baseClimate = localClimate; baseVeg = localVeg; baseTemp = localTemp; CorrectGeos(); }
//checks neighbors for a given biome public bool NeighborContainsBiome(Biome biome) { bool traitIsPresent = false; for(int i = 0; i < NeighborList.Count; i++){ if(NeighborList[i] != null){ Hex target = NeighborList[i].GetComponent<Hex>(); if(target.GetBiome() == biome){ traitIsPresent = true; } } } return traitIsPresent; }
private BiomeType SetBiomeType(Biome newBiome) { BiomeType value; if (newBiome == Biome.Arctic) { value = BiomeType.ARCTIC; } else if (newBiome == Biome.Chaparral) { value = BiomeType.ARID; } else if (newBiome == Biome.Desert) { value = BiomeType.ARID; } else if (newBiome == Biome.Estuary) { value = BiomeType.SALTWATER; } else if (newBiome == Biome.Forest) { value = BiomeType.WOODLAND; } else if (newBiome == Biome.Grassland) { value = BiomeType.PLAINS; } else if (newBiome == Biome.Lentic) { value = BiomeType.FRESHWATER; } else if (newBiome == Biome.Lotic) { value = BiomeType.FRESHWATER; } else if (newBiome == Biome.Ocean) { value = BiomeType.SALTWATER; } else if (newBiome == Biome.Rainforest) { value = BiomeType.WOODLAND; } else if (newBiome == Biome.Reef) { value = BiomeType.SALTWATER; } else if (newBiome == Biome.Savanna) { value = BiomeType.PLAINS; } else if (newBiome == Biome.Shelf) { value = BiomeType.SALTWATER; } else if (newBiome == Biome.Taiga) { value = BiomeType.WOODLAND; } else if (newBiome == Biome.Tundra) { value = BiomeType.ARCTIC; } else if (newBiome == Biome.Wetland) { value = BiomeType.FRESHWATER; } else { value = BiomeType.PLAINS; } UpdateHudBiome(); return value; }
/// <summary> /// Sets the value of the biome at the given column. /// </summary> public void SetBiome(byte x, byte z, Biome value) { Biomes[(byte)(z * Depth) + x] = (byte)value; IsModified = true; }
// Use this for initialization void Awake () { Map = new Map (); BiomeHelper.SetupColors (); SelectedBiomePaintIndexListStyle.normal.textColor = Color.white; SelectedBiomePaintIndexListStyle.onHover.background = new Texture2D (2, 2); SelectedBiomePaintIndexListStyle.hover.background = new Texture2D (2, 2); SelectedBiomePaintIndexListStyle.padding.left = 20; SelectedBiomePaintIndexListStyle.padding.right = 20; SelectedBiomePaintIndexListStyle.padding.top = 4; SelectedBiomePaintIndexListStyle.padding.bottom = 4; Config = GetComponent<CSVReader> (); Config.ParseFile (); foreach (KeyValuePair<int,float[]>pair in Config.ParsedData) { Biome tmpBiome = new Biome (pair.Value); BiomeDefinitions.Add (tmpBiome); } //Debug.Log ("Config has " + BiomeDefinitions.Count + " biome definitions"); foreach (Biome b in BiomeDefinitions) { //Debug.Log ("Heat Max:" + b.Heat_Max); } }
private void InitializeBiomes() { Debug.Log("Initializing Biomes " + Time.realtimeSinceStartup); biomes = new Biome[terrainConfig.Biome.biomeCount]; for (int i = 0; i < biomes.Length; i++) { biomes[i] = new Biome(); } }
//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 Initialize(int chunkIdx, Vector2[] createdPoly, int[] indices) { treesList = new List<GameObject>(); index = chunkIdx; polygon = createdPoly; triIndices = indices; centroid = createdPoly[0]; numTris = triIndices.Length / 3; // Decide on biome if(index == 0 || index == 1) { // The first and second chunks are always grasslands chunkBiome = Biome.Grassland; } else { // TODO: weight the biome selection to the index (lower index = lower biome type? then order biomes correspondingly) chunkBiome = (Biome)Random.Range(0, NUM_BIOME_TYPES); } MeshRenderer renderer = gameObject.GetComponent<MeshRenderer>(); if(renderer != null) { renderer.material = terrainMaterials[(int)chunkBiome]; } else { Debug.Log("ERROR! Chunk could not find mesh renderer!"); } PopulateTrees(); //PopulateCreatures(); }
public static void GenerateBiomeGraph(List<Biome> biomes_, int temperatureMaxValue_, int rainfallMaxValue_, out Biome[][] graph_) { graph_ = new Biome[temperatureMaxValue_][]; for (int temperatureLoopIndex = 0; temperatureLoopIndex < temperatureMaxValue_; ++temperatureLoopIndex) { graph_[temperatureLoopIndex] = new Biome[rainfallMaxValue_]; for (int rainfallLoopIndex = 0; rainfallLoopIndex < rainfallMaxValue_; ++rainfallLoopIndex) { foreach (Biome biome in biomes_) { float currentTemperatureValue = (float)temperatureLoopIndex / temperatureMaxValue_; float currentRainfallValue = (float)rainfallLoopIndex / rainfallMaxValue_; if (biome.Requirements.TemperatureIsWithinBounds(currentTemperatureValue) && biome.Requirements.RainfallIsWithinBounds(currentRainfallValue)) { if (graph_[temperatureLoopIndex][rainfallLoopIndex] == null) { graph_[temperatureLoopIndex][rainfallLoopIndex] = biome; } else { Debug.LogWarning("Biome.GenerateBiomeGraph biome " + biome.Type + " is being ignored as location x = " + temperatureLoopIndex + " y = " + rainfallLoopIndex + " is already occupied by " + graph_[temperatureLoopIndex][rainfallLoopIndex].Type); } } } } } }
public float[] GetHeights(int xstart, int zstart) { int size = chunkSize; height = size - 1; width = size - 1; heights = new float[size * size]; biomes = new Biome[heights.Length]; vertexArray = new Vertex[heights.Length]; indexArray = new int[width * height * 6]; for (int xx = 0; xx < size; xx++) { for (int yy = 0; yy < size; yy++) { float _x = yy + ((int)x * (size - 1)); float _y = xx + ((int)z * (size - 1)); float biomeHeight = 1f, temperature = 1f; int heightIndex = HeightIndexAt(yy, xx); float terrainHeight; if (this.generateBiomes) { biomeHeight = (float)(parent.getSimplexNoise(((double)_y*0.6), ((double)_x*0.6))); temperature = (float)(parent.getSimplexNoise(((double)_y), ((double)_x))); terrainHeight = (float)parent.getSimplexNoise(_x, _y); float mountainHeight = (float)parent.getNoise(_x*0.05f, _y*0.05f) * parent.GetWorleyNoise(_x*0.008f, _y*0.008f); Biome biome = new Biome(); biome.AverageTemperature = temperature; if (biomeHeight < 0.3f) { biome.Topography = Biome.BiomeTopography.Plains; } else { biome.Topography = Biome.BiomeTopography.Hills; } biomeHeight = (float)System.Math.Abs(biomeHeight) * 2; biomeHeight *= biomeHeight; biomes[heightIndex] = biome; heights[heightIndex] = MathUtil.Lerp(terrainHeight * 10, mountainHeight * 150f, MathUtil.Clamp(biomeHeight, 0.0f, 1.0f)); } else { terrainHeight = (float)parent.getNoise(_x, _y); heights[heightIndex] = terrainHeight * 25f; } } } return heights; }
// Methods public Chunk StartGenerate(int x, int y, System.Random rand, Directions direction, GameObject map, bool isPrisme = false) { // Load the chunk this.x = x; this.y = y; this.rand = rand; this.cs = map.GetComponent<Save>().LoadChunk(x, y); this.isPrisme = isPrisme; this.b = BiomeDatabase.RandBiome(this.rand); Spawn(new Vector3(x * Size, 0, y * Size), Quaternion.Euler(new Vector3(0, 90 * (int)direction, 0)), map.transform); // Set good biome this.posIslands = new List<Vector3>(); foreach (Transform child in Prefab.transform) if (child.name.Contains("Island")) { this.posIslands.Add(child.transform.position); if (child.GetComponent<MeshRenderer>().materials[0].name.Contains("Rock")) child.GetComponent<MeshRenderer>().materials = new Material[2] { b.Rock, b.Grass }; else child.GetComponent<MeshRenderer>().materials = new Material[2] { b.Grass, b.Rock }; } Prefab.GetComponent<SyncChunk>().BiomeId = b.ID; Prefab.GetComponent<SyncChunk>().IsCristal = isPrisme; this.ancres = new List<Transform>(); foreach (Transform content in Prefab.transform) if (content.CompareTag("Elements")) foreach (Transform ancre in content.transform) ancres.Add(ancre); return this; }
public void SetBiome(Biome biome) { if(biome < 0) {biome = Biome.Arctic;} else if(biome >= Biome.Desert) {biome = Biome.Desert;} localBiome = biome; }
public static bool Load(string filePath_) { TextAsset asset = (TextAsset)Resources.Load(filePath_); if (asset == null) { Debug.Log("file '" + filePath_ + "' could not be loaded"); return false; } JSONNode jsonData = JSON.Parse(asset.text); //for every biome in file for (int i = 0; i < jsonData.Count; ++i) { string name = jsonData[i]["Name"]; List<BiomeTile> tempTiles = new List<BiomeTile>(); for (int j = 0; j < jsonData[i]["ValidTiles"].Count; ++j) { Tile tile = Tile.GetTile(jsonData[i]["ValidTiles"][j]["Name"]); float chance = jsonData[i]["ValidTiles"][j]["Chance"].AsFloat; tempTiles.Add(new BiomeTile(tile, chance)); } List<BiomeResource> tempResources = new List<BiomeResource>(); for (int j = 0; j < jsonData[i]["ValidResources"].Count; ++j) { GameResource resource = GameResource.GetResource(jsonData[i]["ValidResources"][j]["Name"]); float chance = jsonData[i]["ValidResources"][j]["Chance"].AsFloat; tempResources.Add(new BiomeResource(resource, chance)); } float hMin = jsonData[i]["Requirements"]["Height"]["Min"].AsFloat; float hMax = jsonData[i]["Requirements"]["Height"]["Max"].AsFloat; float tMin = jsonData[i]["Requirements"]["Temperature"]["Min"].AsFloat; float tMax = jsonData[i]["Requirements"]["Temperature"]["Max"].AsFloat; float rMin = jsonData[i]["Requirements"]["Rainfall"]["Min"].AsFloat; float rMax = jsonData[i]["Requirements"]["Rainfall"]["Max"].AsFloat; BiomeRequirements newRequirements = new BiomeRequirements(hMin, hMax, tMin, tMax, rMin, rMax); Biome biome = new Biome(name, tempTiles, tempResources, newRequirements); Biomes.Add(biome); } Debug.Log(Biomes.Count + " Biomes loaded from '" + filePath_ + "'"); return true; }