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