OSDN Git Service

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