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