def parse_mob(text): fields = [line.rstrip() for line in text.strip().split('\n')] d = dict() d['id'] = int(fields[0]) d['aliases'] = fields[1].rstrip('~').split() d['short_desc'] = fields[2].rstrip('~') d['long_desc'] = text.split('~')[2].strip('\n') d['detail_desc'] = text.split('~')[3].strip('\n') tildes = [i for i, a in enumerate(text) if a == '~'] start_bottom_matter = tildes[3] + 1 bottom_fields = text[start_bottom_matter:].strip('\n').split('\n') vector_line = bottom_fields[0] action, affect, alignment, mob_type = vector_line.split() d['mob_type'] = mob_type d['alignment'] = int(alignment) action = clean_bitvector(action) d['flags'] = bitvector_to_flags(action, MOB_ACTION_FLAGS) affect = clean_bitvector(affect) d['affects'] = bitvector_to_flags(affect, MOB_AFFECT_FLAGS) level, thac0, ac, max_hp, bare_hand_dmg = bottom_fields[1].split() gold, xp = bottom_fields[2].split() load_position, default_position, gender = bottom_fields[3].split() d['level'] = int(level) d['thac0'] = int(thac0) d['armor_class'] = int(ac) d['max_hit_points'] = parse_dice_roll_string_to_dict(max_hp) d['bare_hand_damage'] = parse_dice_roll_string_to_dict(bare_hand_dmg) d['gold'] = int(gold) d['xp'] = int(xp) d['position'] = { 'load': lookup_value_to_dict(int(load_position), MOB_POSITION), 'default': lookup_value_to_dict(int(load_position), MOB_POSITION) } d['gender'] = lookup_value_to_dict(int(gender), MOB_GENDER) extra_spec = dict() if len(bottom_fields) > 4: assert mob_type == 'E' assert bottom_fields[-1] == 'E' for line in bottom_fields[4:]: if line == 'E': break # we reached the end of this E-type mob key, value = line.split(': ') extra_spec[key] = int(value) d['extra_spec'] = extra_spec return d
def parse_room(text): parts = text.split('~') vnum, name = parts[0].split('\n') desc = parts[1].strip() zone, flags, sector = parts[2].strip() \ .split('\n')[0].strip().split(' ') d = dict() d['id'] = int(vnum) d['name'] = name.strip() d['desc'] = desc.strip('\n') d['zone_number'] = int(zone) flags = clean_bitvector(flags) d['flags'] = [] if flags: d['flags'] = bitvector_to_flags(flags, ROOM_FLAGS) # sector type flag is always an int d['sector_type'] = lookup_value_to_dict(int(sector), ROOM_SECTOR_TYPES) bottom_matter = '~'.join(parts[2:]) d['exits'] = parse_exits(bottom_matter) d['extra_descs'] = parse_extra_descs(bottom_matter) return d
def parse_object(text): fields = [line.rstrip() for line in text.strip().split('\n')] d = dict() # easy fields d['id'] = int(fields[0]) d['aliases'] = fields[1].rstrip('~').split() d['short_desc'] = fields[2].rstrip('~') d['long_desc'] = fields[3].rstrip('~') d['values'] = [int(v) for v in fields[6].split()] weight, cost, rent, a, b, c = [int(v) for v in fields[7].split()] d['weight'] = weight d['cost'] = cost d['rent'] = rent d['a'] = a d['b'] = b d['c'] = c type_flag, effects_bits, wear_bitvector = fields[5].split() # type flag is always an int d['type'] = lookup_value_to_dict(int(type_flag), OBJECT_TYPE_FLAGS) # parse the bitvectors effects_bits = clean_bitvector(effects_bits) effects = bitvector_to_flags(effects_bits, OBJECT_EXTRA_EFFECTS_FLAGS) d['effects'] = effects wear_bitvector = clean_bitvector(wear_bitvector) d['wear'] = bitvector_to_flags(wear_bitvector, OBJECT_WEAR_FLAGS) action_desc = fields[4].rstrip('~') if action_desc: d['action_desc'] = action_desc d['affects'] = [] d['extra_descs'] = [] if len(fields) > 8: extra_fields = fields[8:] d['affects'] = list(parse_affects(extra_fields)) d['extra_descs'] = list(parse_extra_descs(extra_fields)) return d
def parse_object(text): fields = [line.rstrip() for line in text.strip().split('\n')] d = dict() # easy fields d['id'] = int(fields[0]) d['aliases'] = fields[1].rstrip('~').split() d['short_desc'] = fields[2].rstrip('~') d['long_desc'] = fields[3].rstrip('~') d['values'] = [int(v) for v in fields[6].split()] weight, cost, rent = [int(v) for v in fields[7].split()] d['weight'] = weight d['cost'] = cost d['rent'] = rent type_flag, effects_bits, wear_bitvector = fields[5].split() # type flag is always an int d['type'] = lookup_value_to_dict(int(type_flag), OBJECT_TYPE_FLAGS) # parse the bitvectors effects_bits = clean_bitvector(effects_bits) effects = bitvector_to_flags(effects_bits, OBJECT_EXTRA_EFFECTS_FLAGS) d['effects'] = effects wear_bitvector = clean_bitvector(wear_bitvector) d['wear'] = bitvector_to_flags(wear_bitvector, OBJECT_WEAR_FLAGS) action_desc = fields[4].rstrip('~') if action_desc: d['action_desc'] = action_desc d['affects'] = [] d['extra_descs'] = [] if len(fields) > 8: extra_fields = fields[8:] d['affects'] = list(parse_affects(extra_fields)) d['extra_descs'] = list(parse_extra_descs(extra_fields)) return d