From 73b8af02c320750c52209bf1a342a39595b01736 Mon Sep 17 00:00:00 2001 From: David Meyer Date: Thu, 21 Mar 2024 13:12:46 +0900 Subject: [PATCH] Save top scores for both gold and exp. --- score.c | 94 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/score.c b/score.c index d0cd490..a92bf65 100644 --- a/score.c +++ b/score.c @@ -107,7 +107,7 @@ killed_by(const object *monster, short other) mechanism = mechanism_buf; } snprintf(message_buf, sizeof(message_buf), - "%s with %ld gold and %ld experience (level %d)", + "%s with %ld gold and %ld experience (level%d)", mechanism, rogue.gold, rogue.exp_points, rogue.exp); if ((!other) && (!no_skull)) { @@ -369,6 +369,8 @@ put_scores(const object *monster, short other) sf_error(); } + /* Gold & Glory: First half of score entries are top gold-gatherers, + second half (starting from index expscore) are top experience-earners. */ expscore = numscores / 2; /* Search the gold score list. */ @@ -418,28 +420,52 @@ put_scores(const object *monster, short other) /* If we're going to insert ourselves, do it now */ if (!score_only) { - /* if we aren't better than anyone, add at end. */ - rank = numscores; + /* Gold&Glory: did we make the top gold list? */ + /* if we aren't better than anyone, add at end. */ + rank = expscore; + + /* Otherwise, find our slot. */ + for (i = 0; i < expscore; i++) { + if (rogue.gold >= scores[i].gold) { + rank = i; + break; + } + } - /* Otherwise, find our slot. */ - for (i = 0; i < numscores; i++) { - if (rogue.gold >= scores[i].gold) { - rank = i; - break; - } - } + if (rank < NUM_SCORE_ENTRIES/2) { + /* Open up a slot */ + for (i = numscores; i > rank; i--) { + scores[i] = scores[i-1]; + } + numscores++; - if (rank < NUM_SCORE_ENTRIES) { - /* Open up a slot */ - for (i = numscores; i > rank; i--) { - scores[i] = scores[i-1]; - } - numscores++; + /* Put our info in the slot */ + make_score(&scores[rank], monster, other); + } - /* Put our info in the slot */ - make_score(&scores[rank], monster, other); - } + /* Gold&Glory: did we make the top experience list? */ + /* if we aren't better than anyone, add at end. */ + rank = numscores; + /* Otherwise, find our slot. */ + for (i = expscore; i < numscores; i++) { + if (rogue.exp_level >= scores[i].gold) { + rank = i; + break; + } + } + + if (rank < NUM_SCORE_ENTRIES) { + /* Open up a slot */ + for (i = numscores; i > rank; i--) { + scores[i] = scores[i-1]; + } + numscores++; + + /* Put our info in the slot */ + make_score(&scores[rank], monster, other); + } + /* Now rewrite the score file */ md_ignore_signals(); @@ -456,10 +482,10 @@ put_scores(const object *monster, short other) /* Display the scores */ clear(); - mvaddstr(3, 30, "Top Ten Rogueists"); - mvaddstr(8, 0, "Rank Score Name"); + mvaddstr(3, 27, "Top Gold & Glory Rogueists"); + mvaddstr(7, 0, "Rank Gold Name"); - for (i = 0; i < numscores; i++) { + for (i = 0; i < expscore; i++) { if (i == rank) { standout(); } @@ -470,13 +496,35 @@ put_scores(const object *monster, short other) name = scores[i].username; } - mvprintw(i+10, 0, "%2d %6ld %s: %s", + mvprintw(i+8, 0, "%2d %6ld %s: %s", i+1, scores[i].gold, name, scores[i].death); if (i == rank) { standend(); } } + + mvaddstr(14, 0, "Rank Exp Lev Name"); + + for (i = expscore; i < numscores; i++) { + if (i == rank) { + standout(); + } + + if (scores[i].nickname[0]) { + name = scores[i].nickname; + } else { + name = scores[i].username; + } + + mvprintw(i+15, 0, "%2d %6ld %02d %s: %s", + i+1 - expscore, scores[i].gold, get_exp_level(scores[i].gold), + name, scores[i].death); + + if (i == rank) { + standend(); + } + } refresh(); messagef(0, "%s", ""); /* gcc objects to just "" */ if (dopause) {