OSDN Git Service

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