/* * Predict the players location, and display it. */ void predict_score(void) { int j; high_score the_score; high_score scores[MAX_HISCORES]; /* Read scores, place current score */ highscore_read(scores, N_ELEMENTS(scores)); build_score(&the_score, "nobody (yet!)", NULL); if (p_ptr->is_dead) j = highscore_where(&the_score, scores, N_ELEMENTS(scores)); else j = highscore_add(&the_score, scores, N_ELEMENTS(scores)); /* Hack -- Display the top fifteen scores */ if (j < 10) { display_scores_aux(scores, 0, 15, j); } /* Display some "useful" scores */ else { display_scores_aux(scores, 0, 5, -1); display_scores_aux(scores, j - 2, j + 7, j); } }
/* * Hack -- Display the scores in a given range and quit. * * This function is only called from "main.c" when the user asks * to see the "high scores". */ void display_scores(int from, int to) { char buf[1024]; /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw"); /* Open the binary high score file, for reading */ highscore_fd = fd_open(buf, O_RDONLY); /* Paranoia -- No score file */ if (highscore_fd < 0) quit("Score file unavailable."); /* Clear screen */ Term_clear(); /* Display the scores */ display_scores_aux(from, to, -1, NULL); /* Shut the high score file */ (void)fd_close(highscore_fd); /* Forget the high score fd */ highscore_fd = -1; /* Quit */ quit(NULL); }
/* * Show scores. */ void show_scores(void) { screen_save(); /* Display the scores */ if (character_generated) { predict_score(); } else { high_score scores[MAX_HISCORES]; highscore_read(scores, N_ELEMENTS(scores)); display_scores_aux(scores, 0, MAX_HISCORES, -1); } screen_load(); /* Hack - Flush it */ Term_fresh(); }
/* * Predict the players location, and display it. */ errr predict_score(void) { int j; high_score the_score; /* No score file */ if (highscore_fd < 0) { msg_print("Score file unavailable."); msg_print(NULL); return (0); } /* Save the version */ sprintf(the_score.what, "%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); /* Save the current gold */ sprintf(the_score.gold, "%9d", p_ptr->au); /* Save the current turn */ sprintf(the_score.turns, "%9d", turn_real(turn)); /* Hack -- no time needed */ strcpy(the_score.day, "TODAY"); /* Save the player name (15 chars) */ sprintf(the_score.who, "%-.15s", player_name); /* Save the player info XXX XXX XXX */ sprintf(the_score.uid, "%7u", player_uid); sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f')); sprintf(the_score.p_r, "%2d", p_ptr->prace); sprintf(the_score.p_c, "%2d", p_ptr->pclass); sprintf(the_score.p_a, "%2d", p_ptr->personality); /* Save the level and such */ sprintf(the_score.cur_lev, "%3d", p_ptr->lev); sprintf(the_score.cur_dun, "%3d", dun_level); sprintf(the_score.max_lev, "%3d", p_ptr->max_plv); sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]); /* Hack -- no cause of death */ strcpy(the_score.how, "nobody (yet!)"); /* See where the entry would be placed */ j = highscore_where(&the_score); /* Hack -- Display the top fifteen scores */ if (j < 10) { display_scores_aux(0, 15, j, &the_score); } /* Display some "useful" scores */ else { display_scores_aux(0, 5, -1, NULL); display_scores_aux(j - 2, j + 7, j, &the_score); } /* Success */ return (0); }
/* * Enters a players name on a hi-score table, if "legal", and in any * case, displays some relevant portion of the high score list. * * Assumes "signals_ignore_tstp()" has been called. */ errr top_twenty(void) { int j; high_score the_score; time_t ct = time((time_t*)0); errr err; /* Clear the record */ (void)WIPE(&the_score, high_score); /* Save the version */ sprintf(the_score.what, "%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); the_score.pts[9] = '\0'; /* Save the current gold */ sprintf(the_score.gold, "%9d", p_ptr->au); the_score.gold[9] = '\0'; /* Save the current turn */ sprintf(the_score.turns, "%9d", turn_real(turn)); the_score.turns[9] = '\0'; #ifdef HIGHSCORE_DATE_HACK /* Save the date in a hacked up form (9 chars) */ (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22); #else /* Save the date in standard form (8 chars) */ /* (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */ /* Save the date in standard encoded form (9 chars) */ strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct)); #endif /* Save the player name (15 chars) */ sprintf(the_score.who, "%-.15s", player_name); /* Save the player info XXX XXX XXX */ sprintf(the_score.uid, "%7u", player_uid); sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f')); sprintf(the_score.p_r, "%2d", p_ptr->prace); sprintf(the_score.p_c, "%2d", p_ptr->pclass); sprintf(the_score.p_a, "%2d", p_ptr->personality); /* Save the level and such */ sprintf(the_score.cur_lev, "%3d", p_ptr->lev); sprintf(the_score.cur_dun, "%3d", dun_level); sprintf(the_score.max_lev, "%3d", p_ptr->max_plv); sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]); /* Save the cause of death (31 chars) */ if (strlen(p_ptr->died_from) >= sizeof(the_score.how)) { my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3); strcat(the_score.how, "..."); } else { strcpy(the_score.how, p_ptr->died_from); } /* Grab permissions */ safe_setuid_grab(); /* Lock (for writing) the highscore file, or fail */ err = fd_lock(highscore_fd, F_WRLCK); /* Drop permissions */ safe_setuid_drop(); if (err) return (1); /* Add a new entry to the score list, see where it went */ j = highscore_add(&the_score); /* Grab permissions */ safe_setuid_grab(); /* Unlock the highscore file, or fail */ err = fd_lock(highscore_fd, F_UNLCK); /* Drop permissions */ safe_setuid_drop(); if (err) return (1); /* Hack -- Display the top fifteen scores */ if (j < 10) { display_scores_aux(0, 15, j, NULL); } /* Display the scores surrounding the player */ else { display_scores_aux(0, 5, j, NULL); display_scores_aux(j - 2, j + 7, j, NULL); } /* Success */ return (0); }