示例#1
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);
        }
示例#2
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);
        }