コード例 #1
0
ファイル: loc.py プロジェクト: olympiag3/olymap
def write_loc_map_anchor(v, k, data, outf, instance, inst_dict, map_matrices):
    dimensions = inst_dict[instance]
    region = u.region(k, data)
    region_rec = data[region]
    province = u.province(k, data)
    if province == 0:
        return 0
    province_rec = data[province]
    custom = False
    save_rec = []
    save_world = ''
    try:
        save_rec = map_matrices[region_rec['na'][0].lower()]
        save_world = region_rec['na'][0].lower()
        custom = True
    except KeyError:
        try:
            save_rec = dimensions[region_rec['na'][0].lower()]
            save_world = region_rec['na'][0].lower()
        except KeyError:
            for world in dimensions:
                world_rec = dimensions[world]
                if world_rec[0] <= int(province) < world_rec[0] + (world_rec[2] * 100):
                    save_rec = world_rec
                    save_world = world
                    break
    # if len(save_rec) == 0:
    #     print('error {} {}'.format(to_oid(k),
    #                                u.return_type(v)))
    if len(save_rec) > 0 and not custom:
        world_rec = save_rec
        world = save_world
        x_coord = int(10 * math.floor((int(province) % 100) / 10))
        if x_coord >= world_rec[1] - 10:
            x_coord = world_rec[1] - 20
        y_coord = int(1000 * math.floor(int(province) / 1000))
        if y_coord >= world_rec[0] + (world_rec[2] * 100) - 1000:
            y_coord = world_rec[0] + (world_rec[2] * 100) - 2000
            if y_coord < world_rec[0]:
                y_coord = world_rec[0]
        final_coord = y_coord + x_coord
        if final_coord < world_rec[0]:
            final_coord = world_rec[0]
        anchor_string = world + '_map_leaf_' + to_oid(final_coord)
        outf.write('<p>{}</p>\n'.format(anchor2(anchor_string, 'Return to map')))
    if len(save_rec) > 0 and custom:
        world_rec = save_rec
        world = save_world
        for xx in range(0, len(save_rec[0])):
            for yy in range(0,len(save_rec)):
                if save_rec[yy][xx] == province:
                    xxx = int(math.floor(xx / 10)) * 10
                    yyy = int(math.floor(yy / 10)) * 10
                    final_coord = save_rec[yyy][xxx]
                    break
        anchor_string = world + '_map_leaf_' + to_oid(final_coord)
        outf.write('<p>{}</p>\n'.format(anchor2(anchor_string, 'Return to map')))
コード例 #2
0
ファイル: char.py プロジェクト: akhand2222/olypy
def get_where(box, data):
    if get_loc(box, data) is not None:
        if get_loc(box, data)['kind'] != 'loc' or get_loc(
                box, data)['subkind'] not in details.province_kinds:
            where_id = u.province(u.return_unitid(box), data)
            where_box = data[where_id]
            where_dict = {
                'id': where_id,
                'oid': to_oid(where_id),
                'name': get_name(where_box)
            }
            return where_dict
    return None
コード例 #3
0
ファイル: loc.py プロジェクト: akhand2222/olypy
def get_map_anchor(v, k, data, instance, inst_dict, map_matrices):
    if u.return_subkind(v) in ['tunnel', 'chamber']:
        return None
    dimensions = inst_dict[instance]
    region = u.region(k, data)
    region_rec = data[region]
    province = u.province(k, data)
    if province == 0:
        return None
    province_rec = data[province]
    custom = False
    save_rec = []
    save_world = ''
    try:
        save_rec = map_matrices[region_rec['na'][0].lower()]
    except KeyError:
        try:
            save_rec = dimensions[region_rec['na'][0].lower()]
        except KeyError:
            for world in dimensions:
                world_rec = dimensions[world]
                if world_rec[0] <= int(province) < world_rec[0] + (world_rec[2] * 100):
                    save_rec = world_rec
                    save_world = world
                    break
        else:
            save_world = region_rec['na'][0].lower()
    else:
        save_world = region_rec['na'][0].lower()
        custom = True
    # if len(save_rec) == 0:
    #     print('error {} {}'.format(to_oid(k),
    #                                u.return_subkind(v)))
    if len(save_rec) > 0 and not custom:
        world_rec = save_rec
        world = save_world
        x_coord = int(10 * math.floor((int(province) % 100) / 10))
        if x_coord >= world_rec[1] - 10:
            x_coord = world_rec[1] - 20
        y_coord = int(1000 * math.floor(int(province) / 1000))
        if y_coord >= world_rec[0] + (world_rec[2] * 100) - 1000:
            y_coord = world_rec[0] + (world_rec[2] * 100) - 2000
            if y_coord < world_rec[0]:
                y_coord = world_rec[0]
        final_coord = y_coord + x_coord
        if final_coord < world_rec[0]:
            final_coord = world_rec[0]
        anchor_string = world + '_map_leaf_' + to_oid(final_coord)
        return anchor_string
    if len(save_rec) > 0 and custom:
        world_rec = save_rec
        world = save_world
        for xx in range(0, len(save_rec[0])):
            for yy in range(0,len(save_rec)):
                if save_rec[yy][xx] == province:
                    xxx = int(math.floor(xx / 10)) * 10
                    yyy = int(math.floor(yy / 10)) * 10
                    final_coord = save_rec[yyy][xxx]
                    break
        anchor_string = world + '_map_leaf_' + to_oid(final_coord)
        return anchor_string
    return None
コード例 #4
0
ファイル: loc.py プロジェクト: akhand2222/olypy
def get_destinations(k, v, data):
    dest_list = []
    if 'LO' in v and 'pd' in v['LO']:
        pd_list = v['LO']['pd']
        i = int(0)
        for pd in pd_list:
            if pd != '0':
                direction = pd_directions[i]
                pd_rec = data[pd]
                region_id = u.region(pd, data)
                region_rec = data[region_id]
                if u.province_has_port_city(pd_rec, data) is not None:
                    city_rec = data[u.province_has_port_city(pd_rec, data)]
                    to_dict = create_loc_to_dict_entry(data, direction, city_rec, v, region_rec)
                    dest_list.append(to_dict)
                to_dict = create_loc_to_dict_entry(data, direction, pd_rec, v, region_rec)
                dest_list.append(to_dict)
                # see if port city so show province also
                if u.is_port_city(pd_rec, data):
                    prov_rec = data[u.province(pd, data)]
                    to_dict = create_loc_to_dict_entry(data, direction, prov_rec, v, region_rec)
                    dest_list.append(to_dict)
            i = i + 1
    if u.return_subkind(v) not in details.province_kinds:
        if 'LI' in v and 'wh' in v['LI']:
            out_id = v['LI']['wh'][0]
            out_rec = data[out_id]
            region_id = u.region(out_id, data)
            region_rec = data[region_id]
            to_dict = create_loc_to_dict_entry(data, 'Out', out_rec, v, region_rec)
            dest_list.append(to_dict)
    if 'LI' in v and 'hl' in v['LI']:
        here_list = v['LI']['hl']
        for here in here_list:
            here_record = data[here]
            if u.is_road_or_gate(here_record):
                to_id = here_record['GA']['tl'][0]
                to_rec = data[to_id]
                region_id = u.region(to_id, data)
                region_rec = data[region_id]
                if u.return_kind(here_record) == 'gate':
                    direction = 'Gate'
                else:
                    direction = get_name(here_record)
                to_dict = create_loc_to_dict_entry(data, direction, to_rec, here_record, region_rec)
                dest_list.append(to_dict)
    if 'SL' in v and 'lt' in v['SL']:
        link_id = v['SL']['lt'][0]
        link_rec = data[link_id]
        region_id = u.region(link_id, data)
        region_rec = data[region_id]
        to_dict = create_loc_to_dict_entry(data, get_subkind(link_rec, data).title(), link_rec, v, region_rec)
        dest_list.append(to_dict)
    region_id = u.region(k, data)
    region_rec = data[region_id]
    dest_dict = {'id': k,
                 'oid': to_oid(k),
                 'name': get_name(v),
                 'subkind': get_subkind(v, data),
                 'region_oid': to_oid(region_id),
                 'region_name': get_name(region_rec),
                 'dest': dest_list}
    return dest_dict