Esempio n. 1
0
def compound_generator(gen1, gen2, map_draft, player_hd, generator_type, requests, theme, params):
    merge_factor = float(randrange(*COMPOUND_MERGE_FACTOR)) / 100
    horizontal = util.coinflip()
    bsp = libtcod.bsp_new_with_size(0, 0, map_draft.width, map_draft.height)
    position = int(map_draft.height * merge_factor) if horizontal else int(map_draft.width * merge_factor)
    libtcod.bsp_split_once(bsp, horizontal, position)
    left = libtcod.bsp_left(bsp)
    right = libtcod.bsp_right(bsp)

    lmap = MapDef()
    lmap.width, lmap.height = left.w, left.h
    rmap = MapDef()
    rmap.width, rmap.height = right.w, right.h
    gen1(lmap, player_hd, generator_type, requests, params, theme)
    gen2(rmap, player_hd, generator_type, requests, params, theme)

    map_draft.map = [[None for x in xrange(map_draft.width)] for y in xrange(map_draft.height)]
    for x in xrange(left.x, left.x + left.w):
        for y in xrange(left.y, left.y + left.h):
            map_draft.replace_feature_atxy(x, y, lmap.map[y][x])

    _x, _y = 0, 0
    for x in xrange(right.x, right.x + right.w):
        for y in xrange(right.y, right.y + right.h):
            map_draft.replace_feature_atxy(x, y, rmap.map[_y][_x])
            _y += 1
        _y = 0
        _x +=1

    return map_draft
Esempio n. 2
0
 def generate_map(generator_type,
                  width=1,
                  height=1,
                  player_hd=1,
                  requests=None,
                  params=None,
                  name='',
                  theme=''):
     """generate_map(generator_type, ...) => MapDef
     params : no_large => bool (disable generation of large maps [map file with prefix large_])
             map_id => str (place map with certain id ontop of current map)
             room_maxwidth, room_minwidth, room_maxheight, room_minheight => int (parameters of rooms if applicable)
             road_start, road_end => (int, int) specifies where road should start (if applicabel)
             road_break => (int, int) specifies the min/maximum amount of stright road
             road_fill => features.Tile specifies which tile should make the road
             road_straight => generate straight road
     """
     if not generators.has_key(generator_type):
         raise RuntimeError('Unknow style [%s] for dungeon generator' %
                            generator_type)
     map_draft = MapDef()
     map_draft.name = name
     map_draft.width, map_draft.height = width, height
     _static_request_preprocessor(generator_type, player_hd, requests,
                                  params, theme)
     _assure_mapsize(map_draft, generator_type, requests)
     map_draft = generators[generator_type](
         map_draft, player_hd, generator_type, requests, params, theme
     )  #okay we just take requested generator and invoke it. Now we have draft map
     for transformer in transformation_pipe:
         if transformer.decide(player_hd, generator_type, requests, theme,
                               params):
             transformer.transformer(map_draft, player_hd, generator_type,
                                     requests, theme, params)
     return map_draft
Esempio n. 3
0
def __count_neigh_walls(MapDef, x, y):
    count = 0
    for row in (-1, 0, 1):
        for col in (-1, 0, 1):
            if not tile_passable(MapDef.tile_at(x + row, y + col)) and not(row == 0 and col == 0):
                count += 1
    return count
Esempio n. 4
0
def __count_neigh_walls(MapDef, x, y):
    count = 0
    for row in (-1, 0, 1):
        for col in (-1, 0, 1):
            if not tile_passable(MapDef.tile_at(
                    x + row, y + col)) and not (row == 0 and col == 0):
                count += 1
    return count
Esempio n. 5
0
def compound_generator(gen1, gen2, map_draft, player_hd, generator_type,
                       requests, theme, params):
    merge_factor = float(randrange(*COMPOUND_MERGE_FACTOR)) / 100
    horizontal = util.coinflip()
    bsp = libtcod.bsp_new_with_size(0, 0, map_draft.width, map_draft.height)
    position = int(map_draft.height *
                   merge_factor) if horizontal else int(map_draft.width *
                                                        merge_factor)
    libtcod.bsp_split_once(bsp, horizontal, position)
    left = libtcod.bsp_left(bsp)
    right = libtcod.bsp_right(bsp)

    lmap = MapDef()
    lmap.width, lmap.height = left.w, left.h
    rmap = MapDef()
    rmap.width, rmap.height = right.w, right.h
    gen1(lmap, player_hd, generator_type, requests, params, theme)
    gen2(rmap, player_hd, generator_type, requests, params, theme)

    map_draft.map = [[None for x in xrange(map_draft.width)]
                     for y in xrange(map_draft.height)]
    for x in xrange(left.x, left.x + left.w):
        for y in xrange(left.y, left.y + left.h):
            map_draft.replace_feature_atxy(x, y, lmap.map[y][x])

    _x, _y = 0, 0
    for x in xrange(right.x, right.x + right.w):
        for y in xrange(right.y, right.y + right.h):
            map_draft.replace_feature_atxy(x, y, rmap.map[_y][_x])
            _y += 1
        _y = 0
        _x += 1

    return map_draft
Esempio n. 6
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
Esempio n. 7
0
 def generate_map(generator_type, width=1, height=1, player_hd=1, requests=None, params=None, name='', theme=''):
     """generate_map(generator_type, ...) => MapDef
     params : no_large => bool (disable generation of large maps [map file with prefix large_])
             map_id => str (place map with certain id ontop of current map)
             room_maxwidth, room_minwidth, room_maxheight, room_minheight => int (parameters of rooms if applicable)
             road_start, road_end => (int, int) specifies where road should start (if applicabel)
             road_break => (int, int) specifies the min/maximum amount of stright road
             road_fill => features.Tile specifies which tile should make the road
             road_straight => generate straight road
     """
     if not generators.has_key(generator_type):
         raise RuntimeError('Unknow style [%s] for dungeon generator' % generator_type)
     map_draft = MapDef()
     map_draft.name = name
     map_draft.width, map_draft.height = width, height
     _static_request_preprocessor(generator_type, player_hd, requests, params, theme)
     _assure_mapsize(map_draft, generator_type, requests)
     map_draft = generators[generator_type](map_draft, player_hd, generator_type, requests, params, theme) #okay we just take requested generator and invoke it. Now we have draft map
     for transformer in transformation_pipe:
         if transformer.decide(player_hd, generator_type, requests, theme, params):
             transformer.transformer(map_draft, player_hd, generator_type, requests, theme, params)
     return map_draft
Esempio n. 8
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
Esempio n. 9
0
def _check_static_params(generator_type, hd, MapDef, params):
    """ Check params for MapDef loaded from des file. Check that map theme matches that of generator.
        Player HD is higher or equals that defined in des file etc... """
    if generator_type != 'null':
        if not MapDef.has_terrain(generator_type):
            return False
    if MapDef.HD >  hd:
        return False
    if MapDef.unique and unique_maps_already_generated.has_key(MapDef.id):
        return False
    #we can have exact id specified
    if params and params.has_key('map_id'):
        return params['map_id'] == MapDef.id
    return True
Esempio n. 10
0
def _check_static_params(generator_type, hd, MapDef, params):
    """ Check params for MapDef loaded from des file. Check that map theme matches that of generator.
        Player HD is higher or equals that defined in des file etc... """
    if generator_type != 'null':
        if not MapDef.has_terrain(generator_type):
            return False
    if MapDef.HD > hd:
        return False
    if MapDef.unique and unique_maps_already_generated.has_key(MapDef.id):
        return False
    #we can have exact id specified
    if params and params.has_key('map_id'):
        return params['map_id'] == MapDef.id
    return True
Esempio n. 11
0
def __gen_wall_square(MapDef, x, y, w, h):
    mapsrc = [['#' for y in xrange(x+w)] for x in xrange(y+h)]
    MapDef.map = mapsrc
    return MapDef.prepare(None)
Esempio n. 12
0
def __gen_wall_square(MapDef, x, y, w, h):
    mapsrc = [['#' for y in xrange(x + w)] for x in xrange(y + h)]
    MapDef.map = mapsrc
    return MapDef.prepare(None)