OSDN Git Service

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