private bool InvestigateDoor(RoomDef room, DoorPlaceholder cameFrom)
        {
            if (room is LibraryConnectionRoom && room != this)
            {
                return(true);
            }

            foreach (var door in room.Connected)
            {
                if (door.Value != cameFrom)
                {
                    return(InvestigateDoor(door.Key, door.Value));
                }
            }

            return(false);
        }
示例#2
0
        public void PaintTunnel(Level Level, Tile Floor, Rect space = null, bool Bold = false, bool shift = true, bool randomRect = true, RoomDef defTo = null, DoorPlaceholder to = null)
        {
            if (Connected.Count == 0)
            {
                Log.Error("Invalid connection room");

                return;
            }

            var C         = space ?? GetConnectionSpace();
            var minLeft   = C.Left;
            var maxRight  = C.Right;
            var minTop    = C.Top;
            var maxBottom = C.Bottom;

            var doors = to == null
                                ? Connected
                                : new Dictionary <RoomDef, DoorPlaceholder>()
            {
                { defTo, to }
            };

            foreach (var pair in doors)
            {
                if (pair.Key is GrannyRoom || pair.Key is OldManRoom)
                {
                    continue;
                }

                var Door  = pair.Value;
                var Start = new Dot(Door.X, Door.Y);
                Dot Mid;
                Dot End;

                if (shift)
                {
                    if ((int)Start.X == Left)
                    {
                        Start.X++;
                    }
                    else if ((int)Start.Y == Top)
                    {
                        Start.Y++;
                    }
                    else if ((int)Start.X == Right)
                    {
                        Start.X--;
                    }
                    else if ((int)Start.Y == Bottom)
                    {
                        Start.Y--;
                    }
                }

                int RightShift;
                int DownShift;

                if (Start.X < C.Left)
                {
                    RightShift = (int)(C.Left - Start.X);
                }
                else if (Start.X > C.Right)
                {
                    RightShift = (int)(C.Right - Start.X);
                }
                else
                {
                    RightShift = 0;
                }

                if (Start.Y < C.Top)
                {
                    DownShift = (int)(C.Top - Start.Y);
                }
                else if (Start.Y > C.Bottom)
                {
                    DownShift = (int)(C.Bottom - Start.Y);
                }
                else
                {
                    DownShift = 0;
                }

                if (Door.X == Left || Door.X == Right)
                {
                    Mid = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Start.X + RightShift), MathUtils.Clamp(Top + 1, Bottom - 1, Start.Y));
                    End = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Mid.X), MathUtils.Clamp(Top + 1, Bottom - 1, Mid.Y + DownShift));
                }
                else
                {
                    Mid = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Start.X), MathUtils.Clamp(Top + 1, Bottom - 1, Start.Y + DownShift));
                    End = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Mid.X + RightShift), MathUtils.Clamp(Top + 1, Bottom - 1, Mid.Y));
                }

                Painter.DrawLine(Level, Start, Mid, Floor, Bold);
                Painter.DrawLine(Level, Mid, End, Floor, Bold);

                if (Rnd.Chance(10))
                {
                    Painter.Set(Level, End, Tiles.RandomFloor());
                }

                minLeft   = Math.Min(minLeft, End.X);
                minTop    = Math.Min(minTop, End.Y);
                maxRight  = Math.Max(maxRight, End.X);
                maxBottom = Math.Max(maxBottom, End.Y);
            }

            if (randomRect && Rnd.Chance(20))
            {
                if (Rnd.Chance())
                {
                    minLeft--;
                }

                if (Rnd.Chance())
                {
                    minTop--;
                }

                if (Rnd.Chance())
                {
                    maxRight++;
                }

                if (Rnd.Chance())
                {
                    maxBottom++;
                }
            }

            minLeft   = MathUtils.Clamp(Left + 1, Right - 1, minLeft);
            minTop    = MathUtils.Clamp(Top + 1, Bottom - 1, minTop);
            maxRight  = MathUtils.Clamp(Left + 1, Right - 1, maxRight);
            maxBottom = MathUtils.Clamp(Top + 1, Bottom - 1, maxBottom);

            if (Rnd.Chance())
            {
                Painter.Fill(Level, minLeft, minTop, maxRight - minLeft + 1, maxBottom - minTop + 1, Rnd.Chance() ? Floor : Tiles.RandomFloorOrSpike());
            }
            else
            {
                Painter.Rect(Level, minLeft, minTop, maxRight - minLeft + 1, maxBottom - minTop + 1, Rnd.Chance() ? Floor : Tiles.RandomFloorOrSpike());
            }
        }