OSDN Git Service

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