Beispiel #1
0
def cave_generator(map_draft, player_hd, generator_type, requests, theme, params):
    __gen_wall_square(map_draft, 0, 0, map_draft.width, map_draft.height)
    maputils.generate_border(map_draft, ft.fixed_wall)
    open_area_factor = float(randint(4, 6)) / 10
    walls_left = int(map_draft.width * map_draft.height * open_area_factor)
    #we don't want this process to hang
    ticks = map_draft.width * map_draft.height
    x2, y2 = map_draft.width - 1, map_draft.height - 1
    while walls_left > 0:
        if not ticks:
            print("Map generation takes too long - returning as is")
            break
        rand_x = randrange(1, x2)
        rand_y = randrange(1, y2)

        if map_draft.tile_at(rand_x, rand_y).type == ftype.wall:
            map_draft.replace_feature_atxy(rand_x, rand_y, ft.floor())
            walls_left -= 1
            ticks -= 1

    count_walls = __count_neigh_walls
    for x in xrange(1, x2):
        for y in xrange(1, y2):
            wall_count = count_walls(map_draft, x, y)

            if tile_passable(map_draft.tile_at(x, y)):
                if wall_count > 5:
                    map_draft.replace_feature_atxy(x, y, ft.rock_wall())
            elif wall_count < 4:
                map_draft.replace_feature_atxy(x, y, ft.floor())

    return map_draft
Beispiel #2
0
def cave_generator(map_draft, player_hd, generator_type, requests, theme,
                   params):
    __gen_wall_square(map_draft, 0, 0, map_draft.width, map_draft.height)
    maputils.generate_border(map_draft, ft.fixed_wall)
    open_area_factor = float(randint(4, 6)) / 10
    walls_left = int(map_draft.width * map_draft.height * open_area_factor)
    #we don't want this process to hang
    ticks = map_draft.width * map_draft.height
    x2, y2 = map_draft.width - 1, map_draft.height - 1
    while walls_left > 0:
        if not ticks:
            print("Map generation takes too long - returning as is")
            break
        rand_x = randrange(1, x2)
        rand_y = randrange(1, y2)

        if map_draft.tile_at(rand_x, rand_y).type == ftype.wall:
            map_draft.replace_feature_atxy(rand_x, rand_y, ft.floor())
            walls_left -= 1
            ticks -= 1

    count_walls = __count_neigh_walls
    for x in xrange(1, x2):
        for y in xrange(1, y2):
            wall_count = count_walls(map_draft, x, y)

            if tile_passable(map_draft.tile_at(x, y)):
                if wall_count > 5:
                    map_draft.replace_feature_atxy(x, y, ft.rock_wall())
            elif wall_count < 4:
                map_draft.replace_feature_atxy(x, y, ft.floor())

    return map_draft
Beispiel #3
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 #4
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 #5
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 #6
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