OSDN Git Service

[Refactor] #1489 Moved player-class.* and player-class-types.h to player-info/
[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)
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     if (retouch)
111         (*retouch)(&head);
112
113     return 0;
114 }
115
116 /*!
117  * @brief 地形情報読み込みのメインルーチン /
118  * Initialize the "f_info" array
119  * @return エラーコード
120  */
121 errr init_f_info()
122 {
123     init_header(&f_head, max_f_idx);
124     return init_info("f_info", f_head, f_info, parse_f_info, retouch_f_info);
125 }
126
127 /*!
128  * @brief ベースアイテム情報読み込みのメインルーチン /
129  * Initialize the "k_info" array
130  * @return エラーコード
131  */
132 errr init_k_info()
133 {
134     init_header(&k_head, max_k_idx);
135     return init_info("k_info", k_head, k_info, parse_k_info, nullptr);
136 }
137
138 /*!
139  * @brief 固定アーティファクト情報読み込みのメインルーチン /
140  * Initialize the "a_info" array
141  * @return エラーコード
142  */
143 errr init_a_info()
144 {
145     init_header(&a_head, max_a_idx);
146     return init_info("a_info", a_head, a_info, parse_a_info, nullptr);
147 }
148
149 /*!
150  * @brief 固定アーティファクト情報読み込みのメインルーチン /
151  * Initialize the "e_info" array
152  * @return エラーコード
153  */
154 errr init_e_info()
155 {
156     init_header(&e_head, max_e_idx);
157     return init_info("e_info", e_head, e_info, parse_e_info, nullptr);
158 }
159
160 /*!
161  * @brief モンスター種族情報読み込みのメインルーチン /
162  * Initialize the "r_info" array
163  * @return エラーコード
164  */
165 errr init_r_info()
166 {
167     init_header(&r_head, max_r_idx);
168     return init_info("r_info", r_head, r_info, parse_r_info, nullptr);
169 }
170
171 /*!
172  * @brief ダンジョン情報読み込みのメインルーチン /
173  * Initialize the "d_info" array
174  * @return エラーコード
175  */
176 errr init_d_info()
177 {
178     init_header(&d_head, current_world_ptr->max_d_idx);
179     return init_info("d_info", d_head, d_info, parse_d_info, nullptr);
180 }
181
182 /*!
183  * @brief Vault情報読み込みのメインルーチン /
184  * Initialize the "v_info" array
185  * @return エラーコード
186  * @note
187  * Note that we let each entry have a unique "name" and "text" string,
188  * even if the string happens to be empty (everyone has a unique '\0').
189  */
190 errr init_v_info()
191 {
192     init_header(&v_head, max_v_idx);
193     return init_info("v_info", v_head, v_info, parse_v_info, nullptr);
194 }
195
196 /*!
197  * @brief 職業技能情報読み込みのメインルーチン /
198  * Initialize the "s_info" array
199  * @return エラーコード
200  */
201 errr init_s_info()
202 {
203     init_header(&s_head, MAX_CLASS);
204     return init_info("s_info", s_head, s_info, parse_s_info, nullptr);
205 }
206
207 /*!
208  * @brief 職業魔法情報読み込みのメインルーチン /
209  * Initialize the "m_info" array
210  * @return エラーコード
211  */
212 errr init_m_info()
213 {
214     init_header(&m_head, MAX_CLASS);
215     return init_info("m_info", m_head, m_info, parse_m_info, nullptr);
216 }