OSDN Git Service

Add Doxygen comment to monster1.c.
[hengband/hengband.git] / src / tmp / scores.c
1 /* File: scores.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.  Other copyrights may also apply.
9  */
10
11 /* Purpose: Highscores handling */
12
13 #include "angband.h"
14
15
16 /*
17  * Seek score 'i' in the highscore file
18  */
19 static int highscore_seek(int i)
20 {
21         /* Seek for the requested record */
22         return (fd_seek(highscore_fd, (huge)(i) * sizeof(high_score)));
23 }
24
25
26 /*
27  * Read one score from the highscore file
28  */
29 static errr highscore_read(high_score *score)
30 {
31         /* Read the record, note failure */
32         return (fd_read(highscore_fd, (char*)(score), sizeof(high_score)));
33 }
34
35
36 /*
37  * Write one score to the highscore file
38  */
39 static int highscore_write(high_score *score)
40 {
41         /* Write the record, note failure */
42         return (fd_write(highscore_fd, (char*)(score), sizeof(high_score)));
43 }
44
45
46 /*
47  * Just determine where a new score *would* be placed
48  * Return the location (0 is best) or -1 on failure
49  */
50 static int highscore_where(high_score *score)
51 {
52         int                     i;
53
54         high_score              the_score;
55         int my_score;
56
57         my_score = atoi(score->pts);
58
59         /* Paranoia -- it may not have opened */
60         if (highscore_fd < 0) return (-1);
61
62         /* Go to the start of the highscore file */
63         if (highscore_seek(0)) return (-1);
64
65         /* Read until we get to a higher score */
66         for (i = 0; i < MAX_HISCORES; i++)
67         {
68                 int old_score;
69                 if (highscore_read(&the_score)) return (i);
70                 old_score = atoi(the_score.pts);
71 /*              if (strcmp(the_score.pts, score->pts) < 0) return (i); */
72                 if (my_score > old_score) return (i);
73         }
74
75         /* The "last" entry is always usable */
76         return (MAX_HISCORES - 1);
77 }
78
79
80 /*
81  * Actually place an entry into the high score file
82  * Return the location (0 is best) or -1 on "failure"
83  */
84 static int highscore_add(high_score *score)
85 {
86         int                     i, slot;
87         bool            done = FALSE;
88
89         high_score              the_score, tmpscore;
90
91
92         /* Paranoia -- it may not have opened */
93         if (highscore_fd < 0) return (-1);
94
95         /* Determine where the score should go */
96         slot = highscore_where(score);
97
98         /* Hack -- Not on the list */
99         if (slot < 0) return (-1);
100
101         /* Hack -- prepare to dump the new score */
102         the_score = (*score);
103
104         /* Slide all the scores down one */
105         for (i = slot; !done && (i < MAX_HISCORES); i++)
106         {
107                 /* Read the old guy, note errors */
108                 if (highscore_seek(i)) return (-1);
109                 if (highscore_read(&tmpscore)) done = TRUE;
110
111                 /* Back up and dump the score we were holding */
112                 if (highscore_seek(i)) return (-1);
113                 if (highscore_write(&the_score)) return (-1);
114
115                 /* Hack -- Save the old score, for the next pass */
116                 the_score = tmpscore;
117         }
118
119         /* Return location used */
120         return (slot);
121 }
122
123
124
125 /*
126  * Display the scores in a given range.
127  * Assumes the high score list is already open.
128  * Only five entries per line, too much info.
129  *
130  * Mega-Hack -- allow "fake" entry at the given position.
131  */
132 void display_scores_aux(int from, int to, int note, high_score *score)
133 {
134         int             i, j, k, n, place;
135         byte attr;
136
137         high_score      the_score;
138
139         char    out_val[256];
140         char    tmp_val[160];
141
142         int wid, hgt, per_screen;
143
144         Term_get_size(&wid, &hgt);
145         per_screen = (hgt - 4) / 4;
146
147         /* Paranoia -- it may not have opened */
148         if (highscore_fd < 0) return;
149
150
151         /* Assume we will show the first 10 */
152         if (from < 0) from = 0;
153         if (to < 0) to = 10;
154         if (to > MAX_HISCORES) to = MAX_HISCORES;
155
156
157         /* Seek to the beginning */
158         if (highscore_seek(0)) return;
159
160         /* Hack -- Count the high scores */
161         for (i = 0; i < MAX_HISCORES; i++)
162         {
163                 if (highscore_read(&the_score)) break;
164         }
165
166         /* Hack -- allow "fake" entry to be last */
167         if ((note == i) && score) i++;
168
169         /* Forget about the last entries */
170         if (i > to) i = to;
171
172
173         /* Show per_screen per page, until "done" */
174         for (k = from, place = k+1; k < i; k += per_screen)
175         {
176                 /* Clear screen */
177                 Term_clear();
178
179                 /* Title */
180 #ifdef JP
181 put_str("                ÊѶòÈÚÅÜ: Í¦¼Ô¤ÎÅÂƲ", 0, 0);
182 #else
183                 put_str("                Hengband Hall of Fame", 0, 0);
184 #endif
185
186
187                 /* Indicate non-top scores */
188                 if (k > 0)
189                 {
190 #ifdef JP
191 sprintf(tmp_val, "( %d °Ì°Ê²¼ )", k + 1);
192 #else
193                         sprintf(tmp_val, "(from position %d)", k + 1);
194 #endif
195
196                         put_str(tmp_val, 0, 40);
197                 }
198
199                 /* Dump per_screen entries */
200                 for (j = k, n = 0; j < i && n < per_screen; place++, j++, n++)
201                 {
202                         int pr, pc, pa, clev, mlev, cdun, mdun;
203
204                         cptr user, gold, when, aged;
205
206
207                         /* Hack -- indicate death in yellow */
208                         attr = (j == note) ? TERM_YELLOW : TERM_WHITE;
209
210
211                         /* Mega-Hack -- insert a "fake" record */
212                         if ((note == j) && score)
213                         {
214                                 the_score = (*score);
215                                 attr = TERM_L_GREEN;
216                                 score = NULL;
217                                 note = -1;
218                                 j--;
219                         }
220
221                         /* Read a normal record */
222                         else
223                         {
224                                 /* Read the proper record */
225                                 if (highscore_seek(j)) break;
226                                 if (highscore_read(&the_score)) break;
227                         }
228
229                         /* Extract the race/class */
230                         pr = atoi(the_score.p_r);
231                         pc = atoi(the_score.p_c);
232                         pa = atoi(the_score.p_a);
233
234                         /* Extract the level info */
235                         clev = atoi(the_score.cur_lev);
236                         mlev = atoi(the_score.max_lev);
237                         cdun = atoi(the_score.cur_dun);
238                         mdun = atoi(the_score.max_dun);
239
240                         /* Hack -- extract the gold and such */
241                         for (user = the_score.uid; iswspace(*user); user++) /* loop */;
242                         for (when = the_score.day; iswspace(*when); when++) /* loop */;
243                         for (gold = the_score.gold; iswspace(*gold); gold++) /* loop */;
244                         for (aged = the_score.turns; iswspace(*aged); aged++) /* loop */;
245
246                         /* Clean up standard encoded form of "when" */
247                         if ((*when == '@') && strlen(when) == 9)
248                         {
249                                 sprintf(tmp_val, "%.4s-%.2s-%.2s",
250                                         when + 1, when + 5, when + 7);
251                                 when = tmp_val;
252                         }
253
254                         /* Dump some info */
255 #ifdef JP
256 /*sprintf(out_val, "%3d.%9s  %s%s%s¤È¤¤¤¦Ì¾¤Î%s¤Î%s (¥ì¥Ù¥ë %d)", */
257                         sprintf(out_val, "%3d.%9s  %s%s%s - %s%s (¥ì¥Ù¥ë %d)",
258                                 place, the_score.pts,
259                                 seikaku_info[pa].title, (seikaku_info[pa].no ? "¤Î" : ""),
260                                 the_score.who,
261                                 race_info[pr].title, class_info[pc].title,
262                                 clev);
263
264 #else
265                         sprintf(out_val, "%3d.%9s  %s %s the %s %s, Level %d",
266                                 place, the_score.pts,
267                                 seikaku_info[pa].title,
268                                 the_score.who, race_info[pr].title, class_info[pc].title,
269                                 clev);
270 #endif
271
272
273                         /* Append a "maximum level" */
274 #ifdef JP
275 if (mlev > clev) strcat(out_val, format(" (ºÇ¹â%d)", mlev));
276 #else
277                         if (mlev > clev) strcat(out_val, format(" (Max %d)", mlev));
278 #endif
279
280
281                         /* Dump the first line */
282                         c_put_str(attr, out_val, n*4 + 2, 0);
283
284                         /* Another line of info */
285 #ifdef JP
286                         if (mdun != 0)
287                                 sprintf(out_val, "    ºÇ¹â%3d³¬", mdun);
288                         else
289                                 sprintf(out_val, "             ");
290
291
292                         /* »àË´¸¶°ø¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */
293                         if (streq(the_score.how, "yet"))
294                         {
295                                 sprintf(out_val+13, "  ¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë (%d%s)",
296                                        cdun, "³¬");
297                         }
298                         else
299                         if (streq(the_score.how, "ripe"))
300                         {
301                                 sprintf(out_val+13, "  ¾¡Íø¤Î¸å¤Ë°úÂà (%d%s)",
302                                         cdun, "³¬");
303                         }
304                         else if (streq(the_score.how, "Seppuku"))
305                         {
306                                 sprintf(out_val+13, "  ¾¡Íø¤Î¸å¤ËÀÚÊ¢ (%d%s)",
307                                         cdun, "³¬");
308                         }
309                         else
310                         {
311                                 codeconv(the_score.how);
312
313                                 /* Some people die outside of the dungeon */
314                                 if (!cdun)
315                                         sprintf(out_val+13, "  ÃϾå¤Ç%s¤Ë»¦¤µ¤ì¤¿", the_score.how);
316                                 else
317                                         sprintf(out_val+13, "  %d³¬¤Ç%s¤Ë»¦¤µ¤ì¤¿",
318                                                 cdun, the_score.how);
319                         }
320
321 #else
322                         /* Some people die outside of the dungeon */
323                         if (!cdun)
324                                 sprintf(out_val, 
325                                         "               Killed by %s on the surface",
326                                         the_score.how);
327                         else
328                                 sprintf(out_val, 
329                                         "               Killed by %s on %s %d",
330                                         the_score.how, "Dungeon Level", cdun);
331
332                         /* Append a "maximum level" */
333                         if (mdun > cdun) strcat(out_val, format(" (Max %d)", mdun));
334 #endif
335
336                         /* Dump the info */
337                         c_put_str(attr, out_val, n*4 + 3, 0);
338
339                         /* And still another line of info */
340 #ifdef JP
341                         {
342                                 char buf[11];
343
344                                 /* ÆüÉÕ¤ò 19yy/mm/dd ¤Î·Á¼°¤ËÊѹ¹¤¹¤ë */
345                                 if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') {
346                                         sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when);
347                                         when = buf;
348                                 }
349                                 sprintf(out_val,
350                                                 "        (¥æ¡¼¥¶¡¼:%s, ÆüÉÕ:%s, ½ê»ý¶â:%s, ¥¿¡¼¥ó:%s)",
351                                                 user, when, gold, aged);
352                         }
353
354 #else
355                         sprintf(out_val,
356                                 "               (User %s, Date %s, Gold %s, Turn %s).",
357                                 user, when, gold, aged);
358 #endif
359
360                         c_put_str(attr, out_val, n*4 + 4, 0);
361                 }
362
363
364                 /* Wait for response */
365 #ifdef JP
366 prt("[ ESC¤ÇÃæÃÇ, ¤½¤Î¾¤Î¥­¡¼¤Ç³¤±¤Þ¤¹ ]", hgt - 1, 21);
367 #else
368                 prt("[Press ESC to quit, any other key to continue.]", hgt - 1, 17);
369 #endif
370
371                 j = inkey();
372                 prt("", hgt - 1, 0);
373
374                 /* Hack -- notice Escape */
375                 if (j == ESCAPE) break;
376         }
377 }
378
379
380 /*
381  * Hack -- Display the scores in a given range and quit.
382  *
383  * This function is only called from "main.c" when the user asks
384  * to see the "high scores".
385  */
386 void display_scores(int from, int to)
387 {
388         char buf[1024];
389
390         /* Build the filename */
391         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
392
393         /* Open the binary high score file, for reading */
394         highscore_fd = fd_open(buf, O_RDONLY);
395
396         /* Paranoia -- No score file */
397 #ifdef JP
398 if (highscore_fd < 0) quit("¥¹¥³¥¢¡¦¥Õ¥¡¥¤¥ë¤¬»ÈÍѤǤ­¤Þ¤»¤ó¡£");
399 #else
400         if (highscore_fd < 0) quit("Score file unavailable.");
401 #endif
402
403
404         /* Clear screen */
405         Term_clear();
406
407         /* Display the scores */
408         display_scores_aux(from, to, -1, NULL);
409
410         /* Shut the high score file */
411         (void)fd_close(highscore_fd);
412
413         /* Forget the high score fd */
414         highscore_fd = -1;
415
416         /* Quit */
417         quit(NULL);
418 }
419
420
421
422 bool send_world_score(bool do_send)
423 {
424 #ifdef WORLD_SCORE
425         if(send_score && do_send)
426         {
427                 if(easy_band)
428                 {
429 #ifdef JP
430                         msg_print("½é¿´¼Ô¥â¡¼¥É¤Ç¤Ï¥ï¡¼¥ë¥É¥¹¥³¥¢¤ËÅÐÏ¿¤Ç¤­¤Þ¤»¤ó¡£");
431 #else
432                         msg_print("Since you are in the Easy Mode, you cannot send score to world score server.");
433 #endif
434                 }
435 #ifdef JP
436                 else if(get_check_strict("¥¹¥³¥¢¤ò¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤ËÅÐÏ¿¤·¤Þ¤¹¤«? ", (CHECK_NO_ESCAPE | CHECK_NO_HISTORY)))
437 #else
438                 else if(get_check_strict("Do you send score to the world score sever? ", (CHECK_NO_ESCAPE | CHECK_NO_HISTORY)))
439 #endif
440                 {
441                         errr err;
442                         prt("",0,0);
443 #ifdef JP
444                         prt("Á÷¿®Ãæ¡¥¡¥",0,0);
445 #else
446                         prt("Sending...",0,0);
447 #endif
448                         Term_fresh();
449                         screen_save();
450                         err = report_score();
451                         screen_load();
452                         if (err)
453                         {
454                                 return FALSE;
455                         }
456 #ifdef JP
457                         prt("´°Î»¡£²¿¤«¥­¡¼¤ò²¡¤·¤Æ¤¯¤À¤µ¤¤¡£", 0, 0);
458 #else
459                         prt("Completed.  Hit any key.", 0, 0);
460 #endif
461                         (void)inkey();
462                 }
463                 else return FALSE;
464         }
465 #endif
466         return TRUE;
467 }
468
469 /*
470  * Enters a players name on a hi-score table, if "legal", and in any
471  * case, displays some relevant portion of the high score list.
472  *
473  * Assumes "signals_ignore_tstp()" has been called.
474  */
475 errr top_twenty(void)
476 {
477         int          j;
478
479         high_score   the_score;
480
481         time_t ct = time((time_t*)0);
482
483         errr err;
484
485         /* Clear the record */
486         (void)WIPE(&the_score, high_score);
487
488         /* Save the version */
489         sprintf(the_score.what, "%u.%u.%u",
490                 FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
491
492         /* Calculate and save the points */
493         sprintf(the_score.pts, "%9ld", (long)total_points());
494         the_score.pts[9] = '\0';
495
496         /* Save the current gold */
497         sprintf(the_score.gold, "%9lu", (long)p_ptr->au);
498         the_score.gold[9] = '\0';
499
500         /* Save the current turn */
501         sprintf(the_score.turns, "%9lu", (long)turn_real(turn));
502         the_score.turns[9] = '\0';
503
504 #ifdef HIGHSCORE_DATE_HACK
505         /* Save the date in a hacked up form (9 chars) */
506         (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22);
507 #else
508         /* Save the date in standard form (8 chars) */
509 /*      (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */
510         /* Save the date in standard encoded form (9 chars) */
511         strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct));
512 #endif
513
514         /* Save the player name (15 chars) */
515         sprintf(the_score.who, "%-.15s", player_name);
516
517         /* Save the player info XXX XXX XXX */
518         sprintf(the_score.uid, "%7u", player_uid);
519         sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
520         sprintf(the_score.p_r, "%2d", p_ptr->prace);
521         sprintf(the_score.p_c, "%2d", p_ptr->pclass);
522         sprintf(the_score.p_a, "%2d", p_ptr->pseikaku);
523
524         /* Save the level and such */
525         sprintf(the_score.cur_lev, "%3d", p_ptr->lev);
526         sprintf(the_score.cur_dun, "%3d", dun_level);
527         sprintf(the_score.max_lev, "%3d", p_ptr->max_plv);
528         sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);
529
530         /* Save the cause of death (31 chars) */
531         if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
532         {
533 #ifdef JP
534                 my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 2);
535                 strcat(the_score.how, "¡Ä");
536 #else
537                 my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
538                 strcat(the_score.how, "...");
539 #endif
540         }
541         else
542         {
543                 strcpy(the_score.how, p_ptr->died_from);
544         }
545
546         /* Grab permissions */
547         safe_setuid_grab();
548
549         /* Lock (for writing) the highscore file, or fail */
550         err = fd_lock(highscore_fd, F_WRLCK);
551
552         /* Drop permissions */
553         safe_setuid_drop();
554
555         if (err) return (1);
556
557         /* Add a new entry to the score list, see where it went */
558         j = highscore_add(&the_score);
559
560         /* Grab permissions */
561         safe_setuid_grab();
562
563         /* Unlock the highscore file, or fail */
564         err = fd_lock(highscore_fd, F_UNLCK);
565
566         /* Drop permissions */
567         safe_setuid_drop();
568
569         if (err) return (1);
570
571
572         /* Hack -- Display the top fifteen scores */
573         if (j < 10)
574         {
575                 display_scores_aux(0, 15, j, NULL);
576         }
577
578         /* Display the scores surrounding the player */
579         else
580         {
581                 display_scores_aux(0, 5, j, NULL);
582                 display_scores_aux(j - 2, j + 7, j, NULL);
583         }
584
585
586         /* Success */
587         return (0);
588 }
589
590
591 /*
592  * Predict the players location, and display it.
593  */
594 errr predict_score(void)
595 {
596         int          j;
597
598         high_score   the_score;
599
600
601         /* No score file */
602         if (highscore_fd < 0)
603         {
604 #ifdef JP
605 msg_print("¥¹¥³¥¢¡¦¥Õ¥¡¥¤¥ë¤¬»ÈÍѤǤ­¤Þ¤»¤ó¡£");
606 #else
607                 msg_print("Score file unavailable.");
608 #endif
609
610                 msg_print(NULL);
611                 return (0);
612         }
613
614
615         /* Save the version */
616         sprintf(the_score.what, "%u.%u.%u",
617                 FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
618
619         /* Calculate and save the points */
620         sprintf(the_score.pts, "%9ld", (long)total_points());
621
622         /* Save the current gold */
623         sprintf(the_score.gold, "%9lu", (long)p_ptr->au);
624
625         /* Save the current turn */
626         sprintf(the_score.turns, "%9lu", (long)turn_real(turn));
627
628         /* Hack -- no time needed */
629 #ifdef JP
630 strcpy(the_score.day, "º£Æü");
631 #else
632         strcpy(the_score.day, "TODAY");
633 #endif
634
635
636         /* Save the player name (15 chars) */
637         sprintf(the_score.who, "%-.15s", player_name);
638
639         /* Save the player info XXX XXX XXX */
640         sprintf(the_score.uid, "%7u", player_uid);
641         sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
642         sprintf(the_score.p_r, "%2d", p_ptr->prace);
643         sprintf(the_score.p_c, "%2d", p_ptr->pclass);
644         sprintf(the_score.p_a, "%2d", p_ptr->pseikaku);
645
646         /* Save the level and such */
647         sprintf(the_score.cur_lev, "%3d", p_ptr->lev);
648         sprintf(the_score.cur_dun, "%3d", dun_level);
649         sprintf(the_score.max_lev, "%3d", p_ptr->max_plv);
650         sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);
651
652         /* Hack -- no cause of death */
653 #ifdef JP
654         /* ¤Þ¤À»à¤ó¤Ç¤¤¤Ê¤¤¤È¤­¤Î¼±ÊÌʸ»ú */
655         strcpy(the_score.how, "yet");
656 #else
657         strcpy(the_score.how, "nobody (yet!)");
658 #endif
659
660
661
662         /* See where the entry would be placed */
663         j = highscore_where(&the_score);
664
665
666         /* Hack -- Display the top fifteen scores */
667         if (j < 10)
668         {
669                 display_scores_aux(0, 15, j, &the_score);
670         }
671
672         /* Display some "useful" scores */
673         else
674         {
675                 display_scores_aux(0, 5, -1, NULL);
676                 display_scores_aux(j - 2, j + 7, j, &the_score);
677         }
678
679
680         /* Success */
681         return (0);
682 }
683
684
685
686 /*
687  * show_highclass - selectively list highscores based on class
688  * -KMW-
689  */
690 void show_highclass(void)
691 {
692
693         register int i = 0, j, m = 0;
694         int pr, clev/*, al*/;
695         high_score the_score;
696         char buf[1024], out_val[256];
697
698         screen_save();
699
700         /* Build the filename */
701         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
702
703         highscore_fd = fd_open(buf, O_RDONLY);
704
705         if (highscore_fd < 0)
706         {
707 #ifdef JP
708 msg_print("¥¹¥³¥¢¡¦¥Õ¥¡¥¤¥ë¤¬»ÈÍѤǤ­¤Þ¤»¤ó¡£");
709 #else
710                 msg_print("Score file unavailable.");
711 #endif
712
713                 msg_print(NULL);
714                 return;
715         }
716
717         if (highscore_seek(0)) return;
718
719         for (i = 0; i < MAX_HISCORES; i++)
720                 if (highscore_read(&the_score)) break;
721
722         m = 0;
723         j = 0;
724         clev = 0;
725
726         while ((m < 9) && (j < MAX_HISCORES))
727         {
728                 if (highscore_seek(j)) break;
729                 if (highscore_read(&the_score)) break;
730                 pr = atoi(the_score.p_r);
731                 clev = atoi(the_score.cur_lev);
732
733 #ifdef JP
734                 sprintf(out_val, "   %3d) %s¤Î%s (¥ì¥Ù¥ë %2d)",
735                     (m + 1), race_info[pr].title,the_score.who, clev);
736 #else
737                 sprintf(out_val, "%3d) %s the %s (Level %2d)",
738                     (m + 1), the_score.who, race_info[pr].title, clev);
739 #endif
740
741                 prt(out_val, (m + 7), 0);
742                 m++;
743                 j++;
744         }
745
746 #ifdef JP
747         sprintf(out_val, "¤¢¤Ê¤¿) %s¤Î%s (¥ì¥Ù¥ë %2d)",
748             race_info[p_ptr->prace].title,player_name, p_ptr->lev);
749 #else
750         sprintf(out_val, "You) %s the %s (Level %2d)",
751             player_name, race_info[p_ptr->prace].title, p_ptr->lev);
752 #endif
753
754         prt(out_val, (m + 8), 0);
755
756         (void)fd_close(highscore_fd);
757         highscore_fd = -1;
758 #ifdef JP
759         prt("²¿¤«¥­¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹",0,0);
760 #else
761         prt("Hit any key to continue",0,0);
762 #endif
763
764         (void)inkey();
765
766         for (j = 5; j < 18; j++) prt("", j, 0);
767         screen_load();
768 }
769
770
771 /*
772  * Race Legends
773  * -KMW-
774  */
775 void race_score(int race_num)
776 {
777         register int i = 0, j, m = 0;
778         int pr, clev, lastlev;
779         high_score the_score;
780         char buf[1024], out_val[256], tmp_str[80];
781
782         lastlev = 0;
783
784         /* rr9: TODO - pluralize the race */
785 #ifdef JP
786 sprintf(tmp_str,"ºÇ¹â¤Î%s", race_info[race_num].title);
787 #else
788         sprintf(tmp_str,"The Greatest of all the %s", race_info[race_num].title);
789 #endif
790
791         prt(tmp_str, 5, 15);
792
793         /* Build the filename */
794         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
795
796         highscore_fd = fd_open(buf, O_RDONLY);
797
798         if (highscore_fd < 0)
799         {
800 #ifdef JP
801 msg_print("¥¹¥³¥¢¡¦¥Õ¥¡¥¤¥ë¤¬»ÈÍѤǤ­¤Þ¤»¤ó¡£");
802 #else
803                 msg_print("Score file unavailable.");
804 #endif
805
806                 msg_print(NULL);
807                 return;
808         }
809
810         if (highscore_seek(0)) return;
811
812         for (i = 0; i < MAX_HISCORES; i++)
813         {
814                 if (highscore_read(&the_score)) break;
815         }
816
817         m = 0;
818         j = 0;
819
820         while ((m < 10) || (j < MAX_HISCORES))
821         {
822                 if (highscore_seek(j)) break;
823                 if (highscore_read(&the_score)) break;
824                 pr = atoi(the_score.p_r);
825                 clev = atoi(the_score.cur_lev);
826
827                 if (pr == race_num)
828                 {
829 #ifdef JP
830                 sprintf(out_val, "   %3d) %s¤Î%s (¥ì¥Ù¥ë %2d)",
831                             (m + 1), race_info[pr].title, 
832                                 the_score.who,clev);
833 #else
834                         sprintf(out_val, "%3d) %s the %s (Level %3d)",
835                             (m + 1), the_score.who,
836                         race_info[pr].title, clev);
837 #endif
838
839                         prt(out_val, (m + 7), 0);
840                         m++;
841                         lastlev = clev;
842                 }
843                 j++;
844         }
845
846         /* add player if qualified */
847         if ((p_ptr->prace == race_num) && (p_ptr->lev >= lastlev))
848         {
849 #ifdef JP
850         sprintf(out_val, "¤¢¤Ê¤¿) %s¤Î%s (¥ì¥Ù¥ë %2d)",
851                      race_info[p_ptr->prace].title,player_name, p_ptr->lev);
852 #else
853                 sprintf(out_val, "You) %s the %s (Level %3d)",
854                     player_name, race_info[p_ptr->prace].title, p_ptr->lev);
855 #endif
856
857                 prt(out_val, (m + 8), 0);
858         }
859
860         (void)fd_close(highscore_fd);
861         highscore_fd = -1;
862 }
863
864
865 /*
866  * Race Legends
867  * -KMW-
868  */
869 void race_legends(void)
870 {
871         int i, j;
872
873         for (i = 0; i < MAX_RACES; i++)
874         {
875                 race_score(i);
876 #ifdef JP
877 msg_print("²¿¤«¥­¡¼¤ò²¡¤¹¤È¥²¡¼¥à¤ËÌá¤ê¤Þ¤¹");
878 #else
879                 msg_print("Hit any key to continue");
880 #endif
881
882                 msg_print(NULL);
883                 for (j = 5; j < 19; j++)
884                         prt("", j, 0);
885         }
886 }
887
888
889 /*
890  * Change the player into a King!                       -RAK-
891  */
892 void kingly(void)
893 {
894         int wid, hgt;
895         int cx, cy;
896         bool seppuku = streq(p_ptr->died_from, "Seppuku");
897
898         /* Hack -- retire in town */
899         dun_level = 0;
900
901         /* Fake death */
902         if (!seppuku)
903 #ifdef JP
904                 /* °úÂष¤¿¤È¤­¤Î¼±ÊÌʸ»ú */
905                 (void)strcpy(p_ptr->died_from, "ripe");
906 #else
907                 (void)strcpy(p_ptr->died_from, "Ripe Old Age");
908 #endif
909
910
911         /* Restore the experience */
912         p_ptr->exp = p_ptr->max_exp;
913
914         /* Restore the level */
915         p_ptr->lev = p_ptr->max_plv;
916
917         Term_get_size(&wid, &hgt);
918         cy = hgt / 2;
919         cx = wid / 2;
920
921         /* Hack -- Instant Gold */
922         p_ptr->au += 10000000L;
923
924         /* Clear screen */
925         Term_clear();
926
927         /* Display a crown */
928         put_str("#", cy - 11, cx - 1);
929         put_str("#####", cy - 10, cx - 3);
930         put_str("#", cy - 9, cx - 1);
931         put_str(",,,  $$$  ,,,", cy - 8, cx - 7);
932         put_str(",,=$   \"$$$$$\"   $=,,", cy - 7, cx - 11);
933         put_str(",$$        $$$        $$,", cy - 6, cx - 13);
934         put_str("*>         <*>         <*", cy - 5, cx - 13);
935         put_str("$$         $$$         $$", cy - 4, cx - 13);
936         put_str("\"$$        $$$        $$\"", cy - 3, cx - 13);
937         put_str("\"$$       $$$       $$\"", cy - 2, cx - 12);
938         put_str("*#########*#########*", cy - 1, cx - 11);
939         put_str("*#########*#########*", cy, cx - 11);
940
941         /* Display a message */
942 #ifdef JP
943         put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
944         put_str("Í褿¡¢¸«¤¿¡¢¾¡¤Ã¤¿¡ª", cy + 4, cx - 10);
945         put_str(format("°ÎÂç¤Ê¤ë%sËüºÐ¡ª", sp_ptr->winner), cy + 5, cx - 11);
946 #else
947         put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
948         put_str("I came, I saw, I conquered!", cy + 4, cx - 14);
949         put_str(format("All Hail the Mighty %s!", sp_ptr->winner), cy + 5, cx - 13);
950 #endif
951
952         /* If player did Seppuku, that is already written in playrecord */
953         if (!seppuku)
954         {
955 #ifdef JP
956                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥À¥ó¥¸¥ç¥ó¤Îõº÷¤«¤é°úÂष¤¿¡£");
957                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ¥²¡¼¥à¥ª¡¼¥Ð¡¼ --------");
958 #else
959                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retired exploring dungeons.");
960                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "--------   Game  Over   --------");
961 #endif
962                 do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
963         }
964
965         /* Flush input */
966         flush();
967
968         /* Wait for response */
969         pause_line(hgt - 1);
970 }