MCPcopy Create free account
hub / github.com/NetHack/NetHack / dump_weights

Function dump_weights

src/hack.c:4420–4483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4418static struct weight_table_entry *weightlist;
4419
4420void
4421dump_weights(void)
4422{
4423 int i, cnt = 0, nmwidth = 49, mcount = NUMMONS, ocount = NUM_OBJECTS;
4424 char nmbuf[BUFSZ], nmbufbase[BUFSZ];
4425 size_t num_entries = (size_t) (mcount + ocount);
4426
4427 weightlist = (struct weight_table_entry *)
4428 alloc(sizeof (struct weight_table_entry) * num_entries);
4429 decl_globals_init();
4430 init_objects();
4431 for (i = 0; i < mcount; ++i) {
4432 if (i != PM_LONG_WORM_TAIL) {
4433 boolean cm;
4434
4435 weightlist[cnt].wt = (int) mons[i].cwt;
4436 weightlist[cnt].idx = i;
4437 weightlist[cnt].wtyp = 1;
4438 weightlist[cnt].unique = ((mons[i].geno & G_UNIQ) != 0);
4439 Snprintf(nmbuf, sizeof nmbuf, "%07u", weightlist[cnt].wt);
4440 cm = CapitalMon(mons[i].pmnames[NEUTRAL]);
4441 Snprintf(&nmbuf[7], sizeof nmbuf - 7, "%s%s", "the body of ",
4442 (cm) ? the(mons[i].pmnames[NEUTRAL])
4443 : weightlist[cnt].unique ? mons[i].pmnames[NEUTRAL]
4444 : an(mons[i].pmnames[NEUTRAL]));
4445 weightlist[cnt].nm = dupstr(nmbuf);
4446 cnt++;
4447 }
4448 }
4449 for (i = 0; i < ocount; ++i) {
4450 const char *oc_name = (i == SLIME_MOLD) ? "slime mold"
4451 : obj_descr[i].oc_name;
4452 int wt = (int) objects[i].oc_weight;
4453
4454 if (wt && oc_name) {
4455 weightlist[cnt].idx = i;
4456 weightlist[cnt].wt = wt;
4457 weightlist[cnt].wtyp = 2;
4458 weightlist[cnt].unique = (objects[i].oc_unique != 0);
4459 objects[i].oc_name_known = 1;
4460 Strcpy(nmbufbase, simple_typename(i));
4461 Snprintf(nmbuf, sizeof nmbuf, "%07u%s", wt,
4462 (weightlist[cnt].unique) ? the(nmbufbase)
4463 : an(nmbufbase));
4464 weightlist[cnt].nm = dupstr(nmbuf);
4465 cnt++;
4466 }
4467 }
4468 qsort((genericptr_t) weightlist, cnt,
4469 sizeof (struct weight_table_entry), cmp_weights);
4470 raw_printf("int all_weights[] = {");
4471 for (i = 0; i < cnt; ++i) {
4472 if (weightlist[i].nm) {
4473 raw_printf(" %7u%s /* %*s */", weightlist[i].wt,
4474 (i == cnt - 1) ? " " : ",", -nmwidth,
4475 &weightlist[i].nm[7]);
4476 free((genericptr_t) weightlist[i].nm), weightlist[i].nm = 0;
4477 }

Callers 1

argcheckFunction · 0.85

Calls 12

decl_globals_initFunction · 0.85
init_objectsFunction · 0.85
CapitalMonFunction · 0.85
theFunction · 0.85
anFunction · 0.85
dupstrFunction · 0.85
simple_typenameFunction · 0.85
qsortFunction · 0.85
raw_printFunction · 0.85
freedynamicdataFunction · 0.85
allocFunction · 0.70
raw_printfFunction · 0.70

Tested by

no test coverage detected