OSDN Git Service

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