2 * @file game-data-initializer.cpp
3 * @brief 変愚蛮怒のゲームデータ初期化定義
6 #include "main/game-data-initializer.h"
7 #include "cmd-io/macro-util.h"
8 #include "dungeon/quest.h"
9 #include "floor/floor-util.h"
10 #include "game-option/option-flags.h"
11 #include "game-option/option-types-table.h"
12 #include "monster-race/monster-race.h"
13 #include "system/alloc-entries.h"
14 #include "system/baseitem-info.h"
15 #include "system/dungeon-info.h"
16 #include "system/floor-type-definition.h"
17 #include "system/grid-type-definition.h"
18 #include "system/item-entity.h"
19 #include "system/monster-entity.h"
20 #include "system/monster-race-info.h"
21 #include "system/player-type-definition.h"
22 #include "system/redrawing-flags-updater.h"
23 #include "term/gameterm.h"
24 #include "util/angband-files.h"
25 #include "util/bit-flags-calculator.h"
26 #include "view/display-messages.h"
30 * @brief マクロ登録の最大数 / Maximum number of macros (see "io.c")
31 * @note Default: assume at most 256 macros are used
33 constexpr int MACRO_MAX = 256;
35 static void init_gf_colors()
37 for (auto i = 0; i < enum2i(AttributeType::MAX); i++) {
38 gf_colors.emplace(i2enum<AttributeType>(i), "");
44 * Initialize some other arrays
47 void init_other(PlayerType *player_ptr)
49 player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
50 auto *floor_ptr = player_ptr->current_floor_ptr;
51 floor_ptr->o_list.assign(MAX_FLOOR_ITEMS, {});
52 floor_ptr->m_list.assign(MAX_FLOOR_MONSTERS, {});
53 for (auto &list : floor_ptr->mproc_list) {
54 list.assign(MAX_FLOOR_MONSTERS, {});
57 max_dlv.assign(dungeons_info.size(), {});
58 floor_ptr->grid_array.assign(MAX_HGT, std::vector<Grid>(MAX_WID));
61 macro_patterns.assign(MACRO_MAX, {});
62 macro_actions.assign(MACRO_MAX, {});
63 macro_buffers.assign(FILE_READ_BUFF_SIZE, {});
64 for (auto i = 0; option_info[i].o_desc; i++) {
65 int os = option_info[i].o_set;
66 int ob = option_info[i].o_bit;
67 if (option_info[i].o_var == nullptr) {
71 g_option_masks[os] |= (1UL << ob);
72 if (option_info[i].o_norm) {
73 set_bits(g_option_flags[os], 1U << ob);
75 reset_bits(g_option_flags[os], 1U << ob);
79 for (auto &window_mask : g_window_masks) {
80 for (auto i = 0; i < 32; i++) {
81 if (window_flag_desc[i]) {
82 window_mask.set(i2enum<SubWindowRedrawingFlag>(i));
87 g_window_flags[1].clear();
88 g_window_flags[1].set(SubWindowRedrawingFlag::MESSAGE);
89 g_window_flags[2].clear();
90 g_window_flags[2].set(SubWindowRedrawingFlag::INVENTORY);
94 * @brief モンスター生成テーブルを初期化する
96 void init_monsters_alloc()
98 std::vector<const MonsterRaceInfo *> elements;
99 for (const auto &[r_idx, r_ref] : monraces_info) {
100 if (MonsterRace(r_ref.idx).is_valid()) {
101 elements.push_back(&r_ref);
105 std::sort(elements.begin(), elements.end(),
106 [](const MonsterRaceInfo *r1_ptr, const MonsterRaceInfo *r2_ptr) {
107 return r1_ptr->level < r2_ptr->level;
110 alloc_race_table.clear();
111 for (const auto r_ptr : elements) {
112 if (r_ptr->rarity == 0) {
116 const auto index = static_cast<short>(r_ptr->idx);
117 const auto level = r_ptr->level;
118 const auto prob = static_cast<PROB>(100 / r_ptr->rarity);
119 alloc_race_table.push_back({ index, level, prob, prob });
124 * @brief アイテム生成テーブルを初期化する
126 void init_items_alloc()
128 short num[MAX_DEPTH]{};
129 auto alloc_kind_size = 0;
130 for (const auto &baseitem : baseitems_info) {
131 for (const auto &[level, chance] : baseitem.alloc_tables) {
139 for (auto i = 1; i < MAX_DEPTH; i++) {
140 num[i] += num[i - 1];
144 quit(_("町のアイテムがない!", "No town objects!"));
147 alloc_kind_table.assign(alloc_kind_size, {});
148 short aux[MAX_DEPTH]{};
149 for (const auto &baseitem : baseitems_info) {
150 for (const auto &[level, chance] : baseitem.alloc_tables) {
155 const auto x = level;
156 const short p = 100 / chance;
157 const auto y = (x > 0) ? num[x - 1] : 0;
158 const auto z = y + aux[x];
159 alloc_kind_table[z].index = baseitem.idx;
160 alloc_kind_table[z].level = x;
161 alloc_kind_table[z].prob1 = p;
162 alloc_kind_table[z].prob2 = p;