/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.objnam.c - version 1.0.2 */
#define Sprintf (void) sprintf
#define Strcat (void) strcat
#define Strcpy (void) strcpy
strprepend(s
,pref
) register char *s
, *pref
; {
register int i
= strlen(pref
);
pline("WARNING: prefix too short.");
(void) strncpy(s
, pref
, i
); /* do not copy trailing 0 */
Sprintf(buf
, (a
< 0) ? "%d" : "+%d", a
);
register struct objclass
*ocl
= &objects
[otyp
];
register char *an
= ocl
->oc_name
;
register char *dn
= ocl
->oc_descr
;
register char *un
= ocl
->oc_uname
;
register int nn
= ocl
->oc_name_known
;
if(otyp
>= TURQUOISE
&& otyp
<= JADE
)
Sprintf(eos(buf
), " called %s", un
);
Sprintf(eos(buf
), " (%s)", dn
);
Strcpy(buf
, dn
? dn
: an
);
if(ocl
->oc_olet
== GEM_SYM
)
Sprintf(eos(buf
), " called %s", un
);
/* here for ring/scroll/potion/wand */
Sprintf(eos(buf
), " of %s", an
);
Sprintf(eos(buf
), " called %s", un
);
Sprintf(eos(buf
), " (%s)", dn
);
register struct obj
*obj
;
register char *buf
= &(bufr
[PREFIX
]); /* leave room for "17 -3 " */
register int nn
= objects
[obj
->otyp
].oc_name_known
;
register char *an
= objects
[obj
->otyp
].oc_name
;
register char *dn
= objects
[obj
->otyp
].oc_descr
;
register char *un
= objects
[obj
->otyp
].oc_uname
;
register int pl
= (obj
->quan
!= 1);
if(!obj
->dknown
&& !Blind
) obj
->dknown
= 1; /* %% doesnt belong here */
Strcpy(buf
, (obj
->spe
< 0 && obj
->known
)
? "cheap plastic imitation of the " : "");
Strcat(buf
,"Amulet of Yendor");
if(obj
->otyp
== DEAD_HOMUNCULUS
&& pl
) {
Strcpy(buf
, "dead homunculi");
/* fall into next case */
if(obj
->otyp
== WORM_TOOTH
&& pl
) {
Strcpy(buf
, "worm teeth");
if(obj
->otyp
== CRYSKNIFE
&& pl
) {
Strcpy(buf
, "crysknives");
/* fall into next case */
Sprintf(buf
, "%sheavy iron ball",
(obj
->owt
> objects
[obj
->otyp
].oc_weight
) ? "very " : "");
if(nn
|| un
|| !obj
->dknown
) {
Strcat(buf
, " labeled ");
Sprintf(buf
, "wand of %s", an
);
Sprintf(buf
, "wand called %s", un
);
Sprintf(buf
, "%s wand", dn
);
Sprintf(buf
, "ring of %s", an
);
Sprintf(buf
, "ring called %s", un
);
Sprintf(buf
, "%s ring", dn
);
Sprintf(buf
, "%s gem", dn
);
if(obj
->otyp
>= TURQUOISE
&& obj
->otyp
<= JADE
)
Sprintf(buf
,"glorkum %c (0%o) %u %d",
obj
->olet
,obj
->olet
,obj
->otyp
,obj
->spe
);
if(!strncmp(" of ", p
, 4)) {
/* pieces of, cloves of, lumps of */
register int c1
, c2
= 's';
c1
= c2
; c2
= *p
; *p
++ = c1
;
if(*p
== 's' || *p
== 'z' || *p
== 'x' ||
(*p
== 'h' && p
[-1] == 's'))
Strcat(buf
, "es"); /* boxes */
else if(*p
== 'y' && !index(vowels
, p
[-1]))
Strcpy(p
, "ies"); /* rubies, zruties */
register struct obj
*obj
;
register char *bp
= xname(obj
);
Sprintf(prefix
, "%u ", obj
->quan
);
if(strncmp(bp
, "cheap ", 6))
if(obj
->owornmask
& W_ARMOR
)
Strcat(bp
, " (being worn)");
/* fall into next case */
Strcat(prefix
, sitoa(obj
->spe
));
Sprintf(eos(bp
), " (%d)", obj
->spe
);
if(obj
->owornmask
& W_RINGR
) Strcat(bp
, " (on right hand)");
if(obj
->owornmask
& W_RINGL
) Strcat(bp
, " (on left hand)");
if(obj
->known
&& (objects
[obj
->otyp
].bits
& SPEC
)) {
Strcat(prefix
, sitoa(obj
->spe
));
if(obj
->owornmask
& W_WEP
)
Strcat(bp
, " (weapon in hand)");
if(!strcmp(prefix
, "a ") && index(vowels
, *bp
))
bp
= strprepend(bp
, prefix
);
/* used only in hack.fight.c (thitu) */
Sprintf(buf
, "an %s", str
);
Sprintf(buf
, "a %s", str
);
aobjnam(otmp
,verb
) register struct obj
*otmp
; register char *verb
; {
register char *bp
= xname(otmp
);
Sprintf(prefix
, "%u ", otmp
->quan
);
bp
= strprepend(bp
, prefix
);
/* verb is given in plural (i.e., without trailing s) */
else if(!strcmp(verb
, "are"))
register struct obj
*obj
;
register char *s
= doname(obj
);
if('a' <= *s
&& *s
<= 'z') *s
-= ('a' - 'A');
char *wrp
[] = { "wand", "ring", "potion", "scroll", "gem" };
char wrpsym
[] = { WAND_SYM
, RING_SYM
, POTION_SYM
, SCROLL_SYM
, GEM_SYM
};
readobjnam(bp
) register char *bp
; {
int cnt
, spe
, spesgn
, typ
, heavy
;
/* int the = 0; char *oname = 0; */
cnt
= spe
= spesgn
= typ
= heavy
= 0;
if('A' <= *p
&& *p
<= 'Z') *p
+= 'a'-'A';
if(!strncmp(bp
, "the ", 4)){
} else if(!strncmp(bp
, "an ", 3)){
} else if(!strncmp(bp
, "a ", 2)){
if(!cnt
) cnt
= 1; /* %% what with "gems" etc. ? */
if(*bp
== '+' || *bp
== '-'){
spesgn
= (*bp
++ == '+') ? 1 : -1;
if(p
> bp
&& p
[-1] == ' ') p
[-1] = 0;
if(strcmp(p
, ")")) spe
= 0;
/* now we have the actual name, as delivered by xname, say
green potions called whisky
very heavy iron ball named hoei
for(p
= bp
; *p
; p
++) if(!strncmp(p
, " named ", 7)) {
for(p
= bp
; *p
; p
++) if(!strncmp(p
, " called ", 8)) {
for(p
= bp
; *p
; p
++) if(!strncmp(p
, " labeled ", 9)) {
/* first change to singular if necessary */
/* find "cloves of garlic", "worthless pieces of blue glass" */
for(p
= bp
; *p
; p
++) if(!strncmp(p
, "s of ", 5)){
/* remove -s or -es (boxes) or -ies (rubies, zruties) */
if(!strcmp(p
-7, "cookies"))
/* note: cloves / knives from clove / knife */
if(!strcmp(p
-6, "knives")) {
/* note: nurses, axes but boxes */
if(!strcmp(p
-5, "boxes")) {
if(!strcmp(p
-9, "homunculi")) {
Strcpy(p
-1, "us"); /* !! makes string longer */
if(!strcmp(p
-5, "teeth")) {
/* here we cannot find the plural suffix */
if(!strcmp(bp
, "amulet of yendor")) {
if(!strcmp(p
-5, " mail")){ /* Note: ring mail is not a ring ! */
for(i
= 0; i
< sizeof(wrpsym
); i
++) {
register int j
= strlen(wrp
[i
]);
if(!strncmp(bp
, wrp
[i
], j
)){
if(!strncmp(bp
, " of ", 4)) an
= bp
+4;
if(!strcmp(p
-j
, wrp
[i
])){
if(p
[-1] == ' ') p
[-1] = 0;
if(!strcmp(p
-6, " stone")){
if(!strcmp(bp
, "very heavy iron ball")){
if(let
) i
= bases
[letindex(let
)];
while(i
<= NROFOBJECTS
&& (!let
|| objects
[i
].oc_olet
== let
)){
register char *zn
= objects
[i
].oc_name
;
if(dn
&& (!(zn
= objects
[i
].oc_descr
) || strcmp(dn
, zn
)))
if(un
&& (!(zn
= objects
[i
].oc_uname
) || strcmp(un
, zn
)))
if(!let
) let
= wrpsym
[rn2(sizeof(wrpsym
))];
{ register struct obj
*otmp
;
extern struct obj
*mksobj();
let
= objects
[typ
].oc_olet
;
if(cnt
> 0 && index("%?!*)", let
) &&
(cnt
< 4 || (let
== WEAPON_SYM
&& typ
<= ROCK
&& cnt
< 20)))
if(spe
> 3 && spe
> otmp
->spe
)
if(spe
== 3 && u
.uluck
< 0)
if(let
!= WAND_SYM
&& spesgn
== -1)
else if(let
== AMULET_SYM
)
else if(typ
== WAN_WISHING
&& rn2(10))
spe
= (rn2(10) ? -1 : 0);