private void DoMapping()
        {
            var graph         = levelDescription.GetGraph();
            var stageOneGraph = levelDescription.GetGraphWithoutCorridors();

            foreach (var vertex in graph.Vertices)
            {
                var roomNode = CreateRoomNode(vertex);

                // Create vertices mapping
                mappedGraph.AddVertex(roomNode);

                // Store room description
                roomDescriptions[roomNode.Id] = levelDescription.GetRoomDescription(vertex);
            }

            // Handle main graph edges
            foreach (var edge in graph.Edges)
            {
                mappedGraph.AddEdge(GetRoomNode(edge.From), GetRoomNode(edge.To));
            }

            // Handle stage one graph vertices
            foreach (var vertex in stageOneGraph.Vertices)
            {
                mappedStageOneGraph.AddVertex(GetRoomNode(vertex));
            }

            // Handle stage one graph edges
            foreach (var edge in stageOneGraph.Edges)
            {
                mappedStageOneGraph.AddEdge(GetRoomNode(edge.From), GetRoomNode(edge.To));
            }
        }
Esempio n. 2
0
 public CorridorConstraint(ILevelDescription <TNode> mapDescription, IConfigurationSpaces <TConfiguration> configurationSpaces, IRoomShapeGeometry <TConfiguration> roomShapeGeometry)
 {
     this.mapDescription      = mapDescription;
     this.configurationSpaces = configurationSpaces;
     this.roomShapeGeometry   = roomShapeGeometry;
     graphWithoutCorridors    = mapDescription.GetGraphWithoutCorridors();
     graph = mapDescription.GetGraph();
 }
 protected AbstractLayoutController(int averageSize, ILevelDescription <TNode> levelDescription, IRoomShapesHandler <TLayout, TNode, TShapeContainer> roomShapesHandler, IRoomShapeGeometry <TConfiguration> roomShapeGeometry)
 {
     AverageSize       = averageSize;
     LevelDescription  = levelDescription;
     RoomShapesHandler = roomShapesHandler;
     RoomShapeGeometry = roomShapeGeometry;
     StageOneGraph     = levelDescription.GetGraphWithoutCorridors();
 }
Esempio n. 4
0
        public RoomShapesHandlerGrid2D(
            TwoWayDictionary <RoomTemplateInstanceGrid2D, IntAlias <PolygonGrid2D> > intAliasMapping,
            ILevelDescription <TNode> mapDescription, Dictionary <TNode, List <WeightedShape> > shapesForNodes, RoomTemplateRepeatMode?repeatModeOverride = null, RoomTemplateRepeatMode?repeatModeDefault = null)
        {
            this.intAliasMapping    = intAliasMapping;
            this.mapDescription     = mapDescription;
            this.shapesForNodes     = shapesForNodes;
            this.repeatModeDefault  = repeatModeDefault;
            this.repeatModeOverride = repeatModeOverride;
            graphWithoutCorridors   = mapDescription.GetGraphWithoutCorridors();

            Initialize();
        }
Esempio n. 5
0
        /// <inheritdoc />
        public List <Chain <TNode> > GetChains(IGraph <TNode> graph)
        {
            // Get all the faces from the stage one graph
            var stageOneGraph = mapDescription.GetGraphWithoutCorridors();
            var faces         = decomposition.GetChains(stageOneGraph);

            var usedVertices         = new HashSet <TNode>();
            var notUsedStageTwoRooms = graph.Vertices.Where(x => mapDescription.GetRoomDescription(x).IsCorridor).ToList();

            // Iterate through all the faces, marking all the seen vertices
            // As soon as all the neighbors of a stage two room are used, add the stage two room to the current face
            foreach (var face in faces)
            {
                // TODO: weird ForEach
                face.Nodes.ToList().ForEach(x => usedVertices.Add(x));

                foreach (var stageTwoRoom in notUsedStageTwoRooms.ToList())
                {
                    var neighbors = graph.GetNeighbours(stageTwoRoom).ToList();

                    if (neighbors.TrueForAll(x => usedVertices.Contains(x)))
                    {
                        notUsedStageTwoRooms.Remove(stageTwoRoom);
                        face.Nodes.Add(stageTwoRoom);
                    }
                }
            }

            // It must not happen that a stage two room is not in the decomposition
            if (notUsedStageTwoRooms.Count != 0)
            {
                throw new ArgumentException();
            }

            return(faces);
        }