예제 #1
0
def write_legacy_bitmap(outdir, data, upperleft, height, width, prefix,
                        map_matrix):
    BUFSIZE = 8 * 1024
    color_pallette = {
        'ocean': (0x00, 0xff, 0xff, 0xff),
        'plain': (0x90, 0xee, 0x90, 0xff),
        'forest': (0x32, 0xcd, 0x32, 0xff),
        'swamp': (0xff, 0x00, 0xff, 0xff),
        'mountain': (0x80, 0x80, 0x80, 0xff),
        'desert': (0xff, 0xff, 0x00, 0xff),
        'underground': (0xff, 0xa5, 0x00, 0xff),
        'cloud': (0xad, 0xd8, 0xe6, 0xff)
    }
    outf = open(pathlib.Path(outdir).joinpath(prefix + '_thumbnail.png'), 'wb')
    map = PNGCanvas(width, height, color=(0xff, 0, 0, 0xff))
    for x in range(0, width):
        for y in range(0, height):
            try:
                province_box = data[map_matrix[y][x]]
                try:
                    color = color_pallette[u.return_subkind(province_box)]
                except KeyError:
                    print('missing color for: {}'.format(
                        u.return_subkind(province_box)))
                else:
                    map.point(x, y, color)
            except KeyError:
                # print('missing box record for: {} {}'.format(curr_loc,
                #                                              to_oid(curr_loc)))
                pass
    outf.write(map.dump())
    outf.close()
예제 #2
0
파일: loc.py 프로젝트: akhand2222/olypy
def get_civ_level(k, v, data):
    civ_level = None
    if not u.is_ocean(v) and u.loc_depth(u.return_subkind(v)) == 2 \
    and data[u.region(k, data)]['na'][0] != 'faery' and data[u.region(k, data)]['na'][0] != 'hades':
        civ_level = 'wilderness'
        if 'LO' in v and 'lc' in v['LO']:
            if v['LO']['lc'][0] == '0':
                civ_level = 'wilderness'
            else:
                civ_level = 'civ-' + v['LO']['lc'][0]
    return civ_level
예제 #3
0
def write_cell(castle_chain, currentpoint, data, leftnav, outf, prefix,
               rightnav, x, y, xx, yy, instance, map_matrix):
    left_nav_dict = {}
    if x == 0 and y == 0:
        if leftnav:
            printpoint = map_matrix[yy][xx - 10]
            left_nav_dict = {
                'oid': to_oid(printpoint),
                'width': 20,
                'height': 840
            }
    cell = map_matrix[yy + y][xx + x]
    printpoint = cell
    try:
        loc_rec = data[str(printpoint)]
    except:
        type = 'undefined'
        border_dict = {}
        contents_dict = {}
    else:
        type = u.return_subkind(loc_rec)
        border_dict = maps.generate_border(data, loc_rec, outf, instance)
        contents_dict = maps.generate_cell_contents(castle_chain, printpoint,
                                                    data, loc_rec, outf)
    cell_dict = {
        'oid': to_oid(printpoint),
        'type': type,
        'border_dict': border_dict,
        'contents_dict': contents_dict
    }
    # except KeyError:
    #    outf.write('<td id="{}" class="x-sea">{}</td>\n'.format(to_oid(printpoint), to_oid(printpoint)))
    right_nav_dict = {}
    if x == 19 and y == 0:
        if rightnav:
            printpoint = map_matrix[yy][xx + 10]
            right_nav_dict = {
                'oid': to_oid(printpoint),
                'width': 20,
                'height': 840
            }
    nav_dict = {
        'left_nav_dict': left_nav_dict,
        'cell_dict': cell_dict,
        'right_nav_dict': right_nav_dict
    }
    return nav_dict
예제 #4
0
파일: maps.py 프로젝트: akhand2222/olypy
def write_cell(castle_chain, currentpoint, data, leftnav, outf, prefix,
               rightnav, x, y, rem_width, rem_height, instance):
    left_nav_dict = {}
    if x == 0 and y == 0:
        if leftnav:
            printpoint = currentpoint - 10
            left_nav_dict = {
                'oid': to_oid(printpoint),
                'width': 20,
                'height': 840
            }
    cell = currentpoint + (x + (y * 100))
    printpoint = str(cell)
    try:
        loc_rec = data[str(printpoint)]
    except:
        subkind = 'undefined'
        border_dict = {}
        contents_dict = {}
    else:
        subkind = u.return_subkind(loc_rec)
        border_dict = generate_border(data, loc_rec, outf, instance)
        contents_dict = generate_cell_contents(castle_chain, printpoint, data,
                                               loc_rec, outf)
    cell_dict = {
        'oid': to_oid(printpoint),
        'subkind': subkind,
        'border_dict': border_dict,
        'contents_dict': contents_dict
    }
    # except KeyError:
    #    outf.write('<td id="{}" class="x-sea">{}</td>\n'.format(to_oid(printpoint), to_oid(printpoint)))
    right_nav_dict = {}
    if x == 19 and y == 0:
        if rightnav:
            printpoint = currentpoint + 10
            right_nav_dict = {
                'oid': to_oid(printpoint),
                'width': 20,
                'height': 840
            }
    nav_dict = {
        'left_nav_dict': left_nav_dict,
        'cell_dict': cell_dict,
        'right_nav_dict': right_nav_dict
    }
    return nav_dict
예제 #5
0
파일: char.py 프로젝트: akhand2222/olypy
def get_loc(box, data):
    loc_id = box.get('LI', {}).get('wh', [None])[0]
    if loc_id is not None:
        try:
            loc_box = data[loc_id]
        except:
            return None
        # could be location or stacked under something
        loc_dict = {
            'id': loc_id,
            'oid': to_oid(loc_id),
            'name': get_name(loc_box),
            'kind': u.return_kind(loc_box),
            'subkind': u.return_subkind(loc_box)
        }
        return loc_dict
    return None
예제 #6
0
파일: item.py 프로젝트: akhand2222/olypy
def get_trade_good(k, v, data, trade_chain):
    buy_list = []
    sell_list = []
    if trade_chain is not None and u.return_subkind(v) == 'tradegood':
        trade_list = trade_chain[k]
        if len(trade_list) > 0:
            for loc in trade_list:
                loc_rec = data[loc[0]]
                if loc[1] == '1':
                    buy_entry = {'id': loc[0],
                                 'oid': to_oid(loc[0]),
                                 'name': get_name(loc_rec)}
                    buy_list.append(buy_entry)
                else:
                    sell_entry = {'id': loc[0],
                                 'oid': to_oid(loc[0]),
                                 'name': get_name(loc_rec)}
                    sell_list.append(sell_entry)
            trade_dict = {'buy': buy_list,
                          'sell': sell_list}
            return trade_dict
    return None
예제 #7
0
파일: loc.py 프로젝트: akhand2222/olypy
def get_controlled_by(v, data):
    controlled_dict = {}
    here_list = v.get('LI', {}).get('hl', [None])
    if here_list[0] is not None and len(here_list) > 0:
        for loc in here_list:
            garrison_rec = data[loc] # looking for garrisons
            if u.is_garrison(garrison_rec):
                castle = garrison_rec.get('MI', {}).get('gc', [None])
                if castle[0] is not None and castle[0] != '0':
                    castle_rec = data[castle[0]]
                    castle_name = castle_rec['na'][0]
                    castle_oid = to_oid(castle[0])
                    castle_type = u.return_subkind(castle_rec)
                    castle_loc_id = castle_rec['LI']['wh'][0]
                    castle_loc_rec = data[castle_loc_id]
                    castle_loc_type = get_subkind(castle_loc_rec, data)
                    if castle_loc_type == 'city':  # in a city
                        castle_loc_id = castle_loc_rec['LI']['wh'][0]
                        castle_loc_rec = data[castle_loc_id]
                    castle_loc_oid = to_oid(castle_loc_id)
                    castle_loc_name = castle_loc_rec['na'][0]
                    # calculate top of pledge chain
                    castle_here_list = castle_rec.get('LI', {}).get('hl', [None])
                    ruled_by_dict = None
                    if castle_here_list[0] is not None:
                        top_guy_box = u.top_ruler(data[castle_here_list[0]], data)
                        if top_guy_box is not None:
                            ruled_by_dict = {'id': u.return_unitid(top_guy_box),
                                             'oid': to_oid(u.return_unitid(top_guy_box)),
                                             'name': get_name(top_guy_box)}
                    controlled_dict = {'oid': castle_oid,
                                       'name': castle_name,
                                       'subkind': castle_type,
                                       'loc_oid': castle_loc_oid,
                                       'loc_name': castle_loc_name,
                                       'ruled_by_dict': ruled_by_dict}
    return controlled_dict
예제 #8
0
파일: maps.py 프로젝트: akhand2222/olypy
def generate_cell_contents(castle_chain, cell, data, loc_rec, outf):
    a = to_oid(cell)
    castle_icon = None
    if 'LI' in loc_rec and 'hl' in loc_rec['LI']:
        here_list = loc_rec['LI']['hl']
        for garr in here_list:
            garr_rec = data[garr]
            if u.is_garrison(garr_rec):
                if 'MI' in garr_rec:
                    if 'gc' in garr_rec['MI']:
                        castle_id = garr_rec['MI']['gc'][0]
                        castle_icon = castle_chain[castle_id][0]
    loc1 = ''
    loc2 = ''
    city = ''
    graveyard = ''
    road_or_gate = ''
    count = int(0)
    if 'LI' in loc_rec and 'hl' in loc_rec['LI']:
        if len(loc_rec['LI']['hl']) > 0:
            here_list = loc_rec['LI']['hl']
            for here in here_list:
                # if 56760 <= int(here) <= 78999:
                here_rec = data[here]
                if u.return_subkind(
                        here_rec) in details.subloc_kinds or u.is_road_or_gate(
                            here_rec):
                    count = count + 1
                    if u.is_city(here_rec):
                        city = here_rec
                    elif u.is_graveyard(here_rec):
                        graveyard = here_rec
                    elif u.is_road_or_gate(here_rec):
                        road_or_gate = here_rec
                    elif loc1 == '' and u.is_loc(here_rec):
                        loc1 = here_rec
                    elif loc2 == '' and u.is_loc(here_rec):
                        loc2 = here_rec
    if 'SL' in loc_rec:
        if 'lt' in loc_rec['SL']:
            here_rec = data[loc_rec['SL']['lt'][0]]
            count = count + 1
            if loc1 == '':
                loc1 = here_rec
            elif loc2 == '':
                loc2 = here_rec
        if 'lf' in loc_rec['SL']:
            here_rec = data[loc_rec['SL']['lf'][0]]
            count = count + 1
            if loc1 == '':
                loc1 = here_rec
            elif loc2 == '':
                loc2 = here_rec
    many = False
    loc1_dict = {}
    loc2_dict = {}
    if loc1 != '' or loc2 != '' or city != '' or graveyard != '' or road_or_gate != '':
        if city != '':
            if loc2 == '':
                loc2 = loc1
            loc1 = city
        if graveyard != '':
            if loc1 == '':
                if loc2 == '':
                    loc2 = loc1
                loc1 = graveyard
            else:
                if loc2 == '':
                    loc2 = graveyard
        if road_or_gate != '':
            if loc1 == '':
                if loc2 == '':
                    loc2 = loc1
                loc1 = road_or_gate
            else:
                if loc2 == '':
                    loc2 = road_or_gate
        if count > 2:
            many = True
        else:
            if loc2 != '':
                loc2_oid = ''
                if u.is_city(loc2) or u.is_graveyard(loc2) or u.is_faeryhill(
                        loc2):
                    loc2_oid = to_oid(u.return_unitid(loc2))
                loc2_dict = {
                    'oid': loc2_oid,
                    'subkind': u.return_short_subkind(loc2),
                    'hidden': u.is_hidden(loc2)
                }
        if loc1 != '':
            loc1_oid = ''
            if u.is_city(loc1) or u.is_graveyard(loc1) or u.is_faeryhill(loc1):
                loc1_oid = to_oid(u.return_unitid(loc1))
            loc1_dict = {
                'oid': loc1_oid,
                'subkind': u.return_short_subkind(loc1),
                'hidden': u.is_hidden(loc1)
            }
    contents_dict = {
        'oid': to_oid(cell),
        'civ_level': get_civ_level(cell, loc_rec, data),
        'many': many,
        'castle_icon': castle_icon,
        'loc1_dict': loc1_dict,
        'loc2_dict': loc2_dict
    }
    return contents_dict
예제 #9
0
파일: item.py 프로젝트: akhand2222/olypy
def get_magic_item(data, item_id, item_rec):
    item_type = u.return_subkind(item_rec)
    if item_type == '0':
        if 'IM' in item_rec and 'uk' in item_rec['IM']:
            use_key = item_rec['IM']['uk'][0]
            if use_key == '2':
                magic_type = 'Healing Potion'
                magic_dict = {'oid': to_oid(item_id),
                              'name': get_name(item_rec),
                              'magic_type': magic_type}
                return magic_dict
            elif use_key == '5':
                loc_kind = 'unknown'
                loc_name = 'target'
                loc_id = ''
                if 'IM' in item_rec and 'pc' in item_rec['IM']:
                    loc_id = item_rec['IM']['pc'][0]
                    try:
                        location = data[loc_id]
                    except KeyError:
                        loc_kind = 'unknown'
                        loc_name = 'target'
                        loc_oid = to_oid(loc_id)
                    else:
                        loc_oid = to_oid(loc_id)
                        if u.return_kind(location) != 'loc':
                            loc_kind = u.return_kind(location)
                        else:
                            loc_kind = 'location'
                        loc_name = get_name(location)
                        loc_id = to_oid(u.return_unitid(location))
                else:
                    loc_id = '(no id)'
                    loc_oid = '(no id)'
                magic_type = 'Projected Cast'
                magic_dict = {'oid': to_oid(item_id),
                              'name': get_name(item_rec),
                              'loc_name': loc_name,
                              'loc_kind': loc_kind,
                              'loc_id': loc_id,
                              'loc_oid': loc_oid,
                              'magic_type': magic_type}
                return magic_dict
    elif item_type == 'scroll':
        magic_type = 'Scroll'
        # need to get skill_name
        magic_dict = {'oid': to_oid(item_id),
                      'name': get_name(item_rec),
                      'magic_type': magic_type,
                      'scroll_dict': get_may_study(item_rec, data)}
        return magic_dict
    elif item_type == 'artifact':
        magic_type = 'Artifact'
        magic_dict = {'oid': to_oid(item_id),
                      'name': get_name(item_rec),
                      'magic_type': magic_type,
                      'artifact_dict': get_item_bonuses(item_rec)}
        return magic_dict
    elif item_type == 'dead body':
        magic_type = 'Dead Body'
        magic_dict = {'oid': to_oid(item_id),
                      'name': get_name(item_rec),
                      'magic_type': magic_type,
                      'dead_body_dict': get_dead_body(item_rec, data)}
        return magic_dict
    elif item_type == 'npc_token':
        magic_type = 'NPC_Token'
        magic_dict = {'oid': to_oid(item_id),
                      'name': get_name(item_rec),
                      'magic_type': magic_type,
                      'dead_body_dict': get_dead_body(item_rec, data)}
        return magic_dict
    elif item_type == 'auraculum':
        magic_type = 'Auraculum'
        magic_dict = {'oid': to_oid(item_id),
                      'name': get_name(item_rec),
                      'magic_type': magic_type,
                      'aura': get_auraculum_aura(item_rec)}
        return magic_dict
    return None
예제 #10
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
예제 #11
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