Exemplo n.º 1
0
        //public bool IsPositionValid(int i, int j)
        //{
        //    // If this is already a cliff, the tile has been checked before
        //    // and we can skip the expensive check of the neighbors.
        //    if ((info.Tiles[i, j] & TileInfo.Cliff) == TileInfo.Cliff)
        //        return true;

        //    if ((info.Tiles[i, j] & invalidTiles) != TileInfo.Free)
        //        return false;

        //    // Check if there are any invalid neighbors.
        //    return tileGraph.HasInvalidNeighbors(i, j, invalidTileRadius);
        //    //var invalidNeighbors = tileGraph.GetNeighbors(i, j, invalidTileRadius, false, true);

        //    //foreach (var neighbor in invalidNeighbors)
        //    //{
        //    //    int distance = System.Math.Max(System.Math.Abs(neighbor.X - i), System.Math.Abs(neighbor.Y - j));
        //    //    if (distance <= 1)
        //    //        return false;
        //    //}

        //    //if (invalidNeighbors.Any())
        //    //{
        //    //    minHeight = invalidNeighbors.Max(c => System.Math.Max(System.Math.Abs(c.X - i), System.Math.Max(c.Y - j)));
        //    //    return false;
        //    //}
        //    //else
        //    //    return true;
        //}

        private void DropParticles(int x, int y)
        {
            map.HeightMap.WrapCoordinates(ref x, ref y);
            //if (!IsPositionValid(x, y))
            //    return;

            byte height = map.HeightMap[x, y];

            int index;

            foreach (Coordinates neighbor in tileGraph.GetNeighbors(x, y, 1))
            {
                //if (!IsPositionValid(neighbor.X, neighbor.Y))
                //    continue;

                index = map.HeightMap.Index(neighbor.X, neighbor.Y);

                if (map.HeightMap[index] < height)
                {
                    DropParticle(index);
                    return;
                }
            }

            index = map.HeightMap.Index(x, y);
            DropParticle(index);
        }
Exemplo n.º 2
0
        public void Process(Map map, MapInfo info)
        {
            this.map       = map;
            this.info      = info;
            this.tileGraph = new TileGraph(info.Tiles, invalidTiles);
            this.random    = new Random(info.MapId);

            this.heightConstraints = new Grid <byte>(map.HeightMap.Width, map.HeightMap.Height);
            for (int i = 0; i < map.Tiles.Width; i++)
            {
                for (int j = 0; j < map.Tiles.Height; j++)
                {
                    heightConstraints[i, j] = 255;

                    var invalidNeighbors = tileGraph.GetNeighbors(i, j, invalidTileRadius, false, true);
                    foreach (var neighbor in invalidNeighbors)
                    {
                        if (map.HeightMap.CheckCoordinates(neighbor.X, neighbor.Y))
                        {
                            int distance = System.Math.Max(System.Math.Abs(neighbor.X - i), System.Math.Abs(neighbor.Y - j));
                            heightConstraints[i, j] = (byte)System.Math.Min(heightConstraints[i, j], map.HeightMap[neighbor.X, neighbor.Y] + (distance - 1) * MaxHeightDifferencePerTile);
                        }
                    }
                }
            }

            int min, max;

            switch (info.Settings.NumberOfCliffs)
            {
            case Frequency.Low:
                min = 0;
                max = (int)(map.Tiles.Count / lowDivisor);
                break;

            case Frequency.High:
                min = (int)(map.Tiles.Count / mediumDivisor);
                max = (int)(map.Tiles.Count / highDivisor);
                break;

            default:
                min = (int)(map.Tiles.Count / lowDivisor);
                max = (int)(map.Tiles.Count / mediumDivisor);
                break;
            }

            int count = random.Next(min, max);

            for (int i = 0; i < count && !info.IsCancellationRequested; i++)
            {
                AddCliff();
            }
        }
Exemplo n.º 3
0
        public void Process(Map map, MapInfo info)
        {
            var graph     = new TileGraph(info.Tiles, TileInfo.Free);
            var generator = new RampGenerator(info.MapId);

            foreach (var area in info.FlattenedAreas)
            {
                if (info.IsCancellationRequested)
                {
                    return;
                }

                var coordinates = map.PositionToCoordinates(area.Center);
                var height      = (byte)graph.GetNeighbors(coordinates, (int)(area.Radius / Map.TileWidth) + 3, true, true).Average(c => map.HeightMap[c.X, c.Y]);
                generator.GenerateFlatArea(map, coordinates, height, (int)(area.Radius / Map.TileWidth), area.Radius);
            }
        }