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')
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')
def write_char_basic_info(v, k, data, outf, pledge_chain, prisoner_chain, instance): if u.return_type(v) != 'garrison': outf.write('<table>\n') write_char_type(v, k, data, outf) write_char_rank(v, k, outf) write_char_faction(v, data, outf) write_char_location(data, outf, v) write_char_loyalty(v, outf) write_char_stacked_under(v, data, outf) write_char_stacked_over(v, data, outf) write_char_health(v, outf) write_char_combat(v, outf) write_char_break_point(v, outf, instance) write_char_vision_protection(v, outf) write_char_pledged_to(v, data, outf) write_char_pledged_to_us(k, data, outf, pledge_chain) write_char_concealed(v, outf) write_char_aura(v, data, outf) # appear common not in lib yet # write_char_appear_common(v, k, data, outf) write_char_prisoners(k, data, outf, prisoner_chain) outf.write('</table>\n') if u.return_type(v) != 'garrison': write_char_skills_known(v, data, outf) write_char_inventory(v, data, outf) if u.return_type(v) != 'garrison': write_char_capacity(v, data, outf) write_char_pending_trades(v, data, outf) write_char_visions_received(v, data, outf) write_char_magic_stuff(v, data, outf)
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')
def write_bitmap(outdir, data, upperleft, height, width, prefix): BUFSIZE = 8 * 1024 color_pallette = { 'ocean': (0x00, 0xff, 0xff, 0xff), 'plain': (0x90, 0xee, 0x90, 0xff), 'forest': (0x32, 0xcd, 0x32, 0xff), 'swamp': (0xff, 0x00, 0xff, 0xff), 'mountain': (0x80, 0x80, 0x80, 0xff), 'desert': (0xff, 0xff, 0x00, 0xff), 'underground': (0xff, 0xa5, 0x00, 0xff), 'cloud': (0xad, 0xd8, 0xe6, 0xff) } outf = open(pathlib.Path(outdir).joinpath(prefix + '_thumbnail.png'), 'wb') map = PNGCanvas(width, height, color=(0xff, 0, 0, 0xff)) for x in range(0, width): for y in range(0, height): curr_loc = upperleft + (y * 100) + (x * 1) try: province_box = data[str(curr_loc)] try: color = color_pallette[u.return_type(province_box)] map.point(x, y, color) except KeyError: print('missing color for: {}'.format( u.return_type(province_box))) except KeyError: # print('missing box record for: {} {}'.format(curr_loc, # to_oid(curr_loc))) pass outf.write(map.dump()) outf.close()
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')
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')
def write_storms(v, k, outf): outf.write('<li>\n') if 'na' in v: name = v['na'][0] else: name = u.return_type(v).capitalize() outf.write('{} [{}], {}'.format(name, anchor(to_oid(k)), u.return_type(v))) if 'MI' in v and 'ss' in v['MI']: outf.write(' (strength: {})'.format(v['MI']['ss'][0])) outf.write('</li>\n')
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')
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>')
def write_char_page_header(v, k, outf, data): if u.return_type(v) == 'garrison': name = 'Garrison' else: name = v['na'][0] if name == 'Ni': name = data[v['CH']['ni'][0]]['na'][0].capitalize() outf.write('<H3>{} [{}]</H3>\n'.format(name, to_oid(k)))
def write_garrisons(v, k, data, outf, garrisons_chain): if u.return_type(v) == 'castle': garrison_list = garrisons_chain[k] if len(garrison_list) > 0: province_list = [] for garrison in garrison_list: province_rec = data[garrison] province_list.append([province_rec['LI']['wh'][0], garrison]) province_list.sort() outf.write('<H4>Garrisons:</H4>\n') outf.write('<ul>\n') for province in province_list: garrison_rec = data[province[1]] write_characters(garrison_rec, province[1], data, outf, True) outf.write('</ul>\n')
def write_ship_html(v, k, data, outdir): # generate ship page outf = open(pathlib.Path(outdir).joinpath(to_oid(k) + '.html'), 'w') outf.write('<HTML>\n') outf.write('<HEAD>\n') outf.write('<TITLE>{} [{}], {}'.format(v['na'][0], to_oid(k), u.return_type(v))) outf.write('</TITLE>\n') outf.write('</HEAD>\n') outf.write('<BODY>\n') write_ship_page_header(v, k, outf) write_ship_basic_info(v, k, data, outf) outf.write('</BODY>\n') outf.write('</HTML>\n') outf.close()
def write_ship_bound_storm(v, data, outf): if 'SL' in v and 'bs' in v['SL']: bound_storm = v['SL']['bs'][0] else: bound_storm = '???' if bound_storm != '???': bound_storm_rec = data[bound_storm] if 'na' in bound_storm_rec: name = bound_storm_rec['na'][0] else: name = u.return_type(bound_storm_rec).capitalize() outf.write('<tr>') outf.write('<td>Bound Storm:</td>') outf.write('<td>{} [{}] (Strength: {})</td></tr>\n'.format( name, anchor(to_oid(bound_storm)), bound_storm_rec['MI']['ss'][0]))
def write_storm_html(v, k, data, storm_chain, outdir): # generate storm page outf = open(pathlib.Path(outdir).joinpath(to_oid(k) + '.html'), 'w') outf.write('<HTML>\n') outf.write('<HEAD>\n') if 'na' in v: name = v['na'][0] else: name = u.return_type(v).capitalize() outf.write('<TITLE>{} [{}]'.format(name, to_oid(k))) outf.write('</TITLE>\n') outf.write('</HEAD>\n') outf.write('<BODY>\n') write_storm_page_header(v, k, outf) write_storm_basic_info(v, k, data, outf, storm_chain) outf.write('</BODY>\n') outf.write('</HTML>\n') outf.close()
def write_player_basic_info(v, data, outf): outf.write('<table>\n') outf.write('<tr><td>Type</td><td>{}</td></tr>\n'.format(u.return_type(v))) if 'PL' in v: if 'em' in v['PL']: outf.write('<tr><td>Email Address:</td><td>{}</td></tr>\n'.format(v['PL']['em'][0])) if 'fs' in v['PL']: outf.write('<tr><td>Fast Study Points:</td><td>{}</td></tr>\n'.format(v['PL']['fs'][0])) if 'ft' in v['PL']: outf.write('<tr><td>First Turn:</td><td>{}</td></tr>\n'.format(v['PL']['ft'][0])) write_full_name(outf, v) # outf.write('<tr><td>Known:</td><td></td></tr>\n') if 'PL' in v: if 'lt' in v['PL']: outf.write('<tr><td>Last Turn:</td><td>{}</td></tr>\n'.format(v['PL']['lt'][0])) if 'np' in v['PL']: outf.write('<tr><td>Noble Points</td><td>{}</td></tr>\n'.format(v['PL']['np'][0])) write_unit_list(data, outf, v) outf.write('</table>\n')
def write_structure_basic_info(v, outf): try: defense = v['SL']['de'][0] except KeyError: defense = '0' try: damage = v['SL']['dea'][0] except KeyError: damage = '0' try: effort_given = v['SL']['eg'][0] except KeyError: effort_given = '0' try: effort_required = v['SL']['er'][0] except KeyError: effort_required = '0' try: depth = v['SL']['sd'][0] except KeyError: depth = '0' try: level = v['SL']['cl'][0] except KeyError: level = '0' if defense != '0' or damage != '0' or int(effort_given) < int(effort_required): outf.write('<table>\n') if effort_given < effort_required: outf.write('<tr><td>Percent Complete:</td><td>{}%</td></tr>\n' .format(int(int(effort_given) / int(effort_required)) * 100)) if defense != '0': outf.write('<tr><td>Defense:</td><td>{}</td></tr>\n' .format(defense)) outf.write('<tr><td>Damage:</td><td>{}%</td></tr>\n' .format(damage)) if depth != '0': outf.write('<tr><td>Level:</td><td>{}</td></tr>\n' .format(int(int(depth) / 3))) if u.return_type(v) == 'castle': outf.write('<tr><td>Level:</td><td>{}</td></tr>\n' .format(level)) outf.write('</table>\n')
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)
def write_loc_html(v, k, data, hidden_chain, garrisons_chain, trade_chain, outdir, instance, inst_dict, map_matrices): # generate loc page outf = open(pathlib.Path(outdir).joinpath(to_oid(k) + '.html'), 'w') outf.write('<HTML>\n') outf.write('<HEAD>\n') name = v['na'][0] try: loc2 = data[v['LI']['wh'][0]] loc2_name = ', in ' + loc2['na'][0] except KeyError: loc2_name = '' outf.write('<TITLE>{} [{}], {}{}'.format(name, to_oid(k), u.return_type(v), loc2_name)) outf.write('</TITLE>\n') outf.write('</HEAD>\n') outf.write('<BODY>\n') write_loc_page_header(v, k, data, outf) write_loc_basic_info(v, k, data, outf, hidden_chain, garrisons_chain, trade_chain, instance, inst_dict, map_matrices) outf.write('</BODY>\n') outf.write('</HTML>\n') outf.close()
def write_char_html(v, k, data, pledge_chain, prisoner_chain, outdir, instance): # generate char page outf = open(pathlib.Path(outdir).joinpath(to_oid(k) + '.html'), 'w') outf.write('<HTML>\n') outf.write('<HEAD>\n') if u.return_type(v) == 'garrison': name = 'Garrison' else: name = v['na'][0] if name == 'Ni': name = data[v['CH']['ni'][0]]['na'][0].capitalize() outf.write('<TITLE>{} [{}]'.format(name, to_oid(k))) outf.write('</TITLE>\n') outf.write('</HEAD>\n') outf.write('<BODY>\n') write_char_page_header(v, k, outf, data) write_char_basic_info(v, k, data, outf, pledge_chain, prisoner_chain, instance) outf.write('</BODY>\n') outf.write('</HTML>\n') outf.close()
def write_cell(castle_chain, currentpoint, data, leftnav, outf, prefix, rightnav, x, y, xx, yy, instance, map_matrix): if x == 0 and y == 0: if leftnav: printpoint = map_matrix[yy][xx - 10] outf.write('<td rowspan="20" class="left">') outf.write('<a href="{}_map_leaf_{}.html">'.format( prefix, to_oid(printpoint))) outf.write('<img src="grey.gif" width="20" height="840">') outf.write('</a></td>\n') cell = map_matrix[yy + y][xx + x] printpoint = cell try: loc_rec = data[str(printpoint)] except: outf.write('<td id ="{}" class="{}">'.format(to_oid(printpoint), 'undefined')) outf.write('{}'.format(to_oid(printpoint))) outf.write('<br>{}'.format(' ' * 8)) outf.write('<br>{}'.format(' ' * 8)) outf.write('</td>\n') else: outf.write('<td id ="{}" class="{}"'.format(to_oid(printpoint), u.return_type(loc_rec))) maps.generate_border(data, loc_rec, outf, instance) outf.write('>') maps.generate_cell_contents(castle_chain, printpoint, data, loc_rec, outf) outf.write('</td>\n') # except KeyError: # outf.write('<td id="{}" class="x-sea">{}</td>\n'.format(to_oid(printpoint), to_oid(printpoint))) if x == 19 and y == 0: if rightnav: printpoint = map_matrix[yy][xx + 10] outf.write('<td rowspan="20" class="right">') outf.write('<a href="{}_map_leaf_{}.html">'.format( prefix, to_oid(printpoint))) outf.write('<img src="grey.gif" width="20" height="840">') outf.write('</a></td>\n')
def write_char_type(v, k, data, outf): if u.return_type(v) == 'ni': outf.write('<tr>') outf.write('<td>Type:</td>') outf.write('<td>{} [{}]</td></tr>\n'.format( data[v['CH']['ni'][0]]['na'][0], anchor(to_oid(v['CH']['ni'][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> ' '{} [{}] {}</p>\n'.format(scroll_id, skill_name, skill_id, required_study))
def write_char_inventory(v, data, outf): total_weight = int(0) if 'il' in v: item_list = v['il'] if len(item_list) > 0: outf.write('<p>Inventory:</p>\n') outf.write('<table>\n') outf.write( '<tr><td style="text-align:right">qty</td><td style="text-align:left">name</td><td ' 'style="text-align:right">weight</td><td style="text-align:left"> </td></tr>\n' ) outf.write( '<tr><td style="text-align:right">---</td><td style="text-align:left">----</td><td ' 'style="text-align:right">------</td><td style="text-align:left"> </td></tr>\n' ) for itm in range(0, len(item_list), 2): item_id = item_list[itm] item_qty = int(item_list[itm + 1]) outf.write('<tr>') outf.write(f'<td style="text-align:right">{item_qty:,d}</td>') itemz = data[item_id] itemz_name = u.get_item_name( itemz) if item_qty == 1 else u.get_item_plural(itemz) outf.write('<td style="text-align:left">{} [{}]</td>'.format( itemz_name, anchor(to_oid(item_id)))) if 'wt' in itemz['IT']: item_weight = int(itemz['IT']['wt'][0]) else: item_weight = int(0) item_ext = int(item_weight * item_qty) outf.write(f'<td style="text-align:right">{item_ext:,d}</td>') total_weight = total_weight + (item_weight * item_qty) if u.return_type(v) != "garrison": outf.write('<td>') fly_capacity = int(0) if 'fc' in itemz['IT']: fly_capacity = int(itemz['IT']['fc'][0]) land_capacity = int(0) if 'lc' in itemz['IT']: land_capacity = int(itemz['IT']['lc'][0]) ride_capacity = int(0) if 'rc' in itemz['IT']: ride_capacity = int(itemz['IT']['rc'][0]) if fly_capacity > 0: outf.write(f'fly {(fly_capacity * item_qty):,d}') elif ride_capacity > 0: outf.write(f'ride {(ride_capacity * item_qty):,d}') elif land_capacity > 0: outf.write(f'cap {(land_capacity * item_qty):,d}') if u.is_fighter(itemz, item_id): attack = int(0) defense = int(0) missile = int(0) if 'at' in itemz['IT']: attack = int(itemz['IT']['at'][0]) if 'df' in itemz['IT']: defense = int(itemz['IT']['df'][0]) if 'mi' in itemz['IT']: missile = int(itemz['IT']['mi'][0]) outf.write(' ({},{},{})'.format( attack, defense, missile)) attack_bonus = int(0) defense_bonus = int(0) missile_bonus = int(0) if 'IM' in itemz: if 'ab' in itemz['IM']: attack_bonus = int(itemz['IM']['ab'][0]) if 'db' in itemz['IM']: defense_bonus = int(itemz['IM']['db'][0]) if 'mb' in itemz['IM']: missile_bonus = int(itemz['IM']['mb'][0]) if attack_bonus > 0: outf.write(f'+ {attack_bonus:,d} attack') if defense_bonus > 0: outf.write(f'+ {defense_bonus:,d} defense') if missile_bonus > 0: outf.write(f'+ {missile_bonus:,d} missile') if u.is_magician(v): aura_bonus = 0 if 'IM' in itemz and 'ba' in itemz['IM']: aura_bonus = int(itemz['IM']['ba'][0]) if aura_bonus > 0: outf.write('+{} aura'.format(aura_bonus)) outf.write(' </td>') else: outf.write('<td> </td>') outf.write('</tr>\n') if u.return_type(v) != 'garrison': outf.write( '<tr><td></td><td></td><td style="text-align:right">=====' '</td><td> </td></tr>\n') outf.write( '<tr><td></td><td></td>' f'<td style="text-align:right">{total_weight:,d}</td>' '<td> </td></tr>\n') outf.write('</table>\n')
def write_ship_pct_complete(v, outf): if 'in-progress' in u.return_type(v): outf.write('<tr>') outf.write('<td>Percent Complete:</td>') outf.write('<td>{}%</td></tr>\n'.format( (int(v['SL']['eg'][0]) / int(v['SL']['er'][0])) * 100))
def write_loc_map_anchor(v, k, data, outf, instance, inst_dict, map_matrices): if u.return_type(v) in ['tunnel', 'chamber']: return 0 dimensions = inst_dict[instance] region = u.region(k, data) region_rec = data[region] province = u.province(k, data) if province == 0: return 0 province_rec = data[province] custom = False save_rec = [] save_world = '' try: save_rec = map_matrices[region_rec['na'][0].lower()] except KeyError: try: save_rec = dimensions[region_rec['na'][0].lower()] except KeyError: for world in dimensions: world_rec = dimensions[world] if world_rec[0] <= int( province) < world_rec[0] + (world_rec[2] * 100): save_rec = world_rec save_world = world break else: save_world = region_rec['na'][0].lower() else: save_world = region_rec['na'][0].lower() custom = True # if len(save_rec) == 0: # print('error {} {}'.format(to_oid(k), # u.return_type(v))) if len(save_rec) > 0 and not custom: world_rec = save_rec world = save_world x_coord = int(10 * math.floor((int(province) % 100) / 10)) if x_coord >= world_rec[1] - 10: x_coord = world_rec[1] - 20 y_coord = int(1000 * math.floor(int(province) / 1000)) if y_coord >= world_rec[0] + (world_rec[2] * 100) - 1000: y_coord = world_rec[0] + (world_rec[2] * 100) - 2000 if y_coord < world_rec[0]: y_coord = world_rec[0] final_coord = y_coord + x_coord if final_coord < world_rec[0]: final_coord = world_rec[0] anchor_string = world + '_map_leaf_' + to_oid(final_coord) outf.write('<p>{}</p>\n'.format(anchor2(anchor_string, 'Return to map'))) if len(save_rec) > 0 and custom: world_rec = save_rec world = save_world for xx in range(0, len(save_rec[0])): for yy in range(0, len(save_rec)): if save_rec[yy][xx] == province: xxx = int(math.floor(xx / 10)) * 10 yyy = int(math.floor(yy / 10)) * 10 final_coord = save_rec[yyy][xxx] break anchor_string = world + '_map_leaf_' + to_oid(final_coord) outf.write('<p>{}</p>\n'.format(anchor2(anchor_string, 'Return to map')))
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> 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> 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> 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> "Notice to all mortals, from the Gatekeeper ' 'Spirit of Hades: 100 gold/head<br> ' 'is removed from any stack taking this road"') outf.write('</li>\n')
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 /> ') 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 /> ')
def write_ship_page_header(v, k, outf): outf.write('<H3>{} [{}], {}</H3>\n'.format(v['na'][0], to_oid(k), u.return_type(v)))
def write_characters(v, k, data, outf, print_province = False): outf.write('<li>') if print_province: if 'LI' in v and 'wh' in v['LI']: province_rec = data[v['LI']['wh'][0]] outf.write('({}) '.format(anchor(to_oid(v['LI']['wh'][0])))) # code fix to bug in lib where garrison name is sometimes missing if u.return_type(v) == 'garrison': name = 'Garrison' else: name = v['na'][0] if name == 'Ni': name = data[v['CH']['ni'][0]]['na'][0].capitalize() outf.write('{} [{}]'.format(name, anchor(to_oid(k)))) if u.xlate_loyalty(v) not in {'Undefined'}: outf.write(' ({}'.format(u.xlate_loyalty(v))) if 'CH' in v and 'sl' in v['CH']: skills_list = v['CH']['sl'] if int(len(skills_list)) > 0: iterations = int(len(skills_list) / 5) for skill in range(0, iterations): if skills_list[skill * 5] == '909': if skills_list[(skill * 5) + 1] == '2': outf.write(':AB') outf.write(')') else: if 'CH' in v: if 'sl' in v['CH']: skills_list = v['CH']['sl'] if int(len(skills_list)) > 0: iterations = int(len(skills_list) / 5) for skill in range(0, iterations): if skills_list[skill * 5] == '909': if skills_list[(skill * 5) + 1] == '2': outf.write('(AB') if u.return_type(v) != '0': if u.return_type(v) == 'ni': # char_type = v['na'][0].lower() char_type = data[v['CH']['ni'][0]]['na'][0] else: char_type = u.return_type(v) outf.write(', {}'.format(char_type)) if 'CH' in v: if 'pr' in v['CH'] and v['CH']['pr'][0] == '2': outf.write(', prisoner') if u.is_priest(v): outf.write(', priest') if u.is_magician(v): if u.xlate_magetype(v, data) not in {'', 'undefined'}: outf.write(', {}'.format(u.xlate_magetype(v, data))) if 'CH' in v: if 'gu' in v['CH'] and v['CH']['gu'][0] == '1': outf.write(', on guard') if 'hs' in v['CH'] and v['CH']['hs'][0] == '1': outf.write(' concealed') # print wearing/wielding print_wearable_wielding(v, data, outf) # print prominent items if 'il' in v: item_list = v['il'] iterations = int(len(item_list) / 2) if iterations > 0: for items in range(0, iterations): itemz = data[item_list[items * 2]] if 'IT' in itemz: if 'pr' in itemz['IT']: if itemz['IT']['pr'][0] == '1': item_name = itemz['na'][0] if int(item_list[(items * 2) + 1]) == 1 else itemz['IT']['pl'][0] outf.write(', {} {}'.format(item_list[(items * 2) + 1], item_name)) if 'LI' in v: if 'hl' in v['LI']: outf.write(', accompanied by: ') outf.write('</li>\n') if 'LI' in v: if 'hl' in v['LI']: here_list = v['LI']['hl'] if len(here_list) > 0: outf.write('<ul>\n') for here in here_list: charac = data[here] write_characters(charac, here, data, outf) outf.write('</ul>\n')