1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.objnam.c - version 1.0.2 */
5 #define Sprintf (void) sprintf
6 #define Strcat (void) strcat
7 #define Strcpy (void) strcpy
13 strprepend(s,pref) register char *s, *pref; {
14 register int i = strlen(pref);
16 pline("WARNING: prefix too short.");
20 (void) strncpy(s, pref, i); /* do not copy trailing 0 */
27 Sprintf(buf, (a < 0) ? "%d" : "+%d", a);
35 static char buf[BUFSZ];
36 register struct objclass *ocl = &objects[otyp];
37 register char *an = ocl->oc_name;
38 register char *dn = ocl->oc_descr;
39 register char *un = ocl->oc_uname;
40 register int nn = ocl->oc_name_known;
41 switch(ocl->oc_olet) {
43 Strcpy(buf, "potion");
46 Strcpy(buf, "scroll");
57 if(otyp >= TURQUOISE && otyp <= JADE)
58 Strcat(buf, " stone");
60 Sprintf(eos(buf), " called %s", un);
62 Sprintf(eos(buf), " (%s)", dn);
64 Strcpy(buf, dn ? dn : an);
65 if(ocl->oc_olet == GEM_SYM)
68 Sprintf(eos(buf), " called %s", un);
72 /* here for ring/scroll/potion/wand */
74 Sprintf(eos(buf), " of %s", an);
76 Sprintf(eos(buf), " called %s", un);
78 Sprintf(eos(buf), " (%s)", dn);
84 register struct obj *obj;
86 static char bufr[BUFSZ];
87 register char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */
88 register int nn = objects[obj->otyp].oc_name_known;
89 register char *an = objects[obj->otyp].oc_name;
90 register char *dn = objects[obj->otyp].oc_descr;
91 register char *un = objects[obj->otyp].oc_uname;
92 register int pl = (obj->quan != 1);
93 if(!obj->dknown && !Blind) obj->dknown = 1; /* %% doesnt belong here */
96 Strcpy(buf, (obj->spe < 0 && obj->known)
97 ? "cheap plastic imitation of the " : "");
98 Strcat(buf,"Amulet of Yendor");
108 if(obj->otyp == DEAD_HOMUNCULUS && pl) {
110 Strcpy(buf, "dead homunculi");
114 /* fall into next case */
116 if(obj->otyp == WORM_TOOTH && pl) {
118 Strcpy(buf, "worm teeth");
121 if(obj->otyp == CRYSKNIFE && pl) {
123 Strcpy(buf, "crysknives");
126 /* fall into next case */
133 Sprintf(buf, "%sheavy iron ball",
134 (obj->owt > objects[obj->otyp].oc_weight) ? "very " : "");
137 if(nn || un || !obj->dknown) {
138 Strcpy(buf, "potion");
143 if(!obj->dknown) break;
145 Strcat(buf, " called ");
153 Strcat(buf, " potion");
157 Strcpy(buf, "scroll");
162 if(!obj->dknown) break;
167 Strcat(buf, " called ");
170 Strcat(buf, " labeled ");
176 Sprintf(buf, "wand");
178 Sprintf(buf, "wand of %s", an);
180 Sprintf(buf, "wand called %s", un);
182 Sprintf(buf, "%s wand", dn);
186 Sprintf(buf, "ring");
188 Sprintf(buf, "ring of %s", an);
190 Sprintf(buf, "ring called %s", un);
192 Sprintf(buf, "%s ring", dn);
200 Sprintf(buf, "%s gem", dn);
204 if(obj->otyp >= TURQUOISE && obj->otyp <= JADE)
205 Strcat(buf, " stone");
208 Sprintf(buf,"glorkum %c (0%o) %u %d",
209 obj->olet,obj->olet,obj->otyp,obj->spe);
214 for(p = buf; *p; p++) {
215 if(!strncmp(" of ", p, 4)) {
216 /* pieces of, cloves of, lumps of */
217 register int c1, c2 = 's';
220 c1 = c2; c2 = *p; *p++ = c1;
226 if(*p == 's' || *p == 'z' || *p == 'x' ||
227 (*p == 'h' && p[-1] == 's'))
228 Strcat(buf, "es"); /* boxes */
229 else if(*p == 'y' && !index(vowels, p[-1]))
230 Strcpy(p, "ies"); /* rubies, zruties */
236 Strcat(buf, " named ");
237 Strcat(buf, ONAME(obj));
244 register struct obj *obj;
247 register char *bp = xname(obj);
249 Sprintf(prefix, "%u ", obj->quan);
251 Strcpy(prefix, "a ");
254 if(strncmp(bp, "cheap ", 6))
255 Strcpy(prefix, "the ");
258 if(obj->owornmask & W_ARMOR)
259 Strcat(bp, " (being worn)");
260 /* fall into next case */
263 Strcat(prefix, sitoa(obj->spe));
269 Sprintf(eos(bp), " (%d)", obj->spe);
272 if(obj->owornmask & W_RINGR) Strcat(bp, " (on right hand)");
273 if(obj->owornmask & W_RINGL) Strcat(bp, " (on left hand)");
274 if(obj->known && (objects[obj->otyp].bits & SPEC)) {
275 Strcat(prefix, sitoa(obj->spe));
280 if(obj->owornmask & W_WEP)
281 Strcat(bp, " (weapon in hand)");
283 Strcat(bp, " (unpaid)");
284 if(!strcmp(prefix, "a ") && index(vowels, *bp))
285 Strcpy(prefix, "an ");
286 bp = strprepend(bp, prefix);
290 /* used only in hack.fight.c (thitu) */
292 register char *str,*buf;
294 if(index(vowels,*str))
295 Sprintf(buf, "an %s", str);
297 Sprintf(buf, "a %s", str);
301 aobjnam(otmp,verb) register struct obj *otmp; register char *verb; {
302 register char *bp = xname(otmp);
304 if(otmp->quan != 1) {
305 Sprintf(prefix, "%u ", otmp->quan);
306 bp = strprepend(bp, prefix);
310 /* verb is given in plural (i.e., without trailing s) */
314 else if(!strcmp(verb, "are"))
326 register struct obj *obj;
328 register char *s = doname(obj);
330 if('a' <= *s && *s <= 'z') *s -= ('a' - 'A');
334 char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" };
335 char wrpsym[] = { WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM };
338 readobjnam(bp) register char *bp; {
341 int cnt, spe, spesgn, typ, heavy;
344 /* int the = 0; char *oname = 0; */
345 cnt = spe = spesgn = typ = heavy = 0;
349 if('A' <= *p && *p <= 'Z') *p += 'a'-'A';
350 if(!strncmp(bp, "the ", 4)){
353 } else if(!strncmp(bp, "an ", 3)){
356 } else if(!strncmp(bp, "a ", 2)){
360 if(!cnt && digit(*bp)){
362 while(digit(*bp)) bp++;
363 while(*bp == ' ') bp++;
365 if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */
367 if(*bp == '+' || *bp == '-'){
368 spesgn = (*bp++ == '+') ? 1 : -1;
370 while(digit(*bp)) bp++;
371 while(*bp == ' ') bp++;
375 if(p > bp && p[-1] == ' ') p[-1] = 0;
379 while(digit(*p)) p++;
380 if(strcmp(p, ")")) spe = 0;
384 /* now we have the actual name, as delivered by xname, say
385 green potions called whisky
386 scrolls labeled "QWERTY"
390 very heavy iron ball named hoei
394 for(p = bp; *p; p++) if(!strncmp(p, " named ", 7)) {
398 for(p = bp; *p; p++) if(!strncmp(p, " called ", 8)) {
402 for(p = bp; *p; p++) if(!strncmp(p, " labeled ", 9)) {
407 /* first change to singular if necessary */
409 /* find "cloves of garlic", "worthless pieces of blue glass" */
410 for(p = bp; *p; p++) if(!strncmp(p, "s of ", 5)){
411 while(*p = p[1]) p++;
414 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
419 if(!strcmp(p-7, "cookies"))
425 /* note: cloves / knives from clove / knife */
426 if(!strcmp(p-6, "knives")) {
431 /* note: nurses, axes but boxes */
432 if(!strcmp(p-5, "boxes")) {
440 if(!strcmp(p-9, "homunculi")) {
441 Strcpy(p-1, "us"); /* !! makes string longer */
444 if(!strcmp(p-5, "teeth")) {
445 Strcpy(p-5, "tooth");
448 /* here we cannot find the plural suffix */
452 if(!strcmp(bp, "amulet of yendor")) {
453 typ = AMULET_OF_YENDOR;
457 if(!strcmp(p-5, " mail")){ /* Note: ring mail is not a ring ! */
462 for(i = 0; i < sizeof(wrpsym); i++) {
463 register int j = strlen(wrp[i]);
464 if(!strncmp(bp, wrp[i], j)){
467 if(!strncmp(bp, " of ", 4)) an = bp+4;
468 /* else if(*bp) ?? */
471 if(!strcmp(p-j, wrp[i])){
475 if(p[-1] == ' ') p[-1] = 0;
480 if(!strcmp(p-6, " stone")){
486 if(!strcmp(bp, "very heavy iron ball")){
488 typ = HEAVY_IRON_BALL;
493 if(!an && !dn && !un)
496 if(let) i = bases[letindex(let)];
497 while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){
498 register char *zn = objects[i].oc_name;
501 if(an && strcmp(an, zn))
503 if(dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
505 if(un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
513 if(!let) let = wrpsym[rn2(sizeof(wrpsym))];
516 { register struct obj *otmp;
517 extern struct obj *mksobj();
518 let = objects[typ].oc_olet;
522 if(cnt > 0 && index("%?!*)", let) &&
523 (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
526 if(spe > 3 && spe > otmp->spe)
528 else if(let == WAND_SYM)
530 if(spe == 3 && u.uluck < 0)
532 if(let != WAND_SYM && spesgn == -1)
536 else if(let == AMULET_SYM)
538 else if(typ == WAN_WISHING && rn2(10))
539 spe = (rn2(10) ? -1 : 0);