/** * Format object obj's name into 'buf'. */ static size_t obj_desc_name(char *buf, size_t max, size_t end, const struct object *obj, bool prefix, int mode, bool spoil, bool terse) { bool known = object_is_known(obj) || spoil; bool aware = object_flavor_is_aware(obj) || (mode & ODESC_STORE) || spoil; const char *basename = obj_desc_get_basename(obj, aware, terse, mode); const char *modstr = obj_desc_get_modstr(obj->kind); if (aware && !obj->kind->everseen && !spoil) obj->kind->everseen = TRUE; if (prefix) end = obj_desc_name_prefix(buf, max, end, obj, known, basename, modstr, terse); /* Pluralize if (not forced singular) and * (not a known/visible artifact) and * (not one in stack or forced plural) */ end = obj_desc_name_format(buf, max, end, basename, modstr, !(mode & ODESC_SINGULAR) && !(obj->artifact && (object_name_is_visible(obj) || known)) && (obj->number != 1 || (mode & ODESC_PLURAL))); /** Append extra names of various kinds **/ if ((object_name_is_visible(obj) || known) && obj->artifact) strnfcat(buf, max, &end, " %s", obj->artifact->name); else if (((spoil && obj->ego) || object_ego_is_visible(obj)) && !(mode & ODESC_NOEGO)) strnfcat(buf, max, &end, " %s", obj->ego->name); else if (aware && !obj->artifact && (obj->kind->flavor || obj->kind->tval == TV_SCROLL)) { if (terse) strnfcat(buf, max, &end, " '%s'", obj->kind->name); else strnfcat(buf, max, &end, " of %s", obj->kind->name); } return end; }
/* * Copy 'src' into 'buf, replacing '#' with 'modstr' (if found), putting a plural * in the place indicated by '~' if required, or using alterate... */ static size_t obj_desc_name(char *buf, size_t max, size_t end, const object_type *o_ptr, bool prefix, byte mode, bool spoil) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; bool known = object_is_known(o_ptr) || (o_ptr->ident & IDENT_STORE) || spoil; bool aware = object_flavor_is_aware(o_ptr) || (o_ptr->ident & IDENT_STORE) || spoil; const char *basename = obj_desc_get_basename(o_ptr, aware); const char *modstr = obj_desc_get_modstr(o_ptr); bool pluralise = (mode & ODESC_PLURAL) ? TRUE : FALSE; if (o_ptr->number > 1) pluralise = TRUE; if (mode & ODESC_SINGULAR) pluralise = FALSE; /* Add a pseudo-numerical prefix if desired */ if (prefix) { if (o_ptr->number <= 0) { strnfcat(buf, max, &end, "no more "); /* Pluralise for grammatical correctness */ pluralise = TRUE; } else if (o_ptr->number > 1) strnfcat(buf, max, &end, "%d ", o_ptr->number); else if ((known) && artifact_p(o_ptr)) strnfcat(buf, max, &end, "The "); else if (*basename == '&') { bool an = FALSE; const char *lookahead = basename + 1; while (*lookahead == ' ') lookahead++; if (*lookahead == '#') { if (modstr && is_a_vowel(*modstr)) an = TRUE; } else if (is_a_vowel(*lookahead)) { an = TRUE; } if (an) strnfcat(buf, max, &end, "an "); else strnfcat(buf, max, &end, "a "); } } /* Perfectly balanced throwing weapons are indicated. */ if ((known) && (o_ptr->ident & IDENT_PERFECT_BALANCE)) { strnfcat(buf, max, &end, "Well-balanced "); } /* * Names have the following elements: * * '~' indicates where to place an 's' or an 'es'. Other plural forms should * be handled with the syntax '|singular|plural|', e.g. "kni|fe|ves|". * * '#' indicates the position of the "modifier", e.g. the flavour or spellbook * name. */ /* Copy the string */ while (*basename) { if (*basename == '&') { while (*basename == ' ' || *basename == '&') basename++; continue; } /* Pluralizer (regular English plurals) */ else if (*basename == '~') { char prev = *(basename - 1); if (!pluralise) { basename++; continue; } /* e.g. cutlass-e-s, torch-e-s, box-e-s */ if (prev == 's' || prev == 'h' || prev == 'x') strnfcat(buf, max, &end, "es"); else strnfcat(buf, max, &end, "s"); } /* Special plurals */ else if (*basename == '|') { /* e.g. & Wooden T|o|e|rch~ * ^ ^^ */ const char *singular = basename + 1; const char *plural = strchr(singular, '|'); const char *endmark = NULL; if (plural) { plural++; endmark = strchr(plural, '|'); } if (!singular || !plural || !endmark) return end; if (!pluralise) strnfcat(buf, max, &end, "%.*s", plural - singular - 1, singular); else strnfcat(buf, max, &end, "%.*s", endmark - plural, plural); basename = endmark; } /* Handle pluralisation in the modifier XXX */ else if (*basename == '#') { const char *basename = modstr; while (basename && *basename && (end < max - 1)) { /* Special plurals */ if (*basename == '|') { /* e.g. & Wooden T|o|e|rch~ * ^ ^^ */ const char *singular = basename + 1; const char *plural = strchr(singular, '|'); const char *endmark = NULL; if (plural) { plural++; endmark = strchr(plural, '|'); } if (!singular || !plural || !endmark) return end; if (!pluralise) strnfcat(buf, max, &end, "%.*s", plural - singular - 1, singular); else strnfcat(buf, max, &end, "%.*s", endmark - plural, plural); basename = endmark; } else buf[end++] = *basename; basename++; } } else buf[end++] = *basename; basename++; } /* 0-terminate, just in case XXX */ buf[end] = 0; /** Append extra names of various kinds **/ if ((known) && o_ptr->art_num) strnfcat(buf, max, &end, " %s", a_info[o_ptr->art_num].name); else if ((o_ptr->ego_num) && (known || spoil)) { strnfcat(buf, max, &end, " %s", e_name + e_info[o_ptr->ego_num].name); } else if (aware && !artifact_p(o_ptr) && (k_ptr->flavor || k_ptr->tval == TV_SCROLL)) strnfcat(buf, max, &end, " of %s", k_name + k_ptr->name); return end; }