OSDN Git Service

[Refactor] #40399 Renamed item_activation() to activation_explanation()
[hengband/hengband.git] / src / wizard / wizard-spoiler.c
1 /*!
2  * @file wizard1.c
3  * @brief ウィザードモードの処理(スポイラー出力中心) / Spoiler generation -BEN-
4  * @date 2014/02/17
5  * @author
6  * Copyright (c) 1997 Ben Harrison, and others
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  * 2013 Deskull rearranged comment for Doxygen.
11  */
12
13 #include "wizard/wizard-spoiler.h"
14 #include "core/sort.h"
15 #include "floor/floor-town.h"
16 #include "io/files-util.h"
17 #include "monster/monster.h"
18 #include "object-enchant/artifact.h"
19 #include "object-enchant/object-ego.h"
20 #include "object-enchant/special-object-flags.h"
21 #include "object-enchant/tr-types.h"
22 #include "object-enchant/trc-types.h"
23 #include "object-enchant/trg-types.h"
24 #include "object/object-flags.h"
25 #include "object/object-flavor.h"
26 #include "object/object-generator.h"
27 #include "object/object-kind-hook.h"
28 #include "object/object-kind.h"
29 #include "object/object-value.h"
30 #include "object/object1.h"
31 #include "perception/object-perception.h"
32 #include "store/store-util.h"
33 #include "store/store.h"
34 #include "system/angband-version.h"
35 #include "term/term-color-types.h"
36 #include "util/util.h"
37
38  /*
39   * The spoiler file being created
40   */
41 static FILE *fff = NULL;
42
43 /*!
44  * @brief シンボル職の記述名を返す /
45  * Extract a textual representation of an attribute
46  * @param r_ptr モンスター種族の構造体ポインタ
47  * @return シンボル職の記述名
48  */
49 static concptr attr_to_text(monster_race *r_ptr)
50 {
51         if (r_ptr->flags1 & RF1_ATTR_CLEAR)    return _("透明な", "Clear");
52         if (r_ptr->flags1 & RF1_ATTR_MULTI)    return _("万色の", "Multi");
53         if (r_ptr->flags1 & RF1_ATTR_SEMIRAND) return _("準ランダムな", "S.Rand");
54
55         switch (r_ptr->d_attr)
56         {
57         case TERM_DARK:    return _("黒い", "Dark");
58         case TERM_WHITE:   return _("白い", "White");
59         case TERM_SLATE:   return _("青灰色の", "Slate");
60         case TERM_ORANGE:  return _("オレンジの", "Orange");
61         case TERM_RED:     return _("赤い", "Red");
62         case TERM_GREEN:   return _("緑の", "Green");
63         case TERM_BLUE:    return _("青い", "Blue");
64         case TERM_UMBER:   return _("琥珀色の", "Umber");
65         case TERM_L_DARK:  return _("灰色の", "L.Dark");
66         case TERM_L_WHITE: return _("明るい青灰色の", "L.Slate");
67         case TERM_VIOLET:  return _("紫の", "Violet");
68         case TERM_YELLOW:  return _("黄色の", "Yellow");
69         case TERM_L_RED:   return _("明るい赤の", "L.Red");
70         case TERM_L_GREEN: return _("明るい緑の", "L.Green");
71         case TERM_L_BLUE:  return _("明るい青の", "L.Blue");
72         case TERM_L_UMBER: return _("明るい琥珀色の", "L.Umber");
73         }
74
75         return _("変な色の", "Icky");
76 }
77
78
79
80 /*
81  * A tval grouper
82  */
83 typedef struct
84 {
85         tval_type tval;
86         concptr name;
87 } grouper;
88
89
90
91 /*
92  * Item Spoilers by: benh@phial.com (Ben Harrison)
93  */
94
95
96  /*
97   * The basic items categorized by type
98   */
99 static grouper group_item[] =
100 {
101         { TV_SHOT,          _("射撃物", "Ammo") },
102         { TV_ARROW,         NULL },
103         { TV_BOLT,          NULL },
104         { TV_BOW,           _("弓", "Bows") },
105         { TV_DIGGING,       _("武器", "Weapons") },
106         { TV_POLEARM,       NULL },
107         { TV_HAFTED,        NULL },
108         { TV_SWORD,         NULL },
109         { TV_SOFT_ARMOR,    _("防具 (体)", "Armour (Body)") },
110         { TV_HARD_ARMOR,    NULL },
111         { TV_DRAG_ARMOR,    NULL },
112         { TV_BOOTS,         _("防具 (その他)", "Armour (Misc)") },
113         { TV_GLOVES,        NULL },
114         { TV_HELM,          NULL },
115         { TV_CROWN,         NULL },
116         { TV_SHIELD,        NULL },
117         { TV_CLOAK,         NULL },
118
119         { TV_LITE,          _("光源", "Light Sources") },
120         { TV_AMULET,        _("アミュレット", "Amulets")},
121         { TV_RING,          _("指輪", "Rings") },
122         { TV_STAFF,         _("杖", "Staffs") },
123         { TV_WAND,          _("魔法棒", "Wands") },
124         { TV_ROD,           _("ロッド", "Rods") },
125         { TV_SCROLL,        _("巻物", "Scrolls") },
126         { TV_POTION,        _("薬", "Potions") },
127         { TV_FOOD,          _("食料", "Food") },
128
129         { TV_LIFE_BOOK,     _("魔法書 (生命)", "Books (Life)") },
130         { TV_SORCERY_BOOK,  _("魔法書 (仙術)", "Books (Sorcery)") },
131         { TV_NATURE_BOOK,   _("魔法書 (自然)", "Books (Nature)") },
132         { TV_CHAOS_BOOK,    _("魔法書 (カオス)", "Books (Chaos)") },
133         { TV_DEATH_BOOK,    _("魔法書 (暗黒)", "Books (Death)") },
134         { TV_TRUMP_BOOK,    _("魔法書 (トランプ)", "Books (Trump)") },
135         { TV_ARCANE_BOOK,   _("魔法書 (秘術)", "Books (Arcane)") },
136         { TV_CRAFT_BOOK,    _("魔法書 (匠)", "Books (Craft)") },
137         { TV_DAEMON_BOOK,   _("魔法書 (悪魔)", "Books (Daemon)") },
138         { TV_CRUSADE_BOOK,  _("魔法書 (破邪)", "Books (Crusade)") },
139         { TV_MUSIC_BOOK,    _("歌集", "Song Books") },
140         { TV_HISSATSU_BOOK, _("武芸の書", "Books (Kendo)") },
141         { TV_HEX_BOOK,      _("魔法書 (呪術)", "Books (Hex)") },
142
143         { TV_WHISTLE,       _("笛", "Whistle") },
144         { TV_CAPTURE,       _("キャプチャー・ボール", "Capture Ball") },
145         { TV_CARD,          _("エクスプレスカード", "Express Card") },
146
147         { TV_CHEST,         _("箱", "Chests") },
148
149         { TV_FIGURINE,      _("人形", "Magical Figurines") },
150         { TV_STATUE,        _("像", "Statues") },
151         { TV_CORPSE,        _("死体", "Corpses") },
152
153         { TV_SKELETON,      _("その他", "Misc") },
154         { TV_BOTTLE,        NULL },
155         { TV_JUNK,          NULL },
156         { TV_SPIKE,         NULL },
157         { TV_FLASK,         NULL },
158         { TV_PARCHMENT,     NULL },
159
160         { 0, "" }
161 };
162
163
164 /*!
165  * @brief ベースアイテムの各情報を文字列化する /
166  * Describe the kind
167  * @param player_ptr プレーヤーへの参照ポインタ
168  * @param buf 名称を返すバッファ参照ポインタ
169  * @param dam ダメージダイス記述を返すバッファ参照ポインタ
170  * @param wgt 重量記述を返すバッファ参照ポインタ
171  * @param lev 生成階記述を返すバッファ参照ポインタ
172  * @param chance 生成機会を返すバッファ参照ポインタ
173  * @param val 価値を返すバッファ参照ポインタ
174  * @param k ベースアイテムID
175  * @return なし
176  */
177 static void kind_info(player_type *player_ptr, char *buf, char *dam, char *wgt, char *chance, DEPTH *lev, PRICE *val, OBJECT_IDX k)
178 {
179         object_type forge;
180         object_type *q_ptr;
181         int i;
182         q_ptr = &forge;
183
184         /* Prepare a fake item */
185         object_prep(q_ptr, k);
186
187         /* It is known */
188         q_ptr->ident |= (IDENT_KNOWN);
189
190         /* Cancel bonuses */
191         q_ptr->pval = 0;
192         q_ptr->to_a = 0;
193         q_ptr->to_h = 0;
194         q_ptr->to_d = 0;
195
196         (*lev) = k_info[q_ptr->k_idx].level;
197         (*val) = object_value(q_ptr);
198
199         if (!buf || !dam || !chance || !wgt) return;
200
201         /* Description (too brief) */
202         object_desc(player_ptr, buf, q_ptr, (OD_NAME_ONLY | OD_STORE));
203
204         /* Misc info */
205         strcpy(dam, "");
206
207         /* Damage */
208         switch (q_ptr->tval)
209         {
210                 /* Bows */
211         case TV_BOW:
212         {
213                 break;
214         }
215
216         /* Ammo */
217         case TV_SHOT:
218         case TV_BOLT:
219         case TV_ARROW:
220         {
221                 sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
222                 break;
223         }
224
225         /* Weapons */
226         case TV_HAFTED:
227         case TV_POLEARM:
228         case TV_SWORD:
229         case TV_DIGGING:
230         {
231                 sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
232                 break;
233         }
234
235         /* Armour */
236         case TV_BOOTS:
237         case TV_GLOVES:
238         case TV_CLOAK:
239         case TV_CROWN:
240         case TV_HELM:
241         case TV_SHIELD:
242         case TV_SOFT_ARMOR:
243         case TV_HARD_ARMOR:
244         case TV_DRAG_ARMOR:
245         {
246                 sprintf(dam, "%d", q_ptr->ac);
247                 break;
248         }
249         }
250
251         /* Chance */
252         strcpy(chance, "");
253         for (i = 0; i < 4; i++)
254         {
255                 char chance_aux[20] = "";
256                 if (k_info[q_ptr->k_idx].chance[i] > 0)
257                 {
258                         sprintf(chance_aux, "%s%3dF:%+4d", (i != 0 ? "/" : ""),
259                                 (int)k_info[q_ptr->k_idx].locale[i], 100 / k_info[q_ptr->k_idx].chance[i]);
260                         strcat(chance, chance_aux);
261                 }
262         }
263
264
265         /* Weight */
266         sprintf(wgt, "%3d.%d", (int)(q_ptr->weight / 10), (int)(q_ptr->weight % 10));
267 }
268
269
270 /*!
271  * @brief 各ベースアイテムの情報を一行毎に記述する /
272  * @param player_ptr プレーヤーへの参照ポインタ
273  * Create a spoiler file for items
274  * @param fname ファイル名
275  * @return なし
276  */
277 static void spoil_obj_desc(player_type *player_ptr, concptr fname)
278 {
279         int i, k, s, t, n = 0, group_start = 0;
280
281         OBJECT_IDX who[200];
282
283         char buf[1024];
284
285         char wgt[80];
286         char chance[80];
287         char dam[80];
288
289         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
290
291         fff = my_fopen(buf, "w");
292
293         if (!fff)
294         {
295                 msg_print("Cannot create spoiler file.");
296                 return;
297         }
298
299
300         /* Header */
301         fprintf(fff, "Spoiler File -- Basic Items (Hengband %d.%d.%d.%d)\n\n\n",
302                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, FAKE_VER_EXTRA);
303
304         /* More Header */
305         fprintf(fff, "%-37s%8s%7s%5s %40s%9s\n",
306                 "Description", "Dam/AC", "Wgt", "Lev", "Chance", "Cost");
307         fprintf(fff, "%-37s%8s%7s%5s %40s%9s\n",
308                 "-------------------------------------", "------", "---", "---", "----------------", "----");
309
310         /* List the groups */
311         for (i = 0; TRUE; i++)
312         {
313                 /* Write out the group title */
314                 if (group_item[i].name)
315                 {
316                         if (n)
317                         {
318                                 /* Hack -- bubble-sort by cost and then level */
319                                 for (s = 0; s < n - 1; s++)
320                                 {
321                                         for (t = 0; t < n - 1; t++)
322                                         {
323                                                 int i1 = t;
324                                                 int i2 = t + 1;
325
326                                                 DEPTH e1;
327                                                 DEPTH e2;
328
329                                                 PRICE t1;
330                                                 PRICE t2;
331
332                                                 kind_info(player_ptr, NULL, NULL, NULL, NULL, &e1, &t1, who[i1]);
333                                                 kind_info(player_ptr, NULL, NULL, NULL, NULL, &e2, &t2, who[i2]);
334
335                                                 if ((t1 > t2) || ((t1 == t2) && (e1 > e2)))
336                                                 {
337                                                         u16b tmp = who[i1];
338                                                         who[i1] = who[i2];
339                                                         who[i2] = tmp;
340                                                 }
341                                         }
342                                 }
343
344                                 fprintf(fff, "\n\n%s\n\n", group_item[group_start].name);
345
346                                 /* Spoil each item */
347                                 for (s = 0; s < n; s++)
348                                 {
349                                         DEPTH e;
350                                         PRICE v;
351
352                                         /* Describe the kind */
353                                         kind_info(player_ptr, buf, dam, wgt, chance, &e, &v, who[s]);
354
355                                         /* Dump it */
356                                         fprintf(fff, "  %-35s%8s%7s%5d %-40s%9ld\n",
357                                                 buf, dam, wgt, (int)e, chance, (long)(v));
358                                 }
359
360                                 /* Start a new set */
361                                 n = 0;
362                         }
363
364                         /* Notice the end */
365                         if (!group_item[i].tval) break;
366
367                         /* Start a new set */
368                         group_start = i;
369                 }
370
371                 /* Acquire legal item types */
372                 for (k = 1; k < max_k_idx; k++)
373                 {
374                         object_kind *k_ptr = &k_info[k];
375
376                         /* Skip wrong tval's */
377                         if (k_ptr->tval != group_item[i].tval) continue;
378
379                         /* Hack -- Skip instant-artifacts */
380                         if (k_ptr->gen_flags & (TRG_INSTA_ART)) continue;
381
382                         /* Save the index */
383                         who[n++] = (u16b)k;
384                 }
385         }
386
387
388         /* Check for errors */
389         if (ferror(fff) || my_fclose(fff))
390         {
391                 msg_print("Cannot close spoiler file.");
392                 return;
393         }
394
395         msg_print("Successfully created a spoiler file.");
396 }
397
398
399 /*
400  * Artifact Spoilers by: randy@PICARD.tamu.edu (Randy Hutson)
401  */
402
403
404  /*
405   * Returns a "+" string if a number is non-negative and an empty
406   * string if negative
407   */
408 #define POSITIZE(v) (((v) >= 0) ? "+" : "")
409
410   /*
411    * These are used to format the artifact spoiler file. INDENT1 is used
412    * to indent all but the first line of an artifact spoiler. INDENT2 is
413    * used when a line "wraps". (Bladeturner's resistances cause this.)
414    */
415 #define INDENT1 "    "
416 #define INDENT2 "      "
417
418    /*
419         * MAX_LINE_LEN specifies when a line should wrap.
420         */
421 #define MAX_LINE_LEN 75
422
423         /*
424          * Given an array, determine how many elements are in the array
425          */
426 #define N_ELEMENTS(a) (sizeof (a) / sizeof ((a)[0]))
427
428          /*
429           * The artifacts categorized by type
430           */
431 static grouper group_artifact[] =
432 {
433 #ifdef JP
434         { TV_SWORD,             "刀剣" },
435         { TV_POLEARM,           "槍/斧" },
436         { TV_HAFTED,            "鈍器" },
437         { TV_DIGGING,           "シャベル/つるはし" },
438         { TV_BOW,               "飛び道具" },
439         { TV_ARROW,             "矢" },
440         { TV_BOLT,              NULL },
441
442         { TV_SOFT_ARMOR,        "鎧" },
443         { TV_HARD_ARMOR,        NULL },
444         { TV_DRAG_ARMOR,        NULL },
445
446         { TV_CLOAK,             "クローク" },
447         { TV_SHIELD,            "盾" },
448         { TV_CARD,              NULL },
449         { TV_HELM,              "兜/冠" },
450         { TV_CROWN,             NULL },
451         { TV_GLOVES,            "籠手" },
452         { TV_BOOTS,             "靴" },
453
454         { TV_LITE,              "光源" },
455         { TV_AMULET,            "アミュレット" },
456         { TV_RING,              "指輪" },
457 #else
458         { TV_SWORD,             "Edged Weapons" },
459         { TV_POLEARM,           "Polearms" },
460         { TV_HAFTED,            "Hafted Weapons" },
461         { TV_DIGGING,           "Shovels/Picks" },
462         { TV_BOW,               "Bows" },
463         { TV_ARROW,             "Ammo" },
464         { TV_BOLT,              NULL },
465
466         { TV_SOFT_ARMOR,        "Body Armor" },
467         { TV_HARD_ARMOR,        NULL },
468         { TV_DRAG_ARMOR,        NULL },
469
470         { TV_CLOAK,             "Cloaks" },
471         { TV_SHIELD,            "Shields" },
472         { TV_CARD,              NULL },
473         { TV_HELM,              "Helms/Crowns" },
474         { TV_CROWN,             NULL },
475         { TV_GLOVES,            "Gloves" },
476         { TV_BOOTS,             "Boots" },
477
478         { TV_LITE,              "Light Sources" },
479         { TV_AMULET,            "Amulets" },
480         { TV_RING,              "Rings" },
481 #endif
482
483         { 0, NULL }
484 };
485
486
487
488 /*
489  * Pair together a constant flag with a textual description.
490  *
491  * Used by both "init.c" and "wiz-spo.c".
492  *
493  * Note that it sometimes more efficient to actually make an array
494  * of textual names, where entry 'N' is assumed to be paired with
495  * the flag whose value is "1L << N", but that requires hard-coding.
496  */
497 typedef struct flag_desc
498 {
499         const tr_type flag;
500         concptr const desc;
501 } flag_desc;
502
503
504
505 /*
506  * These are used for "+3 to STR, DEX", etc. These are separate from
507  * the other pval affected traits to simplify the case where an object
508  * affects all stats.  In this case, "All stats" is used instead of
509  * listing each stat individually.
510  */
511
512 static flag_desc stat_flags_desc[] =
513 {
514 #ifdef JP
515         { TR_STR,        "腕力" },
516         { TR_INT,        "知能" },
517         { TR_WIS,        "賢さ" },
518         { TR_DEX,        "器用さ" },
519         { TR_CON,        "耐久力" },
520         { TR_CHR,        "魅力" }
521 #else
522         { TR_STR,        "STR" },
523         { TR_INT,        "INT" },
524         { TR_WIS,        "WIS" },
525         { TR_DEX,        "DEX" },
526         { TR_CON,        "CON" },
527         { TR_CHR,        "CHR" }
528 #endif
529 };
530
531 /*
532  * Besides stats, these are the other player traits
533  * which may be affected by an object's pval
534  */
535
536 static flag_desc pval_flags1_desc[] =
537 {
538 #ifdef JP
539         { TR_MAGIC_MASTERY,    "魔法道具使用能力" },
540         { TR_STEALTH,    "隠密" },
541         { TR_SEARCH,     "探索" },
542         { TR_INFRA,      "赤外線視力" },
543         { TR_TUNNEL,     "採掘" },
544         { TR_BLOWS,      "攻撃回数" },
545         { TR_SPEED,      "スピード" }
546 #else
547         { TR_STEALTH,    "Stealth" },
548         { TR_SEARCH,     "Searching" },
549         { TR_INFRA,      "Infravision" },
550         { TR_TUNNEL,     "Tunneling" },
551         { TR_BLOWS,      "Attacks" },
552         { TR_SPEED,      "Speed" }
553 #endif
554 };
555
556 /*
557  * Slaying preferences for weapons
558  */
559
560 static flag_desc slay_flags_desc[] =
561 {
562 #ifdef JP
563         { TR_SLAY_ANIMAL,        "動物" },
564         { TR_KILL_ANIMAL,        "*動物*" },
565         { TR_SLAY_EVIL,          "邪悪" },
566         { TR_KILL_EVIL,          "*邪悪*" },
567         { TR_SLAY_HUMAN,         "人間" },
568         { TR_KILL_HUMAN,         "*人間*" },
569         { TR_SLAY_UNDEAD,        "アンデッド" },
570         { TR_KILL_UNDEAD,        "*アンデッド*" },
571         { TR_SLAY_DEMON,         "悪魔" },
572         { TR_KILL_DEMON,         "*悪魔*" },
573         { TR_SLAY_ORC,           "オーク" },
574         { TR_KILL_ORC,           "*オーク*" },
575         { TR_SLAY_TROLL,         "トロル" },
576         { TR_KILL_TROLL,         "*トロル*" },
577         { TR_SLAY_GIANT,         "巨人" },
578         { TR_KILL_GIANT,         "*巨人*" },
579         { TR_SLAY_DRAGON,        "ドラゴン" },
580         { TR_KILL_DRAGON,        "*ドラゴン*" },
581 #else
582         { TR_SLAY_ANIMAL,        "Animal" },
583         { TR_KILL_ANIMAL,        "XAnimal" },
584         { TR_SLAY_EVIL,          "Evil" },
585         { TR_KILL_EVIL,          "XEvil" },
586         { TR_SLAY_HUMAN,         "Human" },
587         { TR_KILL_HUMAN,         "XHuman" },
588         { TR_SLAY_UNDEAD,        "Undead" },
589         { TR_KILL_UNDEAD,        "XUndead" },
590         { TR_SLAY_DEMON,         "Demon" },
591         { TR_KILL_DEMON,         "XDemon" },
592         { TR_SLAY_ORC,           "Orc" },
593         { TR_KILL_ORC,           "XOrc" },
594         { TR_SLAY_TROLL,         "Troll" },
595         { TR_KILL_TROLL,         "XTroll" },
596         { TR_SLAY_GIANT,         "Giant" },
597         { TR_KILL_GIANT,         "Xgiant" },
598         { TR_SLAY_DRAGON,        "Dragon" },
599         { TR_KILL_DRAGON,        "Xdragon" }
600 #endif
601 };
602
603 /*
604  * Elemental brands for weapons
605  *
606  * Clearly, TR1_IMPACT is a bit out of place here. To simplify
607  * coding, it has been included here along with the elemental
608  * brands. It does seem to fit in with the brands and slaying
609  * more than the miscellaneous section.
610  */
611 static flag_desc brand_flags_desc[] =
612 {
613 #ifdef JP
614         { TR_BRAND_ACID,         "溶解" },
615         { TR_BRAND_ELEC,         "電撃" },
616         { TR_BRAND_FIRE,         "焼棄" },
617         { TR_BRAND_COLD,         "凍結" },
618         { TR_BRAND_POIS,         "毒殺" },
619
620         { TR_FORCE_WEAPON,       "理力" },
621         { TR_CHAOTIC,            "混沌" },
622         { TR_VAMPIRIC,           "吸血" },
623         { TR_IMPACT,             "地震" },
624         { TR_VORPAL,             "切れ味" },
625 #else
626         { TR_BRAND_ACID,         "Acid Brand" },
627         { TR_BRAND_ELEC,         "Lightning Brand" },
628         { TR_BRAND_FIRE,         "Flame Tongue" },
629         { TR_BRAND_COLD,         "Frost Brand" },
630         { TR_BRAND_POIS,         "Poisoned" },
631
632         { TR_FORCE_WEAPON,       "Force" },
633         { TR_CHAOTIC,            "Mark of Chaos" },
634         { TR_VAMPIRIC,           "Vampiric" },
635         { TR_IMPACT,             "Earthquake impact on hit" },
636         { TR_VORPAL,             "Very sharp" },
637 #endif
638 };
639
640
641 /*
642  * The 15 resistables
643  */
644 static const flag_desc resist_flags_desc[] =
645 {
646 #ifdef JP
647         { TR_RES_ACID,   "酸" },
648         { TR_RES_ELEC,   "電撃" },
649         { TR_RES_FIRE,   "火炎" },
650         { TR_RES_COLD,   "冷気" },
651         { TR_RES_POIS,   "毒" },
652         { TR_RES_FEAR,   "恐怖"},
653         { TR_RES_LITE,   "閃光" },
654         { TR_RES_DARK,   "暗黒" },
655         { TR_RES_BLIND,  "盲目" },
656         { TR_RES_CONF,   "混乱" },
657         { TR_RES_SOUND,  "轟音" },
658         { TR_RES_SHARDS, "破片" },
659         { TR_RES_NETHER, "地獄" },
660         { TR_RES_NEXUS,  "因果混乱" },
661         { TR_RES_CHAOS,  "カオス" },
662         { TR_RES_DISEN,  "劣化" },
663 #else
664         { TR_RES_ACID,   "Acid" },
665         { TR_RES_ELEC,   "Lightning" },
666         { TR_RES_FIRE,   "Fire" },
667         { TR_RES_COLD,   "Cold" },
668         { TR_RES_POIS,   "Poison" },
669         { TR_RES_FEAR,   "Fear"},
670         { TR_RES_LITE,   "Light" },
671         { TR_RES_DARK,   "Dark" },
672         { TR_RES_BLIND,  "Blindness" },
673         { TR_RES_CONF,   "Confusion" },
674         { TR_RES_SOUND,  "Sound" },
675         { TR_RES_SHARDS, "Shards" },
676         { TR_RES_NETHER, "Nether" },
677         { TR_RES_NEXUS,  "Nexus" },
678         { TR_RES_CHAOS,  "Chaos" },
679         { TR_RES_DISEN,  "Disenchantment" },
680 #endif
681 };
682
683 /*
684  * Elemental immunities (along with poison)
685  */
686
687 static const flag_desc immune_flags_desc[] =
688 {
689 #ifdef JP
690         { TR_IM_ACID,    "酸" },
691         { TR_IM_ELEC,    "電撃" },
692         { TR_IM_FIRE,    "火炎" },
693         { TR_IM_COLD,    "冷気" },
694 #else
695         { TR_IM_ACID,    "Acid" },
696         { TR_IM_ELEC,    "Lightning" },
697         { TR_IM_FIRE,    "Fire" },
698         { TR_IM_COLD,    "Cold" },
699 #endif
700 };
701
702 /*
703  * Sustain stats -  these are given their "own" line in the
704  * spoiler file, mainly for simplicity
705  */
706 static const flag_desc sustain_flags_desc[] =
707 {
708 #ifdef JP
709         { TR_SUST_STR,   "腕力" },
710         { TR_SUST_INT,   "知能" },
711         { TR_SUST_WIS,   "賢さ" },
712         { TR_SUST_DEX,   "器用さ" },
713         { TR_SUST_CON,   "耐久力" },
714         { TR_SUST_CHR,   "魅力" },
715 #else
716         { TR_SUST_STR,   "STR" },
717         { TR_SUST_INT,   "INT" },
718         { TR_SUST_WIS,   "WIS" },
719         { TR_SUST_DEX,   "DEX" },
720         { TR_SUST_CON,   "CON" },
721         { TR_SUST_CHR,   "CHR" },
722 #endif
723 };
724
725 /*
726  * Miscellaneous magic given by an object's "flags2" field
727  */
728
729 static const flag_desc misc_flags2_desc[] =
730 {
731 #ifdef JP
732         { TR_THROW,      "投擲" },
733         { TR_REFLECT,    "反射" },
734         { TR_FREE_ACT,   "麻痺知らず" },
735         { TR_HOLD_EXP,   "経験値維持" },
736 #else
737         { TR_THROW,      "Throwing" },
738         { TR_REFLECT,    "Reflection" },
739         { TR_FREE_ACT,   "Free Action" },
740         { TR_HOLD_EXP,   "Hold Experience" },
741 #endif
742 };
743
744 /*
745  * Miscellaneous magic given by an object's "flags3" field
746  *
747  * Note that cursed artifacts and objects with permanent light
748  * are handled "directly" -- see analyze_misc_magic()
749  */
750
751 static const flag_desc misc_flags3_desc[] =
752 {
753 #ifdef JP
754         { TR_SH_FIRE,            "火炎オーラ" },
755         { TR_SH_ELEC,            "電撃オーラ" },
756         { TR_SH_COLD,            "冷気オーラ" },
757         { TR_NO_TELE,            "反テレポート" },
758         { TR_NO_MAGIC,           "反魔法" },
759         { TR_LEVITATION,         "浮遊" },
760         { TR_SEE_INVIS,          "可視透明" },
761         { TR_TELEPATHY,          "テレパシー" },
762         { TR_ESP_ANIMAL,         "動物感知" },
763         { TR_ESP_UNDEAD,         "不死感知" },
764         { TR_ESP_DEMON,          "悪魔感知" },
765         { TR_ESP_ORC,            "オーク感知" },
766         { TR_ESP_TROLL,          "トロル感知" },
767         { TR_ESP_GIANT,          "巨人感知" },
768         { TR_ESP_DRAGON,         "ドラゴン感知" },
769         { TR_ESP_HUMAN,          "人間感知" },
770         { TR_ESP_EVIL,           "邪悪感知" },
771         { TR_ESP_GOOD,           "善良感知" },
772         { TR_ESP_NONLIVING,      "無生物感知" },
773         { TR_ESP_UNIQUE,         "ユニーク感知" },
774         { TR_SLOW_DIGEST,        "遅消化" },
775         { TR_REGEN,              "急速回復" },
776         { TR_WARNING,            "警告" },
777         /*      { TR_XTRA_MIGHT,         "強力射撃" }, */
778                 { TR_XTRA_SHOTS,         "追加射撃" },        /* always +1? */
779                 { TR_DRAIN_EXP,          "経験値吸収" },
780                 { TR_AGGRAVATE,          "反感" },
781                 { TR_BLESSED,            "祝福" },
782                 { TR_DEC_MANA,           "消費魔力減少" },
783         #else
784                 { TR_SH_FIRE,            "Fiery Aura" },
785                 { TR_SH_ELEC,            "Electric Aura" },
786                 { TR_SH_COLD,            "Coldly Aura" },
787                 { TR_NO_TELE,            "Prevent Teleportation" },
788                 { TR_NO_MAGIC,           "Anti-Magic" },
789                 { TR_LEVITATION,            "Levitation" },
790                 { TR_SEE_INVIS,          "See Invisible" },
791                 { TR_TELEPATHY,          "ESP" },
792                 { TR_ESP_ANIMAL,         "Sense Animal" },
793                 { TR_ESP_UNDEAD,         "Sense Undead" },
794                 { TR_ESP_DEMON,          "Sense Demon" },
795                 { TR_ESP_ORC,            "Sense Orc" },
796                 { TR_ESP_TROLL,          "Sense Troll" },
797                 { TR_ESP_GIANT,          "Sense Giant" },
798                 { TR_ESP_DRAGON,         "Sense Dragon" },
799                 { TR_ESP_HUMAN,          "Sense Human" },
800                 { TR_ESP_EVIL,           "Sense Evil" },
801                 { TR_ESP_GOOD,           "Sense Good" },
802                 { TR_ESP_NONLIVING,      "Sense Nonliving" },
803                 { TR_ESP_UNIQUE,         "Sense Unique" },
804                 { TR_SLOW_DIGEST,        "Slow Digestion" },
805                 { TR_REGEN,              "Regeneration" },
806                 { TR_WARNING,            "Warning" },
807                 /*      { TR_XTRA_MIGHT,         "Extra Might" }, */
808                         { TR_XTRA_SHOTS,         "+1 Extra Shot" },        /* always +1? */
809                         { TR_DRAIN_EXP,          "Drains Experience" },
810                         { TR_AGGRAVATE,          "Aggravates" },
811                         { TR_BLESSED,            "Blessed Blade" },
812                         { TR_DEC_MANA,           "Decrease Mana Consumption Rate" },
813                 #endif
814 };
815
816
817 /*
818  * A special type used just for deailing with pvals
819  */
820 typedef struct
821 {
822         /*
823          * This will contain a string such as "+2", "-10", etc.
824          */
825         char pval_desc[12];
826
827         /*
828          * A list of various player traits affected by an object's pval such
829          * as stats, speed, stealth, etc.  "Extra attacks" is NOT included in
830          * this list since it will probably be desirable to format its
831          * description differently.
832          *
833          * Note that room need only be reserved for the number of stats - 1
834          * since the description "All stats" is used if an object affects all
835          * all stats. Also, room must be reserved for a sentinel NULL pointer.
836          *
837          * This will be a list such as ["STR", "DEX", "Stealth", NULL] etc.
838          *
839          * This list includes extra attacks, for simplicity.
840          */
841         concptr pval_affects[N_ELEMENTS(stat_flags_desc) - 1 +
842                 N_ELEMENTS(pval_flags1_desc) + 1];
843
844 } pval_info_type;
845
846
847 /*
848  * An "object analysis structure"
849  *
850  * It will be filled with descriptive strings detailing an object's
851  * various magical powers. The "ignore X" traits are not noted since
852  * all artifacts ignore "normal" destruction.
853  */
854
855 typedef struct
856 {
857         /* "The Longsword Dragonsmiter (6d4) (+20, +25)" */
858         char description[MAX_NLEN];
859
860         /* Description of what is affected by an object's pval */
861         pval_info_type pval_info;
862
863         /* A list of an object's slaying preferences */
864         concptr slays[N_ELEMENTS(slay_flags_desc) + 1];
865
866         /* A list if an object's elemental brands */
867         concptr brands[N_ELEMENTS(brand_flags_desc) + 1];
868
869         /* A list of immunities granted by an object */
870         concptr immunities[N_ELEMENTS(immune_flags_desc) + 1];
871
872         /* A list of resistances granted by an object */
873         concptr resistances[N_ELEMENTS(resist_flags_desc) + 1];
874
875         /* A list of stats sustained by an object */
876         concptr sustains[N_ELEMENTS(sustain_flags_desc) - 1 + 1];
877
878         /* A list of various magical qualities an object may have */
879         concptr misc_magic[N_ELEMENTS(misc_flags2_desc) + N_ELEMENTS(misc_flags3_desc)
880                 + 1       /* Permanent Light */
881                 + 1       /* TY curse */
882                 + 1       /* type of curse */
883                 + 1];     /* sentinel NULL */
884
885 /* Additional ability or resistance */
886         char addition[80];
887
888         /* A string describing an artifact's activation */
889         concptr activation;
890
891         /* "Level 20, Rarity 30, 3.0 lbs, 20000 Gold" */
892         char misc_desc[80];
893 } obj_desc_list;
894
895
896 /*!
897  * @brief ファイルポインタ先に同じ文字を複数出力する /
898  * Write out `n' of the character `c' to the spoiler file
899  * @param n 出力する数
900  * @param c 出力するキャラクタ
901  * @return なし
902  */
903 static void spoiler_out_n_chars(int n, char c)
904 {
905         while (--n >= 0) fputc(c, fff);
906 }
907
908
909 /*!
910  * @brief ファイルポインタ先に改行を複数出力する /
911  * Write out `n' blank lines to the spoiler file
912  * @param n 改行を出力する数
913  * @return なし
914  */
915 static void spoiler_blanklines(int n)
916 {
917         spoiler_out_n_chars(n, '\n');
918 }
919
920
921 /*!
922  * @brief ファイルポインタ先に複数のハイフンで装飾した文字列を出力する /
923  * Write a line to the spoiler file and then "underline" it with hypens
924  * @param str 出力したい文字列
925  * @return なし
926  */
927 static void spoiler_underline(concptr str)
928 {
929         fprintf(fff, "%s\n", str);
930         spoiler_out_n_chars(strlen(str), '-');
931         fprintf(fff, "\n");
932 }
933
934
935
936 /*!
937  * @brief アーティファクトの特性一覧を出力する /
938  * Write a line to the spoiler file and then "underline" it with hypens
939  * @param art_flags アーティファクトのフラグ群
940  * @param flag_ptr フラグ記述情報の参照ポインタ
941  * @param desc_ptr 記述内容を返すための文字列参照ポインタ
942  * @param n_elmnts フラグの要素数
943  * @return desc_ptrと同じアドレス
944  * @details
945  * <pre>
946  * This function does most of the actual "analysis". Given a set of bit flags
947  * (which will be from one of the flags fields from the object in question),
948  * a "flag description structure", a "description list", and the number of
949  * elements in the "flag description structure", this function sets the
950  * "description list" members to the appropriate descriptions contained in
951  * the "flag description structure".
952  * The possibly updated description pointer is returned.
953  * </pre>
954  */
955 static concptr *spoiler_flag_aux(const BIT_FLAGS art_flags[TR_FLAG_SIZE],
956         const flag_desc *flag_ptr,
957         concptr *desc_ptr, const int n_elmnts)
958 {
959         int i;
960
961         for (i = 0; i < n_elmnts; ++i)
962         {
963                 if (have_flag(art_flags, flag_ptr[i].flag))
964                 {
965                         *desc_ptr++ = flag_ptr[i].desc;
966                 }
967         }
968
969         return desc_ptr;
970 }
971
972
973 /*!
974  * @brief アイテムの特定記述内容を返す /
975  * Acquire a "basic" description "The Cloak of Death [1,+10]"
976  * @param o_ptr 記述を得たいオブジェクトの参照ポインタ
977  * @param desc_ptr 記述内容を返すための文字列参照ポインタ
978  * @return なし
979  */
980 static void analyze_general(player_type *player_ptr, object_type *o_ptr, char *desc_ptr)
981 {
982         /* Get a "useful" description of the object */
983         object_desc(player_ptr, desc_ptr, o_ptr, (OD_NAME_AND_ENCHANT | OD_STORE));
984 }
985
986
987 /*!
988  * @brief アーティファクトがプレイヤーに与えるpval修正を構造体に収める /
989  * List "player traits" altered by an artifact's pval. These include stats,
990  * speed, infravision, tunneling, stealth, searching, and extra attacks.
991  * @param o_ptr オブジェクト構造体の参照ポインタ
992  * @param pi_ptr pval修正構造体の参照ポインタ
993  * @return なし
994  */
995 static void analyze_pval(object_type *o_ptr, pval_info_type *pi_ptr)
996 {
997         BIT_FLAGS flgs[TR_FLAG_SIZE];
998
999         concptr *affects_list;
1000
1001         /* If pval == 0, there is nothing to do. */
1002         if (!o_ptr->pval)
1003         {
1004                 /* An "empty" pval description indicates that pval == 0 */
1005                 pi_ptr->pval_desc[0] = '\0';
1006                 return;
1007         }
1008         object_flags(o_ptr, flgs);
1009
1010         affects_list = pi_ptr->pval_affects;
1011
1012         /* Create the "+N" string */
1013         sprintf(pi_ptr->pval_desc, "%s%d", POSITIZE(o_ptr->pval), o_ptr->pval);
1014
1015         /* First, check to see if the pval affects all stats */
1016         if (have_flag(flgs, TR_STR) && have_flag(flgs, TR_INT) &&
1017                 have_flag(flgs, TR_WIS) && have_flag(flgs, TR_DEX) &&
1018                 have_flag(flgs, TR_CON) && have_flag(flgs, TR_CHR))
1019         {
1020                 *affects_list++ = _("全能力", "All stats");
1021         }
1022
1023         /* Are any stats affected? */
1024         else if (have_flag(flgs, TR_STR) || have_flag(flgs, TR_INT) ||
1025                 have_flag(flgs, TR_WIS) || have_flag(flgs, TR_DEX) ||
1026                 have_flag(flgs, TR_CON) || have_flag(flgs, TR_CHR))
1027         {
1028                 affects_list = spoiler_flag_aux(flgs, stat_flags_desc,
1029                         affects_list,
1030                         N_ELEMENTS(stat_flags_desc));
1031         }
1032
1033         /* And now the "rest" */
1034         affects_list = spoiler_flag_aux(flgs, pval_flags1_desc,
1035                 affects_list,
1036                 N_ELEMENTS(pval_flags1_desc));
1037
1038         /* Terminate the description list */
1039         *affects_list = NULL;
1040 }
1041
1042 /*!
1043  * @brief アーティファクトの種族スレイ特性を構造体に収める /
1044  * Note the slaying specialties of a weapon
1045  * @param o_ptr オブジェクト構造体の参照ポインタ
1046  * @param slay_list 種族スレイ構造体の参照ポインタ
1047  * @return なし
1048  */
1049 static void analyze_slay(object_type *o_ptr, concptr *slay_list)
1050 {
1051         BIT_FLAGS flgs[TR_FLAG_SIZE];
1052
1053         object_flags(o_ptr, flgs);
1054
1055         slay_list = spoiler_flag_aux(flgs, slay_flags_desc, slay_list,
1056                 N_ELEMENTS(slay_flags_desc));
1057
1058         /* Terminate the description list */
1059         *slay_list = NULL;
1060 }
1061
1062
1063 /*!
1064  * @brief アーティファクトの属性ブランド特性を構造体に収める /
1065  * Note an object's elemental brands
1066  * @param o_ptr オブジェクト構造体の参照ポインタ
1067  * @param brand_list 属性ブランド構造体の参照ポインタ
1068  * @return なし
1069  */
1070 static void analyze_brand(object_type *o_ptr, concptr *brand_list)
1071 {
1072         BIT_FLAGS flgs[TR_FLAG_SIZE];
1073
1074         object_flags(o_ptr, flgs);
1075
1076         brand_list = spoiler_flag_aux(flgs, brand_flags_desc, brand_list,
1077                 N_ELEMENTS(brand_flags_desc));
1078
1079         /* Terminate the description list */
1080         *brand_list = NULL;
1081 }
1082
1083
1084 /*!
1085  * @brief アーティファクトの通常耐性を構造体に収める /
1086  * Note an object's elemental brands
1087  * @param o_ptr オブジェクト構造体の参照ポインタ
1088  * @param resist_list 通常耐性構造体の参照ポインタ
1089  * @return なし
1090  */
1091 static void analyze_resist(object_type *o_ptr, concptr *resist_list)
1092 {
1093         BIT_FLAGS flgs[TR_FLAG_SIZE];
1094
1095         object_flags(o_ptr, flgs);
1096
1097         resist_list = spoiler_flag_aux(flgs, resist_flags_desc,
1098                 resist_list, N_ELEMENTS(resist_flags_desc));
1099
1100         /* Terminate the description list */
1101         *resist_list = NULL;
1102 }
1103
1104
1105 /*!
1106  * @brief アーティファクトの免疫特性を構造体に収める /
1107  * Note the immunities granted by an object
1108  * @param o_ptr オブジェクト構造体の参照ポインタ
1109  * @param immune_list 免疫構造体の参照ポインタ
1110  * @return なし
1111  */
1112 static void analyze_immune(object_type *o_ptr, concptr *immune_list)
1113 {
1114         BIT_FLAGS flgs[TR_FLAG_SIZE];
1115
1116         object_flags(o_ptr, flgs);
1117
1118         immune_list = spoiler_flag_aux(flgs, immune_flags_desc,
1119                 immune_list, N_ELEMENTS(immune_flags_desc));
1120
1121         /* Terminate the description list */
1122         *immune_list = NULL;
1123 }
1124
1125
1126 /*!
1127  * @brief アーティファクトの維持特性を構造体に収める /
1128  * Note which stats an object sustains
1129  * @param o_ptr オブジェクト構造体の参照ポインタ
1130  * @param sustain_list 維持特性構造体の参照ポインタ
1131  * @return なし
1132  */
1133 static void analyze_sustains(object_type *o_ptr, concptr *sustain_list)
1134 {
1135         BIT_FLAGS flgs[TR_FLAG_SIZE];
1136
1137         object_flags(o_ptr, flgs);
1138
1139         /* Simplify things if an item sustains all stats */
1140         if (have_flag(flgs, TR_SUST_STR) && have_flag(flgs, TR_SUST_INT) &&
1141                 have_flag(flgs, TR_SUST_WIS) && have_flag(flgs, TR_SUST_DEX) &&
1142                 have_flag(flgs, TR_SUST_CON) && have_flag(flgs, TR_SUST_CHR))
1143         {
1144                 *sustain_list++ = _("全能力", "All stats");
1145         }
1146
1147         /* Should we bother? */
1148         else if (have_flag(flgs, TR_SUST_STR) || have_flag(flgs, TR_SUST_INT) ||
1149                 have_flag(flgs, TR_SUST_WIS) || have_flag(flgs, TR_SUST_DEX) ||
1150                 have_flag(flgs, TR_SUST_CON) || have_flag(flgs, TR_SUST_CHR))
1151         {
1152                 sustain_list = spoiler_flag_aux(flgs, sustain_flags_desc,
1153                         sustain_list,
1154                         N_ELEMENTS(sustain_flags_desc));
1155         }
1156
1157         /* Terminate the description list */
1158         *sustain_list = NULL;
1159 }
1160
1161
1162 /*!
1163  * @brief アーティファクトのその他の特性を構造体に収める /
1164  * Note miscellaneous powers bestowed by an artifact such as see invisible,
1165  * free action, permanent light, etc.
1166  * @param o_ptr オブジェクト構造体の参照ポインタ
1167  * @param misc_list その他の特性構造体の参照ポインタ
1168  * @return なし
1169  */
1170 static void analyze_misc_magic(object_type *o_ptr, concptr *misc_list)
1171 {
1172         BIT_FLAGS flgs[TR_FLAG_SIZE];
1173         POSITION rad;
1174         char desc[256];
1175
1176         object_flags(o_ptr, flgs);
1177
1178         misc_list = spoiler_flag_aux(flgs, misc_flags2_desc, misc_list,
1179                 N_ELEMENTS(misc_flags2_desc));
1180
1181         misc_list = spoiler_flag_aux(flgs, misc_flags3_desc, misc_list, N_ELEMENTS(misc_flags3_desc));
1182
1183         /*
1184          * Glowing artifacts -- small radius light.
1185         */
1186         rad = 0;
1187         if (have_flag(flgs, TR_LITE_1))  rad += 1;
1188         if (have_flag(flgs, TR_LITE_2))  rad += 2;
1189         if (have_flag(flgs, TR_LITE_3))  rad += 3;
1190         if (have_flag(flgs, TR_LITE_M1)) rad -= 1;
1191         if (have_flag(flgs, TR_LITE_M2)) rad -= 2;
1192         if (have_flag(flgs, TR_LITE_M3)) rad -= 3;
1193
1194         if (o_ptr->name2 == EGO_LITE_SHINE) rad++;
1195
1196         if (have_flag(flgs, TR_LITE_FUEL))
1197         {
1198                 if (rad > 0) sprintf(desc, _("それは燃料補給によって明かり(半径 %d)を授ける。", "It provides light (radius %d) when fueled."), (int)rad);
1199         }
1200         else
1201         {
1202                 if (rad > 0) sprintf(desc, _("永久光源(半径 %d)", "Permanent Light(radius %d)"), (int)rad);
1203                 if (rad < 0) sprintf(desc, _("永久光源(半径-%d)。", "Permanent Light(radius -%d)"), (int)-rad);
1204         }
1205
1206         if (rad != 0) *misc_list++ = quark_str(quark_add(desc));
1207
1208         /*
1209          * Handle cursed objects here to avoid redundancies such as noting
1210          * that a permanently cursed object is heavily cursed as well as
1211          * being "lightly cursed".
1212          */
1213
1214          /*     if (object_is_cursed(o_ptr)) */
1215         {
1216                 if (have_flag(flgs, TR_TY_CURSE))
1217                 {
1218                         *misc_list++ = _("太古の怨念", "Ancient Curse");
1219                 }
1220                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1221                 {
1222                         *misc_list++ = _("永遠の呪い", "Permanently Cursed");
1223                 }
1224                 else if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
1225                 {
1226                         *misc_list++ = _("強力な呪い", "Heavily Cursed");
1227                 }
1228                 /*              else */
1229                 else if (o_ptr->curse_flags & TRC_CURSED)
1230                 {
1231                         *misc_list++ = _("呪い", "Cursed");
1232                 }
1233                 if (have_flag(flgs, TR_ADD_L_CURSE))
1234                 {
1235                         *misc_list++ = _("呪いを増やす", "Cursing");
1236                 }
1237                 if (have_flag(flgs, TR_ADD_H_CURSE))
1238                 {
1239                         *misc_list++ = _("強力な呪いを増やす", "Heavily Cursing");
1240                 }
1241         }
1242
1243         /* Terminate the description list */
1244         *misc_list = NULL;
1245 }
1246
1247
1248 /*!
1249  * @brief アーティファクトの追加ランダム特性を構造体に収める /
1250  * Note additional ability and/or resistance of fixed artifacts
1251  * @param o_ptr オブジェクト構造体の参照ポインタ
1252  * @param addition 追加ランダム耐性構造体の参照ポインタ
1253  * @return なし
1254  */
1255 static void analyze_addition(object_type *o_ptr, char *addition)
1256 {
1257         artifact_type *a_ptr = &a_info[o_ptr->name1];
1258
1259         /* Init */
1260         strcpy(addition, "");
1261
1262         if ((a_ptr->gen_flags & TRG_XTRA_POWER) && (a_ptr->gen_flags & TRG_XTRA_H_RES)) strcat(addition, _("能力and耐性", "Ability and Resistance"));
1263         else if (a_ptr->gen_flags & TRG_XTRA_POWER)
1264         {
1265                 strcat(addition, _("能力", "Ability"));
1266                 if (a_ptr->gen_flags & TRG_XTRA_RES_OR_POWER) strcat(addition, _("(1/2でand耐性)", "(plus Resistance about 1/2)"));
1267         }
1268         else if (a_ptr->gen_flags & TRG_XTRA_H_RES)
1269         {
1270                 strcat(addition, _("耐性", "Resistance"));
1271                 if (a_ptr->gen_flags & TRG_XTRA_RES_OR_POWER) strcat(addition, _("(1/2でand能力)", "(plus Ability about 1/2)"));
1272         }
1273         else if (a_ptr->gen_flags & TRG_XTRA_RES_OR_POWER) strcat(addition, _("能力or耐性", "Ability or Resistance"));
1274 }
1275
1276
1277 /*!
1278  * @brief アーティファクトの基本情報を文字列に収める /
1279  * Determine the minimum depth an artifact can appear, its rarity, its weight,
1280  * and its value in gold pieces
1281  * @param o_ptr オブジェクト構造体の参照ポインタ
1282  * @param misc_desc 基本情報を収める文字列参照ポインタ
1283  * @return なし
1284  */
1285 static void analyze_misc(object_type *o_ptr, char *misc_desc)
1286 {
1287         artifact_type *a_ptr = &a_info[o_ptr->name1];
1288
1289         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,
1290 #ifdef JP
1291                 lbtokg1(a_ptr->weight), lbtokg2(a_ptr->weight), (long int)a_ptr->cost);
1292 #else
1293                 a_ptr->weight / 10, a_ptr->weight % 10, (long int)a_ptr->cost);
1294 #endif
1295 }
1296
1297
1298 /*!
1299  * @brief アーティファクトの情報全体を構造体に収める /
1300  * Fill in an object description structure for a given object
1301  * and its value in gold pieces
1302  * @param player_ptr プレーヤーへの参照ポインタ
1303  * @param o_ptr オブジェクト構造体の参照ポインタ
1304  * @param desc_ptr 全アーティファクト情報を収める文字列参照ポインタ
1305  * @return なし
1306  */
1307 static void object_analyze(player_type *player_ptr, object_type *o_ptr, obj_desc_list *desc_ptr)
1308 {
1309         analyze_general(player_ptr, o_ptr, desc_ptr->description);
1310         analyze_pval(o_ptr, &desc_ptr->pval_info);
1311         analyze_brand(o_ptr, desc_ptr->brands);
1312         analyze_slay(o_ptr, desc_ptr->slays);
1313         analyze_immune(o_ptr, desc_ptr->immunities);
1314         analyze_resist(o_ptr, desc_ptr->resistances);
1315         analyze_sustains(o_ptr, desc_ptr->sustains);
1316         analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
1317         analyze_addition(o_ptr, desc_ptr->addition);
1318         analyze_misc(o_ptr, desc_ptr->misc_desc);
1319         desc_ptr->activation = activation_explanation(o_ptr);
1320 }
1321
1322
1323 /*!
1324  * @brief バッファにアーティファクト出力情報ヘッダを収める /
1325  * @return なし
1326  */
1327 static void print_header(void)
1328 {
1329         char buf[80];
1330
1331         sprintf(buf, "Artifact Spoilers for Hengband Version %d.%d.%d", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1332         spoiler_underline(buf);
1333 }
1334
1335 /*
1336  * This is somewhat ugly.
1337  *
1338  * Given a header ("Resist", e.g.), a list ("Fire", "Cold", Acid", e.g.),
1339  * and a separator character (',', e.g.), write the list to the spoiler file
1340  * in a "nice" format, such as:
1341  *
1342  *      Resist Fire, Cold, Acid
1343  *
1344  * That was a simple example, but when the list is long, a line wrap
1345  * should occur, and this should induce a new level of indention if
1346  * a list is being spread across lines. So for example, Bladeturner's
1347  * list of resistances should look something like this
1348  *
1349  *     Resist Acid, Lightning, Fire, Cold, Poison, Light, Dark, Blindness,
1350  *       Confusion, Sound, Shards, Nether, Nexus, Chaos, Disenchantment
1351  *
1352  * However, the code distinguishes between a single list of many items vs.
1353  * many lists. (The separator is used to make this determination.) A single
1354  * list of many items will not cause line wrapping (since there is no
1355  * apparent reason to do so). So the lists of Ulmo's miscellaneous traits
1356  * might look like this:
1357  *
1358  *     Free Action; Hold Life; See Invisible; Slow Digestion; Regeneration
1359  *     Blessed Blade
1360  *
1361  * So comparing the two, "Regeneration" has no trailing separator and
1362  * "Blessed Blade" was not indented. (Also, Ulmo's lists have no headers,
1363  * but that's not relevant to line wrapping and indention.)
1364  */
1365
1366  /* ITEM_SEP separates items within a list */
1367 #define ITEM_SEP ','
1368
1369
1370 /* LIST_SEP separates lists */
1371 #ifdef JP
1372 #define LIST_SEP ','
1373 #else
1374 #define LIST_SEP ';'
1375 #endif
1376
1377 /*!
1378  * @brief フラグ名称を出力する汎用関数
1379  * @param header ヘッダに出力するフラグ群の名前
1380  * @param list フラグ名リスト
1381  * @param separator フラグ表示の区切り記号
1382  * @return なし
1383  */
1384 static void spoiler_outlist(concptr header, concptr *list, char separator)
1385 {
1386         int line_len, buf_len;
1387         char line[MAX_LINE_LEN + 1], buf[80];
1388
1389         /* Ignore an empty list */
1390         if (*list == NULL) return;
1391
1392         /* This function always indents */
1393         strcpy(line, INDENT1);
1394
1395         /* Create header (if one was given) */
1396         if (header && (header[0]))
1397         {
1398                 strcat(line, header);
1399                 strcat(line, " ");
1400         }
1401
1402         line_len = strlen(line);
1403
1404         /* Now begin the tedious task */
1405         while (TRUE)
1406         {
1407                 /* Copy the current item to a buffer */
1408                 strcpy(buf, *list);
1409
1410                 /* Note the buffer's length */
1411                 buf_len = strlen(buf);
1412
1413                 /*
1414                  * If there is an item following this one, pad with separator and
1415                  * a space and adjust the buffer length
1416                  */
1417
1418                 if (list[1])
1419                 {
1420                         sprintf(buf + buf_len, "%c ", separator);
1421                         buf_len += 2;
1422                 }
1423
1424                 /*
1425                  * If the buffer will fit on the current line, just append the
1426                  * buffer to the line and adjust the line length accordingly.
1427                  */
1428
1429                 if (line_len + buf_len <= MAX_LINE_LEN)
1430                 {
1431                         strcat(line, buf);
1432                         line_len += buf_len;
1433                 }
1434
1435                 /* Apply line wrapping and indention semantics described above */
1436                 else
1437                 {
1438                         /*
1439                          * Don't print a trailing list separator but do print a trailing
1440                          * item separator.
1441                          */
1442                         if (line_len > 1 && line[line_len - 1] == ' '
1443                                 && line[line_len - 2] == LIST_SEP)
1444                         {
1445                                 /* Ignore space and separator */
1446                                 line[line_len - 2] = '\0';
1447
1448                                 /* Write to spoiler file */
1449                                 fprintf(fff, "%s\n", line);
1450
1451                                 /* Begin new line at primary indention level */
1452                                 sprintf(line, "%s%s", INDENT1, buf);
1453                         }
1454
1455                         else
1456                         {
1457                                 /* Write to spoiler file */
1458                                 fprintf(fff, "%s\n", line);
1459
1460                                 /* Begin new line at secondary indention level */
1461                                 sprintf(line, "%s%s", INDENT2, buf);
1462                         }
1463
1464                         line_len = strlen(line);
1465                 }
1466
1467                 /* Advance, with break */
1468                 if (!*++list) break;
1469         }
1470
1471         /* Write what's left to the spoiler file */
1472         fprintf(fff, "%s\n", line);
1473 }
1474
1475 /*!
1476  * @brief アーティファクト一件をスポイラー出力する /
1477  * Create a spoiler file entry for an artifact
1478  * @param art_ptr アーティファクト情報をまとめた構造体の参照ポインタ
1479  * @return なし
1480  */
1481 static void spoiler_print_art(obj_desc_list *art_ptr)
1482 {
1483         pval_info_type *pval_ptr = &art_ptr->pval_info;
1484         char buf[80];
1485
1486         /* Don't indent the first line */
1487         fprintf(fff, "%s\n", art_ptr->description);
1488
1489         /* An "empty" pval description indicates that the pval affects nothing */
1490         if (pval_ptr->pval_desc[0])
1491         {
1492                 /* Mention the effects of pval */
1493                 sprintf(buf, _("%sの修正:", "%s to"), pval_ptr->pval_desc);
1494                 spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
1495         }
1496
1497         /* Now deal with the description lists */
1498         spoiler_outlist(_("対:", "Slay"), art_ptr->slays, ITEM_SEP);
1499         spoiler_outlist(_("武器属性:", ""), art_ptr->brands, LIST_SEP);
1500         spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, ITEM_SEP);
1501         spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, ITEM_SEP);
1502         spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, ITEM_SEP);
1503         spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
1504
1505         if (art_ptr->addition[0])
1506         {
1507                 fprintf(fff, _("%s追加: %s\n", "%sAdditional %s\n"), INDENT1, art_ptr->addition);
1508         }
1509
1510         /* Write out the possible activation at the primary indention level */
1511         if (art_ptr->activation)
1512         {
1513                 fprintf(fff, _("%s発動: %s\n", "%sActivates for %s\n"), INDENT1, art_ptr->activation);
1514         }
1515
1516         /* End with the miscellaneous facts */
1517         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
1518 }
1519
1520
1521 /*!
1522  * @brief アーティファクト情報を出力するためにダミー生成を行う /
1523  * Hack -- Create a "forged" artifact
1524  * @param o_ptr 一時生成先を保管するオブジェクト構造体
1525  * @param name1 生成するアーティファクトID
1526  * @return 生成が成功した場合TRUEを返す
1527  */
1528 static bool make_fake_artifact(object_type *o_ptr, IDX name1)
1529 {
1530         OBJECT_IDX i;
1531         artifact_type *a_ptr = &a_info[name1];
1532
1533         /* Ignore "empty" artifacts */
1534         if (!a_ptr->name) return FALSE;
1535
1536         /* Acquire the "kind" index */
1537         i = lookup_kind(a_ptr->tval, a_ptr->sval);
1538
1539         if (!i) return FALSE;
1540
1541         object_prep(o_ptr, i);
1542
1543         /* Save the name */
1544         o_ptr->name1 = (byte)name1;
1545
1546         /* Extract the fields */
1547         o_ptr->pval = a_ptr->pval;
1548         o_ptr->ac = a_ptr->ac;
1549         o_ptr->dd = a_ptr->dd;
1550         o_ptr->ds = a_ptr->ds;
1551         o_ptr->to_a = a_ptr->to_a;
1552         o_ptr->to_h = a_ptr->to_h;
1553         o_ptr->to_d = a_ptr->to_d;
1554         o_ptr->weight = a_ptr->weight;
1555
1556         /* Success */
1557         return TRUE;
1558 }
1559
1560
1561 /*!
1562  * @brief アーティファクト情報のスポイラー出力を行うメインルーチン /
1563  * Create a spoiler file for artifacts
1564  * @param player_ptr プレーヤーへの参照ポインタ
1565  * @param fname 生成ファイル名
1566  * @return なし
1567  */
1568 static void spoil_artifact(player_type *player_ptr, concptr fname)
1569 {
1570         int i;
1571         IDX j;
1572
1573         object_type forge;
1574         object_type *q_ptr;
1575         obj_desc_list artifact;
1576         char buf[1024];
1577         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1578
1579         fff = my_fopen(buf, "w");
1580
1581         if (!fff)
1582         {
1583                 msg_print("Cannot create spoiler file.");
1584                 return;
1585         }
1586
1587         /* Dump the header */
1588         print_header();
1589
1590         /* List the artifacts by tval */
1591         for (i = 0; group_artifact[i].tval; i++)
1592         {
1593                 /* Write out the group title */
1594                 if (group_artifact[i].name)
1595                 {
1596                         spoiler_blanklines(2);
1597                         spoiler_underline(group_artifact[i].name);
1598                         spoiler_blanklines(1);
1599                 }
1600
1601                 /* Now search through all of the artifacts */
1602                 for (j = 1; j < max_a_idx; ++j)
1603                 {
1604                         artifact_type *a_ptr = &a_info[j];
1605
1606                         /* We only want objects in the current group */
1607                         if (a_ptr->tval != group_artifact[i].tval) continue;
1608                         q_ptr = &forge;
1609                         object_wipe(q_ptr);
1610
1611                         /* Attempt to "forge" the artifact */
1612                         if (!make_fake_artifact(q_ptr, j)) continue;
1613
1614                         /* Analyze the artifact */
1615                         object_analyze(player_ptr, q_ptr, &artifact);
1616
1617                         /* Write out the artifact description to the spoiler file */
1618                         spoiler_print_art(&artifact);
1619                 }
1620         }
1621
1622         /* Check for errors */
1623         if (ferror(fff) || my_fclose(fff))
1624         {
1625                 msg_print("Cannot close spoiler file.");
1626                 return;
1627         }
1628
1629         msg_print("Successfully created a spoiler file.");
1630 }
1631
1632
1633 /*!
1634  * @brief モンスター簡易情報のスポイラー出力を行うメインルーチン /
1635  * Create a spoiler file for monsters   -BEN-
1636  * @param fname 生成ファイル名
1637  * @return なし
1638  */
1639 static void spoil_mon_desc(concptr fname)
1640 {
1641         int i, n = 0;
1642
1643         u16b why = 2;
1644         MONRACE_IDX *who;
1645
1646         char buf[1024];
1647
1648         char nam[80];
1649         char lev[80];
1650         char rar[80];
1651         char spd[80];
1652         char ac[80];
1653         char hp[80];
1654         char exp[80];
1655         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1656
1657         fff = my_fopen(buf, "w");
1658         if (!fff)
1659         {
1660                 msg_print("Cannot create spoiler file.");
1661                 return;
1662         }
1663
1664         /* Allocate the "who" array */
1665         C_MAKE(who, max_r_idx, MONRACE_IDX);
1666
1667         /* Dump the header */
1668         fprintf(fff, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1669                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1670         fprintf(fff, "------------------------------------------\n\n");
1671
1672         /* Dump the header */
1673         fprintf(fff, "    %-38.38s%4s%4s%4s%7s%5s  %11.11s\n",
1674                 "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info");
1675         fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1676                 "--------", "---", "---", "---", "--", "--", "-----------");
1677
1678
1679         /* Scan the monsters */
1680         for (i = 1; i < max_r_idx; i++)
1681         {
1682                 monster_race *r_ptr = &r_info[i];
1683
1684                 /* Use that monster */
1685                 if (r_ptr->name) who[n++] = (s16b)i;
1686         }
1687
1688         /* Sort the array by dungeon depth of monsters */
1689         ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
1690
1691         /* Scan again */
1692         for (i = 0; i < n; i++)
1693         {
1694                 monster_race *r_ptr = &r_info[who[i]];
1695
1696                 concptr name = (r_name + r_ptr->name);
1697                 if (r_ptr->flags7 & (RF7_KAGE)) continue;
1698
1699                 /* Get the "name" */
1700                 /*
1701                 else if (r_ptr->flags3 & (RF3_NO_CONF))
1702                 {
1703                         sprintf(nam, "[*] %s", name);
1704                 }
1705                 */
1706                 else if (r_ptr->flags1 & (RF1_UNIQUE))
1707                 {
1708                         sprintf(nam, "[U] %s", name);
1709                 }
1710                 else
1711                 {
1712                         sprintf(nam, _("    %s", "The %s"), name);
1713                 }
1714
1715                 /* Level */
1716                 sprintf(lev, "%d", (int)r_ptr->level);
1717
1718                 /* Rarity */
1719                 sprintf(rar, "%d", (int)r_ptr->rarity);
1720
1721                 if (r_ptr->speed >= 110)
1722                 {
1723                         sprintf(spd, "+%d", (r_ptr->speed - 110));
1724                 }
1725                 else
1726                 {
1727                         sprintf(spd, "-%d", (110 - r_ptr->speed));
1728                 }
1729
1730                 /* Armor Class */
1731                 sprintf(ac, "%d", r_ptr->ac);
1732
1733                 /* Hitpoints */
1734                 if ((r_ptr->flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
1735                 {
1736                         sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside);
1737                 }
1738                 else
1739                 {
1740                         sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside);
1741                 }
1742
1743
1744                 /* Experience */
1745                 sprintf(exp, "%ld", (long)(r_ptr->mexp));
1746
1747                 /* Hack -- use visual instead */
1748                 sprintf(exp, "%s '%c'", attr_to_text(r_ptr), r_ptr->d_char);
1749
1750                 /* Dump the info */
1751                 fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1752                         nam, lev, rar, spd, hp, ac, exp);
1753         }
1754
1755         /* End it */
1756         fprintf(fff, "\n");
1757
1758
1759         /* Free the "who" array */
1760         C_KILL(who, max_r_idx, s16b);
1761
1762         /* Check for errors */
1763         if (ferror(fff) || my_fclose(fff))
1764         {
1765                 msg_print("Cannot close spoiler file.");
1766                 return;
1767         }
1768
1769         /* Worked */
1770         msg_print("Successfully created a spoiler file.");
1771 }
1772
1773
1774
1775
1776 /*
1777  * Monster spoilers by: smchorse@ringer.cs.utsa.edu (Shawn McHorse)
1778  *
1779  * Primarily based on code already in mon-desc.c, mostly by -BEN-
1780  */
1781
1782
1783
1784  /*!
1785   * @brief 文字列をファイルポインタに出力する /
1786   * Buffer text to the given file. (-SHAWN-)
1787   * This is basically c_roff() from mon-desc.c with a few changes.
1788   * @param str 文字列参照ポインタ
1789   * @return なし
1790   */
1791 static void spoil_out(concptr str)
1792 {
1793         concptr r;
1794
1795         /* Line buffer */
1796         static char roff_buf[256];
1797
1798         /* Delay buffer */
1799         static char roff_waiting_buf[256];
1800
1801 #ifdef JP
1802         bool iskanji_flag = FALSE;
1803 #endif
1804         /* Current pointer into line roff_buf */
1805         static char *roff_p = roff_buf;
1806
1807         /* Last space saved into roff_buf */
1808         static char *roff_s = NULL;
1809
1810         /* Mega-Hack -- Delayed output */
1811         static bool waiting_output = FALSE;
1812
1813         /* Special handling for "new sequence" */
1814         if (!str)
1815         {
1816                 if (waiting_output)
1817                 {
1818                         fputs(roff_waiting_buf, fff);
1819                         waiting_output = FALSE;
1820                 }
1821
1822                 if (roff_p != roff_buf) roff_p--;
1823                 while (*roff_p == ' ' && roff_p != roff_buf) roff_p--;
1824
1825                 if (roff_p == roff_buf) fprintf(fff, "\n");
1826                 else
1827                 {
1828                         *(roff_p + 1) = '\0';
1829                         fprintf(fff, "%s\n\n", roff_buf);
1830                 }
1831
1832                 roff_p = roff_buf;
1833                 roff_s = NULL;
1834                 roff_buf[0] = '\0';
1835                 return;
1836         }
1837
1838         /* Scan the given string, character at a time */
1839         for (; *str; str++)
1840         {
1841 #ifdef JP
1842                 char cbak;
1843                 bool k_flag = iskanji((unsigned char)(*str));
1844 #endif
1845                 char ch = *str;
1846                 bool wrap = (ch == '\n');
1847
1848 #ifdef JP
1849                 if (!isprint((unsigned char)ch) && !k_flag && !iskanji_flag) ch = ' ';
1850                 iskanji_flag = k_flag && !iskanji_flag;
1851 #else
1852                 if (!isprint(ch)) ch = ' ';
1853 #endif
1854
1855                 if (waiting_output)
1856                 {
1857                         fputs(roff_waiting_buf, fff);
1858                         if (!wrap) fputc('\n', fff);
1859                         waiting_output = FALSE;
1860                 }
1861
1862                 if (!wrap)
1863                 {
1864 #ifdef JP
1865                         if (roff_p >= roff_buf + (k_flag ? 74 : 75)) wrap = TRUE;
1866                         else if ((ch == ' ') && (roff_p >= roff_buf + (k_flag ? 72 : 73))) wrap = TRUE;
1867 #else
1868                         if (roff_p >= roff_buf + 75) wrap = TRUE;
1869                         else if ((ch == ' ') && (roff_p >= roff_buf + 73)) wrap = TRUE;
1870 #endif
1871
1872                         if (wrap)
1873                         {
1874 #ifdef JP
1875                                 bool k_flag_local;
1876                                 bool iskanji_flag_local = FALSE;
1877                                 concptr tail = str + (k_flag ? 2 : 1);
1878 #else
1879                                 concptr tail = str + 1;
1880 #endif
1881
1882                                 for (; *tail; tail++)
1883                                 {
1884                                         if (*tail == ' ') continue;
1885
1886 #ifdef JP
1887                                         k_flag_local = iskanji((unsigned char)(*tail));
1888                                         if (isprint((unsigned char)*tail) || k_flag_local || iskanji_flag_local) break;
1889                                         iskanji_flag_local = k_flag_local && !iskanji_flag_local;
1890 #else
1891                                         if (isprint(*tail)) break;
1892 #endif
1893                                 }
1894
1895                                 if (!*tail) waiting_output = TRUE;
1896                         }
1897                 }
1898
1899                 /* Handle line-wrap */
1900                 if (wrap)
1901                 {
1902                         *roff_p = '\0';
1903                         r = roff_p;
1904 #ifdef JP
1905                         cbak = ' ';
1906 #endif
1907                         if (roff_s && (ch != ' '))
1908                         {
1909 #ifdef JP
1910                                 cbak = *roff_s;
1911 #endif
1912                                 *roff_s = '\0';
1913                                 r = roff_s + 1;
1914                         }
1915                         if (!waiting_output) fprintf(fff, "%s\n", roff_buf);
1916                         else strcpy(roff_waiting_buf, roff_buf);
1917                         roff_s = NULL;
1918                         roff_p = roff_buf;
1919 #ifdef JP
1920                         if (cbak != ' ') *roff_p++ = cbak;
1921 #endif
1922                         while (*r) *roff_p++ = *r++;
1923                 }
1924
1925                 /* Save the char */
1926                 if ((roff_p > roff_buf) || (ch != ' '))
1927                 {
1928 #ifdef JP
1929                         if (!k_flag)
1930                         {
1931                                 if ((ch == ' ') || (ch == '(')) roff_s = roff_p;
1932                         }
1933                         else
1934                         {
1935                                 if (iskanji_flag &&
1936                                         strncmp(str, "。", 2) != 0 &&
1937                                         strncmp(str, "、", 2) != 0 &&
1938                                         strncmp(str, "ィ", 2) != 0 &&
1939                                         strncmp(str, "ー", 2) != 0) roff_s = roff_p;
1940                         }
1941 #else
1942                         if (ch == ' ') roff_s = roff_p;
1943 #endif
1944
1945                         *roff_p++ = ch;
1946                 }
1947         }
1948 }
1949
1950
1951
1952 /*!
1953  * @brief 関数ポインタ用の出力関数 /
1954  * Hook function used in spoil_mon_info()
1955  * @param attr 未使用
1956  * @param str 文字列参照ポインタ
1957  * @return なし
1958  */
1959 static void roff_func(TERM_COLOR attr, concptr str)
1960 {
1961         /* Unused */
1962         (void)attr;
1963
1964         spoil_out(str);
1965 }
1966
1967
1968 /*!
1969  * @brief モンスター詳細情報をスポイラー出力するメインルーチン /
1970  * Create a spoiler file for monsters (-SHAWN-)
1971  * @param fname ファイル名
1972  * @return なし
1973  */
1974 static void spoil_mon_info(player_type *player_ptr, concptr fname)
1975 {
1976         char buf[1024];
1977         int i, l, n = 0;
1978         BIT_FLAGS flags1;
1979
1980         u16b why = 2;
1981         MONRACE_IDX *who;
1982         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1983
1984         fff = my_fopen(buf, "w");
1985         if (!fff)
1986         {
1987                 msg_print("Cannot create spoiler file.");
1988                 return;
1989         }
1990
1991
1992         /* Dump the header */
1993         sprintf(buf, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1994                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1995
1996         spoil_out(buf);
1997         spoil_out("------------------------------------------\n\n");
1998
1999         /* Allocate the "who" array */
2000         C_MAKE(who, max_r_idx, MONRACE_IDX);
2001
2002         /* Scan the monsters */
2003         for (i = 1; i < max_r_idx; i++)
2004         {
2005                 monster_race *r_ptr = &r_info[i];
2006
2007                 /* Use that monster */
2008                 if (r_ptr->name) who[n++] = (s16b)i;
2009         }
2010
2011         ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
2012
2013         /*
2014          * List all monsters in order
2015          */
2016         for (l = 0; l < n; l++)
2017         {
2018                 monster_race *r_ptr = &r_info[who[l]];
2019                 flags1 = r_ptr->flags1;
2020
2021                 /* Prefix */
2022                 /*
2023                 if (flags1 & (RF1_QUESTOR))
2024                 {
2025                         spoil_out("[Q] ");
2026                 }
2027                 else
2028                 */
2029                 if (flags1 & (RF1_UNIQUE))
2030                 {
2031                         spoil_out("[U] ");
2032                 }
2033                 else
2034                 {
2035 #ifdef JP
2036 #else
2037                         spoil_out("The ");
2038 #endif
2039                 }
2040
2041                 /* Name */
2042                 sprintf(buf, _("%s/%s  (", "%s%s ("), (r_name + r_ptr->name), _(r_name + r_ptr->E_name, ""));  /* ---)--- */
2043
2044                 spoil_out(buf);
2045
2046                 /* Color */
2047                 spoil_out(attr_to_text(r_ptr));
2048
2049                 /* Symbol --(-- */
2050                 sprintf(buf, " '%c')\n", r_ptr->d_char);
2051                 spoil_out(buf);
2052
2053
2054                 /* Indent */
2055                 sprintf(buf, "=== ");
2056                 spoil_out(buf);
2057
2058                 /* Number */
2059                 sprintf(buf, "Num:%d  ", who[l]);
2060                 spoil_out(buf);
2061
2062                 /* Level */
2063                 sprintf(buf, "Lev:%d  ", (int)r_ptr->level);
2064                 spoil_out(buf);
2065
2066                 /* Rarity */
2067                 sprintf(buf, "Rar:%d  ", r_ptr->rarity);
2068                 spoil_out(buf);
2069
2070                 if (r_ptr->speed >= 110)
2071                 {
2072                         sprintf(buf, "Spd:+%d  ", (r_ptr->speed - 110));
2073                 }
2074                 else
2075                 {
2076                         sprintf(buf, "Spd:-%d  ", (110 - r_ptr->speed));
2077                 }
2078                 spoil_out(buf);
2079
2080                 /* Hitpoints */
2081                 if ((flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
2082                 {
2083                         sprintf(buf, "Hp:%d  ", r_ptr->hdice * r_ptr->hside);
2084                 }
2085                 else
2086                 {
2087                         sprintf(buf, "Hp:%dd%d  ", r_ptr->hdice, r_ptr->hside);
2088                 }
2089                 spoil_out(buf);
2090
2091                 /* Armor Class */
2092                 sprintf(buf, "Ac:%d  ", r_ptr->ac);
2093                 spoil_out(buf);
2094
2095                 /* Experience */
2096                 sprintf(buf, "Exp:%ld\n", (long)(r_ptr->mexp));
2097                 spoil_out(buf);
2098
2099                 /* Reuse the code of monster recall. */
2100                 output_monster_spoiler(player_ptr, who[l], roff_func);
2101
2102                 spoil_out(NULL);
2103         }
2104
2105         /* Free the "who" array */
2106         C_KILL(who, max_r_idx, s16b);
2107
2108         /* Check for errors */
2109         if (ferror(fff) || my_fclose(fff))
2110         {
2111                 msg_print("Cannot close spoiler file.");
2112                 return;
2113         }
2114
2115         msg_print("Successfully created a spoiler file.");
2116 }
2117
2118
2119
2120 #define MAX_EVOL_DEPTH 64
2121
2122
2123 /*!
2124  * @brief int配列でstrncmp()と似た比較処理を行う /
2125  * Compare two int-type array like strncmp() and return TRUE if equals
2126  * @param a 比較するint配列1
2127  * @param b 比較するint配列2
2128  * @param length
2129  * @return 両者の値が等しければTRUEを返す
2130  */
2131 static bool int_n_cmp(int *a, int *b, int length)
2132 {
2133         /* Null-string comparation is always TRUE */
2134         if (!length) return TRUE;
2135
2136         do
2137         {
2138                 if (*a != *(b++)) return FALSE;
2139                 if (!(*(a++))) break;
2140         } while (--length);
2141
2142         return TRUE;
2143 }
2144
2145
2146 /*!
2147  * @brief ある木が指定された木の部分木かどうかを返す /
2148  * Returns TRUE if an evolution tree is "partial tree"
2149  * @param tree 元となる木構造リスト
2150  * @param partial_tree 部分木かどうか判定したい木構造リスト
2151  * @return 部分木ならばTRUEを返す
2152  */
2153 static bool is_partial_tree(int *tree, int *partial_tree)
2154 {
2155         int pt_head = *(partial_tree++);
2156         int pt_len = 0;
2157
2158         while (partial_tree[pt_len]) pt_len++;
2159
2160         while (*tree)
2161         {
2162                 if (*(tree++) == pt_head)
2163                 {
2164                         if (int_n_cmp(tree, partial_tree, pt_len)) return TRUE;
2165                 }
2166         }
2167
2168         return FALSE;
2169 }
2170
2171 /*!
2172  * @brief 進化ツリーをスポイラー出力するメインルーチン /
2173  * Print monsters' evolution information to file
2174  * @param fname 出力ファイル名
2175  * @return なし
2176  */
2177 static void spoil_mon_evol(concptr fname)
2178 {
2179         char buf[1024];
2180         monster_race *r_ptr;
2181         int **evol_tree, i, j, n, r_idx;
2182         int *evol_tree_zero; /* For C_KILL() */
2183         path_build(buf, sizeof buf, ANGBAND_DIR_USER, fname);
2184
2185         fff = my_fopen(buf, "w");
2186         if (!fff)
2187         {
2188                 msg_print("Cannot create spoiler file.");
2189                 return;
2190         }
2191
2192         /* Dump the header */
2193         sprintf(buf, "Monster Spoilers for Hengband Version %d.%d.%d\n",
2194                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
2195
2196         spoil_out(buf);
2197         spoil_out("------------------------------------------\n\n");
2198
2199         /* Allocate the "evol_tree" array (2-dimension) */
2200         C_MAKE(evol_tree, max_r_idx, int *);
2201         C_MAKE(*evol_tree, max_r_idx * (MAX_EVOL_DEPTH + 1), int);
2202         for (i = 1; i < max_r_idx; i++) evol_tree[i] = *evol_tree + i * (MAX_EVOL_DEPTH + 1);
2203         evol_tree_zero = *evol_tree;
2204
2205         /* Step 1: Build the evolution tree */
2206         for (i = 1; i < max_r_idx; i++)
2207         {
2208                 r_ptr = &r_info[i];
2209
2210                 /* No evolution */
2211                 if (!r_ptr->next_exp) continue;
2212
2213                 /* Trace evolution */
2214                 n = 0;
2215                 evol_tree[i][n++] = i;
2216                 do
2217                 {
2218                         evol_tree[i][n++] = r_ptr->next_r_idx;
2219                         r_ptr = &r_info[r_ptr->next_r_idx];
2220                 } while (r_ptr->next_exp && (n < MAX_EVOL_DEPTH));
2221         }
2222
2223         /* Step 2: Scan the evolution trees and remove "partial tree" */
2224         for (i = 1; i < max_r_idx; i++)
2225         {
2226                 /* Not evolution tree */
2227                 if (!evol_tree[i][0]) continue;
2228
2229                 for (j = 1; j < max_r_idx; j++)
2230                 {
2231                         /* Same tree */
2232                         if (i == j) continue;
2233
2234                         /* Not evolution tree */
2235                         if (!evol_tree[j][0]) continue;
2236
2237                         /* Is evolution tree[i] is part of [j]? */
2238                         if (is_partial_tree(evol_tree[j], evol_tree[i]))
2239                         {
2240                                 /* Remove this evolution tree */
2241                                 evol_tree[i][0] = 0;
2242                                 break;
2243                         }
2244                 }
2245         }
2246
2247         /* Step 3: Sort the evolution trees */
2248         ang_sort(evol_tree, NULL, max_r_idx, ang_sort_comp_evol_tree, ang_sort_swap_evol_tree);
2249
2250         /* Step 4: Print the evolution trees */
2251         for (i = 0; i < max_r_idx; i++)
2252         {
2253                 r_idx = evol_tree[i][0];
2254
2255                 /* No evolution or removed evolution tree */
2256                 if (!r_idx) continue;
2257
2258                 /* Trace the evolution tree */
2259                 r_ptr = &r_info[r_idx];
2260                 fprintf(fff, _("[%d]: %s (レベル%d, '%c')\n", "[%d]: %s (Level %d, '%c')\n"),
2261                         r_idx, r_name + r_ptr->name, (int)r_ptr->level, r_ptr->d_char);
2262
2263                 for (n = 1; r_ptr->next_exp; n++)
2264                 {
2265                         fprintf(fff, "%*s-(%ld)-> ", n * 2, "", (long int)r_ptr->next_exp);
2266                         fprintf(fff, "[%d]: ", r_ptr->next_r_idx);
2267                         r_ptr = &r_info[r_ptr->next_r_idx];
2268                         fprintf(fff, _("%s (レベル%d, '%c')\n", "%s (Level %d, '%c')\n"),
2269                                 r_name + r_ptr->name, (int)r_ptr->level, r_ptr->d_char);
2270                 }
2271
2272                 /* End of evolution tree */
2273                 fputc('\n', fff);
2274         }
2275
2276         /* Free the "evol_tree" array (2-dimension) */
2277         C_KILL(evol_tree_zero, max_r_idx * (MAX_EVOL_DEPTH + 1), int);
2278         C_KILL(evol_tree, max_r_idx, int *);
2279
2280         /* Check for errors */
2281         if (ferror(fff) || my_fclose(fff))
2282         {
2283                 msg_print("Cannot close spoiler file.");
2284                 return;
2285         }
2286
2287         msg_print("Successfully created a spoiler file.");
2288 }
2289
2290
2291 /*!
2292  * @brief スポイラー出力を行うコマンドのメインルーチン /
2293  * Create Spoiler files -BEN-
2294  * @return なし
2295  */
2296 void do_cmd_spoilers(player_type *player_ptr)
2297 {
2298         screen_save();
2299
2300         /* Interact */
2301         while (TRUE)
2302         {
2303                 Term_clear();
2304
2305                 /* Info */
2306                 prt("Create a spoiler file.", 2, 0);
2307
2308                 /* Prompt for a file */
2309                 prt("(1) Brief Object Info (obj-desc.txt)", 5, 5);
2310                 prt("(2) Brief Artifact Info (artifact.txt)", 6, 5);
2311                 prt("(3) Brief Monster Info (mon-desc.txt)", 7, 5);
2312                 prt("(4) Full Monster Info (mon-info.txt)", 8, 5);
2313                 prt("(5) Monster Evolution Info (mon-evol.txt)", 9, 5);
2314
2315                 /* Prompt */
2316                 prt(_("コマンド:", "Command: "), _(18, 12), 0);
2317
2318                 /* Get a choice */
2319                 switch (inkey())
2320                 {
2321                         /* Escape */
2322                 case ESCAPE:
2323                         screen_load();
2324                         return;
2325
2326                         /* Option (1) */
2327                 case '1':
2328                         spoil_obj_desc(player_ptr, "obj-desc.txt");
2329                         break;
2330
2331                         /* Option (2) */
2332                 case '2':
2333                         spoil_artifact(player_ptr, "artifact.txt");
2334                         break;
2335
2336                         /* Option (3) */
2337                 case '3':
2338                         spoil_mon_desc("mon-desc.txt");
2339                         break;
2340
2341                         /* Option (4) */
2342                 case '4':
2343                         spoil_mon_info(player_ptr, "mon-info.txt");
2344                         break;
2345
2346                         /* Option (5) */
2347                 case '5':
2348                         spoil_mon_evol("mon-evol.txt");
2349                         break;
2350
2351                 default:
2352                         bell();
2353                         break;
2354                 }
2355
2356                 msg_erase();
2357         }
2358 }
2359
2360 /*!
2361  * @brief ランダムアーティファクト1件を解析する /
2362  * Fill in an object description structure for a given object
2363  * @param player_ptr プレーヤーへの参照ポインタ
2364  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
2365  * @param desc_ptr 記述内容を収める構造体参照ポインタ
2366  * @return なし
2367  */
2368 static void random_artifact_analyze(player_type *player_ptr, object_type *o_ptr, obj_desc_list *desc_ptr)
2369 {
2370         analyze_general(player_ptr, o_ptr, desc_ptr->description);
2371         analyze_pval(o_ptr, &desc_ptr->pval_info);
2372         analyze_brand(o_ptr, desc_ptr->brands);
2373         analyze_slay(o_ptr, desc_ptr->slays);
2374         analyze_immune(o_ptr, desc_ptr->immunities);
2375         analyze_resist(o_ptr, desc_ptr->resistances);
2376         analyze_sustains(o_ptr, desc_ptr->sustains);
2377         analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
2378         desc_ptr->activation = activation_explanation(o_ptr);
2379 #ifdef JP
2380         sprintf(desc_ptr->misc_desc, "重さ %d.%d kg",
2381                 lbtokg1(o_ptr->weight), lbtokg2(o_ptr->weight));
2382 #else
2383         sprintf(desc_ptr->misc_desc, "Weight %d.%d lbs",
2384                 o_ptr->weight / 10, o_ptr->weight % 10);
2385 #endif
2386 }
2387
2388 /*!
2389  * @brief ランダムアーティファクト1件をスポイラー出力する /
2390  * Create a spoiler file entry for an artifact
2391  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
2392  * @param art_ptr 記述内容を収めた構造体参照ポインタ
2393  * Fill in an object description structure for a given object
2394  * @return なし
2395  */
2396 static void spoiler_print_randart(object_type *o_ptr, obj_desc_list *art_ptr)
2397 {
2398         pval_info_type *pval_ptr = &art_ptr->pval_info;
2399
2400         char buf[80];
2401
2402         /* Don't indent the first line */
2403         fprintf(fff, "%s\n", art_ptr->description);
2404
2405         /* unidentified */
2406         if (!object_is_fully_known(o_ptr))
2407         {
2408                 fprintf(fff, _("%s不明\n", "%sUnknown\n"), INDENT1);
2409         }
2410         else {
2411                 /* An "empty" pval description indicates that the pval affects nothing */
2412                 if (pval_ptr->pval_desc[0])
2413                 {
2414                         /* Mention the effects of pval */
2415                         sprintf(buf, _("%sの修正:", "%s to"), pval_ptr->pval_desc);
2416                         spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
2417                 }
2418
2419                 /* Now deal with the description lists */
2420
2421                 spoiler_outlist(_("対:", "Slay"), art_ptr->slays, ITEM_SEP);
2422                 spoiler_outlist(_("武器属性:", ""), art_ptr->brands, LIST_SEP);
2423                 spoiler_outlist(_("免疫:", "Immunity to"), art_ptr->immunities, ITEM_SEP);
2424                 spoiler_outlist(_("耐性:", "Resist"), art_ptr->resistances, ITEM_SEP);
2425                 spoiler_outlist(_("維持:", "Sustain"), art_ptr->sustains, ITEM_SEP);
2426                 spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
2427
2428                 /* Write out the possible activation at the primary indention level */
2429                 if (art_ptr->activation)
2430                 {
2431                         fprintf(fff, _("%s発動: %s\n", "%sActivates for %s\n"), INDENT1, art_ptr->activation);
2432                 }
2433         }
2434         /* End with the miscellaneous facts */
2435         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
2436 }
2437
2438
2439 /*!
2440  * @brief ランダムアーティファクト内容をスポイラー出力するサブルーチン /
2441  * @param player_ptr プレーヤーへの参照ポインタ
2442  * @param o_ptr ランダムアーティファクトのオブジェクト構造体参照ポインタ
2443  * @param i 出力したい記録ランダムアーティファクトID
2444  * @return なし
2445  */
2446 static void spoil_random_artifact_aux(player_type *player_ptr, object_type *o_ptr, int i)
2447 {
2448         obj_desc_list artifact;
2449
2450         if (!object_is_known(o_ptr) || !o_ptr->art_name
2451                 || o_ptr->tval != group_artifact[i].tval)
2452                 return;
2453
2454         /* Analyze the artifact */
2455         random_artifact_analyze(player_ptr, o_ptr, &artifact);
2456
2457         /* Write out the artifact description to the spoiler file */
2458         spoiler_print_randart(o_ptr, &artifact);
2459 }
2460
2461 /*!
2462  * @brief ランダムアーティファクト内容をスポイラー出力するメインルーチン /
2463  * Create a list file for random artifacts
2464  * @param fname 出力ファイル名
2465  * @return なし
2466  */
2467 void spoil_random_artifact(player_type *creature_ptr, concptr fname)
2468 {
2469         int i, j;
2470
2471         store_type  *store_ptr;
2472         object_type *q_ptr;
2473
2474         char buf[1024];
2475         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2476
2477         fff = my_fopen(buf, "w");
2478         if (!fff)
2479         {
2480                 msg_print("Cannot create list file.");
2481                 return;
2482         }
2483
2484         /* Dump the header */
2485         sprintf(buf, "Random artifacts list.\r");
2486         spoiler_underline(buf);
2487
2488         /* List the artifacts by tval */
2489         for (j = 0; group_artifact[j].tval; j++)
2490         {
2491                 /* random artifacts wielding */
2492                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2493                 {
2494                         q_ptr = &creature_ptr->inventory_list[i];
2495                         spoil_random_artifact_aux(creature_ptr, q_ptr, j);
2496                 }
2497
2498                 for (i = 0; i < INVEN_PACK; i++)
2499                 {
2500                         q_ptr = &creature_ptr->inventory_list[i];
2501                         spoil_random_artifact_aux(creature_ptr, q_ptr, j);
2502                 }
2503
2504                 /* random artifacts in home */
2505                 store_ptr = &town_info[1].store[STORE_HOME];
2506                 for (i = 0; i < store_ptr->stock_num; i++)
2507                 {
2508                         q_ptr = &store_ptr->stock[i];
2509                         spoil_random_artifact_aux(creature_ptr, q_ptr, j);
2510                 }
2511
2512                 /* random artifacts in museum */
2513                 store_ptr = &town_info[1].store[STORE_MUSEUM];
2514                 for (i = 0; i < store_ptr->stock_num; i++)
2515                 {
2516                         q_ptr = &store_ptr->stock[i];
2517                         spoil_random_artifact_aux(creature_ptr, q_ptr, j);
2518                 }
2519         }
2520
2521         /* Check for errors */
2522         if (ferror(fff) || my_fclose(fff))
2523         {
2524                 msg_print("Cannot close list file.");
2525                 return;
2526         }
2527
2528         msg_print("Successfully created a list file.");
2529 }