1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.objnam.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.objnam.c,v 1.3 1999/11/16 02:57:08 billf Exp $ */
6 #define Sprintf (void) sprintf
7 #define Strcat (void) strcat
8 #define Strcpy (void) strcpy
14 strprepend(s,pref) char *s, *pref; {
17 pline("WARNING: prefix too short.");
21 (void) strncpy(s, pref, i); /* do not copy trailing 0 */
28 Sprintf(buf, (a < 0) ? "%d" : "+%d", a);
36 static char buf[BUFSZ];
37 struct objclass *ocl = &objects[otyp];
38 char *an = ocl->oc_name;
39 char *dn = ocl->oc_descr;
40 char *un = ocl->oc_uname;
41 int nn = ocl->oc_name_known;
42 switch(ocl->oc_olet) {
44 Strcpy(buf, "potion");
47 Strcpy(buf, "scroll");
58 if(otyp >= TURQUOISE && otyp <= JADE)
59 Strcat(buf, " stone");
61 Sprintf(eos(buf), " called %s", un);
63 Sprintf(eos(buf), " (%s)", dn);
65 Strcpy(buf, dn ? dn : an);
66 if(ocl->oc_olet == GEM_SYM)
69 Sprintf(eos(buf), " called %s", un);
73 /* here for ring/scroll/potion/wand */
75 Sprintf(eos(buf), " of %s", an);
77 Sprintf(eos(buf), " called %s", un);
79 Sprintf(eos(buf), " (%s)", dn);
87 static char bufr[BUFSZ];
88 char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */
89 int nn = objects[obj->otyp].oc_name_known;
90 char *an = objects[obj->otyp].oc_name;
91 char *dn = objects[obj->otyp].oc_descr;
92 char *un = objects[obj->otyp].oc_uname;
93 int pl = (obj->quan != 1);
94 if(!obj->dknown && !Blind) obj->dknown = 1; /* %% doesnt belong here */
97 Strcpy(buf, (obj->spe < 0 && obj->known)
98 ? "cheap plastic imitation of the " : "");
99 Strcat(buf,"Amulet of Yendor");
109 if(obj->otyp == DEAD_HOMUNCULUS && pl) {
111 Strcpy(buf, "dead homunculi");
115 /* fall into next case */
117 if(obj->otyp == WORM_TOOTH && pl) {
119 Strcpy(buf, "worm teeth");
122 if(obj->otyp == CRYSKNIFE && pl) {
124 Strcpy(buf, "crysknives");
127 /* fall into next case */
134 Sprintf(buf, "%sheavy iron ball",
135 (obj->owt > objects[obj->otyp].oc_weight) ? "very " : "");
138 if(nn || un || !obj->dknown) {
139 Strcpy(buf, "potion");
144 if(!obj->dknown) break;
146 Strcat(buf, " called ");
154 Strcat(buf, " potion");
158 Strcpy(buf, "scroll");
163 if(!obj->dknown) break;
168 Strcat(buf, " called ");
171 Strcat(buf, " labeled ");
177 Sprintf(buf, "wand");
179 Sprintf(buf, "wand of %s", an);
181 Sprintf(buf, "wand called %s", un);
183 Sprintf(buf, "%s wand", dn);
187 Sprintf(buf, "ring");
189 Sprintf(buf, "ring of %s", an);
191 Sprintf(buf, "ring called %s", un);
193 Sprintf(buf, "%s ring", dn);
201 Sprintf(buf, "%s gem", dn);
205 if(obj->otyp >= TURQUOISE && obj->otyp <= JADE)
206 Strcat(buf, " stone");
209 Sprintf(buf,"glorkum %c (0%o) %u %d",
210 obj->olet,obj->olet,obj->otyp,obj->spe);
215 for(p = buf; *p; p++) {
216 if(!strncmp(" of ", p, 4)) {
217 /* pieces of, cloves of, lumps of */
221 c1 = c2; c2 = *p; *p++ = c1;
227 if(*p == 's' || *p == 'z' || *p == 'x' ||
228 (*p == 'h' && p[-1] == 's'))
229 Strcat(buf, "es"); /* boxes */
230 else if(*p == 'y' && !index(vowels, p[-1]))
231 Strcpy(p, "ies"); /* rubies, zruties */
237 Strcat(buf, " named ");
238 Strcat(buf, ONAME(obj));
248 char *bp = xname(obj);
250 Sprintf(prefix, "%u ", obj->quan);
252 Strcpy(prefix, "a ");
255 if(strncmp(bp, "cheap ", 6))
256 Strcpy(prefix, "the ");
259 if(obj->owornmask & W_ARMOR)
260 Strcat(bp, " (being worn)");
261 /* fall into next case */
264 Strcat(prefix, sitoa(obj->spe));
270 Sprintf(eos(bp), " (%d)", obj->spe);
273 if(obj->owornmask & W_RINGR) Strcat(bp, " (on right hand)");
274 if(obj->owornmask & W_RINGL) Strcat(bp, " (on left hand)");
275 if(obj->known && (objects[obj->otyp].bits & SPEC)) {
276 Strcat(prefix, sitoa(obj->spe));
281 if(obj->owornmask & W_WEP)
282 Strcat(bp, " (weapon in hand)");
284 Strcat(bp, " (unpaid)");
285 if(!strcmp(prefix, "a ") && index(vowels, *bp))
286 Strcpy(prefix, "an ");
287 bp = strprepend(bp, prefix);
291 /* used only in hack.fight.c (thitu) */
295 if(index(vowels,*str))
296 Sprintf(buf, "an %s", str);
298 Sprintf(buf, "a %s", str);
302 aobjnam(otmp,verb) struct obj *otmp; char *verb; {
303 char *bp = xname(otmp);
305 if(otmp->quan != 1) {
306 Sprintf(prefix, "%u ", otmp->quan);
307 bp = strprepend(bp, prefix);
311 /* verb is given in plural (i.e., without trailing s) */
315 else if(!strcmp(verb, "are"))
329 char *s = doname(obj);
331 if('a' <= *s && *s <= 'z') *s -= ('a' - 'A');
335 char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" };
336 char wrpsym[] = { WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM };
339 readobjnam(bp) char *bp; {
342 int cnt, spe, spesgn, typ, heavy;
345 /* int the = 0; char *oname = 0; */
346 cnt = spe = spesgn = typ = heavy = 0;
350 if('A' <= *p && *p <= 'Z') *p += 'a'-'A';
351 if(!strncmp(bp, "the ", 4)){
354 } else if(!strncmp(bp, "an ", 3)){
357 } else if(!strncmp(bp, "a ", 2)){
361 if(!cnt && digit(*bp)){
363 while(digit(*bp)) bp++;
364 while(*bp == ' ') bp++;
366 if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */
368 if(*bp == '+' || *bp == '-'){
369 spesgn = (*bp++ == '+') ? 1 : -1;
371 while(digit(*bp)) bp++;
372 while(*bp == ' ') bp++;
376 if(p > bp && p[-1] == ' ') p[-1] = 0;
380 while(digit(*p)) p++;
381 if(strcmp(p, ")")) spe = 0;
385 /* now we have the actual name, as delivered by xname, say
386 green potions called whisky
387 scrolls labeled "QWERTY"
391 very heavy iron ball named hoei
395 for(p = bp; *p; p++) if(!strncmp(p, " named ", 7)) {
399 for(p = bp; *p; p++) if(!strncmp(p, " called ", 8)) {
403 for(p = bp; *p; p++) if(!strncmp(p, " labeled ", 9)) {
408 /* first change to singular if necessary */
410 /* find "cloves of garlic", "worthless pieces of blue glass" */
411 for(p = bp; *p; p++) if(!strncmp(p, "s of ", 5)){
412 while(*p = p[1]) p++;
415 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
420 if(!strcmp(p-7, "cookies"))
426 /* note: cloves / knives from clove / knife */
427 if(!strcmp(p-6, "knives")) {
432 /* note: nurses, axes but boxes */
433 if(!strcmp(p-5, "boxes")) {
441 if(!strcmp(p-9, "homunculi")) {
442 Strcpy(p-1, "us"); /* !! makes string longer */
445 if(!strcmp(p-5, "teeth")) {
446 Strcpy(p-5, "tooth");
449 /* here we cannot find the plural suffix */
453 if(!strcmp(bp, "amulet of yendor")) {
454 typ = AMULET_OF_YENDOR;
458 if(!strcmp(p-5, " mail")){ /* Note: ring mail is not a ring ! */
463 for(i = 0; i < sizeof(wrpsym); i++) {
464 int j = strlen(wrp[i]);
465 if(!strncmp(bp, wrp[i], j)){
468 if(!strncmp(bp, " of ", 4)) an = bp+4;
469 /* else if(*bp) ?? */
472 if(!strcmp(p-j, wrp[i])){
476 if(p[-1] == ' ') p[-1] = 0;
481 if(!strcmp(p-6, " stone")){
487 if(!strcmp(bp, "very heavy iron ball")){
489 typ = HEAVY_IRON_BALL;
494 if(!an && !dn && !un)
497 if(let) i = bases[letindex(let)];
498 while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){
499 char *zn = objects[i].oc_name;
502 if(an && strcmp(an, zn))
504 if(dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
506 if(un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
514 if(!let) let = wrpsym[rn2(sizeof(wrpsym))];
518 extern struct obj *mksobj();
519 let = objects[typ].oc_olet;
523 if(cnt > 0 && index("%?!*)", let) &&
524 (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
527 if(spe > 3 && spe > otmp->spe)
529 else if(let == WAND_SYM)
531 if(spe == 3 && u.uluck < 0)
533 if(let != WAND_SYM && spesgn == -1)
537 else if(let == AMULET_SYM)
539 else if(typ == WAN_WISHING && rn2(10))
540 spe = (rn2(10) ? -1 : 0);