Example #1
0
        public void PresetPicker()
        {
            PresetPicker <int> testPicker = new PresetPicker <int>(5);
            Mock <IRandom>     testRand   = new Mock <IRandom>(MockBehavior.Strict);

            Assert.That(testPicker.Pick(testRand.Object), Is.EqualTo(5));
        }
Example #2
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            //find the first postproc that is a GridRoom postproc and add this to its special rooms
            //NOTE: if a room-based generator is not found as the generation step, it will just skip this floor but treat it as though it was placed.
            if (SpreadPlan.CheckIfDistributed(zoneContext, context))
            {
                //TODO: allow arbitrary components to be added
                RoomGenOption genDuo = Spawns.Pick(context.Rand);
                SetGridSpecialRoomStep <MapGenContext> specialStep     = new SetGridSpecialRoomStep <MapGenContext>();
                SetSpecialRoomStep <ListMapGenContext> listSpecialStep = new SetSpecialRoomStep <ListMapGenContext>();

                specialStep.Filters = genDuo.Filters;
                if (specialStep.CanApply(context))
                {
                    specialStep.Rooms = new PresetPicker <RoomGen <MapGenContext> >(genDuo.GridOption);
                    specialStep.RoomComponents.Set(new ImmutableRoom());
                    queue.Enqueue(PriorityGrid, specialStep);
                }
                else if (listSpecialStep.CanApply(context))
                {
                    listSpecialStep.Rooms = new PresetPicker <RoomGen <ListMapGenContext> >(genDuo.ListOption);
                    listSpecialStep.RoomComponents.Set(new ImmutableRoom());
                    PresetPicker <PermissiveRoomGen <ListMapGenContext> > picker = new PresetPicker <PermissiveRoomGen <ListMapGenContext> >();
                    picker.ToSpawn        = new RoomGenAngledHall <ListMapGenContext>(0);
                    listSpecialStep.Halls = picker;
                    queue.Enqueue(PriorityList, listSpecialStep);
                }
            }
        }
Example #3
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);
        }