Scoreboard working, still problem recording top gold score

This commit is contained in:
David Meyer 2024-03-21 22:55:51 +09:00
parent 0eff9ba9f2
commit 681b7119af
3 changed files with 55 additions and 44 deletions

View File

@ -394,6 +394,9 @@ extern object level_monsters;
#define WIN 5
#define KFIRE 6
#define TOP_GOLD 1
#define TOP_EXP 2
#define UPWARD 0
#define UPRIGHT 1
#define RIGHT 2

BIN
roguegg

Binary file not shown.

96
score.c
View File

@ -228,8 +228,9 @@ struct score_entry {
};
#define NUM_SCORE_ENTRIES 10
#define FIRST_EXP_SCORE 5
static void make_score(struct score_entry *, const object *, int);
static void make_score(struct score_entry *, const object *, int, int);
static
void
@ -336,8 +337,8 @@ write_score_entry(const struct score_entry *se, int rank, FILE *fp)
void
put_scores(const object *monster, short other)
{
short i, rank=-1, found_player = -1, numscores = 0;
short expscore, found_player_exp = -1;
short i, rank=-1, found_player = -1, numscores = NUM_SCORE_ENTRIES;
short rank_exp=-1, expscore = FIRST_EXP_SCORE, found_player_exp = -1;
struct score_entry scores[NUM_SCORE_ENTRIES];
const char *name;
FILE *fp;
@ -356,25 +357,22 @@ put_scores(const object *monster, short other)
rewind(fp);
(void)xxx(1);
for (numscores = 0; numscores < NUM_SCORE_ENTRIES; numscores++) {
if (read_score_entry(&scores[numscores], fp) == 0) {
/* Initialize scores array */
for (i = 0; i < NUM_SCORE_ENTRIES; i++) {
scores[i].gold = -1;
scores[i].username[0] = '\0';
scores[i].death[0] = '\0';
scores[i].nickname[0] = '\0';
}
for (i = 0; i < NUM_SCORE_ENTRIES; i++) {
if (read_score_entry(&scores[i], fp) == 0) {
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();
}
/* 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. */
for (i=0; i<expscore; i++) {
for (i = 0; i < FIRST_EXP_SCORE; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.gold < scores[i].gold) {
@ -389,7 +387,7 @@ put_scores(const object *monster, short other)
}
/* Search the exp score list. */
for (i=expscore; i<numscores; i++) {
for (i = FIRST_EXP_SCORE; i < NUM_SCORE_ENTRIES; i++) {
if (!strcmp(scores[i].username, login_name)) {
/* found our score */
if (rogue.exp_points < scores[i].gold) {
@ -405,16 +403,22 @@ put_scores(const object *monster, short other)
/* Remove superseded entries, if any. */
if (found_player != -1) {
numscores--;
for (i = found_player; i < numscores; i++) {
for (i = found_player; i < FIRST_EXP_SCORE-1; i++) {
scores[i] = scores[i+1];
}
scores[i].gold = 0;
scores[i].username[0] = '\0';
scores[i].death[0] = '\0';
scores[i].nickname[0] = '\0';
}
if (found_player_exp != -1) {
numscores--;
for (i = found_player_exp; i < numscores; i++) {
for (i = found_player_exp; i < NUM_SCORE_ENTRIES-1; i++) {
scores[i] = scores[i+1];
}
scores[i].gold = 0;
scores[i].username[0] = '\0';
scores[i].death[0] = '\0';
scores[i].nickname[0] = '\0';
}
/* If we're going to insert ourselves, do it now */
@ -422,48 +426,46 @@ put_scores(const object *monster, short other)
/* Gold&Glory: did we make the top gold list? */
/* if we aren't better than anyone, add at end. */
rank = expscore;
rank = FIRST_EXP_SCORE;
/* Otherwise, find our slot. */
for (i = 0; i < expscore; i++) {
for (i = 0; i < FIRST_EXP_SCORE; i++) {
if (rogue.gold >= scores[i].gold) {
rank = i;
break;
}
}
if (rank < NUM_SCORE_ENTRIES/2) {
if (rank < FIRST_EXP_SCORE) {
/* Open up a slot */
for (i = numscores; i > rank; i--) {
for (i = FIRST_EXP_SCORE-1; i > rank; i--) {
scores[i] = scores[i-1];
}
numscores++;
/* Put our info in the slot */
make_score(&scores[rank], monster, other);
make_score(&scores[rank], monster, other, TOP_GOLD);
}
/* Gold&Glory: did we make the top experience list? */
/* if we aren't better than anyone, add at end. */
rank = numscores;
rank_exp = NUM_SCORE_ENTRIES;
/* Otherwise, find our slot. */
for (i = expscore; i < numscores; i++) {
for (i = FIRST_EXP_SCORE; i < NUM_SCORE_ENTRIES; i++) {
if (rogue.exp_points >= scores[i].gold) {
rank = i;
rank_exp = i;
break;
}
}
if (rank < NUM_SCORE_ENTRIES) {
if (rank_exp < NUM_SCORE_ENTRIES) {
/* Open up a slot */
for (i = numscores; i > rank; i--) {
for (i = NUM_SCORE_ENTRIES-1; i > rank; i--) {
scores[i] = scores[i-1];
}
numscores++;
/* Put our info in the slot */
make_score(&scores[rank], monster, other);
make_score(&scores[rank_exp], monster, other, TOP_EXP);
}
/* Now rewrite the score file */
@ -485,7 +487,8 @@ put_scores(const object *monster, short other)
mvaddstr(3, 27, "Top Gold & Glory Rogueists");
mvaddstr(7, 0, "Rank Gold Name");
for (i = 0; i < expscore; i++) {
for (i = 0; i < FIRST_EXP_SCORE; i++) {
if (scores[i].gold == 0) break;
if (i == rank) {
standout();
}
@ -504,10 +507,11 @@ put_scores(const object *monster, short other)
}
}
mvaddstr(14, 0, "Rank Exp Lev Name");
mvaddstr(14, 0, "Rank Lvl/Exp Name");
for (i = expscore; i < numscores; i++) {
if (i == rank) {
for (i = FIRST_EXP_SCORE; i < NUM_SCORE_ENTRIES; i++) {
if (scores[i].gold == 0) break;
if (i == rank_exp) {
standout();
}
@ -517,11 +521,11 @@ put_scores(const object *monster, short other)
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),
mvprintw(i+10, 0, "%2d %2d/%-6ld %s: %s",
i+1 - expscore, get_exp_level(scores[i].gold), scores[i].gold,
name, scores[i].death);
if (i == rank) {
if (i == rank_exp) {
standend();
}
}
@ -535,13 +539,17 @@ put_scores(const object *monster, short other)
static
void
make_score(struct score_entry *se, const object *monster, int other)
make_score(struct score_entry *se, const object *monster, int other, int type)
{
const char *death = "bolts from the blue (?)";
const char *hasamulet;
char deathbuf[80];
se->gold = rogue.gold;
if (type==TOP_GOLD) {
se->gold = rogue.gold;
} else {
se->gold = rogue.exp_points;
}
strlcpy(se->username, login_name, sizeof(se->username));
if (other) {