OSDN Git Service

[Refactor] #40483 Removed the inclusion of grid.h from rooms.h
[hengbandforosx/hengbandosx.git] / src / info-reader / ego-reader.c
1 #include "info-reader/ego-reader.h"
2 #include "info-reader/kind-info-tokens-table.h"
3 #include "object-enchant/object-ego.h"
4 #include "object-enchant/tr-types.h"
5 #include "util/bit-flags-calculator.h"
6 #include "util/string-processor.h"
7 #include "view/display-messages.h"
8
9 /*!
10  * @brief テキストトークンを走査してフラグを一つ得る(エゴ用) /
11  * Grab one flag in a ego-item_type from a textual string
12  * @param e_ptr 保管先のエゴ構造体参照ポインタ
13  * @param what 参照元の文字列ポインタ
14  * @return エラーがあった場合1、エラーがない場合0を返す
15  */
16 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
17 {
18     for (int i = 0; i < TR_FLAG_MAX; i++) {
19         if (streq(what, k_info_flags[i])) {
20             add_flag(e_ptr->flags, i);
21             return 0;
22         }
23     }
24
25     if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
26         return 0;
27
28     msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
29     return 1;
30 }
31
32 /*!
33  * @brief アイテムエゴ情報(e_info)のパース関数 /
34  * Initialize the "e_info" array, by parsing an ascii "template" file
35  * @param buf テキスト列
36  * @param head ヘッダ構造体
37  * @return エラーコード
38  */
39 errr parse_e_info(char *buf, angband_header *head)
40 {
41     static ego_item_type *e_ptr = NULL;
42     error_idx = -1;
43     error_line = -1;
44     char *s, *t;
45     if (buf[0] == 'N') {
46         s = angband_strchr(buf + 2, ':');
47         if (!s)
48             return 1;
49
50         *s++ = '\0';
51 #ifdef JP
52         if (!*s)
53             return 1;
54 #endif
55         int i = atoi(buf + 2);
56         if (i < error_idx)
57             return 4;
58         if (i >= head->info_num)
59             return 2;
60
61         error_idx = i;
62         e_ptr = &e_info[i];
63 #ifdef JP
64         if (!add_name(&e_ptr->name, head, s))
65             return 7;
66 #endif
67     } else if (!e_ptr) {
68         return 3;
69     }
70 #ifdef JP
71     /* 英語名を読むルーチンを追加 */
72     /* 'E' から始まる行は英語名 */
73     else if (buf[0] == 'E') {
74         /* nothing to do */
75     }
76 #else
77     else if (buf[0] == 'E') {
78         s = buf + 2;
79         if (!add_name(&e_ptr->name, head, s))
80             return 7;
81     }
82 #endif
83     else if (buf[0] == 'X') {
84         int slot, rating;
85         if (2 != sscanf(buf + 2, "%d:%d", &slot, &rating))
86             return 1;
87
88         e_ptr->slot = (INVENTORY_IDX)slot;
89         e_ptr->rating = (PRICE)rating;
90     } else if (buf[0] == 'W') {
91         int level, rarity, pad2;
92         long cost;
93
94         if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &pad2, &cost))
95             return 1;
96
97         e_ptr->level = level;
98         e_ptr->rarity = (RARITY)rarity;
99         e_ptr->cost = cost;
100     } else if (buf[0] == 'C') {
101         int th, td, ta, pval;
102
103         if (4 != sscanf(buf + 2, "%d:%d:%d:%d", &th, &td, &ta, &pval))
104             return 1;
105
106         e_ptr->max_to_h = (HIT_PROB)th;
107         e_ptr->max_to_d = (HIT_POINT)td;
108         e_ptr->max_to_a = (ARMOUR_CLASS)ta;
109         e_ptr->max_pval = (PARAMETER_VALUE)pval;
110     } else if (buf[0] == 'U') {
111         byte n;
112         n = grab_one_activation_flag(buf + 2);
113         if (n > 0) {
114             e_ptr->act_idx = n;
115         } else {
116             return 5;
117         }
118     } else if (buf[0] == 'F') {
119         for (s = buf + 2; *s;) {
120             /* loop */
121             for (t = s; *t && (*t != ' ') && (*t != '|'); ++t)
122                 ;
123
124             if (*t) {
125                 *t++ = '\0';
126                 while ((*t == ' ') || (*t == '|'))
127                     t++;
128             }
129
130             if (0 != grab_one_ego_item_flag(e_ptr, s))
131                 return 5;
132
133             s = t;
134         }
135     } else {
136         return 6;
137     }
138
139     return 0;
140 }