예제 #1
0
파일: maps.py 프로젝트: olympiag3/olymap
def count_stuff(v, data):
    nbr_men = int(0)
    enemy_found = False
    ships_found = False
    seen_here_list = []
    level = 0
    k = u.return_unitid(v)
    seen_here_list = u.chase_structure(k, data, level, seen_here_list)
    list_length = len(seen_here_list)
    if list_length > 1:
        for un in seen_here_list[1:]:
            unit = data[un[0]]
            if 'char' in u.return_kind(unit):
                if 'il' in unit:
                    item_list = unit['il']
                    iterations = int(len(item_list) / 2)
                    for itemz in range(0, iterations):
                        itemz_rec = data[item_list[itemz * 2]]
                        if 'IT' in itemz_rec and 'pr' in itemz_rec['IT']:
                            if itemz_rec['IT']['pr'][0] == '1':
                                nbr_men = nbr_men + int(
                                    item_list[(itemz * 2) + 1])
                if 'CH' in unit:
                    if 'lo' in unit['CH'] and unit['CH']['lo'][0] == '100':
                        enemy_found = True
            elif u.return_kind(unit) == 'ship':
                ships_found = True
    return nbr_men, enemy_found, ships_found
예제 #2
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_sub_locs(loc, sub_loc, k, data, outf):
    outf.write('<li>')
    outf.write('{} [{}], {}'.format(sub_loc['na'][0],
                                    anchor(to_oid(k)),
                                    u.return_type(sub_loc)))
    if 'LO' in sub_loc and 'hi' in sub_loc['LO']:
        outf.write(', hidden')
    out_distance = u.calc_exit_distance(loc, sub_loc)
    if out_distance > 0:
        outf.write(', {} {}'.format(out_distance,
                                    'day' if out_distance == 1 else 'days'))
    if 'SL' in sub_loc and 'de' in sub_loc['SL']:
        outf.write(', defense {}'.format(sub_loc['SL']['de'][0]))
    if 'castle' in u.return_type(sub_loc):
        if 'SL' in sub_loc:
            if 'cl' in sub_loc['SL']:
                if sub_loc['SL']['cl'][0] != '0':
                    outf.write(', level {}'.format(sub_loc['SL']['cl'][0]))
    if 'mine' in u.return_type(sub_loc):
        if 'SL' in sub_loc and 'sd' in sub_loc['SL']:
            if sub_loc['SL']['sd'][0] != '0':
                outf.write(', level {}'.format(int(sub_loc['SL']['sd'][0]) / 3))
    if 'SL' in sub_loc:
        if 'eg' and 'er' in sub_loc['SL']:
            effort_given = int(sub_loc['SL']['eg'][0])
            effort_required = int(sub_loc['SL']['er'][0])
            pct_complete = int(float(effort_given / effort_required)*100)
            outf.write(', {}% completed'.format(pct_complete))
    if 'SL' in sub_loc and 'da' in sub_loc['SL']:
        outf.write(', {}% damaged'.format(sub_loc['SL']['da'][0]))
    if 'LI' in sub_loc and 'hl' in sub_loc['LI']:
        sub_here_list = sub_loc['LI']['hl']
        if len(sub_here_list) > 0:
            first_here = data[sub_here_list[0]]
            if u.return_kind(first_here) == 'char':
                outf.write(', owner:')
    outf.write('</li>\n')
    # see if stuff stacked under it
    if 'LI' in sub_loc and 'hl' in sub_loc['LI']:
        sub_here_list = sub_loc['LI']['hl']
        if len(sub_here_list) > 0:
            outf.write('<ul>\n')
            for sub_hl in sub_here_list:
                sub_sub_here = data[sub_hl]
                if u.return_kind(sub_sub_here) == 'loc':
                    write_sub_locs(sub_loc,
                                   sub_sub_here,
                                   sub_hl,
                                   data,
                                   outf)
                elif u.return_kind(sub_sub_here) == 'char':
                    write_characters(sub_sub_here,
                                     u.return_unitid(sub_sub_here),
                                     data, outf)
                elif u.return_kind(sub_sub_here) == 'ship':
                    write_ships(sub_sub_here,
                                u.return_unitid(sub_sub_here),
                                data,
                                outf)
            outf.write('</ul>\n')
예제 #3
0
파일: maps.py 프로젝트: pombredanne/olypy
def count_stuff(v, data):
    nbr_men = int(0)
    enemy_found = False
    ships_found = False
    seen_here_list = []
    level = 0
    k = u.return_unitid(v)
    seen_here_list = loop_here(data, k, False, True)
    list_length = len(seen_here_list)
    if list_length >= 1:
        for un in seen_here_list:
            unit = data[un]
            if 'char' in u.return_kind(unit):
                if 'il' in unit:
                    item_list = unit['il']
                    if len(item_list) > 0:
                        for itemz in range(0, len(item_list), 2):
                            itemz_rec = data[item_list[itemz]]
                            if 'IT' in itemz_rec and 'pr' in itemz_rec['IT']:
                                if itemz_rec['IT']['pr'][0] == '1':
                                    if 'an' in itemz_rec['IT']:
                                        if itemz_rec['IT']['an'][0] != '1':
                                            nbr_men = nbr_men + int(
                                                item_list[itemz + 1])
                                    else:
                                        nbr_men = nbr_men + int(
                                            item_list[itemz + 1])
                if 'CH' in unit:
                    if 'lo' in unit['CH'] and unit['CH']['lo'][0] == '100':
                        enemy_found = True
            elif u.return_kind(unit) == 'ship':
                ships_found = True
    return nbr_men, enemy_found, ships_found
예제 #4
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_ships(v, k, data, outf):
    outf.write('<li>\n')
    outf.write('{} [{}], {}'.format(v['na'][0],
                                    anchor(to_oid(k)),
                                    u.return_type(v)))
    if 'SL' in v:
        if 'bs' in v['SL']:
            storm = data[v['SL']['bs'][0]]
            if 'na' in storm:
                name = storm['na'][0]
            else:
                name = u.return_type(storm)
            outf.write(', bound {}-storm {} [{}] (strength: {})'.format(u.return_type(storm),
                                                                        name,
                                                                        anchor(to_oid(v['SL']['bs'][0])),
                                                                        storm['MI']['ss'][0]))
    if 'SL' in v:
        if 'de' in v['SL']:
            outf.write(', defense {}'.format(v['SL']['de'][0]))
        if 'eg' and 'er' in v['SL']:
            effort_given = int(v['SL']['eg'][0])
            effort_required = int(v['SL']['er'][0])
            pct_complete = int(float(effort_given / effort_required)*100)
            outf.write(', {}% completed'.format(pct_complete))
        if 'da' in v['SL']:
            outf.write(', {}% damaged'.format(v['SL']['da'][0]))
    pct_load = ship.calc_pct_loaded(data, k, v)
    if pct_load > 0:
        outf.write(', {}% loaded'.format(pct_load))
    if 'LI' in v and 'hl' in v['LI']:
        sub_here_list = v['LI']['hl']
        if len(sub_here_list) > 0:
            first_here = data[sub_here_list[0]]
            if u.return_kind(first_here) == 'char':
                outf.write(', owner:')
    outf.write('</li>\n')
    # see if stuff stacked under it
    if 'LI' in v and 'hl' in v['LI']:
        sub_here_list = v['LI']['hl']
        if len(sub_here_list) > 0:
            outf.write('<ul>\n')
            for sub_hl in sub_here_list:
                sub_sub_here = data[sub_hl]
                if u.return_kind(sub_sub_here) == 'loc':
                    write_sub_locs(v, sub_sub_here, sub_hl, data, outf)
                elif u.return_kind(sub_sub_here) == 'char':
                    write_characters(sub_sub_here,
                                     u.return_unitid(sub_sub_here),
                                     data, outf)
            outf.write('</ul>\n')
예제 #5
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_inner_locs(v, data, outf, here_list):
    outf.write('<ul>\n')
    if len(here_list) > 0:
        for here in here_list:
            here_rec = data[here]
            if u.return_kind(here_rec) == 'loc':
                write_sub_locs(v, here_rec, u.return_unitid(here_rec),
                               data, outf)
    if 'SL' in v:
        if 'lf' in v['SL']:
            link_from_record = data[v['SL']['lf'][0]]
            if u.return_kind(link_from_record) == 'loc':
                write_sub_locs(v, link_from_record, u.return_unitid(link_from_record),
                               data, outf)
    outf.write('</ul>\n')
예제 #6
0
파일: char.py 프로젝트: akhand2222/olypy
def get_priest_skills(v, data):
    visions_list = []
    skill_751 = None
    skill_753 = None
    if return_char_skill(v, '751') is not None:
        skill_751 = True if return_char_skill(
            v, '751')[0]['known'] == True else False
    if return_char_skill(v, '753') is not None:
        skill_753 = True if return_char_skill(
            v, '753')[0]['known'] == True else False
    if 'CM' in v and 'vi' in v['CM']:
        vision_list = v['CM']['vi']
        for vision in vision_list:
            try:
                visioned = data[vision]
            except KeyError:
                vision_name = 'missing'
                vision_id = None
                vision_oid = None
            else:
                vision_name = visioned.get('na', [u.return_kind(visioned)])[0]
                vision_id = vision
                vision_oid = to_oid(vision)
            vision_dict = {
                'id': vision_id,
                'oid': vision_oid,
                'name': vision_name
            }
            visions_list.append(vision_dict)
    priest_dict = {
        'skill751': skill_751,
        'skill753': skill_753,
        'visions': visions_list
    }
    return priest_dict
예제 #7
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_loc_routes_out(v, data, outf):
    if u.return_type(v) != 'city':
        write_province_destinations(v, data, outf)
    else:
        header_printed = False
        host_prov = data[v['LI']['wh'][0]]
        # If city is in a mountain, can't move from city to ocean
        if u.return_type(host_prov) != 'mountain':
            dest_loc_list = host_prov['LO']['pd']
            i = int(0)
            for pd in dest_loc_list:
                try:
                    pd_loc = data[pd]
                    if u.return_type(pd_loc) == 'ocean':
                        if not header_printed:
                            outf.write('<H4>Routes leaving {}:</H4\n'.format(v['na'][0]))
                            outf.write('<ul>\n')
                        pd_name = pd_loc['na'][0]
                        pd_loc_id = u.return_unitid(pd_loc)
                        out_distance = u.calc_exit_distance(v, pd_loc)
                        outf.write('<li>{}, to {} [{}], {}, {} {}</li>\n'
                                   .format(pd_directions[i],
                                           pd_name,
                                           anchor(to_oid(pd_loc_id)),
                                           data[u.region(pd_loc_id, data)]['na'][0],
                                           out_distance,
                                           'day' if out_distance == 1 else 'days'))
                except KeyError:
                    pass
                i = i + 1
        if not header_printed:
            outf.write('<H4>Routes leaving {}:</H4\n'.format(v['na'][0]))
            outf.write('<ul>\n')
        out_distance = u.calc_exit_distance(v, host_prov)
        outf.write('<li>Out, to {} [{}], {} {}</li>\n'
                   .format(host_prov['na'][0],
                           anchor(to_oid(u.return_unitid(host_prov))),
                           out_distance,
                           'day' if out_distance == 1 else 'days'))
        if 'LI' in v:
            if '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_record = data[here_record['GA']['tl'][0]]
                        if u.return_kind(here_record) == 'gate':
                            name = 'Gate'
                        else:
                            name = here_record['na'][0]
                        if not header_printed:
                            outf.write('<H4>Routes leaving {}:</H4\n'.format(v['na'][0]))
                            outf.write('<ul>\n')
                        write_province_destination(v,
                                                   to_record,
                                                   name,
                                                   data,
                                                   outf)
        if header_printed:
            outf.write('</ul>\n')
예제 #8
0
파일: item.py 프로젝트: akhand2222/olypy
def get_project_cast(v, data):
    projected_cast = v.get('IM', {}).get('pc', [None])
    projected_cast_id = projected_cast[0]
    if projected_cast_id is not None:
        try:
            projected_cast_rec = data[projected_cast_id]
            try:
                region_id = u.region(projected_cast_id, data)
                region_rec = data[region_id]
                region_oid = to_oid(region_id)
                region_name = get_name(region_rec)
            except KeyError:
                region_id = None
                region_oid = None
                region_name = None
            projected_dict = {'id': projected_cast_id,
                              'oid': to_oid(projected_cast_id),
                              'name': get_name(projected_cast_rec),
                              'kind': u.return_kind(projected_cast_rec),
                              'region_id': region_id,
                              'region_oid': region_oid,
                              'region_name': region_name}
        except KeyError:
            projected_dict = {'id': None,
                              'oid': to_oid(projected_cast_id)}
        return projected_dict
    return None
예제 #9
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_seen_here(data, outf, here_list):
    outf.write('<ul>\n')
    for here in here_list:
        here_rec = data[here]
        if u.return_kind(here_rec) == 'char':
            write_characters(here_rec, here, data, outf)
    outf.write('</ul>\n')
예제 #10
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_ships_docked(data, outf, here_list):
    outf.write('<ul>\n')
    for here in here_list:
        here_rec = data[here]
        if u.return_kind(here_rec) == 'ship':
            write_ships(here_rec, here, data, outf)
    outf.write('</ul>\n')
예제 #11
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_storms_here(data, outf, here_list):
    outf.write('<ul>\n')
    for here in here_list:
        here_rec = data[here]
        if u.return_kind(here_rec) == 'storm':
            write_storms(here_rec, here, outf)
    outf.write('</ul>\n')
예제 #12
0
파일: loc.py 프로젝트: pombredanne/olypy
def write_province_destinations(v, data, outf):
    print_header = False
    pd_list = ''
    if 'LO' in v:
        if 'pd' in v['LO']:
            pd_list = v['LO']['pd']
    if len(pd_list) > 0:
        i = int(0)
        for pd in pd_list:
            if pd != '0':
                if not print_header:
                    print_header = True
                    outf.write('<H4>Routes leaving {}:</H4>\n'.format(
                        v['na'][0]))
                    outf.write('<ul>\n')
                write_province_destination(v, data[pd], pd_directions[i], data,
                                           outf)
            i = i + 1
    if u.return_type(v) not in details.province_kinds:
        if 'LI' in v:
            if 'wh' in v['LI']:
                if not print_header:
                    print_header = True
                    outf.write('<H4>Routes leaving {}:</H4>\n'.format(
                        v['na'][0]))
                    outf.write('<ul>\n')
                out_rec = data[v['LI']['wh'][0]]
                write_province_destination(v, out_rec, 'Out', data, outf)
    # see if road or gate
    if 'LI' in v:
        if '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_record = data[here_record['GA']['tl'][0]]
                    if u.return_kind(here_record) == 'gate':
                        name = 'Gate'
                    else:
                        name = here_record['na'][0]
                    if not print_header:
                        print_header = True
                        outf.write('<H4>Routes leaving {}:</H4>\n'.format(
                            v['na'][0]))
                        outf.write('<ul>\n')
                    write_province_destination(v, to_record, name, data, outf)
    if 'SL' in v:
        if 'lt' in v['SL']:
            link_to_record = data[v['SL']['lt'][0]]
            if not print_header:
                print_header = True
                outf.write('<H4>Routes leaving {}:</H4>\n'.format(v['na'][0]))
                outf.write('<ul>\n')
            write_province_destination(v, link_to_record,
                                       u.return_type(link_to_record).title(),
                                       data, outf)
    if print_header:
        outf.write('</ul>\n')
예제 #13
0
def write_char_stacked_under(v, data, outf):
    # LI/wh
    if 'LI' in v and 'wh' in v['LI']:
        charu = data[v['LI']['wh'][0]]
        # if it's not a 'char' type, then it's a location/ship
        # and I handle that in location row
        if u.return_kind(charu) == 'char':
            outf.write('<tr>')
            outf.write('<td>Stacked Under:</td>')
            outf.write('<td>{} [{}]</td></tr>\n'.format(
                charu['na'][0], anchor(to_oid(u.return_unitid(charu)))))
예제 #14
0
파일: loc.py 프로젝트: pombredanne/olypy
def write_here_list(v, data, outf):
    print_inner = False
    seen_here = False
    ships_docked = False
    storms_here = False
    here_list = []
    try:
        here_list = v['LI']['hl']
    except KeyError:
        pass
    else:
        for here in here_list:
            here_rec = data[here]
            if u.return_kind(here_rec) == 'loc':
                print_inner = True
            elif u.return_kind(here_rec) == 'char':
                seen_here = True
            elif u.return_kind(here_rec) == 'ship':
                ships_docked = True
            elif u.return_kind(here_rec) == 'storm':
                storms_here = True
    try:
        inner_list = v['SL']['lf']
    except KeyError:
        pass
    else:
        if len(inner_list) > 0:
            print_inner = True
    if print_inner:
        outf.write('<H4>Inner Locations:</H4>\n')
        write_inner_locs(v, data, outf, here_list)
    if seen_here:
        outf.write('<H4>Seen Here:</H4>\n')
        write_seen_here(data, outf, here_list)
    if ships_docked:
        outf.write('<H4>{}:</H4>\n'.format('Ships docked' if u.return_type(v)
                                           != 'ocean' else 'Ships sighted'))
        write_ships_docked(data, outf, here_list)
    if storms_here:
        outf.write('<H4>Storms Here:</H4>\n')
        write_storms_here(data, outf, here_list)
예제 #15
0
파일: loc.py 프로젝트: akhand2222/olypy
def build_basic_loc_dict(k, v, data, garrisons_chain=None):
    loc_dict = {'oid': to_oid(k),
                'name': get_name(v),
                'subkind': get_subkind(v, data),
                'kind': u.return_kind(v),
                'where': get_where_info(v, data),
                'hidden': u.is_hidden(v),
                'structure': get_structure_info(v),
                'seen_here': get_here_list(k, v, data),
                'region': get_region(k, data),
                'garrisons': get_garrisons(k, v, data, garrisons_chain),}
    return loc_dict
예제 #16
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
예제 #17
0
def write_box_pages(data, chains, outdir, instance, inst_dict, map_matrices):
    print('Writing box pages')
    for k, v in data.items():
        if u.is_loc(v):
            write_loc_html(v, k, data, chains['hidden'], chains['garrisons'],
                           chains['trades'], outdir, instance, inst_dict,
                           map_matrices)
        elif u.is_char(v):
            write_char_html(v, k, data, chains['pledges'], chains['prisoners'],
                            outdir, instance)
        elif u.is_player(v):
            write_player_html(v, k, data, outdir)
        elif u.is_item(v):
            write_item_html(v, k, data, chains['trades'], outdir)
        elif u.is_ship(v):
            write_ship_html(v, k, data, outdir, instance, chains['pledges'],
                            chains['prisoners'])
        elif u.is_skill(v):
            write_skill_html(v, k, data, outdir, chains['teaches'],
                             chains['child_skills'], chains['skills_knowns'])
        elif u.return_kind(v) == 'storm':
            write_storm_html(v, k, data, chains['storms'], outdir)
예제 #18
0
def write_box_pages(data, chains, outdir, instance, inst_dict, map_matrices):
    print('Writing box pages')
    for k, v in data.items():
        if u.return_kind(v) == 'loc':
            loc.write_loc_html(v, k, data, chains['hidden'], chains['garrisons'],
                               chains['trades'], outdir, instance, inst_dict, map_matrices)
        elif u.return_kind(v) == 'char':
            char.write_char_html(v, k, data, chains['pledges'],
                                 chains['prisoners'], outdir, instance)
        elif u.return_kind(v) == 'player':
            player.write_player_html(v, k, data, outdir)
        elif u.return_kind(v) == 'item':
            itm.write_item_html(v, k, data, chains['trades'], outdir)
        elif u.return_kind(v) == 'ship':
            ship.write_ship_html(v, k, data, outdir)
        elif u.return_kind(v) == 'skill':
            skill.write_skill_html(v, k, data, chains['teaches'],
                                   chains['child_skills'], chains['skills_knowns'],
                                   outdir)
        elif u.return_kind(v) == 'storm':
            storm.write_storm_html(v, k, data, chains['storms'], outdir)
예제 #19
0
파일: ship.py 프로젝트: pombredanne/olypy
def write_ship_seen_here(v, k, data, outf):
    label1 = 'Seen Here:'
    # seen_here_list = loop_here(data, k, False, True)
    # list_length = len(seen_here_list)
    # if list_length > 1:
    #     for un in seen_here_list:
    #         char = data[un]
    #         outf.write('<tr>')
    #         outf.write('<td>{}</td>'.format(label1))
    #         outf.write('<td>{} [{}]</td></tr>\n'.format(char['na'][0],
    #                                                        anchor(to_oid(u.return_unitid(char)))))
    #         label1 = '&nbsp;'
    if 'LI' in v and 'hl' in v['LI']:
        sub_here_list = v['LI']['hl']
        if len(sub_here_list) > 0:
            outf.write('<p>Seen Here:</p>\n')
            outf.write('<ul>\n')
            for sub_hl in sub_here_list:
                sub_sub_here = data[sub_hl]
                if u.return_kind(sub_sub_here) == 'char':
                    write_characters(sub_sub_here,
                                     u.return_unitid(sub_sub_here), data, outf)
            outf.write('</ul>\n')
예제 #20
0
파일: ship.py 프로젝트: olympiag3/olymap
def calc_pct_loaded(data, k, v):
    total_weight = 0
    try:
        damaged = int(v['SL']['da'][0])
    except KeyError:
        damaged = 0
    seen_here_list = []
    level = 0
    seen_here_list = u.chase_structure(k, data, level, seen_here_list)
    list_length = len(seen_here_list)
    if list_length > 1:
        for un in seen_here_list[1:]:
            char = data[un[0]]
            if u.return_kind(char) == 'char':
                unit_type = '10'
                if 'CH' in char and 'ni' in char['CH']:
                    unit_type = char['CH']['ni'][0]
                base_unit = data[unit_type]
                if 'IT' in base_unit and 'wt' in base_unit['IT']:
                    item_weight = int(base_unit['IT']['wt'][0]) * 1
                    total_weight = total_weight + item_weight
                if 'il' in char:
                    item_list = char['il']
                    iterations = int(len(item_list) / 2)
                    for itm in range(0, iterations):
                        itemz = data[item_list[itm * 2]]
                        try:
                            item_weight = int(itemz['IT']['wt'][0])
                        except KeyError:
                            item_weight = int(0)
                        qty = int(item_list[(itm * 2) + 1])
                        total_weight = total_weight + int(qty * item_weight)
    ship_capacity = int(v['SL']['ca'][0])
    actual_capacity = int(ship_capacity - ((ship_capacity * damaged) / 100))
    pct_loaded = math.floor((total_weight * 100) / actual_capacity)
    return pct_loaded
예제 #21
0
파일: loc.py 프로젝트: olympiag3/olymap
def write_loc_market_report(v, k, data, outf, trade_chain):
    try:
        trade_list = v['tl']
    except KeyError:
        return
    # load city/character trades
    city_trade_list = []
    if len(trade_list) > 0:
        # city trades
        iterations = int(len(trade_list) / 8)
        for trade in range(0, iterations):
            if trade_list[(trade * 8) + 0] in {'1', '2'}:
                city_trade_list.append([trade_list[(trade * 8) + 0],
                                        trade_list[(trade * 8) + 1],
                                        k,
                                        trade_list[(trade * 8) + 2],
                                        trade_list[(trade * 8) + 3]])
        # character trades - needs to be recursive
        if 'LI' in v and 'hl' in v['LI']:
            seen_here_list = v['LI']['hl']
        else:
            seen_here_list = []
        list_length = len(seen_here_list)
        if list_length > 1:
            for un in seen_here_list[1:]:
                charac_rec = data[un]
                if u.return_kind(charac_rec) == 'char':
                    if 'tl' in charac_rec:
                        trade_list = charac_rec['tl']
                        if len(trade_list) > 0:
                            # character trades
                            iterations = int(len(trade_list) / 8)
                            for trade in range(0, iterations):
                                if trade_list[(trade * 8) + 0] in {'1', '2'}:
                                    city_trade_list.append([trade_list[(trade * 8) + 0],
                                                            trade_list[(trade * 8) + 1],
                                                            un,
                                                            trade_list[(trade * 8) + 2],
                                                            trade_list[(trade * 8) + 3]])
    if len(city_trade_list) > 0:
        sorted_list = sorted(city_trade_list, key=itemgetter(0, 1, 2))
        outf.write('<H4>Market Report:</H4>\n')
        outf.write('<table border="1" cellpadding="5">\n')
        outf.write('<tr>')
        outf.write('<th>trade</th><th>who</th><th>price</th><th>qty</th><th>wt/ea</th><th>item</th>'
                   '<th>recip who</th><th>recip price</th><th>recip qty</th>\n')
        outf.write('</tr>\n')
        for trade in sorted_list:
            if trade[0] in {'1', '2'}:
                trade_kind = 'buy' if trade[0] == '1' else 'sell'
                item_rec = data[trade[1]]
                trade_item = anchor(to_oid(trade[1]))
                trade_qty = trade[3]
                trade_price = trade[4]
                trade_who = anchor(to_oid(trade[2]))
                trade_recip = trade_chain[trade[1]]
                recip_name = ''
                recip_loc = '0'
                recip_rec = ''
                if len(trade_recip) > 0:
                    for recip in trade_recip:
                        if recip[0] != k:
                            recip_type = recip[1]
                            if recip_type != trade[0]:
                                recip_loc = recip[0]
                                recip_rec = data[recip_loc]
                                recip_name = recip_rec['na'][0]
                outf.write('<tr>')
                outf.write('<td>{}</td>\n'.format(trade_kind))
                outf.write('<td>{}</td>\n'.format(trade_who))
                outf.write('<td>{}</td>\n'.format(trade_price))
                outf.write('<td>{}</td>\n'.format(trade_qty))
                outf.write('<td>{}</td>\n'.format(item_rec['IT']['wt'][0]))
                outf.write('<td>{} [{}]</td>\n'.format(item_rec['na'][0], trade_item))
                if recip_loc != '0':
                    outf.write('<td>{} [{}]</td>\n'.format(recip_name,
                                                           anchor(to_oid(recip_loc))))
                    recip_trade_list = recip_rec['tl']
                    recip_iterations = int(len(recip_trade_list) / 8)
                    for recip in range(0, recip_iterations):
                        if recip_trade_list[(recip * 8) + 1] == trade[1]:
                            if recip_trade_list[(recip * 8) + 0] in {'1', '2'}:
                                recip_qty = recip_trade_list[(recip * 8) + 2]
                                recip_price = recip_trade_list[(recip * 8) + 3]
                                outf.write('<td>{}</td>\n'.format(recip_price))
                                outf.write('<td>{}</td>\n'.format(recip_qty))
                else:
                    outf.write('<td>&nbsp;</td>\n')
                    outf.write('<td>&nbsp;</td>\n')
                    outf.write('<td>&nbsp;</td>\n')
            outf.write('</tr>\n')
        outf.write('</table>\n')
예제 #22
0
파일: maps.py 프로젝트: pombredanne/olypy
def generate_cell_contents(castle_chain, cell, data, loc_rec, outf):
    if 'LO' in loc_rec and 'lc' in loc_rec['LO']:
        if loc_rec['LO']['lc'][0] != '0':
            outf.write('<b>')
    a = to_oid(cell)
    outf.write('{}'.format(anchor(to_oid(cell))))
    if 'LO' in loc_rec and 'lc' in loc_rec['LO']:
        if loc_rec['LO']['lc'][0] != '0':
            outf.write('</b>')
    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.return_type(garr_rec) == 'garrison':
                if 'MI' in garr_rec:
                    if 'gc' in garr_rec['MI']:
                        castle_id = garr_rec['MI']['gc'][0]
                        outf.write('{}'.format(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_type(
                        here_rec) in details.subloc_kinds or u.is_road_or_gate(
                            here_rec):
                    count = count + 1
                    if u.return_type(here_rec) == 'city':
                        city = here_rec
                    elif u.return_type(here_rec) == 'graveyard':
                        graveyard = here_rec
                    elif u.is_road_or_gate(here_rec):
                        road_or_gate = here_rec
                    elif loc1 == '' and u.return_kind(here_rec) == 'loc':
                        loc1 = here_rec
                    elif loc2 == '' and u.return_kind(here_rec) == 'loc':
                        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
    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:
            outf.write('<br />many')
        else:
            if loc2 != '':
                if u.return_type(loc2) == 'city' or u.return_type(
                        loc2) == 'graveyard' or u.return_type(
                            loc2) == 'faery hill':
                    outf.write('<br />')
                    outf.write('{}'.format(
                        anchor2(to_oid(u.return_unitid(loc2)),
                                u.return_short_type(loc2))))
                else:
                    outf.write('<br />')
                    if 'LO' in loc2 and 'hi' in loc2['LO']:
                        if loc2['LO']['hi'][0] == '1':
                            outf.write('<i>')
                    outf.write(u.return_short_type(loc2))
                    if 'LO' in loc2:
                        if 'hi' in loc2['LO'] and loc2['LO']['hi'][0] == '1':
                            outf.write('</i>')
            else:
                outf.write('<br />&nbsp;')
        if loc1 != '':
            if u.return_type(loc1) == 'city' or u.return_type(
                    loc1) == 'graveyard' or u.return_type(
                        loc1) == 'faery hill':
                outf.write('<br />')
                outf.write('{}'.format(
                    anchor2(to_oid(u.return_unitid(loc1)),
                            u.return_short_type(loc1))))
            else:
                outf.write('<br />')
                if 'LO' in loc1 and 'hi' in loc1['LO']:
                    if loc1['LO']['hi'][0] == '1':
                        outf.write('<i>')
                outf.write(u.return_short_type(loc1))
                if 'LO' in loc1 and 'hi' in loc1['LO']:
                    if loc1['LO']['hi'][0] == '1':
                        outf.write('</i>')
        else:
            outf.write('<br />&nbsp;')
예제 #23
0
def write_char_magic_stuff(v, data, outf):
    if 'il' in v:
        item_list = v['il']
        for items in range(0, len(item_list), 2):
            try:
                itemz = data[item_list[items]]
            except KeyError:
                pass
            else:
                item_type = u.return_type(itemz)
                if item_type == '0':
                    if 'IM' in itemz and 'uk' in itemz['IM']:
                        use_key = itemz['IM']['uk'][0]
                        if use_key == '2':
                            outf.write('<p>Healing Potion [{}]</p>\n'.format(
                                anchor(to_oid(item_list[items]))))
                        elif use_key == '5':
                            loc_kind = 'unknown'
                            loc_name = 'unknown'
                            loc_id = ''
                            if 'IM' in itemz and 'pc' in itemz['IM']:
                                try:
                                    location = data[itemz['IM']['pc'][0]]
                                except KeyError:
                                    loc_kind = 'unknown'
                                    loc_name = 'unknown'
                                    loc_id = to_oid(itemz['IM']['pc'][0])
                                else:
                                    loc_id = anchor(
                                        to_oid(itemz['IM']['pc'][0]))
                                    if u.return_kind(location) != 'loc':
                                        loc_kind = u.return_kind(location)
                                    else:
                                        loc_kind = 'location'
                                    loc_name = location.get('na',
                                                            ['unknown'])[0]
                                    loc_id = anchor(
                                        to_oid(u.return_unitid(location)))
                            else:
                                loc_id = '(no id)'
                            anch = anchor(to_oid(item_list[items]))
                            outf.write(
                                '<p>Projected Cast [{}] to {} {}'.format(
                                    anch, loc_kind, loc_name))
                            if loc_id != '':
                                outf.write(' [{}]'.format(loc_id))
                            outf.write('</p>\n')
                elif item_type == 'scroll':
                    if 'IM' in itemz and 'ms' in itemz['IM']:
                        skill_id = anchor(to_oid(itemz['IM']['ms'][0]))
                        scroll_id = anchor(to_oid(item_list[items]))
                        required_study = ''
                        try:
                            skill = data[itemz['IM']['ms'][0]]
                        except KeyError:
                            skill_name = 'unknown'
                        else:
                            skill_name = skill['na'][0]
                            if 'SK' in skill:
                                if 'rs' in skill['SK']:
                                    try:
                                        skill2 = data[skill['SK']['rs'][0]]
                                    except KeyError:
                                        skill2_name = 'unknown'
                                    else:
                                        skill2_name = skill2.get(
                                            'na', ['unknown'])[0]
                                    anch = anchor(to_oid(skill['SK']['rs'][0]))
                                    required_study = '(requires {} [{}])'.format(
                                        skill2_name, anch)
                        outf.write(
                            '<p>Scroll [{}] permits the study of the following skills:<br>&nbsp;&nbsp;&nbsp;'
                            '{} [{}] {}</p>\n'.format(scroll_id, skill_name,
                                                      skill_id,
                                                      required_study))
예제 #24
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
예제 #25
0
파일: loc.py 프로젝트: akhand2222/olypy
def get_markets(k, v, data, trade_chain):
    markets_list = []
    trade_list = []
    if 'tl' in v:
        trade_list = v['tl']
    # load city/character trades
    if len(trade_list) > 0:
        # city trades
        for trade in range(0, len(trade_list), 8):
            if trade_list[trade] in {'1', '2'}:
                item_rec = data[trade_list[trade+1]]
                trade_recip = trade_chain[trade_list[trade + 1]]
                recip_list = []
                if len(trade_recip) > 0:
                    for recip in trade_recip:
                        if recip[0] != k:
                            recip_type = recip[1]
                            if recip_type != trade_list[trade]:
                                recip_loc = recip[0]
                                recip_rec = data[recip_loc]
                                recip_name = get_name(recip_rec)
                                recip_trade_list = recip_rec['tl']
                                for recip in range(0, len(recip_trade_list), 8):
                                    if recip_trade_list[recip + 1] == trade_list[trade+1]:
                                        if recip_trade_list[recip] in {'1', '2'}:
                                            recip_qty = recip_trade_list[recip + 2]
                                            recip_price = recip_trade_list[recip + 3]
                                recip_dict = {'loc_id': recip_loc,
                                              'loc_oid': to_oid(recip_loc),
                                              'name': recip_name,
                                              'qty': recip_qty,
                                              'price': recip_price}
                                recip_list.append(recip_dict)
                market_dict = {'subkind': trade_list[trade],
                               'item_id': trade_list[trade + 1],
                               'item_oid': to_oid(trade_list[trade + 1]),
                               'item_name': get_name(item_rec),
                               'item_weight': get_item_weight(item_rec),
                               'who_id': k,
                               'who_oid': to_oid(k),
                               'who_name': get_name(v),
                               'who_qty': trade_list[trade + 2],
                               'who_price': trade_list[trade + 3],
                               'recip_list': recip_list}
                markets_list.append(market_dict)
        # character trades - needs to be recursive
        seen_here_list = loop_here2(data, k, 0, False, False, True)
        if len(seen_here_list) > 1:
            for un in seen_here_list[1:]:
                charac_rec = data[un[0]]
                if u.return_kind(charac_rec) == 'char':
                    if 'tl' in charac_rec:
                        trade_list = charac_rec['tl']
                        if len(trade_list) > 0:
                            # character trades
                            for trade in range(0, len(trade_list), 8):
                                if trade_list[trade] in {'1', '2'}:
                                    item_rec = data[trade_list[trade + 1]]
                                    trade_recip = trade_chain[trade_list[trade + 1]]
                                    recip_list = []
                                    if len(trade_recip) > 0:
                                        for recip in trade_recip:
                                            if recip[0] != k:
                                                recip_type = recip[1]
                                                if recip_type != trade_list[trade]:
                                                    recip_loc = recip[0]
                                                    recip_rec = data[recip_loc]
                                                    recip_name = get_name(recip_rec)
                                                    recip_trade_list = recip_rec['tl']
                                                    for recip in range(0, len(recip_trade_list), 8):
                                                        if recip_trade_list[recip + 1] == trade_list[trade + 1]:
                                                            if recip_trade_list[recip] in {'1', '2'}:
                                                                recip_qty = recip_trade_list[recip + 2]
                                                                recip_price = recip_trade_list[recip + 3]
                                                    recip_dict = {'loc_id': recip_loc,
                                                                  'loc_oid': to_oid(recip_loc),
                                                                  'name': recip_name,
                                                                  'qty' : recip_qty,
                                                                  'price' : recip_price}
                                                    recip_list.append(recip_dict)
                                    market_dict = {'subkind': trade_list[trade],
                                                   'item_id': trade_list[trade + 1],
                                                   'item_oid': to_oid(trade_list[trade + 1]),
                                                   'item_name': get_name(item_rec),
                                                   'item_weight': get_item_weight(item_rec),
                                                   'who_id': un[0],
                                                   'who_oid': to_oid(un[0]),
                                                   'who_name': get_name(charac_rec),
                                                   'who_qty': trade_list[trade + 2],
                                                   'who_price': trade_list[trade + 3],
                                                   'recip_list' : recip_list}
                                    markets_list.append(market_dict)
    sorted_list = sorted(markets_list, key=itemgetter('subkind', 'item_oid', 'who_oid'))
    return sorted_list
예제 #26
0
파일: loc.py 프로젝트: akhand2222/olypy
def get_here_list(k, v, data):
    inner_list_final = []
    seen_list_final = []
    ships_list_final = []
    storms_list_final = []
    if 'LI' in v and 'hl' in v['LI']:
        inner_list = loop_here2(data, k, 0, False, True, False, 'loc')
        seen_list = loop_here2(data, k, 0, False, False, False, 'char')
        ship_list = loop_here2(data, k, 0, False, False, False, 'ship')
        storm_list = loop_here2(data, k, 0, False, False, False, 'storm')
        if len(inner_list) > 0:
            for here in inner_list:
                here_rec = data[here[0]]
                if u.is_loc(here_rec):
                    inner_dict = build_basic_loc_dict(here[0], here_rec, data)
                    inner_dict.update({'level': here[1]})
                    inner_list_final.append(inner_dict)
                elif u.is_char(here_rec):
                    inner_dict = build_basic_char_dict(here[0], here_rec, data, True)
                    inner_dict.update({'level': here[1]})
                    inner_list_final.append(inner_dict)
                elif u.return_kind(here_rec) == 'storm':
                    inner_dict = build_basic_storm_dict(here[0], here_rec, data)
                    inner_dict.update({'level': here[1]})
                    inner_list_final.append(inner_dict)
                elif u.is_ship(here_rec):
                    inner_dict = build_basic_ship_dict(here[0], here_rec, data)
                    inner_dict.update({'level': here[1]})
                    inner_list_final.append(inner_dict)
                # else:
                #     print('here_list unknown {} {}'.format(here[0], u.return_kind(here_rec)))
        if len(seen_list) > 0:
            for seen in seen_list:
                seen_rec = data[seen[0]]
                seen_dict = build_basic_char_dict(seen[0], seen_rec, data, True)
                seen_dict.update({'level': seen[1]})
                seen_list_final.append(seen_dict)
        if len(ship_list) > 0:
            for ship in ship_list:
                ship_rec = data[ship[0]]
                if u.is_ship(ship_rec):
                    ship_dict = build_basic_ship_dict(ship[0], ship_rec, data)
                    ship_dict.update({'level': ship[1]})
                    ships_list_final.append(ship_dict)
                elif u.is_char(ship_rec):
                    ship_dict = build_basic_char_dict(ship[0], ship_rec, data, True)
                    ship_dict.update({'level': ship[1]})
                    ships_list_final.append(ship_dict)
                else:
                    print('ship_list unknown {}'.format(ship[0]))
        if len(storm_list) > 0:
            for storm in storm_list:
                storm_rec = data[storm[0]]
                storm_dict = build_basic_storm_dict(storm[0], storm_rec, data)
                storm_dict.update({'level': storm[1]})
                storms_list_final.append(storm_dict)
    if 'SL' in v and 'lf' in v['SL']:
        here = v['SL']['lf'][0]
        here_rec = data[here]
        if u.is_loc(here_rec):
            inner_dict = build_basic_loc_dict(here, here_rec, data)
            inner_dict.update({'level': 0})
            inner_list_final.append(inner_dict)
    here_dict = {'id': k,
                 'oid': to_oid(k),
                 'inner': inner_list_final,
                 'seen': seen_list_final,
                 'ships': ships_list_final,
                 'storms': storms_list_final}
    return here_dict
예제 #27
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