OSDN Git Service

Avoided compiler warnings about a 32-bit integer being passed to a %ld or %lu format...
[hengbandforosx/hengbandosx.git] / src / cmd4.c
index 2073c06..d6a9606 100644 (file)
@@ -332,10 +332,31 @@ static void close_auto_dump(void)
 }
 
 
+#ifndef JP
 /*
- *   Take note to the dialy.
+ * Return suffix of ordinal number
  */
+cptr get_ordinal_number_suffix(int num)
+{
+       num = ABS(num) % 100;
+       switch (num % 10)
+       {
+       case 1:
+               return (num == 11) ? "th" : "st";
+       case 2:
+               return (num == 12) ? "th" : "nd";
+       case 3:
+               return (num == 13) ? "th" : "rd";
+       default:
+               return "th";
+       }
+}
+#endif
+
 
+/*
+ *   Take note to the diary.
+ */
 errr do_cmd_write_nikki(int type, int num, cptr note)
 {
        int day, hour, min;
@@ -345,6 +366,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
        cptr note_level = "";
        bool do_level = TRUE;
        char note_level_buf[40];
+       int q_idx;
 
        static bool disable_nikki = FALSE;
 
@@ -400,6 +422,8 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
                return (-1);
        }
 
+       q_idx = quest_number(dun_level);
+
        if (write_level)
        {
                if (p_ptr->inside_arena)
@@ -414,7 +438,8 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #else
                        note_level = "Surface:";
 #endif
-               else if (quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT)))
+               else if (q_idx && (is_fixed_quest_idx(q_idx)
+                        && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
 #ifdef JP
                        note_level = "¥¯¥¨¥¹¥È:";
 #else
@@ -436,9 +461,11 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
                case NIKKI_HIGAWARI:
                {
 #ifdef JP
-                       fprintf(fff, "%dÆüÌÜ\n",day);
+                       if (day < MAX_DAYS) fprintf(fff, "%dÆüÌÜ\n", day);
+                       else fputs("*****ÆüÌÜ\n", fff);
 #else
-                       fprintf(fff, "Day %d\n",day);
+                       if (day < MAX_DAYS) fprintf(fff, "Day %d\n", day);
+                       else fputs("Day *****\n", fff);
 #endif
                        do_level = FALSE;
                        break;
@@ -459,7 +486,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s %s¤òȯ¸«¤·¤¿¡£\n", hour, min, note_level, note);
 #else
-                       fprintf(fff, " %2d:%02d %20s discover %s.\n", hour, min, note_level, note);
+                       fprintf(fff, " %2d:%02d %20s discovered %s.\n", hour, min, note_level, note);
 #endif
                        break;
                }
@@ -499,7 +526,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s ¥é¥ó¥À¥à¥¯¥¨¥¹¥È(%s)¤òãÀ®¤·¤¿¡£\n", hour, min, note_level, name);
 #else
-                       fprintf(fff, " %2d:%02d %20s completed randome quest '%s'\n", hour, min, note_level, name);
+                       fprintf(fff, " %2d:%02d %20s completed random quest '%s'\n", hour, min, note_level, name);
 #endif
                        break;
                }
@@ -535,7 +562,8 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
                case NIKKI_STAIR:
                {
                        cptr to;
-                       if (quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT)))
+                       if (q_idx && (is_fixed_quest_idx(q_idx)
+                            && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
                        {
 #ifdef JP
                                to = "ÃϾå";
@@ -567,13 +595,13 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                                fprintf(fff, " %2d:%02d %20s µ¢´Ô¤ò»È¤Ã¤Æ%s¤Î%d³¬¤Ø²¼¤ê¤¿¡£\n", hour, min, note_level, d_name+d_info[dungeon_type].name, max_dlv[dungeon_type]);
 #else
-                               fprintf(fff, " %2d:%02d %20s recall to dungeon level %d of %s.\n", hour, min, note_level, max_dlv[dungeon_type], d_name+d_info[dungeon_type].name);
+                               fprintf(fff, " %2d:%02d %20s recalled to dungeon level %d of %s.\n", hour, min, note_level, max_dlv[dungeon_type], d_name+d_info[dungeon_type].name);
 #endif
                        else
 #ifdef JP
                                fprintf(fff, " %2d:%02d %20s µ¢´Ô¤ò»È¤Ã¤ÆÃϾå¤Ø¤ÈÌá¤Ã¤¿¡£\n", hour, min, note_level);
 #else
-                               fprintf(fff, " %2d:%02d %20s recall from dungeon to surface.\n", hour, min, note_level);
+                               fprintf(fff, " %2d:%02d %20s recalled from dungeon to surface.\n", hour, min, note_level);
 #endif
                        break;
                }
@@ -583,7 +611,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s ¥¯¥¨¥¹¥È¡Ö%s¡×¤Ø¤ÈÆÍÆþ¤·¤¿¡£\n", hour, min, note_level, quest[num].name);
 #else
-                       fprintf(fff, " %2d:%02d %20s enter quest '%s'.\n", hour, min, note_level, quest[num].name);
+                       fprintf(fff, " %2d:%02d %20s entered the quest '%s'.\n", hour, min, note_level, quest[num].name);
 #endif
                        break;
                }
@@ -592,7 +620,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s ¥ì¥Ù¥ë¡¦¥Æ¥ì¥Ý¡¼¥È¤Çæ½Ð¤·¤¿¡£\n", hour, min, note_level);
 #else
-                       fprintf(fff, " %2d:%02d %20s Get out using teleport level.\n", hour, min, note_level);
+                       fprintf(fff, " %2d:%02d %20s Got out using teleport level.\n", hour, min, note_level);
 #endif
                        break;
                }
@@ -601,7 +629,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s %s¤ò¹ØÆþ¤·¤¿¡£\n", hour, min, note_level, note);
 #else
-                       fprintf(fff, " %2d:%02d %20s buy %s.\n", hour, min, note_level, note);
+                       fprintf(fff, " %2d:%02d %20s bought %s.\n", hour, min, note_level, note);
 #endif
                        break;
                }
@@ -610,34 +638,33 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s %s¤òÇäµÑ¤·¤¿¡£\n", hour, min, note_level, note);
 #else
-                       fprintf(fff, " %2d:%02d %20s sell %s.\n", hour, min, note_level, note);
+                       fprintf(fff, " %2d:%02d %20s sold %s.\n", hour, min, note_level, note);
 #endif
                        break;
                }
                case NIKKI_ARENA:
                {
-                       if (num == 99)
+                       if (num < 0)
                        {
-
 #ifdef JP
-                               fprintf(fff, " %2d:%02d %20s Æ®µ»¾ì¤Î%d²óÀï¤Ç¡¢%s¤ÎÁ°¤ËÇÔ¤ìµî¤Ã¤¿¡£\n", hour, min, note_level, p_ptr->arena_number + 1, note);
+                               fprintf(fff, " %2d:%02d %20s Æ®µ»¾ì¤Î%d²óÀï¤Ç¡¢%s¤ÎÁ°¤ËÇÔ¤ìµî¤Ã¤¿¡£\n", hour, min, note_level, -num, note);
 #else
-                               int n =  p_ptr->arena_number + 1;
-                               fprintf(fff, " %2d:%02d %20s beaten by %s in the %d%s fight.\n", hour, min, note_level, note, n, (n%10==1?"st":n%10==2?"nd":n%10==3?"rd":"th"));
+                               int n = -num;
+                               fprintf(fff, " %2d:%02d %20s beaten by %s in the %d%s fight.\n", hour, min, note_level, note, n, get_ordinal_number_suffix(n));
 #endif
                                break;
                        }
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s Æ®µ»¾ì¤Î%d²óÀï(%s)¤Ë¾¡Íø¤·¤¿¡£\n", hour, min, note_level, num, note);
 #else
-                       fprintf(fff, " %2d:%02d %20s win the %d%s fight (%s).\n", hour, min, note_level, num, (num%10==1?"st":num%10==2?"nd":num%10==3?"rd":"th"), note);
+                       fprintf(fff, " %2d:%02d %20s won the %d%s fight (%s).\n", hour, min, note_level, num, get_ordinal_number_suffix(num), note);
 #endif
                        if (num == MAX_ARENA_MONS)
                        {
 #ifdef JP
                                fprintf(fff, "                 Æ®µ»¾ì¤Î¤¹¤Ù¤Æ¤ÎŨ¤Ë¾¡Íø¤·¡¢¥Á¥ã¥ó¥Ô¥ª¥ó¤È¤Ê¤Ã¤¿¡£\n");
 #else
-                               fprintf(fff, "                 win all fight to become a Chanpion.\n");
+                               fprintf(fff, "                 won all fight to become a Chanpion.\n");
 #endif
                                do_level = FALSE;
                        }
@@ -648,7 +675,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s %s¤ò¼±Ê̤·¤¿¡£\n", hour, min, note_level, note);
 #else
-                       fprintf(fff, " %2d:%02d %20s identify %s.\n", hour, min, note_level, note);
+                       fprintf(fff, " %2d:%02d %20s identified %s.\n", hour, min, note_level, note);
 #endif
                        break;
                }
@@ -694,7 +721,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s %s¤Ø¤È¥Ñ¥¿¡¼¥ó¤ÎÎϤǰÜÆ°¤·¤¿¡£\n", hour, min, note_level, to);
 #else
-                       fprintf(fff, " %2d:%02d %20s use Pattern to teleport to %s.\n", hour, min, note_level, to);
+                       fprintf(fff, " %2d:%02d %20s used Pattern to teleport to %s.\n", hour, min, note_level, to);
 #endif
                        break;
                }
@@ -703,7 +730,7 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                        fprintf(fff, " %2d:%02d %20s ¥ì¥Ù¥ë¤¬%d¤Ë¾å¤¬¤Ã¤¿¡£\n", hour, min, note_level, num);
 #else
-                       fprintf(fff, " %2d:%02d %20s reach player level %d.\n", hour, min, note_level, num);
+                       fprintf(fff, " %2d:%02d %20s reached player level %d.\n", hour, min, note_level, num);
 #endif
                        break;
                }
@@ -728,56 +755,63 @@ errr do_cmd_write_nikki(int type, int num, cptr note)
 #ifdef JP
                                        fprintf(fff, "%s¤òι¤Îͧ¤Ë¤¹¤ë¤³¤È¤Ë·è¤á¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "decide to travel together with %s.\n", note);
+                                       fprintf(fff, "decided to travel together with %s.\n", note);
 #endif
                                        break;
                                case 1:
 #ifdef JP
                                        fprintf(fff, "%s¤Î̾Á°¤ò¾Ã¤·¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "unname %s.\n", note);
+                                       fprintf(fff, "unnamed %s.\n", note);
 #endif
                                        break;
                                case 2:
 #ifdef JP
                                        fprintf(fff, "%s¤ò²òÊü¤·¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "dismiss %s.\n", note);
+                                       fprintf(fff, "dismissed %s.\n", note);
 #endif
                                        break;
                                case 3:
 #ifdef JP
                                        fprintf(fff, "%s¤¬»à¤ó¤Ç¤·¤Þ¤Ã¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "%s die.\n", note);
+                                       fprintf(fff, "%s died.\n", note);
 #endif
                                        break;
                                case 4:
 #ifdef JP
                                        fprintf(fff, "%s¤ò¤ª¤¤¤ÆÊ̤ΥޥåפذÜÆ°¤·¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "move to other map leaving %s behind.\n", note);
+                                       fprintf(fff, "moved to another map leaving %s behind.\n", note);
 #endif
                                        break;
                                case 5:
 #ifdef JP
                                        fprintf(fff, "%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "lose sight of %s.\n", note);
+                                       fprintf(fff, "lost sight of %s.\n", note);
 #endif
                                        break;
                                case 6:
 #ifdef JP
                                        fprintf(fff, "%s¤¬*Ç˲õ*¤Ë¤è¤Ã¤Æ¾Ã¤¨µî¤Ã¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "%s is made disappeared by *destruction*.\n", note);
+                                       fprintf(fff, "%s was made disappeared by *destruction*.\n", note);
 #endif
                                        break;
                                case 7:
 #ifdef JP
                                        fprintf(fff, "%s¤¬´äÀФ˲¡¤·ÄÙ¤µ¤ì¤¿¡£\n", note);
 #else
-                                       fprintf(fff, "%s is crushed by falling rocks.\n", note);
+                                       fprintf(fff, "%s was crushed by falling rocks.\n", note);
+#endif
+                                       break;
+                               case 8:
+#ifdef JP
+                                       fprintf(fff, "%s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Ë¤è¤Ã¤Æ¾Ã¤¨µî¤Ã¤¿¡£\n", note);
+#else
+                                       fprintf(fff, "%s was made disappeared by teleport level.\n", note);
 #endif
                                        break;
                                default:
@@ -1719,17 +1753,19 @@ static option_type autosave_info[2] =
 
 static s16b toggle_frequency(s16b current)
 {
-       if (current == 0) return 50;
-       if (current == 50) return 100;
-       if (current == 100) return 250;
-       if (current == 250) return 500;
-       if (current == 500) return 1000;
-       if (current == 1000) return 2500;
-       if (current == 2500) return 5000;
-       if (current == 5000) return 10000;
-       if (current == 10000) return 25000;
-
-       return 0;
+       switch (current)
+       {
+       case 0: return 50;
+       case 50: return 100;
+       case 100: return 250;
+       case 250: return 500;
+       case 500: return 1000;
+       case 1000: return 2500;
+       case 2500: return 5000;
+       case 5000: return 10000;
+       case 10000: return 25000;
+       default: return 0;
+       }
 }
 
 
@@ -2943,7 +2979,7 @@ void do_cmd_macros(void)
 
                /* Describe that action */
 #ifdef JP
-               prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
+               prt("¥Þ¥¯¥í¹ÔÆ°¤¬(¤â¤·¤¢¤ì¤Ð)²¼¤Ëɽ¼¨¤µ¤ì¤Þ¤¹:", 20, 0);
 #else
                prt("Current action (if any) shown below:", 20, 0);
 #endif
@@ -3582,7 +3618,7 @@ void do_cmd_visuals(void)
 
                /* Prompt */
 #ifdef JP
-               prt("¥³¥Þ¥ó¥É:", 18, 0);
+               prt("¥³¥Þ¥ó¥É:", 15, 0);
 #else
                prt("Command: ", 15, 0);
 #endif
@@ -3607,7 +3643,7 @@ void do_cmd_visuals(void)
 
                        /* Prompt */
 #ifdef JP
-                       prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
+                       prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
 #else
                        prt("File: ", 17, 0);
 #endif
@@ -4928,7 +4964,7 @@ static cptr monster_group_text[] =
        "Yeti",
        "Zephyr Hound",
        "Mimic",
-       "Wall/Plant/Gus",
+       "Wall/Plant/Gas",
        "Mushroom patch",
        "Ball",
 #endif
@@ -4940,7 +4976,7 @@ static cptr monster_group_text[] =
  * Symbols of monsters in each group. Note the "Uniques" group
  * is handled differently.
  */
-static cptr monster_group_char[] = 
+static cptr monster_group_char[] =
 {
        (char *) -1L,
        "a",
@@ -4994,8 +5030,8 @@ static cptr monster_group_char[] =
        "X",
        "Y",
        "Z",
-       "$!?=&`.|/\\~[]()>",
-       "#",
+       "!$&()+./=>?[\\]`{|~",
+       "#%",
        ",",
        "*",
        NULL
@@ -5111,6 +5147,7 @@ static cptr object_group_text[] =
        "¥´¥ß",
        "¶õ¤Î¥Ó¥ó",
        "¹ü",
+       "»àÂÎ",
        "Åá·õÎà",       /* "Swords" */
        "Æß´ï",         /* "Blunt Weapons" */
        "ĹÊÁÉð´ï",     /* "Polearms" */
@@ -5143,7 +5180,7 @@ static cptr object_group_text[] =
        "Rods",
        "Cards",
        "Capture Balls",
-       "Parchements",
+       "Parchments",
        "Spikes",
        "Boxs",
        "Figurines",
@@ -5151,6 +5188,7 @@ static cptr object_group_text[] =
        "Junks",
        "Bottles",
        "Skeletons",
+       "Corpses",
        "Swords",
        "Blunt Weapons",
        "Polearms",
@@ -5192,7 +5230,7 @@ static byte object_group_tval[] =
        TV_ROD,
        TV_CARD,
        TV_CAPTURE,
-       TV_PARCHEMENT,
+       TV_PARCHMENT,
        TV_SPIKE,
        TV_CHEST,
        TV_FIGURINE,
@@ -5200,6 +5238,7 @@ static byte object_group_tval[] =
        TV_JUNK,
        TV_BOTTLE,
        TV_SKELETON,
+       TV_CORPSE,
        TV_SWORD,
        TV_HAFTED,
        TV_POLEARM,
@@ -5369,79 +5408,6 @@ static int collect_artifacts(int grp_cur, int object_idx[])
 static char hack[17] = "dwsorgbuDWvyRGBU";
 
 
-static errr photo_fgets(FILE *fff, char *buf, huge n)
-{
-       huge i = 0;
-
-       char *s;
-
-       char tmp[1024];
-
-       /* Read a line */
-       if (fgets(tmp, 1024, fff))
-       {
-               /* Convert weirdness */
-               for (s = tmp; *s; s++)
-               {
-                       /* Handle newline */
-                       if (*s == '\n')
-                       {
-                               /* Terminate */
-                               buf[i] = '\0';
-
-                               /* Success */
-                               return (0);
-                       }
-
-                       /* Handle tabs */
-                       else if (*s == '\t')
-                       {
-                               /* Hack -- require room */
-                               if (i + 8 >= n) break;
-
-                               /* Append a space */
-                               buf[i++] = ' ';
-
-                               /* Append some more spaces */
-                               while (!(i % 8)) buf[i++] = ' ';
-                       }
-
-#ifdef JP
-                       else if (iskanji(*s))
-                       {
-                               if (!s[1]) break;
-                               buf[i++] = *s++;
-                               buf[i++] = *s;
-                       }
-# ifndef EUC
-       /* È¾³Ñ¤«¤Ê¤ËÂбþ */
-                       else if ((((int)*s & 0xff) > 0xa1) && (((int)*s & 0xff ) < 0xdf))
-                       {
-                               buf[i++] = *s;
-                               if (i >= n) break;
-                       }
-# endif
-#endif
-                       /* Handle printables */
-                       else
-                       {
-                               /* Copy */
-                               buf[i++] = *s;
-
-                               /* Check length */
-                               if (i >= n) break;
-                       }
-               }
-       }
-
-       /* Nothing */
-       buf[0] = '\0';
-
-       /* Failure */
-       return (1);
-}
-
-
 /*
  * Hack -- load a screen dump from a file
  */
@@ -5488,32 +5454,46 @@ void do_cmd_load_screen(void)
 
 
        /* Load the screen */
-       for (y = 0; okay && (y < hgt); y++)
+       for (y = 0; okay; y++)
        {
-               /* Get a line of data */
-               if (photo_fgets(fff, buf, 1024)) okay = FALSE;
+               /* Get a line of data including control code */
+               if (!fgets(buf, 1024, fff)) okay = FALSE;
+
+               /* Get the blank line */
+               if (buf[0] == '\n' || buf[0] == '\0') break;
+
+               /* Ignore too large screen image */
+               if (y >= hgt) continue;
 
                /* Show each row */
                for (x = 0; x < wid - 1; x++)
                {
+                       /* End of line */
+                       if (buf[x] == '\n' || buf[x] == '\0') break;
+
                        /* Put the attr/char */
                        Term_draw(x, y, TERM_WHITE, buf[x]);
                }
        }
 
-       /* Get the blank line */
-       if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
-
-
        /* Dump the screen */
-       for (y = 0; okay && (y < hgt); y++)
+       for (y = 0; okay; y++)
        {
-               /* Get a line of data */
-               if (photo_fgets(fff, buf, 1024)) okay = FALSE;
+               /* Get a line of data including control code */
+               if (!fgets(buf, 1024, fff)) okay = FALSE;
+
+               /* Get the blank line */
+               if (buf[0] == '\n' || buf[0] == '\0') break;
+
+               /* Ignore too large screen image */
+               if (y >= hgt) continue;
 
                /* Dump each row */
                for (x = 0; x < wid - 1; x++)
                {
+                       /* End of line */
+                       if (buf[x] == '\n' || buf[x] == '\0') break;
+
                        /* Get the attr/char */
                        (void)(Term_what(x, y, &a, &c));
 
@@ -5530,10 +5510,6 @@ void do_cmd_load_screen(void)
        }
 
 
-       /* Get the blank line */
-       if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
-
-
        /* Close it */
        my_fclose(fff);
 
@@ -6948,6 +6924,7 @@ static void do_cmd_knowledge_pets(void)
        int             i;
        FILE            *fff;
        monster_type    *m_ptr;
+       char            pet_name[80];
        int             t_friends = 0;
        int             show_upkeep = 0;
        char            file_name[1024];
@@ -6968,36 +6945,42 @@ static void do_cmd_knowledge_pets(void)
        /* Process the monsters (backwards) */
        for (i = m_max - 1; i >= 1; i--)
        {
-               monster_race *r_ptr;
                /* Access the monster */
                m_ptr = &m_list[i];
 
                /* Ignore "dead" monsters */
                if (!m_ptr->r_idx) continue;
-               r_ptr = &r_info[m_ptr->r_idx];
 
                /* Calculate "upkeep" for pets */
                if (is_pet(m_ptr))
                {
-                       char pet_name[80];
                        t_friends++;
-                       monster_desc(pet_name, m_ptr, 0x88);
-                       fprintf(fff, "%s (%s)", pet_name, look_mon_desc(i, 0x00));
-                       if (p_ptr->riding == i)
-#ifdef JP
-                               fprintf(fff, " ¾èÇÏÃæ");
-#else
-                               fprintf(fff, " Riding");
-#endif
-                       fprintf(fff, "\n");
+                       monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
+                       fprintf(fff, "%s (%s)\n", pet_name, look_mon_desc(m_ptr, 0x00));
                }
        }
 
+       /* Process the waiting pets (backwards) */
+       for (i = MAX_PARTY_MON - 1; i >= 0; i--)
+       {
+               /* Access the monster */
+               m_ptr = &party_mon[i];
+
+               /* Ignore "dead" monsters */
+               if (!m_ptr->r_idx) continue;
+
+               t_friends++;
+
+               /* List waiting pets */
+               monster_desc(pet_name, m_ptr, MD_ASSUME_OUTSIDE | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
+               fprintf(fff, "%s (%s)\n", pet_name, look_mon_desc(m_ptr, 0x00));
+       }
+
        show_upkeep = calculate_upkeep();
 
        fprintf(fff, "----------------------------------------------\n");
 #ifdef JP
-       fprintf(fff, "    ¹ç·×: %d ɤ¤Î¥Ú¥Ã¥È\n", t_friends);
+       fprintf(fff, "    ¹ç·×: %d ÂΤΥڥåÈ\n", t_friends);
        fprintf(fff, " °Ý»ý¥³¥¹¥È: %d%% MP\n", show_upkeep);
 #else
        fprintf(fff, "   Total: %d pet%s.\n",
@@ -7038,7 +7021,7 @@ static void do_cmd_knowledge_kill_count(void)
 
        char file_name[1024];
 
-       s32b Total = 0;
+       long Total = 0;
 
 
        /* Open a new file */
@@ -7091,21 +7074,12 @@ static void do_cmd_knowledge_kill_count(void)
 #else
                        fprintf(fff,"You have defeated no enemies yet.\n\n");
 #endif
-
-               else if (Total == 1)
-#ifdef JP
-                       fprintf(fff,"¤¢¤Ê¤¿¤Ï°ìɤ¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n");
-#else
-                       fprintf(fff,"You have defeated one enemy.\n\n");
-#endif
-
                else
 #ifdef JP
-                       fprintf(fff,"¤¢¤Ê¤¿¤Ï %lu ɤ¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n", Total);
+                       fprintf(fff,"¤¢¤Ê¤¿¤Ï%ldÂΤÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n", Total);
 #else
-                       fprintf(fff,"You have defeated %lu enemies.\n\n", Total);
+                       fprintf(fff,"You have defeated %ld %s.\n\n", Total, (Total == 1) ? "enemy" : "enemies");
 #endif
-
        }
 
        Total = 0;
@@ -7150,11 +7124,11 @@ static void do_cmd_knowledge_kill_count(void)
                        if (This > 0)
                        {
 #ifdef JP
-                               /* p,t¤Ï¿Í¤È¿ô¤¨¤ë by ita*/
-                               if(strchr("pt",r_ptr->d_char))
+                               /* p,t¤Ï¿Í¤È¿ô¤¨¤ë by ita */
+                               if (strchr("pt", r_ptr->d_char))
                                        fprintf(fff, "     %3d ¿Í¤Î %s\n", This, r_name + r_ptr->name);
                                else
-                                       fprintf(fff, "     %3d ɤ¤Î %s\n", This, r_name + r_ptr->name);
+                                       fprintf(fff, "     %3d ÂΤΠ%s\n", This, r_name + r_ptr->name);
 #else
                                if (This < 2)
                                {
@@ -7184,7 +7158,7 @@ static void do_cmd_knowledge_kill_count(void)
 
        fprintf(fff,"----------------------------------------------\n");
 #ifdef JP
-       fprintf(fff,"    ¹ç·×: %lu ɤ¤òÅݤ·¤¿¡£\n", Total);
+       fprintf(fff,"    ¹ç·×: %lu ÂΤòÅݤ·¤¿¡£\n", Total);
 #else
        fprintf(fff,"   Total: %lu creature%s killed.\n",
                Total, (Total == 1 ? "" : "s"));
@@ -7492,7 +7466,7 @@ static bool visual_mode_command(char ch, bool *visual_list_ptr,
 
        case 'P':
        case 'p':
-               if (attr_idx)
+               if (attr_idx || (!(char_idx & 0x80) && char_idx)) /* Allow TERM_DARK text */
                {
                        /* Set the char */
                        *cur_attr_ptr = attr_idx;
@@ -7587,13 +7561,16 @@ static void display_monster_list(int col, int row, int per_page, s16b mon_idx[],
                }
                else if (p_ptr->wizard) 
                {
-                       c_prt(attr, format("%d", r_idx), row + i, 60);
+                       c_prt(attr, format("%d", r_idx), row + i, 62);
                }
 
                a = r_ptr->x_attr;
                c = r_ptr->x_char;
                if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
 
+               /* Erase chars before overwritten by the race letter */
+               Term_erase(69, row + i, 255);
+
                /* Display symbol */
                Term_putch(70, row + i, a, c);
 
@@ -7603,9 +7580,9 @@ static void display_monster_list(int col, int row, int per_page, s16b mon_idx[],
                /* Display kills */
                if (!(r_ptr->flags1 & RF1_UNIQUE)) put_str(format("%5d", r_ptr->r_pkills), row + i, 73);
 #ifdef JP
-               else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "»àË´" : "À¸Â¸"), row + i, 73);
+               else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "»àË´" : "À¸Â¸"), row + i, 74);
 #else
-               else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "dead" : "alive"), row + i, 73);
+               else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? " dead" : "alive"), row + i, 73);
 #endif
        
        }
@@ -7692,14 +7669,14 @@ static void do_cmd_knowledge_monsters(void)
                        prt("Ãμ± - ¥â¥ó¥¹¥¿¡¼", 2, 0);
                        prt("¥°¥ë¡¼¥×", 4, 0);
                        prt("̾Á°", 4, max + 3);
-                       if (p_ptr->wizard) prt("Idx", 4, 60);
+                       if (p_ptr->wizard) prt("Idx", 4, 62);
                        prt("ʸ»ú »¦³²¿ô", 4, 67);
 #else
                        prt("Knowledge - Monsters", 2, 0);
                        prt("Group", 4, 0);
                        prt("Name", 4, max + 3);
-                       if (p_ptr->wizard) prt("Idx", 4, 60);
-                       prt("Sym   Kills", 4, 67);
+                       if (p_ptr->wizard) prt("Idx", 4, 62);
+                       prt("Sym  Kills", 4, 68);
 #endif
 
                        for (i = 0; i < 78; i++)
@@ -7922,7 +7899,7 @@ static void desc_obj_fake(int k_idx)
        /* Hack -- Handle stuff */
        handle_stuff();
 
-       if (!screen_object(o_ptr, FALSE))
+       if (!screen_object(o_ptr, SCROBJ_FAKE_OBJECT | SCROBJ_FORCE_DETAIL))
        {
 #ifdef JP
                msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
@@ -8011,7 +7988,7 @@ static void do_cmd_knowledge_objects(void)
                        prt("¥°¥ë¡¼¥×", 4, 0);
                        prt("̾Á°", 4, max + 3);
                        if (p_ptr->wizard) prt("Idx", 4, 70);
-                       prt("ʸ»ú", 4, 75);
+                       prt("ʸ»ú", 4, 74);
 #else
                        prt("Knowledge - objects", 2, 0);
                        prt("Group", 4, 0);
@@ -8078,7 +8055,7 @@ static void do_cmd_knowledge_objects(void)
 
                /* Prompt */
 #ifdef JP
-               prt(format("<Êý¸þ>, 'r'¤Ç»×¤¤½Ð¤ò¸«¤ë%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
+               prt(format("<Êý¸þ>, 'r'¤Ç¾ÜºÙ¤ò¸«¤ë%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
 #else
                prt(format("<dir>, 'r' to recall%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER to accept" : ", 'v' for visuals", (attr_idx||char_idx) ? ", 'c', 'p' to paste" : ", 'c' to copy"), hgt - 1, 0);
 #endif
@@ -8268,11 +8245,18 @@ static void do_cmd_knowledge_features(void)
                if (redraw)
                {
                        clear_from(0);
-               
+
+#ifdef JP
+                       prt("ɽ¼¨ - ÃÏ·Á", 2, 0);
+                       prt("¥°¥ë¡¼¥×", 4, 0);
+                       prt("̾Á°", 4, max + 3);
+                       prt("ʸ»ú", 4, 66);
+#else
                        prt("Visuals - features", 2, 0);
                        prt("Group", 4, 0);
                        prt("Name", 4, max + 3);
                        prt("Sym", 4, 67);
+#endif
 
                        for (i = 0; i < 78; i++)
                        {
@@ -8402,6 +8386,8 @@ static void do_cmd_knowledge_kubi(void)
        
        if (fff)
        {
+               bool listed = FALSE;
+
 #ifdef JP
                fprintf(fff, "º£Æü¤Î¥¿¡¼¥²¥Ã¥È : %s\n", (p_ptr->today_mon ? r_name + r_info[p_ptr->today_mon].name : "ÉÔÌÀ"));
                fprintf(fff, "\n");
@@ -8411,17 +8397,25 @@ static void do_cmd_knowledge_kubi(void)
                fprintf(fff, "\n");
                fprintf(fff, "List of wanted monsters\n");
 #endif
+               fprintf(fff, "----------------------------------------------\n");
+
                for (i = 0; i < MAX_KUBI; i++)
                {
-                       fprintf(fff,"%-40s ---- ",r_name + r_info[(kubi_r_idx[i] > 10000 ? kubi_r_idx[i] - 10000 : kubi_r_idx[i])].name);
-                       if (kubi_r_idx[i] > 10000)
+                       if (kubi_r_idx[i] <= 10000)
+                       {
+                               fprintf(fff,"%s\n", r_name + r_info[kubi_r_idx[i]].name);
+
+                               listed = TRUE;
+                       }
+               }
+
+               if (!listed)
+               {
 #ifdef JP
-                               fprintf(fff, "ºÑ\n");
+                       fprintf(fff,"\n%s\n", "¾Þ¶â¼ó¤Ï¤â¤¦»Ä¤Ã¤Æ¤¤¤Þ¤»¤ó¡£");
 #else
-                               fprintf(fff, "done\n");
+                       fprintf(fff,"\n%s\n", "There is no more wanted monster.");
 #endif
-                       else
-                               fprintf(fff, "$%d\n", 300 * (r_info[kubi_r_idx[i]].level + 1));
                }
        }
        
@@ -8611,12 +8605,10 @@ static void do_cmd_knowledge_stat(void)
 
 
 /*
- * Print quest status of all active quests
+ * Print all active quests
  */
-static void do_cmd_knowledge_quests(void)
+static void do_cmd_knowledge_quests_current(FILE *fff)
 {
-       FILE *fff;
-       char file_name[1024];
        char tmp_str[120];
        char rand_tmp_str[120] = "\0";
        char name[80];
@@ -8625,18 +8617,6 @@ static void do_cmd_knowledge_quests(void)
        int rand_level = 100;
        int total = 0;
 
-       /* Open a new file */
-       fff = my_fopen_temp(file_name, 1024);
-       if (!fff) {
-#ifdef JP
-           msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
-#else
-           msg_format("Failed to create temporary file %s.", file_name);
-#endif
-           msg_print(NULL);
-           return;
-       }
-
 #ifdef JP
        fprintf(fff, "¡Ô¿ë¹ÔÃæ¤Î¥¯¥¨¥¹¥È¡Õ\n");
 #else
@@ -8645,21 +8625,16 @@ static void do_cmd_knowledge_quests(void)
 
        for (i = 1; i < max_quests; i++)
        {
-               if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_COMPLETED)
+               if ((quest[i].status == QUEST_STATUS_TAKEN) || (quest[i].status == QUEST_STATUS_COMPLETED))
                {
-                       int old_quest;
+                       /* Set the quest number temporary */
+                       int old_quest = p_ptr->inside_quest;
                        int j;
 
                        /* Clear the text */
-                       for (j = 0; j < 10; j++)
-                       {
-                               quest_text[j][0] = '\0';
-                       }
-
+                       for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
                        quest_text_line = 0;
 
-                       /* Set the quest number temporary */
-                       old_quest = p_ptr->inside_quest;
                        p_ptr->inside_quest = i;
 
                        /* Get the quest text */
@@ -8681,17 +8656,21 @@ static void do_cmd_knowledge_quests(void)
 
                                if (quest[i].status == QUEST_STATUS_TAKEN)
                                {
-                                       if (quest[i].type == QUEST_TYPE_KILL_LEVEL || quest[i].type == QUEST_TYPE_KILL_ANY_LEVEL)
+                                       switch (quest[i].type)
                                        {
+                                       case QUEST_TYPE_KILL_LEVEL:
+                                       case QUEST_TYPE_KILL_ANY_LEVEL:
                                                r_ptr = &r_info[quest[i].r_idx];
                                                strcpy(name, r_name + r_ptr->name);
                                                if (quest[i].max_num > 1)
                                                {
 #ifdef JP
-                                                       sprintf(note," - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",quest[i].max_num, name, quest[i].max_num-quest[i].cur_num);
+                                                       sprintf(note," - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
+                                                               quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
 #else
                                                        plural_aux(name);
-                                                       sprintf(note," - kill %d %s, have killed %d.",quest[i].max_num, name, quest[i].cur_num);
+                                                       sprintf(note," - kill %d %s, have killed %d.",
+                                                               quest[i].max_num, name, quest[i].cur_num);
 #endif
                                                }
                                                else
@@ -8700,44 +8679,51 @@ static void do_cmd_knowledge_quests(void)
 #else
                                                        sprintf(note," - kill %s.",name);
 #endif
-                                       }
-                                       else if (quest[i].type == QUEST_TYPE_KILL_NUMBER)
-                                       {
-#ifdef JP
-                                               sprintf(note," - %d ÂΤΥâ¥ó¥¹¥¿¡¼¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",quest[i].max_num, quest[i].max_num-quest[i].cur_num);
-#else
-                                               sprintf(note," - Kill %d monsters, have killed %d.",quest[i].max_num, quest[i].cur_num);
-#endif
-                                       }
-                                       else if (quest[i].type == QUEST_TYPE_FIND_ARTIFACT)
-                                       {
+                                               break;
+
+                                       case QUEST_TYPE_FIND_ARTIFACT:
                                                strcpy(name, a_name + a_info[quest[i].k_idx].name);
 #ifdef JP
                                                sprintf(note," - %s¤ò¸«¤Ä¤±½Ð¤¹¡£", name);
 #else
                                                sprintf(note," - Find out %s.", name);
 #endif
-                                       }
-                                       else if (quest[i].type == QUEST_TYPE_FIND_EXIT)
+                                               break;
+
+                                       case QUEST_TYPE_FIND_EXIT:
 #ifdef JP
                                                sprintf(note," - Ãµº÷¤¹¤ë¡£");
 #else
                                                sprintf(note," - Search.");
 #endif
-                                       else if (quest[i].type == QUEST_TYPE_KILL_ALL)
+                                               break;
+
+                                       case QUEST_TYPE_KILL_NUMBER:
+#ifdef JP
+                                               sprintf(note," - %d ÂΤΥâ¥ó¥¹¥¿¡¼¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
+                                                       quest[i].max_num, quest[i].max_num - quest[i].cur_num);
+#else
+                                               sprintf(note," - Kill %d monsters, have killed %d.",
+                                                       quest[i].max_num, quest[i].cur_num);
+#endif
+                                               break;
+
+                                       case QUEST_TYPE_KILL_ALL:
 #ifdef JP
                                                sprintf(note," - Á´¤Æ¤Î¥â¥ó¥¹¥¿¡¼¤òÅݤ¹¡£");
 #else
                                                sprintf(note," - Kill all monsters.");
 #endif
+                                               break;
+                                       }
                                }
 
                                /* Print the quest info */
 #ifdef JP
-                               sprintf(tmp_str, "%s (´í¸±ÅÙ:%d³¬ÁêÅö)%s\n",
+                               sprintf(tmp_str, "  %s (´í¸±ÅÙ:%d³¬ÁêÅö)%s\n",
                                        quest[i].name, quest[i].level, note);
 #else
-                               sprintf(tmp_str, "%s (Danger level: %d)%s\n",
+                               sprintf(tmp_str, "  %s (Danger level: %d)%s\n",
                                        quest[i].name, quest[i].level, note);
 #endif
 
@@ -8746,11 +8732,10 @@ static void do_cmd_knowledge_quests(void)
                                if (quest[i].status == QUEST_STATUS_COMPLETED)
                                {
 #ifdef JP
-                                       sprintf(tmp_str, "  ¥¯¥¨¥¹¥ÈãÀ® - ¤Þ¤ÀÊó½·¤ò¼õ¤±¤È¤Ã¤Æ¤Ê¤¤¡£\n");
+                                       sprintf(tmp_str, "    ¥¯¥¨¥¹¥ÈãÀ® - ¤Þ¤ÀÊó½·¤ò¼õ¤±¤È¤Ã¤Æ¤Ê¤¤¡£\n");
 #else
-                                       sprintf(tmp_str, "  Quest Completed - Unrewarded\n");
+                                       sprintf(tmp_str, "    Quest Completed - Unrewarded\n");
 #endif
-
                                        fprintf(fff, tmp_str);
                                }
                                else
@@ -8759,13 +8744,12 @@ static void do_cmd_knowledge_quests(void)
 
                                        while (quest_text[j][0] && j < 10)
                                        {
-                                               fprintf(fff, "  %s\n", quest_text[j]);
+                                               fprintf(fff, "    %s\n", quest_text[j]);
                                                j++;
                                        }
                                }
                        }
-                       else if ((quest[i].type == QUEST_TYPE_RANDOM) &&
-                                (quest[i].level < rand_level))
+                       else if (quest[i].level < rand_level) /* QUEST_TYPE_RANDOM */
                        {
                                /* New random */
                                rand_level = quest[i].level;
@@ -8779,13 +8763,13 @@ static void do_cmd_knowledge_quests(void)
                                        if (quest[i].max_num > 1)
                                        {
 #ifdef JP
-                                               sprintf(rand_tmp_str,"%s (%d ³¬) - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)\n",
+                                               sprintf(rand_tmp_str,"  %s (%d ³¬) - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)\n",
                                                        quest[i].name, quest[i].level,
-                                                       quest[i].max_num, name, quest[i].max_num-quest[i].cur_num);
+                                                       quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
 #else
                                                plural_aux(name);
 
-                                               sprintf(rand_tmp_str,"%s (Dungeon level: %d)\n  Kill %d %s, have killed %d.\n",
+                                               sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %d %s, have killed %d.\n",
                                                        quest[i].name, quest[i].level,
                                                        quest[i].max_num, name, quest[i].cur_num);
 #endif
@@ -8793,10 +8777,10 @@ static void do_cmd_knowledge_quests(void)
                                        else
                                        {
 #ifdef JP
-                                               sprintf(rand_tmp_str,"%s (%d ³¬) - %s¤òÅݤ¹¡£\n",
+                                               sprintf(rand_tmp_str,"  %s (%d ³¬) - %s¤òÅݤ¹¡£\n",
                                                        quest[i].name, quest[i].level, name);
 #else
-                                               sprintf(rand_tmp_str,"%s (Dungeon level: %d)\n  Kill %s.\n",
+                                               sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %s.\n",
                                                        quest[i].name, quest[i].level, name);
 #endif
                                        }
@@ -8809,28 +8793,39 @@ static void do_cmd_knowledge_quests(void)
        if (rand_tmp_str[0]) fprintf(fff, rand_tmp_str);
 
 #ifdef JP
-       if (!total) fprintf(fff, "¤Ê¤·\n");
+       if (!total) fprintf(fff, "  ¤Ê¤·\n");
 #else
-       if (!total) fprintf(fff, "Nothing.\n");
+       if (!total) fprintf(fff, "  Nothing.\n");
 #endif
+}
+
+
+/*
+ * Print all finished quests
+ */
+void do_cmd_knowledge_quests_completed(FILE *fff, int quest_num[])
+{
+       char tmp_str[120];
+       int i;
+       int total = 0;
 
 #ifdef JP
-       fprintf(fff, "\n¡ÔãÀ®¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
+       fprintf(fff, "¡ÔãÀ®¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
 #else
-       fprintf(fff, "\n< Completed Quest >\n");
+       fprintf(fff, "< Completed Quest >\n");
 #endif
-       total = 0;
        for (i = 1; i < max_quests; i++)
        {
-               if (quest[i].status == QUEST_STATUS_FINISHED)
+               int q_idx = quest_num[i];
+
+               if (quest[q_idx].status == QUEST_STATUS_FINISHED)
                {
-                       if (i < MIN_RANDOM_QUEST)
+                       if (is_fixed_quest_idx(q_idx))
                        {
-                               int old_quest;
-
                                /* Set the quest number temporary */
-                               old_quest = p_ptr->inside_quest;
-                               p_ptr->inside_quest = i;
+                               int old_quest = p_ptr->inside_quest;
+
+                               p_ptr->inside_quest = q_idx;
 
                                /* Get the quest */
                                init_flags = INIT_ASSIGN;
@@ -8841,48 +8836,48 @@ static void do_cmd_knowledge_quests(void)
                                p_ptr->inside_quest = old_quest;
 
                                /* No info from "silent" quests */
-                               if (quest[i].flags & QUEST_FLAG_SILENT) continue;
+                               if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
                        }
 
                        total++;
 
-                       if ((i >= MIN_RANDOM_QUEST) && quest[i].r_idx)
+                       if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
                        {
                                /* Print the quest info */
 
-                               if (quest[i].complev == 0)
+                               if (quest[q_idx].complev == 0)
                                {
-                                       sprintf(tmp_str, 
+                                       sprintf(tmp_str,
 #ifdef JP
-                                               "%s (%d³¬) - ÉÔÀᄀ\n",
+                                               "  %-40s (%3d³¬)            -   ÉÔÀᄀ\n",
 #else
-                                               "%s (Dungeon level: %d) - (Cancelled)\n",
+                                               "  %-40s (Dungeon level: %3d) - (Cancelled)\n",
 #endif
-                                               r_name+r_info[quest[i].r_idx].name,
-                                               quest[i].level);
+                                               r_name+r_info[quest[q_idx].r_idx].name,
+                                               quest[q_idx].level);
                                }
                                else
                                {
-                                       sprintf(tmp_str, 
+                                       sprintf(tmp_str,
 #ifdef JP
-                                               "%s (%d³¬) - ¥ì¥Ù¥ë%d\n",
+                                               "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
 #else
-                                               "%s (Dungeon level: %d) - level %d\n",
+                                               "  %-40s (Dungeon level: %3d) - level %2d\n",
 #endif
-                                               r_name+r_info[quest[i].r_idx].name,
-                                               quest[i].level,
-                                               quest[i].complev);
+                                               r_name+r_info[quest[q_idx].r_idx].name,
+                                               quest[q_idx].level,
+                                               quest[q_idx].complev);
                                }
                        }
                        else
                        {
                                /* Print the quest info */
 #ifdef JP
-                               sprintf(tmp_str, "%s (´í¸±ÅÙ:%d³¬ÁêÅö) - ¥ì¥Ù¥ë%d\n",
-                                       quest[i].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
+                                       quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #else
-                               sprintf(tmp_str, "%s (Danger level: %d) - level %d\n",
-                                       quest[i].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
+                                       quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #endif
                        }
 
@@ -8890,28 +8885,39 @@ static void do_cmd_knowledge_quests(void)
                }
        }
 #ifdef JP
-       if (!total) fprintf(fff, "¤Ê¤·\n");
+       if (!total) fprintf(fff, "  ¤Ê¤·\n");
 #else
-       if (!total) fprintf(fff, "Nothing.\n");
+       if (!total) fprintf(fff, "  Nothing.\n");
 #endif
+}
+
+
+/*
+ * Print all failed quests
+ */
+void do_cmd_knowledge_quests_failed(FILE *fff, int quest_num[])
+{
+       char tmp_str[120];
+       int i;
+       int total = 0;
 
 #ifdef JP
-       fprintf(fff, "\n¡Ô¼ºÇÔ¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
+       fprintf(fff, "¡Ô¼ºÇÔ¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
 #else
-       fprintf(fff, "\n< Failed Quest >\n");
+       fprintf(fff, "< Failed Quest >\n");
 #endif
-       total = 0;
        for (i = 1; i < max_quests; i++)
        {
-               if ((quest[i].status == QUEST_STATUS_FAILED_DONE) || (quest[i].status == QUEST_STATUS_FAILED))
+               int q_idx = quest_num[i];
+
+               if ((quest[q_idx].status == QUEST_STATUS_FAILED_DONE) || (quest[q_idx].status == QUEST_STATUS_FAILED))
                {
-                       if (i < MIN_RANDOM_QUEST)
+                       if (is_fixed_quest_idx(q_idx))
                        {
-                               int old_quest;
-
                                /* Set the quest number temporary */
-                               old_quest = p_ptr->inside_quest;
-                               p_ptr->inside_quest = i;
+                               int old_quest = p_ptr->inside_quest;
+
+                               p_ptr->inside_quest = q_idx;
 
                                /* Get the quest text */
                                init_flags = INIT_ASSIGN;
@@ -8922,49 +8928,58 @@ static void do_cmd_knowledge_quests(void)
                                p_ptr->inside_quest = old_quest;
 
                                /* No info from "silent" quests */
-                               if (quest[i].flags & QUEST_FLAG_SILENT) continue;
+                               if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
                        }
 
                        total++;
 
-                       if ((i >= MIN_RANDOM_QUEST) && quest[i].r_idx)
+                       if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
                        {
                                /* Print the quest info */
 #ifdef JP
-                               sprintf(tmp_str, "%s (%d³¬) - ¥ì¥Ù¥ë%d\n",
-                                       r_name+r_info[quest[i].r_idx].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
+                                       r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #else
-                               sprintf(tmp_str, "%s (Dungeon level: %d) - level %d\n",
-                                       r_name+r_info[quest[i].r_idx].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (Dungeon level: %3d) - level %2d\n",
+                                       r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #endif
                        }
                        else
                        {
                                /* Print the quest info */
 #ifdef JP
-                               sprintf(tmp_str, "%s (´í¸±ÅÙ:%d³¬ÁêÅö) - ¥ì¥Ù¥ë%d\n",
-                                       quest[i].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
+                                       quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #else
-                               sprintf(tmp_str, "%s (Danger level: %d) - level %d\n",
-                                       quest[i].name, quest[i].level, quest[i].complev);
+                               sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
+                                       quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
 #endif
                        }
                        fprintf(fff, tmp_str);
                }
        }
 #ifdef JP
-       if (!total) fprintf(fff, "¤Ê¤·\n");
+       if (!total) fprintf(fff, "  ¤Ê¤·\n");
 #else
-       if (!total) fprintf(fff, "Nothing.\n");
+       if (!total) fprintf(fff, "  Nothing.\n");
 #endif
+}
+
+
+/*
+ * Print all random quests
+ */
+static void do_cmd_knowledge_quests_wiz_random(FILE *fff)
+{
+       char tmp_str[120];
+       int i;
+       int total = 0;
 
-       if (p_ptr->wizard) {
 #ifdef JP
-       fprintf(fff, "\n¡Ô»Ä¤ê¤Î¥é¥ó¥À¥à¥¯¥¨¥¹¥È¡Õ\n");
+       fprintf(fff, "¡Ô»Ä¤ê¤Î¥é¥ó¥À¥à¥¯¥¨¥¹¥È¡Õ\n");
 #else
-       fprintf(fff, "\n< Remaining Random Quest >\n");
+       fprintf(fff, "< Remaining Random Quest >\n");
 #endif
-       total = 0;
        for (i = 1; i < max_quests; i++)
        {
                /* No info from "silent" quests */
@@ -8976,21 +8991,94 @@ static void do_cmd_knowledge_quests(void)
 
                        /* Print the quest info */
 #ifdef JP
-                       sprintf(tmp_str, "%s (%d³¬, %s)\n",
+                       sprintf(tmp_str, "  %s (%d³¬, %s)\n",
                                quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
 #else
-                       sprintf(tmp_str, "%s (%d, %s)\n",
+                       sprintf(tmp_str, "  %s (%d, %s)\n",
                                quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
 #endif
                        fprintf(fff, tmp_str);
                }
        }
 #ifdef JP
-       if (!total) fprintf(fff, "¤Ê¤·\n");
+       if (!total) fprintf(fff, "  ¤Ê¤·\n");
 #else
-       if (!total) fprintf(fff, "Nothing.\n");
+       if (!total) fprintf(fff, "  Nothing.\n");
 #endif
-       }       
+}
+
+
+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]];
+
+       /* Unused */
+       (void)v;
+
+       if (qa->complev < qb->complev) return TRUE;
+       if (qa->complev > qb->complev) return FALSE;
+       if (qa->level <= qb->level) return TRUE;
+       return FALSE;
+}
+
+void ang_sort_swap_quest_num(vptr u, vptr v, int a, int b)
+{
+       int *q_num = (int *)u;
+       int tmp;
+
+       /* Unused */
+       (void)v;
+
+       tmp = q_num[a];
+       q_num[a] = q_num[b];
+       q_num[b] = tmp;
+}
+
+
+/*
+ * Print quest status of all active quests
+ */
+static void do_cmd_knowledge_quests(void)
+{
+       FILE *fff;
+       char file_name[1024];
+       int *quest_num, dummy, i;
+
+       /* Open a new file */
+       fff = my_fopen_temp(file_name, 1024);
+       if (!fff)
+       {
+#ifdef JP
+           msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
+#else
+           msg_format("Failed to create temporary file %s.", file_name);
+#endif
+           msg_print(NULL);
+           return;
+       }
+
+       /* 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 */
+       do_cmd_knowledge_quests_current(fff);
+       fputc('\n', fff);
+       do_cmd_knowledge_quests_completed(fff, quest_num);
+       fputc('\n', fff);
+       do_cmd_knowledge_quests_failed(fff, quest_num);
+       if (p_ptr->wizard)
+       {
+               fputc('\n', fff);
+               do_cmd_knowledge_quests_wiz_random(fff);
+       }
 
        /* Close the file */
        my_fclose(fff);
@@ -9002,11 +9090,12 @@ static void do_cmd_knowledge_quests(void)
        show_file(TRUE, file_name, "Quest status", 0, 0);
 #endif
 
-
        /* Remove the file */
        fd_kill(file_name);
-}
 
+       /* Free Memory */
+       C_KILL(quest_num, max_quests, int);
+}
 
 
 /*
@@ -9015,8 +9104,8 @@ static void do_cmd_knowledge_quests(void)
 static void do_cmd_knowledge_home(void)
 {
        FILE *fff;
-       
-       int i, x;
+
+       int i;
        char file_name[1024];
        store_type  *st_ptr;
        char o_name[MAX_NLEN];
@@ -9028,14 +9117,14 @@ static void do_cmd_knowledge_home(void)
        fff = my_fopen_temp(file_name, 1024);
        if (!fff) {
 #ifdef JP
-           msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
+               msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
 #else
-           msg_format("Failed to create temporary file %s.", file_name);
+               msg_format("Failed to create temporary file %s.", file_name);
 #endif
-           msg_print(NULL);
-           return;
+               msg_print(NULL);
+               return;
        }
-       
+
        if (fff)
        {
                /* Print all homes in the different towns */
@@ -9044,13 +9133,15 @@ static void do_cmd_knowledge_home(void)
                /* Home -- if anything there */
                if (st_ptr->stock_num)
                {
+#ifdef JP
+                       int x = 1;
+#endif
                        /* Header with name of the town */
 #ifdef JP
                        fprintf(fff, "  [ ²æ¤¬²È¤Î¥¢¥¤¥Æ¥à ]\n");
 #else
                        fprintf(fff, "  [Home Inventory]\n");
 #endif
-                               x = 1;
 
                        /* Dump all available items */
                        for (i = 0; i < st_ptr->stock_num; i++)
@@ -9084,10 +9175,10 @@ static void do_cmd_knowledge_home(void)
                        fprintf(fff, "\n\n");
                }
        }
-       
+
        /* Close the file */
        my_fclose(fff);
-       
+
        /* Display the file contents */
 #ifdef JP
        show_file(TRUE, file_name, "²æ¤¬²È¤Î¥¢¥¤¥Æ¥à", 0, 0);
@@ -9095,7 +9186,7 @@ static void do_cmd_knowledge_home(void)
        show_file(TRUE, file_name, "Home Inventory", 0, 0);
 #endif
 
-       
+
        /* Remove the file */
        fd_kill(file_name);
 }
@@ -9396,6 +9487,7 @@ void do_cmd_time(void)
        char desc[1024];
 
        char buf[1024];
+       char day_buf[10];
 
        FILE *fff;
 
@@ -9415,14 +9507,17 @@ void do_cmd_time(void)
 #endif
 
 
+       if (day < MAX_DAYS) sprintf(day_buf, "%d", day);
+       else strcpy(day_buf, "*****");
+
        /* Message */
 #ifdef JP
-       msg_format("%d ÆüÌÜ,»þ¹ï¤Ï%d:%02d %s¤Ç¤¹¡£",
-                  day, (hour % 12 == 0) ? 12 : (hour % 12),
+       msg_format("%sÆüÌÜ, »þ¹ï¤Ï%d:%02d %s¤Ç¤¹¡£",
+                  day_buf, (hour % 12 == 0) ? 12 : (hour % 12),
                   min, (hour < 12) ? "AM" : "PM");
 #else
-       msg_format("This is day %d. The time is %d:%02d %s.",
-                  day, (hour % 12 == 0) ? 12 : (hour % 12),
+       msg_format("This is day %s. The time is %d:%02d %s.",
+                  day_buf, (hour % 12 == 0) ? 12 : (hour % 12),
                   min, (hour < 12) ? "AM" : "PM");
 #endif