OSDN Git Service

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