OSDN Git Service

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