Segregate score file into gold and XP sections; print XP in end results

This commit is contained in:
David Meyer 2024-03-20 16:51:29 +09:00
parent 6e191ef7e8
commit 019a9df5d2
1 changed files with 51 additions and 19 deletions

70
score.c
View File

@ -107,7 +107,8 @@ killed_by(const object *monster, short other)
mechanism = mechanism_buf;
}
snprintf(message_buf, sizeof(message_buf),
"%s with %ld gold", mechanism, rogue.gold);
"%s with %ld gold and %ld experience (level %d)",
mechanism, rogue.gold, rogue.exp_points, rogue.exp);
if ((!other) && (!no_skull)) {
clear();
@ -336,6 +337,7 @@ void
put_scores(const object *monster, short other)
{
short i, rank=-1, found_player = -1, numscores = 0;
short expscore, found_player_exp = -1;
struct score_entry scores[NUM_SCORE_ENTRIES];
const char *name;
FILE *fp;
@ -360,27 +362,57 @@ put_scores(const object *monster, short other)
}
}
/* Search the score list. */
for (i=0; i<numscores; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.gold < scores[i].gold) {
/* we didn't do as well as last time */
score_only = 1;
} else {
/* we did better; mark entry for removal */
found_player = i;
}
break;
}
/* Gold & Glory check: there should always be even number of score
entries. */
if (numscores % 2 != 0) {
messagef(0, "invalid score file -- odd number of entries");
sf_error();
}
/* Remove a superseded entry, if any. */
expscore = numscores / 2;
/* Search the gold score list. */
for (i=0; i<expscore; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.gold < scores[i].gold) {
/* we didn't do as well as last time */
score_only = 1;
} else {
/* we did better; mark entry for removal */
found_player = i;
}
break;
}
}
/* Search the exp score list. */
for (i=expscore; i<numscores; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.exp_points < scores[i].gold) {
/* we didn't do as well as last time */
score_only = 1;
} else {
/* we did better; mark entry for removal */
found_player_exp = i;
}
break;
}
}
/* Remove superseded entries, if any. */
if (found_player != -1) {
numscores--;
for (i = found_player; i < numscores; i++) {
scores[i] = scores[i+1];
}
numscores--;
for (i = found_player; i < numscores; i++) {
scores[i] = scores[i+1];
}
}
if (found_player_exp != -1) {
numscores--;
for (i = found_player_exp; i < numscores; i++) {
scores[i] = scores[i+1];
}
}
/* If we're going to insert ourselves, do it now */