OSDN Git Service

bb6156abb487b851aa0e75d56aa34edf4dddc58c
[hengbandforosx/hengbandosx.git] / src / load / info-loader.cpp
1 #include "load/info-loader.h"
2 #include "game-option/runtime-arguments.h"
3 #include "load/angband-version-comparer.h"
4 #include "load/load-util.h"
5 #include "load/option-loader.h"
6 #include "system/angband-version.h"
7 #include "system/angband.h"
8 #include "view/display-messages.h"
9 #include "world/world.h"
10
11 /*!
12  * @brief セーブファイルからバージョン情報及びセーブ情報を取得する
13  * @details
14  * バージョン0.x.x時代のバージョン情報である場合、サポート対象外
15  * (FAKE_VERもH_VERも10台の数字のはず)
16  */
17 void rd_version_info(void)
18 {
19     auto tmp_major = rd_byte();
20     auto is_old_ver = (10 <= tmp_major) && (tmp_major <= 13);
21     constexpr auto variant_length = VARIANT_NAME.length();
22     if (tmp_major == variant_length) {
23         strip_bytes(variant_length);
24         load_xor_byte = 0;
25         w_ptr->h_ver_major = rd_byte();
26         w_ptr->h_ver_minor = rd_byte();
27         w_ptr->h_ver_patch = rd_byte();
28         w_ptr->h_ver_extra = rd_byte();
29         strip_bytes(1);
30     } else if (is_old_ver) {
31         strip_bytes(3);
32     } else {
33         throw("Invalid version is detected!");
34     }
35
36     load_xor_byte = w_ptr->sf_extra;
37     v_check = 0L;
38     x_check = 0L;
39
40     if (is_old_ver) {
41         /* Old savefile will be version 0.0.0.3 */
42         w_ptr->h_ver_extra = rd_byte();
43         w_ptr->h_ver_patch = rd_byte();
44         w_ptr->h_ver_minor = rd_byte();
45         w_ptr->h_ver_major = rd_byte();
46     }
47
48     w_ptr->sf_system = rd_u32b();
49     w_ptr->sf_when = rd_u32b();
50     w_ptr->sf_lives = rd_u16b();
51     w_ptr->sf_saves = rd_u16b();
52
53     loading_savefile_version = rd_u32b();
54
55     /* h_ver_majorがfake_ver_majorと同じだったころへの対策 */
56     if (loading_savefile_version_is_older_than(10)) {
57         constexpr auto fake_ver_plus = 10;
58         if (tmp_major - w_ptr->h_ver_major < fake_ver_plus) {
59             w_ptr->h_ver_major -= fake_ver_plus;
60         }
61     }
62
63     load_note(format(_("バージョン %d.%d.%d のセーブデータ(SAVE%lu形式)をロード中...", "Loading a Verison %d.%d.%d savefile (SAVE%lu format)..."),
64         w_ptr->h_ver_major, w_ptr->h_ver_minor, w_ptr->h_ver_patch,
65         loading_savefile_version));
66 }
67
68 /*!
69  * @brief 乱数状態を読み込む / Read RNG state (added in 2.8.0)
70  */
71 void rd_randomizer(void)
72 {
73     strip_bytes(4);
74
75     Xoshiro128StarStar::state_type state;
76     for (auto &s : state) {
77         s = rd_u32b();
78     }
79     w_ptr->rng.set_state(state);
80
81     strip_bytes(4 * (RAND_DEG - state.size()));
82 }
83
84 /*!
85  * @brief メッセージログを読み込む / Read the saved messages
86  */
87 void rd_messages(void)
88 {
89     if (h_older_than(2, 2, 0, 75)) {
90         auto num = rd_u16b();
91         int message_max;
92         message_max = (int)num;
93
94         for (int i = 0; i < message_max; i++) {
95             char buf[128];
96             rd_string(buf, sizeof(buf));
97             message_add(buf);
98         }
99     }
100
101     auto num = rd_u32b();
102     int message_max = (int)num;
103     for (int i = 0; i < message_max; i++) {
104         char buf[128];
105         rd_string(buf, sizeof(buf));
106         message_add(buf);
107     }
108 }
109
110 void rd_system_info(void)
111 {
112     kanji_code = rd_byte();
113     rd_randomizer();
114     load_note(_("乱数情報をロードしました", "Loaded Randomizer Info"));
115     rd_options();
116     load_note(_("オプションをロードしました", "Loaded Option Flags"));
117     rd_messages();
118     load_note(_("メッセージをロードしました", "Loaded Messages"));
119 }