OSDN Git Service

[Refactor] #3230 sniper_data_type を構造体からクラスへ変更し、メソッドを追加した
[hengbandforosx/hengbandosx.git] / src / save / info-writer.cpp
1 #include "save/info-writer.h"
2 #include "birth/quick-start.h"
3 #include "game-option/cheat-options.h"
4 #include "game-option/option-flags.h"
5 #include "game-option/option-types-table.h"
6 #include "game-option/special-options.h"
7 #include "player-ability/player-ability-types.h"
8 #include "save/item-writer.h"
9 #include "save/save-util.h"
10 #include "save/save.h"
11 #include "store/store-util.h"
12 #include "system/angband.h"
13 #include "system/item-entity.h"
14 #include "util/enum-converter.h"
15 #include "world/world.h"
16
17 /*!
18  * @brief セーブデータに店舗情報を書き込む / Write a "store" record
19  * @param store_ptr 店舗情報の参照ポインタ
20  */
21 void wr_store(store_type *store_ptr)
22 {
23     wr_u32b(store_ptr->store_open);
24     wr_s16b(store_ptr->insult_cur);
25     wr_byte(store_ptr->owner);
26     wr_s16b(store_ptr->stock_num);
27     wr_s16b(store_ptr->good_buy);
28     wr_s16b(store_ptr->bad_buy);
29     wr_s32b(store_ptr->last_visit);
30     for (int j = 0; j < store_ptr->stock_num; j++) {
31         wr_item(&store_ptr->stock[j]);
32     }
33 }
34
35 /*!
36  * @brief セーブデータに乱数情報を書き込む / Write RNG state
37  * @param なし
38  */
39 void wr_randomizer(void)
40 {
41     wr_u16b(0);
42     wr_u16b(0);
43     const auto &state = w_ptr->rng.get_state();
44     for (const auto s : state) {
45         wr_u32b(s);
46     }
47     for (int i = state.size(); i < RAND_DEG; i++) {
48         wr_u32b(0);
49     }
50 }
51
52 /*!
53  * @brief ゲームオプション情報を書き込む / Write the "options"
54  */
55 void wr_options(SaveType type)
56 {
57     for (int i = 0; i < 4; i++) {
58         wr_u32b(0L);
59     }
60
61     wr_u32b(delay_factor);
62
63     wr_byte(hitpoint_warn);
64     wr_byte(mana_warn);
65
66     /*** Cheating options ***/
67     uint16_t c = 0;
68     if (w_ptr->wizard) {
69         c |= 0x0002;
70     }
71
72     if (cheat_sight) {
73         c |= 0x0040;
74     }
75
76     if (cheat_turn) {
77         c |= 0x0080;
78     }
79
80     if (cheat_peek) {
81         c |= 0x0100;
82     }
83
84     if (cheat_hear) {
85         c |= 0x0200;
86     }
87
88     if (cheat_room) {
89         c |= 0x0400;
90     }
91
92     if (cheat_xtra) {
93         c |= 0x0800;
94     }
95
96     if (cheat_know) {
97         c |= 0x1000;
98     }
99
100     if (cheat_live) {
101         c |= 0x2000;
102     }
103
104     if (cheat_save) {
105         c |= 0x4000;
106     }
107
108     if (cheat_diary_output) {
109         c |= 0x8000;
110     }
111
112     if (cheat_immortal) {
113         c |= 0x0020;
114     }
115
116     if (type == SaveType::DEBUG) {
117         c |= 0xFFFF;
118     }
119
120     wr_u16b(c);
121
122     wr_bool(autosave_l);
123     wr_bool(autosave_t);
124     wr_s16b(autosave_freq);
125
126     for (int i = 0; option_info[i].o_desc; i++) {
127         int os = option_info[i].o_set;
128         int ob = option_info[i].o_bit;
129         if (!option_info[i].o_var) {
130             continue;
131         }
132
133         if (*option_info[i].o_var) {
134             g_option_flags[os] |= (1UL << ob);
135         } else {
136             g_option_flags[os] &= ~(1UL << ob);
137         }
138     }
139
140     for (const auto &option_flag : g_option_flags) {
141         wr_u32b(option_flag);
142     }
143
144     for (const auto &option_mask : g_option_masks) {
145         wr_u32b(option_mask);
146     }
147
148     for (const auto &window_flag : g_window_flags) {
149         wr_FlagGroup_bytes(window_flag, wr_byte, 4);
150     }
151
152     for (const auto &window_mask : g_window_masks) {
153         wr_u32b(window_mask);
154     }
155 }
156
157 /*!
158  * @brief ダミー情報スキップを書き込む / Hack -- Write the "ghost" info
159  */
160 void wr_ghost(void)
161 {
162     wr_string(_("不正なゴースト", "Broken Ghost"));
163     for (int i = 0; i < 60; i++) {
164         wr_byte(0);
165     }
166 }
167
168 /*!
169  * @brief クイック・スタート情報を書き込む / Save quick start data
170  */
171 void save_quick_start(void)
172 {
173     wr_byte(previous_char.psex);
174     wr_byte((byte)previous_char.prace);
175     wr_byte((byte)previous_char.pclass);
176     wr_byte((byte)previous_char.ppersonality);
177     wr_byte((byte)previous_char.realm1);
178     wr_byte((byte)previous_char.realm2);
179
180     wr_s16b(previous_char.age);
181     wr_s16b(previous_char.ht);
182     wr_s16b(previous_char.wt);
183     wr_s16b(previous_char.sc);
184     wr_s32b(previous_char.au);
185
186     for (int i = 0; i < A_MAX; i++) {
187         wr_s16b(previous_char.stat_max[i]);
188     }
189
190     for (int i = 0; i < A_MAX; i++) {
191         wr_s16b(previous_char.stat_max_max[i]);
192     }
193
194     for (int i = 0; i < PY_MAX_LEVEL; i++) {
195         wr_s16b((int16_t)previous_char.player_hp[i]);
196     }
197
198     wr_s16b(previous_char.chaos_patron);
199     for (int i = 0; i < 8; i++) {
200         wr_s16b(enum2i(previous_char.vir_types[i]));
201     }
202
203     for (int i = 0; i < 4; i++) {
204         wr_string(previous_char.history[i]);
205     }
206
207     /* UNUSED : Was number of random quests */
208     wr_byte(0);
209     if (w_ptr->noscore) {
210         previous_char.quick_ok = false;
211     }
212
213     wr_byte((byte)previous_char.quick_ok);
214 }