relocate mstrength() and supporting function again

Also, purge the code for makedefs -m
This commit is contained in:
nhmall
2022-11-05 18:40:57 -04:00
parent 242c05ccf3
commit 185322421a
4 changed files with 98 additions and 169 deletions
+3 -3
View File
@@ -1312,9 +1312,6 @@ extern void release_runtime_info(void);
#ifdef ENHANCED_SYMBOLS
extern void dump_glyphids(void);
#endif
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
extern int mstrength(struct permonst *);
#endif
/* ### mhitm.c ### */
@@ -1663,6 +1660,9 @@ extern boolean mon_knows_traps(struct monst *, int);
extern void mon_learns_traps(struct monst *, int);
extern void mons_see_trap(struct trap *);
extern int get_atkdam_type(int);
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
extern int mstrength(struct permonst *);
#endif
/* ### monmove.c ### */
-95
View File
@@ -299,101 +299,6 @@ nh_snprintf(const char *func UNUSED, int line UNUSED, char *str, size_t size,
RESTORE_WARNING_FORMAT_NONLITERAL
#endif /* MAKEDEFS_C */
#if defined(MAKEDEFS_C) \
|| (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
/*
* In 3.4.3 and earlier, this code was used to construct monstr[] array
* in generated file src/monstr.c. It wasn't used in 3.6. For 3.7 it
* has been reincarnated as a way to generate default monster strength
* values:
* add new monster(s) to include/monsters.h with placeholder value
* for the monstr field;
* run 'makedefs -m' to create src/monstr.c; ignore the complaints
* about it being deprecated;
* transfer relevant generated monstr values to include/monsters.h;
* delete src/monstr.c.
*/
static boolean mdlib_ranged_attk(struct permonst *);
/*
* This routine is designed to return an integer value which represents
* an approximation of monster strength. It uses a similar method of
* determination as "experience()" to arrive at the strength.
*/
int
mstrength(struct permonst* ptr)
{
int i, tmp2, n, tmp = ptr->mlevel;
if (tmp > 49) /* special fixed hp monster */
tmp = 2 * (tmp - 6) / 4;
/* for creation in groups */
n = (!!(ptr->geno & G_SGROUP));
n += (!!(ptr->geno & G_LGROUP)) << 1;
/* for ranged attacks */
if (mdlib_ranged_attk(ptr))
n++;
/* for higher ac values */
n += (ptr->ac < 4);
n += (ptr->ac < 0);
/* for very fast monsters */
n += (ptr->mmove >= 18);
/* for each attack and "special" attack */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].aatyp;
n += (tmp2 > 0);
n += (tmp2 == AT_MAGC);
n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
}
/* for each "special" damage type */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].adtyp;
if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
|| (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
n += 2;
else if (strcmp(ptr->pmnames[NEUTRAL], "grid bug"))
n += (tmp2 != AD_PHYS);
n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
}
/* Leprechauns are special cases. They have many hit dice so they
can hit and are hard to kill, but they don't really do much damage. */
if (!strcmp(ptr->pmnames[NEUTRAL], "leprechaun"))
n -= 2;
/* finally, adjust the monster level 0 <= n <= 24 (approx.) */
if (n == 0)
tmp--;
else if (n >= 6)
tmp += (n / 2);
else
tmp += (n / 3 + 1);
return (tmp >= 0) ? tmp : 0;
}
/* returns True if monster can attack at range */
static boolean
mdlib_ranged_attk(register struct permonst* ptr)
{
register int i, j;
register int atk_mask = (1 << AT_BREA) | (1 << AT_SPIT) | (1 << AT_GAZE);
for (i = 0; i < NATTK; i++) {
if ((j = ptr->mattk[i].aatyp) >= AT_WEAP
|| (j < 32 && (atk_mask & (1 << j)) != 0))
return TRUE;
}
return FALSE;
}
#endif /* (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || DEBUG || MAKEDEFS_C */
char *
version_id_string(char *outbuf, int bufsz, const char *build_date)
{
+95
View File
@@ -314,6 +314,101 @@ ranged_attk(struct permonst* ptr)
return FALSE;
}
#if defined(MAKEDEFS_C) \
|| (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || defined(DEBUG)
/*
* In 3.4.3 and earlier, this code was used to construct monstr[] array
* in generated file src/monstr.c. It wasn't used in 3.6. For 3.7 it
* has been reincarnated as a way to generate default monster strength
* values:
* add new monster(s) to include/monsters.h with placeholder value
* for the monstr field;
* run 'makedefs -m' to create src/monstr.c; ignore the complaints
* about it being deprecated;
* transfer relevant generated monstr values to include/monsters.h;
* delete src/monstr.c.
*/
static boolean mstrength_ranged_attk(struct permonst *);
/*
* This routine is designed to return an integer value which represents
* an approximation of monster strength. It uses a similar method of
* determination as "experience()" to arrive at the strength.
*/
int
mstrength(struct permonst* ptr)
{
int i, tmp2, n, tmp = ptr->mlevel;
if (tmp > 49) /* special fixed hp monster */
tmp = 2 * (tmp - 6) / 4;
/* for creation in groups */
n = (!!(ptr->geno & G_SGROUP));
n += (!!(ptr->geno & G_LGROUP)) << 1;
/* for ranged attacks */
if (mstrength_ranged_attk(ptr))
n++;
/* for higher ac values */
n += (ptr->ac < 4);
n += (ptr->ac < 0);
/* for very fast monsters */
n += (ptr->mmove >= 18);
/* for each attack and "special" attack */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].aatyp;
n += (tmp2 > 0);
n += (tmp2 == AT_MAGC);
n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
}
/* for each "special" damage type */
for (i = 0; i < NATTK; i++) {
tmp2 = ptr->mattk[i].adtyp;
if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
|| (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
n += 2;
else if (strcmp(ptr->pmnames[NEUTRAL], "grid bug"))
n += (tmp2 != AD_PHYS);
n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
}
/* Leprechauns are special cases. They have many hit dice so they
can hit and are hard to kill, but they don't really do much damage. */
if (!strcmp(ptr->pmnames[NEUTRAL], "leprechaun"))
n -= 2;
/* finally, adjust the monster level 0 <= n <= 24 (approx.) */
if (n == 0)
tmp--;
else if (n >= 6)
tmp += (n / 2);
else
tmp += (n / 3 + 1);
return (tmp >= 0) ? tmp : 0;
}
/* returns True if monster can attack at range */
static boolean
mstrength_ranged_attk(register struct permonst* ptr)
{
register int i, j;
register int atk_mask = (1 << AT_BREA) | (1 << AT_SPIT) | (1 << AT_GAZE);
for (i = 0; i < NATTK; i++) {
if ((j = ptr->mattk[i].aatyp) >= AT_WEAP
|| (j < 32 && (atk_mask & (1 << j)) != 0))
return TRUE;
}
return FALSE;
}
#endif /* (NH_DEVEL_STATUS != NH_STATUS_RELEASED) || DEBUG || MAKEDEFS_C */
/* True if specific monster is especially affected by silver weapons */
boolean
mon_hates_silver(struct monst *mon)
-71
View File
@@ -54,7 +54,6 @@
#define RUMOR_FILE "rumors"
#define DGN_I_FILE "dungeon.def"
#define DGN_O_FILE "dungeon.pdf"
#define MON_STR_C "monstr.c"
#if 0
#define QTXT_I_FILE "quest.txt"
#define QTXT_O_FILE "quest.dat"
@@ -293,10 +292,6 @@ do_makedefs(char *options)
case 'E':
do_dungeon();
break;
case 'm':
case 'M':
do_monstr();
break;
case 'v':
case 'V':
do_date();
@@ -1869,72 +1864,6 @@ do_dungeon(void)
return;
}
/* not quite obsolete but no longer needed to build nethack */
void
do_monstr(void)
{
struct permonst *ptr;
int i;
/* Don't break anything for ports that haven't been updated. */
printf("DEPRECATION WARNINGS:\n");
printf("'makedefs -m' is deprecated. Remove all references\n");
printf(" to it from the build process.\n");
printf("'monstr.c' is deprecated. Remove all references to\n");
printf(" it from the build process.\n");
printf("monstr[] is deprecated. Replace monstr[x] with\n");
printf(" mons[x].difficulty\n");
printf("monstr_init() is deprecated. Remove all references to it.\n");
/*
* create the source file, "monstr.c"
*/
filename[0] = '\0';
#ifdef FILE_PREFIX
Strcat(filename, file_prefix);
#endif
Sprintf(eos(filename), SOURCE_TEMPLATE, MON_STR_C);
if (!(ofp = fopen(filename, WRTMODE))) {
perror(filename);
makedefs_exit(EXIT_FAILURE);
/*NOTREACHED*/
}
Fprintf(ofp, "%s", Dont_Edit_Code);
Fprintf(ofp, "#include \"config.h\"\n");
Fprintf(ofp, "\nconst int monstrXXX[] = {\n");
Fprintf(ofp, "0};\n");
Fprintf(ofp, "/*\n");
Fprintf(ofp, "DEPRECATION WARNINGS:\n");
Fprintf(ofp, "'makedefs -m' is deprecated. Remove all references\n");
Fprintf(ofp, " to it from the build process.\n");
Fprintf(ofp, "'monstr.c' is deprecated. Remove all references to\n");
Fprintf(ofp, " it from the build process.\n");
Fprintf(ofp, "monstr[] is deprecated. Replace monstr[x] with\n");
Fprintf(ofp, " mons[x].difficulty\n");
Fprintf(ofp,
"monstr_init() is deprecated. Remove all references to it.\n");
Fprintf(ofp, "*/\n");
/* output derived monstr values as a comment */
Fprintf(ofp, "\n\n/*\n * default mons[].difficulty values\n *\n");
for (ptr = &mons[0]; ptr->mlet; ptr++) {
i = mstrength(ptr);
Fprintf(ofp, "%-24s %2u\n", ptr->pmnames[NEUTRAL], (unsigned) i);
}
Fprintf(ofp, " *\n */\n\n");
Fprintf(ofp, "\nvoid monstr_init(void);\n");
Fprintf(ofp, "\nvoid\n");
Fprintf(ofp, "monstr_init(void)\n");
Fprintf(ofp, "{\n");
Fprintf(ofp, " return;\n");
Fprintf(ofp, "}\n");
Fprintf(ofp, "\n/*monstr.c*/\n");
Fclose(ofp);
return;
}
/* obsolete */
void
do_permonst(void)