OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[hengbandforosx/hengbandosx.git] / src / load / option-loader.cpp
1 #include "load/option-loader.h"
2 #include "cmd-io/cmd-gameoption.h"
3 #include "game-option/cheat-options.h"
4 #include "game-option/option-flags.h"
5 #include "game-option/special-options.h"
6 #include "load/angband-version-comparer.h"
7 #include "load/load-util.h"
8 #include "load/load-zangband.h"
9 #include "system/angband.h"
10 #include "util/bit-flags-calculator.h"
11 #include "world/world.h"
12
13 /*!
14  * @brief ゲームオプションを読み込む / Read options (ignore most pre-2.8.0 options)
15  * @details
16  * Note that the normal options are now stored as a set of 256 bit flags,
17  * plus a set of 256 bit masks to indicate which bit flags were defined
18  * at the time the savefile was created.  This will allow new options
19  * to be added, and old options to be removed, at any time, without
20  * hurting old savefiles.
21  *
22  * The window options are stored in the same way, but note that each
23  * window gets 32 options, and their order is fixed by certain defines.
24  */
25 void rd_options()
26 {
27     strip_bytes(16);
28
29     if (loading_savefile_version_is_older_than(9)) {
30         auto b = rd_byte();
31         delay_factor = b * b * b;
32     } else {
33         delay_factor = rd_s32b();
34     }
35
36     hitpoint_warn = rd_byte();
37
38     if (h_older_than(1, 7, 0, 0)) {
39         mana_warn = 2;
40     } else {
41         mana_warn = rd_byte();
42     }
43
44     auto c = rd_u16b();
45
46     if (c & 0x0002) {
47         w_ptr->wizard = true;
48     }
49
50     cheat_peek = any_bits(c, 0x0100);
51     cheat_hear = any_bits(c, 0x0200);
52     cheat_room = any_bits(c, 0x0400);
53     cheat_xtra = any_bits(c, 0x0800);
54     cheat_know = any_bits(c, 0x1000);
55     cheat_live = any_bits(c, 0x2000);
56     cheat_save = any_bits(c, 0x4000);
57     cheat_diary_output = any_bits(c, 0x8000);
58     cheat_turn = any_bits(c, 0x0080);
59     cheat_sight = any_bits(c, 0x0040);
60     cheat_immortal = any_bits(c, 0x0020);
61
62     autosave_l = rd_bool();
63     autosave_t = rd_bool();
64     autosave_freq = rd_s16b();
65
66     uint32_t flag[8]{};
67     for (auto n = 0; n < MAX_WINDOW_ENTITIES; n++) {
68         flag[n] = rd_u32b();
69     }
70
71     uint32_t mask[8]{};
72     for (auto n = 0; n < MAX_WINDOW_ENTITIES; n++) {
73         mask[n] = rd_u32b();
74     }
75
76     for (auto n = 0; n < MAX_WINDOW_ENTITIES; n++) {
77         for (auto i = 0; i < 32; i++) {
78             if (none_bits(mask[n], 1U << i) || none_bits(g_option_masks[n], 1U << i)) {
79                 continue;
80             }
81
82             auto &option_flag = g_option_flags[n];
83             if (flag[n] & (1UL << i)) {
84                 option_flag |= (1UL << i);
85             } else {
86                 option_flag &= ~(1UL << i);
87             }
88         }
89     }
90
91     if (h_older_than(0, 4, 5)) {
92         load_zangband_options();
93     }
94
95     extract_option_vars();
96
97     decltype(g_window_flags) savefile_window_flags;
98     for (auto &window_flag : savefile_window_flags) {
99         rd_FlagGroup_bytes(window_flag, rd_byte, 4);
100     }
101
102     decltype(g_window_masks) savefile_window_masks;
103     for (auto &window_mask : savefile_window_masks) {
104         rd_FlagGroup_bytes(window_mask, rd_byte, 4);
105     }
106
107     for (auto n = 0; n < MAX_WINDOW_ENTITIES; n++) {
108         const auto window_mask = g_window_masks[n] & savefile_window_masks[n];
109         g_window_flags[n] = savefile_window_flags[n] & window_mask;
110     }
111 }