Esempio n. 1
0
        public void ConnectionsOfMultipleDepthFromDeadEndFinalRoomsCanBeFound()
        {
            var standardMap = BuildBranchingTestMap();
            var mapNoCycles = new MapCycleReducer(standardMap.RoomConnectionGraph.Edges);
            var mapH        = new MapHeuristics(mapNoCycles, 1);

            var expectedConnections = new Dictionary <int, List <Connection> > {
                { 0, new List <Connection>(new Connection[] {
                        new Connection(1, 2),
                        new Connection(5, 6),
                        new Connection(13, 14),
                        new Connection(13, 15),
                        new Connection(16, 17),
                        new Connection(12, 18)
                    }) },
                { 1, new List <Connection>(new Connection[] {
                        new Connection(3, 5),
                        new Connection(11, 12),
                        new Connection(4, 16)
                    }) },
                { 2, new List <Connection>(new Connection[] {
                        new Connection(3, 4)
                    }) }
            };

            var terminalConnectionsFound = mapH.GetTerminalBranchConnections();

            CollectionAssert.AreEquivalent(expectedConnections[0], terminalConnectionsFound[0]);
            CollectionAssert.AreEquivalent(expectedConnections[1], terminalConnectionsFound[1]);
            CollectionAssert.AreEquivalent(expectedConnections[2], terminalConnectionsFound[2]);
            CollectionAssert.AreEquivalent(expectedConnections.Keys, terminalConnectionsFound.Keys);
        }
Esempio n. 2
0
        public void DeadEndNodesAreFoundInSinglePathGraphs()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            var mapNoCycles = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);
            var mapH        = new MapHeuristics(mapNoCycles, 1);

            var expectedConnections = new Dictionary <int, List <Connection> > {
                { 0, new List <Connection>(new Connection[] {
                        new Connection(1, 2),
                        new Connection(2, 3)
                    }) }
            };

            var terminalConnectionsFound = mapH.GetTerminalBranchConnections();

            //TODO: We have slightly pathological behaviour that all non-terminal node connections
            //will be double counted in the
            CollectionAssert.AreEquivalent(expectedConnections[0], terminalConnectionsFound[0]);
            CollectionAssert.AreEquivalent(expectedConnections.Keys, terminalConnectionsFound.Keys);
        }
Esempio n. 3
0
        /** Build a map using templated rooms */
        public MapInfo GenerateDungeonWithReplacedVaults()
        {
            //Load standard room types
            RoomTemplate room1     = RoomTemplateLoader.LoadTemplateFromFile("RogueBasin.bin.Debug.vaults.vault1.room", StandardTemplateMapping.terrainMapping);
            RoomTemplate corridor1 = RoomTemplateLoader.LoadTemplateFromFile("RogueBasin.bin.Debug.vaults.corridortemplate3x1.room", StandardTemplateMapping.terrainMapping);

            RoomTemplate replacementVault = RoomTemplateLoader.LoadTemplateFromFile("RogueBasin.bin.Debug.vaults.replacevault1.room", StandardTemplateMapping.terrainMapping);
            RoomTemplate placeHolderVault = RoomTemplateLoader.LoadTemplateFromFile("RogueBasin.bin.Debug.vaults.placeholdervault1.room", StandardTemplateMapping.terrainMapping);

            //Build level 1

            var l1mapBuilder        = new TemplatedMapBuilder(100, 100);
            var l1templateGenerator = new TemplatedMapGenerator(l1mapBuilder);

            PlaceOriginRoom(l1templateGenerator, room1);
            PlaceRandomConnectedRooms(l1templateGenerator, 5, room1, corridor1, 5, 10);

            //Add a place holder room for the elevator
            var l1elevatorConnection = AddRoomToRandomOpenDoor(l1templateGenerator, placeHolderVault, corridor1, 3);
            var l1elevatorIndex      = l1elevatorConnection.Target;

            LogFile.Log.LogEntryDebug("Level 1 elevator at index " + l1elevatorIndex, LogDebugLevel.High);

            //Build level 2

            var l2mapBuilder        = new TemplatedMapBuilder(100, 100);
            var l2templateGenerator = new TemplatedMapGenerator(l2mapBuilder, 100);

            PlaceOriginRoom(l2templateGenerator, room1);
            PlaceRandomConnectedRooms(l2templateGenerator, 5, room1, corridor1, 5, 10);

            //Add a place holder room for the elevator
            var l2elevatorConnection = AddRoomToRandomOpenDoor(l2templateGenerator, placeHolderVault, corridor1, 3);
            var l2elevatorIndex      = l2elevatorConnection.Target;

            LogFile.Log.LogEntryDebug("Level 2 elevator at index " + l2elevatorIndex, LogDebugLevel.High);

            //Replace the placeholder vaults with the actual elevator rooms
            l1templateGenerator.ReplaceRoomTemplate(l1elevatorIndex, l1elevatorConnection, replacementVault, 0);
            l2templateGenerator.ReplaceRoomTemplate(l2elevatorIndex, l2elevatorConnection, replacementVault, 0);

            //Replace spare doors with walls
            l1templateGenerator.ReplaceUnconnectedDoorsWithTerrain(RoomTemplateTerrain.Wall);
            l2templateGenerator.ReplaceUnconnectedDoorsWithTerrain(RoomTemplateTerrain.Wall);

            //Build the graph containing all the levels

            //Build and add the l1 map

            var mapInfoBuilder = new MapInfoBuilder();
            var startRoom      = 0;

            mapInfoBuilder.AddConstructedLevel(0, l1templateGenerator.ConnectivityMap, l1templateGenerator.GetRoomTemplatesInWorldCoords(), l1templateGenerator.GetDoorsInMapCoords(), startRoom);

            //Build and add the l2 map

            mapInfoBuilder.AddConstructedLevel(1, l2templateGenerator.ConnectivityMap, l2templateGenerator.GetRoomTemplatesInWorldCoords(), l2templateGenerator.GetDoorsInMapCoords(),
                                               new Connection(l1elevatorIndex, l2elevatorIndex));

            MapInfo mapInfo       = new MapInfo(mapInfoBuilder);
            var     mapHeuristics = new MapHeuristics(mapInfo.Model.GraphNoCycles, startRoom);

            //LOCKS

            //Add a locked door on a dead end, localised to level 0
            var level0Indices       = mapInfo.GetRoomIndicesForLevel(0);
            var roomConnectivityMap = mapHeuristics.GetTerminalBranchConnections();

            var deadEnds         = roomConnectivityMap[0];
            var deadEndsInLevel0 = deadEnds.Where(c => level0Indices.Contains(c.Source) && level0Indices.Contains(c.Target)).ToList();

            var randomDeadEndToLock = deadEndsInLevel0.RandomElement();

            var allRoomsForClue0    = mapInfo.Model.DoorAndClueManager.GetValidRoomsToPlaceClueForDoor(randomDeadEndToLock);
            var roomsForClue0Level0 = allRoomsForClue0.Intersect(level0Indices);
            var roomForClue0        = roomsForClue0Level0.RandomElement();

            LogFile.Log.LogEntryDebug("Lock door " + randomDeadEndToLock + " clue at " + roomForClue0, LogDebugLevel.High);

            mapInfo.Model.DoorAndClueManager.PlaceDoorAndClue(new DoorRequirements(randomDeadEndToLock, "yellow"), roomForClue0);

            //Add a locked door halfway along the critical path between the l0 and l1 elevators
            var l0CriticalPath       = mapInfo.Model.GetPathBetweenVerticesInReducedMap(startRoom, l1elevatorIndex);
            var l0CriticalConnection = l0CriticalPath.ElementAt(l0CriticalPath.Count() / 2);

            var allRoomsForCriticalL0Clue = mapInfo.Model.DoorAndClueManager.GetValidRoomsToPlaceClueForDoor(l0CriticalConnection);
            var roomForCriticalL0Clue     = allRoomsForCriticalL0Clue.RandomElement();

            mapInfo.Model.DoorAndClueManager.PlaceDoorAndClue(new DoorRequirements(l0CriticalConnection, "green"), roomForCriticalL0Clue);

            LogFile.Log.LogEntryDebug("L0 Critical Path, candidates: " + l0CriticalPath.Count() + " lock at: " + l0CriticalConnection + " clue at " + roomForCriticalL0Clue, LogDebugLevel.High);

            //Add a multi-level clue
            var level1Indices = mapInfo.GetRoomIndicesForLevel(1);

            var deadEndsInLevel1 = deadEnds.Where(c => level1Indices.Contains(c.Source) && level1Indices.Contains(c.Target)).ToList();

            var randomDeadEndToLockL1 = deadEndsInLevel1.RandomElement();

            var allRoomsForClue1    = mapInfo.Model.DoorAndClueManager.GetValidRoomsToPlaceClueForDoor(randomDeadEndToLockL1);
            var roomsForClue1Level0 = allRoomsForClue1.Intersect(level0Indices);
            var roomForClue1        = roomsForClue0Level0.RandomElement();

            LogFile.Log.LogEntryDebug("Lock door " + randomDeadEndToLock + " clue at " + roomForClue0, LogDebugLevel.High);

            mapInfo.Model.DoorAndClueManager.PlaceDoorAndClue(new DoorRequirements(randomDeadEndToLockL1, "red"), roomForClue1);

            //Add a locked door to a dead end, localised to level 1 and place the clue as far away as possible on that level

            var randomDeadEndToLockL1FarClue = deadEndsInLevel1.RandomElement();

            var allRoomsForFarClue          = mapInfo.Model.DoorAndClueManager.GetValidRoomsToPlaceClueForDoor(randomDeadEndToLockL1FarClue);
            var roomsForFarClueLevel1       = allRoomsForFarClue.Intersect(level1Indices);
            var distancesBetweenClueAndDoor = mapInfo.Model.GetDistanceOfVerticesFromParticularVertexInReducedMap(randomDeadEndToLockL1.Source, roomsForFarClueLevel1);
            var roomForFarClue = MaxEntry(distancesBetweenClueAndDoor).Key;

            LogFile.Log.LogEntryDebug("Lock door " + randomDeadEndToLockL1FarClue + " clue at " + roomForFarClue, LogDebugLevel.High);

            mapInfo.Model.DoorAndClueManager.PlaceDoorAndClue(new DoorRequirements(randomDeadEndToLockL1FarClue, "magenta"), roomForFarClue);

            //Add maps to the dungeon

            Map masterMap = l1mapBuilder.MergeTemplatesIntoMap(terrainMapping);

            //Set player's start location (must be done before adding items)

            var firstRoom = mapInfo.GetRoom(0);

            masterMap.PCStartLocation = new Point(firstRoom.X + firstRoom.Room.Width / 2, firstRoom.Y + firstRoom.Room.Height / 2);

            //Add terrain and randomize walls

            Dictionary <MapTerrain, List <MapTerrain> > brickTerrainMapping = new Dictionary <MapTerrain, List <MapTerrain> > {
                { MapTerrain.Wall, new List <MapTerrain> {
                      MapTerrain.BrickWall1, MapTerrain.BrickWall1, MapTerrain.BrickWall1, MapTerrain.BrickWall2, MapTerrain.BrickWall3, MapTerrain.BrickWall4, MapTerrain.BrickWall5
                  } }
            };

            Map randomizedMapL1 = MapTerrainRandomizer.RandomizeTerrainInMap(masterMap, brickTerrainMapping);

            Game.Dungeon.AddMap(randomizedMapL1);

            Map masterMapL2 = l2mapBuilder.MergeTemplatesIntoMap(terrainMapping);
            Dictionary <MapTerrain, List <MapTerrain> > panelTerrainMapping = new Dictionary <MapTerrain, List <MapTerrain> > {
                { MapTerrain.Wall, new List <MapTerrain> {
                      MapTerrain.PanelWall1, MapTerrain.PanelWall1, MapTerrain.PanelWall1, MapTerrain.PanelWall2, MapTerrain.PanelWall3, MapTerrain.PanelWall4, MapTerrain.PanelWall5
                  } }
            };
            Map randomizedMapL2 = MapTerrainRandomizer.RandomizeTerrainInMap(masterMapL2, panelTerrainMapping);

            Game.Dungeon.AddMap(randomizedMapL2);

            //Recalculate walkable to allow placing objects
            Game.Dungeon.RefreshAllLevelPathingAndFOV();

            //Add elevator features to link the maps

            //L1 -> L2
            var elevator1Loc = mapInfo.GetRandomPointInRoomOfTerrain(l1elevatorIndex, RoomTemplateTerrain.Floor);
            var elevator2Loc = mapInfo.GetRandomPointInRoomOfTerrain(l2elevatorIndex, RoomTemplateTerrain.Floor);

            Game.Dungeon.AddFeature(new Features.Elevator(1, elevator2Loc), 0, elevator1Loc);
            Game.Dungeon.AddFeature(new Features.Elevator(0, elevator1Loc), 1, elevator2Loc);


            //Add clues

            //Find a random room corresponding to a vertex with a clue and place a clue there
            foreach (var cluesAtVertex in mapInfo.Model.DoorAndClueManager.ClueMap)
            {
                foreach (var clue in cluesAtVertex.Value)
                {
                    var possibleRooms = clue.PossibleClueRoomsInFullMap;
                    var randomRoom    = possibleRooms[Game.Random.Next(possibleRooms.Count)];

                    var pointInRoom = mapInfo.GetRandomPointInRoomOfTerrain(randomRoom, RoomTemplateTerrain.Floor);

                    Game.Dungeon.AddItem(new Items.Clue(clue), mapInfo.GetLevelForRoomIndex(randomRoom), pointInRoom);
                }
            }

            //Add locks to dungeon as simple doors

            foreach (var door in mapInfo.Model.DoorAndClueManager.DoorMap.Values)
            {
                var lockedDoor = new Locks.SimpleLockedDoor(door);
                var doorInfo   = mapInfo.GetDoorForConnection(door.DoorConnectionFullMap);
                lockedDoor.LocationLevel = doorInfo.LevelNo;
                lockedDoor.LocationMap   = doorInfo.MapLocation;

                LogFile.Log.LogEntryDebug("Lock door level " + lockedDoor.LocationLevel + " loc: " + doorInfo.MapLocation, LogDebugLevel.High);

                Game.Dungeon.AddLock(lockedDoor);
            }

            //Set map for visualisation
            return(mapInfo);
        }