dump monster and obj weights using --dumpweights

This commit is contained in:
nhmall
2025-03-15 19:55:49 -04:00
parent 488011571a
commit b169b79d36
7 changed files with 114 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ staticfn void move_update(boolean);
staticfn int pickup_checks(void);
staticfn void maybe_wail(void);
staticfn boolean water_turbulence(coordxy *, coordxy *);
staticfn int QSORTCALLBACK cmp_weights(const void *, const void *);
#define IS_SHOP(x) (svr.rooms[x].rtype >= SHOPBASE)
@@ -4293,6 +4294,106 @@ check_capacity(const char *str)
return 0;
}
struct weight_table_entry {
unsigned wtyp; /* 1 = monst, 2 = obj */
const char *nm;
int wt, idx;
boolean unique;
};
static struct weight_table_entry *weightlist;
void
dump_weights(void)
{
int i, cnt = 0, nmwidth = 49, mcount = NUMMONS, ocount = NUM_OBJECTS;
char nmbuf[BUFSZ], nmbufbase[BUFSZ];
struct obj o = cg.zeroobj;
weightlist = (struct weight_table_entry *) alloc(sizeof(struct weight_table_entry)
* (mcount + ocount));
decl_globals_init();
init_objects();
o.quan = 1;
o.known = o.dknown == 1;
for (i = 0; i < mcount; ++i) {
if (i != PM_LONG_WORM_TAIL) {
weightlist[cnt].idx = i;
weightlist[cnt].wtyp = 1;
weightlist[cnt].nm = dupstr(mons[i].pmnames[NEUTRAL]);
weightlist[cnt].wt = (int) mons[i].cwt;
weightlist[cnt].unique = ((mons[i].geno & G_UNIQ) != 0);
cnt++;
}
}
for (i = 0; i < ocount; ++i) {
int wt = (int) objects[i].oc_weight;
if (wt && i != SLIME_MOLD && obj_descr[i].oc_name) {
weightlist[cnt].idx = i;
o.otyp = i;
o.oclass = objects[i].oc_class;
weightlist[cnt].wtyp = 2;
weightlist[cnt].nm = dupstr(obj_descr[i].oc_name);
weightlist[cnt].wt = wt;
weightlist[cnt].unique = (objects[i].oc_unique != 0);
cnt++;
}
}
qsort((genericptr_t) weightlist, cnt,
sizeof (struct weight_table_entry), cmp_weights);
raw_printf("int all_weights[] = {");
for (i = 0; i < cnt; ++i) {
if (weightlist[i].wtyp == 1) {
boolean cm = CapitalMon(weightlist[i].nm);
Snprintf(nmbuf, sizeof nmbuf, "%s%s", "the body of ",
(cm) ? the(weightlist[i].nm)
: weightlist[i].unique ? weightlist[i].nm
: an(weightlist[i].nm));
} else {
Snprintf(nmbufbase, sizeof nmbufbase, "%s%s",
objects[weightlist[i].idx].oc_class == POTION_CLASS
? "potion of "
: objects[weightlist[i].idx].oc_class == WAND_CLASS
? "wand of "
: objects[weightlist[i].idx].oc_class == SCROLL_CLASS
? "scroll of "
: objects[weightlist[i].idx].oc_class == SPBOOK_CLASS
? "spellbook of "
: "",
weightlist[i].nm);
Snprintf(nmbuf, sizeof nmbuf, "%s",
(weightlist[i].unique) ? the(nmbufbase) : an(nmbufbase));
}
raw_printf(" %7u%s /* %*s */", weightlist[i].wt,
(i == cnt - 1) ? " " : ",", -nmwidth, nmbuf);
if (weightlist[i].nm)
free((genericptr_t) weightlist[i].nm), weightlist[i].nm = 0;
}
raw_print("};");
raw_print("");
free((genericptr_t) weightlist);
freedynamicdata();
}
staticfn int QSORTCALLBACK
cmp_weights(const void *p1, const void *p2)
{
struct weight_table_entry *i1 = (struct weight_table_entry *) p1,
*i2 = (struct weight_table_entry *) p2;
int x1 = i1->wt << 17, x2 = i2->wt << 17,
t1 = ((i1->wtyp == 1) ? 0 : 1) << 16,
t2 = ((i2->wtyp == 1) ? 0 : 1) << 16;
x1 |= t1 | ((i1->nm != 0) ? i1->nm[0] : 0) << 8;
x2 |= t2 | ((i2->nm != 0) ? i2->nm[0] : 0) << 8;
x1 |= ((i1->nm != 0) ? i1->nm[1] : 0);
x2 |= ((i2->nm != 0) ? i2->nm[1] : 0);
return (x1 - x2);
}
int
inv_cnt(boolean incl_gold)
{