OSDN Git Service

[Refactor] #1008 Reparated score-util.cpp/h from scores.cpp/h
[hengbandforosx/hengbandosx.git] / src / core / scores.cpp
1 /*!
2  * @file scores.c
3  * @brief ハイスコア処理 / Highscores handling
4  * @date 2014/07/14
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  * 2014 Deskull rearranged comment for Doxygen.
11  */
12
13 #include "core/scores.h"
14 #include "cmd-io/cmd-dump.h"
15 #include "core/asking-player.h"
16 #include "core/score-util.h"
17 #include "core/turn-compensator.h"
18 #include "dungeon/dungeon.h"
19 #include "game-option/birth-options.h"
20 #include "game-option/game-play-options.h"
21 #include "io/input-key-acceptor.h"
22 #include "io/report.h"
23 #include "io/signal-handlers.h"
24 #include "io/uid-checker.h"
25 #include "player/player-class.h"
26 #include "player/player-personality.h"
27 #include "player/player-status.h"
28 #include "player/race-info-table.h"
29 #include "system/angband-version.h"
30 #include "system/floor-type-definition.h"
31 #include "system/player-type-definition.h"
32 #include "term/screen-processor.h"
33 #include "term/term-color-types.h"
34 #include "util/angband-files.h"
35 #include "util/int-char-converter.h"
36 #include "util/string-processor.h"
37 #include "view/display-messages.h"
38 #include "world/world.h"
39
40 #ifdef JP
41 #include "locale/japanese.h"
42 #endif
43
44 /*!
45  * @brief 所定ポインタへスコア情報を書き込む / Write one score to the highscore file
46  * @param score スコア情報参照ポインタ
47  * @return エラーコード(問題がなければ0を返す)
48  */
49 static int highscore_write(high_score *score)
50 {
51     /* Write the record, note failure */
52     return (fd_write(highscore_fd, (char *)(score), sizeof(high_score)));
53 }
54
55 /*!
56  * @brief スコア情報を全て得るまで繰り返し取得する / Just determine where a new score *would* be placed
57  * @param score スコア情報参照ポインタ
58  * @return 正常ならば(MAX_HISCORES - 1)、問題があれば-1を返す
59  */
60 static int highscore_where(high_score *score)
61 {
62     /* Paranoia -- it may not have opened */
63     if (highscore_fd < 0)
64         return -1;
65
66     /* Go to the start of the highscore file */
67     if (highscore_seek(0))
68         return -1;
69
70     /* Read until we get to a higher score */
71     high_score the_score;
72     int my_score = atoi(score->pts);
73     for (int i = 0; i < MAX_HISCORES; i++) {
74         int old_score;
75         if (highscore_read(&the_score))
76             return (i);
77         old_score = atoi(the_score.pts);
78         if (my_score > old_score)
79             return (i);
80     }
81
82     /* The "last" entry is always usable */
83     return MAX_HISCORES - 1;
84 }
85
86 /*!
87  * @brief スコア情報をバッファの末尾に追加する / Actually place an entry into the high score file
88  * @param score スコア情報参照ポインタ
89  * @return 正常ならば書き込んだスロット位置、問題があれば-1を返す / Return the location (0 is best) or -1 on "failure"
90  */
91 static int highscore_add(high_score *score)
92 {
93     /* Paranoia -- it may not have opened */
94     if (highscore_fd < 0)
95         return -1;
96
97     /* Determine where the score should go */
98     int slot = highscore_where(score);
99
100     /* Hack -- Not on the list */
101     if (slot < 0)
102         return -1;
103
104     /* Hack -- prepare to dump the new score */
105     high_score the_score = (*score);
106
107     /* Slide all the scores down one */
108     bool done = FALSE;
109     high_score tmpscore;
110     for (int i = slot; !done && (i < MAX_HISCORES); i++) {
111         /* Read the old guy, note errors */
112         if (highscore_seek(i))
113             return -1;
114         if (highscore_read(&tmpscore))
115             done = TRUE;
116
117         /* Back up and dump the score we were holding */
118         if (highscore_seek(i))
119             return -1;
120         if (highscore_write(&the_score))
121             return -1;
122
123         /* Hack -- Save the old score, for the next pass */
124         the_score = tmpscore;
125     }
126
127     /* Return location used */
128     return slot;
129 }
130
131 /*!
132  * @brief 指定された順位範囲でスコアを並べて表示する / Display the scores in a given range.
133  * @param from 順位先頭
134  * @param to 順位末尾
135  * @param note 黄色表示でハイライトする順位
136  * @param score スコア配列参照ポインタ
137  * @details
138  * <pre>
139  * Assumes the high score list is already open.
140  * Only five entries per line, too much info.
141  *
142  * Mega-Hack -- allow "fake" entry at the given position.
143  * </pre>
144  */
145 void display_scores_aux(int from, int to, int note, high_score *score)
146 {
147     int i, j, k, n, place;
148     TERM_COLOR attr;
149
150     high_score the_score;
151
152     GAME_TEXT out_val[256];
153     GAME_TEXT tmp_val[160];
154
155     TERM_LEN wid, hgt, per_screen;
156
157     term_get_size(&wid, &hgt);
158     per_screen = (hgt - 4) / 4;
159
160     /* Paranoia -- it may not have opened */
161     if (highscore_fd < 0)
162         return;
163
164     /* Assume we will show the first 10 */
165     if (from < 0)
166         from = 0;
167     if (to < 0)
168         to = 10;
169     if (to > MAX_HISCORES)
170         to = MAX_HISCORES;
171
172     /* Seek to the beginning */
173     if (highscore_seek(0))
174         return;
175
176     /* Hack -- Count the high scores */
177     for (i = 0; i < MAX_HISCORES; i++) {
178         if (highscore_read(&the_score))
179             break;
180     }
181
182     /* Hack -- allow "fake" entry to be last */
183     if ((note == i) && score)
184         i++;
185
186     /* Forget about the last entries */
187     if (i > to)
188         i = to;
189
190     /* Show per_screen per page, until "done" */
191     for (k = from, place = k + 1; k < i; k += per_screen) {
192         term_clear();
193
194         /* Title */
195         put_str(_("                変愚蛮怒: 勇者の殿堂", "                Hengband Hall of Fame"), 0, 0);
196
197         /* Indicate non-top scores */
198         if (k > 0) {
199             sprintf(tmp_val, _("( %d 位以下 )", "(from position %d)"), k + 1);
200             put_str(tmp_val, 0, 40);
201         }
202
203         /* Dump per_screen entries */
204         for (j = k, n = 0; j < i && n < per_screen; place++, j++, n++) {
205             int pr, pc, pa, clev, mlev, cdun, mdun;
206
207             concptr user, gold, when, aged;
208
209             /* Hack -- indicate death in yellow */
210             attr = (j == note) ? TERM_YELLOW : TERM_WHITE;
211
212             /* Mega-Hack -- insert a "fake" record */
213             if ((note == j) && score) {
214                 the_score = (*score);
215                 attr = TERM_L_GREEN;
216                 score = NULL;
217                 note = -1;
218                 j--;
219             }
220
221             /* Read a normal record */
222             else {
223                 /* Read the proper record */
224                 if (highscore_seek(j))
225                     break;
226                 if (highscore_read(&the_score))
227                     break;
228             }
229
230             /* Extract the race/class */
231             pr = atoi(the_score.p_r);
232             pc = atoi(the_score.p_c);
233             pa = atoi(the_score.p_a);
234
235             /* Extract the level info */
236             clev = atoi(the_score.cur_lev);
237             mlev = atoi(the_score.max_lev);
238             cdun = atoi(the_score.cur_dun);
239             mdun = atoi(the_score.max_dun);
240
241             /* Hack -- extract the gold and such */
242             for (user = the_score.uid; iswspace(*user); user++) /* loop */
243                 ;
244             for (when = the_score.day; iswspace(*when); when++) /* loop */
245                 ;
246             for (gold = the_score.gold; iswspace(*gold); gold++) /* loop */
247                 ;
248             for (aged = the_score.turns; iswspace(*aged); aged++) /* loop */
249                 ;
250
251             /* Clean up standard encoded form of "when" */
252             if ((*when == '@') && strlen(when) == 9) {
253                 sprintf(tmp_val, "%.4s-%.2s-%.2s", when + 1, when + 5, when + 7);
254                 when = tmp_val;
255             }
256
257             /* Dump some info */
258 #ifdef JP
259             /*sprintf(out_val, "%3d.%9s  %s%s%sという名の%sの%s (レベル %d)", */
260             sprintf(out_val, "%3d.%9s  %s%s%s - %s%s (レベル %d)", place, the_score.pts, personality_info[pa].title, (personality_info[pa].no ? "の" : ""),
261                 the_score.who, race_info[pr].title, class_info[pc].title, clev);
262
263 #else
264             sprintf(out_val, "%3d.%9s  %s %s the %s %s, Level %d", place, the_score.pts, personality_info[pa].title, the_score.who, race_info[pr].title,
265                 class_info[pc].title, clev);
266 #endif
267
268             /* Append a "maximum level" */
269             if (mlev > clev)
270                 strcat(out_val, format(_(" (最高%d)", " (Max %d)"), mlev));
271
272             /* Dump the first line */
273             c_put_str(attr, out_val, n * 4 + 2, 0);
274
275             /* Another line of info */
276 #ifdef JP
277             if (mdun != 0)
278                 sprintf(out_val, "    最高%3d階", mdun);
279             else
280                 sprintf(out_val, "             ");
281
282             /* 死亡原因をオリジナルより細かく表示 */
283             if (streq(the_score.how, "yet")) {
284                 sprintf(out_val + 13, "  まだ生きている (%d%s)", cdun, "階");
285             } else if (streq(the_score.how, "ripe")) {
286                 sprintf(out_val + 13, "  勝利の後に引退 (%d%s)", cdun, "階");
287             } else if (streq(the_score.how, "Seppuku")) {
288                 sprintf(out_val + 13, "  勝利の後に切腹 (%d%s)", cdun, "階");
289             } else {
290                 codeconv(the_score.how);
291
292                 /* Some people die outside of the dungeon */
293                 if (!cdun)
294                     sprintf(out_val + 13, "  地上で%sに殺された", the_score.how);
295                 else
296                     sprintf(out_val + 13, "  %d階で%sに殺された", cdun, the_score.how);
297             }
298
299 #else
300             /* Some people die outside of the dungeon */
301             if (!cdun)
302                 sprintf(out_val, "               Killed by %s on the surface", the_score.how);
303             else
304                 sprintf(out_val, "               Killed by %s on %s %d", the_score.how, "Dungeon Level", cdun);
305
306             /* Append a "maximum level" */
307             if (mdun > cdun)
308                 strcat(out_val, format(" (Max %d)", mdun));
309 #endif
310
311             /* Dump the info */
312             c_put_str(attr, out_val, n * 4 + 3, 0);
313
314             /* And still another line of info */
315 #ifdef JP
316             {
317                 char buf[11];
318
319                 /* 日付を 19yy/mm/dd の形式に変更する */
320                 if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') {
321                     sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when);
322                     when = buf;
323                 }
324                 sprintf(out_val, "        (ユーザー:%s, 日付:%s, 所持金:%s, ターン:%s)", user, when, gold, aged);
325             }
326
327 #else
328             sprintf(out_val, "               (User %s, Date %s, Gold %s, Turn %s).", user, when, gold, aged);
329 #endif
330
331             c_put_str(attr, out_val, n * 4 + 4, 0);
332         }
333
334         /* Wait for response */
335         prt(_("[ ESCで中断, その他のキーで続けます ]", "[Press ESC to quit, any other key to continue.]"), hgt - 1, _(21, 17));
336
337         j = inkey();
338         prt("", hgt - 1, 0);
339
340         /* Hack -- notice Escape */
341         if (j == ESCAPE)
342             break;
343     }
344 }
345
346 /*!
347  * @brief スコア表示処理メインルーチン / Hack -- Display the scores in a given range and quit.
348  * @param from 順位先頭
349  * @param to 順位末尾
350  * @details
351  * <pre>
352  * This function is only called from "main.c" when the user asks
353  * to see the "high scores".
354  * </pre>
355  */
356 void display_scores(int from, int to)
357 {
358     char buf[1024];
359     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
360
361     /* Open the binary high score file, for reading */
362     highscore_fd = fd_open(buf, O_RDONLY);
363
364     /* Paranoia -- No score file */
365     if (highscore_fd < 0)
366         quit(_("スコア・ファイルが使用できません。", "Score file unavailable."));
367     term_clear();
368
369     /* Display the scores */
370     display_scores_aux(from, to, -1, NULL);
371
372     /* Shut the high score file */
373     (void)fd_close(highscore_fd);
374
375     /* Forget the high score fd */
376     highscore_fd = -1;
377
378     /* Quit */
379     quit(NULL);
380 }
381
382 /*!
383  * @brief スコアサーバへの転送処理
384  * @param current_player_ptr プレーヤーへの参照ポインタ
385  * @param do_send 実際に転送ア処置を行うか否か
386  * @return 転送が成功したらTRUEを返す
387  */
388 bool send_world_score(player_type *current_player_ptr, bool do_send, display_player_pf display_player)
389 {
390 #ifdef WORLD_SCORE
391     if (!send_score || !do_send) {
392         return true;
393     }
394
395     if (easy_band) {
396         msg_print(_("初心者モードではワールドスコアに登録できません。", "Since you are in the Easy Mode, you cannot send score to world score server."));
397         return true;
398     }
399
400     auto is_registration = get_check_strict(
401         current_player_ptr, _("スコアをスコア・サーバに登録しますか? ", "Do you send score to the world score server? "), (CHECK_NO_ESCAPE | CHECK_NO_HISTORY));
402     if (!is_registration) {
403         return true;
404     }
405
406     prt("", 0, 0);
407     prt(_("送信中..", "Sending..."), 0, 0);
408     term_fresh();
409     screen_save();
410     auto err = report_score(current_player_ptr, display_player);
411     screen_load();
412     if (err) {
413         return false;
414     }
415
416     prt(_("完了。何かキーを押してください。", "Completed.  Hit any key."), 0, 0);
417     (void)inkey();
418 #else
419     (void)current_player_ptr;
420     (void)do_send;
421     (void)display_player;
422 #endif
423     return true;
424 }
425
426 /*!
427  * @brief スコアの過去二十位内ランキングを表示する
428  * Enters a players name on a hi-score table, if "legal", and in any
429  * case, displays some relevant portion of the high score list.
430  * @param current_player_ptr スコアに適用するための現在プレイヤークリーチャー参照ポインタ
431  * @return エラーコード
432  * @details
433  * Assumes "signals_ignore_tstp()" has been called.
434  */
435 errr top_twenty(player_type *current_player_ptr)
436 {
437     high_score the_score;
438     char buf[32];
439     (void)WIPE(&the_score, high_score);
440
441     /* Save the version */
442     sprintf(the_score.what, "%u.%u.%u", FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
443
444     /* Calculate and save the points */
445     sprintf(the_score.pts, "%9ld", (long)calc_score(current_player_ptr));
446     the_score.pts[9] = '\0';
447
448     /* Save the current gold */
449     sprintf(the_score.gold, "%9lu", (long)current_player_ptr->au);
450     the_score.gold[9] = '\0';
451
452     /* Save the current turn */
453     sprintf(the_score.turns, "%9lu", (long)turn_real(current_player_ptr, current_world_ptr->game_turn));
454     the_score.turns[9] = '\0';
455
456     time_t ct = time((time_t *)0);
457
458     /* Save the date in standard encoded form (9 chars) */
459     strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct));
460
461     /* Save the player name (15 chars) */
462     sprintf(the_score.who, "%-.15s", current_player_ptr->name);
463
464     /* Save the player info */
465     sprintf(the_score.uid, "%7u", current_player_ptr->player_uid);
466     sprintf(the_score.sex, "%c", (current_player_ptr->psex ? 'm' : 'f'));
467     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->prace, MAX_RACES));
468     memcpy(the_score.p_r, buf, 3);
469     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->pclass, MAX_CLASS));
470     memcpy(the_score.p_c, buf, 3);
471     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->pseikaku, MAX_PERSONALITIES));
472     memcpy(the_score.p_a, buf, 3);
473
474     /* Save the level and such */
475     sprintf(the_score.cur_lev, "%3d", MIN((u16b)current_player_ptr->lev, 999));
476     sprintf(the_score.cur_dun, "%3d", (int)current_player_ptr->current_floor_ptr->dun_level);
477     sprintf(the_score.max_lev, "%3d", MIN((u16b)current_player_ptr->max_plv, 999));
478     sprintf(the_score.max_dun, "%3d", (int)max_dlv[current_player_ptr->dungeon_idx]);
479
480     /* Save the cause of death (31 chars) */
481     if (strlen(current_player_ptr->died_from) >= sizeof(the_score.how)) {
482 #ifdef JP
483         angband_strcpy(the_score.how, current_player_ptr->died_from, sizeof(the_score.how) - 2);
484         strcat(the_score.how, "…");
485 #else
486         angband_strcpy(the_score.how, current_player_ptr->died_from, sizeof(the_score.how) - 3);
487         strcat(the_score.how, "...");
488 #endif
489     } else {
490         strcpy(the_score.how, current_player_ptr->died_from);
491     }
492
493     /* Grab permissions */
494     safe_setuid_grab(current_player_ptr);
495
496     /* Lock (for writing) the highscore file, or fail */
497     errr err = fd_lock(highscore_fd, F_WRLCK);
498
499     /* Drop permissions */
500     safe_setuid_drop();
501
502     if (err)
503         return 1;
504
505     /* Add a new entry to the score list, see where it went */
506     int j = highscore_add(&the_score);
507
508     /* Grab permissions */
509     safe_setuid_grab(current_player_ptr);
510
511     /* Unlock the highscore file, or fail */
512     err = fd_lock(highscore_fd, F_UNLCK);
513
514     /* Drop permissions */
515     safe_setuid_drop();
516
517     if (err)
518         return 1;
519
520     /* Hack -- Display the top fifteen scores */
521     if (j < 10) {
522         display_scores_aux(0, 15, j, NULL);
523         return 0;
524     }
525
526     /* Display the scores surrounding the player */
527     display_scores_aux(0, 5, j, NULL);
528     display_scores_aux(j - 2, j + 7, j, NULL);
529     return 0;
530 }
531
532 /*!
533  * @brief プレイヤーの現在のスコアをランキングに挟む /
534  * Predict the players location, and display it.
535  * @return エラーコード
536  */
537 errr predict_score(player_type *current_player_ptr)
538 {
539     high_score the_score;
540     char buf[32];
541
542     /* No score file */
543     if (highscore_fd < 0) {
544         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
545         msg_print(NULL);
546         return 0;
547     }
548
549     /* Save the version */
550     sprintf(the_score.what, "%u.%u.%u", FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
551
552     /* Calculate and save the points */
553     sprintf(the_score.pts, "%9ld", (long)calc_score(current_player_ptr));
554
555     /* Save the current gold */
556     sprintf(the_score.gold, "%9lu", (long)current_player_ptr->au);
557
558     /* Save the current turn */
559     sprintf(the_score.turns, "%9lu", (long)turn_real(current_player_ptr, current_world_ptr->game_turn));
560
561     /* Hack -- no time needed */
562     strcpy(the_score.day, _("今日", "TODAY"));
563
564     /* Save the player name (15 chars) */
565     sprintf(the_score.who, "%-.15s", current_player_ptr->name);
566
567     /* Save the player info */
568     sprintf(the_score.uid, "%7u", current_player_ptr->player_uid);
569     sprintf(the_score.sex, "%c", (current_player_ptr->psex ? 'm' : 'f'));
570     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->prace, MAX_RACES));
571     memcpy(the_score.p_r, buf, 3);
572     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->pclass, MAX_CLASS));
573     memcpy(the_score.p_c, buf, 3);
574     snprintf(buf, sizeof(buf), "%2d", MIN(current_player_ptr->pseikaku, MAX_PERSONALITIES));
575     memcpy(the_score.p_a, buf, 3);
576
577     /* Save the level and such */
578     sprintf(the_score.cur_lev, "%3d", MIN((u16b)current_player_ptr->lev, 999));
579     sprintf(the_score.cur_dun, "%3d", (int)current_player_ptr->current_floor_ptr->dun_level);
580     sprintf(the_score.max_lev, "%3d", MIN((u16b)current_player_ptr->max_plv, 999));
581     sprintf(the_score.max_dun, "%3d", (int)max_dlv[current_player_ptr->dungeon_idx]);
582
583     /* Hack -- no cause of death */
584     /* まだ死んでいないときの識別文字 */
585     strcpy(the_score.how, _("yet", "nobody (yet!)"));
586
587     /* See where the entry would be placed */
588     int j = highscore_where(&the_score);
589
590     /* Hack -- Display the top fifteen scores */
591     if (j < 10) {
592         display_scores_aux(0, 15, j, &the_score);
593         return 0;
594     }
595
596     display_scores_aux(0, 5, -1, NULL);
597     display_scores_aux(j - 2, j + 7, j, &the_score);
598     return 0;
599 }
600
601 /*!
602  * @brief スコアランキングの簡易表示 /
603  * show_highclass - selectively list highscores based on class -KMW-
604  */
605 void show_highclass(player_type *current_player_ptr)
606 {
607     screen_save();
608     char buf[1024], out_val[256];
609     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
610
611     highscore_fd = fd_open(buf, O_RDONLY);
612
613     if (highscore_fd < 0) {
614         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
615         msg_print(NULL);
616         return;
617     }
618
619     if (highscore_seek(0))
620         return;
621
622     high_score the_score;
623     for (int i = 0; i < MAX_HISCORES; i++)
624         if (highscore_read(&the_score))
625             break;
626
627     int m = 0;
628     int j = 0;
629     PLAYER_LEVEL clev = 0;
630     int pr;
631     while ((m < 9) && (j < MAX_HISCORES)) {
632         if (highscore_seek(j))
633             break;
634         if (highscore_read(&the_score))
635             break;
636         pr = atoi(the_score.p_r);
637         clev = (PLAYER_LEVEL)atoi(the_score.cur_lev);
638
639 #ifdef JP
640         sprintf(out_val, "   %3d) %sの%s (レベル %2d)", (m + 1), race_info[pr].title, the_score.who, clev);
641 #else
642         sprintf(out_val, "%3d) %s the %s (Level %2d)", (m + 1), the_score.who, race_info[pr].title, clev);
643 #endif
644
645         prt(out_val, (m + 7), 0);
646         m++;
647         j++;
648     }
649
650 #ifdef JP
651     sprintf(out_val, "あなた) %sの%s (レベル %2d)", race_info[current_player_ptr->prace].title, current_player_ptr->name, current_player_ptr->lev);
652 #else
653     sprintf(out_val, "You) %s the %s (Level %2d)", current_player_ptr->name, race_info[current_player_ptr->prace].title, current_player_ptr->lev);
654 #endif
655
656     prt(out_val, (m + 8), 0);
657
658     (void)fd_close(highscore_fd);
659     highscore_fd = -1;
660     prt(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"), 0, 0);
661
662     (void)inkey();
663
664     for (j = 5; j < 18; j++)
665         prt("", j, 0);
666     screen_load();
667 }
668
669 /*!
670  * @brief スコアランキングの簡易表示(種族毎)サブルーチン /
671  * Race Legends -KMW-
672  * @param race_num 種族ID
673  */
674 void race_score(player_type *current_player_ptr, int race_num)
675 {
676     int i = 0, j, m = 0;
677     int pr, clev, lastlev;
678     high_score the_score;
679     char buf[1024], out_val[256], tmp_str[80];
680
681     lastlev = 0;
682
683     /* rr9: TODO - pluralize the race */
684     sprintf(tmp_str, _("最高の%s", "The Greatest of all the %s"), race_info[race_num].title);
685
686     prt(tmp_str, 5, 15);
687     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
688
689     highscore_fd = fd_open(buf, O_RDONLY);
690
691     if (highscore_fd < 0) {
692         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
693         msg_print(NULL);
694         return;
695     }
696
697     if (highscore_seek(0))
698         return;
699
700     for (i = 0; i < MAX_HISCORES; i++) {
701         if (highscore_read(&the_score))
702             break;
703     }
704
705     m = 0;
706     j = 0;
707
708     while ((m < 10) || (j < MAX_HISCORES)) {
709         if (highscore_seek(j))
710             break;
711         if (highscore_read(&the_score))
712             break;
713         pr = atoi(the_score.p_r);
714         clev = atoi(the_score.cur_lev);
715
716         if (pr == race_num) {
717 #ifdef JP
718             sprintf(out_val, "   %3d) %sの%s (レベル %2d)", (m + 1), race_info[pr].title, the_score.who, clev);
719 #else
720             sprintf(out_val, "%3d) %s the %s (Level %3d)", (m + 1), the_score.who, race_info[pr].title, clev);
721 #endif
722
723             prt(out_val, (m + 7), 0);
724             m++;
725             lastlev = clev;
726         }
727         j++;
728     }
729
730     /* add player if qualified */
731     if ((current_player_ptr->prace == race_num) && (current_player_ptr->lev >= lastlev)) {
732 #ifdef JP
733         sprintf(out_val, "あなた) %sの%s (レベル %2d)", race_info[current_player_ptr->prace].title, current_player_ptr->name, current_player_ptr->lev);
734 #else
735         sprintf(out_val, "You) %s the %s (Level %3d)", current_player_ptr->name, race_info[current_player_ptr->prace].title, current_player_ptr->lev);
736 #endif
737
738         prt(out_val, (m + 8), 0);
739     }
740
741     (void)fd_close(highscore_fd);
742     highscore_fd = -1;
743 }
744
745 /*!
746  * @brief スコアランキングの簡易表示(種族毎)メインルーチン /
747  * Race Legends -KMW-
748  */
749 void race_legends(player_type *current_player_ptr)
750 {
751     for (int i = 0; i < MAX_RACES; i++) {
752         race_score(current_player_ptr, i);
753         msg_print(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"));
754         msg_print(NULL);
755         for (int j = 5; j < 19; j++)
756             prt("", j, 0);
757     }
758 }
759
760 /*!
761  * @brief スコアファイル出力
762  * Display some character info
763  */
764 bool check_score(player_type *current_player_ptr)
765 {
766     term_clear();
767
768     /* No score file */
769     if (highscore_fd < 0) {
770         msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
771         msg_print(NULL);
772         return FALSE;
773     }
774
775     /* Wizard-mode pre-empts scoring */
776     if (current_world_ptr->noscore & 0x000F) {
777         msg_print(_("ウィザード・モードではスコアが記録されません。", "Score not registered for wizards."));
778         msg_print(NULL);
779         return FALSE;
780     }
781
782     /* Cheaters are not scored */
783     if (current_world_ptr->noscore & 0xFF00) {
784         msg_print(_("詐欺をやった人はスコアが記録されません。", "Score not registered for cheaters."));
785         msg_print(NULL);
786         return FALSE;
787     }
788
789     /* Interupted */
790     if (!current_world_ptr->total_winner && streq(current_player_ptr->died_from, _("強制終了", "Interrupting"))) {
791         msg_print(_("強制終了のためスコアが記録されません。", "Score not registered due to interruption."));
792         msg_print(NULL);
793         return FALSE;
794     }
795
796     /* Quitter */
797     if (!current_world_ptr->total_winner && streq(current_player_ptr->died_from, _("途中終了", "Quitting"))) {
798         msg_print(_("途中終了のためスコアが記録されません。", "Score not registered due to quitting."));
799         msg_print(NULL);
800         return FALSE;
801     }
802     return TRUE;
803 }