OSDN Git Service

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