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

70
score.c
View File

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