Example #1
0
        public List <RoomHallIndex> CheckCollision(Rect rect)
        {
            // gets all rooms/halls colliding with the rectangle
            List <RoomHallIndex> results = new List <RoomHallIndex>();

            for (int ii = 0; ii < this.Rooms.Count; ii++)
            {
                FloorRoomPlan room = this.Rooms[ii];
                if (Collision.Collides(room.RoomGen.Draw, rect))
                {
                    results.Add(new RoomHallIndex(ii, false));
                }
            }

            for (int ii = 0; ii < this.Halls.Count; ii++)
            {
                FloorHallPlan hall = this.Halls[ii];
                if (Collision.Collides(hall.RoomGen.Draw, rect))
                {
                    results.Add(new RoomHallIndex(ii, true));
                }
            }

            return(results);
        }
Example #2
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);
        }