OSDN Git Service

Merge remote-tracking branch 'remotes/origin/For2.2.2-Fix-Hourier' into For2.2.2...
[hengband/hengband.git] / src / info-reader / artifact-reader.c
1 #include "info-reader/artifact-reader.h"
2 #include "info-reader/kind-info-tokens-table.h"
3 #include "object-enchant/artifact.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 activation index flag
12  * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
13  * @param what 参照元の文字列ポインタ
14  * @return エラーがあった場合1、エラーがない場合0を返す
15  */
16 static errr grab_one_artifact_flag(artifact_type *a_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(a_ptr->flags, i);
21             return 0;
22         }
23     }
24
25     if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
26         return 0;
27
28     msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
29     return 1;
30 }
31
32 /*!
33  * @brief 固定アーティファクト情報(a_info)のパース関数 /
34  * Initialize the "a_info" array, by parsing an ascii "template" file
35  * @param buf テキスト列
36  * @param head ヘッダ構造体
37  * @return エラーコード
38  */
39 errr parse_a_info(char *buf, angband_header *head)
40 {
41     static artifact_type *a_ptr = NULL;
42     char *s, *t;
43     if (buf[0] == 'N') {
44         s = angband_strchr(buf + 2, ':');
45         if (!s)
46             return 1;
47
48         *s++ = '\0';
49 #ifdef JP
50         if (!*s)
51             return 1;
52 #endif
53         int i = atoi(buf + 2);
54         if (i < error_idx)
55             return 4;
56         if (i >= head->info_num)
57             return 2;
58
59         error_idx = i;
60         a_ptr = &a_info[i];
61         add_flag(a_ptr->flags, TR_IGNORE_ACID);
62         add_flag(a_ptr->flags, TR_IGNORE_ELEC);
63         add_flag(a_ptr->flags, TR_IGNORE_FIRE);
64         add_flag(a_ptr->flags, TR_IGNORE_COLD);
65 #ifdef JP
66         if (!add_name(&a_ptr->name, head, s))
67             return 7;
68 #endif
69     } else if (!a_ptr) {
70         return 3;
71     }
72 #ifdef JP
73     /* 英語名を読むルーチンを追加 */
74     /* 'E' から始まる行は英語名としている */
75     else if (buf[0] == 'E') {
76         /* nothing to do */
77     }
78 #else
79     else if (buf[0] == 'E') {
80         s = buf + 2;
81         if (!add_name(&a_ptr->name, head, s))
82             return 7;
83     }
84 #endif
85     else if (buf[0] == 'D') {
86 #ifdef JP
87         if (buf[2] == '$')
88             return 0;
89         s = buf + 2;
90 #else
91         if (buf[2] != '$')
92             return 0;
93         s = buf + 3;
94 #endif
95         if (!add_text(&a_ptr->text, head, s, TRUE))
96             return 7;
97     } else if (buf[0] == 'I') {
98         int tval, sval, pval;
99         if (3 != sscanf(buf + 2, "%d:%d:%d", &tval, &sval, &pval))
100             return 1;
101
102         a_ptr->tval = (tval_type)tval;
103         a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
104         a_ptr->pval = (PARAMETER_VALUE)pval;
105     } else if (buf[0] == 'W') {
106         int level, rarity, wgt;
107         long cost;
108         if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &wgt, &cost))
109             return 1;
110
111         a_ptr->level = (DEPTH)level;
112         a_ptr->rarity = (RARITY)rarity;
113         a_ptr->weight = (WEIGHT)wgt;
114         a_ptr->cost = (PRICE)cost;
115     } else if (buf[0] == 'P') {
116         int ac, hd1, hd2, th, td, ta;
117         if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", &ac, &hd1, &hd2, &th, &td, &ta))
118             return 1;
119
120         a_ptr->ac = (ARMOUR_CLASS)ac;
121         a_ptr->dd = (DICE_NUMBER)hd1;
122         a_ptr->ds = (DICE_SID)hd2;
123         a_ptr->to_h = (HIT_PROB)th;
124         a_ptr->to_d = (HIT_POINT)td;
125         a_ptr->to_a = (ARMOUR_CLASS)ta;
126     } else if (buf[0] == 'U') {
127         byte n;
128         n = grab_one_activation_flag(buf + 2);
129         if (n > 0) {
130             a_ptr->act_idx = n;
131         } else {
132             return 5;
133         }
134     } else if (buf[0] == 'F') {
135         for (s = buf + 2; *s;) {
136             /* loop */
137             for (t = s; *t && (*t != ' ') && (*t != '|'); ++t)
138                 ;
139
140             if (*t) {
141                 *t++ = '\0';
142                 while ((*t == ' ') || (*t == '|'))
143                     t++;
144             }
145
146             if (0 != grab_one_artifact_flag(a_ptr, s))
147                 return 5;
148
149             s = t;
150         }
151     } else {
152         return 6;
153     }
154
155     return 0;
156 }