OSDN Git Service

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