OSDN Git Service

branch-nothere-terrainflags、゙。シ・ク.
[hengband/hengband.git] / src / files.c
index e8ee387..a2d45eb 100644 (file)
@@ -417,11 +417,6 @@ errr process_pref_file_command(char *buf)
 
        switch (buf[0])
        {
-       /* Process "%:<fname>" */
-       case '%':
-               /* Attempt to Process the given file */
-               return process_pref_file(buf + 2);
-
        /* Mega-Hack -- read external player's history file */
        /* Process "H:<history>" */
        case 'H':
@@ -438,7 +433,7 @@ errr process_pref_file_command(char *buf)
                        n2 = strtol(zz[2], NULL, 0);
                        if (i >= max_r_idx) return 1;
                        r_ptr = &r_info[i];
-                       if (n1) r_ptr->x_attr = n1;
+                       if (n1 || (!(n2 & 0x80) && n2)) r_ptr->x_attr = n1; /* Allow ATTR_DARK text */
                        if (n2) r_ptr->x_char = n2;
                        return 0;
                }
@@ -454,27 +449,75 @@ errr process_pref_file_command(char *buf)
                        n2 = strtol(zz[2], NULL, 0);
                        if (i >= max_k_idx) return 1;
                        k_ptr = &k_info[i];
-                       if (n1) k_ptr->x_attr = n1;
+                       if (n1 || (!(n2 & 0x80) && n2)) k_ptr->x_attr = n1; /* Allow ATTR_DARK text */
                        if (n2) k_ptr->x_char = n2;
                        return 0;
                }
                break;
 
        /* Process "F:<num>:<a>/<c>" -- attr/char for terrain features */
+       /* "F:<num>:<a>/<c>" */
+       /* "F:<num>:<a>/<c>:LIT" */
+       /* "F:<num>:<a>/<c>:<la>/<lc>:<da>/<dc>:<Da>/<Dc>" */
        case 'F':
-               if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
                        feature_type *f_ptr;
+                       int num = tokenize(buf + 2, 9, zz, TOKENIZE_CHECKQUOTE);
+
+                       if ((num != 3) && (num != 4) && (num != 9)) return 1;
+                       else if ((num == 4) && !streq(zz[3], "LIT")) return 1;
+
                        i = (huge)strtol(zz[0], NULL, 0);
-                       n1 = strtol(zz[1], NULL, 0);
-                       n2 = strtol(zz[2], NULL, 0);
                        if (i >= max_f_idx) return 1;
                        f_ptr = &f_info[i];
-                       if (n1) f_ptr->x_attr = n1;
-                       if (n2) f_ptr->x_char = n2;
-                       return 0;
+
+                       n1 = strtol(zz[1], NULL, 0);
+                       n2 = strtol(zz[2], NULL, 0);
+                       if (n1 || (!(n2 & 0x80) && n2)) /* Allow ATTR_DARK text */
+                       {
+                               for (j = 0; j < F_LIT_MAX; j++) f_ptr->x_attr[j] = n1;
+                       }
+                       if (n2)
+                       {
+                               for (j = 0; j < F_LIT_MAX; j++) f_ptr->x_char[j] = n2;
+                       }
+
+                       /* Mega-hack -- feat supports lighting */
+                       switch (num)
+                       {
+                       /* No lighting support */
+                       case 3:
+                               break;
+
+                       /* Use default lighting */
+                       case 4:
+                               if (is_ascii_graphics(f_ptr->x_attr[F_LIT_STANDARD]))
+                               {
+                                       f_ptr->x_attr[F_LIT_LITE] = lighting_colours[f_ptr->x_attr[F_LIT_STANDARD]][0];
+                                       f_ptr->x_attr[F_LIT_DARK] = lighting_colours[f_ptr->x_attr[F_LIT_STANDARD]][1];
+                                       f_ptr->x_attr[F_LIT_DARKDARK] = lighting_colours[lighting_colours[f_ptr->x_attr[F_LIT_STANDARD]][1]][1];
+                               }
+                               else
+                               {
+                                       f_ptr->x_char[F_LIT_LITE] += 2;
+                                       f_ptr->x_char[F_LIT_DARK]++;
+                                       f_ptr->x_char[F_LIT_DARKDARK]++;
+                               }
+                               break;
+
+                       /* Use desired lighting */
+                       case 9:
+                               for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
+                               {
+                                       n1 = strtol(zz[j * 2 + 1], NULL, 0);
+                                       n2 = strtol(zz[j * 2 + 2], NULL, 0);
+                                       if (n1 || (!(n2 & 0x80) && n2)) f_ptr->x_attr[j] = n1; /* Allow ATTR_DARK text */
+                                       if (n2) f_ptr->x_char[j] = n2;
+                               }
+                               break;
+                       }
                }
-               break;
+               return 0;
 
        /* Process "S:<num>:<a>/<c>" -- attr/char for special things */
        case 'S':
@@ -624,7 +667,7 @@ errr process_pref_file_command(char *buf)
        case 'Z':
        {
                /* Find the colon */
-               char *t = strchr(buf + 2, ':');
+               char *t = my_strchr(buf + 2, ':');
 
                /* Oops */
                if (!t) return 1;
@@ -853,16 +896,15 @@ cptr process_pref_file_expr(cptr *sp, char *fp)
                /* Function: EQU */
                else if (streq(t, "EQU"))
                {
-                       v = "1";
+                       v = "0";
                        if (*s && (f != b2))
                        {
                                t = process_pref_file_expr(&s, &f);
                        }
                        while (*s && (f != b2))
                        {
-                               p = t;
-                               t = process_pref_file_expr(&s, &f);
-                               if (*t && !streq(p, t)) v = "0";
+                               p = process_pref_file_expr(&s, &f);
+                               if (streq(t, p)) v = "1";
                        }
                }
 
@@ -878,7 +920,7 @@ cptr process_pref_file_expr(cptr *sp, char *fp)
                        {
                                p = t;
                                t = process_pref_file_expr(&s, &f);
-                               if (*t && (strcmp(p, t) > 0)) v = "0";
+                               if (*t && atoi(p) > atoi(t)) v = "0";
                        }
                }
 
@@ -894,7 +936,9 @@ cptr process_pref_file_expr(cptr *sp, char *fp)
                        {
                                p = t;
                                t = process_pref_file_expr(&s, &f);
-                               if (*t && (strcmp(p, t) < 0)) v = "0";
+
+                               /* Compare two numbers instead of string */
+                               if (*t && atoi(p) < atoi(t)) v = "0";
                        }
                }
 
@@ -921,7 +965,7 @@ cptr process_pref_file_expr(cptr *sp, char *fp)
                int i;
 
                /* Accept all printables except spaces and brackets */
-               for (i = 0; isprint(*s) && !strchr(" []", *s); i++)
+               for (i = 0; isprint(*s) && !my_strchr(" []", *s); i++)
                        b[i] = *s++;
 
                /* Terminate */
@@ -1041,7 +1085,7 @@ cptr process_pref_file_expr(cptr *sp, char *fp)
 
 
 #define PREF_TYPE_NORMAL   0
-#define PREF_TYPE_PICKPREF 1
+#define PREF_TYPE_AUTOPICK 1
 #define PREF_TYPE_HISTPREF 2
 
 /*
@@ -1118,11 +1162,19 @@ static errr process_pref_file_aux(cptr name, int preftype)
                /* Process "%:<file>" */
                if (buf[0] == '%')
                {
+                       static int depth_count = 0;
+
+                       /* Ignore if deeper than 20 level */
+                       if (depth_count > 20) continue;
+
+                       /* Count depth level */
+                       depth_count++;
+
                        /* Process that file if allowed */
                        switch (preftype)
                        {
-                       case PREF_TYPE_PICKPREF:
-                               (void)process_pickpref_file(buf + 2);
+                       case PREF_TYPE_AUTOPICK:
+                               (void)process_autopick_file(buf + 2);
                                break;
                        case PREF_TYPE_HISTPREF:
                                (void)process_histpref_file(buf + 2);
@@ -1132,6 +1184,9 @@ static errr process_pref_file_aux(cptr name, int preftype)
                                break;
                        }
 
+                       /* Set back depth level */
+                       depth_count--;
+
                        /* Continue */
                        continue;
                }
@@ -1143,9 +1198,9 @@ static errr process_pref_file_aux(cptr name, int preftype)
                /* This is not original pref line... */
                if (err)
                {
-                       if (preftype != PREF_TYPE_PICKPREF)
+                       if (preftype != PREF_TYPE_AUTOPICK)
                                break;
-                       err = process_pickpref_file_line(buf);
+                       err = process_autopick_file_command(buf);
                }
        }
 
@@ -2318,7 +2373,7 @@ static void player_flags(u32b flgs[TR_FLAG_SIZE])
                add_flag(flgs, TR_RES_LITE);
                break;
        case RACE_HOBBIT:
-               add_flag(flgs, TR_SUST_DEX);
+               add_flag(flgs, TR_HOLD_LIFE);
                break;
        case RACE_GNOME:
                add_flag(flgs, TR_FREE_ACT);
@@ -3926,27 +3981,15 @@ void display_player(int mode)
 }
 
 
-errr make_character_dump(FILE *fff)
+/*
+ *
+ */
+static void dump_aux_display_player(FILE *fff)
 {
-       int             i, x, y;
-       byte            a;
-       char            c;
-       cptr            paren = ")";
-       store_type  *st_ptr;
-       char            o_name[MAX_NLEN];
+       int x, y, i;
+       byte a;
+       char c;
        char            buf[1024];
-       int             *quest_num;
-       int             dummy;
-
-#ifdef JP
-       fprintf(fff, "  [ÊѶòÈÚÅÜ %d.%d.%d ¥­¥ã¥é¥¯¥¿¾ðÊó]\n\n",
-               FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
-#else
-       fprintf(fff, "  [Hengband %d.%d.%d Character Dump]\n\n",
-               FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
-#endif
-
-       update_playtime();
 
        /* Display player */
        display_player(0);
@@ -4072,47 +4115,59 @@ errr make_character_dump(FILE *fff)
        fprintf(fff, "\n");
        for (i = 0; (unsigned int) i < (p_ptr->count % 80); i++)
                fprintf(fff, " ");
+}
+
 
+/*
+ *
+ */
+static void dump_aux_pet(FILE *fff)
+{
+       int i;
+       bool pet = FALSE;
+       char pet_name[80];
+
+       for (i = m_max - 1; i >= 1; i--)
        {
-               bool pet = FALSE;
-               char pet_name[80];
+               monster_type *m_ptr = &m_list[i];
 
-               for (i = m_max - 1; i >= 1; i--)
+               if (!m_ptr->r_idx) continue;
+               if (!is_pet(m_ptr)) continue;
+               if (!m_ptr->nickname && (p_ptr->riding != i)) continue;
+               if (!pet)
                {
-                       monster_type *m_ptr = &m_list[i];
-
-                       if (!m_ptr->r_idx) continue;
-                       if (!is_pet(m_ptr)) continue;
-                       if (!m_ptr->nickname && (p_ptr->riding != i)) continue;
-                       if (!pet)
-                       {
 #ifdef JP
-                               fprintf(fff, "\n  [¼ç¤Ê¥Ú¥Ã¥È]\n\n");
+                       fprintf(fff, "\n  [¼ç¤Ê¥Ú¥Ã¥È]\n\n");
 #else
-                               fprintf(fff, "\n  [leading pets]\n\n");
+                       fprintf(fff, "\n  [leading pets]\n\n");
 #endif
-                               pet = TRUE;
-                       }
-                       monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
-                       fprintf(fff, "%s\n", pet_name);
+                       pet = TRUE;
                }
-
-               if (pet) fprintf(fff, "\n");
+               monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
+               fprintf(fff, "%s\n", pet_name);
        }
 
+       if (pet) fprintf(fff, "\n");
+}
 
-       if (p_ptr->pclass == CLASS_BLUE_MAGE) {
 
-               int             i = 0;
-               int                 j = 0;
-               int                             l1 = 0;
-               int                             l2 = 0;
-               int             num = 0;
-               int             spellnum[MAX_MONSPELLS];
-               s32b            f4 = 0, f5 = 0, f6 = 0;
-               char                    p[60][80];
-               int                             col = 0;
-               bool                    pcol = FALSE;
+/*
+ *
+ */
+static void dump_aux_class_special(FILE *fff)
+{
+       if (p_ptr->pclass == CLASS_BLUE_MAGE)
+       {
+               int i = 0;
+               int j = 0;
+               int l1 = 0;
+               int l2 = 0;
+               int num = 0;
+               int spellnum[MAX_MONSPELLS];
+               s32b f4 = 0, f5 = 0, f6 = 0;
+               char p[60][80];
+               int col = 0;
+               bool pcol = FALSE;
 
                for (i=0;i<60;i++) { p[i][0] = '\0'; }
 
@@ -4234,14 +4289,23 @@ errr make_character_dump(FILE *fff)
                        fprintf(fff, p[i]);
                }
        }
+}
 
-       fprintf(fff, "\n");
+
+/*
+ *
+ */
+static void dump_aux_quest(FILE *fff)
+{
+       int i;
+       int *quest_num;
+       int dummy;
 
 
 #ifdef JP
-       fprintf(fff, "\n  [¥¯¥¨¥¹¥È¾ðÊó]\n");
+       fprintf(fff, "\n\n  [¥¯¥¨¥¹¥È¾ðÊó]\n");
 #else
-       fprintf(fff, "\n  [Quest information]\n");
+       fprintf(fff, "\n\n  [Quest information]\n");
 #endif
 
        /* Allocate Memory */
@@ -4261,11 +4325,20 @@ errr make_character_dump(FILE *fff)
 
        /* Free Memory */
        C_KILL(quest_num, max_quests, int);
+}
 
+
+/*
+ *
+ */
+static void dump_aux_last_message(FILE *fff)
+{
        if (p_ptr->is_dead)
        {
                if (!p_ptr->total_winner)
                {
+                       int i;
+
 #ifdef JP
                        fprintf(fff, "\n  [»à¤ÌľÁ°¤Î¥á¥Ã¥»¡¼¥¸]\n\n");
 #else
@@ -4289,18 +4362,22 @@ errr make_character_dump(FILE *fff)
                        fprintf(fff,"  %s\n", p_ptr->last_message);
                }
        }
+}
 
-#ifdef JP
-       fprintf(fff, "\n  [¤½¤Î¾¤Î¾ðÊó]\n");
-#else
-       fprintf(fff, "\n  [Miscellaneous information]\n");
-#endif
+
+/*
+ *
+ */
+static void dump_aux_recall(FILE *fff)
+{
+       int y;
 
 #ifdef JP
-       fprintf(fff, "\n µ¢´Ô¾ì½ê:\n");
+       fprintf(fff, "\n\n  [µ¢´Ô¾ì½ê]\n\n");
 #else
-       fprintf(fff, "\n Recall Depth:\n");
+       fprintf(fff, "\n\n  [Recall Depth]\n\n");
 #endif
+
        for (y = 1; y < max_d_idx; y++)
        {
                bool seiha = FALSE;
@@ -4319,41 +4396,33 @@ errr make_character_dump(FILE *fff)
                fprintf(fff, "   %c%-16s: level %3d\n", seiha ? '!' : ' ', d_name+d_info[y].name, max_dlv[y]);
 #endif
        }
+}
 
-       if (preserve_mode)
-#ifdef JP
-               fprintf(fff, "\n Êݸ¥â¡¼¥É:         ON");
-#else
-               fprintf(fff, "\n Preserve Mode:      ON");
-#endif
 
-       else
+/*
+ *
+ */
+static void dump_aux_options(FILE *fff)
+{
 #ifdef JP
-               fprintf(fff, "\n Êݸ¥â¡¼¥É:         OFF");
+       fprintf(fff, "\n  [¥ª¥×¥·¥ç¥óÀßÄê]\n");
 #else
-               fprintf(fff, "\n Preserve Mode:      OFF");
+       fprintf(fff, "\n  [Option settings]\n");
 #endif
 
 
-       if (ironman_autoscum)
-#ifdef JP
-               fprintf(fff, "\n ¼«Æ°Áª¤ê¹¥¤ß:       ALWAYS");
-#else
-               fprintf(fff, "\n Autoscum:           ALWAYS");
-#endif
-
-       else if (auto_scum)
+       if (preserve_mode)
 #ifdef JP
-               fprintf(fff, "\n ¼«Æ°Áª¤ê¹¥¤ß:       ON");
+               fprintf(fff, "\n Êݸ¥â¡¼¥É:         ON");
 #else
-               fprintf(fff, "\n Autoscum:           ON");
+               fprintf(fff, "\n Preserve Mode:      ON");
 #endif
 
        else
 #ifdef JP
-               fprintf(fff, "\n ¼«Æ°Áª¤ê¹¥¤ß:       OFF");
+               fprintf(fff, "\n Êݸ¥â¡¼¥É:         OFF");
 #else
-               fprintf(fff, "\n Autoscum:           OFF");
+               fprintf(fff, "\n Preserve Mode:      OFF");
 #endif
 
 
@@ -4455,127 +4524,204 @@ errr make_character_dump(FILE *fff)
 #endif
 
 
+       fprintf(fff,"\n");
+
+       if (p_ptr->noscore)
 #ifdef JP
-       fprintf(fff, "\n ¥é¥ó¥À¥à¥¯¥¨¥¹¥È¿ô: %d", number_of_quests());
+               fprintf(fff, "\n ²¿¤«ÉÔÀµ¤Ê¤³¤È¤ò¤·¤Æ¤·¤Þ¤Ã¤Æ¤¤¤Þ¤¹¡£");
 #else
-       fprintf(fff, "\n Num. Random Quests: %d", number_of_quests());
+               fprintf(fff, "\n You have done something illegal.");
 #endif
 
-       fprintf(fff, "\n");
+       fprintf(fff,"\n");
+}
+
 
-       if (!lite_town && !vanilla_town)
+/*
+ *
+ */
+static void dump_aux_arena(FILE *fff)
+{
+       if (lite_town || vanilla_town) return;
+
+       if (p_ptr->arena_number < 0)
        {
-               if (p_ptr->arena_number < 0)
+               if (p_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
                {
-                       if (p_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
-                       {
-#ifdef JP
-                               fprintf(fff, "\n Æ®µ»¾ì: ÇÔËÌ\n");
-#else
-                               fprintf(fff, "\n Arena: Defeated\n");
-#endif
-                       }
-                       else
-                       {
 #ifdef JP
-                               fprintf(fff, "\n Æ®µ»¾ì: %d²óÀï¤Ç%s¤ÎÁ°¤ËÇÔËÌ\n", -p_ptr->arena_number,
-                                       r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name);
+                       fprintf(fff, "\n Æ®µ»¾ì: ÇÔËÌ\n");
 #else
-                               fprintf(fff, "\n Arena: Defeated by %s in the %d%s fight\n",
-                                       r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name,
-                                       -p_ptr->arena_number, get_ordinal_number_suffix(-p_ptr->arena_number));
+                       fprintf(fff, "\n Arena: Defeated\n");
 #endif
-                       }
                }
-               else if (p_ptr->arena_number > MAX_ARENA_MONS + 2)
+               else
                {
 #ifdef JP
-                       fprintf(fff, "\n Æ®µ»¾ì: ¿¿¤Î¥Á¥ã¥ó¥Ô¥ª¥ó\n");
+                       fprintf(fff, "\n Æ®µ»¾ì: %d²óÀï¤Ç%s¤ÎÁ°¤ËÇÔËÌ\n", -p_ptr->arena_number,
+                               r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name);
 #else
-                       fprintf(fff, "\n Arena: True Champion\n");
+                       fprintf(fff, "\n Arena: Defeated by %s in the %d%s fight\n",
+                               r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name,
+                               -p_ptr->arena_number, get_ordinal_number_suffix(-p_ptr->arena_number));
 #endif
                }
-               else if (p_ptr->arena_number > MAX_ARENA_MONS - 1)
-               {
+       }
+       else if (p_ptr->arena_number > MAX_ARENA_MONS + 2)
+       {
 #ifdef JP
-                       fprintf(fff, "\n Æ®µ»¾ì: ¥Á¥ã¥ó¥Ô¥ª¥ó\n");
+               fprintf(fff, "\n Æ®µ»¾ì: ¿¿¤Î¥Á¥ã¥ó¥Ô¥ª¥ó\n");
 #else
-                       fprintf(fff, "\n Arena: Champion\n");
+               fprintf(fff, "\n Arena: True Champion\n");
 #endif
-               }
-               else
-               {
+       }
+       else if (p_ptr->arena_number > MAX_ARENA_MONS - 1)
+       {
 #ifdef JP
-                       fprintf(fff, "\n Æ®µ»¾ì: %2d¾¡\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
+               fprintf(fff, "\n Æ®µ»¾ì: ¥Á¥ã¥ó¥Ô¥ª¥ó\n");
 #else
-                       fprintf(fff, "\n Arena: %2d Victor%s\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number), (p_ptr->arena_number > 1) ? "ies" : "y");
+               fprintf(fff, "\n Arena: Champion\n");
 #endif
-               }
        }
-
-       if (p_ptr->noscore)
+       else
+       {
 #ifdef JP
-               fprintf(fff, "\n ²¿¤«ÉÔÀµ¤Ê¤³¤È¤ò¤·¤Æ¤·¤Þ¤Ã¤Æ¤Þ¤¹¡£");
+               fprintf(fff, "\n Æ®µ»¾ì: %2d¾¡\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
 #else
-               fprintf(fff, "\n You have done something illegal.");
+               fprintf(fff, "\n Arena: %2d Victor%s\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number), (p_ptr->arena_number > 1) ? "ies" : "y");
 #endif
+       }
 
+       fprintf(fff, "\n");
+}
 
-       fprintf(fff,"\n");
 
+/*
+ *
+ */
+static void dump_aux_monsters(FILE *fff)
+{
        /* Monsters slain */
+
+       int k;
+       unsigned long uniq_total = 0;
+       unsigned long norm_total = 0;
+       s16b *who;
+
+       /* Sort by monster level */
+       u16b why = 2;
+
+#ifdef JP
+       fprintf(fff, "\n  [Åݤ·¤¿¥â¥ó¥¹¥¿¡¼]\n\n");
+#else
+       fprintf(fff, "\n  [Defeated monsters]\n\n");
+#endif
+
+       /* Allocate the "who" array */
+       C_MAKE(who, max_r_idx, s16b);
+
+       /* Count monster kills */
+       for (k = 1; k < max_r_idx; k++)
        {
-               int k;
-               s32b Total = 0;
+               monster_race *r_ptr = &r_info[k];
 
-               for (k = 1; k < max_r_idx; k++)
-               {
-                       monster_race *r_ptr = &r_info[k];
+               /* Ignore unused index */
+               if (!r_ptr->name) continue;
 
-                       if (r_ptr->flags1 & RF1_UNIQUE)
+               /* Unique monsters */
+               if (r_ptr->flags1 & RF1_UNIQUE)
+               {
+                       bool dead = (r_ptr->max_num == 0);
+                       if (dead)
                        {
-                               bool dead = (r_ptr->max_num == 0);
-                               if (dead)
-                               {
-                                       Total++;
-                               }
+                               norm_total++;
+
+                               /* Add a unique monster to the list */
+                               who[uniq_total++] = k;
                        }
-                       else
+               }
+
+               /* Normal monsters */
+               else
+               {
+                       if (r_ptr->r_pkills > 0)
                        {
-                               s16b This = r_ptr->r_pkills;
-                               if (This > 0)
-                               {
-                                       Total += This;
-                               }
+                               norm_total += r_ptr->r_pkills;
                        }
                }
+       }
+
+
+       /* No monsters is defeated */
+       if (norm_total < 1)
+       {
+#ifdef JP
+               fprintf(fff,"¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Þ¤»¤ó¡£\n");
+#else
+               fprintf(fff,"You have defeated no enemies yet.\n");
+#endif
+       }
 
-               if (Total < 1)
+       /* Defeated more than one normal monsters */
+       else if (uniq_total == 0)
+       {
 #ifdef JP
-                       fprintf(fff,"\n ¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Þ¤»¤ó¡£\n");
+               fprintf(fff,"%luÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", norm_total);
 #else
-                       fprintf(fff,"\n You have defeated no enemies yet.\n");
+               fprintf(fff,"You have defeated %lu %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies");
 #endif
+       }
 
-               else if (Total == 1)
+       /* Defeated more than one unique monsters */
+       else /* if (uniq_total > 0) */
+       {
 #ifdef JP
-                       fprintf(fff,"\n °ìÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n");
+               fprintf(fff, "%luÂΤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤ò´Þ¤à¡¢¹ç·×%luÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", uniq_total, norm_total); 
 #else
-                       fprintf(fff,"\n You have defeated one enemy.\n");
+               fprintf(fff, "You have defeated %lu %s including %lu unique monster%s in total.\n", norm_total, norm_total == 1 ? "enemy" : "enemies", uniq_total, (uniq_total == 1 ? "" : "s"));
 #endif
 
-               else
+
+               /* Select the sort method */
+               ang_sort_comp = ang_sort_comp_hook;
+               ang_sort_swap = ang_sort_swap_hook;
+
+               /* Sort the array by dungeon depth of monsters */
+               ang_sort(who, &why, uniq_total);
+
 #ifdef JP
-                       fprintf(fff,"\n %lu ÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", Total);
+               fprintf(fff, "\n¡Ô¾å°Ì%luÂΤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¡Õ\n", MIN(uniq_total, 10));
 #else
-                       fprintf(fff,"\n You have defeated %lu enemies.\n", Total);
+               fprintf(fff, "\n< Unique monsters top %lu >\n", MIN(uniq_total, 10));
 #endif
 
+               /* Print top 10 */
+               for (k = uniq_total - 1; k >= 0 && k >= uniq_total - 10; k--)
+               {
+                       monster_race *r_ptr = &r_info[who[k]];
+
+#ifdef JP
+                       fprintf(fff, "  %-40s (¥ì¥Ù¥ë%3d)\n", (r_name + r_ptr->name), r_ptr->level); 
+#else
+                       fprintf(fff, "  %-40s (level %3d)\n", (r_name + r_ptr->name), r_ptr->level); 
+#endif
+               }
+
        }
 
+       /* Free the "who" array */
+       C_KILL(who, max_r_idx, s16b);
+}
+
 
+/*
+ *
+ */
+static void dump_aux_race_history(FILE *fff)
+{
        if (p_ptr->old_race1 || p_ptr->old_race2)
        {
+               int i;
+
 #ifdef JP
                fprintf(fff, "\n\n ¤¢¤Ê¤¿¤Ï%s¤È¤·¤ÆÀ¸¤Þ¤ì¤¿¡£", race_info[p_ptr->start_race].title);
 #else
@@ -4599,9 +4745,18 @@ errr make_character_dump(FILE *fff)
 #endif
                }
        }
+}
+
 
+/*
+ *
+ */
+static void dump_aux_realm_history(FILE *fff)
+{
        if (p_ptr->old_realm)
        {
+               int i;
+
                for (i = 0; i < MAX_MAGIC; i++)
                {
                        if (!(p_ptr->old_realm & 1L << i)) continue;
@@ -4612,7 +4767,14 @@ errr make_character_dump(FILE *fff)
 #endif
                }
        }
+}
+
 
+/*
+ *
+ */
+static void dump_aux_virtues(FILE *fff)
+{
 #ifdef JP
        fprintf(fff, "\n\n  [¥×¥ì¥¤¥ä¡¼¤ÎÆÁ]\n\n");
 #else
@@ -4624,9 +4786,17 @@ errr make_character_dump(FILE *fff)
 #else
        fprintf(fff, "Your alighnment : %s\n", your_alignment());
 #endif
+
        fprintf(fff, "\n");
        dump_virtues(fff);
+}
+
 
+/*
+ *
+ */
+static void dump_aux_mutations(FILE *fff)
+{
        if (p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3)
        {
 #ifdef JP
@@ -4638,11 +4808,19 @@ errr make_character_dump(FILE *fff)
                dump_mutations(fff);
        }
 
-
        /* Skip some lines */
        fprintf(fff, "\n\n");
+}
 
 
+/*
+ *
+ */
+static void dump_aux_equipment_inventory(FILE *fff)
+{
+       int i;
+       char o_name[MAX_NLEN];
+
        /* Dump the equipment */
        if (equip_cnt)
        {
@@ -4654,15 +4832,16 @@ errr make_character_dump(FILE *fff)
 
                for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
                {
-                       object_desc(o_name, &inventory[i], TRUE, 3);
+                       object_desc(o_name, &inventory[i], 0);
                        if ((i == INVEN_LARM) && p_ptr->ryoute)
 #ifdef JP
                                strcpy(o_name, "(Éð´ï¤òξ¼ê»ý¤Á)");
 #else
                                strcpy(o_name, "(wielding with two-hands)");
 #endif
-                       fprintf(fff, "%c%s %s\n",
-                               index_to_label(i), paren, o_name);
+
+                       fprintf(fff, "%c) %s\n",
+                               index_to_label(i), o_name);
                }
                fprintf(fff, "\n\n");
        }
@@ -4680,28 +4859,40 @@ errr make_character_dump(FILE *fff)
                if (!inventory[i].k_idx) break;
 
                /* Dump the inventory slots */
-               object_desc(o_name, &inventory[i], TRUE, 3);
-               fprintf(fff, "%c%s %s\n", index_to_label(i), paren, o_name);
+               object_desc(o_name, &inventory[i], 0);
+               fprintf(fff, "%c) %s\n", index_to_label(i), o_name);
        }
 
        /* Add an empty line */
        fprintf(fff, "\n\n");
+}
+
+
+/*
+ *
+ */
+static void dump_aux_home_museum(FILE *fff)
+{
+       char o_name[MAX_NLEN];
+       store_type  *st_ptr;
 
-       process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
+       /* Do we need it?? */
+       /* process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x); */
 
-       /* Print all homes in the different towns */
+       /* Print the home */
        st_ptr = &town[1].store[STORE_HOME];
 
        /* Home -- if anything there */
        if (st_ptr->stock_num)
        {
-               /* Header with name of the town */
+               int i;
+               int x = 1;
+
 #ifdef JP
                fprintf(fff, "  [²æ¤¬²È¤Î¥¢¥¤¥Æ¥à]\n");
 #else
                fprintf(fff, "  [Home Inventory]\n");
 #endif
-               x = 1;
 
                /* Dump all available items */
                for (i = 0; i < st_ptr->stock_num; i++)
@@ -4712,8 +4903,8 @@ errr make_character_dump(FILE *fff)
 #else
                                fprintf(fff, "\n ( page %d )\n", x++);
 #endif
-                       object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
-                       fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
+                       object_desc(o_name, &st_ptr->stock[i], 0);
+                       fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
                }
 
                /* Add an empty line */
@@ -4721,31 +4912,32 @@ errr make_character_dump(FILE *fff)
        }
 
 
-       /* Print all homes in the different towns */
+       /* Print the home */
        st_ptr = &town[1].store[STORE_MUSEUM];
 
        /* Home -- if anything there */
        if (st_ptr->stock_num)
        {
-               /* Header with name of the town */
+               int i;
+               int x = 1;
+
 #ifdef JP
                fprintf(fff, "  [Çîʪ´Û¤Î¥¢¥¤¥Æ¥à]\n");
 #else
                fprintf(fff, "  [Museum]\n");
 #endif
-               x = 1;
 
                /* Dump all available items */
                for (i = 0; i < st_ptr->stock_num; i++)
                {
 #ifdef JP
                if ((i % 12) == 0) fprintf(fff, "\n ( %d ¥Ú¡¼¥¸ )\n", x++);
-                       object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
-                       fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
+                       object_desc(o_name, &st_ptr->stock[i], 0);
+                       fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
 #else
                if ((i % 12) == 0) fprintf(fff, "\n ( page %d )\n", x++);
-                       object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
-                       fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
+                       object_desc(o_name, &st_ptr->stock[i], 0);
+                       fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
 #endif
 
                }
@@ -4753,6 +4945,39 @@ errr make_character_dump(FILE *fff)
                /* Add an empty line */
                fprintf(fff, "\n\n");
        }
+}
+
+
+/*
+ * Output the character dump to a file
+ */
+errr make_character_dump(FILE *fff)
+{
+#ifdef JP
+       fprintf(fff, "  [ÊѶòÈÚÅÜ %d.%d.%d ¥­¥ã¥é¥¯¥¿¾ðÊó]\n\n",
+               FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
+#else
+       fprintf(fff, "  [Hengband %d.%d.%d Character Dump]\n\n",
+               FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
+#endif
+
+       update_playtime();
+
+       dump_aux_display_player(fff);
+       dump_aux_last_message(fff);
+       dump_aux_options(fff);
+       dump_aux_recall(fff);
+       dump_aux_quest(fff);
+       dump_aux_arena(fff);
+       dump_aux_monsters(fff);
+       dump_aux_virtues(fff);
+       dump_aux_race_history(fff);
+       dump_aux_realm_history(fff);
+       dump_aux_class_special(fff);
+       dump_aux_mutations(fff);
+       dump_aux_pet(fff);
+       dump_aux_equipment_inventory(fff);
+       dump_aux_home_museum(fff);
 
 #ifdef JP
        fprintf(fff, "  [¥Á¥§¥Ã¥¯¥µ¥à: \"%s\"]\n\n", get_check_sum());
@@ -4844,16 +5069,135 @@ msg_print("
 
 
 /*
- * Recursive file perusal.
+ * Display single line of on-line help file
  *
- * Return FALSE on 'Q', otherwise TRUE.
+ * You can insert some special color tag to change text color.
+ * Such as...
+ * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
+ *
+ * A colored segment is between "[[[[y|" and the last "|".
+ * You can use any single character in place of the "|".
+ */
+static void show_file_aux_line(cptr str, int cy, cptr shower)
+{
+       static const char tag_str[] = "[[[[";
+       byte color = TERM_WHITE;
+       char in_tag = '\0';
+       int cx = 0;
+       int i;
+       char lcstr[1024];
+
+       if (shower)
+       {
+               /* Make a lower case version of str for searching */
+               strcpy(lcstr, str);
+               str_tolower(lcstr);
+       }
+
+       /* Initial cursor position */
+       Term_gotoxy(cx, cy);
+
+       for (i = 0; str[i];)
+       {
+               int len = strlen(&str[i]);
+               int showercol = len + 1;
+               int bracketcol = len + 1;
+               int endcol = len;
+               cptr ptr;
+
+               /* Search for a shower string in the line */
+               if (shower)
+               {
+                       ptr = my_strstr(&lcstr[i], shower);
+                       if (ptr) showercol = ptr - &lcstr[i];
+               }
+
+               /* Search for a color segment tag */
+               ptr = in_tag ? my_strchr(&str[i], in_tag) : my_strstr(&str[i], tag_str);
+               if (ptr) bracketcol = ptr - &str[i];
+
+               /* A color tag is found */
+               if (bracketcol < endcol) endcol = bracketcol;
+
+               /* The shower string is found before the color tag */
+               if (showercol < endcol) endcol = showercol;
+
+               /* Print a segment of the line */
+               Term_addstr(endcol, color, &str[i]);
+               cx += endcol;
+               i += endcol;
+
+               /* Shower string? */
+               if (endcol == showercol)
+               {
+                       int showerlen = strlen(shower);
+
+                       /* Print the shower string in yellow */
+                       Term_addstr(showerlen, TERM_YELLOW, &str[i]);
+                       cx += showerlen;
+                       i += showerlen;
+               }
+
+               /* Colored segment? */
+               else if (endcol == bracketcol)
+               {
+                       if (in_tag)
+                       {
+                               /* Found the end of colored segment */
+                               i++;
+
+                               /* Now looking for an another tag_str */
+                               in_tag = '\0';
+
+                               /* Set back to the default color */
+                               color = TERM_WHITE;
+                       }
+                       else
+                       {
+                               /* Found a tag_str, and get a tag color */
+                               i += sizeof(tag_str)-1;
+
+                               /* Get tag color */
+                               color = color_char_to_attr(str[i]);
+
+                               /* Illegal color tag */
+                               if (color == 255 || str[i+1] == '\0')
+                               {
+                                       /* Illegal color tag */
+                                       color = TERM_WHITE;
+
+                                       /* Print the broken tag as a string */
+                                       Term_addstr(-1, TERM_WHITE, tag_str);
+                                       cx += sizeof(tag_str)-1;
+                               }
+                               else
+                               {
+                                       /* Skip the color tag */
+                                       i++;
+
+                                       /* Now looking for a close tag */
+                                       in_tag = str[i];
+
+                                       /* Skip the close-tag-indicator */
+                                       i++;
+                               }
+                       }
+               }
+
+       } /* for (i = 0; str[i];) */
+
+       /* Clear rest of line */
+       Term_erase(cx, cy, 255);
+}
+
+
+/*
+ * Recursive file perusal.
  *
  * Process various special text in the input file, including
  * the "menu" structures used by the "help file" system.
  *
- * XXX XXX XXX Consider using a temporary file.
- *
- * XXX XXX XXX Allow the user to "save" the current file.
+ * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
  */
 bool show_file(bool show_version, cptr name, cptr what, int line, int mode)
 {
@@ -4868,12 +5212,6 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode)
        /* Backup value for "line" */
        int back = 0;
 
-       /* Color of the next line */
-       byte color = TERM_WHITE;
-
-       /* Loop counter */
-       int cnt;
-
        /* This screen has sub-screens */
        bool menu = FALSE;
 
@@ -4886,11 +5224,12 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode)
        /* Jump to this tag */
        cptr tag = NULL;
 
-       /* Hold a string to find */
-       char finder[81];
+       /* Hold strings to find/show */
+       char finder_str[81];
+       char shower_str[81];
 
-       /* Hold a string to show */
-       char shower[81];
+       /* String to show */
+       cptr shower = NULL;
 
        /* Filename */
        char filename[1024];
@@ -4904,12 +5243,6 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode)
        /* General buffer */
        char buf[1024];
 
-       /* Lower case version of the buffer, for searching */
-       char lc_buf[1024];
-
-       /* Aux pointer for making lc_buf (and find!) lowercase */
-       cptr lc_buf_ptr;
-
        /* Sub-menu information */
        char hook[68][32];
 
@@ -4921,10 +5254,10 @@ bool show_file(bool show_version, cptr name, cptr what, int line, int mode)
        rows = hgt - 4;
 
        /* Wipe finder */
-       strcpy(finder, "");
+       strcpy(finder_str, "");
 
        /* Wipe shower */
-       strcpy(shower, "");
+       strcpy(shower_str, "");
 
        /* Wipe caption */
        strcpy(caption, "");
@@ -5138,7 +5471,6 @@ msg_format("'%s'
                /* Dump the next 20, or rows, lines of the file */
                for (i = 0; i < rows; )
                {
-                       int print_x, x;
                        cptr str = buf;
 
                        /* Hack -- track the "first" line */
@@ -5150,98 +5482,26 @@ msg_format("'%s'
                        /* Hack -- skip "special" lines */
                        if (prefix(buf, "***** ")) continue;
 
-                       /* Get a color */
-                       if (prefix(str, "#####"))
-                       {
-                               str += 5;
-                               if (*str)
-                               {
-                                       color = color_char_to_attr(*str);
-                                       str++;
-                               }
-                       }
-                       else
-                       {
-                               color = TERM_WHITE;
-                       }
-
                        /* Count the "real" lines */
                        next++;
 
-                       /* Make a lower case version of str for searching */
-                       strcpy(lc_buf, str);
-
-                       for (lc_buf_ptr = lc_buf; *lc_buf_ptr != 0; lc_buf_ptr++)
-                       {
-#ifdef JP
-                               if (iskanji(*lc_buf_ptr))
-                                       lc_buf_ptr++;
-                               else
-#endif
-                                       lc_buf[lc_buf_ptr-lc_buf] = tolower(*lc_buf_ptr);
-                       }
-
                        /* Hack -- keep searching */
-                       if (find && !i && !strstr(lc_buf, find)) continue;
-
-                       /* Hack -- stop searching */
-                       find = NULL;
-
-                       /* Dump the line */
-                       x = 0;
-                       print_x = 0;
-                       while (str[x])
+                       if (find && !i)
                        {
-                               /* Color ? */
-                               if (prefix(str + x, "[[[[["))
-                               {
-                                       byte c;
-                                       x += 5;
-
-                                       /* Illigal end of line */
-                                       if (!str[x]) break;
-
-                                       /* Get color attr */
-                                       c = color_char_to_attr(str[x++]);
+                               char lc_buf[1024];
 
-                                       /* Ok print a colored text */
-                                       while (str[x] && str[x] != ']')
-                                       {
-                                               Term_putch(print_x, i + 2, c, str[x]);
-                                               x++;
-                                               print_x++;
-                                       }
+                               /* Make a lower case version of str for searching */
+                               strcpy(lc_buf, str);
+                               str_tolower(lc_buf);
 
-                                       if (str[x] == ']') x++;
-                               }
-                               else
-                               {
-                                       Term_putch(print_x, i + 2, color, str[x]);
-                                       x++;
-                                       print_x++;
-                               }
+                               if (!my_strstr(lc_buf, find)) continue;
                        }
 
-                       /* Clear rest of line */
-                       Term_erase(print_x, i + 2, 255);
-
-                       /* Hilite "shower" */
-                       if (shower[0])
-                       {
-                               cptr s2 = lc_buf;
-
-                               /* Display matches */
-                               while ((s2 = strstr(s2, shower)) != NULL)
-                               {
-                                       int len = strlen(shower);
-
-                                       /* Display the match */
-                                       Term_putstr(s2-lc_buf, i+2, len, TERM_YELLOW, &str[s2-lc_buf]);
+                       /* Hack -- stop searching */
+                       find = NULL;
 
-                                       /* Advance */
-                                       s2 += len;
-                               }
-                       }
+                       /* Dump the line */
+                       show_file_aux_line(str, i + 2, shower);
 
                        /* Count the printed lines */
                        i++;
@@ -5335,12 +5595,18 @@ prt("[
                {
                        /* Get "shower" */
 #ifdef JP
-prt("¶¯Ä´: ", hgt - 1, 0);
+                       prt("¶¯Ä´: ", hgt - 1, 0);
 #else
                        prt("Show: ", hgt - 1, 0);
 #endif
 
-                       (void)askfor_aux(shower, 80);
+                       (void)askfor(shower_str, 80);
+
+                       /* Make it lowercase */
+                       str_tolower(shower_str);
+
+                       /* Show it */
+                       shower = shower_str;
                }
 
                /* Hack -- try finding */
@@ -5354,26 +5620,18 @@ prt("
 #endif
 
 
-                       if (askfor_aux(finder, 80))
+                       if (askfor(finder_str, 80))
                        {
                                /* Find it */
-                               find = finder;
+                               find = finder_str;
                                back = line;
                                line = line + 1;
 
                                /* Make finder lowercase */
-                               for (cnt = 0; finder[cnt] != 0; cnt++)
-                               {
-#ifdef JP
-                                       if (iskanji(finder[cnt]))
-                                               cnt++;
-                                       else
-#endif
-                                               finder[cnt] = tolower(finder[cnt]);
-                               }
+                               str_tolower(finder_str);
 
                                /* Show it */
-                               strcpy(shower, finder);
+                               shower = finder_str;
                        }
                }
 
@@ -5389,7 +5647,7 @@ prt("
 
                        strcpy(tmp, "0");
 
-                       if (askfor_aux(tmp, 80))
+                       if (askfor(tmp, 80))
                        {
                                line = atoi(tmp);
                        }
@@ -5420,7 +5678,7 @@ strcpy(tmp, "jhelp.hlp");
 #endif
 
 
-                       if (askfor_aux(tmp, 80))
+                       if (askfor(tmp, 80))
                        {
                                if (!show_file(TRUE, tmp, NULL, 0, mode)) skey = 'q';
                        }
@@ -5547,7 +5805,10 @@ msg_print("
                if (skey == ESCAPE) break;
                if (skey == '<') break;
 
-               /* Exit on escape */
+               /* Exit on the ^q */
+               if (skey == KTRL('q')) skey = 'q';
+
+               /* Exit on the q key */
                if (skey == 'q') break;
        }
 
@@ -5684,7 +5945,7 @@ quit_fmt("'%s' 
                }
 #ifdef MSDOS
                /* Convert space, dot, and underscore to underscore */
-               else if (strchr(". _", c)) player_base[k++] = '_';
+               else if (my_strchr(". _", c)) player_base[k++] = '_';
 #endif
                else if (isprint(c)) player_base[k++] = c;
        }
@@ -5719,7 +5980,7 @@ quit_fmt("'%s' 
                while (1)
                {
                        cptr t;
-                       t = strstr(s, PATH_SEP);
+                       t = my_strstr(s, PATH_SEP);
                        if (!t)
                                break;
                        s = t+1;
@@ -6464,7 +6725,7 @@ put_str("
                strcpy(out_val, "");
 
                /* Ask for filename (or abort) */
-               if (!askfor_aux(out_val, 60)) return;
+               if (!askfor(out_val, 60)) return;
 
                /* Return means "show on screen" */
                if (!out_val[0]) break;
@@ -6556,7 +6817,7 @@ prt("
                                        prt(tmp_val, j+2, 4);
 
                                        /* Display object description */
-                                       object_desc(o_name, o_ptr, TRUE, 3);
+                                       object_desc(o_name, o_ptr, 0);
                                        c_put_str(tval_to_attr[o_ptr->tval], o_name, j+2, 7);
                                }
 
@@ -7006,7 +7267,7 @@ errr get_rnd_line_jonly(cptr file_name, int entry, char *output, int count)
 /*
  * Process file for auto picker/destroyer.
  */
-errr process_pickpref_file(cptr name)
+errr process_autopick_file(cptr name)
 {
        char buf[1024];
 
@@ -7015,7 +7276,7 @@ errr process_pickpref_file(cptr name)
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
-       err = process_pref_file_aux(buf, PREF_TYPE_PICKPREF);
+       err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
 
        /* Result */
        return (err);
@@ -7133,8 +7394,14 @@ errr counts_write(int where, u32b count)
                /* File type is "DATA" */
                FILE_TYPE(FILE_TYPE_DATA);
 
+               /* Grab permissions */
+               safe_setuid_grab();
+
                /* Create a new high score file */
                fd = fd_make(buf, 0644);
+
+               /* Drop permissions */
+               safe_setuid_drop();
        }
 
        /* Grab permissions */