def build_complete_item_dict(k, v, data, trade_chain): item_dict = {'oid' : get_oid(k), 'name' : get_name(v), 'subkind' : get_subkind(v, data), 'plural' : get_plural(v), 'animal' : get_animal(v), 'attack' : get_item_attack(v), 'aura' : get_auraculum_aura(v), 'dead_body_dict': get_dead_body(v, data), 'defense' : get_item_defense(v), 'fly_capacity' : get_fly_capacity(v), 'land_capacity' : get_land_capacity(v), 'lore' : get_lore(v), 'man_item': get_man_item(v), 'may_study_dict': get_may_study(v, data), 'missile' : get_item_missile(v), 'project_cast' : get_project_cast(v, data), 'prominent' : get_prominent(v), 'ride_capacity' : get_ride_capacity(v), 'use_key' : get_use_key(v), 'weight' : get_item_weight(v), 'who_has_dict': get_who_has(v, data), 'trade_good' : get_trade_good(k, v, data, trade_chain), 'magic_info': get_magic_item(data, k, v)} return item_dict
def build_complete_ship_dict(k, v, data, instance, pledge_chain, prisoner_chain): ship_dict = { 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'kind', 'complete': get_complete(v), 'load': get_load(k, v, data), 'defense': get_defense(v)[0], 'damage': get_ship_damage(v), 'owner': build_owner_dict(v, data), 'storm': build_storm_dict(v, data), 'seen_here': build_seenhere_dict(k, v, data, instance, pledge_chain, prisoner_chain), 'non_prominent_items': build_non_prominent_items_dict(k, v, data), 'loc': build_loc_dict(v, data) } return ship_dict
def build_loc_dict(v, data): loc_id = v['LI']['wh'][0] loc_rec = data[loc_id] loc_dict = { 'oid': get_oid(loc_id), 'name': get_name(loc_rec), 'subkind': get_subkind(loc_rec, data) } return loc_dict
def build_basic_storm_dict(k, v, data): storm_dict = { 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'storm', 'strength': get_strength(v) } return storm_dict
def build_basic_char_dict(k, v, data, prominent_only=False): if not u.is_garrison(v): char_dict = { 'id': k, 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'char', 'rank': get_rank(v), 'faction': get_faction(v, data), 'health_dict': get_health(v), 'nbr_men': get_nbr_men(v, data), 'absorb_blast': u.is_absorb_aura_blast(v), 'prisoner': u.is_prisoner(v), 'stacked_over_list': get_stacked_over(v, data), 'priest': u.is_priest(v), 'magetype': u.xlate_magetype(v, data), 'on_guard': u.is_on_guard(v), 'concealed': u.is_concealed(v), 'wearable': get_wearable_wielding(v, data), 'loyalty': get_loyalty(v), 'skills_known_list': get_skills_known(v, data), 'inventory_dict': get_inventory(v, data, prominent_only), 'aura_dict': get_aura(v, data), 'priest_dict': get_priest_skills(v, data) } return char_dict else: char_dict = { 'id': k, 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'char', 'faction': get_faction(v, data), 'health_dict': get_health(v), 'nbr_men': get_nbr_men(v, data), 'on_guard': u.is_on_guard(v), 'loyalty': get_loyalty(v), 'inventory_dict': get_inventory(v, data, prominent_only) } return char_dict
def build_complete_storm_dict(k, v, data, storm_chain): storm_dict = { 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'storm', 'strength': get_strength(v), 'loc': build_loc_dict(v, data), 'ship': build_ship_dict(k, data, storm_chain) } return storm_dict
def build_basic_loc_dict(k, v, data, garrisons_chain=None): loc_dict = {'oid': to_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': u.return_kind(v), 'where': get_where_info(v, data), 'hidden': u.is_hidden(v), 'structure': get_structure_info(v), 'seen_here': get_here_list(k, v, data), 'region': get_region(k, data), 'garrisons': get_garrisons(k, v, data, garrisons_chain),} return loc_dict
def build_complete_player_dict(k, v, data): player_dict = {'id': k, 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'player', 'email': get_email(v), 'fast_study': get_fast_study(v), 'first_turn': get_first_turn(v), 'full_name': get_full_name(v), 'last_turn': get_last_turn(v), 'noble_points': get_noble_points(v), 'unit_list': get_unit_list(v, data)} return player_dict
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
def build_basic_ship_dict(k, v, data): ship_dict = { 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'ship', 'complete': get_complete(v), 'load': get_load(k, v, data), 'defense': get_defense(v)[0], 'damage': get_ship_damage(v), 'owner': build_owner_dict(v, data), 'storm': build_storm_dict(v, data), 'loc': build_loc_dict(v, data) } return ship_dict
def get_where_info(v, data): where_id = v.get('LI', {}).get('wh', None) if where_id is not None: try: where_rec = data[where_id[0]] except KeyError: where_dict = None else: where_dict = {'id': where_id[0], 'oid': to_oid(where_id[0]), 'name': get_name(where_rec), 'subkind': get_subkind(where_rec, data)} else: where_dict = None return where_dict
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
def build_complete_loc_dict(k, v, data, garrisons_chain, hidden_chain, trade_chain, instance, inst_dict, map_matrices): loc_dict = {'oid': to_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'loc', 'where': get_where_info(v, data), 'safe_haven': get_safe_haven(v), 'hidden': u.is_hidden(v), 'civ_level': get_civ_level(k, v, data), 'barrier': get_barrier(k, v, data), 'shroud': get_shroud(k, v, data), 'anchor': get_map_anchor(v, k, data, instance, inst_dict, map_matrices), 'controlled_by': get_controlled_by (v, data), 'routes_out': get_routes_out(k, v, data), 'structure': get_structure_info(v), 'skills': get_skills_taught(v, data), 'markets': get_markets(k, v, data, trade_chain), 'seen_here': get_here_list(k, v, data), 'hidden_access': get_hidden_access(k, v, data, hidden_chain), 'garrisons': get_garrisons(k, v, data, garrisons_chain), 'region': get_region(k, data)} return loc_dict
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
def get_destinations(k, v, data): dest_list = [] if 'LO' in v and 'pd' in v['LO']: pd_list = v['LO']['pd'] i = int(0) for pd in pd_list: if pd != '0': direction = pd_directions[i] pd_rec = data[pd] region_id = u.region(pd, data) region_rec = data[region_id] if u.province_has_port_city(pd_rec, data) is not None: city_rec = data[u.province_has_port_city(pd_rec, data)] to_dict = create_loc_to_dict_entry(data, direction, city_rec, v, region_rec) dest_list.append(to_dict) to_dict = create_loc_to_dict_entry(data, direction, pd_rec, v, region_rec) dest_list.append(to_dict) # see if port city so show province also if u.is_port_city(pd_rec, data): prov_rec = data[u.province(pd, data)] to_dict = create_loc_to_dict_entry(data, direction, prov_rec, v, region_rec) dest_list.append(to_dict) i = i + 1 if u.return_subkind(v) not in details.province_kinds: if 'LI' in v and 'wh' in v['LI']: out_id = v['LI']['wh'][0] out_rec = data[out_id] region_id = u.region(out_id, data) region_rec = data[region_id] to_dict = create_loc_to_dict_entry(data, 'Out', out_rec, v, region_rec) dest_list.append(to_dict) if 'LI' in v and 'hl' in v['LI']: here_list = v['LI']['hl'] for here in here_list: here_record = data[here] if u.is_road_or_gate(here_record): to_id = here_record['GA']['tl'][0] to_rec = data[to_id] region_id = u.region(to_id, data) region_rec = data[region_id] if u.return_kind(here_record) == 'gate': direction = 'Gate' else: direction = get_name(here_record) to_dict = create_loc_to_dict_entry(data, direction, to_rec, here_record, region_rec) dest_list.append(to_dict) if 'SL' in v and 'lt' in v['SL']: link_id = v['SL']['lt'][0] link_rec = data[link_id] region_id = u.region(link_id, data) region_rec = data[region_id] to_dict = create_loc_to_dict_entry(data, get_subkind(link_rec, data).title(), link_rec, v, region_rec) dest_list.append(to_dict) region_id = u.region(k, data) region_rec = data[region_id] dest_dict = {'id': k, 'oid': to_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'region_oid': to_oid(region_id), 'region_name': get_name(region_rec), 'dest': dest_list} return dest_dict
def build_complete_char_dict(k, v, data, instance, pledge_chain, prisoner_chain, prominent_only): if not u.is_garrison(v): char_dict = { 'id': k, 'oid': get_oid(k), 'name': get_name(v), 'subkind': get_subkind(v, data), 'kind': 'char', 'rank': get_rank(v), 'faction': get_faction(v, data), 'prisoner': u.is_prisoner(v), 'priest': u.is_priest(v), 'magetype': u.xlate_magetype(v, data), 'on_guard': u.is_on_guard(v), 'concealed': u.is_concealed(v), 'wearable': get_wearable_wielding(v, data), 'loc': get_loc(v, data), 'where': get_where(v, data), 'loyalty': get_loyalty(v), # 'stacked_under': get_stacked_under(v, data), 'stacked_over_list': get_stacked_over(v, data), 'health_dict': get_health(v), 'break_point': get_break_point(v), 'vision_protection': get_vision_protection(v), 'pledged_to': get_pledged_to(v, data), 'pledged_to_us_list': get_pledged_to_us(k, data, pledge_chain), 'combat_dict': get_combat(v), 'aura_dict': get_aura(v, data), 'prisoner_list': get_prisoners(k, data, prisoner_chain), 'skills_known_list': get_skills_known(v, data), 'inventory_dict': get_inventory(v, data, prominent_only), 'trades_list': get_pending_trades(v, data), 'visions_list': get_visions_received(v, data), 'magic_list': get_magic_stuff(v, data), 'priest_dict': get_priest_skills(v, data) } else: char_dict = { 'id': k, 'oid': get_oid(k), 'name': get_name(v), 'subkind': None, 'kind': 'char', 'rank': None, 'faction': get_faction(v, data), 'nbr_men': get_nbr_men(v, data), 'prisoner': None, 'priest': None, 'magetype': None, 'on_guard': None, 'wearable': None, 'loc': get_loc(v, data), 'loyalty': None, # 'stacked_under': None, 'stacked_over_list': None, 'health_dict': None, 'break_point': None, 'vision_protection': None, 'pledged_to': None, 'pledged_to_us_list': None, 'combat_dict': None, 'concealed': None, 'aura_dict': None, 'prisoner_list': None, 'skills_known_list': None, 'inventory_dict': get_inventory(v, data, prominent_only), 'trades_list': None, 'visions_list': None, 'magic_list': get_magic_stuff(v, data) } return char_dict