Пример #1
0
        public void AddHall(IPermissiveRoomGen gen, ComponentCollection components, params RoomHallIndex[] attached)
        {
            // we expect that the hall has already been given a size...
            // check against colliding on other rooms (and not halls)
            foreach (var room in this.Rooms)
            {
                if (Collision.Collides(room.RoomGen.Draw, gen.Draw))
                {
                    throw new InvalidOperationException("Tried to add on top of an existing room!");
                }
            }

            // check against rooms that go out of bounds
            if (!this.DrawRect.Contains(gen.Draw))
            {
                throw new InvalidOperationException("Tried to add out of range!");
            }
            var plan = new FloorHallPlan(gen, components);

            // attach everything
            plan.Adjacents.AddRange(attached);
            foreach (RoomHallIndex fromRoom in attached)
            {
                IFloorRoomPlan fromPlan = this.GetRoomHall(fromRoom);
                fromPlan.Adjacents.Add(new RoomHallIndex(this.Halls.Count, true));
            }

            this.Halls.Add(plan);
        }
Пример #2
0
 public void SetGen(IPermissiveRoomGen roomGen)
 {
     this.Gens = new List <IPermissiveRoomGen>();
     if (roomGen != null)
     {
         this.Gens.Add(roomGen);
     }
 }
Пример #3
0
 public static void UnsafeAddHall(LocRay4 locRay, GridPlan floorPlan, IPermissiveRoomGen hallGen, ComponentCollection components)
 {
     floorPlan.SetHall(locRay, hallGen, components.Clone());
     GenContextDebug.DebugProgress("Hall");
     if (floorPlan.GetRoomPlan(locRay.Loc) == null || floorPlan.GetRoomPlan(locRay.Traverse(1)) == null)
     {
         floorPlan.Clear();
         throw new InvalidOperationException("Can't create a hall without rooms to connect!");
     }
 }
Пример #4
0
        /// <summary>
        /// Sets the RoomGen found in the specified hall.
        /// </summary>
        /// <param name="locRay">The location of the room + the direction of the connecting hall relative to the room.</param>
        /// <param name="hallGen"></param>
        /// <param name="components">components to include in the hall</param>
        public void SetHall(LocRay4 locRay, IPermissiveRoomGen hallGen, ComponentCollection components)
        {
            if (locRay.Dir == Dir4.None)
            {
                throw new ArgumentException("Invalid direction.");
            }
            else if (!locRay.Dir.Validate())
            {
                throw new ArgumentOutOfRangeException("Invalid enum value.");
            }

            GridHallPlan plan = null;

            if (hallGen != null)
            {
                plan = new GridHallPlan((IPermissiveRoomGen)hallGen.Copy(), components);
            }

            switch (locRay.Dir)
            {
            case Dir4.Down:
                if (locRay.Loc.Y < this.GridHeight - 1)
                {
                    this.VHalls[locRay.Loc.X][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.Left:
                if (locRay.Loc.X > 0)
                {
                    this.HHalls[locRay.Loc.X - 1][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.Up:
                if (locRay.Loc.Y > 0)
                {
                    this.VHalls[locRay.Loc.X][locRay.Loc.Y - 1].SetHall(plan);
                }
                break;

            case Dir4.Right:
                if (locRay.Loc.X < this.GridWidth - 1)
                {
                    this.HHalls[locRay.Loc.X][locRay.Loc.Y].SetHall(plan);
                }
                break;

            case Dir4.None:
                throw new ArgumentException($"No hall for dir {nameof(Dir4.None)}");

            default:
                throw new ArgumentOutOfRangeException(nameof(locRay.Dir), "Invalid enum value.");
            }
        }
Пример #5
0
        public int GetRoomNum(LocRay4 locRay)
        {
            IPermissiveRoomGen hall = this.GetHall(locRay);

            if (hall != null)
            {
                Loc moveLoc = locRay.Traverse(1);
                return(this.Rooms[moveLoc.X][moveLoc.Y]);
            }

            return(-1);
        }
Пример #6
0
        public static void SafeAddHall(LocRay4 locRay, GridPlan floorPlan, IPermissiveRoomGen hallGen, IRoomGen roomGen, bool preferHall = false)
        {
            floorPlan.SetHall(locRay, hallGen);
            if (floorPlan.GetRoomPlan(locRay.Loc) == null)
            {
                floorPlan.AddRoom(locRay.Loc, roomGen, false, preferHall);
            }
            Loc dest = locRay.Traverse(1);

            if (floorPlan.GetRoomPlan(dest) == null)
            {
                floorPlan.AddRoom(dest, roomGen, false, preferHall);
            }
        }
Пример #7
0
        public static void SafeAddHall(LocRay4 locRay, GridPlan floorPlan, IPermissiveRoomGen hallGen, IRoomGen roomGen, ComponentCollection roomComponents, ComponentCollection hallComponents, bool preferHall = false)
        {
            floorPlan.SetHall(locRay, hallGen, hallComponents.Clone());
            ComponentCollection collection = preferHall ? hallComponents : roomComponents;

            if (floorPlan.GetRoomPlan(locRay.Loc) == null)
            {
                floorPlan.AddRoom(locRay.Loc, roomGen, collection.Clone(), preferHall);
            }
            Loc dest = locRay.Traverse(1);

            if (floorPlan.GetRoomPlan(dest) == null)
            {
                floorPlan.AddRoom(dest, roomGen, collection.Clone(), preferHall);
            }
        }
Пример #8
0
 public FloorHallPlan(IPermissiveRoomGen roomGen, ComponentCollection components)
 {
     this.RoomGen    = roomGen;
     this.Components = components;
     this.Adjacents  = new List <RoomHallIndex>();
 }
Пример #9
0
 public ListPathBranchExpansion(RoomHallIndex from, IRoomGen room, IPermissiveRoomGen hall)
 {
     this.From = from;
     this.Room = room;
     this.Hall = hall;
 }
Пример #10
0
 public GridHallPlan(IPermissiveRoomGen roomGen, ComponentCollection components)
 {
     this.RoomGen    = roomGen;
     this.Components = components;
 }
Пример #11
0
        public static ConsoleKey PrintGridRoomHalls(IGenContext map, string msg, bool printDebug, bool printViewer)
        {
            if (!(map is IRoomGridGenContext context))
            {
                return(ConsoleKey.Enter);
            }

            var      str  = new StringBuilder();
            GridPlan plan = context.GridPlan;

            if (plan == null)
            {
                return(ConsoleKey.Enter);
            }

            for (int yy = 0; yy < plan.GridHeight; yy++)
            {
                if (yy > 0)
                {
                    str.Append('\n');
                }

                for (int xx = 0; xx < plan.GridWidth; xx++)
                {
                    int roomIndex = plan.GetRoomIndex(new Loc(xx, yy));
                    if (roomIndex == -1)
                    {
                        str.Append('0');
                    }
                    else // if (roomIndex < 26)
                    {
                        str.Append((char)('A' + (roomIndex % 26)));
                    }

                    /* else
                     *     str.Append('@');
                     */

                    if (xx < plan.GridWidth - 1)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Right)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }
                    }
                }

                if (yy < plan.GridHeight - 1)
                {
                    str.Append('\n');
                    for (int xx = 0; xx < plan.GridWidth; xx++)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Down)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }

                        if (xx < plan.GridWidth - 1)
                        {
                            str.Append(' ');
                        }
                    }
                }
            }

            string newStr = str.ToString();

            if (gridDebugString[currentDepth].MapString == newStr)
            {
                return(ConsoleKey.Enter);
            }

            gridDebugString[currentDepth].MapString = newStr;

            if (printDebug)
            {
                Debug.WriteLine(msg);
                Debug.Print(newStr);
            }

            if (printViewer)
            {
                SteppingIn = false;
                Console.Clear();
                Console.WriteLine(msg);
                Loc start = new Loc(Console.CursorLeft, Console.CursorTop);
                Console.Write(newStr);
                Loc end = new Loc(Console.CursorLeft, Console.CursorTop + 1);
                Console.SetCursorPosition(start.X, start.Y);
                int prevFarthestPrint = end.Y;

                while (true)
                {
                    int farthestPrint = end.Y;
                    Loc gridLoc       = new Loc(Console.CursorLeft, Console.CursorTop) - start;
                    Loc mapLoc        = gridLoc / 2;
                    RewriteLine(farthestPrint, $"X:{gridLoc.X / 2f:0.0}  Y:{gridLoc.Y / 2f:0.0}");
                    farthestPrint++;

                    bool alignX = gridLoc.X % 2 == 0;
                    bool alignY = gridLoc.Y % 2 == 0;

                    if (alignX && alignY)
                    {
                        int          index    = plan.GetRoomIndex(mapLoc);
                        GridRoomPlan roomPlan = plan.GetRoomPlan(mapLoc);
                        if (roomPlan != null)
                        {
                            string roomString = $"Room #{index}: {roomPlan.RoomGen}";
                            if (roomPlan.Immutable)
                            {
                                roomString += " [Immutable]";
                            }
                            if (roomPlan.PreferHall)
                            {
                                roomString += " [Hall]";
                            }
                            RewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                        }
                    }
                    else if (alignX)
                    {
                        IPermissiveRoomGen hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Down));
                        if (hall != null)
                        {
                            RewriteLine(farthestPrint, "Hall: " + hall);
                            farthestPrint++;
                        }
                    }
                    else if (alignY)
                    {
                        IPermissiveRoomGen hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Right));
                        if (hall != null)
                        {
                            RewriteLine(farthestPrint, "Hall: " + hall);
                            farthestPrint++;
                        }
                    }

                    for (int ii = farthestPrint; ii < prevFarthestPrint; ii++)
                    {
                        ClearLine(ii);
                    }
                    prevFarthestPrint = farthestPrint;
                    Console.SetCursorPosition(start.X + gridLoc.X, start.Y + gridLoc.Y);

                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Max(start.Y, Console.CursorTop - 1));
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Min(Console.CursorTop + 1, end.Y - 1));
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        Console.SetCursorPosition(Math.Max(start.X, Console.CursorLeft - 1), Console.CursorTop);
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        Console.SetCursorPosition(Math.Min(Console.CursorLeft + 1, end.X - 1), Console.CursorTop);
                    }
                    else
                    {
                        return(key.Key);
                    }
                }
            }
            else
            {
                return(ConsoleKey.Enter);
            }
        }
Пример #12
0
        public static ConsoleKey PrintListRoomHalls(IGenContext map, string msg, bool printDebug, bool printViewer)
        {
            if (!(map is IFloorPlanGenContext context))
            {
                return(ConsoleKey.Enter);
            }

            var       str  = new StringBuilder();
            FloorPlan plan = context.RoomPlan;

            if (plan == null)
            {
                return(ConsoleKey.Enter);
            }

            for (int yy = 0; yy < plan.DrawRect.Bottom; yy++)
            {
                for (int xx = 0; xx < plan.DrawRect.Right; xx++)
                {
                    str.Append(' ');
                }
            }

            for (int ii = 0; ii < plan.RoomCount; ii++)
            {
                char     chosenChar = (char)('A' + (ii % 26));
                IRoomGen gen        = plan.GetRoom(ii);
                for (int xx = gen.Draw.Left; xx < gen.Draw.Right; xx++)
                {
                    for (int yy = gen.Draw.Top; yy < gen.Draw.Bottom; yy++)
                    {
                        int index = (yy * plan.DrawRect.Right) + xx;

                        if (str[index] == ' ')
                        {
                            str[index] = chosenChar;
                        }
                        else
                        {
                            str[index] = '!';
                        }
                    }
                }
            }

            for (int ii = 0; ii < plan.HallCount; ii++)
            {
                char chosenChar = (char)('a' + (ii % 26));

                IRoomGen gen = plan.GetHall(ii);

                for (int xx = gen.Draw.Left; xx < gen.Draw.Right; xx++)
                {
                    for (int yy = gen.Draw.Top; yy < gen.Draw.Bottom; yy++)
                    {
                        int index = (yy * plan.DrawRect.Right) + xx;

                        if (str[index] == ' ')
                        {
                            str[index] = chosenChar;
                        }
                        else if ((str[index] >= 'a' && str[index] <= 'z') || str[index] == '#')
                        {
                            str[index] = '+';
                        }
                        else
                        {
                            str[index] = '!';
                        }
                    }
                }
            }

            for (int yy = plan.DrawRect.Bottom - 1; yy > 0; yy--)
            {
                str.Insert(plan.DrawRect.Right * yy, '\n');
            }

            string newStr = str.ToString();

            if (listDebugString[currentDepth].MapString == newStr)
            {
                return(ConsoleKey.Enter);
            }

            listDebugString[currentDepth].MapString = newStr;

            if (printDebug)
            {
                Debug.WriteLine(msg);
                Debug.Print(newStr);
            }

            if (printViewer)
            {
                SteppingIn = false;
                Console.Clear();
                Console.WriteLine(msg);
                Loc start = new Loc(Console.CursorLeft, Console.CursorTop);
                Console.Write(newStr);
                Loc end = new Loc(Console.CursorLeft, Console.CursorTop + 1);
                Console.SetCursorPosition(start.X, start.Y);
                int prevFarthestPrint = end.Y;

                while (true)
                {
                    int farthestPrint = end.Y;
                    Loc mapLoc        = new Loc(Console.CursorLeft, Console.CursorTop) - start;
                    RewriteLine(farthestPrint, $"X:{mapLoc.X:D3}  Y:{mapLoc.Y:D3}");
                    farthestPrint++;

                    for (int ii = 0; ii < plan.RoomCount; ii++)
                    {
                        FloorRoomPlan roomPlan = plan.GetRoomPlan(ii);
                        if (roomPlan.RoomGen.Draw.Contains(mapLoc))
                        {
                            // stats
                            string roomString = $"Room #{ii}: {roomPlan.RoomGen.Draw.X}x{roomPlan.RoomGen.Draw.Y} {roomPlan.RoomGen}";
                            if (roomPlan.Immutable)
                            {
                                roomString += " [Immutable]";
                            }
                            RewriteLine(farthestPrint, roomString);
                            farthestPrint++;

                            // borders
                            var lineString = new StringBuilder(" ");
                            for (int xx = 0; xx < roomPlan.RoomGen.Draw.Width; xx++)
                            {
                                lineString.Append(roomPlan.RoomGen.GetFulfillableBorder(Dir4.Up, xx) ? "^" : " ");
                            }
                            RewriteLine(farthestPrint, lineString.ToString());
                            farthestPrint++;
                            for (int yy = 0; yy < roomPlan.RoomGen.Draw.Height; yy++)
                            {
                                lineString = new StringBuilder(roomPlan.RoomGen.GetFulfillableBorder(Dir4.Left, yy) ? "<" : " ");
                                for (int xx = 0; xx < roomPlan.RoomGen.Draw.Width; xx++)
                                {
                                    lineString.Append("#");
                                }
                                lineString.Append(roomPlan.RoomGen.GetFulfillableBorder(Dir4.Right, yy) ? ">" : " ");
                                RewriteLine(farthestPrint, lineString.ToString());
                                farthestPrint++;
                            }

                            lineString = new StringBuilder(" ");
                            for (int xx = 0; xx < roomPlan.RoomGen.Draw.Width; xx++)
                            {
                                lineString.Append(roomPlan.RoomGen.GetFulfillableBorder(Dir4.Down, xx) ? "V" : " ");
                            }
                            RewriteLine(farthestPrint, lineString.ToString());
                            farthestPrint++;
                        }
                    }

                    for (int ii = 0; ii < plan.HallCount; ii++)
                    {
                        IPermissiveRoomGen gen = plan.GetHall(ii);
                        if (gen.Draw.Contains(mapLoc))
                        {
                            string roomString = $"Hall #{ii}: {gen.Draw.X}x{gen.Draw.Y} {gen}";
                            RewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                        }
                    }

                    for (int ii = farthestPrint; ii < prevFarthestPrint; ii++)
                    {
                        ClearLine(ii);
                    }
                    prevFarthestPrint = farthestPrint;
                    Console.SetCursorPosition(start.X + mapLoc.X, start.Y + mapLoc.Y);

                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Max(start.Y, Console.CursorTop - 1));
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Min(Console.CursorTop + 1, end.Y - 1));
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        Console.SetCursorPosition(Math.Max(start.X, Console.CursorLeft - 1), Console.CursorTop);
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        Console.SetCursorPosition(Math.Min(Console.CursorLeft + 1, end.X - 1), Console.CursorTop);
                    }
                    else
                    {
                        return(key.Key);
                    }
                }
            }
            else
            {
                return(ConsoleKey.Enter);
            }
        }
Пример #13
0
 public FloorHallPlan(IPermissiveRoomGen roomGen)
 {
     this.RoomGen   = roomGen;
     this.Adjacents = new List <RoomHallIndex>();
 }