OSDN Git Service

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