1 #include "info-reader/general-parser.h"
2 #include "dungeon/quest.h"
3 #include "grid/feature.h"
4 #include "info-reader/feature-reader.h"
5 #include "info-reader/parse-error-types.h"
6 #include "info-reader/random-grid-effect-types.h"
7 #include "io/tokenizer.h"
8 #include "main/angband-headers.h"
9 #include "object-enchant/trg-types.h"
10 #include "object/object-kind-hook.h"
11 #include "realm/realm-types.h"
12 #include "system/artifact-type-definition.h"
13 #include "system/building-type-definition.h"
14 #include "system/floor-type-definition.h"
15 #include "system/system-variables.h"
16 #include "util/angband-files.h"
17 #include "util/string-processor.h"
19 dungeon_grid letter[255];
22 * @brief パース関数に基づいてデータファイルからデータを読み取る /
23 * Initialize an "*_info" array, by parsing an ascii "template" file
24 * @param fp 読み取りに使うファイルポインタ
25 * @param buf 読み取りに使うバッファ領域
27 * @param parse_info_txt_line パース関数
30 errr init_info_txt(FILE *fp, char *buf, angband_header *head, parse_info_txt_func parse_info_txt_line)
40 while (angband_fgets(fp, buf, 1024) == 0) {
42 if (!buf[0] || (buf[0] == '#'))
46 return (PARSE_ERROR_GENERIC);
52 if (buf[0] != 'N' && buf[0] != 'D') {
54 for (i = 0; buf[i]; i++) {
55 head->v_extra += (byte)buf[i];
56 head->v_extra ^= (1 << (i % 8));
60 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
73 * @brief 地形情報の「F:」情報をパースする
74 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
75 * @param floor_ptr 現在フロアへの参照ポインタ
79 errr parse_line_feature(floor_type *floor_ptr, char *buf)
81 if (init_flags & INIT_ONLY_BUILDINGS)
85 int num = tokenize(buf + 2, 9, zz, 0);
90 letter[index].feature = feat_none;
91 letter[index].monster = 0;
92 letter[index].object = 0;
93 letter[index].ego = 0;
94 letter[index].artifact = 0;
95 letter[index].trap = feat_none;
96 letter[index].cave_info = 0;
97 letter[index].special = 0;
98 letter[index].random = RANDOM_NONE;
102 letter[index].special = (s16b)atoi(zz[8]);
105 if ((zz[7][0] == '*') && !zz[7][1]) {
106 letter[index].random |= RANDOM_TRAP;
108 letter[index].trap = f_tag_to_index(zz[7]);
109 if (letter[index].trap < 0)
110 return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
114 if (zz[6][0] == '*') {
115 letter[index].random |= RANDOM_ARTIFACT;
117 letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6] + 1);
118 } else if (zz[6][0] == '!') {
119 if (floor_ptr->inside_quest) {
120 letter[index].artifact = quest[floor_ptr->inside_quest].k_idx;
123 letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6]);
127 if (zz[5][0] == '*') {
128 letter[index].random |= RANDOM_EGO;
130 letter[index].ego = (EGO_IDX)atoi(zz[5] + 1);
132 letter[index].ego = (EGO_IDX)atoi(zz[5]);
136 if (zz[4][0] == '*') {
137 letter[index].random |= RANDOM_OBJECT;
139 letter[index].object = (OBJECT_IDX)atoi(zz[4] + 1);
140 } else if (zz[4][0] == '!') {
141 if (floor_ptr->inside_quest) {
142 ARTIFACT_IDX a_idx = quest[floor_ptr->inside_quest].k_idx;
144 artifact_type *a_ptr = &a_info[a_idx];
145 if (!(a_ptr->gen_flags & TRG_INSTA_ART)) {
146 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
151 letter[index].object = (OBJECT_IDX)atoi(zz[4]);
155 if (zz[3][0] == '*') {
156 letter[index].random |= RANDOM_MONSTER;
158 letter[index].monster = (MONSTER_IDX)atoi(zz[3] + 1);
159 } else if (zz[3][0] == 'c') {
161 return PARSE_ERROR_GENERIC;
162 letter[index].monster = -atoi(zz[3] + 1);
164 letter[index].monster = (MONSTER_IDX)atoi(zz[3]);
168 letter[index].cave_info = atoi(zz[2]);
171 if ((zz[1][0] == '*') && !zz[1][1]) {
172 letter[index].random |= RANDOM_FEATURE;
174 letter[index].feature = f_tag_to_index(zz[1]);
175 if (letter[index].feature < 0)
176 return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
186 * @brief 地形情報の「B:」情報をパースする
187 * Process "B:<Index>:<Command>:..." -- Building definition
191 errr parse_line_building(char *buf)
206 s = angband_strchr(s, ':');
216 if (tokenize(s + 2, 3, zz, 0) == 3) {
217 strcpy(building[index].name, zz[0]);
218 strcpy(building[index].owner_name, zz[1]);
219 strcpy(building[index].owner_race, zz[2]);
223 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
226 if (tokenize(s + 2, 8, zz, 0) >= 7) {
227 int action_index = atoi(zz[0]);
228 strcpy(building[index].act_names[action_index], zz[1]);
229 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
230 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
231 building[index].letters[action_index] = zz[4][0];
232 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
233 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
237 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
241 n = tokenize(s + 2, MAX_CLASS, zz, 0);
242 for (int i = 0; i < MAX_CLASS; i++) {
243 building[index].member_class[i] = ((i < n) ? (player_class_type)atoi(zz[i]) : 1);
250 n = tokenize(s + 2, MAX_RACES, zz, 0);
251 for (int i = 0; i < MAX_RACES; i++) {
252 building[index].member_race[i] = ((i < n) ? (player_race_type)atoi(zz[i]) : 1);
259 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
260 for (int i = 0; i < MAX_MAGIC; i++) {
261 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
270 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);