/// <summary> /// 柏林噪声产生地形数据, /// </summary> private void GenerateTerrain() { var perlin = new CPerlinMap(m_numCols, m_numRows); perlin.Generate(); //处理高地 //存储高地的数据 //1代表是高地, 0代表高地被平了 int[,] hillGrid = new int[m_numCols, m_numRows]; var type = (int)CPCGLayer.Terrain; for (int x = 0; x < m_numCols; x++) { for (int z = 0; z < m_numRows; z++) { CForestTerrainSubType subType = GetSubTypeAtHeight(perlin[x, z]); m_grid.FillData(x, z, type, (int)subType, CForestUtil.GetTerrainTypeWalkable(subType)); hillGrid[x, z] = 0; if (subType == CForestTerrainSubType.Hill) { hillGrid[x, z] = 1; } } } m_cell.SmoothOnce(hillGrid); var hillType = (int)CForestTerrainSubType.Hill; var landType = (int)CForestTerrainSubType.Land1; m_floodFill.Process(hillGrid, 11, 1, 0); //将处理过后的数据返还给assets for (int x = 0; x < m_numCols; x++) { for (int z = 0; z < m_numRows; z++) { var subType = m_grid.GetNodeSubType(x, z); if (subType == hillType && hillGrid[x, z] == 0) { m_grid.FillData(x, z, type, landType, true); } } } }
private void GeneratePond() { if (MaxPondNum <= 0) { return; } int num = CDarkRandom.Next(MaxPondNum + 1); if (num <= 0) { return; } //池塘的相关配置 var type = (int)CPCGLayer.Terrain; var subType = CForestTerrainSubType.Pond; var walkable = CForestUtil.GetTerrainTypeWalkable(subType); CPondGenerator p = new CPondGenerator(); int pondCols = CDarkRandom.Next(16, 32); int pondRows = CDarkRandom.Next(16, 32); int leftCols = m_numCols - pondCols; int leftRows = m_numRows - pondRows; Vector2Int size = new Vector2Int(pondCols, pondRows); for (int i = 0; i < num; i++) { int startX = CDarkRandom.Next(0, leftCols); int startZ = CDarkRandom.Next(0, leftRows); var ponds = p.Generate(size); //活着的是池塘 for (int x = 0; x < pondCols; x++) { for (int z = 0; z < pondRows; z++) { if (ponds[x, z] < 1) { continue; } m_grid.FillData(startX + x, startZ + z, type, (int)subType, walkable); } } } }