OSDN Git Service

branch-nothere-terrainflags、゙。シ・ク.
[hengband/hengband.git] / src / files.c
index 3e05144..a2d45eb 100644 (file)
@@ -1,15 +1,15 @@
 /* File: files.c */
 
-/* Purpose: code dealing with files (and death) */
-
 /*
- * 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: code dealing with files (and death) */
+
 #include "angband.h"
 
 
@@ -412,71 +412,115 @@ errr process_pref_file_command(char *buf)
 
 
        /* Require "?:*" format */
-       if (buf[1] != ':') return (1);
+       if (buf[1] != ':') return 1;
 
 
-       /* Process "%:<fname>" */
-       if (buf[0] == '%')
+       switch (buf[0])
        {
-               /* 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':
+               add_history_from_pref_line(buf + 2);
+               return 0;
 
        /* Process "R:<num>:<a>/<c>" -- attr/char for monster races */
-       if (buf[0] == 'R')
-       {
+       case 'R':
                if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
                        monster_race *r_ptr;
                        i = (huge)strtol(zz[0], NULL, 0);
                        n1 = strtol(zz[1], NULL, 0);
                        n2 = strtol(zz[2], NULL, 0);
-                       if (i >= max_r_idx) return (1);
+                       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);
+                       return 0;
                }
-       }
+               break;
 
        /* Process "K:<num>:<a>/<c>"  -- attr/char for object kinds */
-       else if (buf[0] == 'K')
-       {
+       case 'K':
                if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
                        object_kind *k_ptr;
                        i = (huge)strtol(zz[0], NULL, 0);
                        n1 = strtol(zz[1], NULL, 0);
                        n2 = strtol(zz[2], NULL, 0);
-                       if (i >= max_k_idx) return (1);
+                       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);
+                       return 0;
                }
-       }
+               break;
 
        /* Process "F:<num>:<a>/<c>" -- attr/char for terrain features */
-       else if (buf[0] == 'F')
-       {
-               if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
+       /* "F:<num>:<a>/<c>" */
+       /* "F:<num>:<a>/<c>:LIT" */
+       /* "F:<num>:<a>/<c>:<la>/<lc>:<da>/<dc>:<Da>/<Dc>" */
+       case 'F':
                {
                        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);
+                       if (i >= max_f_idx) return 1;
+                       f_ptr = &f_info[i];
+
                        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);
+                       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;
+                       }
                }
-       }
+               return 0;
 
        /* Process "S:<num>:<a>/<c>" -- attr/char for special things */
-       else if (buf[0] == 'S')
-       {
+       case 'S':
                if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
                        j = (byte)strtol(zz[0], NULL, 0);
@@ -484,13 +528,12 @@ errr process_pref_file_command(char *buf)
                        n2 = strtol(zz[2], NULL, 0);
                        misc_to_attr[j] = n1;
                        misc_to_char[j] = n2;
-                       return (0);
+                       return 0;
                }
-       }
+               break;
 
        /* Process "U:<tv>:<a>/<c>" -- attr/char for unaware items */
-       else if (buf[0] == 'U')
-       {
+       case 'U':
                if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
                {
                        j = (huge)strtol(zz[0], NULL, 0);
@@ -505,67 +548,60 @@ errr process_pref_file_command(char *buf)
                                        if (n2) k_ptr->d_char = n2;
                                }
                        }
-                       return (0);
+                       return 0;
                }
-       }
+               break;
 
        /* Process "E:<tv>:<a>" -- attribute for inventory objects */
-       else if (buf[0] == 'E')
-       {
+       case 'E':
                if (tokenize(buf+2, 2, zz, TOKENIZE_CHECKQUOTE) == 2)
                {
                        j = (byte)strtol(zz[0], NULL, 0) % 128;
                        n1 = strtol(zz[1], NULL, 0);
                        if (n1) tval_to_attr[j] = n1;
-                       return (0);
+                       return 0;
                }
-       }
-
+               break;
 
        /* Process "A:<str>" -- save an "action" for later */
-       else if (buf[0] == 'A')
-       {
+       case 'A':
                text_to_ascii(macro__buf, buf+2);
-               return (0);
-       }
+               return 0;
 
        /* Process "P:<str>" -- normal macro */
-       else if (buf[0] == 'P')
+       case 'P':
        {
                char tmp[1024];
+
                text_to_ascii(tmp, buf+2);
                macro_add(tmp, macro__buf);
-               return (0);
+               return 0;
        }
 
-
        /* Process "C:<str>" -- create keymap */
-       else if (buf[0] == 'C')
+       case 'C':
        {
                int mode;
-
                char tmp[1024];
 
-               if (tokenize(buf+2, 2, zz, TOKENIZE_CHECKQUOTE) != 2) return (1);
+               if (tokenize(buf+2, 2, zz, TOKENIZE_CHECKQUOTE) != 2) return 1;
 
                mode = strtol(zz[0], NULL, 0);
-               if ((mode < 0) || (mode >= KEYMAP_MODES)) return (1);
+               if ((mode < 0) || (mode >= KEYMAP_MODES)) return 1;
 
                text_to_ascii(tmp, zz[1]);
-               if (!tmp[0] || tmp[1]) return (1);
+               if (!tmp[0] || tmp[1]) return 1;
                i = (byte)(tmp[0]);
 
                string_free(keymap_act[mode][i]);
 
                keymap_act[mode][i] = string_make(macro__buf);
 
-               return (0);
+               return 0;
        }
 
-
        /* Process "V:<num>:<kv>:<rv>:<gv>:<bv>" -- visual info */
-       else if (buf[0] == 'V')
-       {
+       case 'V':
                if (tokenize(buf+2, 5, zz, TOKENIZE_CHECKQUOTE) == 5)
                {
                        i = (byte)strtol(zz[0], NULL, 0);
@@ -573,78 +609,48 @@ errr process_pref_file_command(char *buf)
                        angband_color_table[i][1] = (byte)strtol(zz[2], NULL, 0);
                        angband_color_table[i][2] = (byte)strtol(zz[3], NULL, 0);
                        angband_color_table[i][3] = (byte)strtol(zz[4], NULL, 0);
-                       return (0);
+                       return 0;
                }
-       }
-
+               break;
 
        /* Process "X:<str>" -- turn option off */
-       else if (buf[0] == 'X')
-       {
+       /* Process "Y:<str>" -- turn option on */
+       case 'X':
+       case 'Y':
                for (i = 0; option_info[i].o_desc; i++)
                {
-                       int os = option_info[i].o_set;
-                       int ob = option_info[i].o_bit;
-
                        if (option_info[i].o_var &&
                            option_info[i].o_text &&
                            streq(option_info[i].o_text, buf + 2))
                        {
-                               if (p_ptr->playing && 6 == option_info[i].o_page && !p_ptr->wizard)
+                               int os = option_info[i].o_set;
+                               int ob = option_info[i].o_bit;
+
+                               if ((p_ptr->playing || character_xtra) &&
+                                       (OPT_PAGE_BIRTH == option_info[i].o_page) && !p_ptr->wizard)
                                {
 #ifdef JP
-                                       msg_format("½é´ü¥ª¥×¥·¥ç¥ó¤ÏÊѹ¹¤Ç¤­¤Þ¤»¤ó! '%s'", buf);        
+                                       msg_format("½é´ü¥ª¥×¥·¥ç¥ó¤ÏÊѹ¹¤Ç¤­¤Þ¤»¤ó! '%s'", buf);
 #else
-                                       msg_format("Startup options can not changed! '%s'", buf);       
+                                       msg_format("Birth options can not changed! '%s'", buf);
 #endif
                                        msg_print(NULL);
                                        return 0;
                                }
 
-                               /* Clear */
-                               option_flag[os] &= ~(1L << ob);
-                               (*option_info[i].o_var) = FALSE;
-                               return (0);
-                       }
-               }
-
-               /* don't know that option. ignore it.*/
-#ifdef JP
-               msg_format("¥ª¥×¥·¥ç¥ó¤Î̾Á°¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡§ %s", buf);
-#else
-               msg_format("Ignored invalid option: %s", buf);
-#endif
-               msg_print(NULL);
-               return 0;
-       }
-
-       /* Process "Y:<str>" -- turn option on */
-       else if (buf[0] == 'Y')
-       {
-               for (i = 0; option_info[i].o_desc; i++)
-               {
-                       int os = option_info[i].o_set;
-                       int ob = option_info[i].o_bit;
-
-                       if (option_info[i].o_var &&
-                           option_info[i].o_text &&
-                           streq(option_info[i].o_text, buf + 2))
-                       {
-                               if (p_ptr->playing && 6 == option_info[i].o_page && !p_ptr->wizard)
+                               if (buf[0] == 'X')
                                {
-#ifdef JP
-                                       msg_format("½é´ü¥ª¥×¥·¥ç¥ó¤ÏÊѹ¹¤Ç¤­¤Þ¤»¤ó! '%s'", buf);        
-#else
-                                       msg_format("Startup options can not changed! '%s'", buf);       
-#endif
-                                       msg_print(NULL);
-                                       return 0;
+                                       /* Clear */
+                                       option_flag[os] &= ~(1L << ob);
+                                       (*option_info[i].o_var) = FALSE;
                                }
-
-                               /* Set */
-                               option_flag[os] |= (1L << ob);
-                               (*option_info[i].o_var) = TRUE;
-                               return (0);
+                               else
+                               {
+                                       /* Set */
+                                       option_flag[os] |= (1L << ob);
+                                       (*option_info[i].o_var) = TRUE;
+                               }
+                               return 0;
                        }
                }
 
@@ -656,16 +662,15 @@ errr process_pref_file_command(char *buf)
 #endif
                msg_print(NULL);
                return 0;
-       }
 
        /* Process "Z:<type>:<str>" -- set spell color */
-       else if (buf[0] == 'Z')
+       case 'Z':
        {
                /* Find the colon */
-               char *t = strchr(buf + 2, ':');
+               char *t = my_strchr(buf + 2, ':');
 
                /* Oops */
-               if (!t) return (1);
+               if (!t) return 1;
 
                /* Nuke the colon */
                *(t++) = '\0';
@@ -679,17 +684,21 @@ errr process_pref_file_command(char *buf)
                                gf_color[gf_desc[i].num] = quark_add(t);
 
                                /* Success */
-                               return (0);
+                               return 0;
                        }
                }
+
+               break;
        }
-       /* set macro trigger names and a template */
+
+       /* Initialize macro trigger names and a template */
        /* Process "T:<trigger>:<keycode>:<shift-keycode>" */
        /* Process "T:<template>:<modifier chr>:<modifier name>:..." */
-       else if (buf[0] == 'T')
+       case 'T':
        {
-               int len, tok;
-               tok = tokenize(buf+2, 2+MAX_MACRO_MOD, zz, 0);
+               int tok = tokenize(buf+2, 2+MAX_MACRO_MOD, zz, 0);
+
+               /* Process "T:<template>:<modifier chr>:<modifier name>:..." */
                if (tok >= 4)
                {
                        int i;
@@ -697,37 +706,60 @@ errr process_pref_file_command(char *buf)
 
                        if (macro_template != NULL)
                        {
-                               free(macro_template);
+                               num = strlen(macro_modifier_chr);
+
+                               /* Kill the template string */
+                               string_free(macro_template);
                                macro_template = NULL;
+
+                               /* Kill flag characters of modifier keys */
+                               string_free(macro_modifier_chr);
+
+                               /* Kill corresponding modifier names */
+                               for (i = 0; i < num; i++)
+                               {
+                                       string_free(macro_modifier_name[i]);
+                               }
+
+                               /* Kill trigger name strings */
                                for (i = 0; i < max_macrotrigger; i++)
-                                       free(macro_trigger_name[i]);
+                               {
+                                       string_free(macro_trigger_name[i]);
+                                       string_free(macro_trigger_keycode[0][i]);
+                                       string_free(macro_trigger_keycode[1][i]);
+                               }
+
                                max_macrotrigger = 0;
                        }
-                       
+
                        if (*zz[0] == '\0') return 0; /* clear template */
+
+                       /* Number of modifier flags */
                        num = strlen(zz[1]);
-                       if (2 + num != tok) return 1; /* error */
 
-                       len = strlen(zz[0])+1+num+1;
-                       for (i = 0; i < num; i++)
-                               len += strlen(zz[2+i])+1;
-                       macro_template = malloc(len);
-
-                       strcpy(macro_template, zz[0]);
-                       macro_modifier_chr =
-                               macro_template + strlen(macro_template) + 1;
-                       strcpy(macro_modifier_chr, zz[1]);
-                       macro_modifier_name[0] =
-                               macro_modifier_chr + strlen(macro_modifier_chr) + 1;
+                       /* Limit the number */
+                       num = MIN(MAX_MACRO_MOD, num);
+
+                       /* Stop if number of modifier is not correct */
+                       if (2 + num != tok) return 1;
+
+                       /* Get a template string */
+                       macro_template = string_make(zz[0]);
+
+                       /* Get flag characters of modifier keys */
+                       macro_modifier_chr = string_make(zz[1]);
+
+                       /* Get corresponding modifier names */
                        for (i = 0; i < num; i++)
                        {
-                               strcpy(macro_modifier_name[i], zz[2+i]);
-                               macro_modifier_name[i+1] = macro_modifier_name[i] + 
-                                       strlen(macro_modifier_name[i]) + 1;
+                               macro_modifier_name[i] = string_make(zz[2+i]);
                        }
                }
+
+               /* Process "T:<trigger>:<keycode>:<shift-keycode>" */
                else if (tok >= 2)
                {
+                       char buf[1024];
                        int m;
                        char *t, *s;
                        if (max_macrotrigger >= MAX_MACRO_TRIG)
@@ -742,12 +774,8 @@ errr process_pref_file_command(char *buf)
                        m = max_macrotrigger;
                        max_macrotrigger++;
 
-                       len = strlen(zz[0]) + 1 + strlen(zz[1]) + 1;
-                       if (tok == 3)
-                               len += strlen(zz[2]) + 1;
-                       macro_trigger_name[m] = malloc(len);
-
-                       t = macro_trigger_name[m];
+                       /* Take into account the escape character  */
+                       t = buf;
                        s = zz[0];
                        while (*s)
                        {
@@ -756,25 +784,30 @@ errr process_pref_file_command(char *buf)
                        }
                        *t = '\0';
 
-                       macro_trigger_keycode[0][m] = macro_trigger_name[m] +
-                               strlen(macro_trigger_name[m]) + 1;
-                       strcpy(macro_trigger_keycode[0][m], zz[1]);
+                       /* Get a trigger name */
+                       macro_trigger_name[m] = string_make(buf);
+
+                       /* Get the corresponding key code */
+                       macro_trigger_keycode[0][m] = string_make(zz[1]);
+
                        if (tok == 3)
                        {
-                               macro_trigger_keycode[1][m] = macro_trigger_keycode[0][m] +
-                                       strlen(macro_trigger_keycode[0][m]) + 1;
-                               strcpy(macro_trigger_keycode[1][m], zz[2]);
+                               /* Key code of a combination of it with the shift key */
+                               macro_trigger_keycode[1][m] = string_make(zz[2]);
                        }
                        else
                        {
-                               macro_trigger_keycode[1][m] = macro_trigger_keycode[0][m];
+                               macro_trigger_keycode[1][m] = string_make(zz[1]);
                        }
                }
+
+               /* No error */
                return 0;
        }
+       }
 
        /* Failure */
-       return (1);
+       return 1;
 }
 
 
@@ -788,12 +821,11 @@ errr process_pref_file_command(char *buf)
  * Output:
  *   result
  */
-static cptr process_pref_file_expr(char **sp, char *fp)
+cptr process_pref_file_expr(cptr *sp, char *fp)
 {
        cptr v;
 
-       char *b;
-       char *s;
+       cptr s;
 
        char b1 = '[';
        char b2 = ']';
@@ -807,9 +839,6 @@ static cptr process_pref_file_expr(char **sp, char *fp)
        /* Skip spaces */
        while (isspace(*s)) s++;
 
-       /* Save start */
-       b = s;
-
        /* Default */
        v = "?o?o?";
 
@@ -867,16 +896,15 @@ static cptr process_pref_file_expr(char **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";
                        }
                }
 
@@ -892,7 +920,7 @@ static cptr process_pref_file_expr(char **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";
                        }
                }
 
@@ -908,7 +936,9 @@ static cptr process_pref_file_expr(char **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";
                        }
                }
 
@@ -925,17 +955,24 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                if (f != b2) v = "?x?x?";
 
                /* Extract final and Terminate */
-               if ((f = *s) != '\0') *s++ = '\0';
+               if ((f = *s) != '\0') s++;
        }
 
        /* Other */
        else
        {
+               char b[1024];
+               int i;
+
                /* Accept all printables except spaces and brackets */
-               while (isprint(*s) && !strchr(" []", *s)) ++s;
+               for (i = 0; isprint(*s) && !my_strchr(" []", *s); i++)
+                       b[i] = *s++;
+
+               /* Terminate */
+               b[i] = '\0';
 
                /* Extract final and Terminate */
-               if ((f = *s) != '\0') *s++ = '\0';
+               if ((f = *s) != '\0') s++;
 
                /* Variable */
                if (*b == '$')
@@ -946,10 +983,10 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                                v = ANGBAND_SYS;
                        }
 
-                        else if (streq(b+1, "KEYBOARD"))
-                        {
-                                v = ANGBAND_KEYBOARD;
-                        }
+                       else if (streq(b+1, "KEYBOARD"))
+                       {
+                               v = ANGBAND_KEYBOARD;
+                       }
 
                        /* Graphics */
                        else if (streq(b+1, "GRAF"))
@@ -970,7 +1007,7 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "RACE"))
                        {
 #ifdef JP
-                                v = rp_ptr->E_title;
+                               v = rp_ptr->E_title;
 #else
                                v = rp_ptr->title;
 #endif
@@ -980,7 +1017,7 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "CLASS"))
                        {
 #ifdef JP
-                                v = cp_ptr->E_title;
+                               v = cp_ptr->E_title;
 #else
                                v = cp_ptr->title;
 #endif
@@ -998,7 +1035,7 @@ static cptr process_pref_file_expr(char **sp, char *fp)
 #ifdef JP
                                v = E_realm_names[p_ptr->realm1];
 #else
-                                v = realm_names[p_ptr->realm1];
+                               v = realm_names[p_ptr->realm1];
 #endif
                        }
 
@@ -1006,7 +1043,7 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "REALM2"))
                        {
 #ifdef JP
-                                v = E_realm_names[p_ptr->realm2];
+                               v = E_realm_names[p_ptr->realm2];
 #else
                                v = realm_names[p_ptr->realm2];
 #endif
@@ -1018,6 +1055,15 @@ static cptr process_pref_file_expr(char **sp, char *fp)
                                sprintf(tmp, "%02d", p_ptr->lev);
                                v = tmp;
                        }
+
+                       /* Autopick auto-register is in-use or not? */
+                       else if (streq(b+1, "AUTOREGISTER"))
+                       {
+                               if (p_ptr->autopick_autoregister)
+                                       v = "1";
+                               else
+                                       v = "0";
+                       }
                }
 
                /* Constant */
@@ -1038,11 +1084,14 @@ static cptr process_pref_file_expr(char **sp, char *fp)
 }
 
 
+#define PREF_TYPE_NORMAL   0
+#define PREF_TYPE_AUTOPICK 1
+#define PREF_TYPE_HISTPREF 2
 
 /*
  * Open the "user pref file" and parse it.
  */
-static errr process_pref_file_aux(cptr name, bool read_pickpref)
+static errr process_pref_file_aux(cptr name, int preftype)
 {
        FILE *fp;
 
@@ -1091,7 +1140,7 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                {
                        char f;
                        cptr v;
-                       char *s;
+                       cptr s;
 
                        /* Start */
                        s = buf + 2;
@@ -1113,11 +1162,30 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                /* Process "%:<file>" */
                if (buf[0] == '%')
                {
-                       /* Process that file if allowed */
-                       if (read_pickpref)
-                               (void)process_pickpref_file(buf + 2);
-                       else
+                       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_AUTOPICK:
+                               (void)process_autopick_file(buf + 2);
+                               break;
+                       case PREF_TYPE_HISTPREF:
+                               (void)process_histpref_file(buf + 2);
+                               break;
+                       default:
                                (void)process_pref_file(buf + 2);
+                               break;
+                       }
+
+                       /* Set back depth level */
+                       depth_count--;
 
                        /* Continue */
                        continue;
@@ -1130,9 +1198,9 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                /* This is not original pref line... */
                if (err)
                {
-                       if (!read_pickpref)
-                               break;
-                       err = process_pickpref_file_line(buf);
+                       if (preftype != PREF_TYPE_AUTOPICK)
+                               break;
+                       err = process_autopick_file_command(buf);
                }
        }
 
@@ -1143,8 +1211,8 @@ static errr process_pref_file_aux(cptr name, bool read_pickpref)
                /* Print error message */
                /* ToDo: Add better error messages */
 #ifdef JP
-              msg_format("¥Õ¥¡¥¤¥ë'%s'¤Î%d¹Ô¤Ç¥¨¥é¡¼ÈÖ¹æ%d¤Î¥¨¥é¡¼¡£", name, line, err);
-              msg_format("('%s'¤ò²òÀÏÃæ)", old);
+             msg_format("¥Õ¥¡¥¤¥ë'%s'¤Î%d¹Ô¤Ç¥¨¥é¡¼ÈÖ¹æ%d¤Î¥¨¥é¡¼¡£", name, line, err);
+             msg_format("('%s'¤ò²òÀÏÃæ)", old);
 #else
                msg_format("Error %d in line %d of file '%s'.", err, line, name);
                msg_format("Parsing '%s'", old);
@@ -1179,23 +1247,17 @@ errr process_pref_file(cptr name)
        path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
 
        /* Process the system pref file */
-       err1 = process_pref_file_aux(buf, FALSE);
+       err1 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
 
        /* Stop at parser errors, but not at non-existing file */
        if (err1 > 0) return err1;
 
 
-       /* Drop priv's */
-       safe_setuid_drop();
-       
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
        
        /* Process the user pref file */
-       err2 = process_pref_file_aux(buf, FALSE);
-
-       /* Grab priv's */
-       safe_setuid_grab();
+       err2 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
 
 
        /* User file does not exist, but read system pref file */
@@ -1491,6 +1553,7 @@ errr check_load_init(void)
 #define ENTRY_ALIGN 42
 
 #define ENTRY_EXP_ANDR 43
+#define ENTRY_EXP_TO_ADV_ANDR 44
 
 
 static struct
@@ -1511,7 +1574,7 @@ static struct
        { 1, 11, 25, ""},
        { 1, 15, 25, "¼Í·â¹¶·â½¤Àµ"},
        { 1, 16, 25, "¼Í·âÉð´ïÇÜΨ"},
-       {01, 20, 25, "²Ã®"},
+       { 1, 20, 25, "²Ã®"},
        { 1, 19, 25, "£Á£Ã"},
        {29, 13, 21, "¥ì¥Ù¥ë"},
        {29, 14, 21, "·Ð¸³ÃÍ"},
@@ -1522,18 +1585,18 @@ static struct
        {29, 10, 21, "£È£Ð"},
        {29, 11, 21, "£Í£Ð"},
        {29, 20, 21, "¥×¥ì¥¤»þ´Ö"},
-       {54, 10, -1, "ÂǷ⹶·â  :"},
-       {54, 11, -1, "¼Í·â¹¶·â  :"},
-       {54, 12, -1, "ËâË¡Ëɸ栠:"},
-       {54, 13, -1, "±£Ì©¹ÔÆ°  :"},
-       {54, 15, -1, "ÃγР     :"},
-       {54, 16, -1, "õº÷      :"},
-       {54, 17, -1, "²ò½ü      :"},
-       {54, 18, -1, "ËâË¡Æ»¶ñ  :"},
-       {01, 12, 25, "ÂÇ·â²ó¿ô"},
-       {01, 17, 25, "¼Í·â²ó¿ô"},
-       {01, 13, 25, "Ê¿¶Ñ¥À¥á¡¼¥¸"},
-       {54, 20, -1, "ÀÖ³°Àþ»ëÎÏ:"},
+       {53, 10, -1, "ÂǷ⹶·â  :"},
+       {53, 11, -1, "¼Í·â¹¶·â  :"},
+       {53, 12, -1, "ËâË¡Ëɸ栠:"},
+       {53, 13, -1, "±£Ì©¹ÔÆ°  :"},
+       {53, 15, -1, "ÃγР     :"},
+       {53, 16, -1, "õº÷      :"},
+       {53, 17, -1, "²ò½ü      :"},
+       {53, 18, -1, "ËâË¡Æ»¶ñ  :"},
+       { 1, 12, 25, "ÂÇ·â²ó¿ô"},
+       { 1, 17, 25, "¼Í·â²ó¿ô"},
+       { 1, 13, 25, "Ê¿¶Ñ¥À¥á¡¼¥¸"},
+       {53, 20, -1, "ÀÖ³°Àþ»ëÎÏ:"},
        {26,  1, -1, "̾Á°  : "},
        { 1,  3, -1, "À­ÊÌ     : "},
        { 1,  4, -1, "¼ï²     : "},
@@ -1546,6 +1609,7 @@ static struct
        {29,  6, 21, "¼Ò²ñŪÃÏ°Ì"},
        {29,  7, 21, "°À­"},
        {29, 14, 21, "¶¯²½ÅÙ"},
+       {29, 16, 21, "¼¡¥ì¥Ù¥ë"},
 };
 #else
 = {
@@ -1558,7 +1622,7 @@ static struct
        { 1, 11, 25, "Posture"},
        { 1, 15, 25, "Shooting"},
        { 1, 16, 25, "Multiplier"},
-       {01, 20, 25, "Speed"},
+       { 1, 20, 25, "Speed"},
        { 1, 19, 25, "AC"},
        {29, 13, 21, "Level"},
        {29, 14, 21, "Experience"},
@@ -1569,18 +1633,18 @@ static struct
        {29, 10, 21, "Hit point"},
        {29, 11, 21, "SP (Mana)"},
        {29, 20, 21, "Play time"},
-       {54, 10, -1, "Fighting    : "},
-       {54, 11, -1, "Bows/Throw  : "},
-       {54, 12, -1, "Saving Throw: "},
-       {54, 13, -1, "Stealth     : "},
-       {54, 15, -1, "Perception  : "},
-       {54, 16, -1, "Searching   : "},
-       {54, 17, -1, "Disarming   : "},
-       {54, 18, -1, "Magic Device: "},
-       {01, 12, 25, "Blows/Round"},
-       {01, 17, 25, "Shots/Round"},
-       {01, 13, 25, "AverageDmg/Rnd"},
-       {54, 20, -1, "Infra-Vision: "},
+       {53, 10, -1, "Fighting   : "},
+       {53, 11, -1, "Bows/Throw : "},
+       {53, 12, -1, "SavingThrow: "},
+       {53, 13, -1, "Stealth    : "},
+       {53, 15, -1, "Perception : "},
+       {53, 16, -1, "Searching  : "},
+       {53, 17, -1, "Disarming  : "},
+       {53, 18, -1, "MagicDevice: "},
+       { 1, 12, 25, "Blows/Round"},
+       { 1, 17, 25, "Shots/Round"},
+       { 1, 13, 25, "AverageDmg/Rnd"},
+       {53, 20, -1, "Infra-Vision: "},
        {26,  1, -1, "Name  : "},
        { 1,  3, -1, "Sex      : "},
        { 1,  4, -1, "Race     : "},
@@ -1593,6 +1657,7 @@ static struct
        {29,  6, 21, "Social Class"},
        {29,  7, 21, "Align"},
        {29, 14, 21, "Construction"},
+       {29, 16, 21, "Const to Adv"},
 };
 #endif
 
@@ -1632,11 +1697,11 @@ static void display_player_one_line(int entry, cptr val, byte attr)
  */
 static void display_player_middle(void)
 {
-        char buf[160];
+       char buf[160];
        int show_tohit, show_todam;
        object_type *o_ptr;
        int tmul = 0;
-        int e;
+       int e;
 
        if(p_ptr->migite)
        {
@@ -1683,7 +1748,7 @@ static void display_player_middle(void)
                else
                        display_player_one_line(ENTRY_LEFT_HAND2, buf, TERM_L_BLUE);
        }
-       else if ((p_ptr->pclass == CLASS_MONK) && (empty_hands(TRUE) > 1))
+       else if ((p_ptr->pclass == CLASS_MONK) && (empty_hands(TRUE) & EMPTY_HAND_RARM))
        {
                int i;
                if (p_ptr->special_defense & KAMAE_MASK)
@@ -1719,13 +1784,13 @@ static void display_player_middle(void)
        if (object_known_p(o_ptr)) show_todam += o_ptr->to_d;
 
        if ((o_ptr->sval == SV_LIGHT_XBOW) || (o_ptr->sval == SV_HEAVY_XBOW))
-               show_tohit += (p_ptr->weapon_exp[0][o_ptr->sval])/400;
+               show_tohit += p_ptr->weapon_exp[0][o_ptr->sval] / 400;
        else
-               show_tohit += (p_ptr->weapon_exp[0][o_ptr->sval]-4000)/200;
+               show_tohit += (p_ptr->weapon_exp[0][o_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200;
 
        /* Range attacks */
        display_player_one_line(ENTRY_SHOOT_HIT_DAM, format("(%+d,%+d)", show_tohit, show_todam), TERM_L_BLUE);
-       
+
        if (inventory[INVEN_BOW].k_idx)
        {
                tmul = bow_tmul(inventory[INVEN_BOW].sval);
@@ -1744,7 +1809,6 @@ static void display_player_middle(void)
 
        /* Dump speed */
        {
-               bool is_fast = (p_ptr->fast || music_singing(MUSIC_SPEED) || music_singing(MUSIC_SHERO));
                int tmp_speed = 0;
                byte attr;
                int i;
@@ -1778,7 +1842,7 @@ static void display_player_middle(void)
 
                if (!p_ptr->riding)
                {
-                       if (is_fast) tmp_speed += 10;
+                       if (IS_FAST()) tmp_speed += 10;
                        if (p_ptr->slow) tmp_speed -= 10;
                        if (p_ptr->lightspeed) tmp_speed = 99;
                }
@@ -1824,7 +1888,7 @@ static void display_player_middle(void)
 
        /* Dump experience */
        if (p_ptr->prace == RACE_ANDROID) e = ENTRY_EXP_ANDR;
-        else e = ENTRY_CUR_EXP;
+       else e = ENTRY_CUR_EXP;
 
        if (p_ptr->exp >= p_ptr->max_exp)
                display_player_one_line(e, format("%ld", p_ptr->exp), TERM_L_GREEN);
@@ -1838,12 +1902,15 @@ static void display_player_middle(void)
                display_player_one_line(ENTRY_MAX_EXP, format("%ld", p_ptr->max_exp), TERM_L_GREEN);
 
        /* Dump exp to advance */
+       if (p_ptr->prace == RACE_ANDROID) e = ENTRY_EXP_TO_ADV_ANDR;
+       else e = ENTRY_EXP_TO_ADV;
+
        if (p_ptr->lev >= PY_MAX_LEVEL)
-               display_player_one_line(ENTRY_EXP_TO_ADV, "*****", TERM_L_GREEN);
-        else if (p_ptr->prace == RACE_ANDROID)
-               display_player_one_line(ENTRY_EXP_TO_ADV, format("%ld", (s32b)(player_exp_a[p_ptr->lev - 1] * p_ptr->expfact / 100L)), TERM_L_GREEN);
+               display_player_one_line(e, "*****", TERM_L_GREEN);
+       else if (p_ptr->prace == RACE_ANDROID)
+               display_player_one_line(e, format("%ld", (s32b)(player_exp_a[p_ptr->lev - 1] * p_ptr->expfact / 100L)), TERM_L_GREEN);
        else
-               display_player_one_line(ENTRY_EXP_TO_ADV, format("%ld", (s32b)(player_exp[p_ptr->lev - 1] * p_ptr->expfact / 100L)), TERM_L_GREEN);
+               display_player_one_line(e, format("%ld", (s32b)(player_exp[p_ptr->lev - 1] * p_ptr->expfact / 100L)), TERM_L_GREEN);
 
        /* Dump gold */
        display_player_one_line(ENTRY_GOLD, format("%ld", p_ptr->au), TERM_L_GREEN);
@@ -1874,7 +1941,7 @@ static void display_player_middle(void)
        /* Dump mana power */
        if (p_ptr->csp >= p_ptr->msp) 
                display_player_one_line(ENTRY_SP, format("%4d/%4d", p_ptr->csp , p_ptr->msp), TERM_L_GREEN);
-       else if (p_ptr->csp > (p_ptr->msp * hitpoint_warn) / 10) 
+       else if (p_ptr->csp > (p_ptr->msp * mana_warn) / 10) 
                display_player_one_line(ENTRY_SP, format("%4d/%4d", p_ptr->csp , p_ptr->msp), TERM_YELLOW);
        else
                display_player_one_line(ENTRY_SP, format("%4d/%4d", p_ptr->csp , p_ptr->msp), TERM_RED);
@@ -1905,117 +1972,97 @@ static cptr likert(int x, int y)
        {
                likert_color = TERM_L_DARK;
 #ifdef JP
-return ("ºÇÄã");
+               return "ºÇÄã";
 #else
-               return ("Very Bad");
+               return "Very Bad";
 #endif
-
        }
 
        /* Analyze the value */
        switch ((x / y))
        {
-               case 0:
-               case 1:
-               {
-                       likert_color = TERM_RED;
+       case 0:
+       case 1:
+               likert_color = TERM_RED;
 #ifdef JP
-return ("°­¤¤");
+               return "°­¤¤";
 #else
-                       return ("Bad");
+               return "Bad";
 #endif
 
-               }
-               case 2:
-               {
-                       likert_color = TERM_L_RED;
+       case 2:
+               likert_color = TERM_L_RED;
 #ifdef JP
-return ("Îô¤ë");
+               return "Îô¤ë";
 #else
-                       return ("Poor");
+               return "Poor";
 #endif
 
-               }
-               case 3:
-               case 4:
-               {
-                       likert_color = TERM_ORANGE;
+       case 3:
+       case 4:
+               likert_color = TERM_ORANGE;
 #ifdef JP
-return ("ÉáÄÌ");
+               return "ÉáÄÌ";
 #else
-                       return ("Fair");
+               return "Fair";
 #endif
 
-               }
-               case 5:
-               {
-                       likert_color = TERM_YELLOW;
+       case 5:
+               likert_color = TERM_YELLOW;
 #ifdef JP
-return ("Îɤ¤");
+               return "Îɤ¤";
 #else
-                       return ("Good");
+               return "Good";
 #endif
 
-               }
-               case 6:
-               {
-                       likert_color = TERM_YELLOW;
+       case 6:
+               likert_color = TERM_YELLOW;
 #ifdef JP
-return ("ÂçÊÑÎɤ¤");
+               return "ÂçÊÑÎɤ¤";
 #else
-                       return ("Very Good");
+               return "Very Good";
 #endif
 
-               }
-               case 7:
-               case 8:
-               {
-                       likert_color = TERM_L_GREEN;
+       case 7:
+       case 8:
+               likert_color = TERM_L_GREEN;
 #ifdef JP
-return ("Âî±Û");
+               return "Âî±Û";
 #else
-                       return ("Excellent");
+               return "Excellent";
 #endif
 
-               }
-               case 9:
-               case 10:
-               case 11:
-               case 12:
-               case 13:
-               {
-                       likert_color = TERM_GREEN;
+       case 9:
+       case 10:
+       case 11:
+       case 12:
+       case 13:
+               likert_color = TERM_GREEN;
 #ifdef JP
-return ("Ķ±Û");
+               return "Ķ±Û";
 #else
-                       return ("Superb");
+               return "Superb";
 #endif
 
-               }
-               case 14:
-               case 15:
-               case 16:
-               case 17:
-               {
-                       likert_color = TERM_BLUE;
+       case 14:
+       case 15:
+       case 16:
+       case 17:
+               likert_color = TERM_BLUE;
 #ifdef JP
-return ("¥«¥ª¥¹¥é¥ó¥¯");
+               return "±ÑͺŪ";
 #else
-                       return ("Chaos Rank");
+               return "Heroic";
 #endif
 
-               }
-               default:
-               {
-                       likert_color = TERM_VIOLET;
+       default:
+               likert_color = TERM_VIOLET;
 #ifdef JP
-sprintf(dummy,"¥¢¥ó¥Ð¡¼ [%d]", (int) ((((x/y)-17)*5)/2));
+               sprintf(dummy, "ÅÁÀâŪ[%d]", (int)((((x / y) - 17) * 5) / 2));
 #else
-                       sprintf(dummy,"Amber [%d]", (int) ((((x/y)-17)*5)/2));
+               sprintf(dummy, "Legendary[%d]", (int)((((x / y) - 17) * 5) / 2));
 #endif
-
-                       return dummy;
-               }
+               return dummy;
        }
 }
 
@@ -2082,10 +2129,10 @@ static void display_player_various(void)
                shot_frac = 0;
        }
 
-       for(i = 0; i< 2; i++)
+       for(i = 0; i < 2; i++)
        {
-               damage[i] = p_ptr->dis_to_d[i]*100;
-               if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(TRUE) > 1))
+               damage[i] = p_ptr->dis_to_d[i] * 100;
+               if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(TRUE) & EMPTY_HAND_RARM))
                {
                        int level = p_ptr->lev;
                        if (i)
@@ -2103,27 +2150,30 @@ static void display_player_various(void)
                }
                else
                {
+                       o_ptr = &inventory[INVEN_RARM + i];
+
                        /* Average damage per round */
-                       o_ptr = &inventory[INVEN_RARM+i];
-                       if (object_known_p(o_ptr)) damage[i] += o_ptr->to_d*100;
-                       basedam = (o_ptr->dd * (o_ptr->ds + 1))*50;
-                       object_flags(o_ptr, flgs);
-                       if ((o_ptr->ident & IDENT_MENTAL) && ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)))
+                       if (o_ptr->k_idx)
                        {
-                               /* vorpal blade */
-                               basedam *= 5;
-                               basedam /= 3;
-                       }
-                       else if (object_known_p(o_ptr) && (have_flag(flgs, TR_VORPAL)))
-                       {
-                               /* vorpal flag only */
-                               basedam *= 11;
-                               basedam /= 9;
+                               if (object_known_p(o_ptr)) damage[i] += o_ptr->to_d * 100;
+                               basedam = ((o_ptr->dd + p_ptr->to_dd[i]) * (o_ptr->ds + p_ptr->to_ds[i] + 1)) * 50;
+                               object_flags_known(o_ptr, flgs);
+                               if ((o_ptr->ident & IDENT_MENTAL) && ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)))
+                               {
+                                       /* vorpal blade */
+                                       basedam *= 5;
+                                       basedam /= 3;
+                               }
+                               else if (have_flag(flgs, TR_VORPAL))
+                               {
+                                       /* vorpal flag only */
+                                       basedam *= 11;
+                                       basedam /= 9;
+                               }
+                               if ((p_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
+                                       basedam = basedam * 7 / 2;
                        }
-                       if (object_known_p(o_ptr) && (p_ptr->pclass != CLASS_SAMURAI) && (have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
-                               basedam = basedam * 7 / 2;
-                       if (p_ptr->riding && (o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE)))
-                               basedam = basedam*(o_ptr->dd+2)/o_ptr->dd;
+                       else basedam = 0;
                }
                damage[i] += basedam;
                if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) damage[i] = 1;
@@ -2151,7 +2201,8 @@ static void display_player_various(void)
        desc = likert(xsav, 7);
        display_player_one_line(ENTRY_SKILL_SAVING, desc, likert_color);
 
-       desc = likert(xstl, 1);
+       /* Hack -- 0 is "minimum stealth value", so print "Very Bad" */
+       desc = likert((xstl > 0) ? xstl : -1, 1);
        display_player_one_line(ENTRY_SKILL_STEALTH, desc, likert_color);
 
        desc = likert(xfos, 6);
@@ -2322,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);
@@ -2571,7 +2622,7 @@ static void player_flags(u32b flgs[TR_FLAG_SIZE])
                add_flag(flgs, TR_RES_BLIND);
                add_flag(flgs, TR_RES_CONF);
                add_flag(flgs, TR_HOLD_LIFE);
-               add_flag(flgs, TR_LITE);
+               if (p_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE);
                if (p_ptr->lev > 9)
                        add_flag(flgs, TR_SPEED);
        }
@@ -2628,7 +2679,7 @@ static void player_flags(u32b flgs[TR_FLAG_SIZE])
 }
 
 
-static void tim_player_flags(u32b flgs[TR_FLAG_SIZE], bool im_and_res)
+static void tim_player_flags(u32b flgs[TR_FLAG_SIZE])
 {
        int i;
 
@@ -2636,48 +2687,28 @@ static void tim_player_flags(u32b flgs[TR_FLAG_SIZE], bool im_and_res)
        for (i = 0; i < TR_FLAG_SIZE; i++)
                flgs[i] = 0L;
 
-       if (p_ptr->hero || p_ptr->shero || music_singing(MUSIC_HERO) || music_singing(MUSIC_SHERO))
+       if (IS_HERO() || p_ptr->shero)
                add_flag(flgs, TR_RES_FEAR);
        if (p_ptr->tim_invis)
                add_flag(flgs, TR_SEE_INVIS);
        if (p_ptr->tim_regen)
                add_flag(flgs, TR_REGEN);
-       if (p_ptr->tim_esp || music_singing(MUSIC_MIND))
+       if (IS_TIM_ESP())
                add_flag(flgs, TR_TELEPATHY);
-       if (p_ptr->fast || p_ptr->slow || music_singing(MUSIC_SPEED) || music_singing(MUSIC_SHERO))
+       if (IS_FAST() || p_ptr->slow)
                add_flag(flgs, TR_SPEED);
-       if  ((p_ptr->special_defense & KATA_MUSOU) || music_singing(MUSIC_RESIST))
-       {
-               add_flag(flgs, TR_RES_FIRE);
-               add_flag(flgs, TR_RES_COLD);
+
+       if (IS_OPPOSE_ACID() && !(p_ptr->special_defense & DEFENSE_ACID) && !(prace_is_(RACE_YEEK) && (p_ptr->lev > 19)))
                add_flag(flgs, TR_RES_ACID);
+       if (IS_OPPOSE_ELEC() && !(p_ptr->special_defense & DEFENSE_ELEC))
                add_flag(flgs, TR_RES_ELEC);
+       if (IS_OPPOSE_FIRE() && !(p_ptr->special_defense & DEFENSE_FIRE))
+               add_flag(flgs, TR_RES_FIRE);
+       if (IS_OPPOSE_COLD() && !(p_ptr->special_defense & DEFENSE_COLD))
+               add_flag(flgs, TR_RES_COLD);
+       if (IS_OPPOSE_POIS())
                add_flag(flgs, TR_RES_POIS);
-       }
-       if (im_and_res)
-       {
-               if (p_ptr->oppose_acid && !(p_ptr->special_defense & DEFENSE_ACID) && !((prace_is_(RACE_YEEK)) && (p_ptr->lev > 19)))
-                       add_flag(flgs, TR_RES_ACID);
-               if (p_ptr->oppose_elec && !(p_ptr->special_defense & DEFENSE_ELEC))
-                       add_flag(flgs, TR_RES_ELEC);
-               if (p_ptr->oppose_fire && !(p_ptr->special_defense & DEFENSE_FIRE))
-                       add_flag(flgs, TR_RES_FIRE);
-               if (p_ptr->oppose_cold && !(p_ptr->special_defense & DEFENSE_COLD))
-                       add_flag(flgs, TR_RES_COLD);
-       }
-       else
-       {
-               if (p_ptr->oppose_acid)
-                       add_flag(flgs, TR_RES_ACID);
-               if (p_ptr->oppose_elec)
-                       add_flag(flgs, TR_RES_ELEC);
-               if (p_ptr->oppose_fire)
-                       add_flag(flgs, TR_RES_FIRE);
-               if (p_ptr->oppose_cold)
-                       add_flag(flgs, TR_RES_COLD);
-       }
-       if (p_ptr->oppose_pois)
-               add_flag(flgs, TR_RES_POIS);
+
        if (p_ptr->special_attack & ATTACK_ACID)
                add_flag(flgs, TR_BRAND_ACID);
        if (p_ptr->special_attack & ATTACK_ELEC)
@@ -2699,9 +2730,8 @@ static void tim_player_flags(u32b flgs[TR_FLAG_SIZE], bool im_and_res)
        if (p_ptr->wraith_form)
                add_flag(flgs, TR_REFLECT);
        /* by henkma */
-       if (p_ptr->tim_reflect){
+       if (p_ptr->tim_reflect)
                add_flag(flgs, TR_REFLECT);
-       }
 
        if (p_ptr->magicdef)
        {
@@ -2772,9 +2802,9 @@ static void display_player_equippy(int y, int x, u16b mode)
 
        object_type *o_ptr;
 
-        /* Weapon flags need only two column */
-        if (mode & DP_WP) max_i = INVEN_LARM + 1;
-        else max_i = INVEN_TOTAL;
+       /* Weapon flags need only two column */
+       if (mode & DP_WP) max_i = INVEN_LARM + 1;
+       else max_i = INVEN_TOTAL;
 
        /* Dump equippy chars */
        for (i = INVEN_RARM; i < max_i; i++)
@@ -2830,10 +2860,10 @@ static void known_obj_immunity(u32b flgs[TR_FLAG_SIZE])
                /* Known flags */
                object_flags_known(o_ptr, o_flgs);
 
-               if (have_flag(flgs, TR_IM_ACID)) add_flag(flgs, TR_RES_ACID);
-               if (have_flag(flgs, TR_IM_ELEC)) add_flag(flgs, TR_RES_ELEC);
-               if (have_flag(flgs, TR_IM_FIRE)) add_flag(flgs, TR_RES_FIRE);
-               if (have_flag(flgs, TR_IM_COLD)) add_flag(flgs, TR_RES_COLD);
+               if (have_flag(o_flgs, TR_IM_ACID)) add_flag(flgs, TR_RES_ACID);
+               if (have_flag(o_flgs, TR_IM_ELEC)) add_flag(flgs, TR_RES_ELEC);
+               if (have_flag(o_flgs, TR_IM_FIRE)) add_flag(flgs, TR_RES_FIRE);
+               if (have_flag(o_flgs, TR_IM_COLD)) add_flag(flgs, TR_RES_COLD);
        }
 }
 
@@ -2904,12 +2934,12 @@ static void player_vuln_flags(u32b flgs[TR_FLAG_SIZE])
  * A struct for storing misc. flags
  */
 typedef struct {
-        u32b player_flags[TR_FLAG_SIZE];
-        u32b tim_player_flags[TR_FLAG_SIZE];
-        u32b player_imm[TR_FLAG_SIZE];
-        u32b tim_player_imm[TR_FLAG_SIZE];
-        u32b player_vuln[TR_FLAG_SIZE];
-        u32b known_obj_imm[TR_FLAG_SIZE];
+       u32b player_flags[TR_FLAG_SIZE];
+       u32b tim_player_flags[TR_FLAG_SIZE];
+       u32b player_imm[TR_FLAG_SIZE];
+       u32b tim_player_imm[TR_FLAG_SIZE];
+       u32b player_vuln[TR_FLAG_SIZE];
+       u32b known_obj_imm[TR_FLAG_SIZE];
 } all_player_flags;
 
 
@@ -2921,12 +2951,12 @@ static void display_flag_aux(int row, int col, cptr header,
 {
        int     i;
        bool    vuln = FALSE;
-        int max_i;
+       int max_i;
 
        if (have_flag(f->player_vuln, flag1) &&
-            !(have_flag(f->known_obj_imm, flag1) ||
-              have_flag(f->player_imm, flag1) ||
-              have_flag(f->tim_player_imm, flag1)))
+           !(have_flag(f->known_obj_imm, flag1) ||
+             have_flag(f->player_imm, flag1) ||
+             have_flag(f->tim_player_imm, flag1)))
                vuln = TRUE;
 
        /* Header */
@@ -2935,14 +2965,14 @@ static void display_flag_aux(int row, int col, cptr header,
        /* Advance */
        col += strlen(header) + 1;
 
-        /* Weapon flags need only two column */
-        if (mode & DP_WP) max_i = INVEN_LARM + 1;
-        else max_i = INVEN_TOTAL;
+       /* Weapon flags need only two column */
+       if (mode & DP_WP) max_i = INVEN_LARM + 1;
+       else max_i = INVEN_TOTAL;
 
        /* Check equipment */
        for (i = INVEN_RARM; i < max_i; i++)
        {
-                u32b flgs[TR_FLAG_SIZE];
+               u32b flgs[TR_FLAG_SIZE];
                object_type *o_ptr;
 
                /* Object */
@@ -2952,30 +2982,30 @@ static void display_flag_aux(int row, int col, cptr header,
                object_flags_known(o_ptr, flgs);
 
                /* Default */
-                if (!(mode & DP_IMM))
-                        c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
+               if (!(mode & DP_IMM))
+                       c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
 
                /* Check flags */
-                if (mode & DP_CURSE)
-                {
-                        if ((mode & DP_CURSE) && (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE)))
-                                c_put_str(TERM_WHITE, "+", row, col);
-                        if ((mode & DP_CURSE) && (o_ptr->curse_flags & TRC_PERMA_CURSE))
-                                c_put_str(TERM_WHITE, "*", row, col);
-                }
-                else
-                {
-                        if (have_flag(flgs, flag1))
-                                c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE),
-                                          (mode & DP_IMM) ? "*" : "+", row, col);
-                }
+               if (mode & DP_CURSE)
+               {
+                       if ((mode & DP_CURSE) && (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE)))
+                               c_put_str(TERM_WHITE, "+", row, col);
+                       if ((mode & DP_CURSE) && (o_ptr->curse_flags & TRC_PERMA_CURSE))
+                               c_put_str(TERM_WHITE, "*", row, col);
+               }
+               else
+               {
+                       if (have_flag(flgs, flag1))
+                               c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE),
+                                         (mode & DP_IMM) ? "*" : "+", row, col);
+               }
 
                /* Advance */
                col++;
        }
 
-        /* Assume that player flag is already written */
-        if (mode & DP_IMM) return;
+       /* Assume that player flag is already written */
+       if (mode & DP_IMM) return;
 
        /* Default */
        c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
@@ -3003,11 +3033,11 @@ static void display_player_flag_info(void)
        int row;
        int col;
 
-        all_player_flags f;
+       all_player_flags f;
 
-        /* Extract flags and store */
+       /* Extract flags and store */
        player_flags(f.player_flags);
-       tim_player_flags(f.tim_player_flags, TRUE);
+       tim_player_flags(f.tim_player_flags);
        player_immunity(f.player_imm);
        tim_player_immunity(f.tim_player_imm);
        known_obj_immunity(f.known_obj_imm);
@@ -3132,11 +3162,11 @@ static void display_player_other_flag_info(void)
        int row;
        int col;
 
-        all_player_flags f;
+       all_player_flags f;
 
-        /* Extract flags and store */
+       /* Extract flags and store */
        player_flags(f.player_flags);
-       tim_player_flags(f.tim_player_flags, TRUE);
+       tim_player_flags(f.tim_player_flags);
        player_immunity(f.player_imm);
        tim_player_immunity(f.tim_player_imm);
        known_obj_immunity(f.known_obj_imm);
@@ -3152,63 +3182,63 @@ static void display_player_other_flag_info(void)
        c_put_str(TERM_WHITE, "ab@", row-1, col+12);
 
 #ifdef JP
-        display_flag_aux(row+ 0, col, "¼Ù°­ ÇÜÂÇ :", TR_SLAY_EVIL, &f, DP_WP);
-        display_flag_aux(row+ 0, col, "¼Ù°­ ÇÜÂÇ :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 1, col, "ÉÔ»à ÇÜÂÇ :", TR_SLAY_UNDEAD, &f, DP_WP);
-        display_flag_aux(row+ 1, col, "ÉÔ»à ÇÜÂÇ :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 2, col, "°­Ëâ ÇÜÂÇ :", TR_SLAY_DEMON, &f, DP_WP);
-        display_flag_aux(row+ 2, col, "°­Ëâ ÇÜÂÇ :", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 3, col, "ζ ÇÜÂÇ   :", TR_SLAY_DRAGON, &f, DP_WP);
-        display_flag_aux(row+ 3, col, "ζ ÇÜÂÇ   :", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 4, col, "¿Í´Ö ÇÜÂÇ :", TR_SLAY_HUMAN, &f, DP_WP);
-        display_flag_aux(row+ 4, col, "¿Í´Ö ÇÜÂÇ :", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 5, col, "ưʪ ÇÜÂÇ :", TR_SLAY_ANIMAL, &f, DP_WP);
-        display_flag_aux(row+ 5, col, "ưʪ ÇÜÂÇ :", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 6, col, "¥ª¡¼¥¯ÇÜÂÇ:", TR_SLAY_ORC, &f, DP_WP);
-        display_flag_aux(row+ 6, col, "¥ª¡¼¥¯ÇÜÂÇ:", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 7, col, "¥È¥í¥ëÇÜÂÇ:", TR_SLAY_TROLL, &f, DP_WP);
-        display_flag_aux(row+ 7, col, "¥È¥í¥ëÇÜÂÇ:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 8, col, "µð¿Í ÇÜÂÇ :", TR_SLAY_GIANT, &f, DP_WP);
-        display_flag_aux(row+ 8, col, "µð¿Í ÇÜÂÇ :", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 9, col, "Íϲò      :", TR_BRAND_ACID, &f, DP_WP);
-        display_flag_aux(row+10, col, "ÅÅ·â      :", TR_BRAND_ELEC, &f, DP_WP);
-        display_flag_aux(row+11, col, "¾Æ´þ      :", TR_BRAND_FIRE, &f, DP_WP);
-        display_flag_aux(row+12, col, "Åà·ë      :", TR_BRAND_COLD, &f, DP_WP);
-        display_flag_aux(row+13, col, "ÆÇ»¦      :", TR_BRAND_POIS, &f, DP_WP);
-        display_flag_aux(row+14, col, "ÀÚ¤ìÌ£    :", TR_VORPAL, &f, DP_WP);
-        display_flag_aux(row+15, col, "ÃÏ¿Ì      :", TR_IMPACT, &f, DP_WP);
-        display_flag_aux(row+16, col, "µÛ·ì      :", TR_VAMPIRIC, &f, DP_WP);
-        display_flag_aux(row+17, col, "¥«¥ª¥¹¸ú²Ì:", TR_CHAOTIC, &f, DP_WP);
-        display_flag_aux(row+18, col, "ÍýÎÏ      :", TR_FORCE_WEAPON, &f, DP_WP);
-#else
-        display_flag_aux(row+ 0, col, "Slay Evil :", TR_SLAY_EVIL, &f, DP_WP);
-        display_flag_aux(row+ 0, col, "Slay Evil :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 1, col, "Slay Und. :", TR_SLAY_UNDEAD, &f, DP_WP);
-        display_flag_aux(row+ 1, col, "Slay Und. :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 2, col, "Slay Demon:", TR_SLAY_DEMON, &f, DP_WP);
-        display_flag_aux(row+ 2, col, "Slay Demon:", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 3, col, "Slay Drag.:", TR_SLAY_DRAGON, &f, DP_WP);
-        display_flag_aux(row+ 3, col, "Slay Drag.:", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 4, col, "Slay Human:", TR_SLAY_HUMAN, &f, DP_WP);
-        display_flag_aux(row+ 4, col, "Slay Human:", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 5, col, "Slay Anim.:", TR_SLAY_ANIMAL, &f, DP_WP);
-        display_flag_aux(row+ 5, col, "Slay Anim.:", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 6, col, "Slay Orc  :", TR_SLAY_ORC, &f, DP_WP);
-        display_flag_aux(row+ 6, col, "Slay Orc  :", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 7, col, "Slay Troll:", TR_SLAY_TROLL, &f, DP_WP);
-        display_flag_aux(row+ 7, col, "Slay Troll:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 8, col, "Slay Giant:", TR_SLAY_GIANT, &f, DP_WP);
-        display_flag_aux(row+ 8, col, "Slay Giant:", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
-        display_flag_aux(row+ 9, col, "Acid Brand:", TR_BRAND_ACID, &f, DP_WP);
-        display_flag_aux(row+10, col, "Elec Brand:", TR_BRAND_ELEC, &f, DP_WP);
-        display_flag_aux(row+11, col, "Fire Brand:", TR_BRAND_FIRE, &f, DP_WP);
-        display_flag_aux(row+12, col, "Cold Brand:", TR_BRAND_COLD, &f, DP_WP);
-        display_flag_aux(row+13, col, "Poison Brd:", TR_BRAND_POIS, &f, DP_WP);
-        display_flag_aux(row+14, col, "Sharpness :", TR_VORPAL, &f, DP_WP);
-        display_flag_aux(row+15, col, "Quake     :", TR_IMPACT, &f, DP_WP);
-        display_flag_aux(row+16, col, "Vampicic  :", TR_VAMPIRIC, &f, DP_WP);
-        display_flag_aux(row+17, col, "Chatic    :", TR_CHAOTIC, &f, DP_WP);
-        display_flag_aux(row+18, col, "Force Wep.:", TR_FORCE_WEAPON, &f, DP_WP);
+       display_flag_aux(row+ 0, col, "¼Ù°­ ÇÜÂÇ :", TR_SLAY_EVIL, &f, DP_WP);
+       display_flag_aux(row+ 0, col, "¼Ù°­ ÇÜÂÇ :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 1, col, "ÉÔ»à ÇÜÂÇ :", TR_SLAY_UNDEAD, &f, DP_WP);
+       display_flag_aux(row+ 1, col, "ÉÔ»à ÇÜÂÇ :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 2, col, "°­Ëâ ÇÜÂÇ :", TR_SLAY_DEMON, &f, DP_WP);
+       display_flag_aux(row+ 2, col, "°­Ëâ ÇÜÂÇ :", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 3, col, "ζ ÇÜÂÇ   :", TR_SLAY_DRAGON, &f, DP_WP);
+       display_flag_aux(row+ 3, col, "ζ ÇÜÂÇ   :", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 4, col, "¿Í´Ö ÇÜÂÇ :", TR_SLAY_HUMAN, &f, DP_WP);
+       display_flag_aux(row+ 4, col, "¿Í´Ö ÇÜÂÇ :", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 5, col, "ưʪ ÇÜÂÇ :", TR_SLAY_ANIMAL, &f, DP_WP);
+       display_flag_aux(row+ 5, col, "ưʪ ÇÜÂÇ :", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 6, col, "¥ª¡¼¥¯ÇÜÂÇ:", TR_SLAY_ORC, &f, DP_WP);
+       display_flag_aux(row+ 6, col, "¥ª¡¼¥¯ÇÜÂÇ:", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 7, col, "¥È¥í¥ëÇÜÂÇ:", TR_SLAY_TROLL, &f, DP_WP);
+       display_flag_aux(row+ 7, col, "¥È¥í¥ëÇÜÂÇ:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 8, col, "µð¿Í ÇÜÂÇ :", TR_SLAY_GIANT, &f, DP_WP);
+       display_flag_aux(row+ 8, col, "µð¿Í ÇÜÂÇ :", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 9, col, "Íϲò      :", TR_BRAND_ACID, &f, DP_WP);
+       display_flag_aux(row+10, col, "ÅÅ·â      :", TR_BRAND_ELEC, &f, DP_WP);
+       display_flag_aux(row+11, col, "¾Æ´þ      :", TR_BRAND_FIRE, &f, DP_WP);
+       display_flag_aux(row+12, col, "Åà·ë      :", TR_BRAND_COLD, &f, DP_WP);
+       display_flag_aux(row+13, col, "ÆÇ»¦      :", TR_BRAND_POIS, &f, DP_WP);
+       display_flag_aux(row+14, col, "ÀÚ¤ìÌ£    :", TR_VORPAL, &f, DP_WP);
+       display_flag_aux(row+15, col, "ÃÏ¿Ì      :", TR_IMPACT, &f, DP_WP);
+       display_flag_aux(row+16, col, "µÛ·ì      :", TR_VAMPIRIC, &f, DP_WP);
+       display_flag_aux(row+17, col, "¥«¥ª¥¹¸ú²Ì:", TR_CHAOTIC, &f, DP_WP);
+       display_flag_aux(row+18, col, "ÍýÎÏ      :", TR_FORCE_WEAPON, &f, DP_WP);
+#else
+       display_flag_aux(row+ 0, col, "Slay Evil :", TR_SLAY_EVIL, &f, DP_WP);
+       display_flag_aux(row+ 0, col, "Slay Evil :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 1, col, "Slay Und. :", TR_SLAY_UNDEAD, &f, DP_WP);
+       display_flag_aux(row+ 1, col, "Slay Und. :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 2, col, "Slay Demon:", TR_SLAY_DEMON, &f, DP_WP);
+       display_flag_aux(row+ 2, col, "Slay Demon:", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 3, col, "Slay Drag.:", TR_SLAY_DRAGON, &f, DP_WP);
+       display_flag_aux(row+ 3, col, "Slay Drag.:", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 4, col, "Slay Human:", TR_SLAY_HUMAN, &f, DP_WP);
+       display_flag_aux(row+ 4, col, "Slay Human:", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 5, col, "Slay Anim.:", TR_SLAY_ANIMAL, &f, DP_WP);
+       display_flag_aux(row+ 5, col, "Slay Anim.:", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 6, col, "Slay Orc  :", TR_SLAY_ORC, &f, DP_WP);
+       display_flag_aux(row+ 6, col, "Slay Orc  :", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 7, col, "Slay Troll:", TR_SLAY_TROLL, &f, DP_WP);
+       display_flag_aux(row+ 7, col, "Slay Troll:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 8, col, "Slay Giant:", TR_SLAY_GIANT, &f, DP_WP);
+       display_flag_aux(row+ 8, col, "Slay Giant:", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
+       display_flag_aux(row+ 9, col, "Acid Brand:", TR_BRAND_ACID, &f, DP_WP);
+       display_flag_aux(row+10, col, "Elec Brand:", TR_BRAND_ELEC, &f, DP_WP);
+       display_flag_aux(row+11, col, "Fire Brand:", TR_BRAND_FIRE, &f, DP_WP);
+       display_flag_aux(row+12, col, "Cold Brand:", TR_BRAND_COLD, &f, DP_WP);
+       display_flag_aux(row+13, col, "Poison Brd:", TR_BRAND_POIS, &f, DP_WP);
+       display_flag_aux(row+14, col, "Sharpness :", TR_VORPAL, &f, DP_WP);
+       display_flag_aux(row+15, col, "Quake     :", TR_IMPACT, &f, DP_WP);
+       display_flag_aux(row+16, col, "Vampiric  :", TR_VAMPIRIC, &f, DP_WP);
+       display_flag_aux(row+17, col, "Chaotic   :", TR_CHAOTIC, &f, DP_WP);
+       display_flag_aux(row+18, col, "Force Wep.:", TR_FORCE_WEAPON, &f, DP_WP);
 #endif
 
 
@@ -3221,45 +3251,45 @@ static void display_player_other_flag_info(void)
        c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+12);
 
 #ifdef JP
-        display_flag_aux(row+ 0, col, "¥Æ¥ì¥Ñ¥·¡¼:", TR_TELEPATHY, &f, 0);
-        display_flag_aux(row+ 1, col, "¼Ù°­ESP   :", TR_ESP_EVIL, &f, 0);
-        display_flag_aux(row+ 2, col, "̵À¸ÊªESP :", TR_ESP_NONLIVING, &f, 0);
-        display_flag_aux(row+ 3, col, "Á±ÎÉESP   :", TR_ESP_GOOD, &f, 0);
-        display_flag_aux(row+ 4, col, "ÉÔ»àESP   :", TR_ESP_UNDEAD, &f, 0);
-        display_flag_aux(row+ 5, col, "°­ËâESP   :", TR_ESP_DEMON, &f, 0);
-        display_flag_aux(row+ 6, col, "ζESP     :", TR_ESP_DRAGON, &f, 0);
-        display_flag_aux(row+ 7, col, "¿Í´ÖESP   :", TR_ESP_HUMAN, &f, 0);
-        display_flag_aux(row+ 8, col, "ưʪESP   :", TR_ESP_ANIMAL, &f, 0);
-        display_flag_aux(row+ 9, col, "¥ª¡¼¥¯ESP :", TR_ESP_ORC, &f, 0);
-        display_flag_aux(row+10, col, "¥È¥í¥ëESP :", TR_ESP_TROLL, &f, 0);
-        display_flag_aux(row+11, col, "µð¿ÍESP   :", TR_ESP_GIANT, &f, 0);
-
-        display_flag_aux(row+13, col, "ÏÓÎÏ°Ý»ý  :", TR_SUST_STR, &f, 0);
-        display_flag_aux(row+14, col, "ÃÎÎÏ°Ý»ý  :", TR_SUST_INT, &f, 0);
-        display_flag_aux(row+15, col, "¸­¤µ°Ý»ý  :", TR_SUST_WIS, &f, 0);
-        display_flag_aux(row+16, col, "´ïÍÑ°Ý»ý  :", TR_SUST_DEX, &f, 0);
-        display_flag_aux(row+17, col, "Âѵװݻý  :", TR_SUST_CON, &f, 0);
-        display_flag_aux(row+18, col, "Ì¥ÎÏ°Ý»ý  :", TR_SUST_CHR, &f, 0);
-#else
-        display_flag_aux(row+ 0, col, "Telepathy :", TR_TELEPATHY, &f, 0);
-        display_flag_aux(row+ 1, col, "ESP Evil  :", TR_ESP_EVIL, &f, 0);
-        display_flag_aux(row+ 2, col, "ESP Noliv.:", TR_ESP_NONLIVING, &f, 0);
-        display_flag_aux(row+ 3, col, "ESP Good  :", TR_ESP_GOOD, &f, 0);
-        display_flag_aux(row+ 4, col, "ESP Undead:", TR_ESP_UNDEAD, &f, 0);
-        display_flag_aux(row+ 5, col, "ESP Demon :", TR_ESP_DEMON, &f, 0);
-        display_flag_aux(row+ 6, col, "ESP Dragon:", TR_ESP_DRAGON, &f, 0);
-        display_flag_aux(row+ 7, col, "ESP Human :", TR_ESP_HUMAN, &f, 0);
-        display_flag_aux(row+ 8, col, "ESP Animal:", TR_ESP_ANIMAL, &f, 0);
-        display_flag_aux(row+ 9, col, "ESP Orc   :", TR_ESP_ORC, &f, 0);
-        display_flag_aux(row+10, col, "ESP Troll :", TR_ESP_TROLL, &f, 0);
-        display_flag_aux(row+11, col, "ESP Giant :", TR_ESP_GIANT, &f, 0);
-
-        display_flag_aux(row+13, col, "Sust Str  :", TR_SUST_STR, &f, 0);
-        display_flag_aux(row+14, col, "Sust Int  :", TR_SUST_INT, &f, 0);
-        display_flag_aux(row+15, col, "Sust Wis  :", TR_SUST_WIS, &f, 0);
-        display_flag_aux(row+16, col, "Sust Dex  :", TR_SUST_DEX, &f, 0);
-        display_flag_aux(row+17, col, "Sust Con  :", TR_SUST_CON, &f, 0);
-        display_flag_aux(row+18, col, "Sust Chr  :", TR_SUST_CHR, &f, 0);
+       display_flag_aux(row+ 0, col, "¥Æ¥ì¥Ñ¥·¡¼:", TR_TELEPATHY, &f, 0);
+       display_flag_aux(row+ 1, col, "¼Ù°­ESP   :", TR_ESP_EVIL, &f, 0);
+       display_flag_aux(row+ 2, col, "̵À¸ÊªESP :", TR_ESP_NONLIVING, &f, 0);
+       display_flag_aux(row+ 3, col, "Á±ÎÉESP   :", TR_ESP_GOOD, &f, 0);
+       display_flag_aux(row+ 4, col, "ÉÔ»àESP   :", TR_ESP_UNDEAD, &f, 0);
+       display_flag_aux(row+ 5, col, "°­ËâESP   :", TR_ESP_DEMON, &f, 0);
+       display_flag_aux(row+ 6, col, "ζESP     :", TR_ESP_DRAGON, &f, 0);
+       display_flag_aux(row+ 7, col, "¿Í´ÖESP   :", TR_ESP_HUMAN, &f, 0);
+       display_flag_aux(row+ 8, col, "ưʪESP   :", TR_ESP_ANIMAL, &f, 0);
+       display_flag_aux(row+ 9, col, "¥ª¡¼¥¯ESP :", TR_ESP_ORC, &f, 0);
+       display_flag_aux(row+10, col, "¥È¥í¥ëESP :", TR_ESP_TROLL, &f, 0);
+       display_flag_aux(row+11, col, "µð¿ÍESP   :", TR_ESP_GIANT, &f, 0);
+
+       display_flag_aux(row+13, col, "ÏÓÎÏ°Ý»ý  :", TR_SUST_STR, &f, 0);
+       display_flag_aux(row+14, col, "ÃÎÎÏ°Ý»ý  :", TR_SUST_INT, &f, 0);
+       display_flag_aux(row+15, col, "¸­¤µ°Ý»ý  :", TR_SUST_WIS, &f, 0);
+       display_flag_aux(row+16, col, "´ïÍÑ°Ý»ý  :", TR_SUST_DEX, &f, 0);
+       display_flag_aux(row+17, col, "Âѵװݻý  :", TR_SUST_CON, &f, 0);
+       display_flag_aux(row+18, col, "Ì¥ÎÏ°Ý»ý  :", TR_SUST_CHR, &f, 0);
+#else
+       display_flag_aux(row+ 0, col, "Telepathy :", TR_TELEPATHY, &f, 0);
+       display_flag_aux(row+ 1, col, "ESP Evil  :", TR_ESP_EVIL, &f, 0);
+       display_flag_aux(row+ 2, col, "ESP Noliv.:", TR_ESP_NONLIVING, &f, 0);
+       display_flag_aux(row+ 3, col, "ESP Good  :", TR_ESP_GOOD, &f, 0);
+       display_flag_aux(row+ 4, col, "ESP Undead:", TR_ESP_UNDEAD, &f, 0);
+       display_flag_aux(row+ 5, col, "ESP Demon :", TR_ESP_DEMON, &f, 0);
+       display_flag_aux(row+ 6, col, "ESP Dragon:", TR_ESP_DRAGON, &f, 0);
+       display_flag_aux(row+ 7, col, "ESP Human :", TR_ESP_HUMAN, &f, 0);
+       display_flag_aux(row+ 8, col, "ESP Animal:", TR_ESP_ANIMAL, &f, 0);
+       display_flag_aux(row+ 9, col, "ESP Orc   :", TR_ESP_ORC, &f, 0);
+       display_flag_aux(row+10, col, "ESP Troll :", TR_ESP_TROLL, &f, 0);
+       display_flag_aux(row+11, col, "ESP Giant :", TR_ESP_GIANT, &f, 0);
+
+       display_flag_aux(row+13, col, "Sust Str  :", TR_SUST_STR, &f, 0);
+       display_flag_aux(row+14, col, "Sust Int  :", TR_SUST_INT, &f, 0);
+       display_flag_aux(row+15, col, "Sust Wis  :", TR_SUST_WIS, &f, 0);
+       display_flag_aux(row+16, col, "Sust Dex  :", TR_SUST_DEX, &f, 0);
+       display_flag_aux(row+17, col, "Sust Con  :", TR_SUST_CON, &f, 0);
+       display_flag_aux(row+18, col, "Sust Chr  :", TR_SUST_CHR, &f, 0);
 #endif
 
 
@@ -3273,43 +3303,43 @@ static void display_player_other_flag_info(void)
        c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+14);
 
 #ifdef JP
-        display_flag_aux(row+ 0, col, "Äɲù¶·â    :", TR_BLOWS, &f, 0);
-        display_flag_aux(row+ 1, col, "ºÎ·¡        :", TR_TUNNEL, &f, 0);
-        display_flag_aux(row+ 2, col, "ÀÖ³°Àþ»ëÎÏ  :", TR_INFRA, &f, 0);
-        display_flag_aux(row+ 3, col, "ËâË¡Æ»¶ñ»ÙÇÛ:", TR_MAGIC_MASTERY, &f, 0);
-        display_flag_aux(row+ 4, col, "±£Ì©        :", TR_STEALTH, &f, 0);
-        display_flag_aux(row+ 5, col, "õº÷        :", TR_SEARCH, &f, 0);
-
-        display_flag_aux(row+ 7, col, "¾èÇÏ        :", TR_RIDING, &f, 0);
-        display_flag_aux(row+ 8, col, "ÅêÚ³        :", TR_THROW, &f, 0);
-        display_flag_aux(row+ 9, col, "½ËÊ¡        :", TR_BLESSED, &f, 0);
-        display_flag_aux(row+10, col, "È¿¥Æ¥ì¥Ý¡¼¥È:", TR_NO_TELE, &f, 0);
-        display_flag_aux(row+11, col, "È¿ËâË¡      :", TR_NO_MAGIC, &f, 0);
-        display_flag_aux(row+12, col, "¾ÃÈñËâÎϸº¾¯:", TR_DEC_MANA, &f, 0);
-
-        display_flag_aux(row+14, col, "·Ð¸³Ã͸º¾¯  :", TR_DRAIN_EXP, &f, 0);
-        display_flag_aux(row+15, col, "Íð¥Æ¥ì¥Ý¡¼¥È:", TR_TELEPORT, &f, 0);
-        display_flag_aux(row+16, col, "È¿´¶        :", TR_AGGRAVATE, &f, 0);
-        display_flag_aux(row+17, col, "ÂÀ¸Å¤Î±åÇ°  :", TR_TY_CURSE, &f, 0);
-#else
-        display_flag_aux(row+ 0, col, "Add Blows   :", TR_BLOWS, &f, 0);
-        display_flag_aux(row+ 1, col, "Add Tunnel  :", TR_TUNNEL, &f, 0);
-        display_flag_aux(row+ 2, col, "Add Infra   :", TR_INFRA, &f, 0);
-        display_flag_aux(row+ 3, col, "Add Device  :", TR_MAGIC_MASTERY, &f, 0);
-        display_flag_aux(row+ 4, col, "Add Stealth :", TR_STEALTH, &f, 0);
-        display_flag_aux(row+ 5, col, "Add Search  :", TR_SEARCH, &f, 0);
-
-        display_flag_aux(row+ 7, col, "Riding      :", TR_RIDING, &f, 0);
-        display_flag_aux(row+ 8, col, "Throw       :", TR_THROW, &f, 0);
-        display_flag_aux(row+ 9, col, "Blessed     :", TR_BLESSED, &f, 0);
-        display_flag_aux(row+10, col, "No Teleport :", TR_NO_TELE, &f, 0);
-        display_flag_aux(row+11, col, "Anti Magic  :", TR_NO_MAGIC, &f, 0);
-        display_flag_aux(row+12, col, "Econom. Mana:", TR_DEC_MANA, &f, 0);
-
-        display_flag_aux(row+14, col, "Drain Exp   :", TR_DRAIN_EXP, &f, 0);
-        display_flag_aux(row+15, col, "Rnd.Teleport:", TR_TELEPORT, &f, 0);
-        display_flag_aux(row+16, col, "Aggravate   :", TR_AGGRAVATE, &f, 0);
-        display_flag_aux(row+17, col, "TY Curse    :", TR_TY_CURSE, &f, 0);
+       display_flag_aux(row+ 0, col, "Äɲù¶·â    :", TR_BLOWS, &f, 0);
+       display_flag_aux(row+ 1, col, "ºÎ·¡        :", TR_TUNNEL, &f, 0);
+       display_flag_aux(row+ 2, col, "ÀÖ³°Àþ»ëÎÏ  :", TR_INFRA, &f, 0);
+       display_flag_aux(row+ 3, col, "ËâË¡Æ»¶ñ»ÙÇÛ:", TR_MAGIC_MASTERY, &f, 0);
+       display_flag_aux(row+ 4, col, "±£Ì©        :", TR_STEALTH, &f, 0);
+       display_flag_aux(row+ 5, col, "õº÷        :", TR_SEARCH, &f, 0);
+
+       display_flag_aux(row+ 7, col, "¾èÇÏ        :", TR_RIDING, &f, 0);
+       display_flag_aux(row+ 8, col, "ÅêÚ³        :", TR_THROW, &f, 0);
+       display_flag_aux(row+ 9, col, "½ËÊ¡        :", TR_BLESSED, &f, 0);
+       display_flag_aux(row+10, col, "È¿¥Æ¥ì¥Ý¡¼¥È:", TR_NO_TELE, &f, 0);
+       display_flag_aux(row+11, col, "È¿ËâË¡      :", TR_NO_MAGIC, &f, 0);
+       display_flag_aux(row+12, col, "¾ÃÈñËâÎϸº¾¯:", TR_DEC_MANA, &f, 0);
+
+       display_flag_aux(row+14, col, "·Ð¸³Ã͸º¾¯  :", TR_DRAIN_EXP, &f, 0);
+       display_flag_aux(row+15, col, "Íð¥Æ¥ì¥Ý¡¼¥È:", TR_TELEPORT, &f, 0);
+       display_flag_aux(row+16, col, "È¿´¶        :", TR_AGGRAVATE, &f, 0);
+       display_flag_aux(row+17, col, "ÂÀ¸Å¤Î±åÇ°  :", TR_TY_CURSE, &f, 0);
+#else
+       display_flag_aux(row+ 0, col, "Add Blows   :", TR_BLOWS, &f, 0);
+       display_flag_aux(row+ 1, col, "Add Tunnel  :", TR_TUNNEL, &f, 0);
+       display_flag_aux(row+ 2, col, "Add Infra   :", TR_INFRA, &f, 0);
+       display_flag_aux(row+ 3, col, "Add Device  :", TR_MAGIC_MASTERY, &f, 0);
+       display_flag_aux(row+ 4, col, "Add Stealth :", TR_STEALTH, &f, 0);
+       display_flag_aux(row+ 5, col, "Add Search  :", TR_SEARCH, &f, 0);
+
+       display_flag_aux(row+ 7, col, "Riding      :", TR_RIDING, &f, 0);
+       display_flag_aux(row+ 8, col, "Throw       :", TR_THROW, &f, 0);
+       display_flag_aux(row+ 9, col, "Blessed     :", TR_BLESSED, &f, 0);
+       display_flag_aux(row+10, col, "No Teleport :", TR_NO_TELE, &f, 0);
+       display_flag_aux(row+11, col, "Anti Magic  :", TR_NO_MAGIC, &f, 0);
+       display_flag_aux(row+12, col, "Econom. Mana:", TR_DEC_MANA, &f, 0);
+
+       display_flag_aux(row+14, col, "Drain Exp   :", TR_DRAIN_EXP, &f, 0);
+       display_flag_aux(row+15, col, "Rnd.Teleport:", TR_TELEPORT, &f, 0);
+       display_flag_aux(row+16, col, "Aggravate   :", TR_AGGRAVATE, &f, 0);
+       display_flag_aux(row+17, col, "TY Curse    :", TR_TY_CURSE, &f, 0);
 #endif
 
 }
@@ -3390,7 +3420,6 @@ static void display_player_stat_info(void)
 
        object_type *o_ptr;
        u32b flgs[TR_FLAG_SIZE];
-       s16b k_idx;
 
        byte a;
        char c;
@@ -3524,9 +3553,6 @@ c_put_str(TERM_L_GREEN, "ǽ
                /* Access object */
                o_ptr = &inventory[i];
 
-               /* Object kind */
-               k_idx = o_ptr->k_idx;
-
                /* Acquire "known" flags */
                object_flags_known(o_ptr, flgs);
 
@@ -3760,7 +3786,7 @@ void display_player(int mode)
                                int value;
 
                                /* Use lowercase stat name */
-                               put_str(stat_names_reduced[i], 3 + i, 54);
+                               put_str(stat_names_reduced[i], 3 + i, 53);
 
                                /* Get the current stat */
                                value = p_ptr->stat_use[i];
@@ -3769,7 +3795,7 @@ void display_player(int mode)
                                cnv_stat(value, buf);
 
                                /* Display the current stat (modified) */
-                               c_put_str(TERM_YELLOW, buf, 3 + i, 61);
+                               c_put_str(TERM_YELLOW, buf, 3 + i, 60);
 
                                /* Acquire the max stat */
                                value = p_ptr->stat_top[i];
@@ -3778,28 +3804,28 @@ void display_player(int mode)
                                cnv_stat(value, buf);
 
                                /* Display the maximum stat (modified) */
-                               c_put_str(TERM_L_GREEN, buf, 3 + i, 68);
+                               c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
                        }
 
                        /* Normal treatment of "normal" stats */
                        else
                        {
                                /* Assume uppercase stat name */
-                               put_str(stat_names[i], 3 + i, 54);
+                               put_str(stat_names[i], 3 + i, 53);
 
                                /* Obtain the current stat (modified) */
                                cnv_stat(p_ptr->stat_use[i], buf);
 
                                /* Display the current stat (modified) */
-                               c_put_str(TERM_L_GREEN, buf, 3 + i, 61);
+                               c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
                        }
 
                        if (p_ptr->stat_max[i] == p_ptr->stat_max_max[i])
                        {
 #ifdef JP
-                               c_put_str(TERM_WHITE, "!", 3+i, 59);
+                               c_put_str(TERM_WHITE, "!", 3 + i, 58);
 #else
-                               c_put_str(TERM_WHITE, "!", 3+i, 59-2);
+                               c_put_str(TERM_WHITE, "!", 3 + i, 58-2);
 #endif
                        }
                }
@@ -3832,75 +3858,82 @@ void display_player(int mode)
                        }
                        else if (p_ptr->is_dead)
                        {
-                               if (dun_level)
+                               if (!dun_level)
                                {
-                                       if (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST))
-                                       {
-                                               /* Get the quest text */
-                                               init_flags = INIT_ASSIGN;
-
-                                               process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
-
 #ifdef JP
-                                               sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¡¢¥¯¥¨¥¹¥È¡Ö%s¡×¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", quest[p_ptr->inside_quest].name, p_ptr->died_from);
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï%s¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", map_name(), p_ptr->died_from);
 #else
-                                               sprintf(statmsg, "...You were killed by %s in the quest '%s'.", p_ptr->died_from, quest[p_ptr->inside_quest].name);
+                                       sprintf(statmsg, "...You were killed by %s in %s.", p_ptr->died_from, map_name());
 #endif
-                                       }
-                                       else
-                                       {                                       
+                               }
+                               else if (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest))
+                               {
+                                       /* Get the quest text */
+                                       /* Bewere that INIT_ASSIGN resets the cur_num. */
+                                       init_flags = INIT_ASSIGN;
+
+                                       process_dungeon_file("q_info.txt", 0, 0, 0, 0);
+
 #ifdef JP
-                                               sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¡¢%s¤Î%d³¬¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", map_name(), dun_level, p_ptr->died_from);
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¡¢¥¯¥¨¥¹¥È¡Ö%s¡×¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", quest[p_ptr->inside_quest].name, p_ptr->died_from);
 #else
-                                               sprintf(statmsg, "...You were killed by %s on level %d of %s.", p_ptr->died_from, dun_level, map_name());
+                                       sprintf(statmsg, "...You were killed by %s in the quest '%s'.", p_ptr->died_from, quest[p_ptr->inside_quest].name);
 #endif
-                                       }
                                }
                                else
+                               {
 #ifdef JP
-                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï%s¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", map_name(), p_ptr->died_from);
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¡¢%s¤Î%d³¬¤Ç%s¤Ë»¦¤µ¤ì¤¿¡£", map_name(), dun_level, p_ptr->died_from);
 #else
-                                       sprintf(statmsg, "...You were killed by %s in %s.", p_ptr->died_from, map_name());
+                                       sprintf(statmsg, "...You were killed by %s on level %d of %s.", p_ptr->died_from, dun_level, map_name());
 #endif
+                               }
                        }
                        else if (character_dungeon)
                        {
-                               if (dun_level)
+                               if (!dun_level)
                                {
-                                       if (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST))
-                                       {
-                                               /* Get the quest text */
-                                               init_flags = INIT_ASSIGN;
-
-                                               process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
-
 #ifdef JP
-                                               sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ ¥¯¥¨¥¹¥È¡Ö%s¡×¤ò¿ë¹ÔÃæ¤À¡£", quest[p_ptr->inside_quest].name);
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ %s ¤Ë¤¤¤ë¡£", map_name());
 #else
-                                               sprintf(statmsg, "...Now, you are in the quest '%s'.", quest[p_ptr->inside_quest].name);
+                                       sprintf(statmsg, "...Now, you are in %s.", map_name());
 #endif
-                                       }                                                       
-                                       else
+                               }
+                               else if (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest))
+                               {
+                                       /* Clear the text */
+                                       /* Must be done before doing INIT_SHOW_TEXT */
+                                       for (i = 0; i < 10; i++)
                                        {
+                                               quest_text[i][0] = '\0';
+                                       }
+                                       quest_text_line = 0;
+
+                                       /* Get the quest text */
+                                       init_flags = INIT_SHOW_TEXT;
+
+                                       process_dungeon_file("q_info.txt", 0, 0, 0, 0);
+
 #ifdef JP
-                                               sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ %s ¤Î %d ³¬¤Çõº÷¤·¤Æ¤¤¤ë¡£", map_name(), dun_level);
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ ¥¯¥¨¥¹¥È¡Ö%s¡×¤ò¿ë¹ÔÃæ¤À¡£", quest[p_ptr->inside_quest].name);
 #else
-                                               sprintf(statmsg, "...Now, you are exploring level %d of %s.", dun_level, map_name());
+                                       sprintf(statmsg, "...Now, you are in the quest '%s'.", quest[p_ptr->inside_quest].name);
 #endif
-                                       }
                                }
                                else
+                               {
 #ifdef JP
-                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ %s ¤Ë¤¤¤ë¡£", map_name());
+                                       sprintf(statmsg, "¡Ä¤¢¤Ê¤¿¤Ï¸½ºß¡¢ %s ¤Î %d ³¬¤Çõº÷¤·¤Æ¤¤¤ë¡£", map_name(), dun_level);
 #else
-                                       sprintf(statmsg, "...Now, you are in %s.", map_name());
+                                       sprintf(statmsg, "...Now, you are exploring level %d of %s.", dun_level, map_name());
 #endif
+                               }
                        }
 
                        if (*statmsg)
                        {
                                char temp[64*2], *t;
-                               roff_to_buf(statmsg, 60, temp);
+                               roff_to_buf(statmsg, 60, temp, sizeof(temp));
                                t = temp;
                                for(i=0 ; i<2 ; i++)
                                {
@@ -3938,7 +3971,7 @@ void display_player(int mode)
        /* Special */
        else if (mode == 3)
        {
-                display_player_other_flag_info();
+               display_player_other_flag_info();
        }
 
        else if (mode == 4)
@@ -3947,50 +3980,16 @@ void display_player(int mode)
        }
 }
 
-static bool ang_sort_comp_quest_num(vptr u, vptr v, int a, int b)
-{
-       int *q_num = (int *)u;
-        quest_type *qa = &quest[q_num[a]];
-        quest_type *qb = &quest[q_num[b]];
-
-       if (qa->complev < qb->complev) return TRUE;
-       if (qa->complev > qb->complev) return FALSE;
-       if (qa->level <= qb->level) return TRUE;
-        return FALSE;
-}
 
-static void ang_sort_swap_quest_num(vptr u, vptr v, int a, int b)
-{
-       int *q_num = (int *)u;
-       int tmp;
-
-       tmp = q_num[a];
-       q_num[a] = q_num[b];
-       q_num[b] = tmp;
-}
-
-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             total;
-       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);
@@ -4016,7 +4015,7 @@ errr make_character_dump(FILE *fff)
 
                /* End the row */
 #ifdef JP
-                        fprintf(fff, "%s\n", buf);
+               fprintf(fff, "%s\n", buf);
 #else
                fprintf(fff, "%s\n", buf);
 #endif
@@ -4116,235 +4115,269 @@ 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;
+               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];
-                       char pet_name[80];
-
-                       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, 0x88);
-                       fprintf(fff, "%s", pet_name);
-                       if (p_ptr->riding == i)
-#ifdef JP
-                               fprintf(fff, " ¾èÇÏÃæ");
-#else
-                               fprintf(fff, " (riding)");
-#endif
-                       fprintf(fff, "\n");
+                       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);
        }
 
-#ifdef JP
-       fprintf(fff, "\n  [¥¯¥¨¥¹¥È¾ðÊó]\n");
-#else
-       fprintf(fff, "\n  [Quest information]\n");
-#endif
-
-#ifdef JP
-       fprintf(fff, "\n¡ÔãÀ®¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
-#else
-       fprintf(fff, "\n< Completed Quest >\n");
-#endif
+       if (pet) fprintf(fff, "\n");
+}
 
-       /* Allocate Memory */
-       C_MAKE(quest_num, max_quests, int);
 
-       /* Sort by compete level */
-       for (i = 1; i < max_quests; i++)
-       {
-               quest_num[i] = i;
-       }
-       ang_sort_comp = ang_sort_comp_quest_num;
-       ang_sort_swap = ang_sort_swap_quest_num;
-       ang_sort(quest_num, &dummy, max_quests);
-
-       /* Dump Quest Information */
-       total = 0;
-       for (i = 1; i < max_quests; i++)
+/*
+ *
+ */
+static void dump_aux_class_special(FILE *fff)
+{
+       if (p_ptr->pclass == CLASS_BLUE_MAGE)
        {
-               int num = quest_num[i];
+               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;
 
-               if (quest[num].status == QUEST_STATUS_FINISHED)
-               {
-                       if (num < MIN_RANDOM_QUEST)
-                       {
-                                int old_quest;
-                        
-                               /* Set the quest number temporary */
-                               old_quest = p_ptr->inside_quest;
-                               p_ptr->inside_quest = num;
+               for (i=0;i<60;i++) { p[i][0] = '\0'; }
 
-                               /* Get the quest */
-                               init_flags = INIT_ASSIGN;
-
-                               process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
-
-                               /* Reset the old quest number */
-                               p_ptr->inside_quest = old_quest;
-
-                                /* No info from "silent" quests */
-                                if (quest[num].flags & QUEST_FLAG_SILENT) continue;
-                       }
+#ifdef JP
+               strcat(p[col], "\n  [³Ø½¬ºÑ¤ß¤ÎÀÄËâË¡]\n");
+#else
+               strcat(p[col], "\n  [Learned blue magic]\n");
+#endif
 
-                       total++;
 
-                       if ((num >= MIN_RANDOM_QUEST) && quest[num].r_idx)
+               for (j=1;j<6;j++)
+               {
+                       col++;
+                       set_rf_masks(&f4, &f5, &f6, j);
+                       switch(j)
                        {
-                               /* Print the quest info */
-
-                                if (quest[num].complev == 0)
-                                {
-                                        fprintf(fff, 
+                               case MONSPELL_TYPE_BOLT:
 #ifdef JP
-                                                "  %s (%d³¬) - ÉÔÀᄀ\n",
+                                       strcat(p[col], "\n     [¥Ü¥ë¥È·¿]\n");
 #else
-                                                "  %s (Dungeon level: %d) - (Cancelled)\n",
+                                       strcat(p[col], "\n     [Bolt  type]\n");
 #endif
-                                                r_name+r_info[quest[num].r_idx].name,
-                                                quest[num].level);
-                                }
-                                else
-                                {
-                                        fprintf(fff, 
+                                       break;
+
+                               case MONSPELL_TYPE_BALL:
 #ifdef JP
-                                                "  %s (%d³¬) - ¥ì¥Ù¥ë%d\n",
+                                       strcat(p[col], "\n     [¥Ü¡¼¥ë·¿]\n");
 #else
-                                                "  %s (Dungeon level: %d) - level %d\n",
+                                       strcat(p[col], "\n     [Ball  type]\n");
 #endif
-                                                r_name+r_info[quest[num].r_idx].name,
-                                                quest[num].level,
-                                                quest[num].complev);
-                                }
-                       }
-                       else
-                       {
-                               /* Print the quest info */
+                                       break;
+
+                               case MONSPELL_TYPE_BREATH:
 #ifdef JP
-                               fprintf(fff, "  %s (´í¸±ÅÙ:%d³¬ÁêÅö) - ¥ì¥Ù¥ë%d\n",
+                                       strcat(p[col], "\n     [¥Ö¥ì¥¹·¿]\n");
 #else
-                               fprintf(fff, "  %s (Danger level: %d) - level %d\n",
+                                       strcat(p[col], "\n     [  Breath  ]\n");
 #endif
+                                       break;
 
-                                       quest[num].name, quest[num].level, quest[num].complev);
-                       }
-               }
-       }
+                               case MONSPELL_TYPE_SUMMON:
 #ifdef JP
-       if (!total) fprintf(fff, "  ¤Ê¤·\n");
+                                       strcat(p[col], "\n     [¾¤´­ËâË¡]\n");
 #else
-       if (!total) fprintf(fff, "  Nothing.\n");
+                                       strcat(p[col], "\n     [Summonning]\n");
 #endif
+                                       break;
 
+                               case MONSPELL_TYPE_OTHER:
 #ifdef JP
-       fprintf(fff, "\n¡Ô¼ºÇÔ¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
+                                       strcat(p[col], "\n     [ ¤½¤Î¾ ]\n");
 #else
-       fprintf(fff, "\n< Failed Quest >\n");
+                                       strcat(p[col], "\n     [Other type]\n");
 #endif
-       total = 0;
-       for (i = 1; i < max_quests; i++)
-       {
-               int num = quest_num[i];
+                                       break;
+                       }
 
-               if ((quest[num].status == QUEST_STATUS_FAILED_DONE) || (quest[num].status == QUEST_STATUS_FAILED))
-               {
-                       if (num < MIN_RANDOM_QUEST)
+                       for (i = 0, num = 0; i < 32; i++)
                        {
-                                int old_quest;
-
-                               /* Set the quest number temporary */
-                               old_quest = p_ptr->inside_quest;
-                               p_ptr->inside_quest = num;
-
-                               /* Get the quest text */
-                               init_flags = INIT_ASSIGN;
-
-                               process_dungeon_file("q_info_j.txt", 0, 0, 0, 0);
-
-                               /* Reset the old quest number */
-                               p_ptr->inside_quest = old_quest;
-
-                                /* No info from "silent" quests */
-                                if (quest[num].flags & QUEST_FLAG_SILENT) continue;
+                               if ((0x00000001 << i) & f4) spellnum[num++] = i;
+                       }
+                       for (; i < 64; i++)
+                       {
+                               if ((0x00000001 << (i - 32)) & f5) spellnum[num++] = i;
+                       }
+                       for (; i < 96; i++)
+                       {
+                               if ((0x00000001 << (i - 64)) & f6) spellnum[num++] = i;
                        }
 
-                       total++;
+                       col++;
+                       pcol = FALSE;
+                       strcat(p[col], "       ");
 
-                       if ((num >= MIN_RANDOM_QUEST) && quest[num].r_idx)
+                       for (i = 0; i < num; i++)
+                       {
+                               if (p_ptr->magic_num2[spellnum[i]])
+                               {
+                                       pcol = TRUE;
+                                       /* Dump blue magic */
+                                       l1 = strlen(p[col]);
+                                       l2 = strlen(monster_powers_short[spellnum[i]]);
+                                       if ((l1 + l2) >= 75)
+                                       {
+                                               strcat(p[col], "\n");
+                                               col++;
+                                               strcat(p[col], "       ");
+                                       }
+                                       strcat(p[col], monster_powers_short[spellnum[i]]);
+                                       strcat(p[col], ", ");
+                               }
+                       }
+                       
+                       if (!pcol)
                        {
-                               /* Print the quest info */
 #ifdef JP
-                               fprintf(fff, "  %s (%d³¬) - ¥ì¥Ù¥ë%d\n",
+                               strcat(p[col], "¤Ê¤·");
 #else
-                               fprintf(fff, "  %s (Dungeon level: %d) - level %d\n",
+                               strcat(p[col], "None");
 #endif
-
-                                       r_name+r_info[quest[num].r_idx].name, quest[num].level, quest[num].complev);
                        }
                        else
                        {
-                               /* Print the quest info */
-#ifdef JP
-                               fprintf(fff, "  %s (´í¸±ÅÙ:%d³¬ÁêÅö) - ¥ì¥Ù¥ë%d\n",
-#else
-                               fprintf(fff, "  %s (Danger level: %d) - level %d\n",
-#endif
-
-                                       quest[num].name, quest[num].level, quest[num].complev);
+                               if (p[col][strlen(p[col])-2] == ',')
+                               {
+                                       p[col][strlen(p[col])-2] = '\0';
+                               }
+                               else
+                               {
+                                       p[col][strlen(p[col])-10] = '\0';
+                               }
                        }
+                       
+                       strcat(p[col], "\n");
+               }
+
+               for (i=0;i<=col;i++)
+               {
+                       fprintf(fff, p[i]);
                }
        }
+}
+
+
+/*
+ *
+ */
+static void dump_aux_quest(FILE *fff)
+{
+       int i;
+       int *quest_num;
+       int dummy;
+
 
 #ifdef JP
-       if (!total) fprintf(fff, "  ¤Ê¤·\n");
+       fprintf(fff, "\n\n  [¥¯¥¨¥¹¥È¾ðÊó]\n");
 #else
-       if (!total) fprintf(fff, "  Nothing.\n");
+       fprintf(fff, "\n\n  [Quest information]\n");
 #endif
-       fprintf(fff, "\n");
+
+       /* Allocate Memory */
+       C_MAKE(quest_num, max_quests, int);
+
+       /* Sort by compete level */
+       for (i = 1; i < max_quests; i++) quest_num[i] = i;
+       ang_sort_comp = ang_sort_comp_quest_num;
+       ang_sort_swap = ang_sort_swap_quest_num;
+       ang_sort(quest_num, &dummy, max_quests);
+
+       /* Dump Quest Information */
+       fputc('\n', fff);
+       do_cmd_knowledge_quests_completed(fff, quest_num);
+       fputc('\n', fff);
+       do_cmd_knowledge_quests_failed(fff, quest_num);
 
        /* Free Memory */
        C_KILL(quest_num, max_quests, int);
+}
+
 
-       if (p_ptr->is_dead && !p_ptr->total_winner)
+/*
+ *
+ */
+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");
+                       fprintf(fff, "\n  [»à¤ÌľÁ°¤Î¥á¥Ã¥»¡¼¥¸]\n\n");
 #else
-               fprintf(fff, "\n  [Last messages]\n\n");
+                       fprintf(fff, "\n  [Last messages]\n\n");
 #endif
-               for (i = MIN(message_num(), 30); i >= 0; i--)
-               {
-                       fprintf(fff,"> %s\n",message_str((s16b)i));
+                       for (i = MIN(message_num(), 30); i >= 0; i--)
+                       {
+                               fprintf(fff,"> %s\n",message_str((s16b)i));
+                       }
+                       fprintf(fff, "\n");
                }
-               fprintf(fff, "\n");
-       }
 
+               /* Hack -- *Winning* message */
+               else if (p_ptr->last_message)
+               {
 #ifdef JP
-       fprintf(fff, "\n  [¤½¤Î¾¤Î¾ðÊó]\n");
+                       fprintf(fff, "\n  [*¾¡Íø*¥á¥Ã¥»¡¼¥¸]\n\n");
 #else
-       fprintf(fff, "\n  [Miscellaneous information]\n");
+                       fprintf(fff, "\n  [*Winning* message]\n\n");
 #endif
+                       fprintf(fff,"  %s\n", p_ptr->last_message);
+               }
+       }
+}
+
+
+/*
+ *
+ */
+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;
@@ -4363,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
 
 
@@ -4432,7 +4457,7 @@ errr make_character_dump(FILE *fff)
 
        if (vanilla_town)
 #ifdef JP
-               fprintf(fff, "\n ¸µÁĤÎÄ®¤Î¤ß: ON");
+               fprintf(fff, "\n ¸µÁĤÎÄ®¤Î¤ß:       ON");
 #else
                fprintf(fff, "\n Vanilla Town:       ON");
 #endif
@@ -4457,15 +4482,15 @@ errr make_character_dump(FILE *fff)
 #ifdef JP
                fprintf(fff, "\n ³¬Ãʤò¾å¤¬¤ì¤Ê¤¤:   ON");
 #else
-               fprintf(fff, "\n Diving only:        ON");
+               fprintf(fff, "\n Diving Only:        ON");
 #endif
 
 
        if (ironman_rooms)
 #ifdef JP
-               fprintf(fff, "\n ÉáÄ̤Ǥʤ¤Éô²°¤òÀ¸À®:         ON");
+               fprintf(fff, "\n ÉáÄ̤Ǥʤ¤Éô²°:     ON");
 #else
-               fprintf(fff, "\n Unusual rooms:      ON");
+               fprintf(fff, "\n Unusual Rooms:      ON");
 #endif
 
 
@@ -4486,34 +4511,62 @@ errr make_character_dump(FILE *fff)
 
        else if (empty_levels)
 #ifdef JP
-               fprintf(fff, "\n ¥¢¥ê¡¼¥Ê:           ON");
+               fprintf(fff, "\n ¥¢¥ê¡¼¥Ê:           ENABLED");
 #else
                fprintf(fff, "\n Arena Levels:       ENABLED");
 #endif
 
        else
 #ifdef JP
-               fprintf(fff, "\n ¥¢¥ê¡¼¥Ê:           OFF");
+               fprintf(fff, "\n ¥¢¥ê¡¼¥Ê:           OFF");
 #else
                fprintf(fff, "\n Arena Levels:       OFF");
 #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
 
-       if (p_ptr->arena_number == 99)
+       fprintf(fff,"\n");
+}
+
+
+/*
+ *
+ */
+static void dump_aux_arena(FILE *fff)
+{
+       if (lite_town || vanilla_town) return;
+
+       if (p_ptr->arena_number < 0)
        {
+               if (p_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
+               {
 #ifdef JP
-               fprintf(fff, "\n Æ®µ»¾ì: ÇÔËÌ\n");
+                       fprintf(fff, "\n Æ®µ»¾ì: ÇÔËÌ\n");
 #else
-               fprintf(fff, "\n Arena: defeated\n");
+                       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);
+#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));
+#endif
+               }
        }
-       else if (p_ptr->arena_number > MAX_ARENA_MONS+2)
+       else if (p_ptr->arena_number > MAX_ARENA_MONS + 2)
        {
 #ifdef JP
                fprintf(fff, "\n Æ®µ»¾ì: ¿¿¤Î¥Á¥ã¥ó¥Ô¥ª¥ó\n");
@@ -4521,7 +4574,7 @@ errr make_character_dump(FILE *fff)
                fprintf(fff, "\n Arena: True Champion\n");
 #endif
        }
-       else if (p_ptr->arena_number > MAX_ARENA_MONS-1)
+       else if (p_ptr->arena_number > MAX_ARENA_MONS - 1)
        {
 #ifdef JP
                fprintf(fff, "\n Æ®µ»¾ì: ¥Á¥ã¥ó¥Ô¥ª¥ó\n");
@@ -4532,90 +4585,143 @@ errr make_character_dump(FILE *fff)
        else
        {
 #ifdef JP
-               fprintf(fff, "\n Æ®µ»¾ì:   %2d¾¡\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
+               fprintf(fff, "\n Æ®µ»¾ì: %2d¾¡\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
 #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: %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
        }
 
-       if (p_ptr->noscore)
-#ifdef JP
-fprintf(fff, "\n ²¿¤«ÉÔÀµ¤Ê¤³¤È¤ò¤·¤Æ¤·¤Þ¤Ã¤Æ¤Þ¤¹¡£");
-#else
-               fprintf(fff, "\n You have done something illegal.");
-#endif
+       fprintf(fff, "\n");
+}
 
 
-       if (stupid_monsters)
-#ifdef JP
-fprintf(fff, "\n Å¨¤Ï¶ò¤«¤Ê¹ÔÆ°¤ò¼è¤ê¤Þ¤¹¡£");
-#else
-               fprintf(fff, "\n Your opponents are behaving stupidly.");
-#endif
+/*
+ *
+ */
+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;
 
-       if (munchkin_death)
 #ifdef JP
-fprintf(fff, "\n ¤¢¤Ê¤¿¤Ï»à¤ò²óÈò¤¹¤ë¥¤¥ó¥Á¥­¤ÊÎϤò»ý¤Ã¤Æ¤¤¤Þ¤¹¡£");
+       fprintf(fff, "\n  [Åݤ·¤¿¥â¥ó¥¹¥¿¡¼]\n\n");
 #else
-               fprintf(fff, "\n You possess munchkinish power over death.");
+       fprintf(fff, "\n  [Defeated monsters]\n\n");
 #endif
 
-       fprintf(fff,"\n");
+       /* Allocate the "who" array */
+       C_MAKE(who, max_r_idx, s16b);
 
-       /* Monsters slain */
+       /* 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;
                        }
                }
+       }
 
-               if (Total < 1)
+
+       /* No monsters is defeated */
+       if (norm_total < 1)
+       {
 #ifdef JP
-fprintf(fff,"\n ¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Þ¤»¤ó¡£\n");
+               fprintf(fff,"¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Þ¤»¤ó¡£\n");
 #else
-                       fprintf(fff,"\n You have defeated no enemies yet.\n");
+               fprintf(fff,"You have defeated no enemies yet.\n");
 #endif
+       }
 
-               else 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 one enemy.\n");
+               fprintf(fff,"You have defeated %lu %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies");
 #endif
+       }
+
+       /* Defeated more than one unique monsters */
+       else /* if (uniq_total > 0) */
+       {
+#ifdef JP
+               fprintf(fff, "%luÂΤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤ò´Þ¤à¡¢¹ç·×%luÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", uniq_total, norm_total); 
+#else
+               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
+
+
+               /* 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", MIN(uniq_total, 10));
+#else
+               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]];
 
-               else
 #ifdef JP
-fprintf(fff,"\n %lu ÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", Total);
+                       fprintf(fff, "  %-40s (¥ì¥Ù¥ë%3d)\n", (r_name + r_ptr->name), r_ptr->level); 
 #else
-                       fprintf(fff,"\n You have defeated %lu enemies.\n", Total);
+                       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
@@ -4639,9 +4745,18 @@ fprintf(fff,"\n %lu 
 #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;
@@ -4652,9 +4767,16 @@ fprintf(fff,"\n %lu 
 #endif
                }
        }
+}
 
+
+/*
+ *
+ */
+static void dump_aux_virtues(FILE *fff)
+{
 #ifdef JP
-fprintf(fff, "\n\n  [¥×¥ì¥¤¥ä¡¼¤ÎÆÁ]\n\n");
+       fprintf(fff, "\n\n  [¥×¥ì¥¤¥ä¡¼¤ÎÆÁ]\n\n");
 #else
        fprintf(fff, "\n\n  [Virtues]\n\n");
 #endif
@@ -4664,13 +4786,21 @@ fprintf(fff, "\n\n  [
 #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
-fprintf(fff, "\n\n  [ÆÍÁ³ÊÑ°Û]\n\n");
+               fprintf(fff, "\n\n  [ÆÍÁ³ÊÑ°Û]\n\n");
 #else
                fprintf(fff, "\n\n  [Mutations]\n\n");
 #endif
@@ -4678,38 +4808,47 @@ fprintf(fff, "\n\n  [
                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)
        {
 #ifdef JP
-fprintf(fff, "  [ ¥­¥ã¥é¥¯¥¿¤ÎÁõÈ÷ ]\n\n");
+               fprintf(fff, "  [¥­¥ã¥é¥¯¥¿¤ÎÁõÈ÷]\n\n");
 #else
                fprintf(fff, "  [Character Equipment]\n\n");
 #endif
 
                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");
        }
 
        /* Dump the inventory */
 #ifdef JP
-fprintf(fff, "  [ ¥­¥ã¥é¥¯¥¿¤Î»ý¤Áʪ ]\n\n");
+       fprintf(fff, "  [¥­¥ã¥é¥¯¥¿¤Î»ý¤Áʪ]\n\n");
 #else
        fprintf(fff, "  [Character Inventory]\n\n");
 #endif
@@ -4720,28 +4859,40 @@ fprintf(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_j.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");
+               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++)
@@ -4750,10 +4901,10 @@ fprintf(fff, "  [ 
 #ifdef JP
                                fprintf(fff, "\n ( %d ¥Ú¡¼¥¸ )\n", x++);
 #else
-                               fprintf(fff, "\n ( page %d )\n", x++);
+                               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 */
@@ -4761,31 +4912,32 @@ fprintf(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");
+               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);
+               if ((i % 12) == 0) fprintf(fff, "\n ( %d ¥Ú¡¼¥¸ )\n", x++);
+                       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);
+               if ((i % 12) == 0) fprintf(fff, "\n ( page %d )\n", x++);
+                       object_desc(o_name, &st_ptr->stock[i], 0);
+                       fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
 #endif
 
                }
@@ -4793,11 +4945,44 @@ fprintf(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, "  [¥Á¥§¥Ã¥¯¥µ¥à: \"%s\"]\n\n", get_check_sum());
+       fprintf(fff, "  [ÊѶòÈÚÅÜ %d.%d.%d ¥­¥ã¥é¥¯¥¿¾ðÊó]\n\n",
+               FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
 #else
-        fprintf(fff, "  [Check Sum: \"%s\"]\n\n", get_check_sum());
+       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());
+#else
+       fprintf(fff, "  [Check Sum: \"%s\"]\n\n", get_check_sum());
 #endif
 
        return 0;
@@ -4809,15 +4994,12 @@ fprintf(fff, "  [ 
  * XXX XXX XXX Allow the "full" flag to dump additional info,
  * and trigger its usage from various places in the code.
  */
-errr file_character(cptr name, bool full)
+errr file_character(cptr name)
 {
        int             fd = -1;
        FILE            *fff = NULL;
        char            buf[1024];
 
-       /* Drop priv's */
-       safe_setuid_drop();
-
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
@@ -4837,7 +5019,7 @@ errr file_character(cptr name, bool full)
 
                /* Build query */
 #ifdef JP
-                (void)sprintf(out_val, "¸½Â¸¤¹¤ë¥Õ¥¡¥¤¥ë %s ¤Ë¾å½ñ¤­¤·¤Þ¤¹¤«? ", buf);
+               (void)sprintf(out_val, "¸½Â¸¤¹¤ë¥Õ¥¡¥¤¥ë %s ¤Ë¾å½ñ¤­¤·¤Þ¤¹¤«? ", buf);
 #else
                (void)sprintf(out_val, "Replace existing file %s? ", buf);
 #endif
@@ -4855,54 +5037,171 @@ errr file_character(cptr name, bool full)
        {
                /* Message */
 #ifdef JP
-                prt("¥­¥ã¥é¥¯¥¿¾ðÊó¤Î¥Õ¥¡¥¤¥ë¤Ø¤Î½ñ¤­½Ð¤·¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡ª", 0, 0);
+               prt("¥­¥ã¥é¥¯¥¿¾ðÊó¤Î¥Õ¥¡¥¤¥ë¤Ø¤Î½ñ¤­½Ð¤·¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡ª", 0, 0);
 #else
                prt("Character dump failed!", 0, 0);
 #endif
 
-                (void)inkey();
+               (void)inkey();
+
+               /* Error */
+               return (-1);
+       }
+
+       (void)make_character_dump(fff);
+
+       /* Close it */
+       my_fclose(fff);
+
+
+       /* Message */
+#ifdef JP
+msg_print("¥­¥ã¥é¥¯¥¿¾ðÊó¤Î¥Õ¥¡¥¤¥ë¤Ø¤Î½ñ¤­½Ð¤·¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£");
+#else
+       msg_print("Character dump successful.");
+#endif
+
+       msg_print(NULL);
+
+       /* Success */
+       return (0);
+}
+
+
+/*
+ * Display single line of on-line help file
+ *
+ * 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;
+               }
 
-               /* Error */
-               return (-1);
-       }
+               /* Colored segment? */
+               else if (endcol == bracketcol)
+               {
+                       if (in_tag)
+                       {
+                               /* Found the end of colored segment */
+                               i++;
 
-       (void)make_character_dump(fff);
+                               /* Now looking for an another tag_str */
+                               in_tag = '\0';
 
-       /* Close it */
-       my_fclose(fff);
+                               /* Set back to the default color */
+                               color = TERM_WHITE;
+                       }
+                       else
+                       {
+                               /* Found a tag_str, and get a tag color */
+                               i += sizeof(tag_str)-1;
 
-       /* Grab priv's */
-       safe_setuid_grab();
+                               /* Get tag color */
+                               color = color_char_to_attr(str[i]);
 
-       /* Message */
-#ifdef JP
-msg_print("¥­¥ã¥é¥¯¥¿¾ðÊó¤Î¥Õ¥¡¥¤¥ë¤Ø¤Î½ñ¤­½Ð¤·¤ËÀ®¸ù¤·¤Þ¤·¤¿¡£");
-#else
-       msg_print("Character dump successful.");
-#endif
+                               /* Illegal color tag */
+                               if (color == 255 || str[i+1] == '\0')
+                               {
+                                       /* Illegal color tag */
+                                       color = TERM_WHITE;
 
-       msg_print(NULL);
+                                       /* 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++;
 
-       /* Success */
-       return (0);
+                                       /* 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.
  *
- * Return FALSE on 'Q', otherwise TRUE.
- *
  * 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)
 {
-       int i, n, k;
+       int i, n, skey;
 
        /* Number of "real" lines passed by */
        int next = 0;
@@ -4913,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;
 
@@ -4931,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];
@@ -4949,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];
 
@@ -4966,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, "");
@@ -5089,27 +5377,23 @@ msg_format("'%s'
        /* Pre-Parse the file */
        while (TRUE)
        {
-               char *str;
+               char *str = buf;
 
                /* Read a line or stop */
                if (my_fgets(fff, buf, sizeof(buf))) break;
 
-               /* Get a color */
-               if (prefix(buf, "#####")) str = &buf[6];
-               else str = buf;
-
                /* XXX Parse "menu" items */
                if (prefix(str, "***** "))
                {
                        /* Notice "menu" requests */
                        if ((str[6] == '[') && isalpha(str[7]))
                        {
+                               /* Extract the menu item */
+                               int k = str[7] - 'A';
+
                                /* This is a menu file */
                                menu = TRUE;
 
-                               /* Extract the menu item */
-                               k = str[7] - 'A';
-
                                if ((str[8] == ']') && (str[9] == ' '))
                                {
                                        /* Extract the menu item */
@@ -5122,8 +5406,13 @@ msg_format("'%s'
                        /* Notice "tag" requests */
                        else if (str[6] == '<')
                        {
-                               str[strlen(str) - 1] = '\0';
-                                if (tag && streq(str + 7, tag)) line = next;
+                               size_t len = strlen(str);
+
+                               if (str[len - 1] == '>')
+                               {
+                                       str[len - 1] = '\0';
+                                       if (tag && streq(str + 7, tag)) line = next;
+                               }
                        }
 
                        /* Skip this */
@@ -5140,12 +5429,12 @@ msg_format("'%s'
        /* start from bottom when reverse mode */
        if (line == -1) line = ((size-1)/rows)*rows;
 
+       /* Clear screen */
+       Term_clear();
+
        /* Display the file */
        while (TRUE)
        {
-               /* Clear screen */
-               Term_clear();
-
                /* Restart when necessary */
                if (line >= size - rows) line = size - rows;
                if (line < 0) line = 0;
@@ -5182,8 +5471,7 @@ msg_format("'%s'
                /* Dump the next 20, or rows, lines of the file */
                for (i = 0; i < rows; )
                {
-                       int print_x, x;
-                       cptr str;
+                       cptr str = buf;
 
                        /* Hack -- track the "first" line */
                        if (!i) line = next;
@@ -5194,87 +5482,36 @@ msg_format("'%s'
                        /* Hack -- skip "special" lines */
                        if (prefix(buf, "***** ")) continue;
 
-                       /* Get a color */
-                       if (prefix(buf, "#####"))
-                       {
-                               color = color_char_to_attr(buf[5]);
-                               str = &buf[6];
-                       }
-                       else
-                       {
-                               color = TERM_WHITE;
-                               str = buf;
-                       }
-
                        /* 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 = color_char_to_attr(str[x + 5]);
-                                       x += 6;
+                               char lc_buf[1024];
 
-                                       /* Ok print the link name */
-                                       while (str[x] != ']')
-                                       {
-                                               Term_putch(print_x, i + 2, c, str[x]);
-                                               x++;
-                                               print_x++;
-                                       }
-                               }
-                               else
-                               {
-                                       Term_putch(print_x, i + 2, color, str[x]);
-                                       print_x++;
-                               }
+                               /* Make a lower case version of str for searching */
+                               strcpy(lc_buf, str);
+                               str_tolower(lc_buf);
 
-                               x++;
+                               if (!my_strstr(lc_buf, find)) continue;
                        }
 
-                       /* Hilite "shower" */
-                       if (shower[0])
-                       {
-                               cptr s2 = lc_buf;
+                       /* Hack -- stop searching */
+                       find = NULL;
 
-                               /* Display matches */
-                               while ((s2 = strstr(s2, shower)) != NULL)
-                               {
-                                       int len = strlen(shower);
+                       /* Dump the line */
+                       show_file_aux_line(str, i + 2, shower);
 
-                                       /* Display the match */
-                                       Term_putstr(s2-lc_buf, i+2, len, TERM_YELLOW, &str[s2-lc_buf]);
+                       /* Count the printed lines */
+                       i++;
+               }
 
-                                       /* Advance */
-                                       s2 += len;
-                               }
-                       }
+               while (i < rows)
+               {
+                       /* Clear rest of line */
+                       Term_erase(0, i + 2, 255);
 
-                       /* Count the printed lines */
                        i++;
                }
 
@@ -5298,8 +5535,8 @@ msg_format("'%s'
                                "[Hengband %d.%d.%d, %s, Line %d/%d]",
 #endif
 
-                          FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH,
-                          caption, line, size), 0, 0);
+                          FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH,
+                          caption, line, size), 0, 0);
                }
                else
                {
@@ -5337,14 +5574,11 @@ prt("[
 #endif
                }
 
-               /* Get a keypress */
-               k = inkey();
-
-               /* Hack -- return to last screen */
-               if (k == '<') break;
+               /* Get a special key code */
+               skey = inkey_special(TRUE);
 
                /* Show the help for the help */
-               if (k == '?')
+               if (skey == '?')
                {
                        /* Hack - prevent silly recursion */
 #ifdef JP
@@ -5357,54 +5591,52 @@ prt("[
                }
 
                /* Hack -- try showing */
-               if (k == '=')
+               if (skey == '=')
                {
                        /* 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 */
-               if (k == '/')
+               if (skey == '/' || skey == KTRL('s'))
                {
                        /* Get "finder" */
 #ifdef JP
-prt("¸¡º÷: ", hgt - 1, 0);
+                       prt("¸¡º÷: ", hgt - 1, 0);
 #else
                        prt("Find: ", hgt - 1, 0);
 #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;
                        }
                }
 
                /* Hack -- go to a specific line */
-               if (k == '#')
+               if (skey == '#')
                {
                        char tmp[81];
 #ifdef JP
@@ -5415,14 +5647,26 @@ prt("
 
                        strcpy(tmp, "0");
 
-                       if (askfor_aux(tmp, 80))
+                       if (askfor(tmp, 80))
                        {
                                line = atoi(tmp);
                        }
                }
 
+               /* Hack -- go to the top line */
+               if (skey == SKEY_TOP)
+               {
+                       line = 0;
+               }
+
+               /* Hack -- go to the bottom line */
+               if (skey == SKEY_BOTTOM)
+               {
+                       line = ((size-1)/rows)*rows;
+               }
+
                /* Hack -- go to a specific file */
-               if (k == '%')
+               if (skey == '%')
                {
                        char tmp[81];
 #ifdef JP
@@ -5434,21 +5678,28 @@ strcpy(tmp, "jhelp.hlp");
 #endif
 
 
-                       if (askfor_aux(tmp, 80))
+                       if (askfor(tmp, 80))
                        {
-                               if (!show_file(TRUE, tmp, NULL, 0, mode)) k = 'q';
+                               if (!show_file(TRUE, tmp, NULL, 0, mode)) skey = 'q';
                        }
                }
 
                /* Allow backing up */
-               if (k == '-')
+               if (skey == '-')
                {
                        line = line + (reverse ? rows : -rows);
                        if (line < 0) line = 0;
                }
 
+               /* One page up */
+               if (skey == SKEY_PGUP)
+               {
+                       line = line - rows;
+                       if (line < 0) line = 0;
+               }
+
                /* Advance a single line */
-               if ((k == '\n') || (k == '\r'))
+               if ((skey == '\n') || (skey == '\r'))
                {
                        line = line + (reverse ? -1 : 1);
                        if (line < 0) line = 0;
@@ -5456,19 +5707,25 @@ strcpy(tmp, "jhelp.hlp");
 
 
                /* Move up / down */
-               if (k == '8')
+               if (skey == '8' || skey == SKEY_UP)
                {
                        line--;
                        if (line < 0) line = 0;
                }
 
-               if (k == '2') line++;
+               if (skey == '2' || skey == SKEY_DOWN) line++;
 
                /* Advance one page */
-               if (k == ' ')
+               if (skey == ' ')
                {
                        line = line + (reverse ? -rows : rows);
-                       if (line < 0) line = ((size-1)/rows)*rows;
+                       if (line < 0) line = 0;
+               }
+
+               /* One page down */
+               if (skey == SKEY_PGDOWN)
+               {
+                       line = line + rows;
                }
 
                /* Recurse on numbers */
@@ -5476,19 +5733,19 @@ strcpy(tmp, "jhelp.hlp");
                {
                        int key = -1;
 
-                       if (isalpha(k))
-                               key = k - 'A';
+                       if (!(skey & SKEY_MASK) && isalpha(skey))
+                               key = skey - 'A';
 
                        if ((key > -1) && hook[key][0])
                        {
                                /* Recurse on that file */
                                if (!show_file(TRUE, hook[key], NULL, 0, mode))
-                                       k = 'q';
+                                       skey = 'q';
                        }
                }
 
                /* Hack, dump to file */
-               if (k == '|')
+               if (skey == '|')
                {
                        FILE *ffp;
                        char buff[1024];
@@ -5508,9 +5765,6 @@ strcpy(tmp, "jhelp.hlp");
                        /* Close it */
                        my_fclose(fff);
 
-                        /* Drop priv's */
-                       safe_setuid_drop();
-
                        /* Build the filename */
                        path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
 
@@ -5528,7 +5782,7 @@ msg_print("
                                msg_print("Failed to open file.");
 #endif
 
-                               k = ESCAPE;
+                               skey = ESCAPE;
                                break;
                        }
 
@@ -5543,23 +5797,26 @@ msg_print("
                        my_fclose(fff);
                        my_fclose(ffp);
 
-                       /* Grab priv's */
-                       safe_setuid_grab();
-
                        /* Hack -- Re-Open the file */
                        fff = my_fopen(path, "r");
                }
 
-               /* Exit on escape */
-               if (k == ESCAPE) break;
-               if (k == 'q') break;
+               /* Return to last screen */
+               if (skey == ESCAPE) break;
+               if (skey == '<') break;
+
+               /* Exit on the ^q */
+               if (skey == KTRL('q')) skey = 'q';
+
+               /* Exit on the q key */
+               if (skey == 'q') break;
        }
 
        /* Close the file */
        my_fclose(fff);
 
        /* Escape */
-       if (k == 'q') return (FALSE);
+       if (skey == 'q') return (FALSE);
 
        /* Normal return */
        return (TRUE);
@@ -5688,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;
        }
@@ -5723,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;
@@ -5793,9 +6050,6 @@ void get_name(void)
                strcpy(player_name, "PLAYER");
        }
 
-       /* Process the player name */
-       process_player_name(FALSE);
-
        strcpy(tmp,ap_ptr->title);
 #ifdef JP
        if(ap_ptr->no == 1)
@@ -5864,6 +6118,28 @@ prt("
                if (i != '@') return;
        }
 
+       /* Initialize "last message" buffer */
+       if (p_ptr->last_message) string_free(p_ptr->last_message);
+       p_ptr->last_message = NULL;
+
+       /* Hack -- Note *winning* message */
+       if (p_ptr->total_winner && last_words)
+       {
+               char buf[1024] = "";
+
+#ifdef JP
+               while (!get_string("*¾¡Íø*¥á¥Ã¥»¡¼¥¸: ", buf, sizeof buf)) ;
+#else
+               while (!get_string("*Winning* message: ", buf, sizeof buf)) ;
+#endif
+
+               if (buf[0])
+               {
+                       p_ptr->last_message = string_make(buf);
+                       msg_print(p_ptr->last_message);
+               }
+       }
+
        /* Stop playing */
        p_ptr->playing = FALSE;
 
@@ -5980,6 +6256,11 @@ prt("
        (void)strcpy(p_ptr->died_from, "(alive and well)");
 #endif
 
+       /* Update some things */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_DISTANCE);
+
+       /* Update stuff */
+       update_stuff();
 }
 
 
@@ -6010,11 +6291,9 @@ long total_points(void)
        u32b point, point_h, point_l;
        int arena_win = MIN(p_ptr->arena_number, MAX_ARENA_MONS);
 
-       if (stupid_monsters) mult -= 70;
        if (!preserve_mode) mult += 10;
        if (!autoroller) mult += 10;
        if (!smart_learn) mult -= 20;
-       if (!terrain_streams) mult -= 20;
        if (smart_cheat) mult += 30;
        if (ironman_shops) mult += 50;
        if (ironman_small_levels) mult += 10;
@@ -6025,11 +6304,11 @@ long total_points(void)
 
        if (mult < 5) mult = 5;
 
-        for (i = 0; i < max_d_idx; i++)
-                if(max_dlv[i] > max_dl)
-                        max_dl = max_dlv[i];
+       for (i = 0; i < max_d_idx; i++)
+               if(max_dlv[i] > max_dl)
+                       max_dl = max_dlv[i];
 
-       point_l = (p_ptr->max_exp + (100 * max_dl));
+       point_l = (p_ptr->max_max_exp + (100 * max_dl));
        point_h = point_l / 0x10000L;
        point_l = point_l % 0x10000L;
        point_h *= mult;
@@ -6042,13 +6321,13 @@ long total_points(void)
        point_l /= 100;
 
        point = (point_h << 16) + (point_l);
-       if (p_ptr->arena_number < 99)
+       if (p_ptr->arena_number >= 0)
                point += (arena_win * arena_win * (arena_win > 29 ? 1000 : 100));
 
        if (ironman_downward) point *= 2;
        if (p_ptr->pclass == CLASS_BERSERKER)
        {
-               if ((p_ptr->prace == RACE_SPECTRE) || (p_ptr->prace == RACE_AMBERITE))
+               if ( p_ptr->prace == RACE_SPECTRE )
                        point = point / 5;
        }
 
@@ -6124,9 +6403,15 @@ static void make_bones(void)
                        /* File type is "TEXT" */
                        FILE_TYPE(FILE_TYPE_TEXT);
 
+                       /* Grab permissions */
+                       safe_setuid_grab();
+
                        /* Try to write a new "Bones File" */
                        fp = my_fopen(str, "w");
 
+                       /* Drop permissions */
+                       safe_setuid_drop();
+
                        /* Not allowed to write it?  Weird. */
                        if (!fp) return;
 
@@ -6216,7 +6501,7 @@ static void print_tomb(void)
                if (p_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL))
                {
 #ifdef JP
-                /* ±ÑÆüÀÚ¤êÂؤ¨ */
+               /* ±ÑÆüÀÚ¤êÂؤ¨ */
                  p= "°ÎÂç¤Ê¤ë¼Ô";
 #else
                        p = "Magnificent";
@@ -6274,57 +6559,57 @@ static void print_tomb(void)
                put_str(buf, 13, 11);
 
 #ifdef JP
-        /* Êè¤Ë¹ï¤à¸ÀÍÕ¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */
-        if (streq(p_ptr->died_from, "ÅÓÃ潪λ"))
-        {
-                strcpy(tmp, "<¼«»¦>");
-        }
-        else
-        {
-                if (streq(p_ptr->died_from, "ripe"))
-                {
-                        strcpy(tmp, "°úÂà¸å¤ËÅ·¼÷¤òÁ´¤¦");
-                }
-                else if (streq(p_ptr->died_from, "Seppuku"))
-                {
-                        strcpy(tmp, "¾¡Íø¤Î¸å¡¢ÀÚÊ¢");
-                }
-                else
-                {
-                        strcpy(tmp, p_ptr->died_from);
-                }
-        }
-        center_string(buf, tmp);
-        put_str(buf, 14, 11);
-
-        if(!streq(p_ptr->died_from, "ripe") && !streq(p_ptr->died_from, "Seppuku"))
-        {
-                if( dun_level == 0 )
-                {
+       /* Êè¤Ë¹ï¤à¸ÀÍÕ¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */
+       if (streq(p_ptr->died_from, "ÅÓÃ潪λ"))
+       {
+               strcpy(tmp, "<¼«»¦>");
+       }
+       else
+       {
+               if (streq(p_ptr->died_from, "ripe"))
+               {
+                       strcpy(tmp, "°úÂà¸å¤ËÅ·¼÷¤òÁ´¤¦");
+               }
+               else if (streq(p_ptr->died_from, "Seppuku"))
+               {
+                       strcpy(tmp, "¾¡Íø¤Î¸å¡¢ÀÚÊ¢");
+               }
+               else
+               {
+                       strcpy(tmp, p_ptr->died_from);
+               }
+       }
+       center_string(buf, tmp);
+       put_str(buf, 14, 11);
+
+       if(!streq(p_ptr->died_from, "ripe") && !streq(p_ptr->died_from, "Seppuku"))
+       {
+               if( dun_level == 0 )
+               {
                        cptr town = (p_ptr->town_num ? "³¹" : "¹ÓÌî");
-                        if(streq(p_ptr->died_from, "ÅÓÃ潪λ"))
-                        {
-                                sprintf(tmp, "%s¤Ç»à¤ó¤À", town);
-                        }
-                        else
-                        {
-                                sprintf(tmp, "¤Ë%s¤Ç»¦¤µ¤ì¤¿", town);
-                        }
-                }
-                else
-                {
-                        if(streq(p_ptr->died_from, "ÅÓÃ潪λ"))
-                        {
-                                sprintf(tmp, "Ãϲ¼ %d ³¬¤Ç»à¤ó¤À", dun_level);
-                        }
-                        else
-                        {
-                                sprintf(tmp, "¤ËÃϲ¼ %d ³¬¤Ç»¦¤µ¤ì¤¿", dun_level);
-                        }
-                }
-                center_string(buf, tmp);
-                put_str(buf, 15, 11);
-        }
+                       if(streq(p_ptr->died_from, "ÅÓÃ潪λ"))
+                       {
+                               sprintf(tmp, "%s¤Ç»à¤ó¤À", town);
+                       }
+                       else
+                       {
+                               sprintf(tmp, "¤Ë%s¤Ç»¦¤µ¤ì¤¿", town);
+                       }
+               }
+               else
+               {
+                       if(streq(p_ptr->died_from, "ÅÓÃ潪λ"))
+                       {
+                               sprintf(tmp, "Ãϲ¼ %d ³¬¤Ç»à¤ó¤À", dun_level);
+                       }
+                       else
+                       {
+                               sprintf(tmp, "¤ËÃϲ¼ %d ³¬¤Ç»¦¤µ¤ì¤¿", dun_level);
+                       }
+               }
+               center_string(buf, tmp);
+               put_str(buf, 15, 11);
+       }
 #else
                (void)sprintf(tmp, "Killed on Level %d", dun_level);
                center_string(buf, tmp);
@@ -6440,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;
@@ -6449,7 +6734,7 @@ put_str("
                screen_save();
 
                /* Dump a character file */
-               (void)file_character(out_val, TRUE);
+               (void)file_character(out_val);
 
                /* Load screen */
                screen_load();
@@ -6532,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);
                                }
 
@@ -6686,9 +6971,14 @@ void close_game(void)
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
+       /* Grab permissions */
+       safe_setuid_grab();
+
        /* Open the high score file, for reading/writing */
        highscore_fd = fd_open(buf, O_RDWR);
 
+       /* Drop permissions */
+       safe_setuid_drop();
 
        /* Handle death */
        if (p_ptr->is_dead)
@@ -6698,9 +6988,9 @@ void close_game(void)
 
                /* Save memories */
 #ifdef JP
-               if (!munchkin_death || get_check("»à¤ó¤À¥Ç¡¼¥¿¤ò¥»¡¼¥Ö¤·¤Þ¤¹¤«¡© "))
+               if (!cheat_save || get_check("»à¤ó¤À¥Ç¡¼¥¿¤ò¥»¡¼¥Ö¤·¤Þ¤¹¤«¡© "))
 #else
-               if (!munchkin_death || get_check("Save death? "))
+               if (!cheat_save || get_check("Save death? "))
 #endif
                {
 
@@ -6780,6 +7070,8 @@ prt("
        /* Forget the high score fd */
        highscore_fd = -1;
 
+       /* Kill all temporal files */
+       clear_saved_floor_files();
 
        /* Allow suspending now */
        signals_handle_tstp();
@@ -6857,9 +7149,8 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
 {
        FILE    *fp;
        char    buf[1024];
-       int     line, counter, test, numentries;
+       int     counter, test;
        int     line_num = 0;
-       bool    found = FALSE;
 
 
        /* Build the filename */
@@ -6869,7 +7160,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
        fp = my_fopen(buf, "r");
 
        /* Failed */
-       if (!fp) return (-1);
+       if (!fp) return -1;
 
        /* Find the entry of the monster */
        while (TRUE)
@@ -6887,42 +7178,28 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
                                if (buf[2] == '*')
                                {
                                        /* Default lines */
-                                       found = TRUE;
                                        break;
                                }
                                else if (buf[2] == 'M')
                                {
-                                       if (r_info[entry].flags1 & RF1_MALE)
-                                       {
-                                               found = TRUE;
-                                               break;
-                                       }
+                                       if (r_info[entry].flags1 & RF1_MALE) break;
                                }
                                else if (buf[2] == 'F')
                                {
-                                       if (r_info[entry].flags1 & RF1_FEMALE)
-                                       {
-                                               found = TRUE;
-                                               break;
-                                       }
+                                       if (r_info[entry].flags1 & RF1_FEMALE) break;
                                }
                                /* Get the monster number */
                                else if (sscanf(&(buf[2]), "%d", &test) != EOF)
                                {
-                                       /* Is it the right monster? */
-                                       if (test == entry)
-                                       {
-                                               found = TRUE;
-                                               break;
-                                       }
+                                       /* Is it the right number? */
+                                       if (test == entry) break;
                                }
                                else
                                {
-                                       /* Error while converting the monster number */
-                                       msg_format("Error in line %d of %s!",
-                                                 line_num, file_name);
+                                       /* Error while converting the number */
+                                       msg_format("Error in line %d of %s!", line_num, file_name);
                                        my_fclose(fp);
-                                       return (-1);
+                                       return -1;
                                }
                        }
                }
@@ -6930,132 +7207,106 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
                {
                        /* Reached end of file */
                        my_fclose(fp);
-                       return (-1);
-               }
-
-       }
-       
-       /* Get the number of entries */
-       while (TRUE)
-       {
-               /* Get the line */
-               if (my_fgets(fp, buf, sizeof(buf)) == 0)
-               {
-                       /* Count the lines */
-                       line_num++;
-
-                       /* Look for the number of entries */
-                       if (isdigit(buf[0]))
-                       {
-                               /* Get the number of entries */
-                               numentries = atoi(buf);
-                               break;
-                       }
-               }
-               else
-               {
-                       /* Count the lines */
-                       line_num++;
-
-                       /* Reached end of file without finding the number */
-                       msg_format("Error in line %d of %s!",
-                                 line_num, file_name);
-
-                       my_fclose(fp);
-                       return (-1);
+                       return -1;
                }
        }
 
-       if (numentries > 0)
+       /* Get the random line */
+       for (counter = 0; ; counter++)
        {
-               /* Grab an appropriate line number */
-               line = randint0(numentries);
-
-               /* Get the random line */
-               for (counter = 0; counter <= line; counter++)
+               while (TRUE)
                {
-                       /* Count the lines */
-                       line_num++;
+                       test = my_fgets(fp, buf, sizeof(buf));
 
-                       while(TRUE)
-                       {
-                               test = my_fgets(fp, buf, sizeof(buf));
-                               if(test || buf[0] != '#')
-                                       break;
-                       }
+                       /* Count the lines */
+                       /* line_num++; No more needed */
 
-                        if (test==0)
+                       if (!test)
                        {
-                               /* Found the line */
-                               if (counter == line) break;
-                       }
-                       else
-                       {
-                               /* Error - End of file */
-                               msg_format("Error in line %d of %s!",
-                                         line_num, file_name);
+                               /* Ignore lines starting with 'N:' */
+                               if ((buf[0] == 'N') && (buf[1] == ':')) continue;
 
-                               my_fclose(fp);
-                               return (-1);
+                               if (buf[0] != '#') break;
                        }
+                       else break;
                }
 
+               /* Abort */
+               if (!buf[0]) break;
+
                /* Copy the line */
-               strcpy(output, buf);
-       }
-       else
-       {
-               return (-1);
+               if (one_in_(counter + 1)) strcpy(output, buf);
        }
 
        /* Close the file */
        my_fclose(fp);
 
        /* Success */
-       return (0);
+       return counter ? 0 : -1;
 }
 
 
 #ifdef JP
 errr get_rnd_line_jonly(cptr file_name, int entry, char *output, int count)
 {
-  int i,j,kanji;
-  errr result=1;
-  for (i=0;i<count;i++){
-    result=get_rnd_line(file_name, entry, output);
-    if(result)break;
-    kanji=0;
-    for(j=0; output[j]; j++) kanji |= iskanji(output[j]);
-    if(kanji)break;
-  }
-  return(result);
+       int  i, j, kanji;
+       errr result = 1;
+
+       for (i = 0; i < count; i++)
+       {
+               result = get_rnd_line(file_name, entry, output);
+               if (result) break;
+               kanji = 0;
+               for (j = 0; output[j]; j++) kanji |= iskanji(output[j]);
+               if (kanji) break;
+       }
+       return result;
 }
 #endif
 
 /*
  * Process file for auto picker/destroyer.
  */
-errr process_pickpref_file(cptr name)
+errr process_autopick_file(cptr name)
 {
        char buf[1024];
 
        errr err = 0;
 
-       /* Drop priv's */
-       safe_setuid_drop();
+       /* Build the filename */
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
+
+       err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
+
+       /* Result */
+       return (err);
+}
+
+
+/*
+ * Process file for player's history editor.
+ */
+errr process_histpref_file(cptr name)
+{
+       char buf[1024];
+       errr err = 0;
+       bool old_character_xtra = character_xtra;
 
        /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
-       err = process_pref_file_aux(buf, TRUE);
+       /* Hack -- prevent modification birth options in this file */
+       character_xtra = TRUE;
 
-       /* Grab priv's */
-       safe_setuid_grab();
+       err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
+
+       character_xtra = old_character_xtra;
 
        /* Result */
        return (err);
 }
 
+
 static errr counts_seek(int fd, u32b where, bool flag)
 {
        huge seekpoint;
@@ -7122,28 +7373,59 @@ errr counts_write(int where, u32b count)
 {
        int fd;
        char buf[1024];
+       errr err;
 
 #ifdef JP
        path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info_j.raw");
 #else
        path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "z_info.raw");
 #endif
+
+       /* Grab permissions */
+       safe_setuid_grab();
+
        fd = fd_open(buf, O_RDWR);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
        if (fd < 0)
        {
                /* 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();
        }
 
-       if (fd_lock(fd, F_WRLCK)) return 1;
+       /* Grab permissions */
+       safe_setuid_grab();
+
+       err = fd_lock(fd, F_WRLCK);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
+       if (err) return 1;
 
        counts_seek(fd, where, TRUE);
        fd_write(fd, (char*)(&count), sizeof(u32b));
 
-       if (fd_lock(fd, F_UNLCK)) return 1;
+       /* Grab permissions */
+       safe_setuid_grab();
+
+       err = fd_lock(fd, F_UNLCK);
+
+       /* Drop permissions */
+       safe_setuid_drop();
+
+       if (err) return 1;
 
        (void)fd_close(fd);
 
@@ -7347,7 +7629,7 @@ static void handle_signal_abort(int sig)
 #ifdef JP
 "¶²¤í¤·¤¤¥½¥Õ¥È¤Î¥Ð¥°¤¬Èô¤Ó¤«¤«¤Ã¤Æ¤­¤¿¡ª");
 #else
-                   "A gruesome software bug LEAPS out at you!");
+                   "A gruesome software bug LEAPS out at you!");
 #endif