OSDN Git Service

Merge branch 'develop' into macos-develop
[hengbandforosx/hengbandosx.git] / src / save / save.cpp
index 1e6cd34..183383a 100644 (file)
@@ -52,7 +52,7 @@
  * @param player_ptr プレイヤーへの参照ポインタ
  * @return 成功すればtrue
  */
-static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
+static bool wr_savefile_new(PlayerType *player_ptr)
 {
     compact_objects(player_ptr, 0);
     compact_monsters(player_ptr, 0);
@@ -102,9 +102,9 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
 #endif
 
     wr_randomizer();
-    wr_options(type);
+    wr_options();
     uint32_t tmp32u = message_num();
-    if ((compress_savefile || (type == SaveType::DEBUG)) && (tmp32u > 40)) {
+    if (compress_savefile && (tmp32u > 40)) {
         tmp32u = 40;
     }
 
@@ -119,7 +119,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
         wr_lore(i2enum<MonsterRaceId>(r_idx));
     }
 
-    tmp16u = static_cast<uint16_t>(baseitems_info.size());
+    tmp16u = static_cast<uint16_t>(BaseitemList::get_instance().size());
     wr_u16b(tmp16u);
     for (short bi_id = 0; bi_id < tmp16u; bi_id++) {
         wr_perception(bi_id);
@@ -153,7 +153,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
         wr_s16b((int16_t)quest.max_num);
         wr_s16b(enum2i(quest.type));
         wr_s16b(enum2i(quest.r_idx));
-        wr_s16b(enum2i(quest.reward_artifact_idx));
+        wr_s16b(enum2i(quest.reward_fa_id));
         wr_byte((byte)quest.flags);
         wr_byte((byte)quest.dungeon);
     }
@@ -170,12 +170,13 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
         }
     }
 
-    auto max_a_num = enum2i(artifacts_info.rbegin()->first);
+    const auto &artifacts = ArtifactList::get_instance();
+    auto max_a_num = enum2i(artifacts.rbegin()->first);
     tmp16u = max_a_num + 1;
     wr_u16b(tmp16u);
     for (auto i = 0U; i < tmp16u; i++) {
         const auto a_idx = i2enum<FixedArtifactId>(i);
-        const auto &artifact = ArtifactsInfo::get_instance().get_artifact(a_idx);
+        const auto &artifact = artifacts.get_artifact(a_idx);
         wr_bool(artifact.is_generated);
         wr_s16b(artifact.floor_id);
     }
@@ -254,7 +255,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type)
  * @param type セーブ後の処理種別
  * @return セーブの成功可否
  */
-static bool save_player_aux(PlayerType *player_ptr, const std::filesystem::path &path, SaveType type)
+static bool save_player_aux(PlayerType *player_ptr, const std::filesystem::path &path)
 {
     safe_setuid_grab();
     auto fd = fd_make(path);
@@ -265,10 +266,11 @@ static bool save_player_aux(PlayerType *player_ptr, const std::filesystem::path
     if (fd >= 0) {
         (void)fd_close(fd);
         safe_setuid_grab();
-        saving_savefile = angband_fopen(path, FileOpenMode::WRITE, true);
+        saving_savefile = angband_fopen(path, FileOpenMode::WRITE, true,
+            FileOpenType::SAVE);
         safe_setuid_drop();
         if (saving_savefile) {
-            if (wr_savefile_new(player_ptr, type)) {
+            if (wr_savefile_new(player_ptr)) {
                 is_save_successful = true;
             }
 
@@ -311,23 +313,18 @@ bool save_player(PlayerType *player_ptr, SaveType type)
     auto savefile_new = ss_new.str();
     safe_setuid_grab();
     fd_kill(savefile_new);
-    if (type == SaveType::DEBUG) {
-        const auto debug_save_dir = std::filesystem::path(debug_savefile).remove_filename();
-        std::error_code ec;
-        std::filesystem::create_directory(debug_save_dir, ec);
-    }
+
     safe_setuid_drop();
-    update_playtime();
-    bool result = false;
-    if (save_player_aux(player_ptr, savefile_new.data(), type)) {
+    w_ptr->update_playtime();
+    auto result = false;
+    if (save_player_aux(player_ptr, savefile_new.data())) {
         std::stringstream ss_old;
         ss_old << savefile.string() << ".old";
         auto savefile_old = ss_old.str();
         safe_setuid_grab();
         fd_kill(savefile_old);
-        const auto &path = type == SaveType::DEBUG ? debug_savefile : savefile;
-        fd_move(path, savefile_old);
-        fd_move(savefile_new, path);
+        fd_move(savefile, savefile_old);
+        fd_move(savefile_new, savefile);
         fd_kill(savefile_old);
         safe_setuid_drop();
         w_ptr->character_loaded = true;