Example #1
0
        bool GenerateSpecialInternal(Room prev, int depth, int targetDepth)
        {
            var connPtNum = GetMaxConnectionPoints(prev);
            var seq       = Enumerable.Range(0, connPtNum).ToList();

            _rand.Shuffle(seq);

            bool specialPlaced;

            do
            {
                Room rm;
                if (targetDepth == depth)
                {
                    rm = _template.CreateSpecial(depth, prev);
                }
                else
                {
                    rm = _template.CreateNormal(depth, prev);
                }

                Link?link = null;
                foreach (var connPt in seq)
                {
                    if ((link = PlaceRoom(prev, rm, connPt)) != null)
                    {
                        seq.Remove(connPt);
                        break;
                    }
                }

                if (link == null)
                {
                    return(false);
                }

                if (targetDepth == depth)
                {
                    specialPlaced = true;
                }
                else
                {
                    specialPlaced = GenerateSpecialInternal(rm, depth + 1, targetDepth);
                }

                if (specialPlaced)
                {
                    rm.Depth = depth;
                    Edge.Link(prev, rm, link.Value);
                    _rooms.Add(rm);
                }
                else
                {
                    _collision.Remove(rm);
                }
            } while (!specialPlaced);
            return(true);
        }