]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.objnam.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.objnam.c,v 1.3 1995/03/23 08:31:10 cgd Exp $";
10 #define Sprintf (void) sprintf
11 #define Strcat (void) strcat
12 #define Strcpy (void) strcpy
18 strprepend(s
,pref
) register char *s
, *pref
; {
19 register int i
= strlen(pref
);
21 pline("WARNING: prefix too short.");
25 (void) strncpy(s
, pref
, i
); /* do not copy trailing 0 */
32 Sprintf(buf
, (a
< 0) ? "%d" : "+%d", a
);
40 static char buf
[BUFSZ
];
41 register struct objclass
*ocl
= &objects
[otyp
];
42 register char *an
= ocl
->oc_name
;
43 register char *dn
= ocl
->oc_descr
;
44 register char *un
= ocl
->oc_uname
;
45 register int nn
= ocl
->oc_name_known
;
46 switch(ocl
->oc_olet
) {
48 Strcpy(buf
, "potion");
51 Strcpy(buf
, "scroll");
62 if(otyp
>= TURQUOISE
&& otyp
<= JADE
)
63 Strcat(buf
, " stone");
65 Sprintf(eos(buf
), " called %s", un
);
67 Sprintf(eos(buf
), " (%s)", dn
);
69 Strcpy(buf
, dn
? dn
: an
);
70 if(ocl
->oc_olet
== GEM_SYM
)
73 Sprintf(eos(buf
), " called %s", un
);
77 /* here for ring/scroll/potion/wand */
79 Sprintf(eos(buf
), " of %s", an
);
81 Sprintf(eos(buf
), " called %s", un
);
83 Sprintf(eos(buf
), " (%s)", dn
);
89 register struct obj
*obj
;
91 static char bufr
[BUFSZ
];
92 register char *buf
= &(bufr
[PREFIX
]); /* leave room for "17 -3 " */
93 register int nn
= objects
[obj
->otyp
].oc_name_known
;
94 register char *an
= objects
[obj
->otyp
].oc_name
;
95 register char *dn
= objects
[obj
->otyp
].oc_descr
;
96 register char *un
= objects
[obj
->otyp
].oc_uname
;
97 register int pl
= (obj
->quan
!= 1);
98 if(!obj
->dknown
&& !Blind
) obj
->dknown
= 1; /* %% doesnt belong here */
101 Strcpy(buf
, (obj
->spe
< 0 && obj
->known
)
102 ? "cheap plastic imitation of the " : "");
103 Strcat(buf
,"Amulet of Yendor");
113 if(obj
->otyp
== DEAD_HOMUNCULUS
&& pl
) {
115 Strcpy(buf
, "dead homunculi");
119 /* fall into next case */
121 if(obj
->otyp
== WORM_TOOTH
&& pl
) {
123 Strcpy(buf
, "worm teeth");
126 if(obj
->otyp
== CRYSKNIFE
&& pl
) {
128 Strcpy(buf
, "crysknives");
131 /* fall into next case */
138 Sprintf(buf
, "%sheavy iron ball",
139 (obj
->owt
> objects
[obj
->otyp
].oc_weight
) ? "very " : "");
142 if(nn
|| un
|| !obj
->dknown
) {
143 Strcpy(buf
, "potion");
148 if(!obj
->dknown
) break;
150 Strcat(buf
, " called ");
158 Strcat(buf
, " potion");
162 Strcpy(buf
, "scroll");
167 if(!obj
->dknown
) break;
172 Strcat(buf
, " called ");
175 Strcat(buf
, " labeled ");
181 Sprintf(buf
, "wand");
183 Sprintf(buf
, "wand of %s", an
);
185 Sprintf(buf
, "wand called %s", un
);
187 Sprintf(buf
, "%s wand", dn
);
191 Sprintf(buf
, "ring");
193 Sprintf(buf
, "ring of %s", an
);
195 Sprintf(buf
, "ring called %s", un
);
197 Sprintf(buf
, "%s ring", dn
);
205 Sprintf(buf
, "%s gem", dn
);
209 if(obj
->otyp
>= TURQUOISE
&& obj
->otyp
<= JADE
)
210 Strcat(buf
, " stone");
213 Sprintf(buf
,"glorkum %c (0%o) %u %d",
214 obj
->olet
,obj
->olet
,obj
->otyp
,obj
->spe
);
219 for(p
= buf
; *p
; p
++) {
220 if(!strncmp(" of ", p
, 4)) {
221 /* pieces of, cloves of, lumps of */
222 register int c1
, c2
= 's';
225 c1
= c2
; c2
= *p
; *p
++ = c1
;
231 if(*p
== 's' || *p
== 'z' || *p
== 'x' ||
232 (*p
== 'h' && p
[-1] == 's'))
233 Strcat(buf
, "es"); /* boxes */
234 else if(*p
== 'y' && !index(vowels
, p
[-1]))
235 Strcpy(p
, "ies"); /* rubies, zruties */
241 Strcat(buf
, " named ");
242 Strcat(buf
, ONAME(obj
));
249 register struct obj
*obj
;
252 register char *bp
= xname(obj
);
254 Sprintf(prefix
, "%u ", obj
->quan
);
256 Strcpy(prefix
, "a ");
259 if(strncmp(bp
, "cheap ", 6))
260 Strcpy(prefix
, "the ");
263 if(obj
->owornmask
& W_ARMOR
)
264 Strcat(bp
, " (being worn)");
265 /* fall into next case */
268 Strcat(prefix
, sitoa(obj
->spe
));
274 Sprintf(eos(bp
), " (%d)", obj
->spe
);
277 if(obj
->owornmask
& W_RINGR
) Strcat(bp
, " (on right hand)");
278 if(obj
->owornmask
& W_RINGL
) Strcat(bp
, " (on left hand)");
279 if(obj
->known
&& (objects
[obj
->otyp
].bits
& SPEC
)) {
280 Strcat(prefix
, sitoa(obj
->spe
));
285 if(obj
->owornmask
& W_WEP
)
286 Strcat(bp
, " (weapon in hand)");
288 Strcat(bp
, " (unpaid)");
289 if(!strcmp(prefix
, "a ") && index(vowels
, *bp
))
290 Strcpy(prefix
, "an ");
291 bp
= strprepend(bp
, prefix
);
295 /* used only in hack.fight.c (thitu) */
297 register char *str
,*buf
;
299 if(index(vowels
,*str
))
300 Sprintf(buf
, "an %s", str
);
302 Sprintf(buf
, "a %s", str
);
306 aobjnam(otmp
,verb
) register struct obj
*otmp
; register char *verb
; {
307 register char *bp
= xname(otmp
);
309 if(otmp
->quan
!= 1) {
310 Sprintf(prefix
, "%u ", otmp
->quan
);
311 bp
= strprepend(bp
, prefix
);
315 /* verb is given in plural (i.e., without trailing s) */
319 else if(!strcmp(verb
, "are"))
331 register struct obj
*obj
;
333 register char *s
= doname(obj
);
335 if('a' <= *s
&& *s
<= 'z') *s
-= ('a' - 'A');
339 char *wrp
[] = { "wand", "ring", "potion", "scroll", "gem" };
340 char wrpsym
[] = { WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
343 readobjnam(bp
) register char *bp
; {
346 int cnt
, spe
, spesgn
, typ
, heavy
;
349 /* int the = 0; char *oname = 0; */
350 cnt
= spe
= spesgn
= typ
= heavy
= 0;
354 if('A' <= *p
&& *p
<= 'Z') *p
+= 'a'-'A';
355 if(!strncmp(bp
, "the ", 4)){
358 } else if(!strncmp(bp
, "an ", 3)){
361 } else if(!strncmp(bp
, "a ", 2)){
365 if(!cnt
&& digit(*bp
)){
367 while(digit(*bp
)) bp
++;
368 while(*bp
== ' ') bp
++;
370 if(!cnt
) cnt
= 1; /* %% what with "gems" etc. ? */
372 if(*bp
== '+' || *bp
== '-'){
373 spesgn
= (*bp
++ == '+') ? 1 : -1;
375 while(digit(*bp
)) bp
++;
376 while(*bp
== ' ') bp
++;
380 if(p
> bp
&& p
[-1] == ' ') p
[-1] = 0;
384 while(digit(*p
)) p
++;
385 if(strcmp(p
, ")")) spe
= 0;
389 /* now we have the actual name, as delivered by xname, say
390 green potions called whisky
391 scrolls labeled "QWERTY"
395 very heavy iron ball named hoei
399 for(p
= bp
; *p
; p
++) if(!strncmp(p
, " named ", 7)) {
403 for(p
= bp
; *p
; p
++) if(!strncmp(p
, " called ", 8)) {
407 for(p
= bp
; *p
; p
++) if(!strncmp(p
, " labeled ", 9)) {
412 /* first change to singular if necessary */
414 /* find "cloves of garlic", "worthless pieces of blue glass" */
415 for(p
= bp
; *p
; p
++) if(!strncmp(p
, "s of ", 5)){
416 while(*p
= p
[1]) p
++;
419 /* remove -s or -es (boxes) or -ies (rubies, zruties) */
424 if(!strcmp(p
-7, "cookies"))
430 /* note: cloves / knives from clove / knife */
431 if(!strcmp(p
-6, "knives")) {
436 /* note: nurses, axes but boxes */
437 if(!strcmp(p
-5, "boxes")) {
445 if(!strcmp(p
-9, "homunculi")) {
446 Strcpy(p
-1, "us"); /* !! makes string longer */
449 if(!strcmp(p
-5, "teeth")) {
450 Strcpy(p
-5, "tooth");
453 /* here we cannot find the plural suffix */
457 if(!strcmp(bp
, "amulet of yendor")) {
458 typ
= AMULET_OF_YENDOR
;
462 if(!strcmp(p
-5, " mail")){ /* Note: ring mail is not a ring ! */
467 for(i
= 0; i
< sizeof(wrpsym
); i
++) {
468 register int j
= strlen(wrp
[i
]);
469 if(!strncmp(bp
, wrp
[i
], j
)){
472 if(!strncmp(bp
, " of ", 4)) an
= bp
+4;
473 /* else if(*bp) ?? */
476 if(!strcmp(p
-j
, wrp
[i
])){
480 if(p
[-1] == ' ') p
[-1] = 0;
485 if(!strcmp(p
-6, " stone")){
491 if(!strcmp(bp
, "very heavy iron ball")){
493 typ
= HEAVY_IRON_BALL
;
498 if(!an
&& !dn
&& !un
)
501 if(let
) i
= bases
[letindex(let
)];
502 while(i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)){
503 register char *zn
= objects
[i
].oc_name
;
506 if(an
&& strcmp(an
, zn
))
508 if(dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
510 if(un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
518 if(!let
) let
= wrpsym
[rn2(sizeof(wrpsym
))];
521 { register struct obj
*otmp
;
522 extern struct obj
*mksobj();
523 let
= objects
[typ
].oc_olet
;
527 if(cnt
> 0 && index("%?!*)", let
) &&
528 (cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
531 if(spe
> 3 && spe
> otmp
->spe
)
533 else if(let
== WAND_SYM
)
535 if(spe
== 3 && u
.uluck
< 0)
537 if(let
!= WAND_SYM
&& spesgn
== -1)
541 else if(let
== AMULET_SYM
)
543 else if(typ
== WAN_WISHING
&& rn2(10))
544 spe
= (rn2(10) ? -1 : 0);