OSDN Git Service

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