Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
def write_loc_controlled_by(v, data, outf):
    if 'LI' in v and 'hl' in v['LI']:
        here_list = v['LI']['hl']
        if len(here_list) > 0:
            for loc in here_list:
                try:
                    charac = data[loc]
                except KeyError:
                    pass
                else:
                    if 'MI' in charac and 'gc' in charac['MI']:
                        if charac['MI']['gc'][0] != '0':
                            dest_loc = data[charac['MI']['gc'][0]]
                            dest_loc2 = data[dest_loc['LI']['wh'][0]]
                            outf.write('<p>Province controlled by ')
                            dest_name = dest_loc['na'][0]
                            dest_id = anchor(to_oid(u.return_unitid(dest_loc)))
                            dest_type = u.return_type(dest_loc)
                            outf.write('{} [{}], {}'.format(
                                dest_name, dest_id, dest_type))
                            dest_type2 = u.return_type(dest_loc2)
                            if dest_type2 != 'city':
                                dest_name2 = dest_loc2['na'][0]
                                dest_id2 = anchor(
                                    to_oid(u.return_unitid(dest_loc2)))
                                outf.write(', in {} [{}]'.format(
                                    dest_name2, dest_id2))
                            else:
                                dest_loc2 = data[dest_loc2['LI']['wh'][0]]
                                dest_name2 = dest_loc2['na'][0]
                                dest_id2 = anchor(
                                    to_oid(u.return_unitid(dest_loc2)))
                                outf.write(', in {} [{}]'.format(
                                    dest_name2, dest_id2))
                            try:
                                garrison = data[dest_loc2['LI']['hl'][0]]
                            except KeyError:
                                pass
                            else:
                                garr_type = u.return_type(garrison)
                                if garr_type == 'garrison':
                                    # calculate top of pledge chain
                                    if 'LI' in dest_loc and 'hl' in dest_loc[
                                            'LI']:
                                        top_guy = u.top_ruler(
                                            dest_loc['LI']['hl'][0], data)
                                        try:
                                            top_dog = data[top_guy]
                                        except KeyError:
                                            pass
                                        else:
                                            a = top_dog['na'][0]
                                            b = anchor(to_oid(top_guy))
                                            outf.write(
                                                '<br>Ruled by {} [{}]'.format(
                                                    a, b))
                            outf.write('</p>\n')
Ejemplo n.º 4
0
def create_loc_to_dict_entry(data, direction, to_loc_rec, from_loc_rec, region_rec):
    to_dict = {'id': u.return_unitid(to_loc_rec),
               'oid': to_oid(u.return_unitid(to_loc_rec)),
               'name': get_name(to_loc_rec),
               'subkind': get_subkind(to_loc_rec, data),
               'is_port': u.is_port_city(to_loc_rec, data),
               'prov_port': u.province_has_port_city(to_loc_rec, data),
               'region_oid': to_oid(u.return_unitid(region_rec)),
               'region_name': get_name(region_rec),
               'direction': direction,
               'barrier': get_barrier(u.return_unitid(to_loc_rec), to_loc_rec, data),
               'distance': u.calc_exit_distance(from_loc_rec, to_loc_rec),
               'impassable': is_impassable(from_loc_rec, to_loc_rec, direction, data)}
    return to_dict
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
def write_unit_list(data, outf, v):
    if 'PL' in v and 'un' in v['PL']:
        unit_list = v['PL']['un']
        unit_list.sort()
        outf.write('<tr><td valign="top">Unit List:</td><td>')
        outf.write('<table>\n')
        columns = int(math.ceil(len(unit_list) / 3))
        for unit in range(0, columns):
            outf.write('<tr>')
            if (columns * 0) + unit < len(unit_list):
                char = data[unit_list[(columns * 0) + unit]]
                if 'na' in char:
                    name = char['na'][0]
                else:
                    name = u.return_type(char).capitalize()
                if name == 'Ni':
                    name = data[char['CH']['ni'][0]]['na'][0].capitalize()
                outf.write('<td>{} [{}]</td>'.format(name,
                                                     anchor(to_oid(u.return_unitid(char)))))
            else:
                outf.write('<td></td>')
            if (columns * 1) + unit < len(unit_list):
                char = data[unit_list[(columns * 1) + unit]]
                if 'na' in char:
                    name = char['na'][0]
                else:
                    name = u.return_type(char).capitalize()
                if name == 'Ni':
                    name = data[char['CH']['ni'][0]]['na'][0].capitalize()
                outf.write('<td>{} [{}]</td>'.format(name,
                                                     anchor(to_oid(u.return_unitid(char)))))
            else:
                outf.write('<td></td><td></td>')
            if (columns * 2) + unit < len(unit_list):
                char = data[unit_list[(columns * 2) + unit]]
                if 'na' in char:
                    name = char['na'][0]
                else:
                    name = u.return_type(char).capitalize()
                if name == 'Ni':
                    name = data[char['CH']['ni'][0]]['na'][0].capitalize()
                outf.write('<td>{} [{}]</td>'.format(name,
                                                     anchor(to_oid(u.return_unitid(char)))))
            else:
                outf.write('<td></td><td></td>')
            outf.write('</tr>\n')
        outf.write('</table>\n')
        outf.write('</td></tr>')
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def write_loc_page_header(v, k, data, outf):
    outf.write('<H3>')
    loc_type = u.return_type(v)
    outf.write('{} [{}]'.format(v['na'][0], to_oid(k)))
    outf.write(', {}'.format(loc_type))
    if u.return_type(v) != 'region':
        outf.write(', in')
        if loc_type == 'city':
            outf.write(' province ')
        try:
            loc2 = data[v['LI']['wh'][0]]
            outf.write(' {} [{}]'.format(loc2['na'][0],
                                         anchor(to_oid(u.return_unitid(loc2)))))
        except KeyError:
            pass
    # if 'city' in loc_type:
    #    outf.write(' [{}]'.format(anchor(to_oid(v['LI']['wh'][0]))))
    if 'SL' in v and 'sh' in v['SL']:
        outf.write(', safe haven')
    if 'LO' in v and 'hi' in v['LO']:
        outf.write(', hidden')
    if loc_type != 'ocean' and u.loc_depth(u.return_type(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]
        outf.write(', {}'.format(civ_level))
    outf.write('</H3>\n')
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def write_char_pledged_to(v, data, outf):
    # CM/pl
    if 'CM' in v and 'pl' in v['CM']:
        pledged_to = data[v['CM']['pl'][0]]
        outf.write('<tr>')
        outf.write('<td>Pledged To:</td>')
        outf.write('<td>{} [{}]</td></tr>\n'.format(
            pledged_to['na'][0], anchor(to_oid(u.return_unitid(pledged_to)))))
Ejemplo n.º 11
0
def write_char_faction(v, data, outf):
    # CH/lo
    if 'CH' in v and 'lo' in v['CH']:
        player = data[v['CH']['lo'][0]]
        outf.write('<tr>')
        outf.write('<td>Faction:</td>')
        outf.write('<td>{} [{}]</td></tr>\n'.format(
            player['na'][0], anchor(to_oid(u.return_unitid(player)))))
Ejemplo n.º 12
0
def print_wearable_wielding(v, data, outf):
    attack_max = 0
    missile_max = 0
    defense_max = 0
    attack = ''
    missile = ''
    defense = ''
    if 'il' in v:
        item_list = v['il']
        if len(item_list) > 0:
            for items in range(0, len(item_list), 2):
                itemz = data[item_list[items]]
                if 'IM' in itemz:
                    if 'ab' in itemz['IM']:
                        if int(itemz['IM']['ab'][0]) > attack_max:
                            attack_max = int(itemz['IM']['ab'][0])
                            attack = u.return_unitid(itemz)
                    if 'mb' in itemz['IM']:
                        if int(itemz['IM']['mb'][0]) > missile_max:
                            missile_max = int(itemz['IM']['mb'][0])
                            missile = u.return_unitid(itemz)
                    if 'db' in itemz['IM']:
                        if int(itemz['IM']['db'][0]) > defense_max:
                            defense_max = int(itemz['IM']['db'][0])
                            defense = u.return_unitid(itemz)
        # found something
        if attack != '' or missile != '' or defense != '':
            if attack == missile:
                missile = ''
        if attack == defense:
            defense = ''
        if attack != '' or missile != '':
            if attack == '':
                missile_rec = data[missile]
                outf.write(', wielding {} [{}]'.format(
                    missile_rec['na'][0],
                    anchor(to_oid(u.return_unitid(missile_rec)))))
            elif missile == '':
                attack_rec = data[attack]
                outf.write(', wielding {} [{}]'.format(
                    attack_rec['na'][0],
                    anchor(to_oid(u.return_unitid(attack_rec)))))
            else:
                missile_rec = data[missile]
                attack_rec = data[attack]
                outf.write(', wielding {} [{}] and {} [{}]'.format(
                    attack_rec['na'][0],
                    anchor(to_oid(u.return_unitid(attack_rec))),
                    missile_rec['na'][0],
                    anchor(to_oid(u.return_unitid(missile_rec)))))
        if defense != '':
            defense_rec = data[defense]
            outf.write(', wearing {} [{}]'.format(
                defense_rec['na'][0],
                anchor(to_oid(u.return_unitid(defense_rec)))))
Ejemplo 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)))))
Ejemplo n.º 14
0
def generate_border(data, loc_rec, outf, instance):
    nbr_men, enemy_found, ships_found = count_stuff(loc_rec, data)
    if enemy_found:
        if instance in {'g2', 'qa'}:
            enemy_found = False
    border_dict = {
        'barrier': get_barrier(u.return_unitid(loc_rec), loc_rec, data),
        'nbr_men': int(nbr_men),
        'ships_found': ships_found,
        'enemy_found': enemy_found
    }
    return border_dict
Ejemplo n.º 15
0
def write_char_stacked_over(v, data, outf):
    # LI/hl
    if 'LI' in v and 'hl' in v['LI']:
        over_list = v['LI']['hl']
        stacked_over = 'Stacked Over:'
        for ov in over_list:
            charo = data[ov]
            outf.write('<tr>')
            outf.write('<td>{}</td>'.format(stacked_over))
            outf.write('<td>{} [{}]</td></tr>\n'.format(
                charo['na'][0], anchor(to_oid(u.return_unitid(charo)))))
            stacked_over = ''
Ejemplo n.º 16
0
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
Ejemplo n.º 17
0
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')
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
def write_ship_owner(v, data, outf):
    if 'LI' in v and 'hl' in v['LI']:
        units = v['LI']['hl']
    else:
        units = '???'
    if units != '???':
        char = data[units[0]]
        outf.write('<tr>')
        outf.write('<td>Owner:</td>')
        outf.write('<td>{} [{}]</td></tr>\n'.format(
            char['na'][0], anchor(to_oid(u.return_unitid(char)))))
    else:
        outf.write('<tr>')
        outf.write('<td>Owner:</td>')
        outf.write('<td>unoccupied</td></tr>\n')
Ejemplo n.º 20
0
def write_ship_seen_here(k, data, outf):
    label1 = 'Seen Here:'
    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]]
            depth = un[1] - 1
            outf.write('<tr>')
            outf.write('<td>{}</td>'.format(label1))
            outf.write('<td>{} {} [{}]</td></tr>\n'.format(
                '.' * depth, char['na'][0],
                anchor(to_oid(u.return_unitid(char)))))
            label1 = '&nbsp;'
Ejemplo n.º 21
0
def get_routes_out(k, v, data):
    routes_out_list = []
    if not u.is_city(v):
        dest_dict = get_destinations(k, v, data)
    else:
        dest_list = []
        host_prov_id = v['LI']['wh'][0]
        host_prov_rec = data[host_prov_id]
        # If city is in a mountain, can't move from city to ocean
        if not u.is_mountain(host_prov_rec):
            dest_loc_list = host_prov_rec['LO']['pd']
            i = int(0)
            for pd in dest_loc_list:
                if pd != '0':
                    pd_loc = data[pd]
                    if u.is_ocean(pd_loc):
                        pd_name = pd_loc['na'][0]
                        pd_loc_id = u.return_unitid(pd_loc)
                        pd_rec = data[pd_loc_id]
                        direction = pd_directions[i]
                        region_id = u.region(pd_loc_id, data)
                        region_rec = data[region_id]
                        to_dict = create_loc_to_dict_entry(data, direction, pd_rec, v, region_rec)
                        dest_list.append(to_dict)
                i = i + 1
        region_id = u.region(host_prov_id, data)
        region_rec = data[region_id]
        direction = 'Out'
        to_dict = create_loc_to_dict_entry(data, direction, host_prov_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
Ejemplo n.º 22
0
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')
Ejemplo n.º 23
0
def get_taught_in(k, v, data, teaches_chain):
    taught_in_list = []
    skill_list = teaches_chain[k]
    if len(skill_list) > 0:
        for loc in skill_list:
            loc_rec = data[loc]
            where_id = loc_rec['LI']['wh'][0]
            where_rec = data[where_id]
            region_id = u.region(u.return_unitid(where_rec), data)
            region_rec = data[region_id]
            loc_dict = {
                'id': loc,
                'oid': to_oid(loc),
                'name': get_name(loc_rec),
                'where_id': where_id,
                'where_oid': to_oid(where_id),
                'where_name': get_name(where_rec),
                'region_id': region_id,
                'region_oid': to_oid(region_id),
                'region_name': get_name(region_rec)
            }
            taught_in_list.append(loc_dict)
    return taught_in_list
Ejemplo n.º 24
0
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;')
Ejemplo n.º 25
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))
Ejemplo n.º 26
0
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
Ejemplo n.º 27
0
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
Ejemplo n.º 28
0
def write_province_destination(loc, dest_loc, direction, data, outf):
    if (u.is_port_city(dest_loc, data) or u.province_has_port_city(dest_loc, data) != '0') \
            and u.return_type(loc) == 'ocean':
        if not u.is_port_city(dest_loc, data):
            dest_loc = data[u.province_has_port_city(dest_loc, data)]
        dest_loc_host = data[dest_loc['LI']['wh'][0]]
        outf.write('<li>{}, port city, to {} [{}]'
                   .format(direction,
                           dest_loc['na'][0],
                           anchor(to_oid(u.return_unitid(dest_loc)))))
        if u.region(u.return_unitid(loc), data) != u.region(u.return_unitid(dest_loc), data):
            region_key = u.return_unitid(dest_loc)
            region_rec = data[u.region(region_key, data)]
            outf.write(', {}'.format(region_rec['na'][0]))
        barrier = '0'
        if 'LO' in dest_loc and 'ba' in dest_loc['LO']:
            barrier = dest_loc['LO']['ba'][0]
        if barrier != '0':
            outf.write(', impassable<br>&nbsp;&nbsp;&nbsp;A magical barrier prevents entry.')
        else:
            out_distance = u.calc_exit_distance(loc, dest_loc)
            outf.write(', {} {}'.format(out_distance,
                                        'day' if out_distance == 1 else 'days'))
        outf.write('</li>\n')
        outf.write('<li> {}, to {} [{}]'.format(direction,
                                                dest_loc_host['na'][0],
                                                anchor(to_oid(u.return_unitid(dest_loc_host)))))
        if u.region(u.return_unitid(loc), data) != \
           u.region(u.return_unitid(dest_loc), data):
            region_key = u.return_unitid(dest_loc_host)
            region_rec = data[u.region(region_key, data)]
            outf.write(', {}'.format(region_rec['na'][0]))
        barrier = '0'
        if 'LO' in dest_loc_host and 'ba' in dest_loc_host['LO']:
            barrier = dest_loc_host['LO']['ba'][0]
        if barrier != '0':
            outf.write(', impassable<br>&nbsp;&nbsp;&nbsp;A magical barrier prevents entry.')
        else:
            outf.write(', impassable')
        outf.write('</li>\n')
    else:
        outf.write('<li>{}'.format(direction))
        if direction == 'Out':
            outf.write(', {}'.format(u.return_type(dest_loc)))
        outf.write(', to {} [{}]'.format(dest_loc['na'][0],
                                         anchor(to_oid(u.return_unitid(dest_loc)))))
        if u.region(u.return_unitid(loc), data) != \
                u.region(u.return_unitid(dest_loc), data):
            region_key = u.return_unitid(dest_loc)
            region_rec = data[u.region(region_key, data)]
            outf.write(', {}'.format(region_rec['na'][0]))
        barrier = '0'
        if 'LO' in dest_loc and 'ba' in dest_loc['LO']:
            barrier = dest_loc['LO']['ba'][0]
        if barrier != '0':
            outf.write(', impassable<br>&nbsp;&nbsp;&nbsp;A magical barrier prevents entry.')
        elif (u.return_type(loc) == 'ocean' and \
            u.return_type(dest_loc) == 'mountain') or \
            (u.return_type(loc) == 'mountain' and \
            u.return_type(dest_loc) == 'ocean') and \
            direction.lower() not in details.road_directions:
            outf.write(', impassable')
        else:
            out_distance = u.calc_exit_distance(loc, dest_loc)
            outf.write(', {} {}'.format(out_distance,
                                        'day' if out_distance == 1 else 'days'))
        if dest_loc['na'][0] == 'Hades' and loc['na'][0] != 'Hades':
            outf.write('<br>&nbsp;&nbsp;&nbsp;"Notice to all mortals, from the Gatekeeper '
                       'Spirit of Hades: 100 gold/head<br>&nbsp;&nbsp;&nbsp;&nbsp;'
                       'is removed from any stack taking this road"')
        outf.write('</li>\n')
Ejemplo n.º 29
0
def write_skill_basic_info(v, k, data, outf, teaches_chain, child_skills_chain,
                           skills_known_chain):
    outf.write('<table>\n')
    if 'SK' in v:
        if 'rs' in v['SK']:
            skill = data[v['SK']['rs'][0]]
            outf.write('<tr><td>Skill Required:</td><td>{} [{}]'
                       '</td></tr>\n'.format(skill['na'][0],
                                             anchor(u.return_unitid(skill))))
        if 'tl' in v['SK']:
            outf.write('<tr><td>Time to Learn:</td><td>{}</td></tr>\n'.format(
                v['SK']['tl'][0]))
    char_list = skills_known_chain[k]
    if len(char_list) > 0:
        outf.write('<tr><td valign="top">Known By:</td><td>')
        outf.write('<table>\n')
        columns = int(math.ceil(len(char_list) / 3))
        for charac in range(0, columns):
            outf.write('<tr>')
            if (columns * 0) + charac < len(char_list):
                char_rec = data[char_list[(columns * 0) + charac]]
                outf.write('<td>{} [{}]</td>'.format(
                    char_rec['na'][0],
                    anchor(to_oid(u.return_unitid(char_rec)))))
            else:
                outf.write('<td></td><td></td>')
            if (columns * 1) + charac < len(char_list):
                char_rec = data[char_list[(columns * 1) + charac]]
                outf.write('<td>{} [{}]</td>'.format(
                    char_rec['na'][0],
                    anchor(to_oid(u.return_unitid(char_rec)))))
            else:
                outf.write('<td></td><td></td>')
            if (columns * 2) + charac < len(char_list):
                char_rec = data[char_list[(columns * 2) + charac]]
                outf.write('<td>{} [{}]</td>'.format(
                    char_rec['na'][0],
                    anchor(to_oid(u.return_unitid(char_rec)))))
            else:
                outf.write('<td></td><td></td>')
            outf.write('</tr>\n')
        outf.write('</table>\n')
        outf.write('</td></tr>')
    child_list = child_skills_chain[k]
    if len(child_list) > 0:
        outf.write('<tr><td valign="top">Child Skills:</td><td>')
        outf.write('<table>\n')
        columns = int(math.ceil(len(child_list) / 3))
        for skill in range(0, columns):
            outf.write('<tr>')
            if (columns * 0) + skill < len(child_list):
                skill_rec = data[child_list[(columns * 0) + skill]]
                outf.write('<td>{} [{}]</td>'.format(
                    skill_rec['na'][0],
                    anchor(to_oid(u.return_unitid(skill_rec)))))
            else:
                outf.write('<td></td><')
            if (columns * 1) + skill < len(child_list):
                skill_rec = data[child_list[(columns * 1) + skill]]
                outf.write('<td>{} [{}]</td>'.format(
                    skill_rec['na'][0],
                    anchor(to_oid(u.return_unitid(skill_rec)))))
            else:
                outf.write('<td></td>')
            if (columns * 2) + skill < len(child_list):
                skill_rec = data[child_list[(columns * 2) + skill]]
                outf.write('<td>{} [{}]</td>'.format(
                    skill_rec['na'][0],
                    anchor(to_oid(u.return_unitid(skill_rec)))))
            else:
                outf.write('<td></td>')
            outf.write('</tr>\n')
        outf.write('</table>\n')
        outf.write('</td></tr>')
    skill_list = teaches_chain[k]
    if len(skill_list) > 0:
        skill_literal = 'Taught in:'
        for loc in skill_list:
            loc_rec = data[loc]
            where_rec = data[loc_rec['LI']['wh'][0]]
            region = data[u.region(u.return_unitid(where_rec), data)]
            outf.write(
                '<tr><td>{}</td><td>{} [{}], {} [{}], in {}</td></tr>\n'.
                format(skill_literal, loc_rec['na'][0],
                       anchor(to_oid(u.return_unitid(loc_rec))),
                       where_rec['na'][0],
                       anchor(to_oid(u.return_unitid(where_rec))),
                       region['na'][0]))
            skill_literal = ''
    outf.write('</table>\n')
Ejemplo n.º 30
0
def get_wearable_wielding(v, data):
    wearable_dict = {}
    attack_max = 0
    missile_max = 0
    defense_max = 0
    attack_unit_id = ''
    missile_unit_id = ''
    defense_unit_id = ''
    if 'il' in v:
        item_list = v['il']
        if len(item_list) > 0:
            for items in range(0, len(item_list), 2):
                itemz = data[item_list[items]]
                if 'IM' in itemz:
                    # find item(s) with best attack, defense and missile ratings
                    if get_attack_bonus(itemz) > attack_max:
                        attack_max = get_attack_bonus(itemz)
                        attack_unit_id = u.return_unitid(itemz)
                    if get_defense_bonus(itemz) > defense_max:
                        defense_max = get_defense_bonus(itemz)
                        defense_unit_id = u.return_unitid(itemz)
                    if get_missile_bonus(itemz) > missile_max:
                        missile_max = get_missile_bonus(itemz)
                        missile_unit_id = u.return_unitid(itemz)
        # found something
        if attack_unit_id != '' or missile_unit_id != '' or defense_unit_id != '':
            if attack_unit_id == missile_unit_id:
                missile_unit_id = ''
        if attack_unit_id == defense_unit_id:
            defense_unit_id = ''
        if attack_unit_id != '' or missile_unit_id != '':
            if attack_unit_id == '':
                missile_rec = data[missile_unit_id]
                missile_dict = {
                    'id': missile_unit_id,
                    'oid': to_oid(missile_unit_id),
                    'name': get_name(missile_rec)
                }
                attack_dict = {}
            elif missile_unit_id == '':
                attack_rec = data[attack_unit_id]
                attack_dict = {
                    'id': attack_unit_id,
                    'oid': to_oid(attack_unit_id),
                    'name': get_name(attack_rec)
                }
                missile_dict = {}
            else:
                missile_rec = data[missile_unit_id]
                missile_dict = {
                    'id': missile_unit_id,
                    'oid': to_oid(missile_unit_id),
                    'name': get_name(missile_rec)
                }
                attack_rec = data[attack_unit_id]
                attack_dict = {
                    'id': attack_unit_id,
                    'oid': to_oid(attack_unit_id),
                    'name': get_name(attack_rec)
                }
        else:
            attack_dict = {}
            missile_dict = {}
        if defense_unit_id != '':
            defense_rec = data[defense_unit_id]
            defense_dict = {
                'id': defense_unit_id,
                'oid': to_oid(defense_unit_id),
                'name': get_name(defense_rec)
            }
        else:
            defense_dict = {}
        wearable_dict = {
            'attack': attack_dict,
            'defense': defense_dict,
            'missile': missile_dict
        }
    return wearable_dict