Esempio n. 1
0
        public override void ApplyToPath(IRandom rand, FloorPlan floorPlan)
        {
            //attempt 10 times
            for (int kk = 0; kk < 10; kk++)
            {
                //add the boss room

                FloorPathBranch <T> .ListPathBranchExpansion?expandBossResult = this.ChooseRoomExpansion(rand, floorPlan);

                if (!expandBossResult.HasValue)
                {
                    continue;
                }

                var bossExpansion = expandBossResult.Value;

                RoomHallIndex from = bossExpansion.From;
                if (bossExpansion.Hall != null)
                {
                    floorPlan.AddHall(bossExpansion.Hall, this.BossHallComponents.Clone(), from);
                    from = new RoomHallIndex(floorPlan.HallCount - 1, true);
                }

                floorPlan.AddRoom(bossExpansion.Room, this.BossComponents.Clone(), from);

                RoomHallIndex bossFrom = new RoomHallIndex(floorPlan.RoomCount - 1, false);

                GenContextDebug.DebugProgress("Extended with Boss Room");

                //now, attempt to add the treasure room and remove the previous rooms if failed


                FloorPathBranch <T> .ListPathBranchExpansion?expansionResult = FloorPathBranch <T> .ChooseRoomExpansion(this.PrepareTreasureRoom, 100, rand, floorPlan, new List <RoomHallIndex>() { bossFrom });

                if (!expansionResult.HasValue)
                {
                    //remove the previously added boss room and hall
                    floorPlan.EraseRoomHall(bossFrom);
                    floorPlan.EraseRoomHall(from);
                    continue;
                }

                var vaultExpansion = expansionResult.Value;

                if (vaultExpansion.Hall != null)
                {
                    floorPlan.AddHall(vaultExpansion.Hall, this.VaultHallComponents.Clone(), bossFrom);
                    bossFrom = new RoomHallIndex(floorPlan.HallCount - 1, true);
                }

                floorPlan.AddRoom(vaultExpansion.Room, this.VaultComponents.Clone(), bossFrom);

                GenContextDebug.DebugProgress("Extended with Treasure Room");

                return;
            }
        }
Esempio n. 2
0
        public static void Run()
        {
            Console.Clear();
            const string title = "2: A Map Made with Rooms and Halls";

            var layout = new MapGen <MapGenContext>();

            // Initialize a 54x40 floorplan with which to populate with rectangular floor and halls.
            InitFloorPlanStep <MapGenContext> startGen = new InitFloorPlanStep <MapGenContext>(54, 40);

            layout.GenSteps.Add(-2, startGen);

            // Create some room types to place
            var genericRooms = new SpawnList <RoomGen <MapGenContext> >
            {
                { new RoomGenSquare <MapGenContext>(new RandRange(4, 8), new RandRange(4, 8)), 10 }, // cross
                { new RoomGenRound <MapGenContext>(new RandRange(5, 9), new RandRange(5, 9)), 10 },  // round
            };

            // Create some hall types to place
            var genericHalls = new SpawnList <PermissiveRoomGen <MapGenContext> >
            {
                { new RoomGenAngledHall <MapGenContext>(0, new RandRange(3, 7), new RandRange(3, 7)), 10 },
                { new RoomGenSquare <MapGenContext>(new RandRange(1), new RandRange(1)), 20 },
            };

            // Feed the room and hall types to a path that is composed of a branching tree
            FloorPathBranch <MapGenContext> path = new FloorPathBranch <MapGenContext>(genericRooms, genericHalls)
            {
                HallPercent = 50,
                FillPercent = new RandRange(45),
                BranchRatio = new RandRange(0, 25),
            };

            layout.GenSteps.Add(-1, path);

            // Draw the rooms onto the tiled map, with 1 TILE padded on each side
            layout.GenSteps.Add(0, new DrawFloorToTileStep <MapGenContext>(1));

            // Run the generator and print
            MapGenContext context = layout.GenMap(MathUtils.Rand.NextUInt64());

            Print(context.Map, title);
        }
Esempio n. 3
0
        public virtual FloorPathBranch <T> .ListPathBranchExpansion?ChooseRoomExpansion(IRandom rand, FloorPlan floorPlan)
        {
            List <RoomHallIndex> availableExpansions = new List <RoomHallIndex>();

            for (int ii = 0; ii < floorPlan.RoomCount; ii++)
            {
                if (!BaseRoomFilter.PassesAllFilters(floorPlan.GetRoomPlan(ii), this.Filters))
                {
                    continue;
                }
                availableExpansions.Add(new RoomHallIndex(ii, false));
            }

            for (int ii = 0; ii < floorPlan.HallCount; ii++)
            {
                if (!BaseRoomFilter.PassesAllFilters(floorPlan.GetHallPlan(ii), this.Filters))
                {
                    continue;
                }
                availableExpansions.Add(new RoomHallIndex(ii, true));
            }

            return(FloorPathBranch <T> .ChooseRoomExpansion(this.PrepareBossRoom, 100, rand, floorPlan, availableExpansions));
        }
Esempio n. 4
0
        public static void Run()
        {
            Console.Clear();
            const string title = "7: A Map with Special Rooms";

            var layout = new MapGen <MapGenContext>();

            // Initialize a 54x40 floorplan with which to populate with rectangular floor and halls.
            InitFloorPlanStep <MapGenContext> startGen = new InitFloorPlanStep <MapGenContext>(54, 40);

            layout.GenSteps.Add(-2, startGen);

            // Create some room types to place
            SpawnList <RoomGen <MapGenContext> > genericRooms = new SpawnList <RoomGen <MapGenContext> >
            {
                { new RoomGenSquare <MapGenContext>(new RandRange(7, 9), new RandRange(7, 9)), 10 },  // square
                { new RoomGenRound <MapGenContext>(new RandRange(6, 10), new RandRange(6, 10)), 10 }, // round
            };

            // Create some hall types to place
            var genericHalls = new SpawnList <PermissiveRoomGen <MapGenContext> >
            {
                { new RoomGenAngledHall <MapGenContext>(0, new RandRange(3, 7), new RandRange(3, 7)), 10 },
            };

            // Feed the room and hall types to a path that is composed of a branching tree
            FloorPathBranch <MapGenContext> path = new FloorPathBranch <MapGenContext>(genericRooms, genericHalls)
            {
                HallPercent = 50,
                FillPercent = new RandRange(40),
                BranchRatio = new RandRange(0, 25),
            };

            path.RoomComponents.Set(new MainRoomComponent());
            path.HallComponents.Set(new MainHallComponent());

            layout.GenSteps.Add(-1, path);

            string[] custom = new string[]
            {
                "~~~..~~~",
                "~~~..~~~",
                "~~#..#~~",
                "........",
                "........",
                "~~#..#~~",
                "~~~..~~~",
                "~~~..~~~",
            };

            SetSpecialRoomStep <MapGenContext> listSpecialStep = new SetSpecialRoomStep <MapGenContext>
            {
                Rooms = new PresetPicker <RoomGen <MapGenContext> >(CreateRoomGenSpecific <MapGenContext>(custom)),
            };

            listSpecialStep.RoomComponents.Set(new TreasureRoomComponent());
            PresetPicker <PermissiveRoomGen <MapGenContext> > picker = new PresetPicker <PermissiveRoomGen <MapGenContext> >
            {
                ToSpawn = new RoomGenAngledHall <MapGenContext>(0),
            };

            listSpecialStep.Halls = picker;
            layout.GenSteps.Add(-1, listSpecialStep);

            // Draw the rooms of the FloorPlan onto the tiled map, with 1 TILE padded on each side
            layout.GenSteps.Add(0, new DrawFloorToTileStep <MapGenContext>(1));

            // Add the stairs up and down
            layout.GenSteps.Add(2, new FloorStairsStep <MapGenContext, StairsUp, StairsDown>(new StairsUp(), new StairsDown()));

            // Apply Items
            var itemSpawns = new SpawnList <Item>
            {
                { new Item((int)'!'), 10 },
                { new Item((int)']'), 10 },
                { new Item((int)'='), 10 },
                { new Item((int)'?'), 10 },
                { new Item((int)'$'), 10 },
                { new Item((int)'/'), 10 },
                { new Item((int)'*'), 50 },
            };
            RandomRoomSpawnStep <MapGenContext, Item> itemPlacement = new RandomRoomSpawnStep <MapGenContext, Item>(new PickerSpawner <MapGenContext, Item>(new LoopedRand <Item>(itemSpawns, new RandRange(10, 19))));

            layout.GenSteps.Add(6, itemPlacement);

            // Apply Treasure Items
            var treasureSpawns = new SpawnList <Item>
            {
                { new Item((int)'!'), 10 },
                { new Item((int)'*'), 50 },
            };
            RandomRoomSpawnStep <MapGenContext, Item> treasurePlacement = new RandomRoomSpawnStep <MapGenContext, Item>(new PickerSpawner <MapGenContext, Item>(new LoopedRand <Item>(treasureSpawns, new RandRange(7, 10))));

            treasurePlacement.Filters.Add(new RoomFilterComponent(false, new TreasureRoomComponent()));
            layout.GenSteps.Add(6, treasurePlacement);

            // Run the generator and print
            MapGenContext context = layout.GenMap(MathUtils.Rand.NextUInt64());

            Print(context.Map, title);
        }