示例#1
0
        void Randomize(TerrainTile[,] buff)
        {
            int w = buff.GetLength(0);
            int h = buff.GetLength(1);

            TerrainTile[,] tmp = (TerrainTile[, ])buff.Clone();
            for (int y = 10; y < h - 10; y++)
            {
                for (int x = 10; x < w - 10; x++)
                {
                    var tile = buff[x, y];

                    if (tile.TileId == TileTypes.Water && tile.Elevation >= elevationThreshold[3])
                    {
                        tile.TileId = TileTypes.SnowRock;
                    }
                    else if (tile.TileId != TileTypes.Water && tile.TileId != TileTypes.Road)
                    {
                        var id = buff[x + rand.Next(-2, 3), y + rand.Next(-2, 3)].TileId;
                        while (id == TileTypes.Water || id == TileTypes.Road)
                        {
                            id = buff[x + rand.Next(-2, 3), y + rand.Next(-2, 3)].TileId;
                        }
                        tile.TileId = id;
                    }

                    if (tile.TileId == TileTypes.Beach)
                    {
                        tile.Region = TileRegion.Spawn;
                    }

                    string biome = tile.Biome;
                    if (tile.TileId == TileTypes.Beach)
                    {
                        biome = "beach";
                    }
                    else if (tile.TileId == TileTypes.MovingWater)
                    {
                        biome = "coast";
                    }

                    var biomeObj = Decoration.GetDecor(biome, rand);
                    if (biomeObj != null)
                    {
                        tile.TileObj = biomeObj;
                        var size = Decoration.GetSize(biomeObj, rand);
                        if (size != null)
                        {
                            tile.Name = "size:" + size;
                        }
                    }

                    buff[x, y] = tile;
                }
            }
        }
示例#2
0
        private void Randomize(TerrainTile[,] buff)
        {
            int w = buff.GetLength(0);
            int h = buff.GetLength(1);

            TerrainTile[,] tmp = (TerrainTile[, ])buff.Clone();
            for (int y = 10; y < h - 10; y++)
            {
                for (int x = 10; x < w - 10; x++)
                {
                    TerrainTile tile = buff[x, y];

                    if (tile.TileId == TileTypes.Water && tile.Elevation >= elevationThreshold[3])
                    {
                        tile.TileId = TileTypes.SnowRock;
                    }
                    else if (tile.TileId != TileTypes.Water && tile.TileId != TileTypes.Road &&
                             tile.TileId != TileTypes.Beach && tile.TileId != TileTypes.MovingWater &&
                             tile.TileId != TileTypes.DeepWater)
                    {
                        ushort id = tmp[x + rand.Next(-3, 4), y + rand.Next(-3, 4)].TileId;
                        while (id == TileTypes.Water || id == TileTypes.Road ||
                               id == TileTypes.Beach || id == TileTypes.MovingWater ||
                               id == TileTypes.DeepWater)
                        {
                            id = tmp[x + rand.Next(-3, 4), y + rand.Next(-3, 4)].TileId;
                        }
                        tile.TileId = id;
                    }

                    //if (tile.TileId == TileTypes.Beach)
                    //    tile.Region = TileRegion.Spawn;

                    string biome = tile.Biome;
                    if (tile.TileId == TileTypes.Beach)
                    {
                        biome = "beach";
                    }
                    else if (tile.TileId == TileTypes.MovingWater)
                    {
                        biome = "coast";
                    }

                    string biomeObj = Decoration.GetDecor(biome, rand);
                    if (biomeObj != null)
                    {
                        tile.TileObj = biomeObj;
                        int?size = Decoration.GetSize(biomeObj, rand);
                        if (size != null)
                        {
                            tile.Name = "size:" + size;
                        }
                    }

                    float elevation = 0;
                    int   c         = 0;
                    for (int dy = -1; dy <= 1; dy++)
                    {
                        for (int dx = -1; dx <= 1; dx++)
                        {
                            if (x + dx < 0 || x + dx >= w || y + dy < 0 || y + dy >= h)
                            {
                                continue;
                            }
                            elevation += tmp[x + dx, y + dy].Elevation;
                            c++;
                        }
                    }
                    tile.Elevation = elevation / c;

                    buff[x, y] = tile;
                }
            }
        }