X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fsave%2Fsave.cpp;h=a6d34cda594d834990f42bdcc844075b27408131;hb=refs%2Fheads%2Fmacos-develop;hp=5e5a05e6d887b63d73d496cf9bf856800976ba85;hpb=6aa0ca7680b60c13405a9cfada22703b8a0048d2;p=hengbandforosx%2Fhengbandosx.git diff --git a/src/save/save.cpp b/src/save/save.cpp index 5e5a05e6d..4a1aad4f1 100644 --- a/src/save/save.cpp +++ b/src/save/save.cpp @@ -16,12 +16,11 @@ #include "dungeon/quest.h" #include "floor/floor-town.h" #include "floor/wild.h" -#include "game-option/text-display-options.h" #include "inventory/inventory-slot-types.h" #include "io/files-util.h" #include "io/report.h" #include "io/uid-checker.h" -#include "monster-race/monster-race.h" +#include "locale/character-encoding.h" #include "monster/monster-compaction.h" #include "monster/monster-status.h" #include "player/player-status.h" @@ -33,13 +32,14 @@ #include "save/save-util.h" #include "store/store-owners.h" #include "store/store-util.h" -#include "system/angband-version.h" +#include "system/angband-system.h" #include "system/artifact-type-definition.h" #include "system/baseitem-info.h" #include "system/item-entity.h" #include "system/monster-race-info.h" #include "system/player-type-definition.h" #include "util/angband-files.h" +#include "util/enum-converter.h" #include "view/display-messages.h" #include "world/world.h" #include @@ -52,15 +52,16 @@ * @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); uint32_t now = (uint32_t)time((time_t *)0); - w_ptr->sf_system = 0L; - w_ptr->sf_when = now; - w_ptr->sf_saves++; + auto &world = AngbandWorld::get_instance(); + world.sf_system = 0L; + world.sf_when = now; + world.sf_saves++; save_xor_byte = 0; auto variant_length = VARIANT_NAME.length(); @@ -81,10 +82,10 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) v_stamp = 0L; x_stamp = 0L; - wr_u32b(w_ptr->sf_system); - wr_u32b(w_ptr->sf_when); - wr_u16b(w_ptr->sf_lives); - wr_u16b(w_ptr->sf_saves); + wr_u32b(world.sf_system); + wr_u32b(world.sf_when); + wr_u16b(world.sf_lives); + wr_u16b(world.sf_saves); wr_u32b(SAVEFILE_VERSION); wr_u16b(0); @@ -92,26 +93,18 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) #ifdef JP #ifdef EUC - wr_byte(2); + wr_byte(enum2i(CharacterEncoding::EUC_JP)); #endif #ifdef SJIS - wr_byte(3); + wr_byte(enum2i(CharacterEncoding::SHIFT_JIS)); #endif #else - wr_byte(1); + wr_byte(enum2i(CharacterEncoding::US_ASCII)); #endif wr_randomizer(); - wr_options(type); - uint32_t tmp32u = message_num(); - if ((compress_savefile || (type == SaveType::DEBUG)) && (tmp32u > 40)) { - tmp32u = 40; - } - - wr_u32b(tmp32u); - for (int i = tmp32u - 1; i >= 0; i--) { - wr_string(*message_str(i)); - } + wr_options(); + wr_message_history(); uint16_t tmp16u = static_cast(monraces_info.size()); wr_u16b(tmp16u); @@ -119,7 +112,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) wr_lore(i2enum(r_idx)); } - tmp16u = static_cast(baseitems_info.size()); + tmp16u = static_cast(BaseitemList::get_instance().size()); wr_u16b(tmp16u); for (short bi_id = 0; bi_id < tmp16u; bi_id++) { wr_perception(bi_id); @@ -128,15 +121,15 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) tmp16u = static_cast(towns_info.size()); wr_u16b(tmp16u); - const auto &quest_list = QuestList::get_instance(); - tmp16u = static_cast(quest_list.size()); + const auto &quests = QuestList::get_instance(); + tmp16u = static_cast(quests.size()); wr_u16b(tmp16u); tmp8u = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST; wr_byte(tmp8u); - for (const auto &[q_idx, quest] : quest_list) { - wr_s16b(enum2i(q_idx)); + for (const auto &[quest_id, quest] : quests) { + wr_s16b(enum2i(quest_id)); wr_s16b(enum2i(quest.status)); wr_s16b((int16_t)quest.level); wr_byte((byte)quest.complev); @@ -144,7 +137,7 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) auto is_quest_running = quest.status == QuestStatusType::TAKEN; is_quest_running |= quest.status == QuestStatusType::COMPLETED; - is_quest_running |= !QuestType::is_fixed(q_idx); + is_quest_running |= !QuestType::is_fixed(quest_id); if (!is_quest_running) { continue; } @@ -153,7 +146,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); } @@ -162,27 +155,28 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) wr_s32b(player_ptr->wilderness_y); wr_bool(player_ptr->wild_mode); wr_bool(player_ptr->ambush_flag); - wr_s32b(w_ptr->max_wild_x); - wr_s32b(w_ptr->max_wild_y); - for (int i = 0; i < w_ptr->max_wild_x; i++) { - for (int j = 0; j < w_ptr->max_wild_y; j++) { + wr_s32b(world.max_wild_x); + wr_s32b(world.max_wild_y); + for (int i = 0; i < world.max_wild_x; i++) { + for (int j = 0; j < world.max_wild_y; j++) { wr_u32b(wilderness[j][i].seed); } } - 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(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); } - wr_u32b(w_ptr->sf_play_time); - wr_FlagGroup(w_ptr->sf_winner, wr_byte); - wr_FlagGroup(w_ptr->sf_retired, wr_byte); + wr_u32b(world.sf_play_time); + wr_FlagGroup(world.sf_winner, wr_byte); + wr_FlagGroup(world.sf_retired, wr_byte); wr_player(player_ptr); tmp16u = PY_MAX_LEVEL; @@ -204,13 +198,13 @@ static bool wr_savefile_new(PlayerType *player_ptr, SaveType type) } for (int i = 0; i < INVEN_TOTAL; i++) { - auto *o_ptr = &player_ptr->inventory_list[i]; - if (!o_ptr->is_valid()) { + const auto &item = player_ptr->inventory_list[i]; + if (!item.is_valid()) { continue; } wr_u16b((uint16_t)i); - wr_item(o_ptr); + wr_item(item); } wr_u16b(0xFFFF); @@ -254,7 +248,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); @@ -269,7 +263,7 @@ static bool save_player_aux(PlayerType *player_ptr, const std::filesystem::path 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; } @@ -290,8 +284,9 @@ static bool save_player_aux(PlayerType *player_ptr, const std::filesystem::path return false; } - counts_write(player_ptr, 0, w_ptr->play_time); - w_ptr->character_saved = true; + auto &world = AngbandWorld::get_instance(); + counts_write(player_ptr, 0, world.play_time); + world.character_saved = true; return true; } @@ -312,34 +307,30 @@ 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)) { + auto &world = AngbandWorld::get_instance(); + world.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; + world.character_loaded = true; result = true; } if (type != SaveType::CLOSE_GAME) { - w_ptr->is_loading_now = false; + world.is_loading_now = false; update_creature(player_ptr); mproc_init(player_ptr->current_floor_ptr); - w_ptr->is_loading_now = true; + world.is_loading_now = true; } return result;