Beispiel #1
0
        /// <summary>
        /// Generates the position and size of each room and hall, and places it in the specified IFloorPlanGenContext.
        /// </summary>
        /// <param name="map"></param>
        public void PlaceRoomsOnFloor(IFloorPlanGenContext map)
        {
            // decide on room sizes
            for (int ii = 0; ii < this.ArrayRooms.Count; ii++)
            {
                this.ChooseRoomBounds(map.Rand, ii);
            }

            // decide on halls; write to RoomSideReqs
            for (int xx = 0; xx < this.VHalls.Length; xx++)
            {
                for (int yy = 0; yy < this.VHalls[xx].Length; yy++)
                {
                    this.ChooseHallBounds(map.Rand, xx, yy, true);
                }
            }

            for (int xx = 0; xx < this.HHalls.Length; xx++)
            {
                for (int yy = 0; yy < this.HHalls[xx].Length; yy++)
                {
                    this.ChooseHallBounds(map.Rand, xx, yy, false);
                }
            }

            GenContextDebug.StepIn("Main Rooms");

            List <RoomHallIndex> roomToHall = new List <RoomHallIndex>();

            foreach (var plan in this.ArrayRooms)
            {
                if (plan.PreferHall)
                {
                    roomToHall.Add(new RoomHallIndex(map.RoomPlan.HallCount, true));
                    map.RoomPlan.AddHall((IPermissiveRoomGen)plan.RoomGen, plan.Components);
                    GenContextDebug.DebugProgress("Add Hall Room");
                }
                else
                {
                    roomToHall.Add(new RoomHallIndex(map.RoomPlan.RoomCount, false));
                    map.RoomPlan.AddRoom(plan.RoomGen, plan.Components);
                    GenContextDebug.DebugProgress("Added Room");
                }
            }

            GenContextDebug.StepOut();

            GenContextDebug.StepIn("Connecting Halls");

            for (int xx = 0; xx < this.VHalls.Length; xx++)
            {
                for (int yy = 0; yy < this.VHalls[xx].Length; yy++)
                {
                    GridHallGroup hallGroup = this.VHalls[xx][yy];
                    for (int ii = 0; ii < hallGroup.HallParts.Count; ii++)
                    {
                        List <RoomHallIndex> adj = new List <RoomHallIndex>();
                        if (ii == 0)
                        {
                            int upRoom = this.Rooms[xx][yy];
                            if (upRoom > -1)
                            {
                                adj.Add(roomToHall[upRoom]);
                            }
                        }
                        else
                        {
                            adj.Add(new RoomHallIndex(map.RoomPlan.HallCount - 1, true));
                        }

                        if (ii == hallGroup.HallParts.Count - 1)
                        {
                            int downRoom = this.Rooms[xx][yy + 1];
                            if (downRoom > -1)
                            {
                                adj.Add(roomToHall[downRoom]);
                            }
                        }

                        map.RoomPlan.AddHall(hallGroup.HallParts[ii].RoomGen, hallGroup.HallParts[ii].Components, adj.ToArray());
                        GenContextDebug.DebugProgress("Add Hall");
                    }
                }
            }

            for (int xx = 0; xx < this.HHalls.Length; xx++)
            {
                for (int yy = 0; yy < this.HHalls[xx].Length; yy++)
                {
                    GridHallGroup hallGroup = this.HHalls[xx][yy];

                    for (int ii = 0; ii < hallGroup.HallParts.Count; ii++)
                    {
                        List <RoomHallIndex> adj = new List <RoomHallIndex>();
                        if (ii == 0)
                        {
                            int leftRoom = this.Rooms[xx][yy];
                            if (leftRoom > -1)
                            {
                                adj.Add(roomToHall[leftRoom]);
                            }
                        }
                        else
                        {
                            adj.Add(new RoomHallIndex(map.RoomPlan.HallCount - 1, true));
                        }

                        if (ii == hallGroup.HallParts.Count - 1)
                        {
                            int rightRoom = this.Rooms[xx + 1][yy];
                            if (rightRoom > -1)
                            {
                                adj.Add(roomToHall[rightRoom]);
                            }
                        }

                        map.RoomPlan.AddHall(hallGroup.HallParts[ii].RoomGen, hallGroup.HallParts[ii].Components, adj.ToArray());
                        GenContextDebug.DebugProgress("Add Hall");
                    }
                }
            }

            GenContextDebug.StepOut();
        }
Beispiel #2
0
        public static ConsoleKey PrintListRoomHalls(IGenContext map, string msg, bool printDebug, bool printViewer)
        {
            IFloorPlanGenContext context = map as IFloorPlanGenContext;

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

            StringBuilder 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 = '@';
                //if (ii < 26)
                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 = '#';
                //if (ii < 26)
                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, String.Format("X:{0}  Y:{1}", mapLoc.X.ToString("D3"), mapLoc.Y.ToString("D3")));
                    farthestPrint++;

                    for (int ii = 0; ii < plan.RoomCount; ii++)
                    {
                        FloorRoomPlan roomPlan = plan.GetRoomPlan(ii);
                        if (roomPlan.RoomGen.Draw.Contains(mapLoc))
                        {
                            //stats
                            string roomString = String.Format("Room #{0}: {1}x{2} {3}", ii, roomPlan.RoomGen.Draw.X, roomPlan.RoomGen.Draw.Y, roomPlan.RoomGen.ToString());
                            rewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                            string componentString = String.Format("Components: {0}", String.Join(", ", roomPlan.Components));
                            rewriteLine(farthestPrint, componentString);
                            farthestPrint++;
                            //borders
                            StringBuilder 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++)
                    {
                        FloorHallPlan hallPlan = plan.GetHallPlan(ii);
                        if (hallPlan.RoomGen.Draw.Contains(mapLoc))
                        {
                            string roomString = String.Format("Hall #{0}: {1}x{2} {3}", ii, hallPlan.RoomGen.Draw.X, hallPlan.RoomGen.Draw.Y, hallPlan.RoomGen.ToString());
                            rewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                            string componentString = String.Format("Components: {0}", String.Join(", ", hallPlan.Components));
                            rewriteLine(farthestPrint, componentString);
                            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);
            }
        }