OSDN Git Service

[Refactor] ZAngbandバージョン番号廃止
authoriks <iks3@users.noreply.github.com>
Fri, 26 Mar 2021 09:05:36 +0000 (18:05 +0900)
committeriks <iks3@users.noreply.github.com>
Fri, 26 Mar 2021 09:05:36 +0000 (18:05 +0900)
Zバージョン2.0.6だったころのHengbandセーブデータの互換性を廃止

src/load/info-loader.cpp
src/load/load-v1-5-0.cpp
src/load/load-zangband.cpp
src/load/load-zangband.h
src/load/load.cpp
src/load/player-info-loader.cpp
src/system/angband-version.h
src/world/world.h

index d04c8f4..87e0646 100644 (file)
@@ -4,12 +4,22 @@
 #include "load/load-util.h"
 #include "load/option-loader.h"
 #include "system/angband.h"
+#include "system/angband-version.h"
 #include "view/display-messages.h"
 #include "world/world.h"
 
+/*!
+ * @brief セーブファイルからバージョン情報及びセーブ情報を取得する
+ * @details
+ * バージョン0.x.x時代のバージョン情報である場合、サポート対象外
+ * (FAKE_VERもH_VERも10台の数字のはず)
+ */
 void rd_version_info(void)
 {
-    strip_bytes(4);
+    byte fake_major;
+    rd_byte(&fake_major);
+
+    strip_bytes(3);
     load_xor_byte = current_world_ptr->sf_extra;
     v_check = 0L;
     x_check = 0L;
@@ -27,9 +37,13 @@ void rd_version_info(void)
 
     rd_u32b(&loading_savefile_version);
 
-    load_note(format(_("バージョン %d.%d.%d.%d のセーブデータ(SAVE%lu形式)をロード中...", "Loading a Verison %d.%d.%d.%d savefile (SAVE%lu format)..."),
-        (current_world_ptr->h_ver_major > 9) ? current_world_ptr->h_ver_major - 10 : current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor,
-        current_world_ptr->h_ver_patch, current_world_ptr->h_ver_extra, loading_savefile_version));
+    /* h_ver_majorがfake_ver_majorと同じだったころへの対策 */
+    if (fake_major - current_world_ptr->h_ver_major < FAKE_VER_PLUS)
+        current_world_ptr->h_ver_major -= FAKE_VER_PLUS;
+
+    load_note(format(_("バージョン %d.%d.%d のセーブデータ(SAVE%lu形式)をロード中...", "Loading a Verison %d.%d.%d savefile (SAVE%lu format)..."),
+        current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor, current_world_ptr->h_ver_patch,
+        loading_savefile_version));
 }
 
 /*!
index 881dae1..9763013 100644 (file)
@@ -426,26 +426,21 @@ void rd_monster_old(player_type *player_ptr, monster_type *m_ptr)
     rd_byte(&tmp8u);
     m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
 
-    if (!(current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)) {
-        u32b tmp32u;
-        rd_u32b(&tmp32u);
-        std::bitset<32> rd_bits(tmp32u);
-        for (size_t i = 0; i < std::min(m_ptr->smart.size(), rd_bits.size()); i++) {
-            auto f = static_cast<SM>(i);
-            m_ptr->smart[f] = rd_bits[i];
-        }
-
-        // 3.0.0Alpha10以前のSM_CLONED(ビット位置22)、SM_PET(23)、SM_FRIEDLY(28)をMFLAG2に移行する
-        // ビット位置の定義はなくなるので、ビット位置の値をハードコードする。
-        m_ptr->mflag2[MFLAG2::CLONED] = rd_bits[22];
-        m_ptr->mflag2[MFLAG2::PET] = rd_bits[23];
-        m_ptr->mflag2[MFLAG2::FRIENDLY] = rd_bits[28];
-        m_ptr->smart.reset(static_cast<SM>(22)).reset(static_cast<SM>(23)).reset(static_cast<SM>(28));
-    } else {
-        m_ptr->smart.clear();
+    u32b tmp32u;
+    rd_u32b(&tmp32u);
+    std::bitset<32> rd_bits(tmp32u);
+    for (size_t i = 0; i < std::min(m_ptr->smart.size(), rd_bits.size()); i++) {
+        auto f = static_cast<SM>(i);
+        m_ptr->smart[f] = rd_bits[i];
     }
 
-    u32b tmp32u;
+    // 3.0.0Alpha10以前のSM_CLONED(ビット位置22)、SM_PET(23)、SM_FRIEDLY(28)をMFLAG2に移行する
+    // ビット位置の定義はなくなるので、ビット位置の値をハードコードする。
+    m_ptr->mflag2[MFLAG2::CLONED] = rd_bits[22];
+    m_ptr->mflag2[MFLAG2::PET] = rd_bits[23];
+    m_ptr->mflag2[MFLAG2::FRIENDLY] = rd_bits[28];
+    m_ptr->smart.reset(static_cast<SM>(22)).reset(static_cast<SM>(23)).reset(static_cast<SM>(28));
+
     if (h_older_than(0, 4, 5)) {
         m_ptr->exp = 0;
     } else {
index bc5f12d..84b18f1 100644 (file)
@@ -119,37 +119,6 @@ void set_zangband_bounty_uniques(player_type *creature_ptr)
     }
 }
 
-/*!
- * @brief ZAngband v2.0.6に存在しない時限効果を0で初期化する / Old savefiles do not have the following fields...
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @return なし
- * @details 厳密にv2.0.6しか見ていないため、ZAngband v2.0.5 以前のセーブデータは非対応
- */
-void set_zangband_timed_effects(player_type *creature_ptr)
-{
-    creature_ptr->tim_esp = 0;
-    creature_ptr->wraith_form = 0;
-    creature_ptr->resist_magic = 0;
-    creature_ptr->tim_regen = 0;
-    creature_ptr->tim_pass_wall = 0;
-    creature_ptr->tim_stealth = 0;
-    creature_ptr->tim_levitation = 0;
-    creature_ptr->tim_sh_touki = 0;
-    creature_ptr->lightspeed = 0;
-    creature_ptr->tsubureru = 0;
-    creature_ptr->tim_res_nether = 0;
-    creature_ptr->tim_res_time = 0;
-    creature_ptr->mimic_form = 0;
-    creature_ptr->tim_mimic = 0;
-    creature_ptr->tim_sh_fire = 0;
-    creature_ptr->tim_reflect = 0;
-    creature_ptr->multishadow = 0;
-    creature_ptr->dustrobe = 0;
-    creature_ptr->chaos_patron = ((creature_ptr->age + creature_ptr->sc) % MAX_PATRON);
-    creature_ptr->muta.clear();
-    get_virtues(creature_ptr);
-}
-
 void set_zangband_mimic(player_type *creature_ptr)
 {
     creature_ptr->tim_res_time = 0;
index 7369c73..fbfd519 100644 (file)
@@ -9,7 +9,6 @@ void set_zangband_skill(player_type *creature_ptr);
 void set_zangband_spells(player_type *creature_ptr);
 void set_zangband_race(player_type *creature_ptr);
 void set_zangband_bounty_uniques(player_type *creature_ptr);
-void set_zangband_timed_effects(player_type *creature_ptr);
 void set_zangband_mimic(player_type *creature_ptr);
 void set_zangband_holy_aura(player_type *creature_ptr);
 void set_zangband_reflection(player_type *creature_ptr);
index 7921b21..a3e3d79 100644 (file)
@@ -283,69 +283,67 @@ bool load_savedata(player_type *player_ptr, bool *new_game)
     }
 #endif
 
-    errr err = 0;
+    bool err = false;
     int fd = -1;
-    byte vvv[4];
+    byte fake_ver[4];
     if (!err) {
         fd = fd_open(savefile, O_RDONLY);
         if (fd < 0)
-            err = -1;
+            err = true;
 
         if (err)
-            what = _("セーブファイルを開けません", "Cannot open savefile");
+            what = _("セーブファイルを開けません", "Cannot open savefile");
     }
 
     if (!err) {
-        if (fd_read(fd, (char *)(vvv), 4))
-            err = -1;
+        if (fd_read(fd, (char *)(fake_ver), 4))
+            err = true;
 
         if (err)
-            what = _("セーブファイルを読めません", "Cannot read savefile");
+            what = _("セーブファイルを読めません", "Cannot read savefile");
 
         (void)fd_close(fd);
     }
 
     if (!err) {
-        current_world_ptr->z_major = vvv[0];
-        current_world_ptr->z_minor = vvv[1];
-        current_world_ptr->z_patch = vvv[2];
-        current_world_ptr->sf_extra = vvv[3];
+        if (fake_ver[0] < FAKE_VER_PLUS) {
+            what = _("セーブデータが古すぎます", "Savefile version is too old");
+            err = true;
+        }
+    }
+
+    if (err) {
+        msg_format("%s: %s", what, savefile);
+        msg_print(NULL);
+        return FALSE;
+    }
+
+    current_world_ptr->sf_extra = fake_ver[3];
+
+    if (!err) {
         term_clear();
-        err = rd_savefile(player_ptr);
+        if (rd_savefile(player_ptr))
+            err = true;
         if (err)
             what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
     }
 
     if (!err) {
         if (!current_world_ptr->game_turn)
-            err = -1;
+            err = true;
 
         if (err)
             what = _("セーブファイルが壊れています", "Broken savefile");
     }
 
     if (err) {
-        msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."), what,
-            (current_world_ptr->z_major > 9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor,
-            current_world_ptr->z_patch);
+        msg_format(_("エラー(%s)がバージョン%d.%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d.% savefile."), what,
+            current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor, current_world_ptr->h_ver_patch, current_world_ptr->h_ver_extra);
 
         msg_print(NULL);
         return FALSE;
     }
 
-    /*!< @todo v3.2.0 で削除予定 */
-    if ((FAKE_VER_MAJOR != current_world_ptr->z_major) || (FAKE_VER_MINOR != current_world_ptr->z_minor) || (FAKE_VER_PATCH != current_world_ptr->z_patch)) {
-        if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6) {
-            msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
-        } else {
-            msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
-                (current_world_ptr->z_major > 9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor,
-                current_world_ptr->z_patch);
-        }
-
-        msg_print(NULL);
-    }
-
     if (player_ptr->is_dead) {
         *new_game = TRUE;
         if (arg_wizard) {
index 6b6a810..e27bad0 100644 (file)
@@ -425,15 +425,9 @@ static void set_virtues(player_type *creature_ptr)
  * @brief 各種時限効果を読み込む
  * @param creature_ptr プレーヤーへの参照ポインタ
  * @return なし
- * @details ZAngbandとの互換性を保つ都合上、突然変異と徳の処理も追加している
  */
 static void rd_timed_effects(player_type *creature_ptr)
 {
-    if ((current_world_ptr->z_major == 2) && (current_world_ptr->z_minor == 0) && (current_world_ptr->z_patch == 6)) {
-        set_zangband_timed_effects(creature_ptr);
-        return;
-    }
-
     set_timed_effects(creature_ptr);
     rd_s16b(&creature_ptr->chaos_patron);
     set_mutations(creature_ptr);
index f3fdbbd..f6d94c3 100644 (file)
@@ -5,26 +5,29 @@
 #define VERSION_NAME "Hengband" /*!< バリアント名称 / Name of the version/variant */
 
 /*!
- * @brief ã\82²ã\83¼ã\83 ã\81®ã\83\90ã\83¼ã\82¸ã\83§ã\83³ç\95ªå\8f·å®\9a義 / "Program Version Number" of the game
+ * @brief ã\82»ã\83¼ã\83\96ã\83\95ã\82¡ã\82¤ã\83«ä¸\8aã\81®ã\83\90ã\83¼ã\82¸ã\83§ã\83³å®\9a義(ã\83¡ã\82¸ã\83£ã\83¼ç\95ªå\8f·) / "Savefile Version Number" for Hengband 1.1.1 and later
  * @details
- * 本FAKE_VERSIONそのものは未使用である。Zangと整合性を合わせるための疑似的処理のためFAKE_VER_MAJORは実値-10が該当のバージョン番号となる
+ * 当面FAKE_VER_*を参照しておく
  * <pre>
- * FAKE_VER_MAJOR=1,2 were reserved for ZAngband version 1.x.x/2.x.x .
  * Program Version of Hengband version is
- *   "(FAKE_VER_MAJOR-10).(FAKE_VER_MINOR).(FAKE_VER_PATCH)".
+ *   "(H_VER_MAJOR).(H_VER_MINOR).(H_VER_PATCH).(H_VER_EXTRA)".
+ * Upper compatibility is always guaranteed when it is more than 1.0.0 .
  * </pre>
  */
-#define FAKE_VERSION 0
+#define H_VER_MAJOR  3 //!< ゲームのバージョン定義(メジャー番号)
+#define H_VER_MINOR  0 //!< ゲームのバージョン定義(マイナー番号)
+#define H_VER_PATCH  0 //!< ゲームのバージョン定義(パッチ番号)
+#define H_VER_EXTRA 13 //!< ゲームのバージョン定義(エクストラ番号)
 
-#define FAKE_VER_MAJOR 13 /*!< ゲームのバージョン番号定義(メジャー番号 + 10) */
-#define FAKE_VER_MINOR 0 /*!< ゲームのバージョン番号定義(マイナー番号) */
-#define FAKE_VER_PATCH 0 /*!< ゲームのバージョン番号定義(パッチ番号) */
-#define FAKE_VER_EXTRA 13 /*!< ゲームのバージョン番号定義(エクストラ番号) */
+/*!
+ * @brief セーブファイルのバージョン(3.0.0から導入)
+ */
+constexpr u32b SAVEFILE_VERSION = 2;
 
 /*!
- * @brief バージョンが開発版が安定版かを返す
+ * @brief バージョンが開発版が安定版かを返す(廃止予定)
  */
-#define IS_STABLE_VERSION (FAKE_VER_MINOR % 2 == 0 && FAKE_VER_EXTRA == 0)
+#define IS_STABLE_VERSION (H_VER_MINOR % 2 == 0 && H_VER_EXTRA == 0)
 
 /*!
  * @brief 状態がアルファ版かどうかを返す
 #define IS_ALPHA_VERSION 1
 
 /*!
- * @brief ã\82»ã\83¼ã\83\96ã\83\95ã\82¡ã\82¤ã\83«ä¸\8aã\81®ã\83\90ã\83¼ã\82¸ã\83§ã\83³å®\9a義(ã\83¡ã\82¸ã\83£ã\83¼ç\95ªå\8f·) / "Savefile Version Number" for Hengband 1.1.1 and later
+ * @brief ã\82²ã\83¼ã\83 ã\81®ã\83\90ã\83¼ã\82¸ã\83§ã\83³ç\95ªå\8f·å®\9a義 / "Program Version Number" of the game
  * @details
- * 当面FAKE_VER_*を参照しておく
+ * 本FAKE_VERSIONそのものは未使用である。Zangと整合性を合わせるための疑似的処理のためFAKE_VER_MAJORは実値-10が該当のバージョン番号となる
  * <pre>
- * First three digits may be same as the Program Version.  But not
- * always same.  It means that newer version may preserves lower
- * compatibility with the older version.
- * For example, newer Hengband 1.4.4 creates savefiles marked with
- * Savefile Version 1.4.0.0 .  It means that Hengband 1.4.0 can load a
- * savefile of Hengband 1.4.4 (lower compatibility!).
- * Upper compatibility is always guaranteed.
+ * FAKE_VER_MAJOR=1,2 were reserved for ZAngband version 1.x.x/2.x.x .
  * </pre>
  */
-#define H_VER_MAJOR (FAKE_VER_MAJOR - 10) /*!< セーブファイル上のバージョン定義(メジャー番号) */
-#define H_VER_MINOR FAKE_VER_MINOR /*!< セーブファイル上のバージョン定義(マイナー番号) */
-#define H_VER_PATCH FAKE_VER_PATCH /*!< セーブファイル上のバージョン定義(パッチ番号) */
-#define H_VER_EXTRA FAKE_VER_EXTRA /*!< セーブファイル上のバージョン定義(エクストラ番号) */
-
-/** セーブファイルのバージョン */
-constexpr u32b SAVEFILE_VERSION = 2;
+#define FAKE_VER_PLUS 10 //!< 偽バージョン番号としていくつ足すか
+#define FAKE_VER_MAJOR (H_VER_MAJOR + FAKE_VER_PLUS) //!< 偽バージョン番号定義(メジャー番号) */
+#define FAKE_VER_MINOR H_VER_MINOR //!< 偽バージョン番号定義(マイナー番号) */
+#define FAKE_VER_PATCH H_VER_PATCH //!< 偽バージョン番号定義(パッチ番号) */
+#define FAKE_VER_EXTRA H_VER_EXTRA //!< 偽バージョン番号定義(エクストラ番号) */
 
 void put_version(char *buf);
index 394e20d..47dd229 100644 (file)
@@ -4,7 +4,10 @@
 
 #define MAX_BOUNTY 20
 
-typedef struct world_type {
+/*!
+ * @brief 世界情報構造体
+ */
+struct world_type {
 
     POSITION max_wild_x; /*!< Maximum size of the wilderness */
     POSITION max_wild_y; /*!< Maximum size of the wilderness */
@@ -29,27 +32,17 @@ typedef struct world_type {
 
     bool is_loading_now; /*!< ロード処理中フラグ...ロード直後にcalc_bonus()時の徳変化、及びsanity_blast()による異常を抑止する */
 
-    /*
-     * Savefile version
-     */
-    byte h_ver_major; /* Savefile version for Hengband 1.1.1 and later */
-    byte h_ver_minor;
-    byte h_ver_patch;
-    byte h_ver_extra;
+    byte h_ver_major; //!< 変愚蛮怒バージョン(メジャー番号) / Hengband version (major ver.)
+    byte h_ver_minor; //!< 変愚蛮怒バージョン(マイナー番号) / Hengband version (minor ver.)
+    byte h_ver_patch; //!< 変愚蛮怒バージョン(パッチ番号) / Hengband version (patch ver.)
+    byte h_ver_extra; //!< 変愚蛮怒バージョン(エクストラ番号) / Hengband version (extra ver.)
 
-    byte sf_extra; /* Savefile's encoding key */
+    byte sf_extra; //!< セーブファイルエンコードキー(XOR)
 
-    byte z_major; /* Savefile version for Hengband */
-    byte z_minor;
-    byte z_patch;
-
-    /*
-     * Savefile information
-     */
-    u32b sf_system; /* Operating system info */
-    u32b sf_when; /* Time when savefile created */
-    u16b sf_lives; /* Number of past "lives" with this file */
-    u16b sf_saves; /* Number of "saves" during this life */
+    u32b sf_system; //!< OS情報 / OS information
+    u32b sf_when; //!< 作成日時 / Created Date
+    u16b sf_lives; //!< このセーブファイルで何人プレイしたか / Number of past "lives" with this file
+    u16b sf_saves; //!< 現在のプレイで何回セーブしたか / Number of "saves" during this life
 
     bool character_generated; /* The character exists */
     bool character_dungeon; /* The character has a dungeon */
@@ -68,7 +61,7 @@ typedef struct world_type {
 
     DUNGEON_IDX max_d_idx;
 
-} world_type;
+};
 
 extern world_type *current_world_ptr;