]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.objnam.c
1 /* $NetBSD: hack.objnam.c,v 1.6 2003/04/02 18:36:39 jsm 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.6 2003/04/02 18:36:39 jsm Exp $");
72 #define Sprintf (void) sprintf
73 #define Strcat (void) strcat
74 #define Strcpy (void) strcpy
83 pline("WARNING: prefix too short.");
87 (void) strncpy(s
, pref
, i
); /* do not copy trailing 0 */
96 Sprintf(buf
, (a
< 0) ? "%d" : "+%d", a
);
104 static char buf
[BUFSZ
];
105 struct objclass
*ocl
= &objects
[otyp
];
106 const char *an
= ocl
->oc_name
;
107 const char *dn
= ocl
->oc_descr
;
108 char *un
= ocl
->oc_uname
;
109 int nn
= ocl
->oc_name_known
;
110 switch (ocl
->oc_olet
) {
112 Strcpy(buf
, "potion");
115 Strcpy(buf
, "scroll");
126 if (otyp
>= TURQUOISE
&& otyp
<= JADE
)
127 Strcat(buf
, " stone");
129 Sprintf(eos(buf
), " called %s", un
);
131 Sprintf(eos(buf
), " (%s)", dn
);
133 Strcpy(buf
, dn
? dn
: an
);
134 if (ocl
->oc_olet
== GEM_SYM
)
137 Sprintf(eos(buf
), " called %s", un
);
141 /* here for ring/scroll/potion/wand */
143 Sprintf(eos(buf
), " of %s", an
);
145 Sprintf(eos(buf
), " called %s", un
);
147 Sprintf(eos(buf
), " (%s)", dn
);
155 static char bufr
[BUFSZ
];
156 char *buf
= &(bufr
[PREFIX
]); /* leave room for "17 -3 " */
157 int nn
= objects
[obj
->otyp
].oc_name_known
;
158 const char *an
= objects
[obj
->otyp
].oc_name
;
159 const char *dn
= objects
[obj
->otyp
].oc_descr
;
160 char *un
= objects
[obj
->otyp
].oc_uname
;
161 int pl
= (obj
->quan
!= 1);
162 if (!obj
->dknown
&& !Blind
)
163 obj
->dknown
= 1;/* %% doesnt belong here */
166 Strcpy(buf
, (obj
->spe
< 0 && obj
->known
)
167 ? "cheap plastic imitation of the " : "");
168 Strcat(buf
, "Amulet of Yendor");
178 if (obj
->otyp
== DEAD_HOMUNCULUS
&& pl
) {
180 Strcpy(buf
, "dead homunculi");
184 /* fall into next case */
186 if (obj
->otyp
== WORM_TOOTH
&& pl
) {
188 Strcpy(buf
, "worm teeth");
191 if (obj
->otyp
== CRYSKNIFE
&& pl
) {
193 Strcpy(buf
, "crysknives");
196 /* fall into next case */
203 Sprintf(buf
, "%sheavy iron ball",
204 (obj
->owt
> objects
[obj
->otyp
].oc_weight
) ? "very " : "");
207 if (nn
|| un
|| !obj
->dknown
) {
208 Strcpy(buf
, "potion");
216 Strcat(buf
, " called ");
224 Strcat(buf
, " potion");
228 Strcpy(buf
, "scroll");
239 Strcat(buf
, " called ");
242 Strcat(buf
, " labeled ");
248 Sprintf(buf
, "wand");
250 Sprintf(buf
, "wand of %s", an
);
252 Sprintf(buf
, "wand called %s", un
);
254 Sprintf(buf
, "%s wand", dn
);
258 Sprintf(buf
, "ring");
260 Sprintf(buf
, "ring of %s", an
);
262 Sprintf(buf
, "ring called %s", un
);
264 Sprintf(buf
, "%s ring", dn
);
272 Sprintf(buf
, "%s gem", dn
);
276 if (obj
->otyp
>= TURQUOISE
&& obj
->otyp
<= JADE
)
277 Strcat(buf
, " stone");
280 Sprintf(buf
, "glorkum %c (0%o) %u %d",
281 obj
->olet
, obj
->olet
, obj
->otyp
, obj
->spe
);
286 for (p
= buf
; *p
; p
++) {
287 if (!strncmp(" of ", p
, 4)) {
288 /* pieces of, cloves of, lumps of */
300 if (*p
== 's' || *p
== 'z' || *p
== 'x' ||
301 (*p
== 'h' && p
[-1] == 's'))
302 Strcat(buf
, "es"); /* boxes */
303 else if (*p
== 'y' && !strchr(vowels
, p
[-1]))
304 Strcpy(p
, "ies"); /* rubies, zruties */
310 Strcat(buf
, " named ");
311 Strcat(buf
, ONAME(obj
));
321 char *bp
= xname(obj
);
323 Sprintf(prefix
, "%u ", obj
->quan
);
325 Strcpy(prefix
, "a ");
328 if (strncmp(bp
, "cheap ", 6))
329 Strcpy(prefix
, "the ");
332 if (obj
->owornmask
& W_ARMOR
)
333 Strcat(bp
, " (being worn)");
334 /* fall into next case */
337 Strcat(prefix
, sitoa(obj
->spe
));
343 Sprintf(eos(bp
), " (%d)", obj
->spe
);
346 if (obj
->owornmask
& W_RINGR
)
347 Strcat(bp
, " (on right hand)");
348 if (obj
->owornmask
& W_RINGL
)
349 Strcat(bp
, " (on left hand)");
350 if (obj
->known
&& (objects
[obj
->otyp
].bits
& SPEC
)) {
351 Strcat(prefix
, sitoa(obj
->spe
));
356 if (obj
->owornmask
& W_WEP
)
357 Strcat(bp
, " (weapon in hand)");
359 Strcat(bp
, " (unpaid)");
360 if (!strcmp(prefix
, "a ") && strchr(vowels
, *bp
))
361 Strcpy(prefix
, "an ");
362 bp
= strprepend(bp
, prefix
);
366 /* used only in hack.fight.c (thitu) */
368 setan(const char *str
, char *buf
)
370 if (strchr(vowels
, *str
))
371 Sprintf(buf
, "an %s", str
);
373 Sprintf(buf
, "a %s", str
);
381 char *bp
= xname(otmp
);
383 if (otmp
->quan
!= 1) {
384 Sprintf(prefix
, "%u ", otmp
->quan
);
385 bp
= strprepend(bp
, prefix
);
388 /* verb is given in plural (i.e., without trailing s) */
392 else if (!strcmp(verb
, "are"))
406 char *s
= doname(obj
);
408 if ('a' <= *s
&& *s
<= 'z')
413 const char *const wrp
[] = {"wand", "ring", "potion", "scroll", "gem"};
414 const char wrpsym
[] = {WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
422 int cnt
, spe
, spesgn
, typ
, heavy
;
425 /* int the = 0; char *oname = 0; */
426 cnt
= spe
= spesgn
= typ
= heavy
= 0;
429 for (p
= bp
; *p
; p
++)
430 if ('A' <= *p
&& *p
<= 'Z')
432 if (!strncmp(bp
, "the ", 4)) {
435 } else if (!strncmp(bp
, "an ", 3)) {
438 } else if (!strncmp(bp
, "a ", 2)) {
442 if (!cnt
&& digit(*bp
)) {
450 cnt
= 1; /* %% what with "gems" etc. ? */
452 if (*bp
== '+' || *bp
== '-') {
453 spesgn
= (*bp
++ == '+') ? 1 : -1;
460 p
= strrchr(bp
, '(');
462 if (p
> bp
&& p
[-1] == ' ')
477 * now we have the actual name, as delivered by xname, say green
478 * potions called whisky scrolls labeled "QWERTY" egg dead zruties
479 * fortune cookies very heavy iron ball named hoei wand of wishing
482 for (p
= bp
; *p
; p
++)
483 if (!strncmp(p
, " named ", 7)) {
487 for (p
= bp
; *p
; p
++)
488 if (!strncmp(p
, " called ", 8)) {
492 for (p
= bp
; *p
; p
++)
493 if (!strncmp(p
, " labeled ", 9)) {
497 /* first change to singular if necessary */
499 /* find "cloves of garlic", "worthless pieces of blue glass" */
500 for (p
= bp
; *p
; p
++)
501 if (!strncmp(p
, "s of ", 5)) {
502 while ((*p
= p
[1]) != '\0')
506 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
511 if (!strcmp(p
- 7, "cookies"))
516 /* note: cloves / knives from clove / knife */
517 if (!strcmp(p
- 6, "knives")) {
521 /* note: nurses, axes but boxes */
522 if (!strcmp(p
- 5, "boxes")) {
530 if (!strcmp(p
- 9, "homunculi")) {
531 Strcpy(p
- 1, "us"); /* !! makes string
535 if (!strcmp(p
- 5, "teeth")) {
536 Strcpy(p
- 5, "tooth");
539 /* here we cannot find the plural suffix */
543 if (!strcmp(bp
, "amulet of yendor")) {
544 typ
= AMULET_OF_YENDOR
;
548 if (!strcmp(p
- 5, " mail")) { /* Note: ring mail is not a ring ! */
553 for (i
= 0; i
< sizeof(wrpsym
); i
++) {
554 int j
= strlen(wrp
[i
]);
555 if (!strncmp(bp
, wrp
[i
], j
)) {
558 if (!strncmp(bp
, " of ", 4))
560 /* else if(*bp) ?? */
563 if (!strcmp(p
- j
, wrp
[i
])) {
573 if (!strcmp(p
- 6, " stone")) {
579 if (!strcmp(bp
, "very heavy iron ball")) {
581 typ
= HEAVY_IRON_BALL
;
586 if (!an
&& !dn
&& !un
)
590 i
= bases
[letindex(let
)];
591 while (i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)) {
592 const char *zn
= objects
[i
].oc_name
;
596 if (an
&& strcmp(an
, zn
))
598 if (dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
600 if (un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
609 let
= wrpsym
[rn2(sizeof(wrpsym
))];
614 let
= objects
[typ
].oc_olet
;
618 if (cnt
> 0 && strchr("%?!*)", let
) &&
619 (cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
622 if (spe
> 3 && spe
> otmp
->spe
)
624 else if (let
== WAND_SYM
)
626 if (spe
== 3 && u
.uluck
< 0)
628 if (let
!= WAND_SYM
&& spesgn
== -1)
632 else if (let
== AMULET_SYM
)
634 else if (typ
== WAN_WISHING
&& rn2(10))
635 spe
= (rn2(10) ? -1 : 0);