예제 #1
0
        protected static bool HasBorderOpening(IRoomGen roomFrom, Rect rectTo, Dir4 expandTo)
        {
            Loc diff   = roomFrom.Draw.Start - rectTo.Start; // 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   = rectTo.Size.GetScalar(expandTo.ToAxis().Orth());

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

            return(false);
        }
예제 #2
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);
        }
예제 #3
0
        public override void ApplyToPath(IRandom rand, GridPlan floorPlan)
        {
            // open rooms on both sides
            Loc gridSize = new Loc(floorPlan.GridWidth, floorPlan.GridHeight);
            int scalar   = gridSize.GetScalar(this.GapAxis);
            int orth     = gridSize.GetScalar(this.GapAxis.Orth());

            if (scalar < 2 || orth < 1)
            {
                throw new InvalidOperationException("Not enough room to create path.");
            }

            GenContextDebug.StepIn("Initial Rooms");

            for (int ii = 0; ii < orth; ii++)
            {
                // place the rooms at the edge
                floorPlan.AddRoom(this.GapAxis.CreateLoc(0, ii), this.GenericRooms.Pick(rand), this.RoomComponents.Clone());
                GenContextDebug.DebugProgress("Room");
                floorPlan.AddRoom(this.GapAxis.CreateLoc(scalar - 1, ii), this.GenericRooms.Pick(rand), this.RoomComponents.Clone());
                GenContextDebug.DebugProgress("Room");

                if (scalar > 2)
                {
                    // place hall rooms
                    Loc loc  = this.GapAxis.CreateLoc(1, ii);
                    Loc size = this.GapAxis.CreateLoc(scalar - 2, 1);
                    floorPlan.AddRoom(new Rect(loc, size), this.GetDefaultGen(), this.HallComponents.Clone(), true);
                    GenContextDebug.DebugProgress("Mid Room");
                }
            }

            GenContextDebug.StepOut();

            GenContextDebug.StepIn("Connecting Sides");

            // halls connecting two tiers of the same side
            bool[][] connections = new bool[orth - 1][];
            for (int ii = 0; ii < orth - 1; ii++)
            {
                connections[ii] = new bool[2];
            }

            // add crosses
            for (int ii = 0; ii < orth - 1; ii++)
            {
                if (rand.Next(2) == 0)
                {
                    connections[ii][0] = true;
                }
                else
                {
                    connections[ii][1] = true;
                }
            }

            // paint hallways
            for (int ii = 0; ii < orth; ii++)
            {
                // place the halls at the sides
                if (ii < orth - 1)
                {
                    if (connections[ii][0])
                    {
                        this.PlaceOrientedHall(this.GapAxis.Orth(), 0, ii, 1, floorPlan, this.GenericHalls.Pick(rand));
                        GenContextDebug.DebugProgress("Side Connection");
                    }

                    if (connections[ii][1])
                    {
                        this.PlaceOrientedHall(this.GapAxis.Orth(), scalar - 1, ii, 1, floorPlan, this.GenericHalls.Pick(rand));
                        GenContextDebug.DebugProgress("Side Connection");
                    }
                }

                // place halls to bridge the gap
                this.PlaceOrientedHall(this.GapAxis, 0, ii, 1, floorPlan, this.GenericHalls.Pick(rand));
                if (scalar > 2)
                {
                    this.PlaceOrientedHall(this.GapAxis, scalar - 1, ii, -1, floorPlan, this.GenericHalls.Pick(rand));
                }
                GenContextDebug.DebugProgress("Bridge");
            }

            GenContextDebug.StepOut();
        }