diff --git a/include/extern.h b/include/extern.h index 49af9d19e..3d7211358 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1695,7 +1695,6 @@ extern struct attack *dmgtype_fromattack(struct permonst *, int, int); extern boolean dmgtype(struct permonst *, int); extern int max_passive_dmg(struct monst *, struct monst *); extern boolean same_race(struct permonst *, struct permonst *); -extern int monsndx(struct permonst *); extern int name_to_mon(const char *, int *); extern int name_to_monplus(const char *, const char **, int *); extern int name_to_monclass(const char *, int *); diff --git a/include/mondata.h b/include/mondata.h index 04c9995c4..13bfff15e 100644 --- a/include/mondata.h +++ b/include/mondata.h @@ -5,6 +5,7 @@ #ifndef MONDATA_H #define MONDATA_H +#define monsndx(ptr) ((ptr)->pmidx) #define verysmall(ptr) ((ptr)->msize < MZ_SMALL) #define bigmonst(ptr) ((ptr)->msize >= MZ_LARGE) diff --git a/include/permonst.h b/include/permonst.h index 9a6ff88e3..2eea5d675 100644 --- a/include/permonst.h +++ b/include/permonst.h @@ -18,6 +18,18 @@ * for a blinding attack, they determine the amount of time blinded. */ +enum monnums { +#define MONS_ENUM +#include "monsters.h" +#undef MONS_ENUM + NUMMONS, + NON_PM = -1, /* "not a monster */ + LOW_PM = NON_PM + 1, /* first monster in mons */ + SPECIAL_PM = PM_LONG_WORM_TAIL /* [normal] < ~ < [special] */ + /* mons[SPECIAL_PM] through mons[NUMMONS-1], inclusive, are + never generated randomly and cannot be polymorphed into */ +}; + struct attack { uchar aatyp; uchar adtyp, damn, damd; @@ -42,6 +54,7 @@ struct attack { struct permonst { const char *pmnames[NUM_MGENDERS]; + const enum monnums pmidx; /* mons array index aka PM_ identifier */ char mlet; /* symbol */ schar mlevel, /* base monster level */ mmove, /* move speed */ @@ -60,17 +73,10 @@ struct permonst { mflags2; /* more boolean bitflags */ unsigned short mflags3; /* yet more boolean bitflags */ uchar difficulty; /* toughness (formerly from makedefs -m) */ - uchar mcolor; /* color to use */ + uchar mcolor; /* color to use */ }; -extern NEARDATA struct permonst mons[]; /* the master list of monster types */ - -enum monnums { -#define MONS_ENUM -#include "monsters.h" -#undef MONS_ENUM - NUMMONS -}; +extern NEARDATA struct permonst mons[NUMMONS + 1]; /* the master list of monster types */ #define VERY_SLOW 3 #define SLOW_SPEED 9 @@ -78,12 +84,6 @@ enum monnums { #define FAST_SPEED 15 #define VERY_FAST 24 -#define NON_PM (-1) /* "not a monster" */ -#define LOW_PM (NON_PM + 1) /* first monster in mons[] */ -#define SPECIAL_PM PM_LONG_WORM_TAIL /* [normal] < ~ < [special] */ -/* mons[SPECIAL_PM] through mons[NUMMONS-1], inclusive, are - never generated randomly and cannot be polymorphed into */ - #ifdef PMNAME_MACROS #define pmname(pm,g) ((((g) == MALE || (g) == FEMALE) && (pm)->pmnames[g]) \ ? (pm)->pmnames[g] : (pm)->pmnames[NEUTRAL]) diff --git a/src/allmain.c b/src/allmain.c index 3dc6297d8..c20175e3c 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -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); diff --git a/src/mondata.c b/src/mondata.c index d66b54cca..04e4b1c8d 100644 --- a/src/mondata.c +++ b/src/mondata.c @@ -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; diff --git a/src/monst.c b/src/monst.c index e08d254d0..2b85c22c3 100644 --- a/src/monst.c +++ b/src/monst.c @@ -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