OSDN Git Service

Merge pull request #2222 from Hourier/Make-Input-Key-Requestor-Class
[hengbandforosx/hengbandosx.git] / src / wizard / artifact-analyzer.cpp
1 #include "wizard/artifact-analyzer.h"
2 #include "flavor/flavor-describer.h"
3 #include "flavor/object-flavor-types.h"
4 #include "locale/japanese.h"
5 #include "object-enchant/object-ego.h"
6 #include "object-enchant/trc-types.h"
7 #include "object-enchant/trg-types.h"
8 #include "object/object-flags.h"
9 #include "object/object-info.h"
10 #include "system/artifact-type-definition.h"
11 #include "system/object-type-definition.h"
12 #include "util/bit-flags-calculator.h"
13 #include "util/enum-range.h"
14 #include "util/quarks.h"
15 #include "wizard/spoiler-util.h"
16
17 /*!
18  * @brief アーティファクトの特性一覧を出力する /
19  * Write a line to the spoiler file and then "underline" it with hypens
20  * @param art_flags アーティファクトのフラグ群
21  * @param flag_ptr フラグ記述情報の参照ポインタ
22  * @param desc_ptr 記述内容を返すための文字列参照ポインタ
23  * @param n_elmnts フラグの要素数
24  * @return desc_ptrと同じアドレス
25  * @details
26  * <pre>
27  * This function does most of the actual "analysis". Given a set of bit flags
28  * (which will be from one of the flags fields from the object in question),
29  * a "flag description structure", a "description list", and the number of
30  * elements in the "flag description structure", this function sets the
31  * "description list" members to the appropriate descriptions contained in
32  * the "flag description structure".
33  * The possibly updated description pointer is returned.
34  * </pre>
35  */
36 static concptr *spoiler_flag_aux(const TrFlags &art_flags, const flag_desc *flag_ptr, concptr *desc_ptr, const int n_elmnts)
37 {
38     for (int i = 0; i < n_elmnts; ++i)
39         if (art_flags.has(flag_ptr[i].flag))
40             *desc_ptr++ = flag_ptr[i].desc;
41
42     return desc_ptr;
43 }
44
45 /*!
46  * @brief アイテムの特定記述内容を返す /
47  * Acquire a "basic" description "The Cloak of Death [1,+10]"
48  * @param o_ptr 記述を得たいオブジェクトの参照ポインタ
49  * @param desc_ptr 記述内容を返すための文字列参照ポインタ
50  */
51 static void analyze_general(PlayerType *player_ptr, ObjectType *o_ptr, char *desc_ptr)
52 {
53     describe_flavor(player_ptr, desc_ptr, o_ptr, OD_NAME_AND_ENCHANT | OD_STORE | OD_DEBUG);
54 }
55
56 /*!
57  * @brief アーティファクトがプレイヤーに与えるpval修正を構造体に収める /
58  * List "player traits" altered by an artifact's pval. These include stats,
59  * speed, infravision, tunneling, stealth, searching, and extra attacks.
60  * @param o_ptr オブジェクト構造体の参照ポインタ
61  * @param pi_ptr pval修正構造体の参照ポインタ
62  */
63 static void analyze_pval(ObjectType *o_ptr, pval_info_type *pi_ptr)
64 {
65     concptr *affects_list;
66     if (!o_ptr->pval) {
67         pi_ptr->pval_desc[0] = '\0';
68         return;
69     }
70
71     auto flgs = object_flags(o_ptr);
72     affects_list = pi_ptr->pval_affects;
73     sprintf(pi_ptr->pval_desc, "%s%d", o_ptr->pval >= 0 ? "+" : "", o_ptr->pval);
74     if (flgs.has_all_of(EnumRange(TR_STR, TR_CHR))) {
75         *affects_list++ = _("全能力", "All stats");
76     } else if (flgs.has_any_of(EnumRange(TR_STR, TR_CHR))) {
77         affects_list = spoiler_flag_aux(flgs, stat_flags_desc, affects_list, N_ELEMENTS(stat_flags_desc));
78     }
79
80     affects_list = spoiler_flag_aux(flgs, pval_flags1_desc, affects_list, N_ELEMENTS(pval_flags1_desc));
81     *affects_list = nullptr;
82 }
83
84 /*!
85  * @brief アーティファクトの種族スレイ特性を構造体に収める /
86  * Note the slaying specialties of a weapon
87  * @param o_ptr オブジェクト構造体の参照ポインタ
88  * @param slay_list 種族スレイ構造体の参照ポインタ
89  */
90 static void analyze_slay(ObjectType *o_ptr, concptr *slay_list)
91 {
92     auto flgs = object_flags(o_ptr);
93     slay_list = spoiler_flag_aux(flgs, slay_flags_desc, slay_list, N_ELEMENTS(slay_flags_desc));
94     *slay_list = nullptr;
95 }
96
97 /*!
98  * @brief アーティファクトの属性ブランド特性を構造体に収める /
99  * Note an object's elemental brands
100  * @param o_ptr オブジェクト構造体の参照ポインタ
101  * @param brand_list 属性ブランド構造体の参照ポインタ
102  */
103 static void analyze_brand(ObjectType *o_ptr, concptr *brand_list)
104 {
105     auto flgs = object_flags(o_ptr);
106     brand_list = spoiler_flag_aux(flgs, brand_flags_desc, brand_list, N_ELEMENTS(brand_flags_desc));
107     *brand_list = nullptr;
108 }
109
110 /*!
111  * @brief アーティファクトの通常耐性を構造体に収める /
112  * Note an object's elemental brands
113  * @param o_ptr オブジェクト構造体の参照ポインタ
114  * @param resist_list 通常耐性構造体の参照ポインタ
115  */
116 static void analyze_resist(ObjectType *o_ptr, concptr *resist_list)
117 {
118     auto flgs = object_flags(o_ptr);
119     resist_list = spoiler_flag_aux(flgs, resist_flags_desc, resist_list, N_ELEMENTS(resist_flags_desc));
120     *resist_list = nullptr;
121 }
122
123 /*!
124  * @brief アーティファクトの免疫特性を構造体に収める /
125  * Note the immunities granted by an object
126  * @param o_ptr オブジェクト構造体の参照ポインタ
127  * @param immune_list 免疫構造体の参照ポインタ
128  */
129 static void analyze_immune(ObjectType *o_ptr, concptr *immune_list)
130 {
131     auto flgs = object_flags(o_ptr);
132     immune_list = spoiler_flag_aux(flgs, immune_flags_desc, immune_list, N_ELEMENTS(immune_flags_desc));
133     *immune_list = nullptr;
134 }
135
136 /*!
137  * @brief アーティファクトの弱点付与を構造体に収める /
138  * Note the immunities granted by an object
139  * @param o_ptr オブジェクト構造体の参照ポインタ
140  * @param immune_list 弱点構造体の参照ポインタ
141  */
142 static void analyze_vulnerable(ObjectType *o_ptr, concptr *vulnerable_list)
143 {
144     auto flgs = object_flags(o_ptr);
145     vulnerable_list = spoiler_flag_aux(flgs, vulnerable_flags_desc, vulnerable_list, N_ELEMENTS(vulnerable_flags_desc));
146     *vulnerable_list = nullptr;
147 }
148
149 /*!
150  * @brief アーティファクトの維持特性を構造体に収める /
151  * Note which stats an object sustains
152  * @param o_ptr オブジェクト構造体の参照ポインタ
153  * @param sustain_list 維持特性構造体の参照ポインタ
154  */
155 static void analyze_sustains(ObjectType *o_ptr, concptr *sustain_list)
156 {
157     auto flgs = object_flags(o_ptr);
158     if (flgs.has_all_of(EnumRange(TR_SUST_STR, TR_SUST_CHR))) {
159         *sustain_list++ = _("全能力", "All stats");
160     } else if (flgs.has_any_of(EnumRange(TR_SUST_STR, TR_SUST_CHR))) {
161         sustain_list = spoiler_flag_aux(flgs, sustain_flags_desc, sustain_list, N_ELEMENTS(sustain_flags_desc));
162     }
163
164     *sustain_list = nullptr;
165 }
166
167 /*!
168  * @brief アーティファクトのその他の特性を構造体に収める /
169  * Note miscellaneous powers bestowed by an artifact such as see invisible,
170  * free action, permanent light, etc.
171  * @param o_ptr オブジェクト構造体の参照ポインタ
172  * @param misc_list その他の特性構造体の参照ポインタ
173  */
174 static void analyze_misc_magic(ObjectType *o_ptr, concptr *misc_list)
175 {
176     char desc[256];
177
178     auto flgs = object_flags(o_ptr);
179     misc_list = spoiler_flag_aux(flgs, misc_flags2_desc, misc_list, N_ELEMENTS(misc_flags2_desc));
180     misc_list = spoiler_flag_aux(flgs, misc_flags3_desc, misc_list, N_ELEMENTS(misc_flags3_desc));
181     POSITION rad = 0;
182     if (flgs.has(TR_LITE_1))
183         rad += 1;
184
185     if (flgs.has(TR_LITE_2))
186         rad += 2;
187
188     if (flgs.has(TR_LITE_3))
189         rad += 3;
190
191     if (flgs.has(TR_LITE_M1))
192         rad -= 1;
193
194     if (flgs.has(TR_LITE_M2))
195         rad -= 2;
196
197     if (flgs.has(TR_LITE_M3))
198         rad -= 3;
199
200     if (o_ptr->name2 == EgoType::LITE_SHINE)
201         rad++;
202
203     if (flgs.has(TR_LITE_FUEL)) {
204         if (rad > 0)
205             sprintf(desc, _("それは燃料補給によって明かり(半径 %d)を授ける。", "It provides light (radius %d) when fueled."), (int)rad);
206     } else {
207         if (rad > 0)
208             sprintf(desc, _("永久光源(半径 %d)", "Permanent Light(radius %d)"), (int)rad);
209
210         if (rad < 0)
211             sprintf(desc, _("永久光源(半径-%d)。", "Permanent Light(radius -%d)"), (int)-rad);
212     }
213
214     if (rad != 0)
215         *misc_list++ = quark_str(quark_add(desc));
216
217     if (flgs.has(TR_TY_CURSE))
218         *misc_list++ = _("太古の怨念", "Ancient Curse");
219
220     if (o_ptr->curse_flags.has(CurseTraitType::PERMA_CURSE))
221         *misc_list++ = _("永遠の呪い", "Permanently Cursed");
222     else if (o_ptr->curse_flags.has(CurseTraitType::HEAVY_CURSE))
223         *misc_list++ = _("強力な呪い", "Heavily Cursed");
224     else if (o_ptr->curse_flags.has(CurseTraitType::CURSED))
225         *misc_list++ = _("呪い", "Cursed");
226
227     if (flgs.has(TR_ADD_L_CURSE))
228         *misc_list++ = _("呪いを増やす", "Cursing");
229
230     if (flgs.has(TR_ADD_H_CURSE))
231         *misc_list++ = _("強力な呪いを増やす", "Heavily Cursing");
232
233     *misc_list = nullptr;
234 }
235
236 /*!
237  * @brief アーティファクトの追加ランダム特性を構造体に収める /
238  * Note additional ability and/or resistance of fixed artifacts
239  * @param o_ptr オブジェクト構造体の参照ポインタ
240  * @param addition 追加ランダム耐性構造体の参照ポインタ
241  */
242 static void analyze_addition(ObjectType *o_ptr, char *addition)
243 {
244     auto *a_ptr = &a_info[o_ptr->name1];
245     strcpy(addition, "");
246
247     if (a_ptr->gen_flags.has_all_of({ ItemGenerationTraitType::XTRA_POWER, ItemGenerationTraitType::XTRA_H_RES })) {
248         strcat(addition, _("能力and耐性", "Ability and Resistance"));
249     } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_POWER)) {
250         strcat(addition, _("能力", "Ability"));
251         if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER))
252             strcat(addition, _("(1/2でand耐性)", "(plus Resistance about 1/2)"));
253     } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_H_RES)) {
254         strcat(addition, _("耐性", "Resistance"));
255         if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER))
256             strcat(addition, _("(1/2でand能力)", "(plus Ability about 1/2)"));
257     } else if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_RES_OR_POWER))
258         strcat(addition, _("能力or耐性", "Ability or Resistance"));
259
260     if (a_ptr->gen_flags.has(ItemGenerationTraitType::XTRA_DICE)) {
261         if (strlen(addition) > 0)
262             strcat(addition, _("、", ", "));
263         strcat(addition, _("ダイス数", "Dice number"));
264     }
265 }
266
267 /*!
268  * @brief アーティファクトの基本情報を文字列に収める /
269  * Determine the minimum depth an artifact can appear, its rarity, its weight,
270  * and its value in gold pieces
271  * @param o_ptr オブジェクト構造体の参照ポインタ
272  * @param misc_desc 基本情報を収める文字列参照ポインタ
273  */
274 static void analyze_misc(ObjectType *o_ptr, char *misc_desc)
275 {
276     auto *a_ptr = &a_info[o_ptr->name1];
277     sprintf(misc_desc, _("レベル %d, 希少度 %u, %d.%d kg, $%ld", "Level %d, Rarity %u, %d.%d lbs, %ld Gold"), (int)a_ptr->level, a_ptr->rarity,
278         _(lb_to_kg_integer(a_ptr->weight), a_ptr->weight / 10), _(lb_to_kg_fraction(a_ptr->weight), a_ptr->weight % 10), (long int)a_ptr->cost);
279 }
280
281 /*!
282  * @brief アーティファクトの情報全体を構造体に収める /
283  * Fill in an object description structure for a given object
284  * and its value in gold pieces
285  * @param player_ptr プレイヤーへの参照ポインタ
286  * @param o_ptr オブジェクト構造体の参照ポインタ
287  * @param desc_ptr 全アーティファクト情報を収める文字列参照ポインタ
288  */
289 void object_analyze(PlayerType *player_ptr, ObjectType *o_ptr, obj_desc_list *desc_ptr)
290 {
291     analyze_general(player_ptr, o_ptr, desc_ptr->description);
292     analyze_pval(o_ptr, &desc_ptr->pval_info);
293     analyze_brand(o_ptr, desc_ptr->brands);
294     analyze_slay(o_ptr, desc_ptr->slays);
295     analyze_immune(o_ptr, desc_ptr->immunities);
296     analyze_resist(o_ptr, desc_ptr->resistances);
297     analyze_vulnerable(o_ptr, desc_ptr->vulnerables);
298     analyze_sustains(o_ptr, desc_ptr->sustains);
299     analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
300     analyze_addition(o_ptr, desc_ptr->addition);
301     analyze_misc(o_ptr, desc_ptr->misc_desc);
302     desc_ptr->activation = activation_explanation(o_ptr);
303 }
304
305 /*!
306  * @brief ランダムアーティファクト1件を解析する /
307  * Fill in an object description structure for a given object
308  * @param player_ptr プレイヤーへの参照ポインタ
309  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
310  * @param desc_ptr 記述内容を収める構造体参照ポインタ
311  */
312 void random_artifact_analyze(PlayerType *player_ptr, ObjectType *o_ptr, obj_desc_list *desc_ptr)
313 {
314     analyze_general(player_ptr, o_ptr, desc_ptr->description);
315     analyze_pval(o_ptr, &desc_ptr->pval_info);
316     analyze_brand(o_ptr, desc_ptr->brands);
317     analyze_slay(o_ptr, desc_ptr->slays);
318     analyze_immune(o_ptr, desc_ptr->immunities);
319     analyze_resist(o_ptr, desc_ptr->resistances);
320     analyze_vulnerable(o_ptr, desc_ptr->vulnerables);
321     analyze_sustains(o_ptr, desc_ptr->sustains);
322     analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
323     desc_ptr->activation = activation_explanation(o_ptr);
324     sprintf(desc_ptr->misc_desc, _("重さ %d.%d kg", "Weight %d.%d lbs"), _(lb_to_kg_integer(o_ptr->weight), o_ptr->weight / 10),
325         _(lb_to_kg_fraction(o_ptr->weight), o_ptr->weight % 10));
326 }