OSDN Git Service

GF_ICE属性の攻撃に対し、目には目を等の反撃ダメージが発動しないバグを修正。
[hengband/hengband.git] / src / scores.c
index d7d8b46..8b40f21 100644 (file)
@@ -1,15 +1,15 @@
 /* File: scores.c */
 
-/* Purpose: Highscores handling */
-
 /*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  *
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
  */
 
+/* Purpose: Highscores handling */
+
 #include "angband.h"
 
 
@@ -247,7 +247,7 @@ sprintf(tmp_val, "( %d 
                        if ((*when == '@') && strlen(when) == 9)
                        {
                                sprintf(tmp_val, "%.4s-%.2s-%.2s",
-                                       when + 1, when + 5, when + 7);
+                                       when + 1, when + 5, when + 7);
                                when = tmp_val;
                        }
 
@@ -255,18 +255,18 @@ sprintf(tmp_val, "( %d 
 #ifdef JP
 /*sprintf(out_val, "%3d.%9s  %s%s%s¤È¤¤¤¦Ì¾¤Î%s¤Î%s (¥ì¥Ù¥ë %d)", */
                        sprintf(out_val, "%3d.%9s  %s%s%s - %s%s (¥ì¥Ù¥ë %d)",
-                               place, the_score.pts,
-                               seikaku_info[pa].title, (seikaku_info[pa].no ? "¤Î" : ""),
+                               place, the_score.pts,
+                               seikaku_info[pa].title, (seikaku_info[pa].no ? "¤Î" : ""),
                                the_score.who,
                                race_info[pr].title, class_info[pc].title,
-                               clev);
+                               clev);
 
 #else
                        sprintf(out_val, "%3d.%9s  %s %s the %s %s, Level %d",
-                               place, the_score.pts,
+                               place, the_score.pts,
                                seikaku_info[pa].title,
                                the_score.who, race_info[pr].title, class_info[pc].title,
-                               clev);
+                               clev);
 #endif
 
 
@@ -289,13 +289,13 @@ if (mlev > clev) strcat(out_val, format(" (
                                sprintf(out_val, "             ");
 
 
-                        /* »àË´¸¶°ø¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */
-                        if (streq(the_score.how, "yet"))
-                        {
-                                sprintf(out_val+13, "  ¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë (%d%s)",
-                                       cdun, "³¬");
-                        }
-                        else
+                       /* »àË´¸¶°ø¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */
+                       if (streq(the_score.how, "yet"))
+                       {
+                               sprintf(out_val+13, "  ¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë (%d%s)",
+                                      cdun, "³¬");
+                       }
+                       else
                        if (streq(the_score.how, "ripe"))
                        {
                                sprintf(out_val+13, "  ¾¡Íø¤Î¸å¤Ë°úÂà (%d%s)",
@@ -338,23 +338,23 @@ if (mlev > clev) strcat(out_val, format(" (
 
                        /* And still another line of info */
 #ifdef JP
-                        {
-                                char buf[11];
-
-                                /* ÆüÉÕ¤ò 19yy/mm/dd ¤Î·Á¼°¤ËÊѹ¹¤¹¤ë */
-                                if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') {
-                                        sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when);
-                                        when = buf;
-                                }
-                                sprintf(out_val,
-                                                "        (¥æ¡¼¥¶¡¼:%s, ÆüÉÕ:%s, ½ê»ý¶â:%s, ¥¿¡¼¥ó:%s)",
-                                                user, when, gold, aged);
-                        }
+                       {
+                               char buf[11];
+
+                               /* ÆüÉÕ¤ò 19yy/mm/dd ¤Î·Á¼°¤ËÊѹ¹¤¹¤ë */
+                               if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') {
+                                       sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when);
+                                       when = buf;
+                               }
+                               sprintf(out_val,
+                                               "        (¥æ¡¼¥¶¡¼:%s, ÆüÉÕ:%s, ½ê»ý¶â:%s, ¥¿¡¼¥ó:%s)",
+                                               user, when, gold, aged);
+                       }
 
 #else
                        sprintf(out_val,
-                               "               (User %s, Date %s, Gold %s, Turn %s).",
-                               user, when, gold, aged);
+                               "               (User %s, Date %s, Gold %s, Turn %s).",
+                               user, when, gold, aged);
 #endif
 
                        c_put_str(attr, out_val, n*4 + 4, 0);
@@ -388,7 +388,7 @@ void display_scores(int from, int to)
        char buf[1024];
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        /* Open the binary high score file, for reading */
        highscore_fd = fd_open(buf, O_RDONLY);
@@ -422,7 +422,7 @@ if (highscore_fd < 0) quit("
 bool send_world_score(bool do_send)
 {
 #ifdef WORLD_SCORE
-        if(send_score && do_send)
+       if(send_score && do_send)
        {
                if(easy_band)
                {
@@ -461,7 +461,7 @@ bool send_world_score(bool do_send)
                        (void)inkey();
                }
                else return FALSE;
-        }
+       }
 #endif
        return TRUE;
 }
@@ -480,12 +480,14 @@ errr top_twenty(void)
 
        time_t ct = time((time_t*)0);
 
+       errr err;
+
        /* Clear the record */
        (void)WIPE(&the_score, high_score);
 
        /* Save the version */
        sprintf(the_score.what, "%u.%u.%u",
-               FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
+               FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
 
        /* Calculate and save the points */
        sprintf(the_score.pts, "%9ld", (long)total_points());
@@ -526,49 +528,45 @@ errr top_twenty(void)
        sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);
 
        /* Save the cause of death (31 chars) */
-#ifdef JP
-#if 0
+       if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
        {
-               /* 2byte Ê¸»ú¤ò¹Íθ¤·¤Ê¤¬¤é¥³¥Ô¡¼(EUC ¤ò²¾Äê) */
-               int cnt = 0;
-               unsigned char *d = (unsigned char*)p_ptr->died_from;
-               unsigned char *h = (unsigned char*)the_score.how;
-               while(*d && cnt < 31){
-                       if(iskanji(*d)){
-                               if(cnt + 2 > 31) break;
-                               *h++ = *d++;
-                               *h++ = *d++;
-                               cnt += 2;
-                       }else{
-                               if(cnt + 1 > 31) break;
-                               *h++ = *d++;
-                               cnt++;
-                       }
-               }
-               *h = '\0';
-       }
-#endif
-       if (strlen(p_ptr->died_from) >= 39)
-       {
-               mb_strlcpy(the_score.how, p_ptr->died_from, 37+1);
+#ifdef JP
+               my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 2);
                strcat(the_score.how, "¡Ä");
+#else
+               my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3);
+               strcat(the_score.how, "...");
+#endif
        }
        else
+       {
                strcpy(the_score.how, p_ptr->died_from);
+       }
 
-#else
-       sprintf(the_score.how, "%-.31s", p_ptr->died_from);
-#endif
-
+       /* Grab permissions */
+       safe_setuid_grab();
 
        /* Lock (for writing) the highscore file, or fail */
-       if (fd_lock(highscore_fd, F_WRLCK)) return (1);
+       err = fd_lock(highscore_fd, F_WRLCK);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
+       if (err) return (1);
 
        /* Add a new entry to the score list, see where it went */
        j = highscore_add(&the_score);
 
+       /* Grab permissions */
+       safe_setuid_grab();
+
        /* Unlock the highscore file, or fail */
-       if (fd_lock(highscore_fd, F_UNLCK)) return (1);
+       err = fd_lock(highscore_fd, F_UNLCK);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
+       if (err) return (1);
 
 
        /* Hack -- Display the top fifteen scores */
@@ -616,7 +614,7 @@ msg_print("
 
        /* Save the version */
        sprintf(the_score.what, "%u.%u.%u",
-               FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
+               FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
 
        /* Calculate and save the points */
        sprintf(the_score.pts, "%9ld", (long)total_points());
@@ -653,8 +651,8 @@ strcpy(the_score.day, "
 
        /* Hack -- no cause of death */
 #ifdef JP
-        /* ¤Þ¤À»à¤ó¤Ç¤¤¤Ê¤¤¤È¤­¤Î¼±ÊÌʸ»ú */
-        strcpy(the_score.how, "yet");
+       /* ¤Þ¤À»à¤ó¤Ç¤¤¤Ê¤¤¤È¤­¤Î¼±ÊÌʸ»ú */
+       strcpy(the_score.how, "yet");
 #else
        strcpy(the_score.how, "nobody (yet!)");
 #endif
@@ -689,18 +687,18 @@ strcpy(the_score.day, "
  * show_highclass - selectively list highscores based on class
  * -KMW-
  */
-void show_highclass(int building)
+void show_highclass(void)
 {
 
        register int i = 0, j, m = 0;
-       int pr, pc, pa, clev/*, al*/;
+       int pr, clev/*, al*/;
        high_score the_score;
        char buf[1024], out_val[256];
 
        screen_save();
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        highscore_fd = fd_open(buf, O_RDONLY);
 
@@ -730,8 +728,6 @@ msg_print("
                if (highscore_seek(j)) break;
                if (highscore_read(&the_score)) break;
                pr = atoi(the_score.p_r);
-               pc = atoi(the_score.p_c);
-               pa = atoi(the_score.p_a);
                clev = atoi(the_score.cur_lev);
 
 #ifdef JP
@@ -779,7 +775,7 @@ msg_print("
 void race_score(int race_num)
 {
        register int i = 0, j, m = 0;
-       int pr, pc, pa, clev, lastlev;
+       int pr, clev, lastlev;
        high_score the_score;
        char buf[1024], out_val[256], tmp_str[80];
 
@@ -795,7 +791,7 @@ sprintf(tmp_str,"
        prt(tmp_str, 5, 15);
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        highscore_fd = fd_open(buf, O_RDONLY);
 
@@ -826,8 +822,6 @@ msg_print("
                if (highscore_seek(j)) break;
                if (highscore_read(&the_score)) break;
                pr = atoi(the_score.p_r);
-               pc = atoi(the_score.p_c);
-               pa = atoi(the_score.p_a);
                clev = atoi(the_score.cur_lev);
 
                if (pr == race_num)
@@ -897,14 +891,18 @@ msg_print("
  */
 void kingly(void)
 {
+       int wid, hgt;
+       int cx, cy;
+       bool seppuku = streq(p_ptr->died_from, "Seppuku");
+
        /* Hack -- retire in town */
        dun_level = 0;
 
        /* Fake death */
-       if (!streq(p_ptr->died_from, "Seppuku"))
+       if (!seppuku)
 #ifdef JP
-               /* °úÂष¤¿¤È¤­¤Î¼±ÊÌʸ»ú */
-               (void)strcpy(p_ptr->died_from, "ripe");
+               /* °úÂष¤¿¤È¤­¤Î¼±ÊÌʸ»ú */
+               (void)strcpy(p_ptr->died_from, "ripe");
 #else
                (void)strcpy(p_ptr->died_from, "Ripe Old Age");
 #endif
@@ -916,6 +914,10 @@ void kingly(void)
        /* Restore the level */
        p_ptr->lev = p_ptr->max_plv;
 
+       Term_get_size(&wid, &hgt);
+       cy = hgt / 2;
+       cx = wid / 2;
+
        /* Hack -- Instant Gold */
        p_ptr->au += 10000000L;
 
@@ -923,42 +925,46 @@ void kingly(void)
        Term_clear();
 
        /* Display a crown */
-       put_str("#", 1, 34);
-       put_str("#####", 2, 32);
-       put_str("#", 3, 34);
-       put_str(",,,  $$$  ,,,", 4, 28);
-       put_str(",,=$   \"$$$$$\"   $=,,", 5, 24);
-       put_str(",$$        $$$        $$,", 6, 22);
-       put_str("*>         <*>         <*", 7, 22);
-       put_str("$$         $$$         $$", 8, 22);
-       put_str("\"$$        $$$        $$\"", 9, 22);
-       put_str("\"$$       $$$       $$\"", 10, 23);
-       put_str("*#########*#########*", 11, 24);
-       put_str("*#########*#########*", 12, 24);
+       put_str("#", cy - 11, cx - 1);
+       put_str("#####", cy - 10, cx - 3);
+       put_str("#", cy - 9, cx - 1);
+       put_str(",,,  $$$  ,,,", cy - 8, cx - 7);
+       put_str(",,=$   \"$$$$$\"   $=,,", cy - 7, cx - 11);
+       put_str(",$$        $$$        $$,", cy - 6, cx - 13);
+       put_str("*>         <*>         <*", cy - 5, cx - 13);
+       put_str("$$         $$$         $$", cy - 4, cx - 13);
+       put_str("\"$$        $$$        $$\"", cy - 3, cx - 13);
+       put_str("\"$$       $$$       $$\"", cy - 2, cx - 12);
+       put_str("*#########*#########*", cy - 1, cx - 11);
+       put_str("*#########*#########*", cy, cx - 11);
 
        /* Display a message */
 #ifdef JP
-put_str("Veni, Vidi, Vici!", 15, 26);
-put_str("Í褿¡¢¸«¤¿¡¢¾¡¤Ã¤¿¡ª", 16, 25);
-put_str(format("°ÎÂç¤Ê¤ë%sËüºÐ¡ª", sp_ptr->winner), 17, 22);
+       put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
+       put_str("Í褿¡¢¸«¤¿¡¢¾¡¤Ã¤¿¡ª", cy + 4, cx - 10);
+       put_str(format("°ÎÂç¤Ê¤ë%sËüºÐ¡ª", sp_ptr->winner), cy + 5, cx - 11);
 #else
-       put_str("Veni, Vidi, Vici!", 15, 26);
-       put_str("I came, I saw, I conquered!", 16, 21);
-       put_str(format("All Hail the Mighty %s!", sp_ptr->winner), 17, 22);
+       put_str("Veni, Vidi, Vici!", cy + 3, cx - 9);
+       put_str("I came, I saw, I conquered!", cy + 4, cx - 14);
+       put_str(format("All Hail the Mighty %s!", sp_ptr->winner), cy + 5, cx - 13);
 #endif
 
+       /* If player did Seppuku, that is already written in playrecord */
+       if (!seppuku)
+       {
 #ifdef JP
-       do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥À¥ó¥¸¥ç¥ó¤Îõº÷¤«¤é°úÂष¤¿¡£");
-       do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ¥²¡¼¥à¥ª¡¼¥Ð¡¼ --------");
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥À¥ó¥¸¥ç¥ó¤Îõº÷¤«¤é°úÂष¤¿¡£");
+               do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ¥²¡¼¥à¥ª¡¼¥Ð¡¼ --------");
 #else
-       do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retire exploring dungeons.");
-       do_cmd_write_nikki(NIKKI_GAMESTART, 1, "--------   Game  Over   --------");
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retired exploring dungeons.");
+               do_cmd_write_nikki(NIKKI_GAMESTART, 1, "--------   Game  Over   --------");
 #endif
-       do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
+       }
 
        /* Flush input */
        flush();
 
        /* Wait for response */
-       pause_line(23);
+       pause_line(hgt - 1);
 }