minimal_xname (trunk only)

simple_typename and obj_typename operate on item types rather than
particular objects so have to assume that the item involved has been seen.
That means that simple_typename(obj->otyp) is not suitable; if obj->dknown
hasn't been set, it gives away information.  This adds mininal_xname(obj)
to be used for that purpose.  I'm not aware of any straightforward way to
actually expose the original problem; it's more than hypothetical but not
something anyone's likely to have come across.

     Not fixed:  test driver program reveals that obj_typename(GOLD_PIECE)
and simple_typename(GOLD_PIECE) yield "coin of gold piece".  But I don't
think there's any way to get nethack to show that to the user.
This commit is contained in:
nethack.rankin
2006-11-26 05:15:52 +00:00
parent 95729beb4a
commit 59354953cc
4 changed files with 54 additions and 13 deletions
+1 -1
View File
@@ -697,7 +697,7 @@ struct obj *obj;
boolean vis; boolean vis;
if(!getdir((char *)0)) return 0; if(!getdir((char *)0)) return 0;
mirror = simple_typename(obj->otyp); /* "mirror" or "looking glass" */ mirror = simpleonames(obj); /* "mirror" or "looking glass" */
if(obj->cursed && !rn2(2)) { if(obj->cursed && !rn2(2)) {
if (!Blind) if (!Blind)
pline_The("%s fogs up and doesn't reflect!", mirror); pline_The("%s fogs up and doesn't reflect!", mirror);
+3 -4
View File
@@ -517,7 +517,7 @@ int alter_type;
xchar ox, oy; xchar ox, oy;
char objroom; char objroom;
boolean set_bknown; boolean set_bknown;
const char *those, *them, *what; const char *those, *them;
struct monst *shkp = 0; struct monst *shkp = 0;
if (alter_type < 0 || alter_type >= SIZE(alteration_verbs)) { if (alter_type < 0 || alter_type >= SIZE(alteration_verbs)) {
@@ -559,10 +559,9 @@ int alter_type;
case OBJ_FREE: /* obj_no_longer_held() */ case OBJ_FREE: /* obj_no_longer_held() */
case OBJ_INVENT: case OBJ_INVENT:
if (set_bknown) obj->bknown = 1; if (set_bknown) obj->bknown = 1;
what = simple_typename(obj->otyp);
if (obj->quan != 1L) what = makeplural(what);
verbalize("You %s %s %s, you pay for %s!", verbalize("You %s %s %s, you pay for %s!",
alteration_verbs[alter_type], those, what, them); alteration_verbs[alter_type], those,
simpleonames(obj), them);
bill_dummy_object(obj); bill_dummy_object(obj);
break; break;
case OBJ_FLOOR: case OBJ_FLOOR:
+49 -7
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)objnam.c 3.5 2006/10/16 */ /* SCCS Id: @(#)objnam.c 3.5 2006/11/25 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -13,6 +13,7 @@ STATIC_DCL char *FDECL(strprepend,(char *,const char *));
STATIC_DCL boolean FDECL(wishymatch, (const char *,const char *,BOOLEAN_P)); STATIC_DCL boolean FDECL(wishymatch, (const char *,const char *,BOOLEAN_P));
STATIC_DCL char *NDECL(nextobuf); STATIC_DCL char *NDECL(nextobuf);
STATIC_DCL void FDECL(releaseobuf, (char *)); STATIC_DCL void FDECL(releaseobuf, (char *));
STATIC_DCL char *FDECL(minimal_xname, (struct obj *));
STATIC_DCL void FDECL(add_erosion_words, (struct obj *, char *)); STATIC_DCL void FDECL(add_erosion_words, (struct obj *, char *));
struct Jitem { struct Jitem {
@@ -490,6 +491,47 @@ nameit:
return(buf); return(buf);
} }
/* similar to simple_typename but minimal_xname operates on a particular
object rather than its general type; it formats the most basic info:
potion -- if description not known
brown potion -- if oc_name_known not set
potion of object detection -- if discovered
*/
static char *
minimal_xname(obj)
struct obj *obj;
{
char *bufp;
struct obj bareobj;
struct objclass saveobcls;
int otyp = obj->otyp;
/* suppress user-supplied name */
saveobcls.oc_uname = objects[otyp].oc_uname;
objects[otyp].oc_uname = 0;
/* suppress actual name if object's description is unknown */
saveobcls.oc_name_known = objects[otyp].oc_name_known;
if (!obj->dknown) objects[otyp].oc_name_known = 0;
/* caveat: this makes a lot of assumptions about which fields
are required in order for xname() to yield a sensible result */
bareobj = zeroobj;
bareobj.otyp = otyp;
bareobj.oclass = obj->oclass;
bareobj.dknown = obj->dknown;
/* suppress known except for amulets (needed for fakes and real A-of-Y) */
bareobj.known = (obj->oclass == AMULET_CLASS) ? obj->known :
/* default is "on" for types which don't use it */
!objects[otyp].oc_uses_known;
bareobj.quan = 1L; /* don't want plural */
bufp = distant_name(&bareobj, xname); /* xname(&bareobj) */
if (!strncmp(bufp, "uncursed ", 9)) bufp += 9; /* Role_if(PM_PRIEST) */
objects[otyp].oc_uname = saveobcls.oc_uname;
objects[otyp].oc_name_known = saveobcls.oc_name_known;
return bufp;
}
/* xname() output augmented for multishot missile feedback */ /* xname() output augmented for multishot missile feedback */
char * char *
mshot_xname(obj) mshot_xname(obj)
@@ -1099,7 +1141,7 @@ unsigned lenlimit;
outbuf = (*func)(obj); outbuf = (*func)(obj);
if (altfunc && (unsigned)strlen(outbuf) > lenlimit) { if (altfunc && (unsigned)strlen(outbuf) > lenlimit) {
/* still long; use the alternate function (usually one of /* still long; use the alternate function (usually one of
the jackets around simple_typename()) */ the jackets around minimal_xname()) */
releaseobuf(outbuf); releaseobuf(outbuf);
outbuf = (*altfunc)(obj); outbuf = (*altfunc)(obj);
} }
@@ -1469,9 +1511,9 @@ struct obj *obj;
return s; return s;
} }
/* returns "your simple_typename(obj->otyp)" /* returns "your minimal_xname(obj)"
* or "Foobar's simple_typename(obj->otyp)" * or "Foobar's minimal_xname(obj)"
* or "the simple_typename(obj-otyp)" * or "the minimal_xname(obj)"
*/ */
char * char *
ysimple_name(obj) ysimple_name(obj)
@@ -1481,7 +1523,7 @@ struct obj *obj;
char *s = shk_your(outbuf, obj); /* assert( s == outbuf ); */ char *s = shk_your(outbuf, obj); /* assert( s == outbuf ); */
int space_left = BUFSZ - 1 - strlen(s); int space_left = BUFSZ - 1 - strlen(s);
return strncat(s, simple_typename(obj->otyp), space_left); return strncat(s, minimal_xname(obj), space_left);
} }
/* capitalized variant of ysimple_name() */ /* capitalized variant of ysimple_name() */
@@ -1500,7 +1542,7 @@ char *
simpleonames(obj) simpleonames(obj)
struct obj *obj; struct obj *obj;
{ {
char *simpleoname = simple_typename(obj->otyp); char *simpleoname = minimal_xname(obj);
if (obj->quan != 1L) simpleoname = makeplural(simpleoname); if (obj->quan != 1L) simpleoname = makeplural(simpleoname);
return simpleoname; return simpleoname;
+1 -1
View File
@@ -498,7 +498,7 @@ outer_break:
buf, distant_name(best,doname)); buf, distant_name(best,doname));
if (autocurse) if (autocurse)
pline("%s %s %s %s for a moment.", pline("%s %s %s %s for a moment.",
s_suffix(Monnam(mon)), simple_typename(best->otyp), s_suffix(Monnam(mon)), simpleonames(best),
otense(best, "glow"), hcolor(NH_BLACK)); otense(best, "glow"), hcolor(NH_BLACK));
} /* can see it */ } /* can see it */
m_delay += objects[best->otyp].oc_delay; m_delay += objects[best->otyp].oc_delay;