Ejemplo n.º 1
0
        public override void Generate()
        {
            markDirty();
            drawDirty();

            MapPrinter.PrintGeneratorMap(Bounds, noise, UsedCells, info.ID);
        }
Ejemplo n.º 2
0
        public void Generate(bool[,] dirt)
        {
            UsedCells = dirt;
            drawDirty();

            MapPrinter.PrintGeneratorMap(Bounds, noise, UsedCells, info.ID);
        }
        public override void Generate()
        {
            if (!info.SpawnOnObjectives.Contains(ObjectiveType.NONE) && !info.SpawnOnObjectives.Contains(Loader.ObjectiveType))
            {
                return;
            }

            var pieceIndex = info.Pieces[Random.Next(info.Pieces.Length)];
            var piece      = PieceManager.GetPiece(pieceIndex);

            var noise = Loader.GetNoise(info.NoiseMapID);

            switch (info.PositionType)
            {
            case PositionType.POSITION:
                Loader.GenerateCrucialPiece(piece, info.Position, info.ID);
                markDirty(info.Position, piece);
                break;

            case PositionType.SPAWN:
                generateSpawn(piece);
                break;

            case PositionType.KEY:
                generateKey(piece, noise);
                break;

            case PositionType.EXIT:
                generateExit(piece, noise);
                break;
            }

            MapPrinter.PrintGeneratorMap(Bounds, noise, UsedCells, info.ID);
        }
Ejemplo n.º 4
0
        public override void Generate()
        {
            var count = Random.Next(info.MinCount, info.MaxCount);

            // To have maximum diversity, we should get each path two nodes plus two extra.
            var nodesToGenerate = (count * 2 + 2) - Loader.Waypoints.Count;

            for (int i = 0; i < nodesToGenerate; i++)
            {
                Loader.Waypoints.Add(MapUtils.RandomPositionFromEdge(Random, 1, Bounds));
            }

            var waypointEnds     = Loader.Waypoints.Where(w => w.Type == WaypointType.END).ToList();
            var waypointPassages = Loader.Waypoints.Where(w => w.Type == WaypointType.PASSAGE).ToList();

            for (int i = 0; i < count; i++)
            {
                var previousIndex = Random.Next(waypointEnds.Count);
                var previous      = waypointEnds[previousIndex];
                waypointEnds.RemoveAt(previousIndex);

                var passageCount = Math.Clamp(Random.Next(3), 0, waypointPassages.Count);

                for (int j = 0; j < passageCount; j++)
                {
                    var current = waypointPassages[Random.Next(waypointPassages.Count)];

                    generateSingle(previous.Position, current.Position);

                    previous = current;
                }

                var nextIndex = Random.Next(waypointEnds.Count);
                var next      = waypointEnds[nextIndex];
                waypointEnds.RemoveAt(nextIndex);

                generateSingle(previous.Position, next.Position);
            }

            markDirty();
            drawDirty();

            MapPrinter.PrintGeneratorMap(Bounds, noise, UsedCells, info.ID);
        }
Ejemplo n.º 5
0
        public override void Generate()
        {
            var spawn = info.FillMap ? MPos.Zero : Center - new MPos(info.MinimumDimensions, info.MinimumDimensions);

            if (spawn.X < 0)
            {
                spawn = new MPos(0, spawn.Y);
            }

            if (spawn.Y < 0)
            {
                spawn = new MPos(spawn.X, 0);
            }

            var bounds = info.FillMap ? Bounds : new MPos(Random.Next(info.MaximumDimensions - info.MinimumDimensions) + info.MinimumDimensions, Random.Next(info.MaximumDimensions - info.MinimumDimensions) + info.MinimumDimensions);

            if (spawn.X + bounds.X >= Bounds.X)
            {
                bounds = new MPos(Bounds.X - spawn.X, bounds.Y);
            }

            if (spawn.Y + bounds.Y >= Bounds.Y)
            {
                bounds = new MPos(bounds.X, Bounds.Y - spawn.Y);
            }

            // If smaller than map bounds, abort
            if (bounds.X < info.MinimumDimensions || bounds.Y < info.MinimumDimensions)
            {
                return;
            }

            var baseCell = new Cell(16, spawn, bounds, info);

            cells = cellLoop(baseCell, 16);

            for (int x = spawn.X; x < spawn.X + bounds.X; x++)
            {
                for (int y = spawn.Y; y < spawn.Y + bounds.Y; y++)
                {
                    road[x, y] = true;
                }
            }

            pieceCells = new List <PieceCell>();
            foreach (var cell in cells)
            {
                var piece = new PieceCell(cell.Position, cell.Size, info);
                pieceCells.AddRange(pieceLoop(piece));
            }

            foreach (var cell in cells)
            {
                if (!Loader.CanAcquireArea(cell.Position, cell.Size, info.ID))
                {
                    continue;
                }

                for (int x = cell.Position.X; x < cell.Position.X + cell.Size.X; x++)
                {
                    for (int y = cell.Position.Y; y < cell.Position.Y + cell.Size.Y; y++)
                    {
                        if (Loader.AcquireCell(new MPos(x, y), info.ID))
                        {
                            UsedCells[x, y] = true;
                        }

                        road[x, y] = false;
                    }
                }
            }

            // Roads
            var type = Loader.Infos.FirstOrDefault(i => i.ID == info.PathGeneratorID && i is PathGeneratorInfo);

            if (type != null)
            {
                for (int x = 0; x < Bounds.X; x++)
                {
                    for (int y = 0; y < Bounds.Y; y++)
                    {
                        if (!(road[x, y] && Loader.AcquireCell(new MPos(x, y), info.PathGeneratorID)))
                        {
                            road[x, y] = false;
                        }
                    }
                }
                var generator = new PathGenerator(Random, Loader, type as PathGeneratorInfo);
                generator.Generate(road);
            }
            // Pieces
            foreach (var piece in pieceCells)
            {
                var size = piece.Size / new MPos(info.CellSize, info.CellSize);

                var fitting = info.Pieces.FirstOrDefault(p => p.Size == size);

                if (fitting == null)
                {
                    continue;
                }

                Loader.GeneratePiece(getPiece(fitting.Pieces), piece.Position, info.ID, idInclusive: true);
            }

            MapPrinter.PrintGeneratorMap(Bounds, NoiseMap.Empty, UsedCells, info.ID);
        }
Ejemplo n.º 6
0
        public override void Generate()
        {
            var noise = Loader.GetNoise(info.NoiseMapID);

            searchBlocks = info.MaxBounds;
            if (searchBlocks == MPos.Zero)
            {
                var blockSizes = new MPos[info.Pieces.Length];
                for (int i = 0; i < blockSizes.Length; i++)
                {
                    blockSizes[i] = PieceManager.GetPiece(info.Pieces[i]).Size;
                }

                var x = blockSizes.Max(b => b.X);
                var y = blockSizes.Max(b => b.Y);
                searchBlocks = new MPos(x, y);
            }
            searchBounds = new MPos((int)Math.Floor(Bounds.X / (float)searchBlocks.X), (int)Math.Floor(Bounds.Y / (float)searchBlocks.Y));
            positions    = searchBounds.X * searchBounds.Y;

            // usual grid
            for (int i = 0; i < positions; i++)
            {
                var xStart = (i % searchBounds.X) * searchBounds.X;
                if (xStart >= Bounds.X)
                {
                    break;
                }

                var yStart = (int)Math.Floor(i / (float)searchBounds.X) * searchBounds.Y;

                var canAcquire = true;
                for (var x = xStart; x < xStart + searchBlocks.X; x++)
                {
                    if (x >= Bounds.X)
                    {
                        break;
                    }

                    if (!canAcquire)
                    {
                        break;
                    }

                    for (var y = yStart; y < yStart + searchBlocks.Y; y++)
                    {
                        if (y >= Bounds.Y)
                        {
                            break;
                        }

                        var value = noise[x, y];
                        if (info.NoiseMapLimit > value)
                        {
                            canAcquire = false;
                            break;
                        }

                        if (!Loader.CanAcquireCell(new MPos(x, y), info.ID))
                        {
                            canAcquire = false;
                            break;
                        }
                    }
                }

                if (canAcquire)
                {
                    possiblePlaces.Add(new MPos(xStart, yStart));
                }
            }

            // Additional refining using steps
            for (int step = 0; step < searchBounds.X; step += info.ShiftStep)
            {
                for (int i = 0; i < positions; i++)
                {
                    var xStart = (i % searchBounds.X) * searchBounds.X + step;
                    if (xStart >= Bounds.X)
                    {
                        break;
                    }

                    var yStart = (int)Math.Floor(i / (float)searchBounds.X) * searchBounds.Y;

                    var canAcquire = true;
                    for (var x = xStart; x < xStart + searchBlocks.X; x++)
                    {
                        if (x >= Bounds.X)
                        {
                            break;
                        }

                        if (!canAcquire)
                        {
                            break;
                        }

                        for (var y = yStart; y < yStart + searchBlocks.Y; y++)
                        {
                            if (y >= Bounds.Y)
                            {
                                break;
                            }

                            if (!Loader.CanAcquireCell(new MPos(x, y), info.ID))
                            {
                                canAcquire = false;
                                break;
                            }
                        }
                    }

                    if (canAcquire)
                    {
                        possiblePlaces.Add(new MPos(xStart, yStart));
                    }
                }
            }
            for (int step = 0; step < searchBounds.Y; step += info.ShiftStep)
            {
                for (int i = 0; i < positions; i++)
                {
                    var xStart = (i % searchBounds.X) * searchBounds.X;
                    var yStart = (int)Math.Floor(i / (float)searchBounds.X) * searchBounds.Y + step;
                    if (yStart >= Bounds.Y)
                    {
                        break;
                    }

                    var canAcquire = true;
                    for (var x = xStart; x < xStart + searchBlocks.X; x++)
                    {
                        if (x >= Bounds.X)
                        {
                            break;
                        }

                        if (!canAcquire)
                        {
                            break;
                        }

                        for (var y = yStart; y < yStart + searchBlocks.Y; y++)
                        {
                            if (y >= Bounds.Y)
                            {
                                break;
                            }

                            if (!Loader.CanAcquireCell(new MPos(x, y), info.ID))
                            {
                                canAcquire = false;
                                break;
                            }
                        }
                    }

                    if (canAcquire)
                    {
                        possiblePlaces.Add(new MPos(xStart, yStart));
                    }
                }
            }

            var multiplier = Bounds.X * Bounds.Y / (float)(32 * 32);
            var count      = Random.Next((int)(info.MinimumCount * multiplier), (int)(info.MaximumCount * multiplier));

            for (int i = 0; i < count; i++)
            {
                if (possiblePlaces.Count == 0)
                {
                    break;
                }

                var piece = info.Pieces[Random.Next(info.Pieces.Length)];
                var input = PieceManager.GetPiece(piece);

                var position = Random.Next(possiblePlaces.Count);

                if (!Loader.GeneratePiece(input, possiblePlaces[position], info.ID))
                {
                    i--;
                }
                else
                {
                    markDirty(possiblePlaces[position], input);
                }

                possiblePlaces.RemoveAt(position);
            }

            MapPrinter.PrintGeneratorMap(Bounds, noise, UsedCells, info.ID);
        }