OSDN Git Service

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