OSDN Git Service

クエスト達成時に, 階段が鏡の上(下?)に作られるのを禁止.
[hengbandforosx/hengbandosx.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         sprintf(buf, "Artifact Spoilers for Hengband Version %d.%d.%d",
1286                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1287         spoiler_underline(buf);
1288 }
1289
1290 /*
1291  * This is somewhat ugly.
1292  *
1293  * Given a header ("Resist", e.g.), a list ("Fire", "Cold", Acid", e.g.),
1294  * and a separator character (',', e.g.), write the list to the spoiler file
1295  * in a "nice" format, such as:
1296  *
1297  *      Resist Fire, Cold, Acid
1298  *
1299  * That was a simple example, but when the list is long, a line wrap
1300  * should occur, and this should induce a new level of indention if
1301  * a list is being spread across lines. So for example, Bladeturner's
1302  * list of resistances should look something like this
1303  *
1304  *     Resist Acid, Lightning, Fire, Cold, Poison, Light, Dark, Blindness,
1305  *       Confusion, Sound, Shards, Nether, Nexus, Chaos, Disenchantment
1306  *
1307  * However, the code distinguishes between a single list of many items vs.
1308  * many lists. (The separator is used to make this determination.) A single
1309  * list of many items will not cause line wrapping (since there is no
1310  * apparent reason to do so). So the lists of Ulmo's miscellaneous traits
1311  * might look like this:
1312  *
1313  *     Free Action; Hold Life; See Invisible; Slow Digestion; Regeneration
1314  *     Blessed Blade
1315  *
1316  * So comparing the two, "Regeneration" has no trailing separator and
1317  * "Blessed Blade" was not indented. (Also, Ulmo's lists have no headers,
1318  * but that's not relevant to line wrapping and indention.)
1319  */
1320
1321 /* ITEM_SEP separates items within a list */
1322 #define ITEM_SEP ','
1323
1324
1325 /* LIST_SEP separates lists */
1326 #ifdef JP
1327 #define LIST_SEP ','
1328 #else
1329 #define LIST_SEP ';'
1330 #endif
1331
1332 static void spoiler_outlist(cptr header, cptr *list, char separator)
1333 {
1334         int line_len, buf_len;
1335         char line[MAX_LINE_LEN+1], buf[80];
1336
1337         /* Ignore an empty list */
1338         if (*list == NULL) return;
1339
1340         /* This function always indents */
1341         strcpy(line, INDENT1);
1342
1343         /* Create header (if one was given) */
1344         if (header && (header[0]))
1345         {
1346                 strcat(line, header);
1347                 strcat(line, " ");
1348         }
1349
1350         line_len = strlen(line);
1351
1352         /* Now begin the tedious task */
1353         while (1)
1354         {
1355                 /* Copy the current item to a buffer */
1356                 strcpy(buf, *list);
1357
1358                 /* Note the buffer's length */
1359                 buf_len = strlen(buf);
1360
1361                 /*
1362                  * If there is an item following this one, pad with separator and
1363                  * a space and adjust the buffer length
1364                  */
1365
1366                 if (list[1])
1367                 {
1368                         sprintf(buf + buf_len, "%c ", separator);
1369                         buf_len += 2;
1370                 }
1371
1372                 /*
1373                  * If the buffer will fit on the current line, just append the
1374                  * buffer to the line and adjust the line length accordingly.
1375                  */
1376
1377                 if (line_len + buf_len <= MAX_LINE_LEN)
1378                 {
1379                         strcat(line, buf);
1380                         line_len += buf_len;
1381                 }
1382
1383                 /* Apply line wrapping and indention semantics described above */
1384                 else
1385                 {
1386                         /*
1387                          * Don't print a trailing list separator but do print a trailing
1388                          * item separator.
1389                          */
1390                         if (line_len > 1 && line[line_len - 1] == ' '
1391                             && line[line_len - 2] == LIST_SEP)
1392                         {
1393                                 /* Ignore space and separator */
1394                                 line[line_len - 2] = '\0';
1395
1396                                 /* Write to spoiler file */
1397                                 fprintf(fff, "%s\n", line);
1398
1399                                 /* Begin new line at primary indention level */
1400                                 sprintf(line, "%s%s", INDENT1, buf);
1401                         }
1402
1403                         else
1404                         {
1405                                 /* Write to spoiler file */
1406                                 fprintf(fff, "%s\n", line);
1407
1408                                 /* Begin new line at secondary indention level */
1409                                 sprintf(line, "%s%s", INDENT2, buf);
1410                         }
1411
1412                         line_len = strlen(line);
1413                 }
1414
1415                 /* Advance, with break */
1416                 if (!*++list) break;
1417         }
1418
1419         /* Write what's left to the spoiler file */
1420         fprintf(fff, "%s\n", line);
1421 }
1422
1423
1424 /* Create a spoiler file entry for an artifact */
1425
1426 static void spoiler_print_art(obj_desc_list *art_ptr)
1427 {
1428         pval_info_type *pval_ptr = &art_ptr->pval_info;
1429
1430         char buf[80];
1431
1432         /* Don't indent the first line */
1433         fprintf(fff, "%s\n", art_ptr->description);
1434
1435         /* An "empty" pval description indicates that the pval affects nothing */
1436         if (pval_ptr->pval_desc[0])
1437         {
1438                 /* Mention the effects of pval */
1439 #ifdef JP
1440                 sprintf(buf, "%s¤Î½¤Àµ:", pval_ptr->pval_desc);
1441 #else
1442                 sprintf(buf, "%s to", pval_ptr->pval_desc);
1443 #endif
1444                 spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
1445         }
1446
1447         /* Now deal with the description lists */
1448
1449 #ifdef JP
1450         spoiler_outlist("ÂÐ:", art_ptr->slays, ITEM_SEP);
1451
1452         spoiler_outlist("Éð´ï°À­:", art_ptr->brands, LIST_SEP);
1453
1454         spoiler_outlist("ÌȱÖ:", art_ptr->immunities, ITEM_SEP);
1455
1456         spoiler_outlist("ÂÑÀ­:", art_ptr->resistances, ITEM_SEP);
1457
1458         spoiler_outlist("°Ý»ý:", art_ptr->sustains, ITEM_SEP);
1459 #else
1460         spoiler_outlist("Slay", art_ptr->slays, ITEM_SEP);
1461
1462         spoiler_outlist("", art_ptr->brands, LIST_SEP);
1463
1464         spoiler_outlist("Immunity to", art_ptr->immunities, ITEM_SEP);
1465
1466         spoiler_outlist("Resist", art_ptr->resistances, ITEM_SEP);
1467
1468         spoiler_outlist("Sustain", art_ptr->sustains, ITEM_SEP);
1469 #endif
1470         spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
1471
1472
1473         /* Write out the possible activation at the primary indention level */
1474         if (art_ptr->activation)
1475         {
1476 #ifdef JP
1477                 fprintf(fff, "%sȯư: %s\n", INDENT1, art_ptr->activation);
1478 #else
1479                 fprintf(fff, "%sActivates for %s\n", INDENT1, art_ptr->activation);
1480 #endif
1481         }
1482
1483         /* End with the miscellaneous facts */
1484         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
1485 }
1486
1487
1488 /*
1489  * Hack -- Create a "forged" artifact
1490  */
1491 static bool make_fake_artifact(object_type *o_ptr, int name1)
1492 {
1493         int i;
1494
1495         artifact_type *a_ptr = &a_info[name1];
1496
1497
1498         /* Ignore "empty" artifacts */
1499         if (!a_ptr->name) return FALSE;
1500
1501         /* Acquire the "kind" index */
1502         i = lookup_kind(a_ptr->tval, a_ptr->sval);
1503
1504         /* Oops */
1505         if (!i) return (FALSE);
1506
1507         /* Create the artifact */
1508         object_prep(o_ptr, i);
1509
1510         /* Save the name */
1511         o_ptr->name1 = name1;
1512
1513         /* Extract the fields */
1514         o_ptr->pval = a_ptr->pval;
1515         o_ptr->ac = a_ptr->ac;
1516         o_ptr->dd = a_ptr->dd;
1517         o_ptr->ds = a_ptr->ds;
1518         o_ptr->to_a = a_ptr->to_a;
1519         o_ptr->to_h = a_ptr->to_h;
1520         o_ptr->to_d = a_ptr->to_d;
1521         o_ptr->weight = a_ptr->weight;
1522
1523         /* Success */
1524         return (TRUE);
1525 }
1526
1527
1528 /*
1529  * Create a spoiler file for artifacts
1530  */
1531 static void spoil_artifact(cptr fname)
1532 {
1533         int i, j;
1534
1535         object_type forge;
1536         object_type *q_ptr;
1537
1538         obj_desc_list artifact;
1539
1540         char buf[1024];
1541
1542
1543         /* Build the filename */
1544         path_build(buf, 1024, ANGBAND_DIR_USER, fname);
1545
1546         /* File type is "TEXT" */
1547         FILE_TYPE(FILE_TYPE_TEXT);
1548
1549         /* Open the file */
1550         fff = my_fopen(buf, "w");
1551
1552         /* Oops */
1553         if (!fff)
1554         {
1555                 msg_print("Cannot create spoiler file.");
1556                 return;
1557         }
1558
1559         /* Dump the header */
1560         print_header();
1561
1562         /* List the artifacts by tval */
1563         for (i = 0; group_artifact[i].tval; i++)
1564         {
1565                 /* Write out the group title */
1566                 if (group_artifact[i].name)
1567                 {
1568                         spoiler_blanklines(2);
1569                         spoiler_underline(group_artifact[i].name);
1570                         spoiler_blanklines(1);
1571                 }
1572
1573                 /* Now search through all of the artifacts */
1574                 for (j = 1; j < max_a_idx; ++j)
1575                 {
1576                         artifact_type *a_ptr = &a_info[j];
1577
1578                         /* We only want objects in the current group */
1579                         if (a_ptr->tval != group_artifact[i].tval) continue;
1580
1581                         /* Get local object */
1582                         q_ptr = &forge;
1583
1584                         /* Wipe the object */
1585                         object_wipe(q_ptr);
1586
1587                         /* Attempt to "forge" the artifact */
1588                         if (!make_fake_artifact(q_ptr, j)) continue;
1589
1590                         /* Analyze the artifact */
1591                         object_analyze(q_ptr, &artifact);
1592
1593                         /* Write out the artifact description to the spoiler file */
1594                         spoiler_print_art(&artifact);
1595                 }
1596         }
1597
1598         /* Check for errors */
1599         if (ferror(fff) || my_fclose(fff))
1600         {
1601                 msg_print("Cannot close spoiler file.");
1602                 return;
1603         }
1604
1605         /* Message */
1606         msg_print("Successfully created a spoiler file.");
1607 }
1608
1609
1610
1611
1612
1613 /*
1614  * Create a spoiler file for monsters   -BEN-
1615  */
1616 static void spoil_mon_desc(cptr fname)
1617 {
1618         int i, n = 0;
1619
1620         u16b why = 2;
1621         s16b *who;
1622
1623         char buf[1024];
1624
1625         char nam[80];
1626         char lev[80];
1627         char rar[80];
1628         char spd[80];
1629         char ac[80];
1630         char hp[80];
1631         char exp[80];
1632
1633         /* Build the filename */
1634         path_build(buf, 1024, ANGBAND_DIR_USER, fname);
1635
1636         /* File type is "TEXT" */
1637         FILE_TYPE(FILE_TYPE_TEXT);
1638
1639         /* Open the file */
1640         fff = my_fopen(buf, "w");
1641
1642         /* Oops */
1643         if (!fff)
1644         {
1645                 msg_print("Cannot create spoiler file.");
1646                 return;
1647         }
1648
1649         /* Allocate the "who" array */
1650         C_MAKE(who, max_r_idx, s16b);
1651
1652         /* Dump the header */
1653         fprintf(fff, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1654                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1655         fprintf(fff, "------------------------------------------\n\n");
1656
1657         /* Dump the header */
1658         fprintf(fff, "    %-38.38s%4s%4s%4s%7s%5s  %11.11s\n",
1659                 "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info");
1660         fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1661                 "--------", "---", "---", "---", "--", "--", "-----------");
1662
1663
1664         /* Scan the monsters */
1665         for (i = 1; i < max_r_idx; i++)
1666         {
1667                 monster_race *r_ptr = &r_info[i];
1668
1669                 /* Use that monster */
1670                 if (r_ptr->name) who[n++] = i;
1671         }
1672
1673         /* Select the sort method */
1674         ang_sort_comp = ang_sort_comp_hook;
1675         ang_sort_swap = ang_sort_swap_hook;
1676
1677         /* Sort the array by dungeon depth of monsters */
1678         ang_sort(who, &why, n);
1679
1680         /* Scan again */
1681         for (i = 0; i < n; i++)
1682         {
1683                 monster_race *r_ptr = &r_info[who[i]];
1684
1685                 cptr name = (r_name + r_ptr->name);
1686                 if (r_ptr->flags7 & (RF7_KAGE)) continue;
1687
1688                 /* Get the "name" */
1689 /*              if (r_ptr->flags1 & (RF1_QUESTOR)) */
1690                 if (0)
1691                 {
1692                         sprintf(nam, "[Q] %s", name);
1693                 }
1694                 else if (r_ptr->flags1 & (RF1_UNIQUE))
1695                 {
1696                         sprintf(nam, "[U] %s", name);
1697                 }
1698                 else
1699                 {
1700 #ifdef JP
1701                         sprintf(nam, "    %s", name);
1702 #else
1703                         sprintf(nam, "The %s", name);
1704 #endif
1705                 }
1706
1707
1708                 /* Level */
1709                 sprintf(lev, "%d", r_ptr->level);
1710
1711                 /* Rarity */
1712                 sprintf(rar, "%d", r_ptr->rarity);
1713
1714                 /* Speed */
1715                 if (r_ptr->speed >= 110)
1716                 {
1717                         sprintf(spd, "+%d", (r_ptr->speed - 110));
1718                 }
1719                 else
1720                 {
1721                         sprintf(spd, "-%d", (110 - r_ptr->speed));
1722                 }
1723
1724                 /* Armor Class */
1725                 sprintf(ac, "%d", r_ptr->ac);
1726
1727                 /* Hitpoints */
1728                 if ((r_ptr->flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
1729                 {
1730                         sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside);
1731                 }
1732                 else
1733                 {
1734                         sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside);
1735                 }
1736
1737
1738                 /* Experience */
1739                 sprintf(exp, "%ld", (long)(r_ptr->mexp));
1740
1741                 /* Hack -- use visual instead */
1742                 sprintf(exp, "%s '%c'", attr_to_text(r_ptr->d_attr), r_ptr->d_char);
1743
1744                 /* Dump the info */
1745                 fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1746                         nam, lev, rar, spd, hp, ac, exp);
1747         }
1748
1749         /* End it */
1750         fprintf(fff, "\n");
1751
1752
1753         /* Free the "who" array */
1754         C_KILL(who, max_r_idx, s16b);
1755
1756         /* Check for errors */
1757         if (ferror(fff) || my_fclose(fff))
1758         {
1759                 msg_print("Cannot close spoiler file.");
1760                 return;
1761         }
1762
1763         /* Worked */
1764         msg_print("Successfully created a spoiler file.");
1765 }
1766
1767
1768
1769
1770 /*
1771  * Monster spoilers by: smchorse@ringer.cs.utsa.edu (Shawn McHorse)
1772  *
1773  * Primarily based on code already in mon-desc.c, mostly by -BEN-
1774  */
1775
1776
1777
1778 /*
1779  * Buffer text to the given file. (-SHAWN-)
1780  * This is basically c_roff() from mon-desc.c with a few changes.
1781  */
1782 static void spoil_out(cptr str)
1783 {
1784         cptr r;
1785
1786         /* Line buffer */
1787         static char roff_buf[256];
1788
1789 #ifdef JP
1790         char iskanji2=0;
1791 #endif
1792         /* Current pointer into line roff_buf */
1793         static char *roff_p = roff_buf;
1794
1795         /* Last space saved into roff_buf */
1796         static char *roff_s = NULL;
1797
1798         /* Special handling for "new sequence" */
1799         if (!str)
1800         {
1801                 if (roff_p != roff_buf) roff_p--;
1802                 while (*roff_p == ' ' && roff_p != roff_buf) roff_p--;
1803                 if (roff_p == roff_buf) fprintf(fff, "\n");
1804                 else
1805                 {
1806                         *(roff_p + 1) = '\0';
1807                         fprintf(fff, "%s\n\n", roff_buf);
1808                 }
1809                 roff_p = roff_buf;
1810                 roff_s = NULL;
1811                 roff_buf[0] = '\0';
1812                 return;
1813         }
1814
1815         /* Scan the given string, character at a time */
1816         for (; *str; str++)
1817         {
1818 #ifdef JP
1819                 char cbak;
1820                 int k_flag = iskanji((unsigned char)(*str));
1821 #endif
1822                 char ch = *str;
1823                 int wrap = (ch == '\n');
1824
1825 #ifdef JP
1826                 if (!isprint(ch) && !k_flag && !iskanji2) ch = ' ';
1827                 if(k_flag && !iskanji2)iskanji2=1;else iskanji2=0;
1828 #else
1829                 if (!isprint(ch)) ch = ' ';
1830 #endif
1831
1832 #ifdef JP
1833                 if ( roff_p >= roff_buf+( (k_flag) ? 74 : 75) ) wrap=1;
1834                 if ((ch == ' ') && (roff_p + 2 >= roff_buf + ((k_flag) ? 74 : 75))) wrap = 1;
1835 #else
1836                 if (roff_p >= roff_buf + 75) wrap = 1;
1837                 if ((ch == ' ') && (roff_p + 2 >= roff_buf + 75)) wrap = 1;
1838 #endif
1839
1840
1841                 /* Handle line-wrap */
1842                 if (wrap)
1843                 {
1844                         *roff_p = '\0';
1845                         r = roff_p;
1846 #ifdef JP
1847                                 cbak=' ';
1848 #endif
1849                         if (roff_s && (ch != ' '))
1850                         {
1851 #ifdef JP
1852                                 cbak=*roff_s;
1853 #endif
1854                                 *roff_s = '\0';
1855                                 r = roff_s + 1;
1856                         }
1857                         fprintf(fff, "%s\n", roff_buf);
1858                         roff_s = NULL;
1859                         roff_p = roff_buf;
1860 #ifdef JP
1861                         if(cbak != ' ') *roff_p++ = cbak; 
1862 #endif
1863                         while (*r) *roff_p++ = *r++;
1864                 }
1865
1866                 /* Save the char */
1867                 if ((roff_p > roff_buf) || (ch != ' '))
1868                 {
1869 #ifdef JP
1870                   if( !k_flag ){
1871                         if (ch == ' ' || ch == '(' ) roff_s = roff_p;
1872                   }
1873                   else{
1874                     if( iskanji2 && 
1875                         strncmp(str, "¡£", 2) != 0 && 
1876                         strncmp(str, "¡¢", 2) != 0 &&
1877                         strncmp(str, "¥£", 2) != 0 &&
1878                         strncmp(str, "¡¼", 2) != 0) roff_s = roff_p;
1879                   }
1880 #else
1881                         if (ch == ' ') roff_s = roff_p;
1882 #endif
1883
1884                         *roff_p++ = ch;
1885                 }
1886         }
1887 }
1888
1889
1890
1891 /*
1892  *  Hook function used in spoil_mon_info()
1893  */
1894 static void roff_func(byte attr, cptr str)
1895 {
1896         spoil_out(str);
1897 }
1898
1899
1900 /*
1901  * Create a spoiler file for monsters (-SHAWN-)
1902  */
1903 static void spoil_mon_info(cptr fname)
1904 {
1905         char buf[1024];
1906         int msex, i, l, n=0;
1907         bool breath, magic;
1908         u32b flags1, flags2, flags3, flags4, flags5, flags6, flags7;
1909
1910         u16b why = 2;
1911         s16b *who;
1912
1913         /* Build the filename */
1914         path_build(buf, 1024, ANGBAND_DIR_USER, fname);
1915
1916         /* File type is "TEXT" */
1917         FILE_TYPE(FILE_TYPE_TEXT);
1918
1919         /* Open the file */
1920         fff = my_fopen(buf, "w");
1921
1922         /* Oops */
1923         if (!fff)
1924         {
1925                 msg_print("Cannot create spoiler file.");
1926                 return;
1927         }
1928
1929
1930         /* Dump the header */
1931         sprintf(buf, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1932              FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1933
1934         spoil_out(buf);
1935         spoil_out("------------------------------------------\n\n");
1936
1937         /* Allocate the "who" array */
1938         C_MAKE(who, max_r_idx, s16b);
1939
1940         /* Scan the monsters */
1941         for (i = 1; i < max_r_idx; i++)
1942         {
1943                 monster_race *r_ptr = &r_info[i];
1944
1945                 /* Use that monster */
1946                 if (r_ptr->name) who[n++] = i;
1947         }
1948
1949         /* Select the sort method */
1950         ang_sort_comp = ang_sort_comp_hook;
1951         ang_sort_swap = ang_sort_swap_hook;
1952
1953         /* Sort the array by dungeon depth of monsters */
1954         ang_sort(who, &why, n);
1955
1956
1957         /*
1958          * List all monsters in order
1959          */
1960         for (l = 0; l < n; l++)
1961         {
1962                 monster_race *r_ptr = &r_info[who[l]];
1963
1964                 /* Extract the flags */
1965                 flags1 = r_ptr->flags1;
1966                 flags2 = r_ptr->flags2;
1967                 flags3 = r_ptr->flags3;
1968                 flags4 = r_ptr->flags4;
1969                 flags5 = r_ptr->flags5;
1970                 flags6 = r_ptr->flags6;
1971                 flags7 = r_ptr->flags7;
1972                 breath = FALSE;
1973                 magic = FALSE;
1974
1975                 /* Extract a gender (if applicable) */
1976                 if (flags1 & (RF1_FEMALE)) msex = 2;
1977                 else if (flags1 & (RF1_MALE)) msex = 1;
1978                 else msex = 0;
1979
1980
1981                 /* Prefix */
1982                 if (flags1 & (RF1_QUESTOR))
1983                 {
1984                         spoil_out("[Q] ");
1985                 }
1986                 else if (flags1 & (RF1_UNIQUE))
1987                 {
1988                         spoil_out("[U] ");
1989                 }
1990                 else
1991                 {
1992 #ifndef JP
1993                         spoil_out("The ");
1994 #endif
1995                 }
1996
1997                 /* Name */
1998 #ifdef JP
1999                 sprintf(buf, "%s/%s  (", (r_name + r_ptr->name),(r_name+r_ptr->E_name));  /* ---)--- */
2000 #else
2001                 sprintf(buf, "%s  (", (r_name + r_ptr->name));  /* ---)--- */
2002 #endif
2003
2004                 spoil_out(buf);
2005
2006                 /* Color */
2007                 spoil_out(attr_to_text(r_ptr->d_attr));
2008
2009                 /* Symbol --(-- */
2010                 sprintf(buf, " '%c')\n", r_ptr->d_char);
2011                 spoil_out(buf);
2012
2013
2014                 /* Indent */
2015                 sprintf(buf, "=== ");
2016                 spoil_out(buf);
2017
2018                 /* Number */
2019                 sprintf(buf, "Num:%d  ", who[l]);
2020                 spoil_out(buf);
2021
2022                 /* Level */
2023                 sprintf(buf, "Lev:%d  ", r_ptr->level);
2024                 spoil_out(buf);
2025
2026                 /* Rarity */
2027                 sprintf(buf, "Rar:%d  ", r_ptr->rarity);
2028                 spoil_out(buf);
2029
2030                 /* Speed */
2031                 if (r_ptr->speed >= 110)
2032                 {
2033                         sprintf(buf, "Spd:+%d  ", (r_ptr->speed - 110));
2034                 }
2035                 else
2036                 {
2037                         sprintf(buf, "Spd:-%d  ", (110 - r_ptr->speed));
2038                 }
2039                 spoil_out(buf);
2040
2041                 /* Hitpoints */
2042                 if ((flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
2043                 {
2044                         sprintf(buf, "Hp:%d  ", r_ptr->hdice * r_ptr->hside);
2045                 }
2046                 else
2047                 {
2048                         sprintf(buf, "Hp:%dd%d  ", r_ptr->hdice, r_ptr->hside);
2049                 }
2050                 spoil_out(buf);
2051
2052                 /* Armor Class */
2053                 sprintf(buf, "Ac:%d  ", r_ptr->ac);
2054                 spoil_out(buf);
2055
2056                 /* Experience */
2057                 sprintf(buf, "Exp:%ld\n", (long)(r_ptr->mexp));
2058                 spoil_out(buf);
2059
2060                 /* Reuse the code of monster recall. */
2061                 output_monster_spoiler(who[l], roff_func);
2062
2063                 spoil_out(NULL);
2064         }
2065
2066         /* Free the "who" array */
2067         C_KILL(who, max_r_idx, s16b);
2068
2069         /* Check for errors */
2070         if (ferror(fff) || my_fclose(fff))
2071         {
2072                 msg_print("Cannot close spoiler file.");
2073                 return;
2074         }
2075
2076         msg_print("Successfully created a spoiler file.");
2077 }
2078
2079
2080
2081 /*
2082  * Forward declare
2083  */
2084 extern void do_cmd_spoilers(void);
2085
2086 /*
2087  * Create Spoiler files -BEN-
2088  */
2089 void do_cmd_spoilers(void)
2090 {
2091         int i;
2092
2093
2094         /* Save the screen */
2095         screen_save();
2096
2097
2098         /* Drop priv's */
2099         safe_setuid_drop();
2100
2101
2102         /* Interact */
2103         while (1)
2104         {
2105                 /* Clear screen */
2106                 Term_clear();
2107
2108                 /* Info */
2109                 prt("Create a spoiler file.", 2, 0);
2110
2111                 /* Prompt for a file */
2112                 prt("(1) Brief Object Info (obj-desc.spo)", 5, 5);
2113                 prt("(2) Brief Artifact Info (artifact.spo)", 6, 5);
2114                 prt("(3) Brief Monster Info (mon-desc.spo)", 7, 5);
2115                 prt("(4) Full Monster Info (mon-info.spo)", 8, 5);
2116
2117                 /* Prompt */
2118 #ifdef JP
2119 prt("¥³¥Þ¥ó¥É:", 18, 0);
2120 #else
2121                 prt("Command: ", 12, 0);
2122 #endif
2123
2124
2125                 /* Get a choice */
2126                 i = inkey();
2127
2128                 /* Escape */
2129                 if (i == ESCAPE)
2130                 {
2131                         break;
2132                 }
2133
2134                 /* Option (1) */
2135                 else if (i == '1')
2136                 {
2137                         spoil_obj_desc("obj-desc.spo");
2138                 }
2139
2140                 /* Option (2) */
2141                 else if (i == '2')
2142                 {
2143                         spoil_artifact("artifact.spo");
2144                 }
2145
2146                 /* Option (3) */
2147                 else if (i == '3')
2148                 {
2149                         spoil_mon_desc("mon-desc.spo");
2150                 }
2151
2152                 /* Option (4) */
2153                 else if (i == '4')
2154                 {
2155                         spoil_mon_info("mon-info.spo");
2156                 }
2157
2158                 /* Oops */
2159                 else
2160                 {
2161                         bell();
2162                 }
2163
2164                 /* Flush messages */
2165                 msg_print(NULL);
2166         }
2167
2168
2169         /* Grab priv's */
2170         safe_setuid_grab();
2171
2172
2173         /* Restore the screen */
2174         screen_load();
2175 }
2176
2177 /*
2178  * Fill in an object description structure for a given object
2179  */
2180 static void random_artifact_analyze(object_type *o_ptr, obj_desc_list *desc_ptr)
2181 {
2182         analyze_general(o_ptr, desc_ptr->description);
2183         analyze_pval(o_ptr, &desc_ptr->pval_info);
2184         analyze_brand(o_ptr, desc_ptr->brands);
2185         analyze_slay(o_ptr, desc_ptr->slays);
2186         analyze_immune(o_ptr, desc_ptr->immunities);
2187         analyze_resist(o_ptr, desc_ptr->resistances);
2188         analyze_sustains(o_ptr, desc_ptr->sustains);
2189         analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
2190         desc_ptr->activation = item_activation(o_ptr);
2191 #ifdef JP
2192         sprintf(desc_ptr->misc_desc, "½Å¤µ %d.%d kg",
2193                 lbtokg1(o_ptr->weight), lbtokg2(o_ptr->weight));
2194 #else
2195         sprintf(desc_ptr->misc_desc, "Weight %d.%d lbs",
2196                 o_ptr->weight / 10, o_ptr->weight % 10);
2197 #endif
2198 }
2199
2200 /* Create a spoiler file entry for an artifact */
2201
2202 static void spoiler_print_randart(object_type *o_ptr, obj_desc_list *art_ptr)
2203 {
2204         pval_info_type *pval_ptr = &art_ptr->pval_info;
2205
2206         char buf[80];
2207
2208         /* Don't indent the first line */
2209         fprintf(fff, "%s\n", art_ptr->description);
2210         
2211         /* unidentified */
2212         if (!(o_ptr->ident & (IDENT_MENTAL)))
2213         {
2214 #ifdef JP
2215                 fprintf(fff, "%sÉÔÌÀ\n",INDENT1);
2216 #else
2217                 fprintf(fff, "%sUnknown\n",INDENT1);
2218 #endif
2219         }
2220         else {
2221                 /* An "empty" pval description indicates that the pval affects nothing */
2222                 if (pval_ptr->pval_desc[0])
2223                 {
2224                         /* Mention the effects of pval */
2225 #ifdef JP
2226                         sprintf(buf, "%s¤Î½¤Àµ:", pval_ptr->pval_desc);
2227 #else
2228                         sprintf(buf, "%s to", pval_ptr->pval_desc);
2229 #endif
2230                         spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
2231                 }
2232           
2233                 /* Now deal with the description lists */
2234
2235 #ifdef JP
2236                 spoiler_outlist("ÂÐ:", art_ptr->slays, ITEM_SEP);
2237                 spoiler_outlist("Éð´ï°À­:", art_ptr->brands, LIST_SEP);
2238                 spoiler_outlist("ÌȱÖ:", art_ptr->immunities, ITEM_SEP);
2239                 spoiler_outlist("ÂÑÀ­:", art_ptr->resistances, ITEM_SEP);
2240                 spoiler_outlist("°Ý»ý:", art_ptr->sustains, ITEM_SEP);
2241 #else
2242                 spoiler_outlist("Slay", art_ptr->slays, ITEM_SEP);
2243                 spoiler_outlist("", art_ptr->brands, LIST_SEP);
2244                 spoiler_outlist("Immunity to", art_ptr->immunities, ITEM_SEP);
2245                 spoiler_outlist("Resist", art_ptr->resistances, ITEM_SEP);
2246                 spoiler_outlist("Sustain", art_ptr->sustains, ITEM_SEP);
2247 #endif
2248                 spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
2249
2250                 /* Write out the possible activation at the primary indention level */
2251                 if (art_ptr->activation)
2252                 {
2253 #ifdef JP
2254                         fprintf(fff, "%sȯư: %s\n", INDENT1, art_ptr->activation);
2255 #else
2256                         fprintf(fff, "%sActivates for %s\n", INDENT1, art_ptr->activation);
2257 #endif
2258                 }
2259         }
2260         /* End with the miscellaneous facts */
2261         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
2262 }
2263
2264 /* Create a part of file for random artifacts */
2265
2266 static void spoil_random_artifact_aux(object_type *o_ptr, int i)
2267 {
2268         obj_desc_list artifact;
2269
2270         if (!object_known_p(o_ptr) || !o_ptr->art_name
2271                 || o_ptr->tval != group_artifact[i].tval)
2272                 return;
2273
2274         /* Analyze the artifact */
2275         random_artifact_analyze(o_ptr, &artifact);
2276
2277         /* Write out the artifact description to the spoiler file */
2278         spoiler_print_randart(o_ptr, &artifact);
2279 }
2280
2281 /*
2282  * Create a list file for random artifacts
2283  */
2284 void spoil_random_artifact(cptr fname)
2285 {
2286         int i,j;
2287
2288         store_type  *st_ptr;
2289         object_type *q_ptr;
2290
2291         char buf[1024];
2292
2293
2294         /* Drop priv's */
2295         safe_setuid_drop();
2296
2297         /* Build the filename */
2298         path_build(buf, 1024, ANGBAND_DIR_USER, fname);
2299
2300         /* File type is "TEXT" */
2301         FILE_TYPE(FILE_TYPE_TEXT);
2302
2303         /* Open the file */
2304         fff = my_fopen(buf, "w");
2305
2306         /* Oops */
2307         if (!fff)
2308         {
2309                 msg_print("Cannot create list file.");
2310                 return;
2311         }
2312
2313         /* Dump the header */
2314         sprintf(buf, "Random artifacts list.\r");
2315         spoiler_underline(buf);
2316
2317         /* List the artifacts by tval */
2318         for (j = 0; group_artifact[j].tval; j++)
2319         {
2320                 /* random artifacts wielding */
2321                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2322                 {
2323                         q_ptr = &inventory[i];
2324                         spoil_random_artifact_aux(q_ptr, j);
2325                 }
2326
2327                 /* random artifacts in inventory */
2328                 for (i = 0; i < INVEN_PACK; i++)
2329                 {
2330                         q_ptr = &inventory[i];
2331                         spoil_random_artifact_aux(q_ptr, j);
2332                 }
2333
2334                 /* random artifacts in home */
2335                 st_ptr = &town[1].store[STORE_HOME];
2336                 for (i = 0; i < st_ptr->stock_num; i++)
2337                 {
2338                         q_ptr = &st_ptr->stock[i];
2339                         spoil_random_artifact_aux(q_ptr, j);
2340                 }
2341
2342                 /* random artifacts in museum */
2343                 st_ptr = &town[1].store[STORE_MUSEUM];
2344                 for (i = 0; i < st_ptr->stock_num; i++)
2345                 {
2346                         q_ptr = &st_ptr->stock[i];
2347                         spoil_random_artifact_aux(q_ptr, j);
2348                 }
2349         }
2350
2351         /* Check for errors */
2352         if (ferror(fff) || my_fclose(fff))
2353         {
2354                 msg_print("Cannot close list file.");
2355                 return;
2356         }
2357
2358         /* Grab priv's */
2359         safe_setuid_grab();
2360
2361         /* Message */
2362         msg_print("Successfully created a list file.");
2363 }
2364
2365 #else
2366
2367 #ifdef MACINTOSH
2368 static int i = 0;
2369 #endif /* MACINTOSH */
2370
2371 #endif