making the code more readable.
Instead of doing strcmp(OBJ_DESCR(objects[otyp]), "foo"),
just call objdescr_is(obj, "foo")
(via xNetHack)
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 *));
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,
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...");
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)
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;
}
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]))
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]))
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()
dodrink()
{
register struct obj *otmp;
- const char *potion_descr;
if (Strangled) {
pline("If you can't breathe air, how can you drink liquid?");
}
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);
}
/* 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);
}
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)