simplify #vanquished monsters processing...

...prior to making it more complicated.  Most of the diff is just
reducing the block nesting level of the kill-count formatting by
a couple of tab stops.
This commit is contained in:
PatR
2016-05-01 13:54:08 -07:00
parent 759544dd33
commit a952162a7b
+33 -14
View File
@@ -50,6 +50,8 @@ STATIC_DCL void FDECL(artifact_score, (struct obj *, BOOLEAN_P, winid));
STATIC_DCL void FDECL(really_done, (int)) NORETURN; STATIC_DCL void FDECL(really_done, (int)) NORETURN;
STATIC_DCL boolean FDECL(odds_and_ends, (struct obj *, int)); STATIC_DCL boolean FDECL(odds_and_ends, (struct obj *, int));
STATIC_DCL void FDECL(savelife, (int)); STATIC_DCL void FDECL(savelife, (int));
STATIC_PTR int FDECL(CFDECLSPEC vanqsort_cmp, (const genericptr,
const genericptr));
STATIC_DCL void FDECL(list_vanquished, (CHAR_P, BOOLEAN_P)); STATIC_DCL void FDECL(list_vanquished, (CHAR_P, BOOLEAN_P));
STATIC_DCL void FDECL(list_genocided, (CHAR_P, BOOLEAN_P)); STATIC_DCL void FDECL(list_genocided, (CHAR_P, BOOLEAN_P));
STATIC_DCL boolean FDECL(should_query_disclose_option, (int, char *)); STATIC_DCL boolean FDECL(should_query_disclose_option, (int, char *));
@@ -1424,6 +1426,23 @@ int status;
nethack_exit(status); nethack_exit(status);
} }
STATIC_PTR int CFDECLSPEC
vanqsort_cmp(vptr1, vptr2)
const genericptr vptr1;
const genericptr vptr2;
{
int indx1 = *(short *) vptr1, indx2 = *(short *) vptr2,
mlev1 = mons[indx1].mlevel, mlev2 = mons[indx2].mlevel,
res;
/* sort by monster level */
res = mlev2 - mlev1; /* mlevel high to low */
if (res == 0)
res = indx1 - indx2; /* tiebreaker, mons[] index low to high */
return res;
}
/* #vanquished command */ /* #vanquished command */
int int
dovanquished() dovanquished()
@@ -1437,20 +1456,21 @@ list_vanquished(defquery, ask)
char defquery; char defquery;
boolean ask; boolean ask;
{ {
register int i, lev; register int i;
int ntypes = 0, max_lev = 0, pfx, nkilled; int pfx, nkilled;
unsigned ntypes, ni;
long total_killed = 0L; long total_killed = 0L;
char c;
winid klwin; winid klwin;
char buf[BUFSZ], buftoo[BUFSZ]; short mindx[NUMMONS];
char c, buf[BUFSZ], buftoo[BUFSZ];
/* get totals first */ /* get totals first */
ntypes = 0;
for (i = LOW_PM; i < NUMMONS; i++) { for (i = LOW_PM; i < NUMMONS; i++) {
if (mvitals[i].died) if ((nkilled = (int) mvitals[i].died) == 0)
ntypes++; continue;
total_killed += (long) mvitals[i].died; mindx[ntypes++] = i;
if (mons[i].mlevel > max_lev) total_killed += (long) nkilled;
max_lev = mons[i].mlevel;
} }
/* vanquished creatures list; /* vanquished creatures list;
@@ -1468,11 +1488,10 @@ boolean ask;
putstr(klwin, 0, "Vanquished creatures:"); putstr(klwin, 0, "Vanquished creatures:");
putstr(klwin, 0, ""); putstr(klwin, 0, "");
/* countdown by monster "toughness" */ qsort((genericptr_t) mindx, ntypes, sizeof *mindx, vanqsort_cmp);
for (lev = max_lev; lev >= 0; lev--) for (ni = 0; ni < ntypes; ni++) {
for (i = LOW_PM; i < NUMMONS; i++) i = mindx[ni];
if (mons[i].mlevel == lev nkilled = mvitals[i].died;
&& (nkilled = mvitals[i].died) > 0) {
if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) { if ((mons[i].geno & G_UNIQ) && i != PM_HIGH_PRIEST) {
Sprintf(buf, "%s%s", Sprintf(buf, "%s%s",
!type_is_pname(&mons[i]) ? "the " : "", !type_is_pname(&mons[i]) ? "the " : "",