OSDN Git Service

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