public BiomeParam(EBiome type) { this._type = type; this.DecoDict = new Dictionary <EDeco, double>(); this.LandmarkDict = new Dictionary <ELandmark, double>(); this.TileDict = new Dictionary <ETile, double>(); }
static public ETile Biome2Tile(EBiome biome) { switch (biome) { case EBiome.Plain: return(ETile.Grass); case EBiome.Ocean: return(ETile.Water); case EBiome.Forest: return(ETile.Tree); case EBiome.Desert: return(ETile.Desert); case EBiome.Mountain: return(ETile.Mountain); default: return(ETile.Grass); } }
private void HandleLandmarks(XElement el, EBiome type) { foreach (var ele in el.Elements()) { foreach (var name in ele.Attributes()) { var landmark = ELandmark.None; if (EnumUtil <ELandmark> .TryGetEnumValue(name.Value, ref landmark)) { foreach (var elem in ele.Elements()) { if (elem.Name == "Chance") { double chance = 0; if (double.TryParse(elem.Value, out chance)) { this.table.Table[type].LandmarkDict.Add(landmark, chance); } } } } } } }
private void HandleDecos(XElement el, EBiome type) { foreach (var ele in el.Elements()) { foreach (var name in ele.Attributes()) { var deco = EDeco.None; if (EnumUtil <EDeco> .TryGetEnumValue(name.Value, ref deco)) { foreach (var elem in ele.Elements()) { if (elem.Name == "Chance") { double chance = 0; if (double.TryParse(elem.Value, out chance)) { this.table.Table[type].DecoDict.Add(deco, chance); } } } } } } }
private void HandleTiles(XElement el, EBiome type) { foreach (var ele in el.Elements()) { foreach (var name in ele.Attributes()) { var tileType = ETile.None; if (EnumUtil <ETile> .TryGetEnumValue(name.Value, ref tileType)) { foreach (var elem in ele.Elements()) { if (elem.Name == "Chance") { double chance = 0; if (double.TryParse(elem.Value, out chance)) { this.table.Table[type].TileDict.Add(tileType, chance); } } } } } } }
public void UpdateMappings(Vector2 playerPos) { mBiome = mBiomeMap.GetBiom(playerPos, mWorldSize); mHeight = mHeightMap.GetHeight(playerPos, mWorldSize); mAiSpawnID = mAiSpawnMap.GetAiSpawnMapId(playerPos, mWorldSize); }
public GenerationTemplate GetTemplateFromBiome(EBiome biome) { return(m_biomeToGeneration[biome]); }
private void SpawnChunkAt(Vector2 chunkPos) { Vector3 spawnPos = m_worldAnchorRoot.transform.position; spawnPos.x += chunkPos.x * 64; spawnPos.y += chunkPos.y * 64; Quaternion spawnRot = m_worldAnchorRoot.transform.rotation; Stopwatch sw = Stopwatch.StartNew(); int x = (int)chunkPos.x; int y = (int)chunkPos.y; GameObject chunkObj = (GameObject)Instantiate(m_worldMapChunkPrefab, spawnPos, spawnRot); chunkObj.GetComponent <Renderer>().material.mainTexture = m_tileTextureMap; chunkObj.name = string.Format("Chunk({0},{1})", x, y); sw.Stop(); UnityEngine.Debug.Log(string.Format("Mesh Instanciation in {0}ms", sw.ElapsedMilliseconds)); ChunkInfo chunkInfo = new ChunkInfo(chunkPos, chunkObj); // update all mapping m_chunks.AddLast(chunkInfo); m_posToChunks[new Vector2(chunkPos.x, chunkPos.y)] = chunkInfo; chunkInfo.PostInitialize(); TileMap anotherTileMap = chunkObj.GetComponent <TileMap>(); anotherTileMap.SourceChunk = chunkInfo; #if SIMPLE_BIOME for (int j = 0; j < ChunkInfo.Height; j++) { for (int i = 0; i < ChunkInfo.Width; i++) { Vector2 worldPos = Chunk2World(chunkInfo, i, j); int biomeX = (int)worldPos.x + m_biomeManager.Width / 2; int biomeY = (int)worldPos.y + m_biomeManager.Height / 2; Debug.Assert(biomeX >= 0 && biomeX < m_biomeManager.Width); Debug.Assert(biomeY >= 0 && biomeY < m_biomeManager.Height); EBiome biome = m_biomeManager.Map[biomeX, biomeY]; ETile tile = BiomeManager.Biome2Tile(biome); chunkInfo.WriteSlotValue(i, j, tile); } } // Special case for starting spot if (x == 0 && y == 0) { chunkInfo.GenerateSquare(ETile.Grass, 8, 8); } #else // Chunk goes from -Inf to + Inf // But biomeMap goes from 0 to Width / 2 // So, this won't work for boundary, but temporary remap by adding half-size // TODO: fix me int biomeX = x + m_biomeManager.Width / 2; int biomeY = y + m_biomeManager.Height / 2; EBiome biome = m_biomeManager.Map[biomeX, biomeY]; GenerationTemplate template = m_biomeManager.GetTemplateFromBiome(biome); chunkInfo.Generate(template); #endif }