Beispiel #1
0
def rooms_corridors_generator(map_draft, player_hd, generator_type, requests, theme, params):
    map_draft = __gen_wall_square(map_draft, 0, 0, map_draft.width, map_draft.height)
    num_rooms = 0
    square = map_draft.width * map_draft.height
    max_rooms = int((square / MIN_ROOM_SIZE) * CORRIDOR_FACTOR) #determine maximum number of rooms
    logger.debug('Generating maximum number of %d rooms' % max_rooms)

    prevroom = None
    for roomid in xrange(max_rooms):
        if num_rooms > max_rooms: break

        minw, maxw, minh, maxh = __get_room_size_params(params, map_draft.width, map_draft.height)

        ticks = max_rooms * 5 #retries to generate all rooms
        while True:
            if ticks <= 0:
                logger.debug('Giving up on generating current room - no space')
                break
            ticks -= 1

            width = randrange(minw, maxw)
            height = randrange(minh, maxh)
            #random position without going out of the boundaries of the map
            x = randrange(1, max(map_draft.width - 1 - width, 2))
            y = randrange(1, max(map_draft.height - 1 - height, 2))

            if not util.one_chance_in(OVERLAP_ROOM_CHANCE):
                if filter(lambda room: room.overlap(x - 2, y - 2, x+width + 2, y+height+2), map_draft.rooms.values()):
                    continue #room overlap
            room = Room()
            room.x, room.y = x, y
            room.width, room.height = width, height
            for _x in xrange(width):
                for _y in xrange(height):
                    if map_draft.map[y+_y][x+_x].type == ftype.door:
                        continue #don't mess with doors
                    map_draft.replace_feature_atxy(x+_x, y+_y, ft.floor())

            new_x, new_y = room.center
            if prevroom:
                prev_x, prev_y = prevroom.center
                if util.coinflip():
                    maputils.create_h_tunnel(map_draft, prev_x, new_x, prev_y, room, prevroom)
                    maputils.create_v_tunnel(map_draft, prev_y, new_y, new_x, room, prevroom)
                else:
                    maputils.create_v_tunnel(map_draft, prev_y, new_y, prev_x, room, prevroom)
                    maputils.create_h_tunnel(map_draft, prev_x, new_x, new_y, room, prevroom)

            prevroom = room
            map_draft.rooms['roomc' + str(roomid)] = room
            num_rooms += 1
            break
    return map_draft
Beispiel #2
0
def _create_bsp_room(node, userdata, MapDef, bsp):
    if libtcod.bsp_is_leaf(node):
        # dig the room
        for x in xrange(node.x + 1, node.x + node.w - 1):
            for y in xrange(node.y + 1, node.y + node.h - 1):
                MapDef.replace_feature_atxy(x, y, ft.floor())
    else:
#        # resize the node to fit its sons
        left = libtcod.bsp_left(node)
        right = libtcod.bsp_right(node)
        rleft = Room(left.x, left.y, left.w, left.h)
        rright = Room(right.x, right.y, right.w, right.h)
        lx, ly = rleft.center
        rx, ry = rright.center
        if node.horizontal:
#            # vertical corridor
            maputils.create_v_tunnel(MapDef, ly, ry, lx, rleft, rright)
            maputils.create_h_tunnel(MapDef, lx, rx, ly, rleft, rright)
        else:
            maputils.create_h_tunnel(MapDef, lx, rx, ly, rleft, rright)
            maputils.create_v_tunnel(MapDef, ly, ry, lx, rleft, rright)
    return True
Beispiel #3
0
def _create_bsp_room(node, userdata, MapDef, bsp):
    if libtcod.bsp_is_leaf(node):
        # dig the room
        for x in xrange(node.x + 1, node.x + node.w - 1):
            for y in xrange(node.y + 1, node.y + node.h - 1):
                MapDef.replace_feature_atxy(x, y, ft.floor())
    else:
        #        # resize the node to fit its sons
        left = libtcod.bsp_left(node)
        right = libtcod.bsp_right(node)
        rleft = Room(left.x, left.y, left.w, left.h)
        rright = Room(right.x, right.y, right.w, right.h)
        lx, ly = rleft.center
        rx, ry = rright.center
        if node.horizontal:
            #            # vertical corridor
            maputils.create_v_tunnel(MapDef, ly, ry, lx, rleft, rright)
            maputils.create_h_tunnel(MapDef, lx, rx, ly, rleft, rright)
        else:
            maputils.create_h_tunnel(MapDef, lx, rx, ly, rleft, rright)
            maputils.create_v_tunnel(MapDef, ly, ry, lx, rleft, rright)
    return True
Beispiel #4
0
def rooms_corridors_generator(map_draft, player_hd, generator_type, requests,
                              theme, params):
    map_draft = __gen_wall_square(map_draft, 0, 0, map_draft.width,
                                  map_draft.height)
    num_rooms = 0
    square = map_draft.width * map_draft.height
    max_rooms = int((square / MIN_ROOM_SIZE) *
                    CORRIDOR_FACTOR)  #determine maximum number of rooms
    logger.debug('Generating maximum number of %d rooms' % max_rooms)

    prevroom = None
    for roomid in xrange(max_rooms):
        if num_rooms > max_rooms: break

        minw, maxw, minh, maxh = __get_room_size_params(
            params, map_draft.width, map_draft.height)

        ticks = max_rooms * 5  #retries to generate all rooms
        while True:
            if ticks <= 0:
                logger.debug('Giving up on generating current room - no space')
                break
            ticks -= 1

            width = randrange(minw, maxw)
            height = randrange(minh, maxh)
            #random position without going out of the boundaries of the map
            x = randrange(1, max(map_draft.width - 1 - width, 2))
            y = randrange(1, max(map_draft.height - 1 - height, 2))

            if not util.one_chance_in(OVERLAP_ROOM_CHANCE):
                if filter(
                        lambda room: room.overlap(x - 2, y - 2, x + width + 2,
                                                  y + height + 2),
                        map_draft.rooms.values()):
                    continue  #room overlap
            room = Room()
            room.x, room.y = x, y
            room.width, room.height = width, height
            for _x in xrange(width):
                for _y in xrange(height):
                    if map_draft.map[y + _y][x + _x].type == ftype.door:
                        continue  #don't mess with doors
                    map_draft.replace_feature_atxy(x + _x, y + _y, ft.floor())

            new_x, new_y = room.center
            if prevroom:
                prev_x, prev_y = prevroom.center
                if util.coinflip():
                    maputils.create_h_tunnel(map_draft, prev_x, new_x, prev_y,
                                             room, prevroom)
                    maputils.create_v_tunnel(map_draft, prev_y, new_y, new_x,
                                             room, prevroom)
                else:
                    maputils.create_v_tunnel(map_draft, prev_y, new_y, prev_x,
                                             room, prevroom)
                    maputils.create_h_tunnel(map_draft, prev_x, new_x, new_y,
                                             room, prevroom)

            prevroom = room
            map_draft.rooms['roomc' + str(roomid)] = room
            num_rooms += 1
            break
    return map_draft