OSDN Git Service

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