Пример #1
0
    private void _placeTerrainObjects(Area area, System.Random rng)
    {
        TerrainData data = area.Owner;
        Block start = area.GetPoint(0);

        HashSet<Block> visited = new HashSet<Block>();
        Queue<Block> frontier = new Queue<Block>();

        frontier.Enqueue(start);

        int iterationsSince = 0;

        Block next;
        while (frontier.Count > 0)
        {
            next = frontier.Dequeue();

            if (iterationsSince <= 0)
            {
                if (rng.NextDouble() < m_chanceToSpawnObject)
                {
                    iterationsSince = m_minDistanceBetweenObjects;
                    next.Value = m_objectIds[rng.Next(m_objectIds.Length)] + 1;
                }
            }

            iterationsSince--;

            for (int x = next.Location.X - 1; x <= next.Location.X + 1; x++)
            {
                for (int y = next.Location.Y - 1; y <= next.Location.Y + 1; y++)
                {
                    Block block = data.GetBlock(new Point(x, y));
                    if (block != null && block.Value != 0 && !visited.Contains(block))
                    {
                        visited.Add(block);
                        frontier.Enqueue(block);
                    }
                }
            }
        }
    }