OSDN Git Service

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