OSDN Git Service

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