Permalink
Browse files

Route mname through mons_mname() during play

This allows shuffled dragon appearances to work (specifically, the
dragon names), while make mons[] immutable again.

In general, any code that needs or gets monster names via the mname
member of struct permonst should instead use mons_mname() to account for
randomized dragon appearances.
  • Loading branch information...
1 parent dde7532 commit 74ab88b6b07b6234f20054f4b95870d89e2891b9 @tung committed Apr 10, 2012
@@ -1002,6 +1002,7 @@ extern int num_horns(const struct permonst *);
extern boolean dmgtype(const struct permonst *,int);
extern int max_passive_dmg(struct monst *,struct monst *);
extern int monsndx(const struct permonst *);
+extern int vis_monsndx(const struct permonst *);
extern int name_to_mon(const char *);
extern int gender(struct monst *);
extern int pronoun_gender(struct monst *);
@@ -1012,6 +1013,7 @@ extern const char *locomotion(const struct permonst *,const char *);
extern const char *stagger(const struct permonst *,const char *);
extern const char *on_fire(const struct permonst *, const struct attack *);
extern const struct permonst *raceptr(struct monst *);
+extern const char *mons_mname(const struct permonst *);
/* ### monmove.c ### */
@@ -1091,8 +1093,6 @@ extern void restnames(struct memfile *mf);
extern void discover_object(int,boolean,boolean);
extern void undiscover_object(int);
extern int dodiscovered(void);
-extern void dragons_init(void);
-extern int rndndx_dragon(int);
/* ### objnam.c ### */
@@ -145,8 +145,8 @@
#define emits_light(ptr) (((ptr)->mlet == S_LIGHT || \
(ptr) == &mons[PM_FLAMING_SPHERE] || \
(ptr) == &mons[PM_SHOCKING_SPHERE] || \
- !strcmp((ptr)->mname, "gold dragon") || \
- !strcmp((ptr)->mname, "baby gold dragon") || \
+ !strcmp(mons_mname(ptr), "gold dragon") || \
+ !strcmp(mons_mname(ptr), "baby gold dragon") || \
(ptr) == &mons[PM_FIRE_VORTEX]) ? 1 : \
((ptr) == &mons[PM_FIRE_ELEMENTAL]) ? 1 : 0)
/* [note: the light ranges above were reduced to 1 for performance...] */
@@ -69,7 +69,7 @@ struct permonst {
uchar mcolor; /* color to use */
};
-extern struct permonst mons[]; /* the master list of monster types */
+extern const struct permonst mons[]; /* the master list of monster types */
#define VERY_SLOW 3
#define SLOW_SPEED 9
@@ -216,10 +216,6 @@ static void realtime_tasks(void)
static void post_init_tasks(void)
{
- /* must be done after dragon armor in objects[] has been
- * shuffled (new game) or loaded (restored game). */
- dragons_init();
-
realtime_tasks();
encumber_msg(); /* in case they auto-picked up something */
View
@@ -166,7 +166,7 @@ static boolean its_dead(int rx, int ry, int *resp, struct obj *tobj)
} else {
ttmp = t_at(level, rx, ry);
pline("%s appears to be in %s health for a statue.",
- The(mons[otmp->corpsenm].mname),
+ The(mons_mname(&mons[otmp->corpsenm])),
(ttmp && ttmp->ttyp == STATUE_TRAP) ?
"extraordinary" : "excellent");
}
@@ -1321,12 +1321,12 @@ static void use_tinning_kit(struct obj *obj)
if (poly_when_stoned(youmonst.data))
pline("You tin %s without wearing gloves.",
- an(mons[corpse->corpsenm].mname));
+ an(mons_mname(&mons[corpse->corpsenm])));
else {
pline("Tinning %s without wearing gloves is a fatal mistake...",
- an(mons[corpse->corpsenm].mname));
+ an(mons_mname(&mons[corpse->corpsenm])));
sprintf(kbuf, "trying to tin %s without gloves",
- an(mons[corpse->corpsenm].mname));
+ an(mons_mname(&mons[corpse->corpsenm])));
}
instapetrify(kbuf);
}
@@ -2182,7 +2182,7 @@ static int use_whip(struct obj *obj)
char kbuf[BUFSZ];
sprintf(kbuf, "%s corpse",
- an(mons[otmp->corpsenm].mname));
+ an(mons_mname(&mons[otmp->corpsenm])));
pline("Snatching %s is a fatal mistake.", kbuf);
instapetrify(kbuf);
}
View
@@ -264,7 +264,7 @@ void savebones(struct obj *corpse)
mtmp = christen_monst(mtmp, plname);
newsym(u.ux, u.uy);
pline("Your body rises from the dead as %s...",
- an(mons[u.ugrave_arise].mname));
+ an(mons_mname(&mons[u.ugrave_arise])));
win_pause_output(P_MESSAGE);
drop_upon_death(mtmp, NULL);
m_dowear(mtmp, TRUE);
View
@@ -158,7 +158,7 @@ static void make_player_info(struct nh_player_info *pi)
char mbot[BUFSZ];
int k = 0;
- strcpy(mbot, mons[u.umonnum].mname);
+ strcpy(mbot, mons_mname(&mons[u.umonnum]));
while (mbot[k] != 0) {
if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) &&
'a' <= mbot[k] && mbot[k] <= 'z')
View
@@ -770,12 +770,12 @@ void enlightenment(int final)
if (Polymorph) you_are(&menu, "polymorphing");
if (Polymorph_control) you_have(&menu, "polymorph control");
if (u.ulycn >= LOW_PM) {
- strcpy(buf, an(mons[u.ulycn].mname));
+ strcpy(buf, an(mons_mname(&mons[u.ulycn])));
you_are(&menu, buf);
}
if (Upolyd) {
if (u.umonnum == u.ulycn) strcpy(buf, "in beast form");
- else sprintf(buf, "polymorphed into %s", an(youmonst.data->mname));
+ else sprintf(buf, "polymorphed into %s", an(mons_mname(youmonst.data)));
if (wizard) sprintf(eos(buf), " (%d)", u.mtimedone);
you_are(&menu, buf);
}
@@ -924,7 +924,7 @@ static boolean minimal_enlightenment(void)
/* Current name, race, role, gender */
set_menuitem(&items[i++], 0, MI_NORMAL, "", 0, FALSE);
set_menuitem(&items[i++], 0, MI_HEADING, "Current", 0, FALSE);
- sprintf(buf, fmtstr, "race", Upolyd ? youmonst.data->mname : urace.noun);
+ sprintf(buf, fmtstr, "race", Upolyd ? mons_mname(youmonst.data) : urace.noun);
set_menuitem(&items[i++], 0, MI_NORMAL, buf, 0, FALSE);
if (Upolyd)
sprintf(buf, fmtstr, "role (base)",
@@ -401,8 +401,8 @@ static void display_monster(
if (worm_tail) {
monnum = PM_LONG_WORM_TAIL;
} else {
- /* Fix color of random dragons by faking their index. */
- monnum = rndndx_dragon(monsndx(mon->data));
+ /* vis_monsndx accounts for e.g. shuffled dragon appearances */
+ monnum = vis_monsndx(mon->data);
}
if (sightflags == DETECTED)
@@ -922,8 +922,8 @@ void swallowed(int first)
dbuf_set(lastx, lasty, 0,0,0,0,0,0,0,0); /* remove hero symbol */
}
- /* Fix color of random dragons by faking their index. */
- swallower = rndndx_dragon(monsndx(u.ustuck->data));
+ /* vis_monsndx accounts for e.g. shuffled dragon appearances */
+ swallower = vis_monsndx(u.ustuck->data);
/* assume isok(u.ux,u.uy) */
left_ok = isok(u.ux-1,u.uy);
rght_ok = isok(u.ux+1,u.uy);
@@ -453,7 +453,7 @@ char *x_monnam(const struct monst *mtmp,
strcat(buf, " the ");
if (do_invis)
strcat(buf, "invisible ");
- strcat(buf, mdat->mname);
+ strcat(buf, mons_mname(mdat));
return buf;
}
@@ -484,7 +484,7 @@ char *x_monnam(const struct monst *mtmp,
sprintf(eos(buf), "%s ghost", s_suffix(name));
name_at_start = TRUE;
} else if (called) {
- sprintf(eos(buf), "%s called %s", mdat->mname, name);
+ sprintf(eos(buf), "%s called %s", mons_mname(mdat), name);
name_at_start = (boolean)type_is_pname(mdat);
} else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) {
/* <name> the <adjective> <invisible> <saddled> <rank> */
@@ -513,7 +513,7 @@ char *x_monnam(const struct monst *mtmp,
strcat(buf, "Rider");
name_at_start = FALSE;
} else {
- strcat(buf, mdat->mname);
+ strcat(buf, mons_mname(mdat));
name_at_start = (boolean)type_is_pname(mdat);
}
@@ -786,7 +786,7 @@ const char *rndmonnam(void)
(type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
if (name >= SPECIAL_PM) return bogusmons[name - SPECIAL_PM];
- return mons[name].mname;
+ return mons_mname(&mons[name]);
}
@@ -154,7 +154,7 @@ static void kick_monster(xchar x, xchar y, schar dx, schar dy)
char kbuf[BUFSZ];
int dis_dmg;
sprintf(kbuf, "barefootedly kicking %s",
- an(mon->data->mname));
+ an(mons_mname(mon->data)));
dis_dmg = instadisintegrate(kbuf);
break;
}
@@ -80,8 +80,8 @@ static int throw_obj(struct obj *obj, int shotlimit)
if (!uarmg && !Stone_resistance && (obj->otyp == CORPSE &&
touch_petrifies(&mons[obj->corpsenm]))) {
pline("You throw the %s corpse with your bare %s.",
- mons[obj->corpsenm].mname, body_part(HAND));
- sprintf(killer_buf, "%s corpse", an(mons[obj->corpsenm].mname));
+ mons_mname(&mons[obj->corpsenm]), body_part(HAND));
+ sprintf(killer_buf, "%s corpse", an(mons_mname(&mons[obj->corpsenm])));
instapetrify(killer_buf);
}
if (welded(obj)) {
View
@@ -178,7 +178,7 @@ static const char *food_xname(struct obj *food, boolean the_pfx)
char *bufp = xname(food);
sprintf(bufp, "%s%s corpse",
(the_pfx && !type_is_pname(&mons[mnum])) ? "the " : "",
- s_suffix(mons[mnum].mname));
+ s_suffix(mons_mname(&mons[mnum])));
result = bufp;
} else {
/* the ordinary case */
@@ -394,7 +394,7 @@ static void cprefx(int pm)
if (touch_petrifies(&mons[pm]) || pm == PM_MEDUSA) {
if (!Stone_resistance &&
!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
- sprintf(killer_buf, "tasting %s meat", mons[pm].mname);
+ sprintf(killer_buf, "tasting %s meat", mons_mname(&mons[pm]));
killer_format = KILLED_BY;
killer = killer_buf;
pline("You turn to stone.");
@@ -413,7 +413,7 @@ static void cprefx(int pm)
case PM_HOUSECAT:
case PM_LARGE_CAT:
if (!CANNIBAL_ALLOWED()) {
- pline("You feel that eating the %s was a bad idea.", mons[pm].mname);
+ pline("You feel that eating the %s was a bad idea.", mons_mname(&mons[pm]));
HAggravate_monster |= FROMOUTSIDE;
}
break;
@@ -426,7 +426,7 @@ static void cprefx(int pm)
{ char buf[BUFSZ];
pline("Eating that is instantly fatal.");
sprintf(buf, "unwisely ate the body of %s",
- mons[pm].mname);
+ mons_mname(&mons[pm]));
killer = buf;
killer_format = NO_KILLER_PREFIX;
done(DIED);
@@ -707,7 +707,7 @@ static void cpostfx(int pm) /* called after completely consuming a corpse */
sprintf(buf, Hallucination ?
"You suddenly dread being peeled and mimic %s again!" :
"You now prefer mimicking %s again.",
- an(Upolyd ? youmonst.data->mname : urace.noun));
+ an(Upolyd ? mons_mname(youmonst.data) : urace.noun));
eatmbuf = strcpy(malloc(strlen(buf) + 1), buf);
nomovemsg = eatmbuf;
afternmv = eatmdone;
@@ -885,7 +885,7 @@ static int opentin(void) /* called during each move whilst opening a tin */
if (Hallucination) {
what = rndmonnam();
} else {
- what = mons[tin.tin->corpsenm].mname;
+ what = mons_mname(&mons[tin.tin->corpsenm]);
if (mons[tin.tin->corpsenm].geno & G_UNIQ)
which = type_is_pname(&mons[tin.tin->corpsenm]) ? 1 : 2;
}
@@ -902,7 +902,7 @@ static int opentin(void) /* called during each move whilst opening a tin */
victual.fullwarn = victual.eating = victual.doreset = FALSE;
pline("You consume %s %s.", tintxts[r].txt,
- mons[tin.tin->corpsenm].mname);
+ mons_mname(&mons[tin.tin->corpsenm]));
/* KMH, conduct */
u.uconduct.food++;
@@ -1099,7 +1099,7 @@ static int eatcorpse(struct obj *otmp)
else
sprintf(buf, "%s%s rotted corpse",
!type_is_pname(&mons[mnum]) ? "the " : "",
- s_suffix(mons[mnum].mname));
+ s_suffix(mons_mname(&mons[mnum])));
make_sick(sick_time, buf, TRUE, SICK_VOMITABLE);
}
if (carried(otmp)) useup(otmp);
@@ -1511,7 +1511,7 @@ static void fpostfx(struct obj *otmp)
!(poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))) {
if (!Stoned) Stoned = 5;
killer_format = KILLED_BY_AN;
- sprintf(killer_buf, "%s egg", mons[otmp->corpsenm].mname);
+ sprintf(killer_buf, "%s egg", mons_mname(&mons[otmp->corpsenm]));
delayed_killer = killer_buf;
}
}
View
@@ -117,7 +117,7 @@ void done_in_by(struct monst *mtmp)
killer = m_monnam(mtmp);
strcat(buf, killer);
} else {
- strcat(buf, mtmp->data->mname);
+ strcat(buf, mons_mname(mtmp->data));
if (mtmp->mnamelth)
sprintf(eos(buf), " called %s", NAME(mtmp));
}
@@ -913,7 +913,7 @@ static void list_vanquished(char defquery, boolean ask)
if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) {
sprintf(buf, "%s%s",
!type_is_pname(&mons[i]) ? "The " : "",
- mons[i].mname);
+ mons_mname(&mons[i]));
if (nkilled > 1) {
switch (nkilled) {
case 2: sprintf(eos(buf)," (twice)"); break;
@@ -927,10 +927,10 @@ static void list_vanquished(char defquery, boolean ask)
/* trolls or undead might have come back,
but we don't keep track of that */
if (nkilled == 1)
- strcpy(buf, an(mons[i].mname));
+ strcpy(buf, an(mons_mname(&mons[i])));
else
sprintf(buf, "%d %s",
- nkilled, makeplural(mons[i].mname));
+ nkilled, makeplural(mons_mname(&mons[i])));
}
add_menutext(&menu, buf);
}
@@ -990,9 +990,9 @@ static void list_genocided(char defquery, boolean ask)
if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST)
sprintf(buf, "%s%s",
!type_is_pname(&mons[i]) ? "" : "the ",
- mons[i].mname);
+ mons_mname(&mons[i]));
else
- strcpy(buf, makeplural(mons[i].mname));
+ strcpy(buf, makeplural(mons_mname(&mons[i])));
if( !(mvitals[i].mvflags & G_GENOD) )
strcat(buf, " (extinct)");
@@ -1765,11 +1765,11 @@ void feel_cockatrice(struct obj *otmp, boolean force_touch)
if (will_feel_cockatrice(otmp, force_touch)) {
if (poly_when_stoned(youmonst.data))
pline("You touched the %s corpse with your bare %s.",
- mons[otmp->corpsenm].mname, makeplural(body_part(HAND)));
+ mons_mname(&mons[otmp->corpsenm]), makeplural(body_part(HAND)));
else
pline("Touching the %s corpse is a fatal mistake...",
- mons[otmp->corpsenm].mname);
- sprintf(kbuf, "%s corpse", an(mons[otmp->corpsenm].mname));
+ mons_mname(&mons[otmp->corpsenm]));
+ sprintf(kbuf, "%s corpse", an(mons_mname(&mons[otmp->corpsenm])));
instapetrify(kbuf);
}
}
@@ -1360,7 +1360,7 @@ const struct permonst *grow_up(struct monst *mtmp, /* `mtmp' might "grow up" int
if (mvitals[newtype].mvflags & G_GENOD) { /* allow G_EXTINCT */
if (sensemon(mtmp))
pline("As %s grows up into %s, %s %s!", mon_nam(mtmp),
- an(ptr->mname), mhe(mtmp),
+ an(mons_mname(ptr)), mhe(mtmp),
nonliving(ptr) ? "expires" : "dies");
set_mon_data(mtmp, ptr, -1); /* keep mvitals[] accurate */
mondied(mtmp);
Oops, something went wrong.

0 comments on commit 74ab88b

Please sign in to comment.