/// <summary> /// 寻找一个可同行的地块. /// </summary> /// <returns>The walkable tile.</returns> public Vector3 FindWalkableTile() { int times = 10; while (times > 0) { int col = CDarkRandom.Next(m_mapWalkableData.NumCols); int row = CDarkRandom.Next(m_mapWalkableData.NumRows); if (IsWalkable(col, row)) { return(new Vector3(col, 0, row)); } times--; } for (int c = 0; c < m_mapWalkableData.NumCols; c++) { for (int r = 0; r < m_mapWalkableData.NumRows; r++) { if (IsWalkable(c, r)) { return(new Vector3(c, 0, r)); } } } return(Vector3.zero); }
/*地图中随机一个位置*/ public static Vector2Int FindRandomNodeLocation(int maxCol, int maxRow) { int row = CDarkRandom.Next(0, maxRow); int col = CDarkRandom.Next(0, maxCol); return(new Vector2Int(col, row)); }
//随机填充地图 private void RandomFillMap() { for (int x = 0; x < m_numCols; x++) { for (int y = 0; y < m_numRows; y++) { bool b = CDarkRandom.SmallerThan(Threshold); m_values[x, y] = b ? 1 : 0; } } if (m_needAliveEdage) { //如果是整地图, 则我们需要在四周筑上围墙 //随机填充满所有的地图 int maxIndex_Y = m_numRows - 1; int maxIndex_X = m_numCols - 1; for (int x = 0; x < m_numCols; x++) { m_values[x, 0] = 1; m_values[x, maxIndex_Y] = 1; } for (int y = 0; y < m_numRows; y++) { m_values[0, y] = 1; m_values[maxIndex_X, y] = 1; } } }
/// <summary> /// walk = true mean alive /// </summary> private int GetTypeByAlive(bool alive) { if (alive) { return(0); } if (CDarkRandom.SmallerThan(0.5f)) { return(1); } return(2); }
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); } } } }
/// <summary> /// 返回二维数组[y,x], 0代表死亡 /// </summary> public int[,] Generate(int cols, int rows) { m_numCols = cols; m_numRows = rows; m_values = new int[m_numCols, m_numRows]; if (RandomSeed) { Seed = Random.Range(-10000, 1000); } CDarkRandom.SetSeed(Seed); RandomFillMap(); for (int i = 0; i < m_iterations; ++i) { MoreIsBetterThanLess(); } return(m_values); }
//路标, 大块石头, 路灯等 public void CreateDecoration(int decoBlockNum, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid) { string name; //添加阻碍装饰物 for (int i = 0; i < decoBlockNum; ++i) { int col = CDarkRandom.Next(_numCols); int row = CDarkRandom.Next(_numRows); if (!walkGrid.IsWalkable(col, row)) { continue; } walkGrid.SetWalkable(col, row, false); int nameIndex = CDarkRandom.Next(1, 6); name = string.Format("Preb_Deco_Block_00{0}", nameIndex); //assetGrid.SetName(row, col, name); } }
public void CreateDecal(string decalNameRoot, int decalStartIndex, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid) { string name; //添加贴花 for (int i = 0; i < 30; ++i) { int col = CDarkRandom.Next(_numCols); int row = CDarkRandom.Next(_numRows); //if(typeGrid.IsSpecial(row, col))continue; if (!walkGrid.IsWalkable(row, col)) { continue; } //typeGrid.SetType(row, col, (int)RayConst.TileType.DECAL); int nameIndex = CDarkRandom.Next(decalStartIndex, decalStartIndex + 5); name = string.Format("{0}{1}", decalNameRoot, nameIndex); //assetGrid.SetName(row, col, name); } }
/// <summary> /// 根据高度, 从配置中读取相关的asset /// </summary> private CForestTerrainSubType GetSubTypeAtHeight(float height) { //两种草 if (height <= GrassHeight) { if (CDarkRandom.SmallerThan(0.5f)) { return(CForestTerrainSubType.Grass1); } return(CForestTerrainSubType.Grass1); } //另外一种草 if (height <= GrassHeight2) { return(CForestTerrainSubType.Grass2); } //两种地面 if (height <= LandHeight) { return(CForestTerrainSubType.Land1); } if (height <= LandHeight2) { return(CForestTerrainSubType.Land2); } //墙壁 if (height <= WallHeight) { return(CForestTerrainSubType.Hill); } //默认的绿草地 return(CForestTerrainSubType.Grass1); }
//创建可以销毁的障碍物. 比如说坦克大战和炸弹人的地块 public void CreateDestroyBlock(int decoDestroyNum, CAssetGrid walkGrid, CAssetGrid typeGrid, CAssetGrid assetGrid) { string name; //添加阻碍装饰物 for (int i = 0; i < decoDestroyNum; ++i) { int col = CDarkRandom.Next(_numCols); int row = CDarkRandom.Next(_numRows); //if(typeGrid.IsSpecial(row, col))continue; if (!walkGrid.IsWalkable(row, col)) { continue; } //typeGrid.SetType(row, col, (int)RayConst.TileType.DECO_DESTROY); walkGrid.SetWalkable(row, col, false); //5个里面随机一个 int nameIndex = CDarkRandom.Next(1, 6); name = string.Format("Preb_Deco_Destroy_00{0}", nameIndex); //assetGrid.SetName(row, col, name); } }
/// <summary> /// 根据高度, 从配置中读取相关的asset /// </summary> private int GetTypeAtHeight(float height) { //两种海洋 if (height < SeaLevel) { if (CDarkRandom.SmallerThan(0.5f)) { return(0); } return(1); } //两种海岸线 if (height <= BeachHeight) { if (CDarkRandom.SmallerThan(0.5f)) { return(2); } return(3); } //两种草 if (height <= GrassHeight) { if (CDarkRandom.SmallerThan(0.5f)) { return(4); } return(5); } //另外一种草 if (height <= GrassHeight2) { return(6); } //两种地面 if (height <= LandHeight) { return(7); } if (height <= LandHeight2) { return(8); } //两种石头 if (height <= StoneHeight) { if (CDarkRandom.SmallerThan(0.5f)) { return(9); } return(10); } //默认的绿草地 return(4); }