Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        public void PlaceRoom(int roll, int expectedChosen)
        {
            // verify rand is working
            // place on a floor where the first room is immutable
            // place on a floor where the first room is default
            string[] inGrid =
            {
                "0.0.0.0.0.0.0",
                ". . . . . . .",
                "0.A#B#C#D#E.0",
                ". . . . . . .",
                "0.0.0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(1);

            roomPlan.Components.Set(new TestComponent());
            roomPlan            = floorPlan.GetRoomPlan(3);
            roomPlan.RoomGen    = new RoomGenDefault <IGridPathTestContext>();
            roomPlan.PreferHall = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            // The roll for size
            testRand.Setup(p => p.Next(0, 0)).Returns(0);

            // The roll for choosing room index
            testRand.Setup(p => p.Next(3)).Returns(roll);

            var pathGen = new SetGridSpecialRoomStep <IGridPathTestContext>
            {
                Rooms = new PresetPicker <RoomGen <IGridPathTestContext> >(new RoomGenSquare <IGridPathTestContext>()),
            };

            pathGen.Filters.Add(new RoomFilterComponent(true, new TestComponent()));

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(5));
            for (int ii = 0; ii < 5; ii++)
            {
                if (ii == expectedChosen)
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
                else
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.Not.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
            }
        }