Match object description via single function
making the code more readable. Instead of doing strcmp(OBJ_DESCR(objects[otyp]), "foo"), just call objdescr_is(obj, "foo") (via xNetHack)
This commit is contained in:
@@ -1776,6 +1776,7 @@ E void NDECL(nttty_exit);
|
||||
E void NDECL(init_objects);
|
||||
E void FDECL(obj_shuffle_range, (int, int *, int *));
|
||||
E int NDECL(find_skates);
|
||||
E boolean FDECL(objdescr_is, (struct obj *, const char *));
|
||||
E void NDECL(oinit);
|
||||
E void FDECL(savenames, (NHFILE *));
|
||||
E void FDECL(restnames, (NHFILE *));
|
||||
|
||||
@@ -3406,7 +3406,7 @@ struct obj *obj;
|
||||
boolean fillmsg = FALSE;
|
||||
int expltype = EXPL_MAGICAL;
|
||||
char confirm[QBUFSZ], buf[BUFSZ];
|
||||
boolean is_fragile = (!strcmp(OBJ_DESCR(objects[obj->otyp]), "balsa"));
|
||||
boolean is_fragile = objdescr_is(obj, "balsa");
|
||||
|
||||
if (!paranoid_query(ParanoidBreakwand,
|
||||
safe_qbuf(confirm,
|
||||
|
||||
@@ -2134,7 +2134,7 @@ eatspecial()
|
||||
pline("Yuck%c", otmp->blessed ? '!' : '.');
|
||||
else if (otmp->oclass == SCROLL_CLASS
|
||||
/* check description after checking for specific scrolls */
|
||||
&& !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
|
||||
&& objdescr_is(otmp, "YUM YUM"))
|
||||
pline("Yum%c", otmp->blessed ? '!' : '.');
|
||||
else
|
||||
pline("Needs salt...");
|
||||
|
||||
@@ -1114,7 +1114,7 @@ struct monst *mtmp;
|
||||
distant_name(otmp, doname));
|
||||
/* give this one even if !verbose */
|
||||
if (otmp->oclass == SCROLL_CLASS
|
||||
&& !strcmpi(OBJ_DESCR(objects[otmp->otyp]), "YUM YUM"))
|
||||
&& objdescr_is(otmp, "YUM YUM"))
|
||||
pline("Yum%c", otmp->blessed ? '!' : '.');
|
||||
} else {
|
||||
if (flags.verbose)
|
||||
|
||||
@@ -271,8 +271,7 @@ struct obj *obj; /* aatyp == AT_WEAP, AT_SPIT */
|
||||
o = (mdef == &g.youmonst) ? g.invent : mdef->minvent;
|
||||
for (; o; o = o->nobj)
|
||||
if ((o->owornmask & W_ARMH)
|
||||
&& (s = OBJ_DESCR(objects[o->otyp])) != (char *) 0
|
||||
&& !strcmp(s, "visored helmet"))
|
||||
&& objdescr_is(o, "visored helmet"))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,11 +57,9 @@ struct obj *obj;
|
||||
if (obj->oclass == POTION_CLASS) {
|
||||
coord cc;
|
||||
static const char *empty = "The potion turns out to be empty.";
|
||||
const char *potion_descr;
|
||||
struct monst *mtmp;
|
||||
|
||||
potion_descr = OBJ_DESCR(objects[obj->otyp]);
|
||||
if (potion_descr && !strcmp(potion_descr, "milky")) {
|
||||
if (objdescr_is(obj, "milky")) {
|
||||
if (!(g.mvitals[PM_GHOST].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_GHOST].born))) {
|
||||
if (!enexto(&cc, mon->mx, mon->my, &mons[PM_GHOST]))
|
||||
@@ -87,7 +85,7 @@ struct obj *obj;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (potion_descr && !strcmp(potion_descr, "smoky")
|
||||
if (objdescr_is(obj, "smoky")
|
||||
&& !(g.mvitals[PM_DJINNI].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_DJINNI].born))) {
|
||||
if (!enexto(&cc, mon->mx, mon->my, &mons[PM_DJINNI]))
|
||||
|
||||
20
src/o_init.c
20
src/o_init.c
@@ -282,6 +282,26 @@ shuffle_all()
|
||||
return;
|
||||
}
|
||||
|
||||
/* Return TRUE if the provided string matches the unidentified description of
|
||||
* the provided object. */
|
||||
boolean
|
||||
objdescr_is(obj, descr)
|
||||
struct obj *obj;
|
||||
const char *descr;
|
||||
{
|
||||
const char *objdescr;
|
||||
|
||||
if (!obj) {
|
||||
impossible("objdescr_is: null obj");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
objdescr = OBJ_DESCR(objects[obj->otyp]);
|
||||
if (!objdescr)
|
||||
return FALSE; /* no obj description, no match */
|
||||
return !strcmp(objdescr, descr);
|
||||
}
|
||||
|
||||
/* find the object index for snow boots; used [once] by slippery ice code */
|
||||
int
|
||||
find_skates()
|
||||
|
||||
28
src/potion.c
28
src/potion.c
@@ -486,7 +486,6 @@ int
|
||||
dodrink()
|
||||
{
|
||||
register struct obj *otmp;
|
||||
const char *potion_descr;
|
||||
|
||||
if (Strangled) {
|
||||
pline("If you can't breathe air, how can you drink liquid?");
|
||||
@@ -538,21 +537,18 @@ dodrink()
|
||||
}
|
||||
otmp->in_use = TRUE; /* you've opened the stopper */
|
||||
|
||||
potion_descr = OBJ_DESCR(objects[otmp->otyp]);
|
||||
if (potion_descr) {
|
||||
if (!strcmp(potion_descr, "milky")
|
||||
&& !(g.mvitals[PM_GHOST].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_GHOST].born))) {
|
||||
ghost_from_bottle();
|
||||
useup(otmp);
|
||||
return 1;
|
||||
} else if (!strcmp(potion_descr, "smoky")
|
||||
&& !(g.mvitals[PM_DJINNI].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_DJINNI].born))) {
|
||||
djinni_from_bottle(otmp);
|
||||
useup(otmp);
|
||||
return 1;
|
||||
}
|
||||
if (objdescr_is(otmp, "milky")
|
||||
&& !(g.mvitals[PM_GHOST].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_GHOST].born))) {
|
||||
ghost_from_bottle();
|
||||
useup(otmp);
|
||||
return 1;
|
||||
} else if (objdescr_is(otmp, "smoky")
|
||||
&& !(g.mvitals[PM_DJINNI].mvflags & G_GONE)
|
||||
&& !rn2(POTION_OCCUPANT_CHANCE(g.mvitals[PM_DJINNI].born))) {
|
||||
djinni_from_bottle(otmp);
|
||||
useup(otmp);
|
||||
return 1;
|
||||
}
|
||||
return dopotion(otmp);
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ register struct obj *spellbook;
|
||||
|
||||
/* attempting to read dull book may make hero fall asleep */
|
||||
if (!confused && !Sleep_resistance
|
||||
&& !strcmp(OBJ_DESCR(objects[booktype]), "dull")) {
|
||||
&& objdescr_is(spellbook, "dull")) {
|
||||
const char *eyes;
|
||||
int dullbook = rnd(25) - ACURR(A_WIS);
|
||||
|
||||
|
||||
@@ -114,12 +114,10 @@ struct obj *otmp;
|
||||
}
|
||||
if (Confusion || Fumbling || Glib)
|
||||
chance -= 20;
|
||||
else if (uarmg && (s = OBJ_DESCR(objects[uarmg->otyp])) != (char *) 0
|
||||
&& !strncmp(s, "riding ", 7))
|
||||
else if (uarmg && objdescr_is(uarmg, "riding gloves"))
|
||||
/* Bonus for wearing "riding" (but not fumbling) gloves */
|
||||
chance += 10;
|
||||
else if (uarmf && (s = OBJ_DESCR(objects[uarmf->otyp])) != (char *) 0
|
||||
&& !strncmp(s, "riding ", 7))
|
||||
else if (uarmf && objdescr_is(uarmf, "riding boots"))
|
||||
/* ... or for "riding boots" */
|
||||
chance += 10;
|
||||
if (otmp->cursed)
|
||||
|
||||
Reference in New Issue
Block a user