OSDN Git Service

[Feature] *_infoのname、text、tagをstd::stringにする
[hengbandforosx/hengbandosx.git] / src / info-reader / artifact-reader.cpp
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 #include <string>
10
11 /*!
12  * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
13  * Grab one activation index flag
14  * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
15  * @param what 参照元の文字列ポインタ
16  * @return エラーがあった場合1、エラーがない場合0を返す
17  */
18 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
19 {
20     for (int i = 0; i < TR_FLAG_MAX; i++) {
21         if (streq(what, k_info_flags[i])) {
22             add_flag(a_ptr->flags, i);
23             return 0;
24         }
25     }
26
27     if (FlagGroup<TRG>::grab_one_flag(a_ptr->gen_flags, k_info_gen_flags, what))
28         return 0;
29
30     msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
31     return 1;
32 }
33
34 /*!
35  * @brief 固定アーティファクト情報(a_info)のパース関数 /
36  * Initialize the "a_info" array, by parsing an ascii "template" file
37  * @param buf テキスト列
38  * @param head ヘッダ構造体
39  * @return エラーコード
40  */
41 errr parse_a_info(char *buf, angband_header *head)
42 {
43     static artifact_type *a_ptr = NULL;
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         a_ptr = &a_info[i];
63         add_flag(a_ptr->flags, TR_IGNORE_ACID);
64         add_flag(a_ptr->flags, TR_IGNORE_ELEC);
65         add_flag(a_ptr->flags, TR_IGNORE_FIRE);
66         add_flag(a_ptr->flags, TR_IGNORE_COLD);
67 #ifdef JP
68         a_ptr->name = std::string(s);
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         a_ptr->name = std::string(s);
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         a_ptr->text.append(s);
96     } else if (buf[0] == 'I') {
97         int tval, sval, pval;
98         if (3 != sscanf(buf + 2, "%d:%d:%d", &tval, &sval, &pval))
99             return 1;
100
101         a_ptr->tval = (tval_type)tval;
102         a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
103         a_ptr->pval = (PARAMETER_VALUE)pval;
104     } else if (buf[0] == 'W') {
105         int level, rarity, wgt;
106         long cost;
107         if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &wgt, &cost))
108             return 1;
109
110         a_ptr->level = (DEPTH)level;
111         a_ptr->rarity = (RARITY)rarity;
112         a_ptr->weight = (WEIGHT)wgt;
113         a_ptr->cost = (PRICE)cost;
114     } else if (buf[0] == 'P') {
115         int ac, hd1, hd2, th, td, ta;
116         if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", &ac, &hd1, &hd2, &th, &td, &ta))
117             return 1;
118
119         a_ptr->ac = (ARMOUR_CLASS)ac;
120         a_ptr->dd = (DICE_NUMBER)hd1;
121         a_ptr->ds = (DICE_SID)hd2;
122         a_ptr->to_h = (HIT_PROB)th;
123         a_ptr->to_d = (HIT_POINT)td;
124         a_ptr->to_a = (ARMOUR_CLASS)ta;
125     } else if (buf[0] == 'U') {
126         byte n;
127         n = grab_one_activation_flag(buf + 2);
128         if (n > 0) {
129             a_ptr->act_idx = n;
130         } else {
131             return 5;
132         }
133     } else if (buf[0] == 'F') {
134         for (s = buf + 2; *s;) {
135             /* loop */
136             for (t = s; *t && (*t != ' ') && (*t != '|'); ++t)
137                 ;
138
139             if (*t) {
140                 *t++ = '\0';
141                 while ((*t == ' ') || (*t == '|'))
142                     t++;
143             }
144
145             if (0 != grab_one_artifact_flag(a_ptr, s))
146                 return 5;
147
148             s = t;
149         }
150     } else {
151         return 6;
152     }
153
154     return 0;
155 }