mon_pmname(), obj_pmname()

Revive some code from 5 or so years ago that's been sitting in a
defunct local git branch.  There are a couple of references to
figurines having gender; the old, unfinished code did already have
support for that, the current code doesn't.  It probably won't take
much effort to add it in but I want to get this first part out of
the way.

Replace some of the
pmname(mon->data, Mgender[mon]) calls with simpler
mon_pmname(mon) and some
pmname(&mons[statue->corpsenm],
   (statue->spe & CORPSTAT_GENDER) == ... ? ... : ...) with simpler
obj_pmname(obj).  There are other instances of them which haven't
been changed but could be.
This commit is contained in:
PatR
2021-06-12 03:07:30 -07:00
parent 234eceae60
commit 57e970b227
5 changed files with 83 additions and 58 deletions

View File

@@ -1672,12 +1672,12 @@ rndghostname(void)
* options works, since those are special cases.
*/
char *
x_monnam(register struct monst *mtmp, int article,
x_monnam(struct monst *mtmp, int article,
const char *adjective, int suppress, boolean called)
{
char *buf = nextmbuf();
struct permonst *mdat = mtmp->data;
const char *pm_name = pmname(mdat, Mgender(mtmp));
const char *pm_name = mon_pmname(mtmp);
boolean do_hallu, do_invis, do_it, do_saddle, do_name;
boolean name_at_start, has_adjectives;
char *bp;
@@ -2054,7 +2054,7 @@ minimal_monnam(struct monst *mon, boolean ckloc)
} else {
Sprintf(outbuf, "%s%s <%d,%d>",
mon->mtame ? "tame " : mon->mpeaceful ? "peaceful " : "",
pmname(mon->data, Mgender(mon)), mon->mx, mon->my);
mon_pmname(mon), mon->mx, mon->my);
if (mon->cham != NON_PM)
Sprintf(eos(outbuf), "{%s}",
pmname(&mons[mon->cham], Mgender(mon)));
@@ -2080,13 +2080,39 @@ Mgender(struct monst *mtmp)
const char *
pmname(struct permonst *pm, int mgender)
{
if ((mgender >= MALE && mgender < NUM_MGENDERS) && pm->pmnames[mgender])
return pm->pmnames[mgender];
else
return pm->pmnames[NEUTRAL];
if (mgender < MALE || mgender >= NUM_MGENDERS || !pm->pmnames[mgender])
mgender = NEUTRAL;
return pm->pmnames[mgender];
}
#endif /* PMNAME_MACROS */
/* mons[]->pmname for a monster */
const char *
mon_pmname(struct monst *mon)
{
/* for neuter, mon->data->pmnames[MALE] will be Null and use [NEUTRAL] */
return pmname(mon->data, mon->female ? FEMALE : MALE);
}
/* mons[]->pmname for a corpse or statue or figurine */
const char *
obj_pmname(struct obj *obj)
{
if (has_omonst(obj))
return mon_pmname(OMONST(obj));
if ((obj->otyp == CORPSE || obj->otyp == STATUE || obj->otyp == FIGURINE)
&& obj->corpsenm >= LOW_PM) {
int cgend = (obj->spe & CORPSTAT_GENDER),
mgend = ((cgend == CORPSTAT_MALE) ? MALE
: (cgend == CORPSTAT_FEMALE) ? FEMALE
: NEUTRAL);
return pmname(&mons[obj->corpsenm], mgend);
}
return "";
}
/* fake monsters used to be in a hard-coded array, now in a data file */
char *
bogusmon(char *buf, char *code)