3 * @brief ハイスコア処理 / Highscores handling
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.
14 #include "player-status.h"
19 * @brief i番目のスコア情報にバッファ位置をシークする / Seek score 'i' in the highscore file
23 static int highscore_seek(int i)
25 /* Seek for the requested record */
26 return (fd_seek(highscore_fd, (huge)(i) * sizeof(high_score)));
31 * @brief 所定ポインタからスコア情報を読み取る / Read one score from the highscore file
32 * @param score スコア情報参照ポインタ
35 static errr highscore_read(high_score *score)
37 /* Read the record, note failure */
38 return (fd_read(highscore_fd, (char*)(score), sizeof(high_score)));
43 * @brief 所定ポインタへスコア情報を書き込む / Write one score to the highscore file
44 * @param score スコア情報参照ポインタ
45 * @return エラーコード(問題がなければ0を返す)
47 static int highscore_write(high_score *score)
49 /* Write the record, note failure */
50 return (fd_write(highscore_fd, (char*)(score), sizeof(high_score)));
54 * @brief スコア情報を全て得るまで繰り返し取得する / Just determine where a new score *would* be placed
55 * @param score スコア情報参照ポインタ
56 * @return 正常ならば(MAX_HISCORES - 1)、問題があれば-1を返す
58 static int highscore_where(high_score *score)
65 my_score = atoi(score->pts);
67 /* Paranoia -- it may not have opened */
68 if (highscore_fd < 0) return (-1);
70 /* Go to the start of the highscore file */
71 if (highscore_seek(0)) return (-1);
73 /* Read until we get to a higher score */
74 for (i = 0; i < MAX_HISCORES; i++)
77 if (highscore_read(&the_score)) return (i);
78 old_score = atoi(the_score.pts);
79 /* if (strcmp(the_score.pts, score->pts) < 0) return (i); */
80 if (my_score > old_score) return (i);
83 /* The "last" entry is always usable */
84 return (MAX_HISCORES - 1);
89 * @brief スコア情報をバッファの末尾に追加する / Actually place an entry into the high score file
90 * @param score スコア情報参照ポインタ
91 * @return 正常ならば書き込んだスロット位置、問題があれば-1を返す / Return the location (0 is best) or -1 on "failure"
93 static int highscore_add(high_score *score)
98 high_score the_score, tmpscore;
101 /* Paranoia -- it may not have opened */
102 if (highscore_fd < 0) return (-1);
104 /* Determine where the score should go */
105 slot = highscore_where(score);
107 /* Hack -- Not on the list */
108 if (slot < 0) return (-1);
110 /* Hack -- prepare to dump the new score */
111 the_score = (*score);
113 /* Slide all the scores down one */
114 for (i = slot; !done && (i < MAX_HISCORES); i++)
116 /* Read the old guy, note errors */
117 if (highscore_seek(i)) return (-1);
118 if (highscore_read(&tmpscore)) done = TRUE;
120 /* Back up and dump the score we were holding */
121 if (highscore_seek(i)) return (-1);
122 if (highscore_write(&the_score)) return (-1);
124 /* Hack -- Save the old score, for the next pass */
125 the_score = tmpscore;
128 /* Return location used */
135 * @brief 指定された順位範囲でスコアを並べて表示する / Display the scores in a given range.
138 * @param note 黄色表示でハイライトする順位
139 * @param score スコア配列参照ポインタ
143 * Assumes the high score list is already open.
144 * Only five entries per line, too much info.
146 * Mega-Hack -- allow "fake" entry at the given position.
149 void display_scores_aux(int from, int to, int note, high_score *score)
151 int i, j, k, n, place;
154 high_score the_score;
156 GAME_TEXT out_val[256];
157 GAME_TEXT tmp_val[160];
159 TERM_LEN wid, hgt, per_screen;
161 Term_get_size(&wid, &hgt);
162 per_screen = (hgt - 4) / 4;
164 /* Paranoia -- it may not have opened */
165 if (highscore_fd < 0) return;
168 /* Assume we will show the first 10 */
169 if (from < 0) from = 0;
171 if (to > MAX_HISCORES) to = MAX_HISCORES;
174 /* Seek to the beginning */
175 if (highscore_seek(0)) return;
177 /* Hack -- Count the high scores */
178 for (i = 0; i < MAX_HISCORES; i++)
180 if (highscore_read(&the_score)) break;
183 /* Hack -- allow "fake" entry to be last */
184 if ((note == i) && score) i++;
186 /* Forget about the last entries */
190 /* Show per_screen per page, until "done" */
191 for (k = from, place = k+1; k < i; k += per_screen)
196 put_str(_(" 変愚蛮怒: 勇者の殿堂", " Hengband Hall of Fame"), 0, 0);
198 /* Indicate non-top scores */
201 sprintf(tmp_val, _("( %d 位以下 )", "(from position %d)"), k + 1);
202 put_str(tmp_val, 0, 40);
205 /* Dump per_screen entries */
206 for (j = k, n = 0; j < i && n < per_screen; place++, j++, n++)
208 int pr, pc, pa, clev, mlev, cdun, mdun;
210 concptr user, gold, when, aged;
213 /* Hack -- indicate death in yellow */
214 attr = (j == note) ? TERM_YELLOW : TERM_WHITE;
217 /* Mega-Hack -- insert a "fake" record */
218 if ((note == j) && score)
220 the_score = (*score);
227 /* Read a normal record */
230 /* Read the proper record */
231 if (highscore_seek(j)) break;
232 if (highscore_read(&the_score)) break;
235 /* Extract the race/class */
236 pr = atoi(the_score.p_r);
237 pc = atoi(the_score.p_c);
238 pa = atoi(the_score.p_a);
240 /* Extract the level info */
241 clev = atoi(the_score.cur_lev);
242 mlev = atoi(the_score.max_lev);
243 cdun = atoi(the_score.cur_dun);
244 mdun = atoi(the_score.max_dun);
246 /* Hack -- extract the gold and such */
247 for (user = the_score.uid; iswspace(*user); user++) /* loop */;
248 for (when = the_score.day; iswspace(*when); when++) /* loop */;
249 for (gold = the_score.gold; iswspace(*gold); gold++) /* loop */;
250 for (aged = the_score.turns; iswspace(*aged); aged++) /* loop */;
252 /* Clean up standard encoded form of "when" */
253 if ((*when == '@') && strlen(when) == 9)
255 sprintf(tmp_val, "%.4s-%.2s-%.2s",
256 when + 1, when + 5, when + 7);
262 /*sprintf(out_val, "%3d.%9s %s%s%sという名の%sの%s (レベル %d)", */
263 sprintf(out_val, "%3d.%9s %s%s%s - %s%s (レベル %d)",
264 place, the_score.pts,
265 seikaku_info[pa].title, (seikaku_info[pa].no ? "の" : ""),
267 race_info[pr].title, class_info[pc].title,
271 sprintf(out_val, "%3d.%9s %s %s the %s %s, Level %d",
272 place, the_score.pts,
273 seikaku_info[pa].title,
274 the_score.who, race_info[pr].title, class_info[pc].title,
279 /* Append a "maximum level" */
280 if (mlev > clev) strcat(out_val, format(_(" (最高%d)", " (Max %d)"), mlev));
282 /* Dump the first line */
283 c_put_str(attr, out_val, n*4 + 2, 0);
285 /* Another line of info */
288 sprintf(out_val, " 最高%3d階", mdun);
290 sprintf(out_val, " ");
293 /* 死亡原因をオリジナルより細かく表示 */
294 if (streq(the_score.how, "yet"))
296 sprintf(out_val+13, " まだ生きている (%d%s)",
300 if (streq(the_score.how, "ripe"))
302 sprintf(out_val+13, " 勝利の後に引退 (%d%s)",
305 else if (streq(the_score.how, "Seppuku"))
307 sprintf(out_val+13, " 勝利の後に切腹 (%d%s)",
312 codeconv(the_score.how);
314 /* Some people die outside of the dungeon */
316 sprintf(out_val+13, " 地上で%sに殺された", the_score.how);
318 sprintf(out_val+13, " %d階で%sに殺された",
319 cdun, the_score.how);
323 /* Some people die outside of the dungeon */
326 " Killed by %s on the surface",
330 " Killed by %s on %s %d",
331 the_score.how, "Dungeon Level", cdun);
333 /* Append a "maximum level" */
334 if (mdun > cdun) strcat(out_val, format(" (Max %d)", mdun));
338 c_put_str(attr, out_val, n*4 + 3, 0);
340 /* And still another line of info */
345 /* 日付を 19yy/mm/dd の形式に変更する */
346 if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') {
347 sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when);
351 " (ユーザー:%s, 日付:%s, 所持金:%s, ターン:%s)",
352 user, when, gold, aged);
357 " (User %s, Date %s, Gold %s, Turn %s).",
358 user, when, gold, aged);
361 c_put_str(attr, out_val, n*4 + 4, 0);
365 /* Wait for response */
366 prt(_("[ ESCで中断, その他のキーで続けます ]", "[Press ESC to quit, any other key to continue.]"), hgt - 1, _(21, 17));
371 /* Hack -- notice Escape */
372 if (j == ESCAPE) break;
378 * @brief スコア表示処理メインルーチン / Hack -- Display the scores in a given range and quit.
384 * This function is only called from "main.c" when the user asks
385 * to see the "high scores".
388 void display_scores(int from, int to)
392 /* Build the filename */
393 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
395 /* Open the binary high score file, for reading */
396 highscore_fd = fd_open(buf, O_RDONLY);
398 /* Paranoia -- No score file */
399 if (highscore_fd < 0) quit(_("スコア・ファイルが使用できません。", "Score file unavailable."));
402 /* Display the scores */
403 display_scores_aux(from, to, -1, NULL);
405 /* Shut the high score file */
406 (void)fd_close(highscore_fd);
408 /* Forget the high score fd */
417 * @brief スコアサーバへの転送処理
418 * @param do_send 実際に転送ア処置を行うか否か
419 * @return 転送が成功したらTRUEを返す
421 bool send_world_score(bool do_send)
424 if(send_score && do_send)
428 msg_print(_("初心者モードではワールドスコアに登録できません。",
429 "Since you are in the Easy Mode, you cannot send score to world score server."));
431 else if(get_check_strict(_("スコアをスコア・サーバに登録しますか? ", "Do you send score to the world score sever? "),
432 (CHECK_NO_ESCAPE | CHECK_NO_HISTORY)))
436 prt(_("送信中..", "Sending..."),0,0);
439 err = report_score();
445 prt(_("完了。何かキーを押してください。", "Completed. Hit any key."), 0, 0);
455 * @brief スコアの過去二十位内ランキングを表示する
456 * Enters a players name on a hi-score table, if "legal", and in any
457 * case, displays some relevant portion of the high score list.
460 * Assumes "signals_ignore_tstp()" has been called.
462 errr top_twenty(void)
466 high_score the_score;
468 time_t ct = time((time_t*)0);
472 /* Clear the record */
473 (void)WIPE(&the_score, high_score);
475 /* Save the version */
476 sprintf(the_score.what, "%u.%u.%u",
477 FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
479 /* Calculate and save the points */
480 sprintf(the_score.pts, "%9ld", (long)calc_score());
481 the_score.pts[9] = '\0';
483 /* Save the current gold */
484 sprintf(the_score.gold, "%9lu", (long)p_ptr->au);
485 the_score.gold[9] = '\0';
487 /* Save the current current_world_ptr->game_turn */
488 sprintf(the_score.turns, "%9lu", (long)turn_real(current_world_ptr->game_turn));
489 the_score.turns[9] = '\0';
491 #ifdef HIGHSCORE_DATE_HACK
492 /* Save the date in a hacked up form (9 chars) */
493 (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22);
495 /* Save the date in standard form (8 chars) */
496 /* (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */
497 /* Save the date in standard encoded form (9 chars) */
498 strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct));
501 /* Save the player name (15 chars) */
502 sprintf(the_score.who, "%-.15s", p_ptr->name);
504 /* Save the player info */
505 sprintf(the_score.uid, "%7u", player_uid);
506 sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
507 sprintf(the_score.p_r, "%2d", MIN(p_ptr->prace, MAX_RACES));
508 sprintf(the_score.p_c, "%2d", MIN(p_ptr->pclass, MAX_CLASS));
509 sprintf(the_score.p_a, "%2d", MIN(p_ptr->pseikaku, MAX_SEIKAKU));
511 /* Save the level and such */
512 sprintf(the_score.cur_lev, "%3d", MIN((u16b)p_ptr->lev, 999));
513 sprintf(the_score.cur_dun, "%3d", (int)current_floor_ptr->dun_level);
514 sprintf(the_score.max_lev, "%3d", MIN((u16b)p_ptr->max_plv, 999));
515 sprintf(the_score.max_dun, "%3d", (int)max_dlv[p_ptr->dungeon_idx]);
517 /* Save the cause of death (31 chars) */
518 if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
521 my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 2);
522 strcat(the_score.how, "…");
524 my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
525 strcat(the_score.how, "...");
530 strcpy(the_score.how, p_ptr->died_from);
533 /* Grab permissions */
536 /* Lock (for writing) the highscore file, or fail */
537 err = fd_lock(highscore_fd, F_WRLCK);
539 /* Drop permissions */
544 /* Add a new entry to the score list, see where it went */
545 j = highscore_add(&the_score);
547 /* Grab permissions */
550 /* Unlock the highscore file, or fail */
551 err = fd_lock(highscore_fd, F_UNLCK);
553 /* Drop permissions */
559 /* Hack -- Display the top fifteen scores */
562 display_scores_aux(0, 15, j, NULL);
565 /* Display the scores surrounding the player */
568 display_scores_aux(0, 5, j, NULL);
569 display_scores_aux(j - 2, j + 7, j, NULL);
578 * @brief プレイヤーの現在のスコアをランキングに挟む /
579 * Predict the players location, and display it.
582 errr predict_score(void)
586 high_score the_score;
590 if (highscore_fd < 0)
592 msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
598 /* Save the version */
599 sprintf(the_score.what, "%u.%u.%u",
600 FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
602 /* Calculate and save the points */
603 sprintf(the_score.pts, "%9ld", (long)calc_score());
605 /* Save the current gold */
606 sprintf(the_score.gold, "%9lu", (long)p_ptr->au);
608 /* Save the current current_world_ptr->game_turn */
609 sprintf(the_score.turns, "%9lu", (long)turn_real(current_world_ptr->game_turn));
611 /* Hack -- no time needed */
612 strcpy(the_score.day, _("今日", "TODAY"));
614 /* Save the player name (15 chars) */
615 sprintf(the_score.who, "%-.15s", p_ptr->name);
617 /* Save the player info */
618 sprintf(the_score.uid, "%7u", player_uid);
619 sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f'));
620 sprintf(the_score.p_r, "%2d", MIN(p_ptr->prace, MAX_RACES));
621 sprintf(the_score.p_c, "%2d", MIN(p_ptr->pclass, MAX_CLASS));
622 sprintf(the_score.p_a, "%2d", MIN(p_ptr->pseikaku, MAX_SEIKAKU));
624 /* Save the level and such */
625 sprintf(the_score.cur_lev, "%3d", MIN((u16b)p_ptr->lev, 999));
626 sprintf(the_score.cur_dun, "%3d", (int)current_floor_ptr->dun_level);
627 sprintf(the_score.max_lev, "%3d", MIN((u16b)p_ptr->max_plv, 999));
628 sprintf(the_score.max_dun, "%3d", (int)max_dlv[p_ptr->dungeon_idx]);
630 /* Hack -- no cause of death */
631 /* まだ死んでいないときの識別文字 */
632 strcpy(the_score.how, _("yet", "nobody (yet!)"));
634 /* See where the entry would be placed */
635 j = highscore_where(&the_score);
638 /* Hack -- Display the top fifteen scores */
641 display_scores_aux(0, 15, j, &the_score);
644 /* Display some "useful" scores */
647 display_scores_aux(0, 5, -1, NULL);
648 display_scores_aux(j - 2, j + 7, j, &the_score);
658 * @brief スコアランキングの簡易表示 /
659 * show_highclass - selectively list highscores based on class -KMW-
662 void show_highclass(void)
665 register int i = 0, j, m = 0;
667 PLAYER_LEVEL clev/*, al*/;
668 high_score the_score;
669 char buf[1024], out_val[256];
673 /* Build the filename */
674 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
676 highscore_fd = fd_open(buf, O_RDONLY);
678 if (highscore_fd < 0)
680 msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
685 if (highscore_seek(0)) return;
687 for (i = 0; i < MAX_HISCORES; i++)
688 if (highscore_read(&the_score)) break;
694 while ((m < 9) && (j < MAX_HISCORES))
696 if (highscore_seek(j)) break;
697 if (highscore_read(&the_score)) break;
698 pr = atoi(the_score.p_r);
699 clev = (PLAYER_LEVEL)atoi(the_score.cur_lev);
702 sprintf(out_val, " %3d) %sの%s (レベル %2d)",
703 (m + 1), race_info[pr].title,the_score.who, clev);
705 sprintf(out_val, "%3d) %s the %s (Level %2d)",
706 (m + 1), the_score.who, race_info[pr].title, clev);
709 prt(out_val, (m + 7), 0);
715 sprintf(out_val, "あなた) %sの%s (レベル %2d)",
716 race_info[p_ptr->prace].title,p_ptr->name, p_ptr->lev);
718 sprintf(out_val, "You) %s the %s (Level %2d)",
719 p_ptr->name, race_info[p_ptr->prace].title, p_ptr->lev);
722 prt(out_val, (m + 8), 0);
724 (void)fd_close(highscore_fd);
726 prt(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"),0,0);
730 for (j = 5; j < 18; j++) prt("", j, 0);
735 * @brief スコアランキングの簡易表示(種族毎)サブルーチン /
737 * @param race_num 種族ID
740 void race_score(int race_num)
742 register int i = 0, j, m = 0;
743 int pr, clev, lastlev;
744 high_score the_score;
745 char buf[1024], out_val[256], tmp_str[80];
749 /* rr9: TODO - pluralize the race */
750 sprintf(tmp_str,_("最高の%s", "The Greatest of all the %s"), race_info[race_num].title);
754 /* Build the filename */
755 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
757 highscore_fd = fd_open(buf, O_RDONLY);
759 if (highscore_fd < 0)
761 msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
766 if (highscore_seek(0)) return;
768 for (i = 0; i < MAX_HISCORES; i++)
770 if (highscore_read(&the_score)) break;
776 while ((m < 10) || (j < MAX_HISCORES))
778 if (highscore_seek(j)) break;
779 if (highscore_read(&the_score)) break;
780 pr = atoi(the_score.p_r);
781 clev = atoi(the_score.cur_lev);
786 sprintf(out_val, " %3d) %sの%s (レベル %2d)",
787 (m + 1), race_info[pr].title,
790 sprintf(out_val, "%3d) %s the %s (Level %3d)",
791 (m + 1), the_score.who,
792 race_info[pr].title, clev);
795 prt(out_val, (m + 7), 0);
802 /* add player if qualified */
803 if ((p_ptr->prace == race_num) && (p_ptr->lev >= lastlev))
806 sprintf(out_val, "あなた) %sの%s (レベル %2d)",
807 race_info[p_ptr->prace].title,p_ptr->name, p_ptr->lev);
809 sprintf(out_val, "You) %s the %s (Level %3d)",
810 p_ptr->name, race_info[p_ptr->prace].title, p_ptr->lev);
813 prt(out_val, (m + 8), 0);
816 (void)fd_close(highscore_fd);
822 * @brief スコアランキングの簡易表示(種族毎)メインルーチン /
826 void race_legends(void)
830 for (i = 0; i < MAX_RACES; i++)
833 msg_print(_("何かキーを押すとゲームに戻ります", "Hit any key to continue"));
835 for (j = 5; j < 19; j++)
841 * @brief 勝利者用の引退演出処理 /
842 * Change the player into a King! -RAK-
849 bool seppuku = streq(p_ptr->died_from, "Seppuku");
851 /* Hack -- retire in town */
852 current_floor_ptr->dun_level = 0;
857 (void)strcpy(p_ptr->died_from, _("ripe", "Ripe Old Age"));
859 /* Restore the experience */
860 p_ptr->exp = p_ptr->max_exp;
862 /* Restore the level */
863 p_ptr->lev = p_ptr->max_plv;
865 Term_get_size(&wid, &hgt);
869 /* Hack -- Instant Gold */
870 p_ptr->au += 10000000L;
873 /* Display a crown */
874 put_str("#", cy - 11, cx - 1);
875 put_str("#####", cy - 10, cx - 3);
876 put_str("#", cy - 9, cx - 1);
877 put_str(",,, $$$ ,,,", cy - 8, cx - 7);
878 put_str(",,=$ \"$$$$$\" $=,,", cy - 7, cx - 11);
879 put_str(",$$ $$$ $$,", cy - 6, cx - 13);
880 put_str("*> <*> <*", cy - 5, cx - 13);
881 put_str("$$ $$$ $$", cy - 4, cx - 13);
882 put_str("\"$$ $$$ $$\"", cy - 3, cx - 13);
883 put_str("\"$$ $$$ $$\"", cy - 2, cx - 12);
884 put_str("*#########*#########*", cy - 1, cx - 11);
885 put_str("*#########*#########*", cy, cx - 11);
887 /* Display a message */
889 put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
890 put_str("来た、見た、勝った!", cy + 4, cx - 10);
891 put_str(format("偉大なる%s万歳!", sp_ptr->winner), cy + 5, cx - 11);
893 put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
894 put_str("I came, I saw, I conquered!", cy + 4, cx - 14);
895 put_str(format("All Hail the Mighty %s!", sp_ptr->winner), cy + 5, cx - 13);
898 /* If player did Seppuku, that is already written in playrecord */
901 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("ダンジョンの探索から引退した。", "retired exploring dungeons."));
902 do_cmd_write_nikki(NIKKI_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
903 do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
909 /* Wait for response */