OSDN Git Service

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