diff --git a/rogue.h b/rogue.h index 814f829..9128e1e 100644 --- a/rogue.h +++ b/rogue.h @@ -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 diff --git a/roguegg b/roguegg index e305c3e..9fc3e07 100755 Binary files a/roguegg and b/roguegg differ diff --git a/score.c b/score.c index b7477ef..ccdf6e5 100644 --- a/score.c +++ b/score.c @@ -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= 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) {