public List <Room> execute(TemplateResults formattedRects)
        {
            var rooms = new List <Room>();

            formattedRects.pathIndices.ForEach((path) =>
            {
                rooms.Add(new Room(path, "path"));
            });
            formattedRects.centers.ForEach((path) =>
            {
                rooms.Add(new Room(path, "center"));
            });
            formattedRects.nonPathIndices.ForEach((path) =>
            {
                rooms.Add(new Room(path, "room"));
            });
            rooms = new List <Room>(new HashSet <Room>(rooms));
            chooseEntrances(rooms);


            rooms = mergeRooms(rooms, 1, IsDisconnected, IsValidRoom);
            rooms = mergeRooms(rooms, 1, IsValidRoom, IsValidRoom);
            rooms = mergeRooms(rooms, 100, IsHallwayRoom, IsHallwayRoom);

            return(rooms);
        }
Exemple #2
0
        TemplateResults removeDoubleWalls(TemplateResults formattedRects)
        {
            var roomRects = formattedRects.allRects;

            for (var i = 0; i < roomRects.Count; i++)
            {
                var r             = roomRects[i];
                var nextX         = r.maxX + 1;
                var nextZ         = r.maxY + 1;
                var adjacentRectZ = roomRects.Find((rect) => { return(rect.minY == nextZ); });
                var adjacentRectX = roomRects.Find((rect) => { return(rect.minX == nextX); });


                if (adjacentRectX != null && adjacentRectZ != null)
                {
                    roomRects[i] = new Rect(r.minX, r.minY, r.Width + 1, r.Height + 1);
                }
                else if (adjacentRectX != null)
                {
                    roomRects[i] = new Rect(r.minX, r.minY, r.Width + 1, r.Height);
                }
                else if (adjacentRectZ != null)
                {
                    roomRects[i] = new Rect(r.minX, r.minY, r.Width, r.Height + 1);
                }
            }
            return(formattedRects);
        }
Exemple #3
0
        TemplateResults selectHallways(TemplateResults formattedRects)
        {
            var edges = new List <Edge>();

            var coordinates = new List <Coordinate>();

            formattedRects.centers.ForEach((p) =>
            {
                coordinates.Add(new Coordinate(p.min.X, p.min.Y));
            });

            var triangulator = new  DelaunayTriangulationBuilder();

            triangulator.SetSites(coordinates.ToArray());
            var triangulatedEdges = triangulator.GetEdges(new GeometryFactory(new PrecisionModel(.1)));

            triangulatedEdges.Geometries.ToList().ForEach((edge) => {
                var Q = edge.Coordinates[0];
                var P = edge.Coordinates[1];
                edges.Add(new Edge(new Point((int)Q.X, (int)Q.Y), new Point((int)P.X, (int)P.Y)));
            });


            var edgePoints = new HashSet <Point>();

            edges = new Prims().exec(edges);
            edges.ForEach((edge) =>
            {
                var p12 = edge.getPoints();
                edgePoints.UnionWith(edge.getPoints());
            });

            var newPaths    = new HashSet <Rect>();
            var newNonPaths = formattedRects.nonPathIndices;

            formattedRects.allRects.ForEach((r) =>
            {
                if (edgePoints.Contains(r.min))
                {
                    newPaths.Add(r);
                }
                else
                {
                    newNonPaths.Add(r);
                }
            });
            formattedRects.nonPathIndices = newNonPaths.ToList();
            formattedRects.pathIndices    = newPaths.ToList();
            return(formattedRects);
        }
Exemple #4
0
        TemplateResults scaleRoomsAndHallways(TemplateResults formattedRects)
        {
            var paths    = formattedRects.pathIndices;
            var nonPaths = formattedRects.nonPathIndices;
            var allRects = formattedRects.allRects;
            var centers  = formattedRects.centers;

            for (var i = 0; i < nonPaths.Count; i++)
            {
                var adjustedHeight = random.Next(6, 13);
                var adjustedWidth  = random.Next(6, 13);

                processSingleRect(allRects, nonPaths[i], adjustedWidth, adjustedHeight);
            }

            for (var i = 0; i < centers.Count; i++)
            {
                var adjustedWidth = random.Next(3, 5);

                processSingleRect(allRects, centers[i], adjustedWidth, adjustedWidth);
            }
            return(formattedRects);
        }
Exemple #5
0
        TemplateResults selectEntrances(TemplateResults formattedRects)
        {
            var numberOfEntrances = 4;

            formattedRects.allRects = formattedRects.allRects.OrderBy((x) => random.NextDouble()).ToList();

            var options = new List <Rect>(formattedRects.allRects);

            for (var i = 0; i < options.Count; i++)
            {
                if (numberOfEntrances == 0)
                {
                    break;
                }
                var option = options[i];
                if (Rect.neighbors(option, formattedRects.allRects).Count == 3 && Rect.neighbors(option, formattedRects.centers).Count == 1)
                {
                    formattedRects.centers.Add(option);
                    formattedRects.pathIndices.Remove(option);
                    numberOfEntrances--;
                }
            }
            return(formattedRects);
        }