Beispiel #1
0
 void GenerateRoom(DunGen.Room roomBase)
 {
     // pick a room template from the floor;
     var roomTemplateKey = tpd.RollMap(env.roomTemplateChances);
     var roomTemplate = JSONResource.Get<RoomTemplate>(roomTemplateKey);
     var roomGenerator = new RoomGenerator(env, roomTemplate, roomBase);
     env.rooms.Add(roomGenerator.CreateRoom());
 }
Beispiel #2
0
    void GenerateRoom(DunGen.Room roomBase)
    {
        // pick a room template from the floor;
        var roomTemplateKey = tpd.RollMap(env.roomTemplateChances);
        var roomTemplate    = JSONResource.Get <RoomTemplate>(roomTemplateKey);
        var roomGenerator   = new RoomGenerator(env, roomTemplate, roomBase);

        env.rooms.Add(roomGenerator.CreateRoom());
    }
Beispiel #3
0
 public void NewGame()
 {
     _room   = RoomGenerator.CreateRoom(1);
     _player = new Player.Player
     {
         Id         = Guid.NewGuid(),
         HitPoints  = 5,
         Location   = _room.Location,
         Name       = "Player",
         ArmorClass = 14
     };
 }
    private VirtualRoom CreateRoom(VirtualMap map, RoomGenerator roomGenerator)
    {
        int width  = DungeonGenerator.Random.Instance.Next(minRoomWidth, maxRoomWidth);
        int height = DungeonGenerator.Random.Instance.Next(minRoomHeight, maxRoomHeight);

        VirtualRoom r = new VirtualRoom(width, height, new CellLocation(0, 0));

        PickBestRoomLocation(map, r);
        //		PickRandomLocation(map,r);

        VirtualRoom room = roomGenerator.CreateRoom(map, width, height, r);

        if (room != null)
        {
            CreateDoors(map, room, roomGenerator);
        }

        return(room);
    }
Beispiel #5
0
    VirtualRoom CreateRoom(VirtualMap map, RoomGenerator roomGenerator, BSPTreeNode node, CellLocation starting_location)
    {
        // Get the maximum bounds
        BSPTreeNodeBounds bounds = node.areaBounds;
        int range_x = bounds.max_x - bounds.min_x;
        int range_y = bounds.max_y - bounds.min_y;

        // Cannot create a room if the area is empty!
        if (range_x == 0 || range_y == 0)
        {
            Debug.LogWarning("Room size too small to be created! " + range_x + "," + range_y);
            return(null);
        }

        // Choose a random size for the room
        int min_size_x = Mathf.Max(1, Mathf.FloorToInt(range_x * roomSizeMinRange));
        int max_size_x = Mathf.Max(1, Mathf.CeilToInt(range_x * roomSizeMaxRange));
        int min_size_y = Mathf.Max(1, Mathf.FloorToInt(range_y * roomSizeMinRange));
        int max_size_y = Mathf.Max(1, Mathf.CeilToInt(range_y * roomSizeMaxRange));

        // Compute size
        int size_x = DungeonGenerator.Random.Instance.Next(min_size_x, max_size_x);
        int size_y = DungeonGenerator.Random.Instance.Next(min_size_y, max_size_y);

        // Compute start
        int start_x, start_y;

        start_x = bounds.min_x + DungeonGenerator.Random.Instance.Next(range_x - size_x);
        start_y = bounds.min_y + DungeonGenerator.Random.Instance.Next(range_y - size_y);

        // If the starting location is inside these bounds, we must force it to create the room on it
        if (starting_location.isValid() && bounds.Contain(starting_location))
        {
            //Debug.Log("YES IN");
            int x = starting_location.x / 2;
            int y = starting_location.y / 2;

            //Debug.Log("Start bounds: " + (new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y)).ToString());

            // Make sure the start includes this, or decrease it
            if (x < start_x)
            {
                start_x = x;
            }
            if (y < start_y)
            {
                start_y = y;
            }

            //Debug.Log(y);
            //Debug.Log(start_y + size_y);

            // Make sure the end includes thid, or increase it
            if (x + 1 >= start_x + size_x)
            {
                size_x = x + 1 - start_x;
            }
            if (y + 1 >= start_y + size_y)
            {
                size_y = y + 1 - start_y;
            }

            //Debug.Log("End bounds: " + (new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y)).ToString());
        }

        //Debug.Log("MIN " + min_size_x + " MAX " + max_size_x + " SIZE " + size_x);

        //Debug.Log("SPACE " + " [" + node.areaBounds.min_x + "," + node.areaBounds.max_x + "] [" + node.areaBounds.min_y + "," + node.areaBounds.max_y + "]");

        //Debug.Log("delta_low " + delta_low + " delta_high " + delta_high);

        //Debug.Log("CREATING ROOM: " + start_x + " + " + size_x + "   ||   " + start_y + " + " + size_y);

        node.roomBounds = new BSPTreeNodeBounds(start_x, start_y, start_x + size_x, start_y + size_y);

        // Start and end must be converted to whole-map sizes (not just floors)
        start_x = start_x * 2 + 1;
        start_y = start_y * 2 + 1;

        return(roomGenerator.CreateRoom(map, size_x, size_y, start_x, start_y));
    }