OSDN Git Service

#37449 (2.2.0.75) ゲームメッセージのログ拡張に伴って発生したセーブデータのトラブルを修正。 / Fix trouble of savedata...
[hengband/hengband.git] / src / load.c
index b723105..11db047 100644 (file)
@@ -1,11 +1,14 @@
-/* File: load.c */
-
-/* Purpose: support for loading savefiles -BEN- */
-
-#include "angband.h"
-
-
-/*
+/*!
+ * @file load.c
+ * @brief セーブファイル読み込み処理 / Purpose: support for loading savefiles -BEN-
+ * @date 2014/07/07
+ * @author
+ * 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.  Other copyrights may also apply.
+ * @details
  * This file loads savefiles from Angband 2.7.X and 2.8.X
  *
  * Ancient savefiles (pre-2.7.0) are loaded by another file.
@@ -37,6 +40,7 @@
  * XXX XXX XXX
  */
 
+#include "angband.h"
 
 
 /*
@@ -65,11 +69,22 @@ static u32b v_check = 0L;
  */
 static u32b    x_check = 0L;
 
-
-
 /*
- * This function determines if the version of the savefile
- * currently being read is older than version "major.minor.patch.extra".
+ * Hack -- Japanese Kanji code
+ * 0: Unknown
+ * 1: ASCII
+ * 2: EUC
+ * 3: SJIS
+ */
+static byte kanji_code = 0;
+
+/*!
+ * @brief 変愚蛮怒のバージョン比較処理 / This function determines if the version of the savefile currently being read is older than version "major.minor.patch.extra".
+ * @param major メジャーバージョン値
+ * @param minor マイナーバージョン値
+ * @param patch パッチバージョン値
+ * @param extra エクストラパージョン値
+ * @return 現在のバージョンより値が古いならtrue
  */
 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
 {
@@ -94,8 +109,12 @@ static bool h_older_than(byte major, byte minor, byte patch, byte extra)
 }
 
 
-/*
- * The above function, adapted for Zangband
+/*!
+ * @brief Zangbandのバージョン比較処理 / The above function, adapted for Zangband
+ * @param x メジャーバージョン値
+ * @param y マイナーバージョン値
+ * @param z パッチバージョン値
+ * @return 現在のバージョンより値が古いならtrue
  */
 static bool z_older_than(byte x, byte y, byte z)
 {
@@ -116,9 +135,11 @@ static bool z_older_than(byte x, byte y, byte z)
 }
 
 
-/*
- * Hack -- Show information on the screen, one line at a time.
- *
+/*!
+ * @brief ゲームスクリーンにメッセージを表示する / Hack -- Show information on the screen, one line at a time.
+ * @param msg 表示文字列
+ * @return なし
+ * @details
  * Avoid the top two lines, to avoid interference with "msg_print()".
  */
 static void note(cptr msg)
@@ -136,11 +157,13 @@ static void note(cptr msg)
 }
 
 
-/*
+/*!
+ * @brief ロードファイルポインタから1バイトを読み込む
+ * @return 読み込んだバイト値
+ * @details
  * The following functions are used to load the basic building blocks
  * of savefiles.  They also maintain the "checksum" info for 2.7.0+
  */
-
 static byte sf_get(void)
 {
        byte c, v;
@@ -158,22 +181,42 @@ static byte sf_get(void)
        return (v);
 }
 
+/*!
+ * @brief ロードファイルポインタから1バイトを読み込んでポインタに渡す
+ * @param ip 読み込みポインタ
+ * @return なし
+ */
 static void rd_byte(byte *ip)
 {
        *ip = sf_get();
 }
 
+/*!
+ * @brief ロードファイルポインタから符号なし16bit値を読み込んでポインタに渡す
+ * @param ip 読み込みポインタ
+ * @return なし
+ */
 static void rd_u16b(u16b *ip)
 {
        (*ip) = sf_get();
        (*ip) |= ((u16b)(sf_get()) << 8);
 }
 
+/*!
+ * @brief ロードファイルポインタから符号つき16bit値を読み込んでポインタに渡す
+ * @param ip 読み込みポインタ
+ * @return なし
+ */
 static void rd_s16b(s16b *ip)
 {
        rd_u16b((u16b*)ip);
 }
 
+/*!
+ * @brief ロードファイルポインタから符号なし32bit値を読み込んでポインタに渡す
+ * @param ip 読み込みポインタ
+ * @return なし
+ */
 static void rd_u32b(u32b *ip)
 {
        (*ip) = sf_get();
@@ -182,14 +225,22 @@ static void rd_u32b(u32b *ip)
        (*ip) |= ((u32b)(sf_get()) << 24);
 }
 
+/*!
+ * @brief ロードファイルポインタから符号つき32bit値を読み込んでポインタに渡す
+ * @param ip 読み込みポインタ
+ * @return なし
+ */
 static void rd_s32b(s32b *ip)
 {
        rd_u32b((u32b*)ip);
 }
 
 
-/*
- * Hack -- read a string
+/*!
+ * @brief ロードファイルポインタから文字列を読み込んでポインタに渡す / Hack -- read a string
+ * @param str 読み込みポインタ
+ * @param max 最大読み取りバイト数
+ * @return なし
  */
 static void rd_string(char *str, int max)
 {
@@ -212,14 +263,48 @@ static void rd_string(char *str, int max)
 
        /* Terminate */
        str[max-1] = '\0';
+
+
 #ifdef JP
-       codeconv(str);
+       /* Convert Kanji code */
+       switch (kanji_code)
+       {
+#ifdef SJIS
+       case 2:
+               /* EUC to SJIS */
+               euc2sjis(str);
+               break;
+#endif
+
+#ifdef EUC
+       case 3:
+               /* SJIS to EUC */
+               sjis2euc(str);
+               break;
+#endif
+
+       case 0:
+       {
+               /* 不明の漢字コードからシステムの漢字コードに変換 */
+               byte code = codeconv(str);
+
+               /* 漢字コードが判明したら、それを記録 */
+               if (code) kanji_code = code;
+
+               break;
+       }
+       default:
+               /* No conversion needed */
+               break;
+       }
 #endif
 }
 
 
-/*
- * Hack -- strip some bytes
+/*!
+ * @brief ロードファイルポインタを指定バイト分飛ばして進める / Hack -- strip some bytes
+ * @param n スキップバイト数
+ * @return なし
  */
 static void strip_bytes(int n)
 {
@@ -231,9 +316,11 @@ static void strip_bytes(int n)
 
 #define OLD_MAX_MANE 22
 
-/*
- * Read an object (Old method)
- *
+/*!
+ * @brief アイテムオブジェクト1件を読み込む(変愚ver1.5.0以前) / Read an object (Old method)
+ * @param o_ptr アイテムオブジェクト読み取り先ポインタ
+ * @return なし
+ * @details
  * This function attempts to "repair" old savefiles, and to extract
  * the most up to date values for various object fields.
  *
@@ -316,13 +403,13 @@ static void rd_item_old(object_type *o_ptr)
                        o_ptr->curse_flags |= TRC_CURSED;
                        if (o_ptr->art_flags[2] & 0x40000000L) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
                        if (o_ptr->art_flags[2] & 0x80000000L) o_ptr->curse_flags |= TRC_PERMA_CURSE;
-                       if (o_ptr->name1)
+                       if (object_is_fixed_artifact(o_ptr))
                        {
                                artifact_type *a_ptr = &a_info[o_ptr->name1];
                                if (a_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
                                if (a_ptr->gen_flags & (TRG_PERMA_CURSE)) o_ptr->curse_flags |= TRC_PERMA_CURSE;
                        }
-                       else if (o_ptr->name2)
+                       else if (object_is_ego(o_ptr))
                        {
                                ego_item_type *e_ptr = &e_info[o_ptr->name2];
                                if (e_ptr->gen_flags & (TRG_HEAVY_CURSE)) o_ptr->curse_flags |= TRC_HEAVY_CURSE;
@@ -380,14 +467,14 @@ static void rd_item_old(object_type *o_ptr)
                {
                        switch (o_ptr->xtra2 % 8)
                        {
-                       case 0: add_flag(o_ptr->art_flags, TR_FEATHER);     break;
-                       case 1: add_flag(o_ptr->art_flags, TR_LITE);        break;
+                       case 0: add_flag(o_ptr->art_flags, TR_LEVITATION);     break;
+                       case 1: add_flag(o_ptr->art_flags, TR_LITE_1);        break;
                        case 2: add_flag(o_ptr->art_flags, TR_SEE_INVIS);   break;
                        case 3: add_flag(o_ptr->art_flags, TR_WARNING);     break;
                        case 4: add_flag(o_ptr->art_flags, TR_SLOW_DIGEST); break;
                        case 5: add_flag(o_ptr->art_flags, TR_REGEN);       break;
                        case 6: add_flag(o_ptr->art_flags, TR_FREE_ACT);    break;
-                       case 7: add_flag(o_ptr->art_flags, TR_HOLD_LIFE);   break;
+                       case 7: add_flag(o_ptr->art_flags, TR_HOLD_EXP);   break;
                        }
                        o_ptr->xtra2 = 0;
                }
@@ -422,7 +509,7 @@ static void rd_item_old(object_type *o_ptr)
                rd_byte(&o_ptr->xtra3);
                if (h_older_than(1, 3, 0, 1))
                {
-                       if (o_ptr->tval > TV_CAPTURE && o_ptr->xtra3 >= 1+96)
+                       if (object_is_smith(o_ptr) && o_ptr->xtra3 >= 1+96)
                                o_ptr->xtra3 += -96 + MIN_SPECIAL_ESSENCE;
                }
 
@@ -470,7 +557,7 @@ static void rd_item_old(object_type *o_ptr)
        }
 
        /* Paranoia */
-       if (o_ptr->name1)
+       if (object_is_fixed_artifact(o_ptr))
        {
                artifact_type *a_ptr;
 
@@ -482,7 +569,7 @@ static void rd_item_old(object_type *o_ptr)
        }
 
        /* Paranoia */
-       if (o_ptr->name2)
+       if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr;
 
@@ -496,8 +583,10 @@ static void rd_item_old(object_type *o_ptr)
 }
 
 
-/*
- * Read an object (New method)
+/*!
+ * @brief アイテムオブジェクトを読み込む(現版) / Read an object (New method)
+ * @param o_ptr アイテムオブジェクト保存先ポインタ
+ * @return なし
  */
 static void rd_item(object_type *o_ptr)
 {
@@ -575,6 +664,8 @@ static void rd_item(object_type *o_ptr)
        else o_ptr->art_flags[2] = 0;
        if (flags & SAVE_ITEM_ART_FLAGS3) rd_u32b(&o_ptr->art_flags[3]);
        else o_ptr->art_flags[3] = 0;
+       if (flags & SAVE_ITEM_ART_FLAGS4) rd_u32b(&o_ptr->art_flags[4]);
+       else o_ptr->art_flags[4] = 0;
 
        if (flags & SAVE_ITEM_CURSE_FLAGS) rd_u32b(&o_ptr->curse_flags);
        else o_ptr->curse_flags = 0;
@@ -603,23 +694,81 @@ static void rd_item(object_type *o_ptr)
        if (flags & SAVE_ITEM_INSCRIPTION)
        {
                rd_string(buf, sizeof(buf));
-               if (buf[0]) o_ptr->inscription = quark_add(buf);
-               else o_ptr->inscription = 0;
+               o_ptr->inscription = quark_add(buf);
        }
        else o_ptr->inscription = 0;
 
        if (flags & SAVE_ITEM_ART_NAME)
        {
                rd_string(buf, sizeof(buf));
-               if (buf[0]) o_ptr->art_name = quark_add(buf);
-               else o_ptr->art_name = 0;
+               o_ptr->art_name = quark_add(buf);
        }
        else o_ptr->art_name = 0;
+       
+       if(h_older_than(2,1,2,4))
+       {
+               u32b flgs[TR_FLAG_SIZE];
+               object_flags(o_ptr, flgs);
+               
+               if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
+               {
+                       add_flag(o_ptr->art_flags, TR_LITE_M1);
+                       remove_flag(o_ptr->art_flags, TR_LITE_1);
+                       remove_flag(o_ptr->art_flags, TR_LITE_2);
+                       remove_flag(o_ptr->art_flags, TR_LITE_3);
+               }
+               else if (o_ptr->name2 == EGO_LITE_DARKNESS)
+               {
+                       if (o_ptr->tval == TV_LITE)
+                       {
+                               if (o_ptr->sval == SV_LITE_TORCH)
+                               {
+                                       add_flag(o_ptr->art_flags, TR_LITE_M1);
+                               }
+                               else if (o_ptr->sval == SV_LITE_LANTERN)
+                               {
+                                       add_flag(o_ptr->art_flags, TR_LITE_M2);
+                               }
+                               else if (o_ptr->sval == SV_LITE_FEANOR)
+                               {
+                                       add_flag(o_ptr->art_flags, TR_LITE_M3);
+                               }
+                       }
+                       else
+                       {
+                               /* Paranoia */
+                               add_flag(o_ptr->art_flags, TR_LITE_M1);
+                       }
+               }
+               else if (o_ptr->tval == TV_LITE)
+               {
+                       if (object_is_fixed_artifact(o_ptr))
+                       {
+                               add_flag(o_ptr->art_flags, TR_LITE_3);
+                       }
+                       else if (o_ptr->sval == SV_LITE_TORCH)
+                       {
+                               add_flag(o_ptr->art_flags, TR_LITE_1);
+                               add_flag(o_ptr->art_flags, TR_LITE_FUEL);
+                       }
+                       else if (o_ptr->sval == SV_LITE_LANTERN)
+                       {
+                               add_flag(o_ptr->art_flags, TR_LITE_2);
+                               add_flag(o_ptr->art_flags, TR_LITE_FUEL);       
+                       }
+                       else if (o_ptr->sval == SV_LITE_FEANOR)
+                       {
+                               add_flag(o_ptr->art_flags, TR_LITE_2);
+                       }
+               }
+       }
 }
 
 
-/*
- * Read a monster (Old method)
+/*!
+ * @brief モンスターを読み込む(変愚ver1.5.0以前) / Read a monster (Old method)
+ * @param m_ptr モンスター保存先ポインタ
+ * @return なし
  */
 static void rd_monster_old(monster_type *m_ptr)
 {
@@ -658,7 +807,16 @@ static void rd_monster_old(monster_type *m_ptr)
        {
                rd_s16b(&m_ptr->max_maxhp);
        }
-       rd_s16b(&m_ptr->csleep);
+       if(h_older_than(2, 1, 2, 1))
+       {
+               m_ptr->dealt_damage = 0;
+       }
+       else
+       {
+               rd_u32b(&m_ptr->dealt_damage); 
+       }
+       
+       rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
        rd_byte(&m_ptr->mspeed);
        if (z_older_than(10, 4, 2))
        {
@@ -672,17 +830,22 @@ static void rd_monster_old(monster_type *m_ptr)
 
        if (z_older_than(10,0,7))
        {
-               m_ptr->fast = 0;
-               m_ptr->slow = 0;
+               m_ptr->mtimed[MTIMED_FAST] = 0;
+               m_ptr->mtimed[MTIMED_SLOW] = 0;
        }
        else
        {
-               rd_byte(&m_ptr->fast);
-               rd_byte(&m_ptr->slow);
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
        }
-       rd_byte(&m_ptr->stunned);
-       rd_byte(&m_ptr->confused);
-       rd_byte(&m_ptr->monfear);
+       rd_byte(&tmp8u);
+       m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
+       rd_byte(&tmp8u);
+       m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
+       rd_byte(&tmp8u);
+       m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
 
        if (z_older_than(10,0,10))
        {
@@ -700,7 +863,8 @@ static void rd_monster_old(monster_type *m_ptr)
                rd_s16b(&m_ptr->target_x);
        }
 
-       rd_byte(&m_ptr->invulner);
+       rd_byte(&tmp8u);
+       m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
 
        if (!(z_major == 2 && z_minor == 0 && z_patch == 6))
                rd_u32b(&m_ptr->smart);
@@ -717,7 +881,7 @@ static void rd_monster_old(monster_type *m_ptr)
                if (m_ptr->r_idx < 0)
                {
                        m_ptr->r_idx = (0-m_ptr->r_idx);
-                       m_ptr->mflag2 |= MFLAG_KAGE;
+                       m_ptr->mflag2 |= MFLAG2_KAGE;
                }
        }
        else
@@ -727,7 +891,7 @@ static void rd_monster_old(monster_type *m_ptr)
 
        if (z_older_than(11, 0, 12))
        {
-               if (m_ptr->mflag2 & MFLAG_KAGE)
+               if (m_ptr->mflag2 & MFLAG2_KAGE)
                        m_ptr->ap_r_idx = MON_KAGE;
        }
 
@@ -745,13 +909,16 @@ static void rd_monster_old(monster_type *m_ptr)
 }
 
 
-/*
- * Read a monster (New method)
+/*!
+ * @brief モンスターを読み込む(現版) / Read a monster (New method)
+ * @param m_ptr モンスター保存先ポインタ
+ * @return なし
  */
 static void rd_monster(monster_type *m_ptr)
 {
        u32b flags;
        char buf[128];
+       byte tmp8u;
 
        if (h_older_than(1, 5, 0, 0))
        {
@@ -773,6 +940,14 @@ static void rd_monster(monster_type *m_ptr)
        rd_s16b(&m_ptr->hp);
        rd_s16b(&m_ptr->maxhp);
        rd_s16b(&m_ptr->max_maxhp);
+       if(h_older_than(2, 1, 2, 1))
+       {
+               m_ptr->dealt_damage = 0;
+       }
+       else
+       {
+               rd_u32b(&m_ptr->dealt_damage); 
+       }
 
        /* Monster race index of its appearance */
        if (flags & SAVE_MON_AP_R_IDX) rd_s16b(&m_ptr->ap_r_idx);
@@ -781,31 +956,55 @@ static void rd_monster(monster_type *m_ptr)
        if (flags & SAVE_MON_SUB_ALIGN) rd_byte(&m_ptr->sub_align);
        else m_ptr->sub_align = 0;
 
-       if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->csleep);
-       else m_ptr->csleep = 0;
+       if (flags & SAVE_MON_CSLEEP) rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
+       else m_ptr->mtimed[MTIMED_CSLEEP] = 0;
 
        rd_byte(&m_ptr->mspeed);
 
        rd_s16b(&m_ptr->energy_need);
 
-       if (flags & SAVE_MON_FAST) rd_byte(&m_ptr->fast);
-       else m_ptr->fast = 0;
-       if (flags & SAVE_MON_SLOW) rd_byte(&m_ptr->slow);
-       else m_ptr->slow = 0;
-       if (flags & SAVE_MON_STUNNED) rd_byte(&m_ptr->stunned);
-       else m_ptr->stunned = 0;
-       if (flags & SAVE_MON_CONFUSED) rd_byte(&m_ptr->confused);
-       else m_ptr->confused = 0;
-       if (flags & SAVE_MON_MONFEAR) rd_byte(&m_ptr->monfear);
-       else m_ptr->monfear = 0;
+       if (flags & SAVE_MON_FAST)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_FAST] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_FAST] = 0;
+       if (flags & SAVE_MON_SLOW)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_SLOW] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_SLOW] = 0;
+       if (flags & SAVE_MON_STUNNED)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_STUNNED] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_STUNNED] = 0;
+       if (flags & SAVE_MON_CONFUSED)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_CONFUSED] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_CONFUSED] = 0;
+       if (flags & SAVE_MON_MONFEAR)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_MONFEAR] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_MONFEAR] = 0;
 
        if (flags & SAVE_MON_TARGET_Y) rd_s16b(&m_ptr->target_y);
        else m_ptr->target_y = 0;
        if (flags & SAVE_MON_TARGET_X) rd_s16b(&m_ptr->target_x);
        else m_ptr->target_x = 0;
 
-       if (flags & SAVE_MON_INVULNER) rd_byte(&m_ptr->invulner);
-       else m_ptr->invulner = 0;
+       if (flags & SAVE_MON_INVULNER)
+       {
+               rd_byte(&tmp8u);
+               m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
+       }
+       else m_ptr->mtimed[MTIMED_INVULNER] = 0;
 
        if (flags & SAVE_MON_SMART) rd_u32b(&m_ptr->smart);
        else m_ptr->smart = 0;
@@ -821,16 +1020,63 @@ static void rd_monster(monster_type *m_ptr)
        if (flags & SAVE_MON_NICKNAME) 
        {
                rd_string(buf, sizeof(buf));
-               if (buf[0]) m_ptr->nickname = quark_add(buf);
-               else m_ptr->nickname = 0;
+               m_ptr->nickname = quark_add(buf);
        }
        else m_ptr->nickname = 0;
-}
 
+       if (flags & SAVE_MON_PARENT) rd_s16b(&m_ptr->parent_m_idx);
+       else m_ptr->parent_m_idx = 0;
+}
 
 
 /*
- * Read the monster lore
+ * Old monster bit flags of racial resistances
+ */
+#define RF3_IM_ACID         0x00010000  /* Resist acid a lot */
+#define RF3_IM_ELEC         0x00020000  /* Resist elec a lot */
+#define RF3_IM_FIRE         0x00040000  /* Resist fire a lot */
+#define RF3_IM_COLD         0x00080000  /* Resist cold a lot */
+#define RF3_IM_POIS         0x00100000  /* Resist poison a lot */
+#define RF3_RES_TELE        0x00200000  /* Resist teleportation */
+#define RF3_RES_NETH        0x00400000  /* Resist nether a lot */
+#define RF3_RES_WATE        0x00800000  /* Resist water */
+#define RF3_RES_PLAS        0x01000000  /* Resist plasma */
+#define RF3_RES_NEXU        0x02000000  /* Resist nexus */
+#define RF3_RES_DISE        0x04000000  /* Resist disenchantment */
+#define RF3_RES_ALL         0x08000000  /* Resist all */
+
+#define MOVE_RF3_TO_RFR(R_PTR,RF3,RFR) \
+{\
+       if ((R_PTR)->r_flags3 & (RF3)) \
+       { \
+               (R_PTR)->r_flags3 &= ~(RF3); \
+               (R_PTR)->r_flagsr |= (RFR); \
+       } \
+}
+
+#define RF4_BR_TO_RFR(R_PTR,RF4_BR,RFR) \
+{\
+       if ((R_PTR)->r_flags4 & (RF4_BR)) \
+       { \
+               (R_PTR)->r_flagsr |= (RFR); \
+       } \
+}
+
+#define RF4_BR_LITE         0x00004000  /* Breathe Lite */
+#define RF4_BR_DARK         0x00008000  /* Breathe Dark */
+#define RF4_BR_CONF         0x00010000  /* Breathe Confusion */
+#define RF4_BR_SOUN         0x00020000  /* Breathe Sound */
+#define RF4_BR_CHAO         0x00040000  /* Breathe Chaos */
+#define RF4_BR_TIME         0x00200000  /* Breathe Time */
+#define RF4_BR_INER         0x00400000  /* Breathe Inertia */
+#define RF4_BR_GRAV         0x00800000  /* Breathe Gravity */
+#define RF4_BR_SHAR         0x01000000  /* Breathe Shards */
+#define RF4_BR_WALL         0x04000000  /* Breathe Force */
+
+/*!
+ * @brief モンスターの思い出を読み込む / Read the monster lore
+ * @param r_idx 読み込み先モンスターID
+ * @return なし
  */
 static void rd_lore(int r_idx)
 {
@@ -842,6 +1088,14 @@ static void rd_lore(int r_idx)
        rd_s16b(&r_ptr->r_sights);
        rd_s16b(&r_ptr->r_deaths);
        rd_s16b(&r_ptr->r_pkills);
+       if (h_older_than(1, 7, 0, 5))
+       {
+               r_ptr->r_akills = r_ptr->r_pkills;
+       }
+       else
+       {
+               rd_s16b(&r_ptr->r_akills);
+       }
        rd_s16b(&r_ptr->r_tkills);
 
        /* Count wakes and ignores */
@@ -873,6 +1127,46 @@ static void rd_lore(int r_idx)
        rd_u32b(&r_ptr->r_flags4);
        rd_u32b(&r_ptr->r_flags5);
        rd_u32b(&r_ptr->r_flags6);
+       if (h_older_than(1, 5, 0, 3))
+       {
+               r_ptr->r_flagsr = 0L;
+
+               /* Move RF3 resistance flags to RFR */
+               MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ACID,  RFR_IM_ACID);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_IM_ELEC,  RFR_IM_ELEC);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_IM_FIRE,  RFR_IM_FIRE);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_IM_COLD,  RFR_IM_COLD);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_IM_POIS,  RFR_IM_POIS);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_TELE, RFR_RES_TELE);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NETH, RFR_RES_NETH);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_WATE, RFR_RES_WATE);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_PLAS, RFR_RES_PLAS);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_NEXU, RFR_RES_NEXU);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_DISE, RFR_RES_DISE);
+               MOVE_RF3_TO_RFR(r_ptr, RF3_RES_ALL,  RFR_RES_ALL);
+
+               /* Separate breathers resistance from RF4 to RFR */
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_LITE, RFR_RES_LITE);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_DARK, RFR_RES_DARK);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_SOUN, RFR_RES_SOUN);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_CHAO, RFR_RES_CHAO);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_TIME, RFR_RES_TIME);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_INER, RFR_RES_INER);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_GRAV, RFR_RES_GRAV);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_SHAR, RFR_RES_SHAR);
+               RF4_BR_TO_RFR(r_ptr, RF4_BR_WALL, RFR_RES_WALL);
+
+               /* Resist confusion is merged to RF3_NO_CONF */
+               if (r_ptr->r_flags4 & RF4_BR_CONF) r_ptr->r_flags3 |= RF3_NO_CONF;
+
+               /* Misc resistance hack to RFR */
+               if (r_idx == MON_STORMBRINGER) r_ptr->r_flagsr |= RFR_RES_CHAO;
+               if (r_ptr->r_flags3 & RF3_ORC) r_ptr->r_flagsr |= RFR_RES_DARK;
+       }
+       else
+       {
+               rd_u32b(&r_ptr->r_flagsr);
+       }
 
        /* Read the "Racial" monster limit per level */
        rd_byte(&r_ptr->max_num);
@@ -888,16 +1182,17 @@ static void rd_lore(int r_idx)
        r_ptr->r_flags2 &= r_ptr->flags2;
        r_ptr->r_flags3 &= r_ptr->flags3;
        r_ptr->r_flags4 &= r_ptr->flags4;
-       r_ptr->r_flags5 &= r_ptr->flags5;
-       r_ptr->r_flags6 &= r_ptr->flags6;
+       r_ptr->r_flags5 &= r_ptr->a_ability_flags1;
+       r_ptr->r_flags6 &= r_ptr->a_ability_flags2;
+       r_ptr->r_flagsr &= r_ptr->flagsr;
 }
 
-
-
-
-/*
- * Add the item "o_ptr" to the inventory of the "Home"
- *
+/*!
+ * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
+ * @param st_ptr 店舗の参照ポインタ
+ * @param o_ptr アイテムオブジェクト参照ポインタ
+ * @return なし
+ * @details
  * In all cases, return the slot (or -1) where the object was placed
  *
  * Note that this is a hacked up version of "inven_carry()".
@@ -908,7 +1203,7 @@ static void rd_lore(int r_idx)
 static void home_carry(store_type *st_ptr, object_type *o_ptr)
 {
        int                             slot;
-       s32b                       value, j_value;
+       s32b                       value;
        int     i;
        object_type *j_ptr;
 
@@ -941,45 +1236,7 @@ static void home_carry(store_type *st_ptr, object_type *o_ptr)
        /* Check existing slots to see if we must "slide" */
        for (slot = 0; slot < st_ptr->stock_num; slot++)
        {
-               /* Get that item */
-               j_ptr = &st_ptr->stock[slot];
-
-               /* Hack -- readable books always come first */
-               if ((o_ptr->tval == mp_ptr->spell_book) &&
-                       (j_ptr->tval != mp_ptr->spell_book)) break;
-               if ((j_ptr->tval == mp_ptr->spell_book) &&
-                       (o_ptr->tval != mp_ptr->spell_book)) continue;
-
-               /* Objects sort by decreasing type */
-               if (o_ptr->tval > j_ptr->tval) break;
-               if (o_ptr->tval < j_ptr->tval) continue;
-
-               /* Can happen in the home */
-               if (!object_aware_p(o_ptr)) continue;
-               if (!object_aware_p(j_ptr)) break;
-
-               /* Objects sort by increasing sval */
-               if (o_ptr->sval < j_ptr->sval) break;
-               if (o_ptr->sval > j_ptr->sval) continue;
-
-               /* Objects in the home can be unknown */
-               if (!object_known_p(o_ptr)) continue;
-               if (!object_known_p(j_ptr)) break;
-
-               /*
-                * Hack:  otherwise identical rods sort by
-                * increasing recharge time --dsb
-                */
-               if (o_ptr->tval == TV_ROD)
-               {
-                       if (o_ptr->pval < j_ptr->pval) break;
-                       if (o_ptr->pval > j_ptr->pval) continue;
-               }
-
-               /* Objects sort by decreasing value */
-               j_value = object_value(j_ptr);
-               if (value > j_value) break;
-               if (value < j_value) continue;
+               if (object_sort_comp(o_ptr, value, &st_ptr->stock[slot])) break;
        }
 
        /* Slide the others up */
@@ -1000,9 +1257,11 @@ static void home_carry(store_type *st_ptr, object_type *o_ptr)
        return;
 }
 
-
-/*
- * Read a store
+/*!
+ * @brief 店舗情報を読み込む / Read a store
+ * @param town_number 街ID 
+ * @param store_number 店舗ID
+ * @return エラーID
  */
 static errr rd_store(int town_number, int store_number)
 {
@@ -1086,9 +1345,9 @@ static errr rd_store(int town_number, int store_number)
 }
 
 
-
-/*
- * Read RNG state (added in 2.8.0)
+/*!
+ * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
+ * @return なし
  */
 static void rd_randomizer(void)
 {
@@ -1107,16 +1366,14 @@ static void rd_randomizer(void)
        {
                rd_u32b(&Rand_state[i]);
        }
-
-       /* Accept */
-       Rand_quick = FALSE;
 }
 
 
 
-/*
- * Read options (ignore most pre-2.8.0 options)
- *
+/*!
+ * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
+ * @return なし
+ * @details
  * Note that the normal options are now stored as a set of 256 bit flags,
  * plus a set of 256 bit masks to indicate which bit flags were defined
  * at the time the savefile was created.  This will allow new options
@@ -1154,6 +1411,17 @@ static void rd_options(void)
        rd_byte(&b);
        hitpoint_warn = b;
 
+       /* Read "mana_warn" */
+       if(h_older_than(1, 7, 0, 0))
+       {
+               mana_warn=2;
+       }
+       else 
+       {
+               rd_byte(&b);
+               mana_warn = b;
+       }
+
 
        /*** Cheating options ***/
 
@@ -1168,6 +1436,7 @@ static void rd_options(void)
        cheat_know = (c & 0x1000) ? TRUE : FALSE;
        cheat_live = (c & 0x2000) ? TRUE : FALSE;
        cheat_save = (c & 0x4000) ? TRUE : FALSE;
+       cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
 
        rd_byte((byte *)&autosave_l);
        rd_byte((byte *)&autosave_t);
@@ -1234,6 +1503,9 @@ static void rd_options(void)
                else option_flag[5] |= (0x00000001 << 3);
        }
 
+       /* Extract the options */
+       extract_option_vars();
+
 
        /*** Window Options ***/
 
@@ -1276,11 +1548,10 @@ static void rd_options(void)
 
 
 
-
-
-/*
- * Hack -- strip the "ghost" info
- *
+/*!
+ * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
+ * @return なし
+ * @details
  * XXX XXX XXX This is such a nasty hack it hurts.
  */
 static void rd_ghost(void)
@@ -1295,8 +1566,9 @@ static void rd_ghost(void)
 }
 
 
-/*
- * Save quick start data
+/*!
+ * @brief クイックスタート情報を読み込む / Load quick start data
+ * @return なし
  */
 static void load_quick_start(void)
 {
@@ -1333,14 +1605,16 @@ static void load_quick_start(void)
 
        for (i = 0; i < 4; i++) rd_string(previous_char.history[i], sizeof(previous_char.history[i]));
 
-       rd_byte(&previous_char.quests);
+       /* UNUSED : Was number of random quests */
+       rd_byte(&tmp8u);
 
        rd_byte(&tmp8u);
        previous_char.quick_ok = (bool)tmp8u;
 }
 
-/*
- * Read the "extra" information
+/*!
+ * @brief その他の情報を読み込む / Read the "extra" information
+ * @return なし
  */
 static void rd_extra(void)
 {
@@ -1348,11 +1622,21 @@ static void rd_extra(void)
 
        byte tmp8u;
        s16b tmp16s;
+       u16b tmp16u;
 
-       rd_string(player_name, sizeof(player_name));
+       rd_string(p_ptr->name, sizeof(p_ptr->name));
 
        rd_string(p_ptr->died_from, sizeof(p_ptr->died_from));
 
+       if (!h_older_than(1, 7, 0, 1))
+       {
+               char buf[1024];
+
+               /* Read the message */
+               rd_string(buf, sizeof buf);
+               if (buf[0]) p_ptr->last_message = string_make(buf);
+       }
+
        load_quick_start();
 
        for (i = 0; i < 4; i++)
@@ -1396,21 +1680,32 @@ static void rd_extra(void)
        rd_s32b(&p_ptr->au);
 
        rd_s32b(&p_ptr->max_exp);
+       if (h_older_than(1, 5, 4, 1)) p_ptr->max_max_exp = p_ptr->max_exp;
+       else rd_s32b(&p_ptr->max_max_exp);
        rd_s32b(&p_ptr->exp);
-       rd_u16b(&p_ptr->exp_frac);
+
+       if (h_older_than(1, 7, 0, 3))
+       {
+               rd_u16b(&tmp16u);
+               p_ptr->exp_frac = (u32b)tmp16u;
+       }
+       else
+       {
+               rd_u32b(&p_ptr->exp_frac);
+       }
 
        rd_s16b(&p_ptr->lev);
 
        for (i = 0; i < 64; i++) rd_s16b(&p_ptr->spell_exp[i]);
        if ((p_ptr->pclass == CLASS_SORCERER) && z_older_than(10, 4, 2))
        {
-               for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = 1600;
+               for (i = 0; i < 64; i++) p_ptr->spell_exp[i] = SPELL_EXP_MASTER;
        }
        if (z_older_than(10, 3, 6))
                for (i = 0; i < 5; i++) for (j = 0; j < 60; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
        else
                for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) rd_s16b(&p_ptr->weapon_exp[i][j]);
-       for (i = 0; i < 10; i++) rd_s16b(&p_ptr->skill_exp[i]);
+       for (i = 0; i < GINOU_MAX; i++) rd_s16b(&p_ptr->skill_exp[i]);
        if (z_older_than(10, 4, 1))
        {
                if (p_ptr->pclass != CLASS_BEASTMASTER) p_ptr->skill_exp[GINOU_RIDING] /= 2;
@@ -1436,7 +1731,7 @@ static void rd_extra(void)
                        }
                }
        }
-       if ((p_ptr->pclass == CLASS_BARD) && p_ptr->magic_num1[0]) p_ptr->action = ACTION_SING;
+       if (music_singing_any()) p_ptr->action = ACTION_SING;
 
        if (z_older_than(11, 0, 7))
        {
@@ -1455,7 +1750,7 @@ static void rd_extra(void)
 
        if (z_older_than(10, 0, 1))
        {
-               for (i = 0; i < OLD_MAX_MANE; i++)
+               for (i = 0; i < MAX_MANE; i++)
                {
                        p_ptr->mane_spell[i] = -1;
                        p_ptr->mane_dam[i] = 0;
@@ -1489,46 +1784,12 @@ static void rd_extra(void)
 
        if (z_older_than(10, 0, 3))
        {
-               get_mon_num_prep(NULL, NULL);
-               for (i = 0; i < MAX_KUBI; i++)
-               {
-                       monster_race *r_ptr;
-                       while (1)
-                       {
-                               int j;
+               determine_bounty_uniques();
 
-                               kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
-                               r_ptr = &r_info[kubi_r_idx[i]];
-
-                               if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
-
-                               if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
-
-                               if(r_ptr->flags6 & RF6_SPECIAL) continue;
-
-                               for (j = 0; j < i; j++)
-                                       if (kubi_r_idx[i] == kubi_r_idx[j])break;
-
-                               if (j == i) break;
-                       }
-               }
-               for (i = 0; i < MAX_KUBI -1; i++)
-               {
-                       int j,tmp;
-                       for (j = i; j < MAX_KUBI; j++)
-                       {
-                               if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
-                               {
-                                       tmp = kubi_r_idx[i];
-                                       kubi_r_idx[i] = kubi_r_idx[j];
-                                       kubi_r_idx[j] = tmp;
-                               }
-                       }
-               }
                for (i = 0; i < MAX_KUBI; i++)
                {
-                       if(!r_info[kubi_r_idx[i]].max_num)
-                               kubi_r_idx[i] += 10000;
+                       /* Is this bounty unique already dead? */
+                       if (!r_info[kubi_r_idx[i]].max_num) kubi_r_idx[i] += 10000;
                }
        }
        else
@@ -1561,6 +1822,11 @@ static void rd_extra(void)
 
        /* Read arena and rewards information */
        rd_s16b(&p_ptr->arena_number);
+       if (h_older_than(1, 5, 0, 1))
+       {
+               /* Arena loser of previous version was marked number 99 */
+               if (p_ptr->arena_number >= 99) p_ptr->arena_number = ARENA_DEFEATED_OLD_VER;
+       }
        rd_s16b(&tmp16s);
        p_ptr->inside_arena = (bool)tmp16s;
        rd_s16b(&p_ptr->inside_quest);
@@ -1571,33 +1837,55 @@ static void rd_extra(void)
                p_ptr->inside_battle = (bool)tmp16s;
        }
        rd_byte(&p_ptr->exit_bldg);
-       rd_byte(&p_ptr->leftbldg);
+       rd_byte(&tmp8u);
 
        rd_s16b(&p_ptr->oldpx);
        rd_s16b(&p_ptr->oldpy);
        if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->oldpy = 33;p_ptr->oldpx = 131;}
 
+       /* Was p_ptr->rewards[MAX_BACT] */
        rd_s16b(&tmp16s);
+       for (i = 0; i < tmp16s; i++)
+       {
+               s16b tmp16s2;
+               rd_s16b(&tmp16s2);
+       }
 
-       if (tmp16s > MAX_BACT)
+       if (h_older_than(1, 7, 0, 3))
        {
-#ifdef JP
-note(format("¤ÎÃæ", tmp16s));
-#else
-               note(format("Too many (%d) building rewards!", tmp16s));
-#endif
+               rd_s16b(&tmp16s);
+               p_ptr->mhp = tmp16s;
+
+               rd_s16b(&tmp16s);
+               p_ptr->chp = tmp16s;
 
+               rd_u16b(&tmp16u);
+               p_ptr->chp_frac = (u32b)tmp16u;
+       }
+       else
+       {
+               rd_s32b(&p_ptr->mhp);
+               rd_s32b(&p_ptr->chp);
+               rd_u32b(&p_ptr->chp_frac);
        }
 
-       for (i = 0; i < tmp16s; i++) rd_s16b(&p_ptr->rewards[i]);
+       if (h_older_than(1, 7, 0, 3))
+       {
+               rd_s16b(&tmp16s);
+               p_ptr->msp = tmp16s;
 
-       rd_s16b(&p_ptr->mhp);
-       rd_s16b(&p_ptr->chp);
-       rd_u16b(&p_ptr->chp_frac);
+               rd_s16b(&tmp16s);
+               p_ptr->csp = tmp16s;
 
-       rd_s16b(&p_ptr->msp);
-       rd_s16b(&p_ptr->csp);
-       rd_u16b(&p_ptr->csp_frac);
+               rd_u16b(&tmp16u);
+               p_ptr->csp_frac = (u32b)tmp16u;
+       }
+       else
+       {
+               rd_s32b(&p_ptr->msp);
+               rd_s32b(&p_ptr->csp);
+               rd_u32b(&p_ptr->csp_frac);
+       }
 
        rd_s16b(&p_ptr->max_plv);
        if (z_older_than(10, 3, 8))
@@ -1623,7 +1911,7 @@ note(format("
        /* More info */
        strip_bytes(8);
        rd_s16b(&p_ptr->sc);
-       strip_bytes(2);
+       rd_s16b(&p_ptr->concent);
 
        /* Read the flags */
        strip_bytes(2); /* Old "rest" */
@@ -1636,6 +1924,10 @@ note(format("
        rd_s16b(&p_ptr->energy_need);
        if (z_older_than(11, 0, 13))
                p_ptr->energy_need = 100 - p_ptr->energy_need;
+       if (h_older_than(2, 1, 2, 0))
+               p_ptr->enchant_energy_need = 0;
+       else
+               rd_s16b(&p_ptr->enchant_energy_need);
 
        rd_s16b(&p_ptr->fast);
        rd_s16b(&p_ptr->slow);
@@ -1688,7 +1980,7 @@ note(format("
                p_ptr->tim_regen = 0;
                p_ptr->kabenuke = 0;
                p_ptr->tim_stealth = 0;
-               p_ptr->tim_ffall = 0;
+               p_ptr->tim_levitation = 0;
                p_ptr->tim_sh_touki = 0;
                p_ptr->lightspeed = 0;
                p_ptr->tsubureru = 0;
@@ -1703,7 +1995,7 @@ note(format("
                p_ptr->multishadow = 0;
                p_ptr->dustrobe = 0;
 
-               p_ptr->chaos_patron = get_chaos_patron();
+               p_ptr->chaos_patron = ((p_ptr->age + p_ptr->sc) % MAX_PATRON);
                p_ptr->muta1 = 0;
                p_ptr->muta2 = 0;
                p_ptr->muta3 = 0;
@@ -1717,7 +2009,7 @@ note(format("
                rd_s16b(&p_ptr->tim_regen);
                rd_s16b(&p_ptr->kabenuke);
                rd_s16b(&p_ptr->tim_stealth);
-               rd_s16b(&p_ptr->tim_ffall);
+               rd_s16b(&p_ptr->tim_levitation);
                rd_s16b(&p_ptr->tim_sh_touki);
                rd_s16b(&p_ptr->lightspeed);
                rd_s16b(&p_ptr->tsubureru);
@@ -1802,7 +2094,10 @@ note(format("
                rd_u32b(&p_ptr->special_defense);
        }
        rd_byte(&p_ptr->knowledge);
-       rd_byte(&tmp8u); /* oops */
+
+       rd_byte(&tmp8u);
+       p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
+
        rd_byte(&tmp8u); /* oops */
        rd_byte(&p_ptr->action);
        if (!z_older_than(10, 4, 3))
@@ -1836,12 +2131,35 @@ note(format("
        p_ptr->is_dead = tmp8u;
 
        /* Read "feeling" */
-       rd_byte(&tmp8u);
-       feeling = tmp8u;
+       rd_byte(&p_ptr->feeling);
 
-       /* Turn of last "feeling" */
+       switch (p_ptr->start_race)
+       {
+       case RACE_VAMPIRE:
+       case RACE_SKELETON:
+       case RACE_ZOMBIE:
+       case RACE_SPECTRE:
+               turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
+               break;
+       default:
+               turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
+               break;
+       }
+       dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
+
+       /* Turn when level began */
        rd_s32b(&old_turn);
 
+       if (h_older_than(1, 7, 0, 4))
+       {
+               p_ptr->feeling_turn = old_turn;
+       }
+       else
+       {
+               /* Turn of last "feeling" */
+               rd_s32b(&p_ptr->feeling_turn);
+       }
+
        /* Current turn */
        rd_s32b(&turn);
 
@@ -1854,6 +2172,7 @@ note(format("
        if (z_older_than(11, 0, 13))
        {
                old_turn /= 2;
+               p_ptr->feeling_turn /= 2;
                turn /= 2;
                dungeon_turn /= 2;
        }
@@ -1866,23 +2185,7 @@ note(format("
 
        if (z_older_than(10,0,3))
        {
-               monster_race *r_ptr;
-
-               while (1)
-               {
-                       today_mon = get_mon_num(MAX(max_dlv[DUNGEON_ANGBAND], 3));
-                       r_ptr = &r_info[today_mon];
-               
-                       if (r_ptr->flags1 & RF1_UNIQUE) continue;
-                       if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
-                       if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
-                       if (r_ptr->level < MIN(max_dlv[DUNGEON_ANGBAND], 40)) continue;
-                       if (r_ptr->rarity > 10) continue;
-                       if (r_ptr->level == 0) continue;
-                       break;
-               }
-
-               p_ptr->today_mon = 0;
+               determine_today_mon(TRUE);
        }
        else
        {
@@ -1909,6 +2212,24 @@ note(format("
                rd_s16b(&p_ptr->floor_id);
        }
 
+       if (h_older_than(1, 5, 0, 2))
+       {
+               /* Nothing to do */
+       }
+       else
+       {
+               /* Get number of party_mon array */
+               rd_s16b(&tmp16s);
+
+               /* Strip old temporary preserved pets */
+               for (i = 0; i < tmp16s; i++)
+               {
+                       monster_type dummy_mon;
+
+                       rd_monster(&dummy_mon);
+               }
+       }
+
        if (z_older_than(10,1,2))
        {
                playtime = 0;
@@ -1939,11 +2260,10 @@ note(format("
 }
 
 
-
-
-/*
- * Read the player inventory
- *
+/*!
+ * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
+ * @return なし
+ * @details
  * Note that the inventory changed in Angband 2.7.4.  Two extra
  * pack slots were added and the equipment was rearranged.  Note
  * that these two features combine when parsing old save-files, in
@@ -1992,6 +2312,9 @@ static errr rd_inventory(void)
                /* Wield equipment */
                if (n >= INVEN_RARM)
                {
+                       /* Player touches it */
+                       q_ptr->marked |= OM_TOUCHED;
+
                        /* Copy object */
                        object_copy(&inventory[n], q_ptr);
 
@@ -2006,12 +2329,7 @@ static errr rd_inventory(void)
                else if (inven_cnt == INVEN_PACK)
                {
                        /* Oops */
-#ifdef JP
-note("»ý¤Áʪ¤ÎÃæ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë¡ª");
-#else
-                       note("Too many items in the inventory!");
-#endif
-
+                       note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
 
                        /* Fail */
                        return (54);
@@ -2023,6 +2341,9 @@ note("
                        /* Get a slot */
                        n = slot++;
 
+                       /* Player touches it */
+                       q_ptr->marked |= OM_TOUCHED;
+
                        /* Copy object */
                        object_copy(&inventory[n], q_ptr);
 
@@ -2039,29 +2360,49 @@ note("
 }
 
 
-
-/*
- * Read the saved messages
+/*!
+ * @brief メッセージログを読み込む / Read the saved messages
+ * @return なし
  */
 static void rd_messages(void)
 {
        int i;
        char buf[128];
 
-       s16b num;
 
-       /* Total */
-       rd_s16b(&num);
+       if (h_older_than(2, 2, 0, 75))
+       {
+               s16b num;
+               /* Total */
+               rd_s16b(&num);
+
+               /* Read the messages */
+               for (i = 0; i < num; i++)
+               {
+                       /* Read the message */
+                       rd_string(buf, sizeof(buf));
 
-       /* Read the messages */
-       for (i = 0; i < num; i++)
+                       /* Save the message */
+                       message_add(buf);
+               }
+       }
+       else
        {
-               /* Read the message */
-               rd_string(buf, sizeof(buf));
+               u32b num;
+               /* Total */
+               rd_u32b(&num);
+
+               /* Read the messages */
+               for (i = 0; i < num; i++)
+               {
+                       /* Read the message */
+                       rd_string(buf, sizeof(buf));
 
-               /* Save the message */
-               message_add(buf);
+                       /* Save the message */
+                       message_add(buf);
+               }
        }
+
 }
 
 
@@ -2069,9 +2410,26 @@ static void rd_messages(void)
 /* Old hidden trap flag */
 #define CAVE_TRAP       0x8000
 
-/*
- * Read the dungeon (old method)
- *
+/*** Terrain Feature Indexes (see "lib/edit/f_info.txt") ***/
+#define OLD_FEAT_INVIS              0x02
+#define OLD_FEAT_GLYPH              0x03
+#define OLD_FEAT_QUEST_ENTER        0x08
+#define OLD_FEAT_QUEST_EXIT         0x09
+#define OLD_FEAT_MINOR_GLYPH        0x40
+#define OLD_FEAT_BLDG_1             0x81
+#define OLD_FEAT_MIRROR             0xc3
+
+/* Old quests */
+#define OLD_QUEST_WATER_CAVE 18
+
+/* Quest constants */
+#define QUEST_OLD_CASTLE  27
+#define QUEST_ROYAL_CRYPT 28
+
+/*!
+ * @brief メッセージログを読み込む / Read the dungeon (old method)
+ * @return なし
+ * @details
  * The monsters/objects must be loaded in the same order
  * that they were stored, since the actual indexes matter.
  */
@@ -2100,17 +2458,17 @@ static errr rd_dungeon_old(void)
 
        rd_s16b(&num_repro);
        rd_s16b(&tmp16s);
-       py = (int)tmp16s;
+       p_ptr->y = (int)tmp16s;
        rd_s16b(&tmp16s);
-       px = (int)tmp16s;
-       if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {py = 33;px = 131;}
+       p_ptr->x = (int)tmp16s;
+       if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena) {p_ptr->y = 33;p_ptr->x = 131;}
        rd_s16b(&cur_hgt);
        rd_s16b(&cur_wid);
        rd_s16b(&tmp16s); /* max_panel_rows */
        rd_s16b(&tmp16s); /* max_panel_cols */
 
 #if 0
-       if (!py || !px) {py = 10;px = 10;}/* ¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ¤·¤Æ¥»¥°¥á¥ó¥Æ¤Ã¤¿¤È¤­¤ÎÉüµìÍÑ */
+       if (!p_ptr->y || !p_ptr->x) {p_ptr->y = 10;p_ptr->x = 10;}/* ダンジョン生成に失敗してセグメンテったときの復旧用 */
 #endif
 
        /* Maximal size */
@@ -2137,7 +2495,7 @@ static errr rd_dungeon_old(void)
                        rd_u16b(&info);
 
                        /* Decline invalid flags */
-                       info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT);
+                       info &= ~(CAVE_LITE | CAVE_VIEW | CAVE_MNLT | CAVE_MNDK);
                }
 
                /* Apply the RLE info */
@@ -2178,7 +2536,7 @@ static errr rd_dungeon_old(void)
                        c_ptr = &cave[y][x];
 
                        /* Extract "feat" */
-                       c_ptr->feat = tmp8u;
+                       c_ptr->feat = (s16b)tmp8u;
 
                        /* Advance/Wrap */
                        if (++x >= xmax)
@@ -2207,8 +2565,8 @@ static errr rd_dungeon_old(void)
                        /* Access the cave */
                        c_ptr = &cave[y][x];
 
-                       /* Extract "feat" */
-                       c_ptr->mimic = tmp8u;
+                       /* Extract "mimic" */
+                       c_ptr->mimic = (s16b)tmp8u;
 
                        /* Advance/Wrap */
                        if (++x >= xmax)
@@ -2270,16 +2628,16 @@ static errr rd_dungeon_old(void)
                        c_ptr = &cave[y][x];
 
                        /* Very old */
-                       if (c_ptr->feat == FEAT_INVIS)
+                       if (c_ptr->feat == OLD_FEAT_INVIS)
                        {
-                               c_ptr->feat = FEAT_FLOOR;
+                               c_ptr->feat = feat_floor;
                                c_ptr->info |= CAVE_TRAP;
                        }
-               
+
                        /* Older than 1.1.1 */
-                       if (c_ptr->feat == FEAT_MIRROR)
+                       if (c_ptr->feat == OLD_FEAT_MIRROR)
                        {
-                               c_ptr->feat = FEAT_FLOOR;
+                               c_ptr->feat = feat_floor;
                                c_ptr->info |= CAVE_OBJECT;
                        }
                }
@@ -2295,16 +2653,16 @@ static errr rd_dungeon_old(void)
                        /* Old CAVE_IN_MIRROR flag */
                        if (c_ptr->info & CAVE_OBJECT)
                        {
-                               c_ptr->mimic = FEAT_MIRROR;
+                               c_ptr->mimic = feat_mirror;
                        }
 
                        /* Runes will be mimics and flags */
-                       else if (c_ptr->feat == FEAT_MINOR_GLYPH ||
-                                c_ptr->feat == FEAT_GLYPH)
+                       else if ((c_ptr->feat == OLD_FEAT_MINOR_GLYPH) ||
+                                (c_ptr->feat == OLD_FEAT_GLYPH))
                        {
                                c_ptr->info |= CAVE_OBJECT;
                                c_ptr->mimic = c_ptr->feat;
-                               c_ptr->feat = FEAT_FLOOR;
+                               c_ptr->feat = feat_floor;
                        }
 
                        /* Hidden traps will be trap terrains mimicing floor */
@@ -2316,17 +2674,39 @@ static errr rd_dungeon_old(void)
                        }
 
                        /* Another hidden trap */
-                       else if (c_ptr->feat == FEAT_INVIS)
+                       else if (c_ptr->feat == OLD_FEAT_INVIS)
                        {
-                               c_ptr->mimic = FEAT_FLOOR;
-                               c_ptr->feat = FEAT_TRAP_OPEN;
+                               c_ptr->mimic = feat_floor;
+                               c_ptr->feat = feat_trap_open;
                        }
+               }
+       }
+
+       /* Quest 18 was removed */
+       if (h_older_than(1, 7, 0, 6) && !vanilla_town)
+       {
+               for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
+               {
+                       /* Access the cave */
+                       c_ptr = &cave[y][x];
 
-                       /* Hidden doors will be closed doors mimicing wall */
-                       else if (c_ptr->feat == FEAT_SECRET)
+                       if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
                        {
-                               place_closed_door(y, x);
-                               c_ptr->mimic = FEAT_WALL_EXTRA;
+                               if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
+                               {
+                                       c_ptr->feat = feat_tree;
+                                       c_ptr->special = 0;
+                               }
+                               else if (c_ptr->feat == OLD_FEAT_BLDG_1)
+                               {
+                                       c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
+                               }
+                       }
+                       else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
+                                (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
+                       {
+                               c_ptr->feat = feat_up_stair;
+                               c_ptr->special = 0;
                        }
                }
        }
@@ -2339,12 +2719,7 @@ static errr rd_dungeon_old(void)
        /* Verify maximum */
        if (limit > max_o_idx)
        {
-#ifdef JP
-note(format("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë(%d)¡ª", limit));
-#else
-               note(format("Too many (%d) object entries!", limit));
-#endif
-
+               note(format(_("アイテムの配列が大きすぎる(%d)!", "Too many (%d) object entries!"), limit));
                return (151);
        }
 
@@ -2362,12 +2737,7 @@ note(format("
                /* Oops */
                if (i != o_idx)
                {
-#ifdef JP
-note(format("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, o_idx));
-#else
-                       note(format("Object allocation error (%d <> %d)", i, o_idx));
-#endif
-
+                       note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
                        return (152);
                }
 
@@ -2419,12 +2789,7 @@ note(format("
        /* Hack -- verify */
        if (limit > max_m_idx)
        {
-#ifdef JP
-note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë(%d)¡ª", limit));
-#else
-               note(format("Too many (%d) monster entries!", limit));
-#endif
-
+               note(format(_("モンスターの配列が大きすぎる(%d)!", "Too many (%d) monster entries!"), limit));
                return (161);
        }
 
@@ -2440,12 +2805,7 @@ note(format("
                /* Oops */
                if (i != m_idx)
                {
-#ifdef JP
-note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
-#else
-                       note(format("Monster allocation error (%d <> %d)", i, m_idx));
-#endif
-
+                       note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
                        return (162);
                }
 
@@ -2480,10 +2840,10 @@ note(format("
 }
 
 
-
-/*
- * Read the saved floor
- *
+/*!
+ * @brief 保存されたフロアを読み込む / Read the saved floor
+ * @return なし
+ * @details
  * The monsters/objects must be loaded in the same order
  * that they were stored, since the actual indexes matter.
  */
@@ -2499,7 +2859,7 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        u32b tmp32u;
        u16b limit;
 
-       cave_template_type *template;
+       cave_template_type *templates;
 
 
        /*** Wipe all cave ***/
@@ -2548,15 +2908,15 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        rd_s16b(&num_repro);
 
        rd_u16b(&tmp16u);
-       py = (int)tmp16u;
+       p_ptr->y = (int)tmp16u;
 
        rd_u16b(&tmp16u);
-       px = (int)tmp16u;
+       p_ptr->x = (int)tmp16u;
 
        rd_s16b(&cur_hgt);
        rd_s16b(&cur_wid);
 
-       rd_byte(&feeling);
+       rd_byte(&p_ptr->feeling);
 
 
 
@@ -2566,17 +2926,27 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        rd_u16b(&limit);
 
        /* Allocate the "template" array */
-       C_MAKE(template, limit, cave_template_type);
+       C_MAKE(templates, limit, cave_template_type);
 
        /* Read the templates */
        for (i = 0; i < limit; i++)
        {
-               cave_template_type *ct_ptr = &template[i];
+               cave_template_type *ct_ptr = &templates[i];
 
                /* Read it */
                rd_u16b(&ct_ptr->info);
-               rd_byte(&ct_ptr->feat);
-               rd_byte(&ct_ptr->mimic);
+               if (h_older_than(1, 7, 0, 2))
+               {
+                       rd_byte(&tmp8u);
+                       ct_ptr->feat = (s16b)tmp8u;
+                       rd_byte(&tmp8u);
+                       ct_ptr->mimic = (s16b)tmp8u;
+               }
+               else
+               {
+                       rd_s16b(&ct_ptr->feat);
+                       rd_s16b(&ct_ptr->mimic);
+               }
                rd_s16b(&ct_ptr->special);
        }
 
@@ -2609,10 +2979,10 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
                        cave_type *c_ptr = &cave[y][x];
 
                        /* Extract cave data */
-                       c_ptr->info = template[id].info;
-                       c_ptr->feat = template[id].feat;
-                       c_ptr->mimic = template[id].mimic;
-                       c_ptr->special = template[id].special;
+                       c_ptr->info = templates[id].info;
+                       c_ptr->feat = templates[id].feat;
+                       c_ptr->mimic = templates[id].mimic;
+                       c_ptr->special = templates[id].special;
 
                        /* Advance/Wrap */
                        if (++x >= xmax)
@@ -2626,8 +2996,37 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
                }
        }
 
+       /* Quest 18 was removed */
+       if (h_older_than(1, 7, 0, 6) && !vanilla_town)
+       {
+               for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
+               {
+                       /* Access the cave */
+                       cave_type *c_ptr = &cave[y][x];
+
+                       if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
+                       {
+                               if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
+                               {
+                                       c_ptr->feat = feat_tree;
+                                       c_ptr->special = 0;
+                               }
+                               else if (c_ptr->feat == OLD_FEAT_BLDG_1)
+                               {
+                                       c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
+                               }
+                       }
+                       else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
+                                (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
+                       {
+                               c_ptr->feat = feat_up_stair;
+                               c_ptr->special = 0;
+                       }
+               }
+       }
+
        /* Free the "template" array */
-       C_FREE(template, limit, cave_template_type);
+       C_KILL(templates, limit, cave_template_type);
 
 
        /*** Objects ***/
@@ -2733,9 +3132,10 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
 }
 
 
-/*
- * Read the dungeon (new method)
- *
+/*!
+ * @brief 保存されたフロアを読み込む(現版) / Read the dungeon (new method)
+ * @return なし
+ * @details
  * The monsters/objects must be loaded in the same order
  * that they were stored, since the actual indexes matter.
  */
@@ -2746,7 +3146,7 @@ static errr rd_dungeon(void)
        int i;
 
        /* Initialize saved_floors array and temporal files */
-       init_saved_floors();
+       init_saved_floors(FALSE);
 
        /* Older method */
        if (h_older_than(1, 5, 0, 0))
@@ -2773,15 +3173,12 @@ static errr rd_dungeon(void)
        rd_byte(&dungeon_type);
 
 
-       /*** On the surface  ***/
-       if (!p_ptr->floor_id)
-       {
-               /* Number of array elements?? */
-               rd_byte(&num);
-
-               /* It should be 0 */
-               if (num) err = 181;
+       /* Number of the saved_floors array elements */
+       rd_byte(&num);
 
+       /*** No saved floor (On the surface etc.) ***/
+       if (!num)
+       {
                /* Read the current floor data */
                err = rd_saved_floor(NULL);
        }
@@ -2789,8 +3186,6 @@ static errr rd_dungeon(void)
        /*** In the dungeon ***/
        else
        {
-               /* Number of array elements */
-               rd_byte(&num);
 
                /* Read the saved_floors array */
                for (i = 0; i < num; i++)
@@ -2812,7 +3207,7 @@ static errr rd_dungeon(void)
                {
                        saved_floor_type *sf_ptr = &saved_floors[i];
                        byte tmp8u;
-               
+
                        /* Unused element */
                        if (!sf_ptr->floor_id) continue;
 
@@ -2822,7 +3217,7 @@ static errr rd_dungeon(void)
 
                        /* Read from the save file */
                        err = rd_saved_floor(sf_ptr);
-                       
+
                        /* Error? */
                        if (err) break;
 
@@ -2845,67 +3240,31 @@ static errr rd_dungeon(void)
        switch (err)
        {
        case 151:
-#ifdef JP
-               note("¥¢¥¤¥Æ¥à¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë¡ª");
-#else
-               note("Too many object entries!");
-#endif
+               note(_("アイテムの配列が大きすぎる!", "Too many object entries!"));
                break;
 
        case 152:
-#ifdef JP
-               note("¥¢¥¤¥Æ¥àÇÛÃÖ¥¨¥é¡¼");
-#else
-               note("Object allocation error");
-#endif
+               note(_("アイテム配置エラー", "Object allocation error"));
                break;
 
        case 161:
-#ifdef JP
-               note("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礭¤¹¤®¤ë¡ª");
-#else
-               note("Too many monster entries!");
-#endif
+               note(_("モンスターの配列が大きすぎる!", "Too many monster entries!"));
                break;
 
        case 162:
-#ifdef JP
-               note("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼");
-#else
-               note("Monster allocation error");
-#endif
+               note(_("モンスター配置エラー", "Monster allocation error"));
                break;
 
        case 171:
-#ifdef JP
-               note("Êݸ¤µ¤ì¤¿¥Õ¥í¥¢¤Î¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿¤¬²õ¤ì¤Æ¤¤¤Þ¤¹¡ª");
-#else
-               note("Dungeon data of saved floors are broken!");
-#endif
-               break;
-
-       case 181:
-#ifdef JP
-               note("Error 181");
-#else
-               note("Error 181");
-#endif
+               note(_("保存されたフロアのダンジョンデータが壊れています!", "Dungeon data of saved floors are broken!"));
                break;
 
        case 182:
-#ifdef JP
-               note("¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¡ª");
-#else
-               note("Failed to make temporal files!");
-#endif
+               note(_("テンポラリ・ファイルを作成できません!", "Failed to make temporal files!"));
                break;
 
        case 183:
-#ifdef JP
-               note("Error 183");
-#else
-               note("Error 183");
-#endif
+               note(_("Error 183", "Error 183"));
                break;
        }
 
@@ -2917,8 +3276,9 @@ static errr rd_dungeon(void)
 }
 
 
-/*
- * Actually read the savefile
+/*!
+ * @brief ロード処理全体のサブ関数 / Actually read the savefile
+ * @return エラーコード
  */
 static errr rd_savefile_new_aux(void)
 {
@@ -2940,11 +3300,7 @@ static errr rd_savefile_new_aux(void)
 
        /* Mention the savefile version */
        note(format(
-#ifdef JP
-                    "¥Ð¡¼¥¸¥ç¥ó %d.%d.%d ¤Î¥»¡¼¥Ö¡¦¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥ÉÃæ...",
-#else
-                    "Loading a %d.%d.%d savefile...",
-#endif
+                    _("バージョン %d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d savefile..."),
                     (z_major > 9) ? z_major - 10 : z_major, z_minor, z_patch));
 
 
@@ -2983,36 +3339,25 @@ static errr rd_savefile_new_aux(void)
        rd_u32b(&tmp32u);
 
        /* Later use (always zero) */
-       rd_u32b(&tmp32u);
+       rd_u16b(&tmp16u);
+
+       /* Later use (always zero) */
+       rd_byte(&tmp8u);
 
+       /* Kanji code */
+       rd_byte(&kanji_code);
 
        /* Read RNG state */
        rd_randomizer();
-#ifdef JP
-if (arg_fiddle) note("Íð¿ô¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Randomizer Info");
-#endif
-
-
+       if (arg_fiddle) note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
 
        /* Then the options */
        rd_options();
-#ifdef JP
-if (arg_fiddle) note("¥ª¥×¥·¥ç¥ó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Option Flags");
-#endif
+       if (arg_fiddle) note(_("オプションをロードしました", "Loaded Option Flags"));
 
        /* Then the "messages" */
        rd_messages();
-#ifdef JP
-if (arg_fiddle) note("¥á¥Ã¥»¡¼¥¸¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Messages");
-#endif
-
-
+       if (arg_fiddle) note(_("メッセージをロードしました", "Loaded Messages"));
 
        for (i = 0; i < max_r_idx; i++)
        {
@@ -3021,8 +3366,11 @@ if (arg_fiddle) note("
 
                /* Hack -- Reset the death counter */
                r_ptr->max_num = 100;
+
                if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1;
-               if (r_ptr->flags7 & RF7_UNIQUE_7) r_ptr->max_num = 7;
+
+               /* Hack -- Non-unique Nazguls are semi-unique */
+               else if (r_ptr->flags7 & RF7_NAZGUL) r_ptr->max_num = MAX_NAZGUL_NUM;
        }
 
        /* Monster Memory */
@@ -3031,12 +3379,7 @@ if (arg_fiddle) note("
        /* Incompatible save files */
        if (tmp16u > max_r_idx)
        {
-#ifdef JP
-note(format("¥â¥ó¥¹¥¿¡¼¤Î¼ï²¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
-#else
-               note(format("Too many (%u) monster races!", tmp16u));
-#endif
-
+               note(format(_("モンスターの種族が多すぎる(%u)!", "Too many (%u) monster races!"), tmp16u));
                return (21);
        }
 
@@ -3047,13 +3390,7 @@ note(format("
                rd_lore(i);
        }
 
-#ifdef JP
-if (arg_fiddle) note("¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Monster Memory");
-#endif
-
-
+       if (arg_fiddle) note(_("モンスターの思い出をロードしました", "Loaded Monster Memory"));
 
        /* Object Memory */
        rd_u16b(&tmp16u);
@@ -3061,19 +3398,13 @@ if (arg_fiddle) note("
        /* Incompatible save files */
        if (tmp16u > max_k_idx)
        {
-#ifdef JP
-note(format("¥¢¥¤¥Æ¥à¤Î¼ïÎब¿¤¹¤®¤ë(%u)¡ª", tmp16u));
-#else
-               note(format("Too many (%u) object kinds!", tmp16u));
-#endif
-
+               note(format(_("アイテムの種類が多すぎる(%u)!", "Too many (%u) object kinds!"), tmp16u));
                return (22);
        }
 
        /* Read the object memory */
        for (i = 0; i < tmp16u; i++)
        {
-               byte tmp8u;
                object_kind *k_ptr = &k_info[i];
 
                rd_byte(&tmp8u);
@@ -3081,39 +3412,7 @@ note(format("
                k_ptr->aware = (tmp8u & 0x01) ? TRUE: FALSE;
                k_ptr->tried = (tmp8u & 0x02) ? TRUE: FALSE;
        }
-#ifdef JP
-if (arg_fiddle) note("¥¢¥¤¥Æ¥à¤Îµ­Ï¿¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Object Memory");
-#endif
-
-
-#if 0
-       /*
-        * Initialize arena and rewards information
-        */
-       p_ptr->arena_number = 0;
-       p_ptr->inside_arena = 0;
-       p_ptr->inside_quest = 0;
-       p_ptr->leftbldg = FALSE;
-       p_ptr->exit_bldg = TRUE;
-
-       /* Start in town 1 */
-       p_ptr->town_num = 1;
-
-       p_ptr->wilderness_x = 4;
-       p_ptr->wilderness_y = 4;
-
-#endif
-
-       /* Init the wilderness seeds */
-       for (i = 0; i < max_wild_x; i++)
-       {
-               for (j = 0; j < max_wild_y; j++)
-               {
-                       wilderness[j][i].seed = randint0(0x10000000);
-               }
-       }
+       if (arg_fiddle) note(_("アイテムの記録をロードしました", "Loaded Object Memory"));
 
        /* 2.1.3 or newer version */
        {
@@ -3128,12 +3427,7 @@ if (arg_fiddle) note("
                /* Incompatible save files */
                if (max_towns_load > max_towns)
                {
-#ifdef JP
-note(format("Ä®¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_towns_load));
-#else
-                       note(format("Too many (%u) towns!", max_towns_load));
-#endif
-
+                       note(format(_("町が多すぎる(%u)!", "Too many (%u) towns!"), max_towns_load));
                        return (23);
                }
 
@@ -3152,12 +3446,7 @@ note(format("Į
                /* Incompatible save files */
                if (max_quests_load > max_quests)
                {
-#ifdef JP
-note(format("¥¯¥¨¥¹¥È¤¬Â¿¤¹¤®¤ë(%u)¡ª", max_quests_load));
-#else
-                       note(format("Too many (%u) quests!", max_quests_load));
-#endif
-
+                       note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
                        return (23);
                }
 
@@ -3165,75 +3454,58 @@ note(format("
                {
                        if (i < max_quests)
                        {
-                               rd_s16b(&quest[i].status);
-                               rd_s16b(&quest[i].level);
+                               quest_type* const q_ptr = &quest[i];
+                               
+                               rd_s16b(&q_ptr->status);
+                               rd_s16b(&q_ptr->level);
 
                                if (z_older_than(11, 0, 6))
                                {
-                                       quest[i].complev = 0;
+                                       q_ptr->complev = 0;
+                               }
+                               else
+                               {
+                                       rd_byte(&q_ptr->complev);
+                               }
+                               if(h_older_than(2, 1, 2, 2))
+                               {
+                                       q_ptr->comptime = 0;
                                }
                                else
                                {
-                                       rd_byte(&quest[i].complev);
+                                       rd_u32b(&q_ptr->comptime);
                                }
 
                                /* Load quest status if quest is running */
-                               if (quest[i].status == QUEST_STATUS_TAKEN || (!z_older_than(10, 3, 14) && (quest[i].status == QUEST_STATUS_COMPLETED)) || (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST+max_rquests_load))))
+                               if ((q_ptr->status == QUEST_STATUS_TAKEN) ||
+                                   (!z_older_than(10, 3, 14) && (q_ptr->status == QUEST_STATUS_COMPLETED)) ||
+                                   (!z_older_than(11, 0, 7) && (i >= MIN_RANDOM_QUEST) && (i <= (MIN_RANDOM_QUEST + max_rquests_load))))
                                {
-                                       rd_s16b(&quest[i].cur_num);
-                                       rd_s16b(&quest[i].max_num);
-                                       rd_s16b(&quest[i].type);
+                                       rd_s16b(&q_ptr->cur_num);
+                                       rd_s16b(&q_ptr->max_num);
+                                       rd_s16b(&q_ptr->type);
 
                                        /* Load quest monster index */
-                                       rd_s16b(&quest[i].r_idx);
+                                       rd_s16b(&q_ptr->r_idx);
 
-                                       if ((quest[i].type == QUEST_TYPE_RANDOM) && (!quest[i].r_idx))
+                                       if ((q_ptr->type == QUEST_TYPE_RANDOM) && (!q_ptr->r_idx))
                                        {
-                                               int r_idx;
-                                               while (1)
-                                               {
-                                                        monster_race *r_ptr;
-
-                                                       /*
-                                                        * Random monster 5 - 10 levels out of depth
-                                                        * (depending on level)
-                                                        */
-                                                       r_idx = get_mon_num(quest[i].level + 5 + randint1(quest[i].level / 10));
-                                                       r_ptr = &r_info[r_idx];
-
-                                                       if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
-
-                                                       if(r_ptr->flags6 & RF6_SPECIAL) continue;
-
-                                                       if(r_ptr->flags7 & RF7_FRIENDLY) continue;
-
-                                                       if(r_ptr->flags7 & RF7_AQUATIC) continue;
-
-                                                       if(r_ptr->flags8 & RF8_WILD_ONLY) continue;
-
-                                                       /*
-                                                        * Accept monsters that are 2 - 6 levels
-                                                        * out of depth depending on the quest level
-                                                        */
-                                                       if (r_ptr->level > (quest[i].level + (quest[i].level / 20))) break;
-                                               }
-
-                                               quest[i].r_idx = r_idx;
+                                               determine_random_questor(&quest[i]);
                                        }
 
                                        /* Load quest item index */
-                                       rd_s16b(&quest[i].k_idx);
+                                       rd_s16b(&q_ptr->k_idx);
 
-                                       if (quest[i].k_idx)
-                                               a_info[quest[i].k_idx].gen_flags |= TRG_QUESTITEM;
+                                       if (q_ptr->k_idx)
+                                               a_info[q_ptr->k_idx].gen_flags |= TRG_QUESTITEM;
 
-                                       rd_byte(&quest[i].flags);
+                                       rd_byte(&q_ptr->flags);
 
                                        if (z_older_than(10, 3, 11))
                                        {
-                                               if (quest[i].flags & QUEST_FLAG_PRESET)
+                                               if (q_ptr->flags & QUEST_FLAG_PRESET)
                                                {
-                                                       quest[i].dungeon = 0;
+                                                       q_ptr->dungeon = 0;
                                                }
                                                else
                                                {
@@ -3246,12 +3518,12 @@ note(format("
                                        }
                                        else
                                        {
-                                               rd_byte(&quest[i].dungeon);
+                                               rd_byte(&q_ptr->dungeon);
                                        }
                                        /* Mark uniques */
-                                       if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_UNTAKEN)
-                                               if (r_info[quest[i].r_idx].flags1 & RF1_UNIQUE)
-                                                       r_info[quest[i].r_idx].flags1 |= RF1_QUESTOR;
+                                       if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_UNTAKEN)
+                                               if (r_info[q_ptr->r_idx].flags1 & RF1_UNIQUE)
+                                                       r_info[q_ptr->r_idx].flags1 |= RF1_QUESTOR;
                                }
                        }
                        /* Ignore the empty quests from old versions */
@@ -3270,6 +3542,13 @@ note(format("
                        }
                }
 
+               /* Quest 18 was removed */
+               if (h_older_than(1, 7, 0, 6))
+               {
+                       (void)WIPE(&quest[OLD_QUEST_WATER_CAVE], quest_type);
+                       quest[OLD_QUEST_WATER_CAVE].status = QUEST_STATUS_UNTAKEN;
+               }
+
                /* Position in the wilderness */
                rd_s32b(&p_ptr->wilderness_x);
                rd_s32b(&p_ptr->wilderness_y);
@@ -3291,12 +3570,7 @@ note(format("
                /* Incompatible save files */
                if ((wild_x_size > max_wild_x) || (wild_y_size > max_wild_y))
                {
-#ifdef JP
-note(format("¹ÓÌÂ礭¤¹¤®¤ë(%u/%u)¡ª", wild_x_size, wild_y_size));
-#else
-                       note(format("Wilderness is too big (%u/%u)!", wild_x_size, wild_y_size));
-#endif
-
+                       note(format(_("荒野が大きすぎる(%u/%u)!", "Wilderness is too big (%u/%u)!"), wild_x_size, wild_y_size));
                        return (23);
                }
 
@@ -3310,11 +3584,7 @@ note(format("
                }
        }
 
-#ifdef JP
-if (arg_fiddle) note("¥¯¥¨¥¹¥È¾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Quests");
-#endif
+       if (arg_fiddle) note(_("クエスト情報をロードしました", "Loaded Quests"));
 
        /* Load the Artifacts */
        rd_u16b(&tmp16u);
@@ -3322,12 +3592,7 @@ if (arg_fiddle) note("
        /* Incompatible save files */
        if (tmp16u > max_a_idx)
        {
-#ifdef JP
-note(format("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë(%u)¡ª", tmp16u));
-#else
-               note(format("Too many (%u) artifacts!", tmp16u));
-#endif
-
+               note(format(_("伝説のアイテムが多すぎる(%u)!", "Too many (%u) artifacts!"), tmp16u));
                return (24);
        }
 
@@ -3352,23 +3617,13 @@ note(format("
                        rd_s16b(&a_ptr->floor_id);
                }
        }
-#ifdef JP
-if (arg_fiddle) note("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded Artifacts");
-#endif
-
-
+       if (arg_fiddle) note(_("伝説のアイテムをロードしました", "Loaded Artifacts"));
 
        /* Read the extra stuff */
        rd_extra();
        if (p_ptr->energy_need < -999) world_player = TRUE;
 
-#ifdef JP
-if (arg_fiddle) note("ÆÃÊ̾ðÊó¤ò¥í¡¼¥É¤·¤Þ¤·¤¿");
-#else
-       if (arg_fiddle) note("Loaded extra information");
-#endif
+       if (arg_fiddle) note(_("特別情報をロードしました", "Loaded extra information"));
 
 
        /* Read the player_hp array */
@@ -3377,12 +3632,7 @@ if (arg_fiddle) note("
        /* Incompatible save files */
        if (tmp16u > PY_MAX_LEVEL)
        {
-#ifdef JP
-note(format("¥Ò¥Ã¥È¥Ý¥¤¥ó¥ÈÇÛÎó¤¬Â礭¤¹¤®¤ë(%u)¡ª", tmp16u));
-#else
-               note(format("Too many (%u) hitpoint entries!", tmp16u));
-#endif
-
+               note(format(_("ヒットポイント配列が大きすぎる(%u)!", "Too many (%u) hitpoint entries!"), tmp16u));
                return (25);
        }
 
@@ -3465,12 +3715,7 @@ note(format("
        /* Read the inventory */
        if (rd_inventory())
        {
-#ifdef JP
-note("»ý¤Áʪ¾ðÊó¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó");
-#else
-               note("Unable to read inventory");
-#endif
-
+               note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
                return (21);
        }
 
@@ -3549,20 +3794,11 @@ note("
        if (!p_ptr->is_dead)
        {
                /* Dead players have no dungeon */
-#ifdef JP
-note("¥À¥ó¥¸¥ç¥óÉü¸µÃæ...");
-#else
-               note("Restoring Dungeon...");
-#endif
+               note(_("ダンジョン復元中...", "Restoring Dungeon..."));
 
                if (rd_dungeon())
                {
-#ifdef JP
-note("¥À¥ó¥¸¥ç¥ó¥Ç¡¼¥¿Æɤ߹þ¤ß¼ºÇÔ");
-#else
-                       note("Error reading dungeon data");
-#endif
-
+                       note(_("ダンジョンデータ読み込み失敗", "Error reading dungeon data"));
                        return (34);
                }
 
@@ -3577,6 +3813,17 @@ note("
                }
        }
 
+       /* Quest 18 was removed */
+       if (h_older_than(1, 7, 0, 6))
+       {
+               if (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE)
+               {
+                       dungeon_type = lite_town ? DUNGEON_ANGBAND : DUNGEON_GALGALS;
+                       dun_level = 1;
+                       p_ptr->inside_quest = 0;
+               }
+       }
+
 
 #ifdef VERIFY_CHECKSUMS
 
@@ -3589,12 +3836,7 @@ note("
        /* Verify */
        if (o_v_check != n_v_check)
        {
-#ifdef JP
-note("¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
-#else
-               note("Invalid checksum");
-#endif
-
+               note(_("チェックサムがおかしい", "Invalid checksum"));
                return (11);
        }
 
@@ -3609,12 +3851,7 @@ note("
        /* Verify */
        if (o_x_check != n_x_check)
        {
-#ifdef JP
-note("¥¨¥ó¥³¡¼¥É¤µ¤ì¤¿¥Á¥§¥Ã¥¯¥µ¥à¤¬¤ª¤«¤·¤¤");
-#else
-               note("Invalid encoded checksum");
-#endif
-
+               note(_("エンコードされたチェックサムがおかしい", "Invalid encoded checksum"));
                return (11);
        }
 
@@ -3624,17 +3861,23 @@ note("
        return (0);
 }
 
-
-/*
- * Actually read the savefile
+/*!
+ * @brief ロード処理全体のメイン関数 / Actually read the savefile
+ * @return エラーコード
  */
 errr rd_savefile_new(void)
 {
        errr err;
 
+       /* Grab permissions */
+       safe_setuid_grab();
+
        /* The savefile is a binary file */
        fff = my_fopen(savefile, "rb");
 
+       /* Drop permissions */
+       safe_setuid_drop();
+
        /* Paranoia */
        if (!fff) return (-1);
 
@@ -3652,8 +3895,10 @@ errr rd_savefile_new(void)
 }
 
 
-/*
- * Actually load and verify a floor save data
+/*!
+ * @brief 保存フロア読み込みのサブ関数 / Actually load and verify a floor save data
+ * @param sf_ptr 保存フロア読み込み先
+ * @return 成功したらtrue
  */
 static bool load_floor_aux(saved_floor_type *sf_ptr)
 {
@@ -3713,8 +3958,11 @@ static bool load_floor_aux(saved_floor_type *sf_ptr)
 }
 
 
-/*
- * Attempt to load the temporally saved-floor data
+/*!
+ * @brief 一時保存フロア情報を読み込む / Attempt to load the temporally saved-floor data
+ * @param sf_ptr 保存フロア読み込み先
+ * @param mode オプション
+ * @return 成功したらtrue
  */
 bool load_floor(saved_floor_type *sf_ptr, u32b mode)
 {
@@ -3726,10 +3974,31 @@ bool load_floor(saved_floor_type *sf_ptr, u32b mode)
        byte old_h_ver_minor = 0;
        byte old_h_ver_patch = 0;
        byte old_h_ver_extra = 0;
-
        bool ok = TRUE;
        char floor_savefile[1024];
 
+       byte old_kanji_code = kanji_code;
+
+       /*
+        * Temporal files are always written in system depended kanji
+        * code.
+        */
+#ifdef JP
+# ifdef EUC
+       /* EUC kanji code */
+       kanji_code = 2;
+# endif
+# ifdef SJIS
+       /* SJIS kanji code */
+       kanji_code = 3;
+# endif
+#else
+       /* ASCII */
+       kanji_code = 1;
+#endif
+
+
        /* We have one file already opened */
        if (mode & SLF_SECOND)
        {
@@ -3747,9 +4016,15 @@ bool load_floor(saved_floor_type *sf_ptr, u32b mode)
        /* floor savefile */
        sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
 
+       /* Grab permissions */
+       safe_setuid_grab();
+
        /* The savefile is a binary file */
        fff = my_fopen(floor_savefile, "rb");
 
+       /* Drop permissions */
+       safe_setuid_drop();
+
        /* Couldn't read */
        if (!fff) ok = FALSE;
 
@@ -3765,8 +4040,14 @@ bool load_floor(saved_floor_type *sf_ptr, u32b mode)
                /* Close the file */
                my_fclose(fff);
 
+               /* Grab permissions */
+               safe_setuid_grab();
+
                /* Delete the file */
                if (!(mode & SLF_NO_KILL)) (void)fd_kill(floor_savefile);
+
+               /* Drop permissions */
+               safe_setuid_drop();
        }
 
        /* We have one file already opened */
@@ -3783,6 +4064,9 @@ bool load_floor(saved_floor_type *sf_ptr, u32b mode)
                h_ver_extra = old_h_ver_extra;
        }
 
+       /* Restore old knowledge */
+       kanji_code = old_kanji_code;
+
        /* Result */
        return ok;
 }