Esempio n. 1
0
        public void ReceiveOpenedBorder(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, Dir4 dir, int expectedStart, int expectedEnd, bool exception)
        {
            Mock <IRandom> testRand    = new Mock <IRandom>(MockBehavior.Strict);
            var            roomGenTo   = new TestRoomGen <ITiledGenContext>();
            var            roomGenFrom = new TestRoomGen <ITiledGenContext>();

            roomGenTo.PrepareSize(testRand.Object, new Loc(w1, h1));
            roomGenTo.SetLoc(new Loc(x1, y1));
            roomGenFrom.PrepareSize(testRand.Object, new Loc(w2, h2));
            roomGenFrom.SetLoc(new Loc(x2, y2));
            for (int ii = 0; ii < roomGenFrom.PublicOpenedBorder[dir.Reverse()].Length; ii++)
            {
                roomGenFrom.PublicOpenedBorder[dir.Reverse()][ii] = true;
            }

            if (exception)
            {
                Assert.Throws <ArgumentException>(() => { roomGenTo.ReceiveOpenedBorder(roomGenFrom, dir); });
            }
            else
            {
                roomGenTo.ReceiveOpenedBorder(roomGenFrom, dir);
                IntRange newRange = roomGenTo.RoomSideReqs[dir][0];
                Assert.That(newRange, Is.EqualTo(new IntRange(expectedStart, expectedEnd)));
            }
        }
Esempio n. 2
0
 public void Reverse(Dir4 dir, Dir4 expected, bool exception = false)
 {
     if (exception)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { dir.Reverse(); });
     }
     else
     {
         Assert.That(dir.Reverse(), Is.EqualTo(expected));
         Assert.That(expected.Reverse(), Is.EqualTo(dir));
     }
 }
Esempio n. 3
0
        public static int GetBorderMatch(IRoomGen roomFrom, IRoomGen room, Loc candLoc, Dir4 expandTo)
        {
            int totalMatch = 0;

            Loc diff   = roomFrom.Draw.Start - candLoc; // how far ahead the start of source is to dest
            int offset = diff.GetScalar(expandTo.ToAxis().Orth());

            // Traverse the region that both borders touch
            int sourceLength = roomFrom.GetBorderLength(expandTo);
            int destLength   = room.GetBorderLength(expandTo.Reverse());

            for (int ii = Math.Max(0, offset); ii - offset < sourceLength && ii < destLength; ii++)
            {
                bool sourceFulfill = roomFrom.GetFulfillableBorder(expandTo, ii - offset);
                bool destFulfill   = room.GetFulfillableBorder(expandTo.Reverse(), ii);
                if (sourceFulfill && destFulfill)
                {
                    totalMatch++;
                }
            }

            return(totalMatch);
        }
Esempio n. 4
0
        public override void ApplyToPath(IRandom rand, GridPlan floorPlan)
        {
            if (floorPlan.GridWidth < 3 || floorPlan.GridHeight < 3)
            {
                throw new InvalidOperationException("Not enough room to create path.");
            }

            int maxRooms = (2 * floorPlan.GridWidth) + (2 * floorPlan.GridHeight) - 4;
            int roomOpen = maxRooms * this.CircleRoomRatio.Pick(rand) / 100;
            int paths    = this.Paths.Pick(rand);

            if (roomOpen < 1 && paths < 1)
            {
                roomOpen = 1;
            }

            GenContextDebug.StepIn("Outer Circle");

            // draw the top and bottom
            for (int xx = 0; xx < floorPlan.GridWidth; xx++)
            {
                this.RollOpenRoom(rand, floorPlan, new Loc(xx, 0), ref roomOpen, ref maxRooms);
                GenContextDebug.DebugProgress("Room");
                this.RollOpenRoom(rand, floorPlan, new Loc(xx, floorPlan.GridHeight - 1), ref roomOpen, ref maxRooms);
                GenContextDebug.DebugProgress("Room");
                if (xx > 0)
                {
                    floorPlan.SetHall(new LocRay4(new Loc(xx, 0), Dir4.Left), this.GenericHalls.Pick(rand), this.HallComponents.Clone());
                    GenContextDebug.DebugProgress("Hall");
                    floorPlan.SetHall(new LocRay4(new Loc(xx, floorPlan.GridHeight - 1), Dir4.Left), this.GenericHalls.Pick(rand), this.HallComponents.Clone());
                    GenContextDebug.DebugProgress("Hall");
                }
            }

            // draw the left and right (excluding the top and bottom)
            for (int yy = 0; yy < floorPlan.GridHeight; yy++)
            {
                // exclude the top and bottom
                if (yy > 0 && yy < floorPlan.GridHeight - 1)
                {
                    this.RollOpenRoom(rand, floorPlan, new Loc(0, yy), ref roomOpen, ref maxRooms);
                    GenContextDebug.DebugProgress("Room");
                    this.RollOpenRoom(rand, floorPlan, new Loc(floorPlan.GridWidth - 1, yy), ref roomOpen, ref maxRooms);
                    GenContextDebug.DebugProgress("Room");
                }

                if (yy > 0)
                {
                    floorPlan.SetHall(new LocRay4(new Loc(0, yy), Dir4.Up), this.GenericHalls.Pick(rand), this.HallComponents.Clone());
                    GenContextDebug.DebugProgress("Hall");
                    floorPlan.SetHall(new LocRay4(new Loc(floorPlan.GridWidth - 1, yy), Dir4.Up), this.GenericHalls.Pick(rand), this.HallComponents.Clone());
                    GenContextDebug.DebugProgress("Hall");
                }
            }

            GenContextDebug.StepOut();

            GenContextDebug.StepIn("Inner Paths");

            Rect innerRect = new Rect(1, 1, floorPlan.GridWidth - 2, floorPlan.GridHeight - 2);

            // create inner paths
            for (int pathsMade = 0; pathsMade < paths; pathsMade++)
            {
                GenContextDebug.StepIn($"Path {pathsMade}");

                Dir4 startDir = DirExt.VALID_DIR4.ElementAt(rand.Next(DirExt.DIR4_COUNT));
                int  x        = rand.Next(innerRect.Start.X, innerRect.End.X);
                int  y        = rand.Next(innerRect.Start.Y, innerRect.End.Y);
                switch (startDir)
                {
                case Dir4.Down:
                    y = 0;
                    break;

                case Dir4.Left:
                    x = floorPlan.GridWidth - 1;
                    break;

                case Dir4.Up:
                    y = floorPlan.GridHeight - 1;
                    break;

                case Dir4.Right:
                    x = 0;
                    break;

                case Dir4.None:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(startDir), "Invalid enum value.");
                }

                Loc  wanderer   = new Loc(x, y);
                Dir4 prevDir    = Dir4.None; // direction of movement
                int  pathLength = (startDir.ToAxis() == Axis4.Vert) ? innerRect.Height : innerRect.Width;
                for (int currentLength = 0; currentLength < pathLength; currentLength++)
                {
                    Dir4 chosenDir = startDir;

                    // avoid this block the first time
                    if (currentLength > 0)
                    {
                        List <Dir4> dirs = new List <Dir4>();
                        foreach (Dir4 dir in DirExt.VALID_DIR4)
                        {
                            // do not backtrack
                            if (dir == prevDir)
                            {
                                continue;
                            }

                            // do not hit edge
                            if (!Collision.InBounds(innerRect, wanderer + dir.GetLoc()))
                            {
                                continue;
                            }
                            dirs.Add(dir);
                        }

                        chosenDir = dirs[rand.Next(dirs.Count)];
                    }

                    Loc dest = wanderer + chosenDir.GetLoc();

                    GridRoomPlan existingRoom = floorPlan.GetRoomPlan(dest);
                    if (existingRoom == null)
                    {
                        if (currentLength == pathLength - 1) // only the end room can be a non-hall
                        {
                            floorPlan.AddRoom(dest, this.GenericRooms.Pick(rand), this.RoomComponents.Clone());
                        }
                        else
                        {
                            floorPlan.AddRoom(dest, this.GetDefaultGen(), this.HallComponents.Clone(), true);
                        }
                        GenContextDebug.DebugProgress("Room");
                    }
                    else if (existingRoom.PreferHall)
                    {
                        if (currentLength == pathLength - 1)
                        {
                            // override the hall room
                            existingRoom.RoomGen    = this.GenericRooms.Pick(rand).Copy();
                            existingRoom.PreferHall = false;
                        }
                    }

                    floorPlan.SetHall(new LocRay4(wanderer, chosenDir), this.GenericHalls.Pick(rand), this.HallComponents.Clone());
                    GenContextDebug.DebugProgress("Hall");

                    wanderer = dest;
                    prevDir  = chosenDir.Reverse();
                }

                GenContextDebug.StepOut();
            }

            GenContextDebug.StepOut();
        }
Esempio n. 5
0
 public virtual int GetSideBorderMatch(IRoomGen newGen, Dictionary <Dir4, List <IRoomGen> > adjacentsByDir, Loc loc, Dir4 dir, int matchValue)
 {
     foreach (IRoomGen adj in adjacentsByDir[dir])
     {
         matchValue = Math.Min(matchValue, FloorPlan.GetBorderMatch(adj, newGen, loc, dir.Reverse()));
     }
     return(matchValue);
 }
Esempio n. 6
0
        /// <summary>
        /// Decides on the bounds for each hall.  Also writes to the adjacent rooms' SideReqs and tile permissions
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="vertical"></param>
        /// <param name="rand">todo: describe rand parameter on ChooseHallBounds</param>
        public void ChooseHallBounds(IRandom rand, int x, int y, bool vertical)
        {
            GridRoomPlan startRoom = this.GetRoomPlan(new Loc(x, y));
            GridRoomPlan endRoom   = this.GetRoomPlan(new Loc(x + (vertical ? 0 : 1), y + (vertical ? 1 : 0)));

            GridHallGroup hallGroup = vertical ? this.VHalls[x][y] : this.HHalls[x][y];

            if (hallGroup.MainHall != null)
            {
                // also sets the sidereqs
                int      tier          = vertical ? x : y;
                Dir4     dir           = vertical ? Dir4.Down : Dir4.Right;
                IntRange startRange    = this.GetHallTouchRange(startRoom.RoomGen, dir, tier);
                IntRange endRange      = this.GetHallTouchRange(endRoom.RoomGen, dir.Reverse(), tier);
                IntRange combinedRange = new IntRange(Math.Min(startRange.Min, endRange.Min), Math.Max(startRange.Max, endRange.Max));
                Loc      start         = startRoom.RoomGen.Draw.End;
                Loc      end           = endRoom.RoomGen.Draw.Start;

                Rect startCell = this.GetCellBounds(startRoom.Bounds);
                Rect endCell   = this.GetCellBounds(endRoom.Bounds);

                Rect bounds = vertical ? new Rect(combinedRange.Min, start.Y, combinedRange.Length, end.Y - start.Y)
                    : new Rect(start.X, combinedRange.Min, end.X - start.X, combinedRange.Length);

                // a side constitutes intruding bound when the rectangle moves forward enough to go to the other side
                // and the other side touched is outside of side B's bound (including borders)

                // startRange intrudes if startRange goes outside end's tier (borders included)
                bool startIntrude = !endCell.GetSide(dir.ToAxis()).Contains(startRange);

                // and end is greater than the edge (borders excluded)
                bool endTouch = bounds.GetScalar(dir) == endCell.GetScalar(dir.Reverse());

                bool endIntrude = !startCell.GetSide(dir.ToAxis()).Contains(endRange);

                // and end is greater than the edge (borders excluded)
                bool startTouch = bounds.GetScalar(dir.Reverse()) == startCell.GetScalar(dir);

                // neither side intrudes bound: use the computed rectangle
                if ((!startIntrude && !endIntrude) || (endTouch && startTouch) ||
                    (!(startIntrude && endIntrude) && ((startIntrude && endTouch) || (endIntrude && startTouch))))
                {
                    hallGroup.MainHall.RoomGen.PrepareSize(rand, bounds.Size);
                    hallGroup.MainHall.RoomGen.SetLoc(bounds.Start);
                }
                else
                {
                    int      divPoint      = startCell.GetScalar(dir) + 1;
                    IntRange startDivRange = startRange;
                    IntRange endDivRange   = endRange;
                    if (startIntrude && !endIntrude)
                    {
                        // side A intrudes bound, side B does not: divide A and B; doesn't matter who gets border
                        // side A touches border, side B does not: divide A and B; A gets border
                        //
                        // side A does not, side B touches border: A gets border; don't need B - this cannot happen
                        // side A touches border, side B touches border: A gets border; don't need B - this cannot happen
                        //
                        // in short, divide with start getting the border
                        // startDivRange needs to contain endRange
                        startDivRange = combinedRange;
                    }
                    else if (!startIntrude && endIntrude)
                    {
                        // side A does not, side B intrudes bound: divide A and B; doesn't matter who gets border
                        // side A does not, side B touches border: divide A and B; B gets border
                        //
                        // side A touches border, side B does not: B gets border; don't need A - this cannot happen
                        // side A touches border, side B touches border: B gets border; don't need B - this cannot happen
                        //
                        // in short, divide with end getting the border
                        // endDivRange needs to contain startRange
                        divPoint    = startCell.GetScalar(dir);
                        endDivRange = combinedRange;
                    }
                    else
                    {
                        // side A intrudes bound, side B intrudes bound: divide A and B; doesn't matter who gets border
                        if (startTouch)
                        {
                            // side A touches border, side B does not: divide A and B; A gets border
                        }

                        if (endTouch)
                        {
                            // side A does not, side B touches border: divide A and B; B gets border
                            divPoint = startCell.GetScalar(dir);
                        }

                        // side A touches border, side B touches border: A gets border; don't need B -  this cannot happen
                        // both sides need to cover the intersection of their cells
                        IntRange interCellSide = IntRange.Intersect(startCell.GetSide(dir.ToAxis()), endCell.GetSide(dir.ToAxis()));
                        startDivRange = IntRange.IncludeRange(startDivRange, interCellSide);
                        endDivRange   = IntRange.IncludeRange(endDivRange, interCellSide);
                    }

                    Rect startBox = vertical ? new Rect(startDivRange.Min, start.Y, startDivRange.Length, divPoint - start.Y)
                        : new Rect(start.X, startDivRange.Min, divPoint - start.X, startDivRange.Length);
                    Rect endBox = vertical ? new Rect(endDivRange.Min, divPoint, endDivRange.Length, end.Y - divPoint)
                        : new Rect(divPoint, endDivRange.Min, end.X - divPoint, endDivRange.Length);

                    GridHallPlan originalHall = hallGroup.MainHall;
                    hallGroup.HallParts.Add(new GridHallPlan((IPermissiveRoomGen)originalHall.RoomGen.Copy(), originalHall.Components));
                    hallGroup.HallParts[0].RoomGen.PrepareSize(rand, startBox.Size);
                    hallGroup.HallParts[0].RoomGen.SetLoc(startBox.Start);
                    hallGroup.HallParts[1].RoomGen.PrepareSize(rand, endBox.Size);
                    hallGroup.HallParts[1].RoomGen.SetLoc(endBox.Start);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Draws the hall connecting the first opposite pair of sides.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cross"></param>
        /// <param name="possibleStarts"></param>
        /// <param name="vertical"></param>
        /// <param name="turn"></param>
        private void DrawPrimaryHall(T map, HashSet <int> cross, Dictionary <Dir4, List <HashSet <int> > > possibleStarts, bool vertical, bool turn)
        {
            if (!turn)
            {
                // if not turning, use the cross variables
                this.DrawStraightHall(map, cross, vertical);
            }
            else
            {
                // if turning, use the respective possible starts
                // there is a guarantee that both sides have at least one open bordertile
                Dir4 forwardDir = vertical ? Dir4.Up : Dir4.Left;
                List <HashSet <int> > starts = possibleStarts[forwardDir];
                List <HashSet <int> > ends   = possibleStarts[forwardDir.Reverse()];

                // the chosen tiles to start digging the hall from
                int[] startTiles = new int[starts.Count];
                int[] endTiles   = new int[ends.Count];

                // TODO: when rolling start tiles or end tiles, prefer not to use the edge.
                if (starts.Count == 1 && ends.Count == 1)
                {
                    Choose1on1BentHallStarts(map, starts[0], ends[0], startTiles, endTiles);
                }
                else
                {
                    // simply roll for all starts and ends
                    for (int jj = 0; jj < starts.Count; jj++)
                    {
                        int[] crossArray = new int[starts[jj].Count];
                        starts[jj].CopyTo(crossArray);
                        startTiles[jj] = crossArray[map.Rand.Next(crossArray.Length)];
                    }

                    for (int jj = 0; jj < ends.Count; jj++)
                    {
                        int[] crossArray = new int[ends[jj].Count];
                        ends[jj].CopyTo(crossArray);
                        endTiles[jj] = crossArray[map.Rand.Next(crossArray.Length)];
                    }
                }

                // make the hall turn at a place not close to the edge, if possible
                int forwardTurn;
                if ((vertical ? this.Draw.End.Y - this.Draw.Y : this.Draw.End.X - this.Draw.X) > 2)
                {
                    forwardTurn = map.Rand.Next((vertical ? this.Draw.Y : this.Draw.X) + 1, (vertical ? this.Draw.End.Y : this.Draw.End.X) - 1);
                }
                else // otherwise, just use the full extent
                {
                    forwardTurn = map.Rand.Next(vertical ? this.Draw.Y : this.Draw.X, vertical ? this.Draw.End.Y : this.Draw.End.X);
                }

                // min and max used to determine the range of the turn hall
                int globalMin = startTiles[0];
                int globalMax = startTiles[0];

                for (int ii = 0; ii < startTiles.Length; ii++)
                {
                    globalMin = Math.Min(globalMin, startTiles[ii]);
                    globalMax = Math.Max(globalMax, startTiles[ii]);
                    Loc startLoc = new Loc(vertical ? startTiles[ii] : this.Draw.X, vertical ? this.Draw.Y : startTiles[ii]);
                    Loc endLoc   = new Loc(vertical ? startTiles[ii] : forwardTurn, vertical ? forwardTurn : startTiles[ii]);
                    this.DrawHall(map, startLoc, endLoc, vertical);
                }

                for (int ii = 0; ii < endTiles.Length; ii++)
                {
                    globalMin = Math.Min(globalMin, endTiles[ii]);
                    globalMax = Math.Max(globalMax, endTiles[ii]);
                    Loc startLoc = new Loc(vertical ? endTiles[ii] : this.Draw.End.X - 1, vertical ? this.Draw.End.Y - 1 : endTiles[ii]);
                    Loc endLoc   = new Loc(vertical ? endTiles[ii] : forwardTurn, vertical ? forwardTurn : endTiles[ii]);
                    this.DrawHall(map, startLoc, endLoc, vertical);
                }

                Loc startMid = new Loc(vertical ? globalMin : forwardTurn, vertical ? forwardTurn : globalMin);
                Loc endMid   = new Loc(vertical ? globalMax : forwardTurn, vertical ? forwardTurn : globalMax);
                this.DrawHall(map, startMid, endMid, !vertical);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// In a 4- or 3-way hall situation, this method is called to add the remaining ways after the first two have been added.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cross"></param>
        /// <param name="possibleStarts"></param>
        /// <param name="vertical"></param>
        /// <param name="turn"></param>
        private void DrawSecondaryHall(T map, HashSet <int> cross, Dictionary <Dir4, List <HashSet <int> > > possibleStarts, bool vertical, bool turn)
        {
            if (!turn)
            {
                // if not turning, use the cross variables
                this.DrawStraightHall(map, cross, vertical);
            }
            else
            {
                Dir4 forwardDir = vertical ? Dir4.Up : Dir4.Left;
                List <HashSet <int> > starts = possibleStarts[forwardDir];
                List <HashSet <int> > ends   = possibleStarts[forwardDir.Reverse()];

                // the chosen tiles to start digging the hall from
                int[] startTiles = new int[starts.Count];
                int[] endTiles   = new int[ends.Count];

                if (starts.Count == 1 && ends.Count == 1)
                {
                    Choose1on1BentHallStarts(map, starts[0], ends[0], startTiles, endTiles);

                    // forward until hit
                    {
                        Loc forwardStart = this.Draw.Start;
                        Loc startLoc     = new Loc(vertical ? startTiles[0] : forwardStart.X, vertical ? forwardStart.Y : startTiles[0]);
                        Loc endLoc       = startLoc;

                        // the assumption is that there is already roomterrain to cross over at another point in this room
                        while (!map.GetTile(endLoc).TileEquivalent(map.RoomTerrain))
                        {
                            endLoc += forwardDir.Reverse().GetLoc();
                        }
                        this.DrawHall(map, startLoc, endLoc, vertical);
                    }

                    // backward until hit
                    {
                        Loc backwardStart = this.Draw.End - new Loc(1);
                        Loc startLoc      = new Loc(vertical ? endTiles[0] : backwardStart.X, vertical ? backwardStart.Y : endTiles[0]);
                        Loc endLoc        = startLoc;

                        // the assumption is that there is already roomterrain to cross over at another point in this room
                        while (!map.GetTile(endLoc).TileEquivalent(map.RoomTerrain))
                        {
                            endLoc += forwardDir.GetLoc();
                        }
                        this.DrawHall(map, startLoc, endLoc, vertical);
                    }
                }
                else
                {
                    // if turning, use the respective possible starts and draw until the primary lines are hit
                    foreach (Dir4 dir in DirExt.VALID_DIR4)
                    {
                        // choose vertical starts if vertical, horiz starts if otherwise
                        if ((dir.ToAxis() == Axis4.Vert) == vertical)
                        {
                            for (int jj = 0; jj < possibleStarts[dir].Count; jj++)
                            {
                                int[] crossArray = new int[possibleStarts[dir][jj].Count];
                                possibleStarts[dir][jj].CopyTo(crossArray);
                                int startSideDist = crossArray[map.Rand.Next(crossArray.Length)];
                                Loc forwardStart  = (dir == Dir4.Up || dir == Dir4.Left) ? this.Draw.Start : this.Draw.End - new Loc(1);
                                Loc startLoc      = new Loc(vertical ? startSideDist : forwardStart.X, vertical ? forwardStart.Y : startSideDist);
                                Loc endLoc        = startLoc;

                                // the assumption is that there is already roomterrain to cross over at another point in this room
                                while (!map.GetTile(endLoc).TileEquivalent(map.RoomTerrain))
                                {
                                    endLoc += dir.Reverse().GetLoc();
                                }

                                this.DrawHall(map, startLoc, endLoc, vertical);
                            }
                        }
                    }

                    // there is no guarantee that both sides will have an open bordertile; they'll just come in from their respective directions
                }
            }
        }
Esempio n. 9
0
        protected static ListPathTraversalNode?GetRoomToConnect(FloorPlan floorPlan, RoomHallIndex chosenFrom, Dir4 dir)
        {
            // extend a rectangle to the border of the floor in the chosen direction
            bool     vertical   = dir.ToAxis() == Axis4.Vert;
            int      dirSign    = dir.GetLoc().GetScalar(dir.ToAxis());
            IRoomGen genFrom    = floorPlan.GetRoomHall(chosenFrom).RoomGen;
            Rect     sampleRect = genFrom.Draw;

            // expand from the start of that border direction to the borders of the floor
            sampleRect.Start += dir.GetLoc() * sampleRect.Size.GetScalar(dir.ToAxis());

            // it doesn't have to be exactly the borders so just add the total size to be sure
            sampleRect.Expand(dir, vertical ? floorPlan.Size.Y : floorPlan.Size.X);

            // find the closest room.
            var chosenTo = new RoomHallIndex(-1, false);

            foreach (RoomHallIndex collision in floorPlan.CheckCollision(sampleRect))
            {
                Rect collidedRect = floorPlan.GetRoomHall(collision).RoomGen.Draw;

                // limit the expansion by direction
                int  sampleScalar   = sampleRect.GetScalar(dir);
                int  collidedScalar = collidedRect.GetScalar(dir.Reverse());
                bool limit          = dirSign == Math.Sign(sampleScalar - collidedScalar);
                if (limit)
                {
                    // update the boundaries
                    sampleRect.SetScalar(dir, collidedScalar);
                    chosenTo = collision;
                }
            }

            // if it didn't collide with ANYTHING, then quit
            if (chosenTo.Index == -1)
            {
                return(null);
            }

            IRoomGen genTo = floorPlan.GetRoomHall(chosenTo).RoomGen;

            // narrow the rectangle if touching something on the side
            // widen the rectangle by width
            Rect widthRect = sampleRect;

            widthRect.Inflate(vertical ? 1 : 0, vertical ? 0 : 1);
            bool retractLeft  = false;
            bool retractRight = false;
            Dir4 leftDir      = DirExt.AddAngles(dir, Dir4.Left);
            Dir4 rightDir     = DirExt.AddAngles(dir, Dir4.Right);

            foreach (RoomHallIndex collision in floorPlan.CheckCollision(widthRect))
            {
                Rect collidedRect = floorPlan.GetRoomHall(collision).RoomGen.Draw;
                if (!retractLeft)
                {
                    if (collidedRect.GetScalar(leftDir.Reverse()) == sampleRect.GetScalar(leftDir))
                    {
                        retractLeft = true;
                    }
                }

                if (!retractRight)
                {
                    if (collidedRect.GetScalar(rightDir.Reverse()) == sampleRect.GetScalar(rightDir))
                    {
                        retractRight = true;
                    }
                }
            }

            // retract the rectangle
            if (retractLeft)
            {
                sampleRect.Expand(leftDir, -1);
            }
            if (retractRight)
            {
                sampleRect.Expand(rightDir, -1);
            }

            // if the rectangle has been retracted too much, we can't go on
            if (sampleRect.Area <= 0)
            {
                return(null);
            }

            // check for border availability between start and end
            bool foundFrom = HasBorderOpening(genFrom, sampleRect, dir);
            bool foundTo   = HasBorderOpening(genTo, sampleRect, dir.Reverse());

            // return the expansion if one is found
            if (foundFrom && foundTo)
            {
                return(new ListPathTraversalNode(chosenFrom, chosenTo, sampleRect));
            }
            else
            {
                return(null);
            }
        }