/// <summary>
        /// 删除不合理的树的位置
        /// 比如此地块不可通行, 那么就不能种树
        /// </summary>
        public void DeleteBlockAtIllegalPostion(CAssetGrid terrainGrid)
        {
            var noneType = (int)CForestBlockSubType.None;
            var type     = (int)CPCGLayer.Block;

            for (int col = 0; col < m_numCols; col++)
            {
                for (int row = 0; row < m_numRows; row++)
                {
                    var node = m_grid.GetNode(col, row);
                    if (node.SubType == noneType)
                    {
                        continue;
                    }

                    var terrType = (CForestTerrainSubType)terrainGrid.GetNodeSubType(col, row);
                    if (CForestUtil.CanPlacePropsOnTerrainType(terrType))
                    {
                        continue;
                    }
                    m_grid.FillData(col, row, type, noneType, true);
                }
            }

            BreatheTree();
        }
示例#2
0
        /// <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);
                    }
                }
            }
        }
示例#3
0
        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);
                    }
                }
            }
        }