]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.objnam.c
1 /* $NetBSD: hack.objnam.c,v 1.8 2009/06/07 18:30:39 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.objnam.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
72 #define Sprintf (void) sprintf
73 #define Strcat (void) strcat
74 #define Strcpy (void) strcpy
78 strprepend(char *s
, char *pref
)
82 pline("WARNING: prefix too short.");
86 (void) strncpy(s
, pref
, i
); /* do not copy trailing 0 */
94 Sprintf(buf
, (a
< 0) ? "%d" : "+%d", a
);
101 static char buf
[BUFSZ
];
102 struct objclass
*ocl
= &objects
[otyp
];
103 const char *an
= ocl
->oc_name
;
104 const char *dn
= ocl
->oc_descr
;
105 char *un
= ocl
->oc_uname
;
106 int nn
= ocl
->oc_name_known
;
107 switch (ocl
->oc_olet
) {
109 Strcpy(buf
, "potion");
112 Strcpy(buf
, "scroll");
123 if (otyp
>= TURQUOISE
&& otyp
<= JADE
)
124 Strcat(buf
, " stone");
126 Sprintf(eos(buf
), " called %s", un
);
128 Sprintf(eos(buf
), " (%s)", dn
);
130 Strcpy(buf
, dn
? dn
: an
);
131 if (ocl
->oc_olet
== GEM_SYM
)
134 Sprintf(eos(buf
), " called %s", un
);
138 /* here for ring/scroll/potion/wand */
140 Sprintf(eos(buf
), " of %s", an
);
142 Sprintf(eos(buf
), " called %s", un
);
144 Sprintf(eos(buf
), " (%s)", dn
);
149 xname(struct obj
*obj
)
151 static char bufr
[BUFSZ
];
152 char *buf
= &(bufr
[PREFIX
]); /* leave room for "17 -3 " */
153 int nn
= objects
[obj
->otyp
].oc_name_known
;
154 const char *an
= objects
[obj
->otyp
].oc_name
;
155 const char *dn
= objects
[obj
->otyp
].oc_descr
;
156 char *un
= objects
[obj
->otyp
].oc_uname
;
157 int pl
= (obj
->quan
!= 1);
158 if (!obj
->dknown
&& !Blind
)
159 obj
->dknown
= 1;/* %% doesnt belong here */
162 Strcpy(buf
, (obj
->spe
< 0 && obj
->known
)
163 ? "cheap plastic imitation of the " : "");
164 Strcat(buf
, "Amulet of Yendor");
174 if (obj
->otyp
== DEAD_HOMUNCULUS
&& pl
) {
176 Strcpy(buf
, "dead homunculi");
180 /* fall into next case */
182 if (obj
->otyp
== WORM_TOOTH
&& pl
) {
184 Strcpy(buf
, "worm teeth");
187 if (obj
->otyp
== CRYSKNIFE
&& pl
) {
189 Strcpy(buf
, "crysknives");
192 /* fall into next case */
199 Sprintf(buf
, "%sheavy iron ball",
200 (obj
->owt
> objects
[obj
->otyp
].oc_weight
) ? "very " : "");
203 if (nn
|| un
|| !obj
->dknown
) {
204 Strcpy(buf
, "potion");
212 Strcat(buf
, " called ");
220 Strcat(buf
, " potion");
224 Strcpy(buf
, "scroll");
235 Strcat(buf
, " called ");
238 Strcat(buf
, " labeled ");
244 Sprintf(buf
, "wand");
246 Sprintf(buf
, "wand of %s", an
);
248 Sprintf(buf
, "wand called %s", un
);
250 Sprintf(buf
, "%s wand", dn
);
254 Sprintf(buf
, "ring");
256 Sprintf(buf
, "ring of %s", an
);
258 Sprintf(buf
, "ring called %s", un
);
260 Sprintf(buf
, "%s ring", dn
);
268 Sprintf(buf
, "%s gem", dn
);
272 if (obj
->otyp
>= TURQUOISE
&& obj
->otyp
<= JADE
)
273 Strcat(buf
, " stone");
276 Sprintf(buf
, "glorkum %c (0%o) %u %d",
277 obj
->olet
, obj
->olet
, obj
->otyp
, obj
->spe
);
282 for (p
= buf
; *p
; p
++) {
283 if (!strncmp(" of ", p
, 4)) {
284 /* pieces of, cloves of, lumps of */
296 if (*p
== 's' || *p
== 'z' || *p
== 'x' ||
297 (*p
== 'h' && p
[-1] == 's'))
298 Strcat(buf
, "es"); /* boxes */
299 else if (*p
== 'y' && !strchr(vowels
, p
[-1]))
300 Strcpy(p
, "ies"); /* rubies, zruties */
306 Strcat(buf
, " named ");
307 Strcat(buf
, ONAME(obj
));
313 doname(struct obj
*obj
)
316 char *bp
= xname(obj
);
318 Sprintf(prefix
, "%u ", obj
->quan
);
320 Strcpy(prefix
, "a ");
323 if (strncmp(bp
, "cheap ", 6))
324 Strcpy(prefix
, "the ");
327 if (obj
->owornmask
& W_ARMOR
)
328 Strcat(bp
, " (being worn)");
329 /* fall into next case */
332 Strcat(prefix
, sitoa(obj
->spe
));
338 Sprintf(eos(bp
), " (%d)", obj
->spe
);
341 if (obj
->owornmask
& W_RINGR
)
342 Strcat(bp
, " (on right hand)");
343 if (obj
->owornmask
& W_RINGL
)
344 Strcat(bp
, " (on left hand)");
345 if (obj
->known
&& (objects
[obj
->otyp
].bits
& SPEC
)) {
346 Strcat(prefix
, sitoa(obj
->spe
));
351 if (obj
->owornmask
& W_WEP
)
352 Strcat(bp
, " (weapon in hand)");
354 Strcat(bp
, " (unpaid)");
355 if (!strcmp(prefix
, "a ") && strchr(vowels
, *bp
))
356 Strcpy(prefix
, "an ");
357 bp
= strprepend(bp
, prefix
);
361 /* used only in hack.fight.c (thitu) */
363 setan(const char *str
, char *buf
)
365 if (strchr(vowels
, *str
))
366 Sprintf(buf
, "an %s", str
);
368 Sprintf(buf
, "a %s", str
);
372 aobjnam(struct obj
*otmp
, const char *verb
)
374 char *bp
= xname(otmp
);
376 if (otmp
->quan
!= 1) {
377 Sprintf(prefix
, "%u ", otmp
->quan
);
378 bp
= strprepend(bp
, prefix
);
381 /* verb is given in plural (i.e., without trailing s) */
385 else if (!strcmp(verb
, "are"))
396 Doname(struct obj
*obj
)
398 char *s
= doname(obj
);
400 if ('a' <= *s
&& *s
<= 'z')
405 const char *const wrp
[] = {"wand", "ring", "potion", "scroll", "gem"};
406 const char wrpsym
[] = {WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
414 int cnt
, spe
, spesgn
, typ
, heavy
;
417 /* int the = 0; char *oname = 0; */
418 cnt
= spe
= spesgn
= typ
= heavy
= 0;
421 for (p
= bp
; *p
; p
++)
422 if ('A' <= *p
&& *p
<= 'Z')
424 if (!strncmp(bp
, "the ", 4)) {
427 } else if (!strncmp(bp
, "an ", 3)) {
430 } else if (!strncmp(bp
, "a ", 2)) {
434 if (!cnt
&& digit(*bp
)) {
442 cnt
= 1; /* %% what with "gems" etc. ? */
444 if (*bp
== '+' || *bp
== '-') {
445 spesgn
= (*bp
++ == '+') ? 1 : -1;
452 p
= strrchr(bp
, '(');
454 if (p
> bp
&& p
[-1] == ' ')
469 * now we have the actual name, as delivered by xname, say green
470 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
471 * fortune cookies very heavy iron ball named hoei wand of wishing
474 for (p
= bp
; *p
; p
++)
475 if (!strncmp(p
, " named ", 7)) {
479 for (p
= bp
; *p
; p
++)
480 if (!strncmp(p
, " called ", 8)) {
484 for (p
= bp
; *p
; p
++)
485 if (!strncmp(p
, " labeled ", 9)) {
489 /* first change to singular if necessary */
491 /* find "cloves of garlic", "worthless pieces of blue glass" */
492 for (p
= bp
; *p
; p
++)
493 if (!strncmp(p
, "s of ", 5)) {
494 while ((*p
= p
[1]) != '\0')
498 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
503 if (!strcmp(p
- 7, "cookies"))
508 /* note: cloves / knives from clove / knife */
509 if (!strcmp(p
- 6, "knives")) {
513 /* note: nurses, axes but boxes */
514 if (!strcmp(p
- 5, "boxes")) {
522 if (!strcmp(p
- 9, "homunculi")) {
523 Strcpy(p
- 1, "us"); /* !! makes string
527 if (!strcmp(p
- 5, "teeth")) {
528 Strcpy(p
- 5, "tooth");
531 /* here we cannot find the plural suffix */
535 if (!strcmp(bp
, "amulet of yendor")) {
536 typ
= AMULET_OF_YENDOR
;
540 if (!strcmp(p
- 5, " mail")) { /* Note: ring mail is not a ring ! */
545 for (ii
= 0; ii
< sizeof(wrpsym
); ii
++) {
546 int j
= strlen(wrp
[ii
]);
547 if (!strncmp(bp
, wrp
[ii
], j
)) {
550 if (!strncmp(bp
, " of ", 4))
552 /* else if(*bp) ?? */
555 if (!strcmp(p
- j
, wrp
[ii
])) {
565 if (!strcmp(p
- 6, " stone")) {
571 if (!strcmp(bp
, "very heavy iron ball")) {
573 typ
= HEAVY_IRON_BALL
;
578 if (!an
&& !dn
&& !un
)
582 i
= bases
[letindex(let
)];
583 while (i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)) {
584 const char *zn
= objects
[i
].oc_name
;
588 if (an
&& strcmp(an
, zn
))
590 if (dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
592 if (un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
601 let
= wrpsym
[rn2(sizeof(wrpsym
))];
606 let
= objects
[typ
].oc_olet
;
610 if (cnt
> 0 && strchr("%?!*)", let
) &&
611 (cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
614 if (spe
> 3 && spe
> otmp
->spe
)
616 else if (let
== WAND_SYM
)
618 if (spe
== 3 && u
.uluck
< 0)
620 if (let
!= WAND_SYM
&& spesgn
== -1)
624 else if (let
== AMULET_SYM
)
626 else if (typ
== WAN_WISHING
&& rn2(10))
627 spe
= (rn2(10) ? -1 : 0);