OSDN Git Service

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