]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.objnam.c
1 /* $NetBSD: hack.objnam.c,v 1.5 2001/03/25 20:44:02 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.objnam.c,v 1.5 2001/03/25 20:44:02 jsm Exp $");
15 #define Sprintf (void) sprintf
16 #define Strcat (void) strcat
17 #define Strcpy (void) strcpy
26 pline("WARNING: prefix too short.");
30 (void) strncpy(s
, pref
, i
); /* do not copy trailing 0 */
39 Sprintf(buf
, (a
< 0) ? "%d" : "+%d", a
);
47 static char buf
[BUFSZ
];
48 struct objclass
*ocl
= &objects
[otyp
];
49 const char *an
= ocl
->oc_name
;
50 const char *dn
= ocl
->oc_descr
;
51 char *un
= ocl
->oc_uname
;
52 int nn
= ocl
->oc_name_known
;
53 switch (ocl
->oc_olet
) {
55 Strcpy(buf
, "potion");
58 Strcpy(buf
, "scroll");
69 if (otyp
>= TURQUOISE
&& otyp
<= JADE
)
70 Strcat(buf
, " stone");
72 Sprintf(eos(buf
), " called %s", un
);
74 Sprintf(eos(buf
), " (%s)", dn
);
76 Strcpy(buf
, dn
? dn
: an
);
77 if (ocl
->oc_olet
== GEM_SYM
)
80 Sprintf(eos(buf
), " called %s", un
);
84 /* here for ring/scroll/potion/wand */
86 Sprintf(eos(buf
), " of %s", an
);
88 Sprintf(eos(buf
), " called %s", un
);
90 Sprintf(eos(buf
), " (%s)", dn
);
98 static char bufr
[BUFSZ
];
99 char *buf
= &(bufr
[PREFIX
]); /* leave room for "17 -3 " */
100 int nn
= objects
[obj
->otyp
].oc_name_known
;
101 const char *an
= objects
[obj
->otyp
].oc_name
;
102 const char *dn
= objects
[obj
->otyp
].oc_descr
;
103 char *un
= objects
[obj
->otyp
].oc_uname
;
104 int pl
= (obj
->quan
!= 1);
105 if (!obj
->dknown
&& !Blind
)
106 obj
->dknown
= 1;/* %% doesnt belong here */
109 Strcpy(buf
, (obj
->spe
< 0 && obj
->known
)
110 ? "cheap plastic imitation of the " : "");
111 Strcat(buf
, "Amulet of Yendor");
121 if (obj
->otyp
== DEAD_HOMUNCULUS
&& pl
) {
123 Strcpy(buf
, "dead homunculi");
127 /* fall into next case */
129 if (obj
->otyp
== WORM_TOOTH
&& pl
) {
131 Strcpy(buf
, "worm teeth");
134 if (obj
->otyp
== CRYSKNIFE
&& pl
) {
136 Strcpy(buf
, "crysknives");
139 /* fall into next case */
146 Sprintf(buf
, "%sheavy iron ball",
147 (obj
->owt
> objects
[obj
->otyp
].oc_weight
) ? "very " : "");
150 if (nn
|| un
|| !obj
->dknown
) {
151 Strcpy(buf
, "potion");
159 Strcat(buf
, " called ");
167 Strcat(buf
, " potion");
171 Strcpy(buf
, "scroll");
182 Strcat(buf
, " called ");
185 Strcat(buf
, " labeled ");
191 Sprintf(buf
, "wand");
193 Sprintf(buf
, "wand of %s", an
);
195 Sprintf(buf
, "wand called %s", un
);
197 Sprintf(buf
, "%s wand", dn
);
201 Sprintf(buf
, "ring");
203 Sprintf(buf
, "ring of %s", an
);
205 Sprintf(buf
, "ring called %s", un
);
207 Sprintf(buf
, "%s ring", dn
);
215 Sprintf(buf
, "%s gem", dn
);
219 if (obj
->otyp
>= TURQUOISE
&& obj
->otyp
<= JADE
)
220 Strcat(buf
, " stone");
223 Sprintf(buf
, "glorkum %c (0%o) %u %d",
224 obj
->olet
, obj
->olet
, obj
->otyp
, obj
->spe
);
229 for (p
= buf
; *p
; p
++) {
230 if (!strncmp(" of ", p
, 4)) {
231 /* pieces of, cloves of, lumps of */
243 if (*p
== 's' || *p
== 'z' || *p
== 'x' ||
244 (*p
== 'h' && p
[-1] == 's'))
245 Strcat(buf
, "es"); /* boxes */
246 else if (*p
== 'y' && !strchr(vowels
, p
[-1]))
247 Strcpy(p
, "ies"); /* rubies, zruties */
253 Strcat(buf
, " named ");
254 Strcat(buf
, ONAME(obj
));
264 char *bp
= xname(obj
);
266 Sprintf(prefix
, "%u ", obj
->quan
);
268 Strcpy(prefix
, "a ");
271 if (strncmp(bp
, "cheap ", 6))
272 Strcpy(prefix
, "the ");
275 if (obj
->owornmask
& W_ARMOR
)
276 Strcat(bp
, " (being worn)");
277 /* fall into next case */
280 Strcat(prefix
, sitoa(obj
->spe
));
286 Sprintf(eos(bp
), " (%d)", obj
->spe
);
289 if (obj
->owornmask
& W_RINGR
)
290 Strcat(bp
, " (on right hand)");
291 if (obj
->owornmask
& W_RINGL
)
292 Strcat(bp
, " (on left hand)");
293 if (obj
->known
&& (objects
[obj
->otyp
].bits
& SPEC
)) {
294 Strcat(prefix
, sitoa(obj
->spe
));
299 if (obj
->owornmask
& W_WEP
)
300 Strcat(bp
, " (weapon in hand)");
302 Strcat(bp
, " (unpaid)");
303 if (!strcmp(prefix
, "a ") && strchr(vowels
, *bp
))
304 Strcpy(prefix
, "an ");
305 bp
= strprepend(bp
, prefix
);
309 /* used only in hack.fight.c (thitu) */
311 setan(const char *str
, char *buf
)
313 if (strchr(vowels
, *str
))
314 Sprintf(buf
, "an %s", str
);
316 Sprintf(buf
, "a %s", str
);
324 char *bp
= xname(otmp
);
326 if (otmp
->quan
!= 1) {
327 Sprintf(prefix
, "%u ", otmp
->quan
);
328 bp
= strprepend(bp
, prefix
);
331 /* verb is given in plural (i.e., without trailing s) */
335 else if (!strcmp(verb
, "are"))
349 char *s
= doname(obj
);
351 if ('a' <= *s
&& *s
<= 'z')
356 const char *const wrp
[] = {"wand", "ring", "potion", "scroll", "gem"};
357 const char wrpsym
[] = {WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
365 int cnt
, spe
, spesgn
, typ
, heavy
;
368 /* int the = 0; char *oname = 0; */
369 cnt
= spe
= spesgn
= typ
= heavy
= 0;
372 for (p
= bp
; *p
; p
++)
373 if ('A' <= *p
&& *p
<= 'Z')
375 if (!strncmp(bp
, "the ", 4)) {
378 } else if (!strncmp(bp
, "an ", 3)) {
381 } else if (!strncmp(bp
, "a ", 2)) {
385 if (!cnt
&& digit(*bp
)) {
393 cnt
= 1; /* %% what with "gems" etc. ? */
395 if (*bp
== '+' || *bp
== '-') {
396 spesgn
= (*bp
++ == '+') ? 1 : -1;
403 p
= strrchr(bp
, '(');
405 if (p
> bp
&& p
[-1] == ' ')
420 * now we have the actual name, as delivered by xname, say green
421 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
422 * fortune cookies very heavy iron ball named hoei wand of wishing
425 for (p
= bp
; *p
; p
++)
426 if (!strncmp(p
, " named ", 7)) {
430 for (p
= bp
; *p
; p
++)
431 if (!strncmp(p
, " called ", 8)) {
435 for (p
= bp
; *p
; p
++)
436 if (!strncmp(p
, " labeled ", 9)) {
440 /* first change to singular if necessary */
442 /* find "cloves of garlic", "worthless pieces of blue glass" */
443 for (p
= bp
; *p
; p
++)
444 if (!strncmp(p
, "s of ", 5)) {
445 while ((*p
= p
[1]) != '\0')
449 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
454 if (!strcmp(p
- 7, "cookies"))
459 /* note: cloves / knives from clove / knife */
460 if (!strcmp(p
- 6, "knives")) {
464 /* note: nurses, axes but boxes */
465 if (!strcmp(p
- 5, "boxes")) {
473 if (!strcmp(p
- 9, "homunculi")) {
474 Strcpy(p
- 1, "us"); /* !! makes string
478 if (!strcmp(p
- 5, "teeth")) {
479 Strcpy(p
- 5, "tooth");
482 /* here we cannot find the plural suffix */
486 if (!strcmp(bp
, "amulet of yendor")) {
487 typ
= AMULET_OF_YENDOR
;
491 if (!strcmp(p
- 5, " mail")) { /* Note: ring mail is not a ring ! */
496 for (i
= 0; i
< sizeof(wrpsym
); i
++) {
497 int j
= strlen(wrp
[i
]);
498 if (!strncmp(bp
, wrp
[i
], j
)) {
501 if (!strncmp(bp
, " of ", 4))
503 /* else if(*bp) ?? */
506 if (!strcmp(p
- j
, wrp
[i
])) {
516 if (!strcmp(p
- 6, " stone")) {
522 if (!strcmp(bp
, "very heavy iron ball")) {
524 typ
= HEAVY_IRON_BALL
;
529 if (!an
&& !dn
&& !un
)
533 i
= bases
[letindex(let
)];
534 while (i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)) {
535 const char *zn
= objects
[i
].oc_name
;
539 if (an
&& strcmp(an
, zn
))
541 if (dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
543 if (un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
552 let
= wrpsym
[rn2(sizeof(wrpsym
))];
557 let
= objects
[typ
].oc_olet
;
561 if (cnt
> 0 && strchr("%?!*)", let
) &&
562 (cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
565 if (spe
> 3 && spe
> otmp
->spe
)
567 else if (let
== WAND_SYM
)
569 if (spe
== 3 && u
.uluck
< 0)
571 if (let
!= WAND_SYM
&& spesgn
== -1)
575 else if (let
== AMULET_SYM
)
577 else if (typ
== WAN_WISHING
&& rn2(10))
578 spe
= (rn2(10) ? -1 : 0);