include the PM_ index in mons (permonst)

This is useful for debugging and it allows the index
to be used directly instead of calculated in a
monsndx() function, which has been removed.

I left monsndx() in as a simple short-hand macro for the value
and didn't change the use cases, the reasoning being that this:
    monsndx(mon->data)
is arguably a little easier on the eyes than:
    mon->data->pmidx

LOW_PM, NON_PM, SPECIAL_PM have been included in the 'enum monnums'
now, instead of as individual macro definitions.

I chose to add the pmidx field as an instance of the enum declaration,
because that has very advantageous results in some debuggers, where it is
then shown as:
    pmidx PM_GRAND_MASTER (349) monnums
instead of the less-informative:
    pmidx 349 int

Adding the element count to the extern declaration for mons from:
    'extern struct permonst *mons[];'
to the more specific declaration to that in src/monst.c:
    'extern struct permonst *mons[NUMMONS + 1];'
then allows navigation through the mons array in one of the debuggers.
This commit is contained in:
nhmall
2023-11-23 12:22:47 -05:00
parent 99141b3242
commit 2a48859de2
6 changed files with 37 additions and 41 deletions

View File

@@ -1110,6 +1110,9 @@ timet_delta(time_t etim, time_t stim) /* end and start times */
struct enum_dump monsdump[] = {
#include "monsters.h"
{ NUMMONS, "NUMMONS" },
{ NON_PM, "NON_PM" },
{ LOW_PM, "LOW_PM" },
{ SPECIAL_PM, "SPECIAL_PM" }
};
struct enum_dump objdump[] = {
#include "objects.h"
@@ -1162,7 +1165,9 @@ dump_enums(void)
for (i = 0; i < NUM_ENUM_DUMPS; ++ i) {
raw_printf("enum %s = {", titles[i]);
for (j = 0; j < szd[i]; ++j) {
nmprefix = (j == szd[i] - 1) ? "" : pfx[i]; /* "" or "PM_" */
int unprefixed_count = (i == monsters_enum) ? 4 : 1;
nmprefix = (j >= szd[i] - unprefixed_count)
? "" : pfx[i]; /* "" or "PM_" */
nmwidth = 27 - (int) strlen(nmprefix); /* 27 or 24 */
raw_printf(" %s%*s = %3d,",
nmprefix, -nmwidth, ed[i][j].nm, ed[i][j].val);

View File

@@ -771,26 +771,6 @@ same_race(struct permonst *pm1, struct permonst *pm2)
return FALSE;
}
DISABLE_WARNING_UNREACHABLE_CODE
/* return an index into the mons array */
int
monsndx(struct permonst *ptr)
{
register int i;
i = (int) (ptr - &mons[0]);
if (i < LOW_PM || i >= NUMMONS) {
panic("monsndx - could not index monster (%s)",
fmt_ptr((genericptr_t) ptr));
/*NOTREACHED*/
return NON_PM; /* will not get here */
}
return i;
}
RESTORE_WARNING_UNREACHABLE_CODE
/* for handling alternate spellings */
struct alt_spl {
const char *name;

View File

@@ -23,13 +23,15 @@
flg1, flg2, flg3, d, col, bn) \
{ \
{ (const char *) 0, (const char *) 0, nam }, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
PM_##bn, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
}
#define MON3(namm, namf, namn, sym, lvl, gen, atk, siz, mr1, mr2, \
flg1, flg2, flg3, d, col, bn) \
{ \
{ namm, namf, namn }, \
PM_##bn, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
}
/* LVL() and SIZ() collect several fields to cut down on number of args
@@ -52,11 +54,22 @@ struct permonst mons_init[NUMMONS + 1] = {
/*
* array terminator
*/
#undef MON
#define MON(nam, sym, lvl, gen, atk, siz, mr1, mr2, \
flg1, flg2, flg3, d, col, bn) \
{ \
{ (const char *) 0, (const char *) 0, nam }, \
NON_PM, \
sym, lvl, gen, atk, siz, mr1, mr2, flg1, flg2, flg3, d, C(col) \
}
MON("", 0, LVL(0, 0, 0, 0, 0), (0),
A(NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK, NO_ATTK),
SIZ(0, 0, 0, 0), 0, 0, 0L, 0L, 0, 0, 0, 0)
SIZ(0, 0, 0, 0), 0, 0, 0L, 0L, 0, 0, 0, 0),
};
#undef MON
#undef MON3
void monst_globals_init(void); /* in hack.h but we're using config.h */
struct permonst mons[SIZE(mons_init)];
@@ -76,8 +89,6 @@ const struct attack c_sa_no[NATTK] = SEDUCTION_ATTACKS_NO;
#undef C
#define C(c) (0x1f & (c)) /* global.h */
#undef NO_ATTK
#undef MON
#undef MON3
#undef LVL
#undef SIZ
#undef ATTK