OSDN Git Service

[Refactor] #1752 PlayerClassTypeをenumからenum classへ変更した
[hengbandforosx/hengbandosx.git] / src / main / info-initializer.cpp
1 /*!
2  * @file info-initializer.cpp
3  * @brief 変愚蛮怒のゲームデータ解析処理定義
4  */
5
6 #include "main/info-initializer.h"
7 #include "dungeon/dungeon.h"
8 #include "grid/feature.h"
9 #include "info-reader/artifact-reader.h"
10 #include "info-reader/dungeon-reader.h"
11 #include "info-reader/ego-reader.h"
12 #include "info-reader/feature-reader.h"
13 #include "info-reader/fixed-map-parser.h"
14 #include "info-reader/general-parser.h"
15 #include "info-reader/info-reader-util.h"
16 #include "info-reader/kind-reader.h"
17 #include "info-reader/magic-reader.h"
18 #include "info-reader/race-reader.h"
19 #include "info-reader/skill-reader.h"
20 #include "info-reader/vault-reader.h"
21 #include "io/files-util.h"
22 #include "io/uid-checker.h"
23 #include "main/angband-headers.h"
24 #include "main/init-error-messages-table.h"
25 #include "monster-race/monster-race.h"
26 #include "object-enchant/object-ego.h"
27 #include "object/object-kind.h"
28 #include "player-info/class-info.h"
29 #include "player/player-skill.h"
30 #include "room/rooms-vault.h"
31 #include "system/angband-version.h"
32 #include "system/artifact-type-definition.h"
33 #include "system/monster-race-definition.h"
34 #include "system/player-type-definition.h"
35 #include "util/angband-files.h"
36 #include "view/display-messages.h"
37 #include "world/world.h"
38 #include <sys/stat.h>
39 #ifndef WINDOWS
40 #include <sys/types.h>
41 #endif
42 #include <string_view>
43
44 /*!
45  * @brief 基本情報読み込みのメインルーチン /
46  * Initialize misc. values
47  * @param player_ptr プレイヤーへの参照ポインタ
48  * @return エラーコード
49  */
50 errr init_misc(player_type *player_ptr)
51 {
52     return parse_fixed_map(player_ptr, "misc.txt", 0, 0, 0, 0);
53 }
54
55 /*!
56  * @brief ヘッダ構造体の更新
57  * Initialize the header of an *_info.raw file.
58  * @param head rawファイルのヘッダ
59  * @param num データ数
60  * @param len データの長さ
61  * @return エラーコード
62  */
63 static void init_header(angband_header *head, IDX num = 0)
64 {
65     head->checksum = 0;
66     head->info_num = (IDX)num;
67 }
68
69 /*!
70  * @brief 各種設定データをlib/edit/のテキストから読み込み
71  * Initialize the "*_info" array
72  * @param filename ファイル名(拡張子txt)
73  * @param head 処理に用いるヘッダ構造体
74  * @param info データ保管先の構造体ポインタ
75  * @return エラーコード
76  * @note
77  * Note that we let each entry have a unique "name" and "text" string,
78  * even if the string happens to be empty (everyone has a unique '\0').
79  */
80 template <typename InfoType>
81 static errr init_info(concptr filename, angband_header &head, std::vector<InfoType> &info, std::function<errr(std::string_view, angband_header *)> parser,
82     void (*retouch)(angband_header *head))
83 {
84     char buf[1024];
85     path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
86
87     FILE *fp = angband_fopen(buf, "r");
88
89     if (!fp)
90         quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
91
92     info = std::vector<InfoType>(head.info_num);
93
94     errr err = init_info_txt(fp, buf, &head, parser);
95     angband_fclose(fp);
96
97     if (err) {
98         concptr oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : _("未知の", "unknown"));
99 #ifdef JP
100         msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
101 #else
102         msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
103 #endif
104         msg_format(_("レコード %d は '%s' エラーがあります。", "Record %d contains a '%s' error."), error_idx, oops);
105         msg_format(_("構文 '%s'。", "Parsing '%s'."), buf);
106         msg_print(nullptr);
107         quit(format(_("'%s.txt'ファイルにエラー", "Error in '%s.txt' file."), filename));
108     }
109
110     info.shrink_to_fit();
111     head.info_num = static_cast<uint16_t>(info.size());
112
113     if (retouch)
114         (*retouch)(&head);
115
116     return 0;
117 }
118
119 /*!
120  * @brief 地形情報読み込みのメインルーチン /
121  * Initialize the "f_info" array
122  * @return エラーコード
123  */
124 errr init_f_info()
125 {
126     init_header(&f_head);
127     return init_info("f_info", f_head, f_info, parse_f_info, retouch_f_info);
128 }
129
130 /*!
131  * @brief ベースアイテム情報読み込みのメインルーチン /
132  * Initialize the "k_info" array
133  * @return エラーコード
134  */
135 errr init_k_info()
136 {
137     init_header(&k_head);
138     return init_info("k_info", k_head, k_info, parse_k_info, nullptr);
139 }
140
141 /*!
142  * @brief 固定アーティファクト情報読み込みのメインルーチン /
143  * Initialize the "a_info" array
144  * @return エラーコード
145  */
146 errr init_a_info()
147 {
148     init_header(&a_head);
149     return init_info("a_info", a_head, a_info, parse_a_info, nullptr);
150 }
151
152 /*!
153  * @brief 固定アーティファクト情報読み込みのメインルーチン /
154  * Initialize the "e_info" array
155  * @return エラーコード
156  */
157 errr init_e_info()
158 {
159     init_header(&e_head);
160     return init_info("e_info", e_head, e_info, parse_e_info, nullptr);
161 }
162
163 /*!
164  * @brief モンスター種族情報読み込みのメインルーチン /
165  * Initialize the "r_info" array
166  * @return エラーコード
167  */
168 errr init_r_info()
169 {
170     init_header(&r_head);
171     return init_info("r_info", r_head, r_info, parse_r_info, nullptr);
172 }
173
174 /*!
175  * @brief ダンジョン情報読み込みのメインルーチン /
176  * Initialize the "d_info" array
177  * @return エラーコード
178  */
179 errr init_d_info()
180 {
181     init_header(&d_head);
182     return init_info("d_info", d_head, d_info, parse_d_info, nullptr);
183 }
184
185 /*!
186  * @brief Vault情報読み込みのメインルーチン /
187  * Initialize the "v_info" array
188  * @return エラーコード
189  * @note
190  * Note that we let each entry have a unique "name" and "text" string,
191  * even if the string happens to be empty (everyone has a unique '\0').
192  */
193 errr init_v_info()
194 {
195     init_header(&v_head);
196     return init_info("v_info", v_head, v_info, parse_v_info, nullptr);
197 }
198
199 /*!
200  * @brief 職業技能情報読み込みのメインルーチン /
201  * Initialize the "s_info" array
202  * @return エラーコード
203  */
204 errr init_s_info()
205 {
206     init_header(&s_head, enum2i(PlayerClassType::MAX));
207     return init_info("s_info", s_head, s_info, parse_s_info, nullptr);
208 }
209
210 /*!
211  * @brief 職業魔法情報読み込みのメインルーチン /
212  * Initialize the "m_info" array
213  * @return エラーコード
214  */
215 errr init_m_info()
216 {
217     init_header(&m_head, enum2i(PlayerClassType::MAX));
218     return init_info("m_info", m_head, m_info, parse_m_info, nullptr);
219 }