OSDN Git Service

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