Example #1
0
 /// <summary>
 /// Find other doors that the room links too.
 /// </summary>
 /// <param name="room"></param>
 private void LinkDoors(Room room)
 {
     foreach (Door door in doors)
     {
         foreach (VectorInt exit in door.Exits)
         {
             if (room[exit])
             {
                 if (!room.Doors.Contains(door))
                 {
                     room.Doors.Add(door);
                 }
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// Find Rooms based on door positions
        /// </summary>
        private void AnalyseRooms()
        {
            int roomID = 0;
            foreach (Door door in doors)
            {
                foreach (VectorInt exit in door.Exits)
                {
                    // Does this belong to a room already?
                    if (FindRooms(exit.X, exit.Y) == null)
                    {
                        roomID++;
                        Room newRoom = new Room("R" + roomID.ToString(), controller.Map.Size);
                        newRoom.Doors.Add(door);

                        // Set Room region
                        Bitmap boundry = controller.StaticAnalysis.BoundryMap.BitwiseOR(doorBitmap);
                        FloodFillStrategy floodfill = new FloodFillStrategy(boundry, exit);

                        Evaluator<LocationNode> eval = new Evaluator<LocationNode>();
                        eval.Evaluate(floodfill);

                        // Set region from floodfill
                        newRoom.Set(floodfill.Result);
                        newRoom[exit] = true; // Make sure the exit is also in the room

                        newRoom.Goals = newRoom.BitwiseAND(controller.StaticAnalysis.GoalMap).Count;
                        if (newRoom.Goals == 0)
                        {
                            newRoom.Roomtype = Room.RoomTypes.StorageRoom;
                        }
                        else
                        {
                            newRoom.Roomtype = Room.RoomTypes.GoalRoom;
                        }

                        // Human Readable name
                        newRoom.Name = newRoom.Description;

                        // Link to other doors
                        LinkDoors(newRoom);

                        // Add it the size if more than one floor space
                        if (newRoom.Count > 1)
                        {
                            rooms.Add(newRoom);

                            controller.DebugReport.AppendHeading(3,"{0} Room ({1}) found with {2} goals:", newRoom.Roomtype, newRoom.Name, newRoom.Goals);
                            controller.DebugReport.Append("Doors: {0}",  StringHelper.Join(newRoom.Doors,
                                delegate(Door item)
                                    {
                                        return string.Format("{0}({2})@{1}", item.Type, item.Position, item.DoorID);
                                    }, ", "));
                            controller.DebugReport.Append(newRoom.ToString());
                            controller.DebugReport.CompleteSection();
                        }
                    }
                }
            }
            controller.DebugReport.CompleteSection();
        }