]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.objnam.c
1 /* $NetBSD: hack.objnam.c,v 1.4 1997/10/19 16:58:39 christos Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.objnam.c,v 1.4 1997/10/19 16:58:39 christos 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 char *an
= ocl
->oc_name
;
50 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 char *an
= objects
[obj
->otyp
].oc_name
;
102 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) */
314 if (strchr(vowels
, *str
))
315 Sprintf(buf
, "an %s", str
);
317 Sprintf(buf
, "a %s", str
);
325 char *bp
= xname(otmp
);
327 if (otmp
->quan
!= 1) {
328 Sprintf(prefix
, "%u ", otmp
->quan
);
329 bp
= strprepend(bp
, prefix
);
332 /* verb is given in plural (i.e., without trailing s) */
336 else if (!strcmp(verb
, "are"))
350 char *s
= doname(obj
);
352 if ('a' <= *s
&& *s
<= 'z')
357 char *wrp
[] = {"wand", "ring", "potion", "scroll", "gem"};
358 char wrpsym
[] = {WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
366 int cnt
, spe
, spesgn
, typ
, heavy
;
369 /* int the = 0; char *oname = 0; */
370 cnt
= spe
= spesgn
= typ
= heavy
= 0;
373 for (p
= bp
; *p
; p
++)
374 if ('A' <= *p
&& *p
<= 'Z')
376 if (!strncmp(bp
, "the ", 4)) {
379 } else if (!strncmp(bp
, "an ", 3)) {
382 } else if (!strncmp(bp
, "a ", 2)) {
386 if (!cnt
&& digit(*bp
)) {
394 cnt
= 1; /* %% what with "gems" etc. ? */
396 if (*bp
== '+' || *bp
== '-') {
397 spesgn
= (*bp
++ == '+') ? 1 : -1;
404 p
= strrchr(bp
, '(');
406 if (p
> bp
&& p
[-1] == ' ')
421 * now we have the actual name, as delivered by xname, say green
422 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
423 * fortune cookies very heavy iron ball named hoei wand of wishing
426 for (p
= bp
; *p
; p
++)
427 if (!strncmp(p
, " named ", 7)) {
431 for (p
= bp
; *p
; p
++)
432 if (!strncmp(p
, " called ", 8)) {
436 for (p
= bp
; *p
; p
++)
437 if (!strncmp(p
, " labeled ", 9)) {
441 /* first change to singular if necessary */
443 /* find "cloves of garlic", "worthless pieces of blue glass" */
444 for (p
= bp
; *p
; p
++)
445 if (!strncmp(p
, "s of ", 5)) {
446 while ((*p
= p
[1]) != '\0')
450 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
455 if (!strcmp(p
- 7, "cookies"))
460 /* note: cloves / knives from clove / knife */
461 if (!strcmp(p
- 6, "knives")) {
465 /* note: nurses, axes but boxes */
466 if (!strcmp(p
- 5, "boxes")) {
474 if (!strcmp(p
- 9, "homunculi")) {
475 Strcpy(p
- 1, "us"); /* !! makes string
479 if (!strcmp(p
- 5, "teeth")) {
480 Strcpy(p
- 5, "tooth");
483 /* here we cannot find the plural suffix */
487 if (!strcmp(bp
, "amulet of yendor")) {
488 typ
= AMULET_OF_YENDOR
;
492 if (!strcmp(p
- 5, " mail")) { /* Note: ring mail is not a ring ! */
497 for (i
= 0; i
< sizeof(wrpsym
); i
++) {
498 int j
= strlen(wrp
[i
]);
499 if (!strncmp(bp
, wrp
[i
], j
)) {
502 if (!strncmp(bp
, " of ", 4))
504 /* else if(*bp) ?? */
507 if (!strcmp(p
- j
, wrp
[i
])) {
517 if (!strcmp(p
- 6, " stone")) {
523 if (!strcmp(bp
, "very heavy iron ball")) {
525 typ
= HEAVY_IRON_BALL
;
530 if (!an
&& !dn
&& !un
)
534 i
= bases
[letindex(let
)];
535 while (i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)) {
536 char *zn
= objects
[i
].oc_name
;
540 if (an
&& strcmp(an
, zn
))
542 if (dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
544 if (un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
553 let
= wrpsym
[rn2(sizeof(wrpsym
))];
558 let
= objects
[typ
].oc_olet
;
562 if (cnt
> 0 && strchr("%?!*)", let
) &&
563 (cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
566 if (spe
> 3 && spe
> otmp
->spe
)
568 else if (let
== WAND_SYM
)
570 if (spe
== 3 && u
.uluck
< 0)
572 if (let
!= WAND_SYM
&& spesgn
== -1)
576 else if (let
== AMULET_SYM
)
578 else if (typ
== WAN_WISHING
&& rn2(10))
579 spe
= (rn2(10) ? -1 : 0);