/**
  * Sometimes the dungeon is loaded from a DB so this isnt always needed. this used when a new dungeon is created
  * @param size the amount of rooms to have in the dungeon
  * @param objectlist the list of all objects includeing rooms and their descriptions.
  */
 public void Init(int size, GameObjectList objectList)
 {
     RoomList   = GenerateDungeon(size, objectList);
     DungeonStr = GenerateDungeonString(RoomList);
 }
        /**
         * Map generation stuff
         */
        public static List <Room> GenerateDungeon(int size, GameObjectList gol)
        {
            //check if its logical map
            if (size < 4)
            {
                size = 4;
            }

            //add one for origin
            size += 1;


            List <Room>     rRooms        = new List <Room>();
            List <Vector2D> usedPositions = new List <Vector2D>();
            List <Room>     usedRooms     = new List <Room>();


            //create empty rooms
            int iter = 0;

            while (rRooms.Count < size)
            {
                Room r = new Room("Room" + iter, iter);

                KeyValuePair <String, String> RoomDesc = gol.GetRandomRoom();

                r.name = RoomDesc.Key;
                r.desc = RoomDesc.Value;
                rRooms.Add(r);
                iter++;
            }

            //set up possible directions
            Vector2D[] Dir = { NORTH, EAST, SOUTH, WEST };

            //make origin and attach first four rooms manually
            Room origin = rRooms[0];

            rRooms.Remove(origin);
            origin.Position = new Vector2D(0, 0);
            usedRooms.Add(origin);

            MakeBranch(origin, rRooms[0], NORTH, usedRooms, rRooms, usedPositions);
            MakeBranch(origin, rRooms[0], EAST, usedRooms, rRooms, usedPositions);
            MakeBranch(origin, rRooms[0], SOUTH, usedRooms, rRooms, usedPositions);
            MakeBranch(origin, rRooms[0], WEST, usedRooms, rRooms, usedPositions);

            //If this vec is returned we know the room is out of directions
            Vector2D badVec = new Vector2D(0, 0);

            //populate until there are no more rooms left
            while (rRooms.Count > 1)
            {
                int roomIndex = rand.Next(usedRooms.Count);

                Vector2D dir = usedRooms[roomIndex].GetAvailableDirection();
                if (!dir.Equals(badVec) && rand.NextDouble() >= 0.4)
                {
                    MakeBranch(usedRooms[roomIndex], rRooms[0], dir, usedRooms, rRooms, usedPositions);
                }
            }

            return(usedRooms);
        }