Files
nethack/src/monst.c
nhmall 2a48859de2 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.
2023-11-23 12:22:47 -05:00

98 lines
3.1 KiB
C

/* NetHack 3.7 monst.c $NHDT-Date: 1682205027 2023/04/22 23:10:27 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.97 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2006. */
/* NetHack may be freely redistributed. See license for details. */
#include "config.h"
#include "permonst.h"
#include "wintype.h"
#include "sym.h"
#ifdef C
#undef C
#endif
#include "color.h"
#define C(color) color
#define NO_ATTK \
{ \
0, 0, 0, 0 \
}
#define MON(nam, sym, lvl, gen, atk, siz, mr1, mr2, \
flg1, flg2, flg3, d, col, bn) \
{ \
{ (const char *) 0, (const char *) 0, nam }, \
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
* for MON()
*/
#define LVL(lvl, mov, ac, mr, aln) lvl, mov, ac, mr, aln
#define SIZ(wt, nut, snd, siz) wt, nut, snd, siz
/* ATTK() and A() are to avoid braces and commas within args to MON() */
#define ATTK(at, ad, n, d) \
{ \
at, ad, n, d \
}
#define A(a1, a2, a3, a4, a5, a6) \
{ \
a1, a2, a3, a4, a5, a6 \
}
struct permonst mons_init[NUMMONS + 1] = {
#include "monsters.h"
/*
* 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),
};
#undef MON
#undef MON3
void monst_globals_init(void); /* in hack.h but we're using config.h */
struct permonst mons[SIZE(mons_init)];
void
monst_globals_init(void)
{
memcpy(mons, mons_init, sizeof mons);
return;
}
const struct attack c_sa_yes[NATTK] = SEDUCTION_ATTACKS_YES;
const struct attack c_sa_no[NATTK] = SEDUCTION_ATTACKS_NO;
/* for 'onefile' processing where end of this file isn't necessarily the
end of the source code seen by the compiler */
#undef C
#define C(c) (0x1f & (c)) /* global.h */
#undef NO_ATTK
#undef LVL
#undef SIZ
#undef ATTK
#undef A
/*monst.c*/