OSDN Git Service

Merge pull request #867 from shimitei/feature/refactor_bg_menu
[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     if (k_info_flags.find(what) != k_info_flags.end()) {
21         add_flag(a_ptr->flags, k_info_flags[what]);
22         return 0;
23     }
24
25     if (EnumClassFlagGroup<TRG>::grab_one_flag(a_ptr->gen_flags, k_info_gen_flags, what))
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         a_ptr->name = std::string(s);
67 #endif
68     } else if (!a_ptr) {
69         return 3;
70     }
71 #ifdef JP
72     /* 英語名を読むルーチンを追加 */
73     /* 'E' から始まる行は英語名としている */
74     else if (buf[0] == 'E') {
75         /* nothing to do */
76     }
77 #else
78     else if (buf[0] == 'E') {
79         s = buf + 2;
80         a_ptr->name = std::string(s);
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         a_ptr->text.append(s);
94     } else if (buf[0] == 'I') {
95         int tval, sval, pval;
96         if (3 != sscanf(buf + 2, "%d:%d:%d", &tval, &sval, &pval))
97             return 1;
98
99         a_ptr->tval = (tval_type)tval;
100         a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
101         a_ptr->pval = (PARAMETER_VALUE)pval;
102     } else if (buf[0] == 'W') {
103         int level, rarity, wgt;
104         long cost;
105         if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", &level, &rarity, &wgt, &cost))
106             return 1;
107
108         a_ptr->level = (DEPTH)level;
109         a_ptr->rarity = (RARITY)rarity;
110         a_ptr->weight = (WEIGHT)wgt;
111         a_ptr->cost = (PRICE)cost;
112     } else if (buf[0] == 'P') {
113         int ac, hd1, hd2, th, td, ta;
114         if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", &ac, &hd1, &hd2, &th, &td, &ta))
115             return 1;
116
117         a_ptr->ac = (ARMOUR_CLASS)ac;
118         a_ptr->dd = (DICE_NUMBER)hd1;
119         a_ptr->ds = (DICE_SID)hd2;
120         a_ptr->to_h = (HIT_PROB)th;
121         a_ptr->to_d = (HIT_POINT)td;
122         a_ptr->to_a = (ARMOUR_CLASS)ta;
123     } else if (buf[0] == 'U') {
124         byte n;
125         n = grab_one_activation_flag(buf + 2);
126         if (n > 0) {
127             a_ptr->act_idx = n;
128         } else {
129             return 5;
130         }
131     } else if (buf[0] == 'F') {
132         for (s = buf + 2; *s;) {
133             /* loop */
134             for (t = s; *t && (*t != ' ') && (*t != '|'); ++t)
135                 ;
136
137             if (*t) {
138                 *t++ = '\0';
139                 while ((*t == ' ') || (*t == '|'))
140                     t++;
141             }
142
143             if (0 != grab_one_artifact_flag(a_ptr, s))
144                 return 5;
145
146             s = t;
147         }
148     } else {
149         return 6;
150     }
151
152     return 0;
153 }