OSDN Git Service

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