OSDN Git Service

既に忘れた何かの理由によって、長い事tabをスペース8文字にする設定で
[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, sizeof(buf), 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 int 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         { TR_STR,        "ÏÓÎÏ" },
590         { TR_INT,        "ÃÎǽ" },
591         { TR_WIS,        "¸­¤µ" },
592         { TR_DEX,        "´ïÍѤµ" },
593         { TR_CON,        "Âѵ×ÎÏ" },
594         { TR_CHR,        "Ì¥ÎÏ" }
595 #else
596         { TR_STR,        "STR" },
597         { TR_INT,        "INT" },
598         { TR_WIS,        "WIS" },
599         { TR_DEX,        "DEX" },
600         { TR_CON,        "CON" },
601         { TR_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         { TR_MAGIC_MASTERY,    "ËâË¡Æ»¶ñ»ÈÍÑǽÎÏ" },
614         { TR_STEALTH,    "±£Ì©" },
615         { TR_SEARCH,     "õº÷" },
616         { TR_INFRA,      "ÀÖ³°Àþ»ëÎÏ" },
617         { TR_TUNNEL,     "ºÎ·¡" },
618         { TR_BLOWS,      "¹¶·â²ó¿ô" },
619         { TR_SPEED,      "¥¹¥Ô¡¼¥É" }
620 #else
621         { TR_STEALTH,    "Stealth" },
622         { TR_SEARCH,     "Searching" },
623         { TR_INFRA,      "Infravision" },
624         { TR_TUNNEL,     "Tunneling" },
625         { TR_BLOWS,      "Attacks" },
626         { TR_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         { TR_SLAY_ANIMAL,        "ưʪ" },
638         { TR_KILL_ANIMAL,        "*ưʪ*" },
639         { TR_SLAY_EVIL,          "¼Ù°­" },
640         { TR_KILL_EVIL,          "*¼Ù°­*" },
641         { TR_SLAY_HUMAN,         "¿Í´Ö" },
642         { TR_KILL_HUMAN,         "*¿Í´Ö*" },
643         { TR_SLAY_UNDEAD,        "¥¢¥ó¥Ç¥Ã¥É" },
644         { TR_KILL_UNDEAD,        "*¥¢¥ó¥Ç¥Ã¥É*" },
645         { TR_SLAY_DEMON,         "°­Ëâ" },
646         { TR_KILL_DEMON,         "*°­Ëâ*" },
647         { TR_SLAY_ORC,           "¥ª¡¼¥¯" },
648         { TR_KILL_ORC,           "*¥ª¡¼¥¯*" },
649         { TR_SLAY_TROLL,         "¥È¥í¥ë" },
650         { TR_KILL_TROLL,         "*¥È¥í¥ë*" },
651         { TR_SLAY_GIANT,         "µð¿Í" },
652         { TR_KILL_GIANT,         "*µð¿Í*" },
653         { TR_SLAY_DRAGON,        "¥É¥é¥´¥ó" },
654         { TR_KILL_DRAGON,        "*¥É¥é¥´¥ó*" },
655 #else
656         { TR_SLAY_ANIMAL,        "Animal" },
657         { TR_KILL_ANIMAL,        "XAnimal" },
658         { TR_SLAY_EVIL,          "Evil" },
659         { TR_KILL_EVIL,          "XEvil" },
660         { TR_SLAY_HUMAN,         "Human" },
661         { TR_KILL_HUMAN,         "XHuman" },
662         { TR_SLAY_UNDEAD,        "Undead" },
663         { TR_KILL_UNDEAD,        "XUndead" },
664         { TR_SLAY_DEMON,         "Demon" },
665         { TR_KILL_DEMON,         "XDemon" },
666         { TR_SLAY_ORC,           "Orc" },
667         { TR_KILL_ORC,           "XOrc" },
668         { TR_SLAY_TROLL,         "Troll" },
669         { TR_KILL_TROLL,         "XTroll" },
670         { TR_SLAY_GIANT,         "Giant" },
671         { TR_KILL_GIANT,         "Xgiant" },
672         { TR_SLAY_DRAGON,        "Dragon" },
673         { TR_KILL_DRAGON,        "Xdragon" }
674 #endif
675 };
676
677 /*
678  * Elemental brands for weapons
679  *
680  * Clearly, TR1_IMPACT is a bit out of place here. To simplify
681  * coding, it has been included here along with the elemental
682  * brands. It does seem to fit in with the brands and slaying
683  * more than the miscellaneous section.
684  */
685 static flag_desc brand_flags_desc[] =
686 {
687 #ifdef JP
688         { TR_BRAND_ACID,         "Íϲò" },
689         { TR_BRAND_ELEC,         "ÅÅ·â" },
690         { TR_BRAND_FIRE,         "¾Æ´þ" },
691         { TR_BRAND_COLD,         "Åà·ë" },
692         { TR_BRAND_POIS,         "ÆÇ»¦" },
693
694         { TR_FORCE_WEAPON,       "ÍýÎÏ" },
695         { TR_CHAOTIC,            "º®ÆÙ" },
696         { TR_VAMPIRIC,           "µÛ·ì" },
697         { TR_IMPACT,             "ÃÏ¿Ì" },
698         { TR_VORPAL,             "ÀÚ¤ìÌ£" },
699 #else
700         { TR_BRAND_ACID,         "Acid Brand" },
701         { TR_BRAND_ELEC,         "Lightning Brand" },
702         { TR_BRAND_FIRE,         "Flame Tongue" },
703         { TR_BRAND_COLD,         "Frost Brand" },
704         { TR_BRAND_POIS,         "Poisoned" },
705
706         { TR_FORCE_WEAPON,       "Force" },
707         { TR_CHAOTIC,            "Mark of Chaos" },
708         { TR_VAMPIRIC,           "Vampiric" },
709         { TR_IMPACT,             "Earthquake impact on hit" },
710         { TR_VORPAL,             "Very sharp" },
711 #endif
712 };
713
714
715 /*
716  * The 15 resistables
717  */
718 static const flag_desc resist_flags_desc[] =
719 {
720 #ifdef JP
721         { TR_RES_ACID,   "»À" },
722         { TR_RES_ELEC,   "ÅÅ·â" },
723         { TR_RES_FIRE,   "²Ð±ê" },
724         { TR_RES_COLD,   "Î䵤" },
725         { TR_RES_POIS,   "ÆÇ" },
726         { TR_RES_FEAR,   "¶²ÉÝ"},
727         { TR_RES_LITE,   "Á®¸÷" },
728         { TR_RES_DARK,   "°Å¹õ" },
729         { TR_RES_BLIND,  "ÌÕÌÜ" },
730         { TR_RES_CONF,   "º®Íð" },
731         { TR_RES_SOUND,  "¹ì²»" },
732         { TR_RES_SHARDS, "ÇËÊÒ" },
733         { TR_RES_NETHER, "ÃϹö" },
734         { TR_RES_NEXUS,  "°ø²Ìº®Íð" },
735         { TR_RES_CHAOS,  "¥«¥ª¥¹" },
736         { TR_RES_DISEN,  "Îô²½" },
737 #else
738         { TR_RES_ACID,   "Acid" },
739         { TR_RES_ELEC,   "Lightning" },
740         { TR_RES_FIRE,   "Fire" },
741         { TR_RES_COLD,   "Cold" },
742         { TR_RES_POIS,   "Poison" },
743         { TR_RES_FEAR,   "Fear"},
744         { TR_RES_LITE,   "Light" },
745         { TR_RES_DARK,   "Dark" },
746         { TR_RES_BLIND,  "Blindness" },
747         { TR_RES_CONF,   "Confusion" },
748         { TR_RES_SOUND,  "Sound" },
749         { TR_RES_SHARDS, "Shards" },
750         { TR_RES_NETHER, "Nether" },
751         { TR_RES_NEXUS,  "Nexus" },
752         { TR_RES_CHAOS,  "Chaos" },
753         { TR_RES_DISEN,  "Disenchantment" },
754 #endif
755 };
756
757 /*
758  * Elemental immunities (along with poison)
759  */
760
761 static const flag_desc immune_flags_desc[] =
762 {
763 #ifdef JP
764         { TR_IM_ACID,    "»À" },
765         { TR_IM_ELEC,    "ÅÅ·â" },
766         { TR_IM_FIRE,    "²Ð±ê" },
767         { TR_IM_COLD,    "Î䵤" },
768 #else
769         { TR_IM_ACID,    "Acid" },
770         { TR_IM_ELEC,    "Lightning" },
771         { TR_IM_FIRE,    "Fire" },
772         { TR_IM_COLD,    "Cold" },
773 #endif
774 };
775
776 /*
777  * Sustain stats -  these are given their "own" line in the
778  * spoiler file, mainly for simplicity
779  */
780 static const flag_desc sustain_flags_desc[] =
781 {
782 #ifdef JP
783         { TR_SUST_STR,   "ÏÓÎÏ" },
784         { TR_SUST_INT,   "ÃÎǽ" },
785         { TR_SUST_WIS,   "¸­¤µ" },
786         { TR_SUST_DEX,   "´ïÍѤµ" },
787         { TR_SUST_CON,   "Âѵ×ÎÏ" },
788         { TR_SUST_CHR,   "Ì¥ÎÏ" },
789 #else
790         { TR_SUST_STR,   "STR" },
791         { TR_SUST_INT,   "INT" },
792         { TR_SUST_WIS,   "WIS" },
793         { TR_SUST_DEX,   "DEX" },
794         { TR_SUST_CON,   "CON" },
795         { TR_SUST_CHR,   "CHR" },
796 #endif
797 };
798
799 /*
800  * Miscellaneous magic given by an object's "flags2" field
801  */
802
803 static const flag_desc misc_flags2_desc[] =
804 {
805 #ifdef JP
806         { TR_THROW,      "ÅêÚ³" },
807         { TR_REFLECT,    "È¿¼Í" },
808         { TR_FREE_ACT,   "ËãáãÃΤ餺" },
809         { TR_HOLD_LIFE,  "À¸Ì¿ÎÏ°Ý»ý" },
810 #else
811         { TR_THROW,      "Throwing" },
812         { TR_REFLECT,    "Reflection" },
813         { TR_FREE_ACT,   "Free Action" },
814         { TR_HOLD_LIFE,  "Hold Life" },
815 #endif
816 };
817
818 /*
819  * Miscellaneous magic given by an object's "flags3" field
820  *
821  * Note that cursed artifacts and objects with permanent light
822  * are handled "directly" -- see analyze_misc_magic()
823  */
824
825 static const flag_desc misc_flags3_desc[] =
826 {
827 #ifdef JP
828         { TR_SH_FIRE,            "²Ð±ê¥ª¡¼¥é" },
829         { TR_SH_ELEC,            "Åŷ⥪¡¼¥é" },
830         { TR_SH_COLD,            "Î䵤¥ª¡¼¥é" },
831         { TR_NO_TELE,            "È¿¥Æ¥ì¥Ý¡¼¥È" },
832         { TR_NO_MAGIC,           "È¿ËâË¡" },
833         { TR_FEATHER,            "ÉâÍ·" },
834         { TR_SEE_INVIS,          "²Ä»ëÆ©ÌÀ" },
835         { TR_TELEPATHY,          "¥Æ¥ì¥Ñ¥·¡¼" },
836         { TR_ESP_ANIMAL,             "ưʪ´¶ÃÎ" },
837         { TR_ESP_UNDEAD,             "ÉԻശÃÎ" },
838         { TR_ESP_DEMON,              "°­Ëâ´¶ÃÎ" },
839         { TR_ESP_ORC,                "¥ª¡¼¥¯´¶ÃÎ" },
840         { TR_ESP_TROLL,              "¥È¥í¥ë´¶ÃÎ" },
841         { TR_ESP_GIANT,              "µð¿Í´¶ÃÎ" },
842         { TR_ESP_DRAGON,             "¥É¥é¥´¥ó´¶ÃÎ" },
843         { TR_ESP_HUMAN,              "¿Í´Ö´¶ÃÎ" },
844         { TR_ESP_EVIL,               "¼Ù°­´¶ÃÎ" },
845         { TR_ESP_GOOD,               "Á±ÎÉ´¶ÃÎ" },
846         { TR_ESP_NONLIVING,          "̵À¸Êª´¶ÃÎ" },
847         { TR_ESP_UNIQUE,             "¥æ¥Ë¡¼¥¯´¶ÃÎ" },
848         { TR_SLOW_DIGEST,        "Ãپò½" },
849         { TR_REGEN,              "µÞ®²óÉü" },
850         { TR_WARNING,            "·Ù¹ð" },
851 /*      { TR_XTRA_MIGHT,         "¶¯Îϼͷâ" }, */
852         { TR_XTRA_SHOTS,         "Äɲüͷâ" },        /* always +1? */
853         { TR_DRAIN_EXP,          "·Ð¸³Ã͵ۼý" },
854         { TR_AGGRAVATE,          "È¿´¶" },
855         { TR_BLESSED,            "½ËÊ¡" },
856         { TR_DEC_MANA,           "¾ÃÈñËâÎϸº¾¯" },
857 #else
858         { TR_SH_FIRE,            "Fiery Aura" },
859         { TR_SH_ELEC,            "Electric Aura" },
860         { TR_SH_COLD,            "Coldly Aura" },
861         { TR_NO_TELE,            "Prevent Teleportation" },
862         { TR_NO_MAGIC,           "Anti-Magic" },
863         { TR_FEATHER,            "Levitation" },
864         { TR_SEE_INVIS,          "See Invisible" },
865         { TR_TELEPATHY,          "ESP" },
866         { TR_SLOW_DIGEST,        "Slow Digestion" },
867         { TR_REGEN,              "Regeneration" },
868         { TR_WARNING,            "Warning" },
869 /*      { TR_XTRA_MIGHT,         "Extra Might" }, */
870         { TR_XTRA_SHOTS,         "+1 Extra Shot" },        /* always +1? */
871         { TR_DRAIN_EXP,          "Drains Experience" },
872         { TR_AGGRAVATE,          "Aggravates" },
873         { TR_BLESSED,            "Blessed Blade" },
874         { TR_DEC_MANA,           "Decrease Mana Consumption Rate" },
875 #endif
876 };
877
878
879 /*
880  * A special type used just for deailing with pvals
881  */
882 typedef struct
883 {
884         /*
885          * This will contain a string such as "+2", "-10", etc.
886          */
887         char pval_desc[12];
888
889         /*
890          * A list of various player traits affected by an object's pval such
891          * as stats, speed, stealth, etc.  "Extra attacks" is NOT included in
892          * this list since it will probably be desirable to format its
893          * description differently.
894          *
895          * Note that room need only be reserved for the number of stats - 1
896          * since the description "All stats" is used if an object affects all
897          * all stats. Also, room must be reserved for a sentinel NULL pointer.
898          *
899          * This will be a list such as ["STR", "DEX", "Stealth", NULL] etc.
900          *
901          * This list includes extra attacks, for simplicity.
902          */
903         cptr pval_affects[N_ELEMENTS(stat_flags_desc) - 1 +
904                           N_ELEMENTS(pval_flags1_desc) + 1];
905
906 } pval_info_type;
907
908
909 /*
910  * An "object analysis structure"
911  *
912  * It will be filled with descriptive strings detailing an object's
913  * various magical powers. The "ignore X" traits are not noted since
914  * all artifacts ignore "normal" destruction.
915  */
916
917 typedef struct
918 {
919         /* "The Longsword Dragonsmiter (6d4) (+20, +25)" */
920         char description[MAX_NLEN];
921
922         /* Description of what is affected by an object's pval */
923         pval_info_type pval_info;
924
925         /* A list of an object's slaying preferences */
926         cptr slays[N_ELEMENTS(slay_flags_desc) + 1];
927
928         /* A list if an object's elemental brands */
929         cptr brands[N_ELEMENTS(brand_flags_desc) + 1];
930
931         /* A list of immunities granted by an object */
932         cptr immunities[N_ELEMENTS(immune_flags_desc) + 1];
933
934         /* A list of resistances granted by an object */
935         cptr resistances[N_ELEMENTS(resist_flags_desc) + 1];
936
937         /* A list of stats sustained by an object */
938         cptr sustains[N_ELEMENTS(sustain_flags_desc)  - 1 + 1];
939
940         /* A list of various magical qualities an object may have */
941         cptr misc_magic[N_ELEMENTS(misc_flags2_desc) + N_ELEMENTS(misc_flags3_desc)
942                         + 1       /* Permanent Light */
943                         + 1       /* TY curse */
944                         + 1       /* type of curse */
945                         + 1];     /* sentinel NULL */
946
947         /* A string describing an artifact's activation */
948         cptr activation;
949
950         /* "Level 20, Rarity 30, 3.0 lbs, 20000 Gold" */
951         char misc_desc[80];
952 } obj_desc_list;
953
954
955 /*
956  * Write out `n' of the character `c' to the spoiler file
957  */
958 static void spoiler_out_n_chars(int n, char c)
959 {
960         while (--n >= 0) fputc(c, fff);
961 }
962
963
964 /*
965  * Write out `n' blank lines to the spoiler file
966  */
967 static void spoiler_blanklines(int n)
968 {
969         spoiler_out_n_chars(n, '\n');
970 }
971
972
973 /*
974  * Write a line to the spoiler file and then "underline" it with hypens
975  */
976 static void spoiler_underline(cptr str)
977 {
978         fprintf(fff, "%s\n", str);
979         spoiler_out_n_chars(strlen(str), '-');
980         fprintf(fff, "\n");
981 }
982
983
984
985 /*
986  * This function does most of the actual "analysis". Given a set of bit flags
987  * (which will be from one of the flags fields from the object in question),
988  * a "flag description structure", a "description list", and the number of
989  * elements in the "flag description structure", this function sets the
990  * "description list" members to the appropriate descriptions contained in
991  * the "flag description structure".
992  *
993  * The possibly updated description pointer is returned.
994  */
995 static cptr *spoiler_flag_aux(const u32b art_flags[TR_FLAG_SIZE],
996                               const flag_desc *flag_ptr,
997                               cptr *desc_ptr, const int n_elmnts)
998 {
999         int i;
1000
1001         for (i = 0; i < n_elmnts; ++i)
1002         {
1003                 if (have_flag(art_flags, flag_ptr[i].flag))
1004                 {
1005                         *desc_ptr++ = flag_ptr[i].desc;
1006                 }
1007         }
1008
1009         return desc_ptr;
1010 }
1011
1012
1013 /*
1014  * Acquire a "basic" description "The Cloak of Death [1,+10]"
1015  */
1016 static void analyze_general (object_type *o_ptr, char *desc_ptr)
1017 {
1018         /* Get a "useful" description of the object */
1019         object_desc_store(desc_ptr, o_ptr, TRUE, 1);
1020 }
1021
1022
1023 /*
1024  * List "player traits" altered by an artifact's pval. These include stats,
1025  * speed, infravision, tunneling, stealth, searching, and extra attacks.
1026  */
1027 static void analyze_pval (object_type *o_ptr, pval_info_type *p_ptr)
1028 {
1029         u32b flgs[TR_FLAG_SIZE];
1030
1031         cptr *affects_list;
1032
1033         /* If pval == 0, there is nothing to do. */
1034         if (!o_ptr->pval)
1035         {
1036                 /* An "empty" pval description indicates that pval == 0 */
1037                 p_ptr->pval_desc[0] = '\0';
1038                 return;
1039         }
1040
1041         /* Extract the flags */
1042         object_flags(o_ptr, flgs);
1043
1044         affects_list = p_ptr->pval_affects;
1045
1046         /* Create the "+N" string */
1047         sprintf(p_ptr->pval_desc, "%s%d", POSITIZE(o_ptr->pval), o_ptr->pval);
1048
1049         /* First, check to see if the pval affects all stats */
1050         if (have_flag(flgs, TR_STR) && have_flag(flgs, TR_INT) &&
1051             have_flag(flgs, TR_WIS) && have_flag(flgs, TR_DEX) &&
1052             have_flag(flgs, TR_CON) && have_flag(flgs, TR_CHR))
1053         {
1054 #ifdef JP
1055                 *affects_list++ = "Á´Ç½ÎÏ";
1056 #else
1057                 *affects_list++ = "All stats";
1058 #endif
1059         }
1060
1061         /* Are any stats affected? */
1062         else if (have_flag(flgs, TR_STR) || have_flag(flgs, TR_INT) ||
1063                  have_flag(flgs, TR_WIS) || have_flag(flgs, TR_DEX) ||
1064                  have_flag(flgs, TR_CON) || have_flag(flgs, TR_CHR))
1065         {
1066                 affects_list = spoiler_flag_aux(flgs, stat_flags_desc,
1067                                                 affects_list,
1068                                                 N_ELEMENTS(stat_flags_desc));
1069         }
1070
1071         /* And now the "rest" */
1072         affects_list = spoiler_flag_aux(flgs, pval_flags1_desc,
1073                                         affects_list,
1074                                         N_ELEMENTS(pval_flags1_desc));
1075
1076         /* Terminate the description list */
1077         *affects_list = NULL;
1078 }
1079
1080
1081 /* Note the slaying specialties of a weapon */
1082 static void analyze_slay (object_type *o_ptr, cptr *slay_list)
1083 {
1084         u32b flgs[TR_FLAG_SIZE];
1085
1086         object_flags(o_ptr, flgs);
1087
1088         slay_list = spoiler_flag_aux(flgs, slay_flags_desc, slay_list,
1089                                      N_ELEMENTS(slay_flags_desc));
1090
1091         /* Terminate the description list */
1092         *slay_list = NULL;
1093 }
1094
1095 /* Note an object's elemental brands */
1096 static void analyze_brand (object_type *o_ptr, cptr *brand_list)
1097 {
1098         u32b flgs[TR_FLAG_SIZE];
1099
1100         object_flags(o_ptr, flgs);
1101
1102         brand_list = spoiler_flag_aux(flgs, brand_flags_desc, brand_list,
1103                                       N_ELEMENTS(brand_flags_desc));
1104
1105         /* Terminate the description list */
1106         *brand_list = NULL;
1107 }
1108
1109
1110 /* Note the resistances granted by an object */
1111 static void analyze_resist (object_type *o_ptr, cptr *resist_list)
1112 {
1113         u32b flgs[TR_FLAG_SIZE];
1114
1115         object_flags(o_ptr, flgs);
1116
1117         resist_list = spoiler_flag_aux(flgs, resist_flags_desc,
1118                                        resist_list, N_ELEMENTS(resist_flags_desc));
1119
1120         /* Terminate the description list */
1121         *resist_list = NULL;
1122 }
1123
1124
1125 /* Note the immunities granted by an object */
1126 static void analyze_immune (object_type *o_ptr, cptr *immune_list)
1127 {
1128         u32b flgs[TR_FLAG_SIZE];
1129
1130         object_flags(o_ptr, flgs);
1131
1132         immune_list = spoiler_flag_aux(flgs, immune_flags_desc,
1133                                        immune_list, N_ELEMENTS(immune_flags_desc));
1134
1135         /* Terminate the description list */
1136         *immune_list = NULL;
1137 }
1138
1139 /* Note which stats an object sustains */
1140
1141 static void analyze_sustains (object_type *o_ptr, cptr *sustain_list)
1142 {
1143         u32b flgs[TR_FLAG_SIZE];
1144
1145         object_flags(o_ptr, flgs);
1146
1147         /* Simplify things if an item sustains all stats */
1148         if (have_flag(flgs, TR_SUST_STR) && have_flag(flgs, TR_SUST_INT) &&
1149             have_flag(flgs, TR_SUST_WIS) && have_flag(flgs, TR_SUST_DEX) &&
1150             have_flag(flgs, TR_SUST_CON) && have_flag(flgs, TR_SUST_CHR))
1151         {
1152 #ifdef JP
1153                 *sustain_list++ = "Á´Ç½ÎÏ";
1154 #else
1155                 *sustain_list++ = "All stats";
1156 #endif
1157         }
1158
1159         /* Should we bother? */
1160         else if (have_flag(flgs, TR_SUST_STR) || have_flag(flgs, TR_SUST_INT) ||
1161                  have_flag(flgs, TR_SUST_WIS) || have_flag(flgs, TR_SUST_DEX) ||
1162                  have_flag(flgs, TR_SUST_CON) || have_flag(flgs, TR_SUST_CHR))
1163         {
1164                 sustain_list = spoiler_flag_aux(flgs, sustain_flags_desc,
1165                                                 sustain_list,
1166                                                 N_ELEMENTS(sustain_flags_desc));
1167         }
1168
1169         /* Terminate the description list */
1170         *sustain_list = NULL;
1171 }
1172
1173
1174 /*
1175  * Note miscellaneous powers bestowed by an artifact such as see invisible,
1176  * free action, permanent light, etc.
1177  */
1178 static void analyze_misc_magic (object_type *o_ptr, cptr *misc_list)
1179 {
1180         u32b flgs[TR_FLAG_SIZE];
1181
1182         object_flags(o_ptr, flgs);
1183
1184         misc_list = spoiler_flag_aux(flgs, misc_flags2_desc, misc_list,
1185                                      N_ELEMENTS(misc_flags2_desc));
1186
1187         misc_list = spoiler_flag_aux(flgs, misc_flags3_desc, misc_list,
1188                                      N_ELEMENTS(misc_flags3_desc));
1189
1190         /*
1191          * Artifact lights -- large radius light.
1192          */
1193         if ((o_ptr->tval == TV_LITE) && artifact_p(o_ptr))
1194         {
1195 #ifdef JP
1196                 *misc_list++ = "±Êµ×¸÷¸»(Ⱦ·Â3)";
1197 #else
1198                 *misc_list++ = "Permanent Light(3)";
1199 #endif
1200         }
1201
1202         /*
1203          * Glowing artifacts -- small radius light.
1204          */
1205         if (have_flag(flgs, TR_LITE))
1206         {
1207 #ifdef JP
1208                 *misc_list++ = "±Êµ×¸÷¸»(Ⱦ·Â1)";
1209 #else
1210                 *misc_list++ = "Permanent Light(1)";
1211 #endif
1212         }
1213
1214         /*
1215          * Handle cursed objects here to avoid redundancies such as noting
1216          * that a permanently cursed object is heavily cursed as well as
1217          * being "lightly cursed".
1218          */
1219
1220 /*      if (cursed_p(o_ptr)) */
1221         if (1)
1222         {
1223                 if (have_flag(flgs, TR_TY_CURSE))
1224                 {
1225 #ifdef JP
1226                         *misc_list++ = "ÂÀ¸Å¤Î±åÇ°";
1227 #else
1228                         *misc_list++ = "Ancient Curse";
1229 #endif
1230                 }
1231                 if (o_ptr->curse_flags & TRC_PERMA_CURSE)
1232                 {
1233 #ifdef JP
1234                         *misc_list++ = "±Ê±ó¤Î¼ö¤¤";
1235 #else
1236                         *misc_list++ = "Permanently Cursed";
1237 #endif
1238                 }
1239                 else if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
1240                 {
1241 #ifdef JP
1242                         *misc_list++ = "¶¯ÎϤʼö¤¤";
1243 #else
1244                         *misc_list++ = "Heavily Cursed";
1245 #endif
1246                 }
1247 /*              else */
1248                 else if (o_ptr->curse_flags & TRC_CURSED)
1249                 {
1250 #ifdef JP
1251                         *misc_list++ = "¼ö¤¤";
1252 #else
1253                         *misc_list++ = "Cursed";
1254 #endif
1255                 }
1256         }
1257
1258         /* Terminate the description list */
1259         *misc_list = NULL;
1260 }
1261
1262
1263
1264
1265 /*
1266  * Determine the minimum depth an artifact can appear, its rarity, its weight,
1267  * and its value in gold pieces
1268  */
1269 static void analyze_misc (object_type *o_ptr, char *misc_desc)
1270 {
1271         artifact_type *a_ptr = &a_info[o_ptr->name1];
1272
1273 #ifdef JP
1274         sprintf(misc_desc, "¥ì¥Ù¥ë %u, ´õ¾¯ÅÙ %u, %d.%d kg, ¡ð%ld",
1275                 a_ptr->level, a_ptr->rarity,
1276                 lbtokg1(a_ptr->weight), lbtokg2(a_ptr->weight), a_ptr->cost);
1277 #else
1278         sprintf(misc_desc, "Level %u, Rarity %u, %d.%d lbs, %ld Gold",
1279                 a_ptr->level, a_ptr->rarity,
1280                 a_ptr->weight / 10, a_ptr->weight % 10, a_ptr->cost);
1281 #endif
1282 }
1283
1284
1285 /*
1286  * Fill in an object description structure for a given object
1287  */
1288 static void object_analyze(object_type *o_ptr, obj_desc_list *desc_ptr)
1289 {
1290         analyze_general(o_ptr, desc_ptr->description);
1291
1292         analyze_pval(o_ptr, &desc_ptr->pval_info);
1293
1294         analyze_brand(o_ptr, desc_ptr->brands);
1295
1296         analyze_slay(o_ptr, desc_ptr->slays);
1297
1298         analyze_immune(o_ptr, desc_ptr->immunities);
1299
1300         analyze_resist(o_ptr, desc_ptr->resistances);
1301
1302         analyze_sustains(o_ptr, desc_ptr->sustains);
1303
1304         analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
1305
1306         analyze_misc(o_ptr, desc_ptr->misc_desc);
1307
1308         desc_ptr->activation = item_activation(o_ptr);
1309 }
1310
1311
1312 static void print_header(void)
1313 {
1314         char buf[80];
1315
1316         sprintf(buf, "Artifact Spoilers for Hengband Version %d.%d.%d",
1317                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1318         spoiler_underline(buf);
1319 }
1320
1321 /*
1322  * This is somewhat ugly.
1323  *
1324  * Given a header ("Resist", e.g.), a list ("Fire", "Cold", Acid", e.g.),
1325  * and a separator character (',', e.g.), write the list to the spoiler file
1326  * in a "nice" format, such as:
1327  *
1328  *      Resist Fire, Cold, Acid
1329  *
1330  * That was a simple example, but when the list is long, a line wrap
1331  * should occur, and this should induce a new level of indention if
1332  * a list is being spread across lines. So for example, Bladeturner's
1333  * list of resistances should look something like this
1334  *
1335  *     Resist Acid, Lightning, Fire, Cold, Poison, Light, Dark, Blindness,
1336  *       Confusion, Sound, Shards, Nether, Nexus, Chaos, Disenchantment
1337  *
1338  * However, the code distinguishes between a single list of many items vs.
1339  * many lists. (The separator is used to make this determination.) A single
1340  * list of many items will not cause line wrapping (since there is no
1341  * apparent reason to do so). So the lists of Ulmo's miscellaneous traits
1342  * might look like this:
1343  *
1344  *     Free Action; Hold Life; See Invisible; Slow Digestion; Regeneration
1345  *     Blessed Blade
1346  *
1347  * So comparing the two, "Regeneration" has no trailing separator and
1348  * "Blessed Blade" was not indented. (Also, Ulmo's lists have no headers,
1349  * but that's not relevant to line wrapping and indention.)
1350  */
1351
1352 /* ITEM_SEP separates items within a list */
1353 #define ITEM_SEP ','
1354
1355
1356 /* LIST_SEP separates lists */
1357 #ifdef JP
1358 #define LIST_SEP ','
1359 #else
1360 #define LIST_SEP ';'
1361 #endif
1362
1363 static void spoiler_outlist(cptr header, cptr *list, char separator)
1364 {
1365         int line_len, buf_len;
1366         char line[MAX_LINE_LEN+1], buf[80];
1367
1368         /* Ignore an empty list */
1369         if (*list == NULL) return;
1370
1371         /* This function always indents */
1372         strcpy(line, INDENT1);
1373
1374         /* Create header (if one was given) */
1375         if (header && (header[0]))
1376         {
1377                 strcat(line, header);
1378                 strcat(line, " ");
1379         }
1380
1381         line_len = strlen(line);
1382
1383         /* Now begin the tedious task */
1384         while (1)
1385         {
1386                 /* Copy the current item to a buffer */
1387                 strcpy(buf, *list);
1388
1389                 /* Note the buffer's length */
1390                 buf_len = strlen(buf);
1391
1392                 /*
1393                  * If there is an item following this one, pad with separator and
1394                  * a space and adjust the buffer length
1395                  */
1396
1397                 if (list[1])
1398                 {
1399                         sprintf(buf + buf_len, "%c ", separator);
1400                         buf_len += 2;
1401                 }
1402
1403                 /*
1404                  * If the buffer will fit on the current line, just append the
1405                  * buffer to the line and adjust the line length accordingly.
1406                  */
1407
1408                 if (line_len + buf_len <= MAX_LINE_LEN)
1409                 {
1410                         strcat(line, buf);
1411                         line_len += buf_len;
1412                 }
1413
1414                 /* Apply line wrapping and indention semantics described above */
1415                 else
1416                 {
1417                         /*
1418                          * Don't print a trailing list separator but do print a trailing
1419                          * item separator.
1420                          */
1421                         if (line_len > 1 && line[line_len - 1] == ' '
1422                             && line[line_len - 2] == LIST_SEP)
1423                         {
1424                                 /* Ignore space and separator */
1425                                 line[line_len - 2] = '\0';
1426
1427                                 /* Write to spoiler file */
1428                                 fprintf(fff, "%s\n", line);
1429
1430                                 /* Begin new line at primary indention level */
1431                                 sprintf(line, "%s%s", INDENT1, buf);
1432                         }
1433
1434                         else
1435                         {
1436                                 /* Write to spoiler file */
1437                                 fprintf(fff, "%s\n", line);
1438
1439                                 /* Begin new line at secondary indention level */
1440                                 sprintf(line, "%s%s", INDENT2, buf);
1441                         }
1442
1443                         line_len = strlen(line);
1444                 }
1445
1446                 /* Advance, with break */
1447                 if (!*++list) break;
1448         }
1449
1450         /* Write what's left to the spoiler file */
1451         fprintf(fff, "%s\n", line);
1452 }
1453
1454
1455 /* Create a spoiler file entry for an artifact */
1456
1457 static void spoiler_print_art(obj_desc_list *art_ptr)
1458 {
1459         pval_info_type *pval_ptr = &art_ptr->pval_info;
1460
1461         char buf[80];
1462
1463         /* Don't indent the first line */
1464         fprintf(fff, "%s\n", art_ptr->description);
1465
1466         /* An "empty" pval description indicates that the pval affects nothing */
1467         if (pval_ptr->pval_desc[0])
1468         {
1469                 /* Mention the effects of pval */
1470 #ifdef JP
1471                 sprintf(buf, "%s¤Î½¤Àµ:", pval_ptr->pval_desc);
1472 #else
1473                 sprintf(buf, "%s to", pval_ptr->pval_desc);
1474 #endif
1475                 spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
1476         }
1477
1478         /* Now deal with the description lists */
1479
1480 #ifdef JP
1481         spoiler_outlist("ÂÐ:", art_ptr->slays, ITEM_SEP);
1482
1483         spoiler_outlist("Éð´ï°À­:", art_ptr->brands, LIST_SEP);
1484
1485         spoiler_outlist("ÌȱÖ:", art_ptr->immunities, ITEM_SEP);
1486
1487         spoiler_outlist("ÂÑÀ­:", art_ptr->resistances, ITEM_SEP);
1488
1489         spoiler_outlist("°Ý»ý:", art_ptr->sustains, ITEM_SEP);
1490 #else
1491         spoiler_outlist("Slay", art_ptr->slays, ITEM_SEP);
1492
1493         spoiler_outlist("", art_ptr->brands, LIST_SEP);
1494
1495         spoiler_outlist("Immunity to", art_ptr->immunities, ITEM_SEP);
1496
1497         spoiler_outlist("Resist", art_ptr->resistances, ITEM_SEP);
1498
1499         spoiler_outlist("Sustain", art_ptr->sustains, ITEM_SEP);
1500 #endif
1501         spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
1502
1503
1504         /* Write out the possible activation at the primary indention level */
1505         if (art_ptr->activation)
1506         {
1507 #ifdef JP
1508                 fprintf(fff, "%sȯư: %s\n", INDENT1, art_ptr->activation);
1509 #else
1510                 fprintf(fff, "%sActivates for %s\n", INDENT1, art_ptr->activation);
1511 #endif
1512         }
1513
1514         /* End with the miscellaneous facts */
1515         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
1516 }
1517
1518
1519 /*
1520  * Hack -- Create a "forged" artifact
1521  */
1522 static bool make_fake_artifact(object_type *o_ptr, int name1)
1523 {
1524         int i;
1525
1526         artifact_type *a_ptr = &a_info[name1];
1527
1528
1529         /* Ignore "empty" artifacts */
1530         if (!a_ptr->name) return FALSE;
1531
1532         /* Acquire the "kind" index */
1533         i = lookup_kind(a_ptr->tval, a_ptr->sval);
1534
1535         /* Oops */
1536         if (!i) return (FALSE);
1537
1538         /* Create the artifact */
1539         object_prep(o_ptr, i);
1540
1541         /* Save the name */
1542         o_ptr->name1 = name1;
1543
1544         /* Extract the fields */
1545         o_ptr->pval = a_ptr->pval;
1546         o_ptr->ac = a_ptr->ac;
1547         o_ptr->dd = a_ptr->dd;
1548         o_ptr->ds = a_ptr->ds;
1549         o_ptr->to_a = a_ptr->to_a;
1550         o_ptr->to_h = a_ptr->to_h;
1551         o_ptr->to_d = a_ptr->to_d;
1552         o_ptr->weight = a_ptr->weight;
1553
1554         /* Success */
1555         return (TRUE);
1556 }
1557
1558
1559 /*
1560  * Create a spoiler file for artifacts
1561  */
1562 static void spoil_artifact(cptr fname)
1563 {
1564         int i, j;
1565
1566         object_type forge;
1567         object_type *q_ptr;
1568
1569         obj_desc_list artifact;
1570
1571         char buf[1024];
1572
1573
1574         /* Build the filename */
1575         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1576
1577         /* File type is "TEXT" */
1578         FILE_TYPE(FILE_TYPE_TEXT);
1579
1580         /* Open the file */
1581         fff = my_fopen(buf, "w");
1582
1583         /* Oops */
1584         if (!fff)
1585         {
1586                 msg_print("Cannot create spoiler file.");
1587                 return;
1588         }
1589
1590         /* Dump the header */
1591         print_header();
1592
1593         /* List the artifacts by tval */
1594         for (i = 0; group_artifact[i].tval; i++)
1595         {
1596                 /* Write out the group title */
1597                 if (group_artifact[i].name)
1598                 {
1599                         spoiler_blanklines(2);
1600                         spoiler_underline(group_artifact[i].name);
1601                         spoiler_blanklines(1);
1602                 }
1603
1604                 /* Now search through all of the artifacts */
1605                 for (j = 1; j < max_a_idx; ++j)
1606                 {
1607                         artifact_type *a_ptr = &a_info[j];
1608
1609                         /* We only want objects in the current group */
1610                         if (a_ptr->tval != group_artifact[i].tval) continue;
1611
1612                         /* Get local object */
1613                         q_ptr = &forge;
1614
1615                         /* Wipe the object */
1616                         object_wipe(q_ptr);
1617
1618                         /* Attempt to "forge" the artifact */
1619                         if (!make_fake_artifact(q_ptr, j)) continue;
1620
1621                         /* Analyze the artifact */
1622                         object_analyze(q_ptr, &artifact);
1623
1624                         /* Write out the artifact description to the spoiler file */
1625                         spoiler_print_art(&artifact);
1626                 }
1627         }
1628
1629         /* Check for errors */
1630         if (ferror(fff) || my_fclose(fff))
1631         {
1632                 msg_print("Cannot close spoiler file.");
1633                 return;
1634         }
1635
1636         /* Message */
1637         msg_print("Successfully created a spoiler file.");
1638 }
1639
1640
1641
1642
1643
1644 /*
1645  * Create a spoiler file for monsters   -BEN-
1646  */
1647 static void spoil_mon_desc(cptr fname)
1648 {
1649         int i, n = 0;
1650
1651         u16b why = 2;
1652         s16b *who;
1653
1654         char buf[1024];
1655
1656         char nam[80];
1657         char lev[80];
1658         char rar[80];
1659         char spd[80];
1660         char ac[80];
1661         char hp[80];
1662         char exp[80];
1663
1664         /* Build the filename */
1665         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1666
1667         /* File type is "TEXT" */
1668         FILE_TYPE(FILE_TYPE_TEXT);
1669
1670         /* Open the file */
1671         fff = my_fopen(buf, "w");
1672
1673         /* Oops */
1674         if (!fff)
1675         {
1676                 msg_print("Cannot create spoiler file.");
1677                 return;
1678         }
1679
1680         /* Allocate the "who" array */
1681         C_MAKE(who, max_r_idx, s16b);
1682
1683         /* Dump the header */
1684         fprintf(fff, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1685                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1686         fprintf(fff, "------------------------------------------\n\n");
1687
1688         /* Dump the header */
1689         fprintf(fff, "    %-38.38s%4s%4s%4s%7s%5s  %11.11s\n",
1690                 "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info");
1691         fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1692                 "--------", "---", "---", "---", "--", "--", "-----------");
1693
1694
1695         /* Scan the monsters */
1696         for (i = 1; i < max_r_idx; i++)
1697         {
1698                 monster_race *r_ptr = &r_info[i];
1699
1700                 /* Use that monster */
1701                 if (r_ptr->name) who[n++] = i;
1702         }
1703
1704         /* Select the sort method */
1705         ang_sort_comp = ang_sort_comp_hook;
1706         ang_sort_swap = ang_sort_swap_hook;
1707
1708         /* Sort the array by dungeon depth of monsters */
1709         ang_sort(who, &why, n);
1710
1711         /* Scan again */
1712         for (i = 0; i < n; i++)
1713         {
1714                 monster_race *r_ptr = &r_info[who[i]];
1715
1716                 cptr name = (r_name + r_ptr->name);
1717                 if (r_ptr->flags7 & (RF7_KAGE)) continue;
1718
1719                 /* Get the "name" */
1720 /*              if (r_ptr->flags1 & (RF1_QUESTOR)) */
1721                 if (0)
1722                 {
1723                         sprintf(nam, "[Q] %s", name);
1724                 }
1725                 else if (r_ptr->flags1 & (RF1_UNIQUE))
1726                 {
1727                         sprintf(nam, "[U] %s", name);
1728                 }
1729                 else
1730                 {
1731 #ifdef JP
1732                         sprintf(nam, "    %s", name);
1733 #else
1734                         sprintf(nam, "The %s", name);
1735 #endif
1736                 }
1737
1738
1739                 /* Level */
1740                 sprintf(lev, "%d", r_ptr->level);
1741
1742                 /* Rarity */
1743                 sprintf(rar, "%d", r_ptr->rarity);
1744
1745                 /* Speed */
1746                 if (r_ptr->speed >= 110)
1747                 {
1748                         sprintf(spd, "+%d", (r_ptr->speed - 110));
1749                 }
1750                 else
1751                 {
1752                         sprintf(spd, "-%d", (110 - r_ptr->speed));
1753                 }
1754
1755                 /* Armor Class */
1756                 sprintf(ac, "%d", r_ptr->ac);
1757
1758                 /* Hitpoints */
1759                 if ((r_ptr->flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
1760                 {
1761                         sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside);
1762                 }
1763                 else
1764                 {
1765                         sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside);
1766                 }
1767
1768
1769                 /* Experience */
1770                 sprintf(exp, "%ld", (long)(r_ptr->mexp));
1771
1772                 /* Hack -- use visual instead */
1773                 sprintf(exp, "%s '%c'", attr_to_text(r_ptr->d_attr), r_ptr->d_char);
1774
1775                 /* Dump the info */
1776                 fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s  %11.11s\n",
1777                         nam, lev, rar, spd, hp, ac, exp);
1778         }
1779
1780         /* End it */
1781         fprintf(fff, "\n");
1782
1783
1784         /* Free the "who" array */
1785         C_KILL(who, max_r_idx, s16b);
1786
1787         /* Check for errors */
1788         if (ferror(fff) || my_fclose(fff))
1789         {
1790                 msg_print("Cannot close spoiler file.");
1791                 return;
1792         }
1793
1794         /* Worked */
1795         msg_print("Successfully created a spoiler file.");
1796 }
1797
1798
1799
1800
1801 /*
1802  * Monster spoilers by: smchorse@ringer.cs.utsa.edu (Shawn McHorse)
1803  *
1804  * Primarily based on code already in mon-desc.c, mostly by -BEN-
1805  */
1806
1807
1808
1809 /*
1810  * Buffer text to the given file. (-SHAWN-)
1811  * This is basically c_roff() from mon-desc.c with a few changes.
1812  */
1813 static void spoil_out(cptr str)
1814 {
1815         cptr r;
1816
1817         /* Line buffer */
1818         static char roff_buf[256];
1819
1820 #ifdef JP
1821         char iskanji2=0;
1822 #endif
1823         /* Current pointer into line roff_buf */
1824         static char *roff_p = roff_buf;
1825
1826         /* Last space saved into roff_buf */
1827         static char *roff_s = NULL;
1828
1829         /* Special handling for "new sequence" */
1830         if (!str)
1831         {
1832                 if (roff_p != roff_buf) roff_p--;
1833                 while (*roff_p == ' ' && roff_p != roff_buf) roff_p--;
1834                 if (roff_p == roff_buf) fprintf(fff, "\n");
1835                 else
1836                 {
1837                         *(roff_p + 1) = '\0';
1838                         fprintf(fff, "%s\n\n", roff_buf);
1839                 }
1840                 roff_p = roff_buf;
1841                 roff_s = NULL;
1842                 roff_buf[0] = '\0';
1843                 return;
1844         }
1845
1846         /* Scan the given string, character at a time */
1847         for (; *str; str++)
1848         {
1849 #ifdef JP
1850                 char cbak;
1851                 int k_flag = iskanji((unsigned char)(*str));
1852 #endif
1853                 char ch = *str;
1854                 int wrap = (ch == '\n');
1855
1856 #ifdef JP
1857                 if (!isprint(ch) && !k_flag && !iskanji2) ch = ' ';
1858                 if(k_flag && !iskanji2)iskanji2=1;else iskanji2=0;
1859 #else
1860                 if (!isprint(ch)) ch = ' ';
1861 #endif
1862
1863 #ifdef JP
1864                 if ( roff_p >= roff_buf+( (k_flag) ? 74 : 75) ) wrap=1;
1865                 if ((ch == ' ') && (roff_p + 2 >= roff_buf + ((k_flag) ? 74 : 75))) wrap = 1;
1866 #else
1867                 if (roff_p >= roff_buf + 75) wrap = 1;
1868                 if ((ch == ' ') && (roff_p + 2 >= roff_buf + 75)) wrap = 1;
1869 #endif
1870
1871
1872                 /* Handle line-wrap */
1873                 if (wrap)
1874                 {
1875                         *roff_p = '\0';
1876                         r = roff_p;
1877 #ifdef JP
1878                                 cbak=' ';
1879 #endif
1880                         if (roff_s && (ch != ' '))
1881                         {
1882 #ifdef JP
1883                                 cbak=*roff_s;
1884 #endif
1885                                 *roff_s = '\0';
1886                                 r = roff_s + 1;
1887                         }
1888                         fprintf(fff, "%s\n", roff_buf);
1889                         roff_s = NULL;
1890                         roff_p = roff_buf;
1891 #ifdef JP
1892                         if(cbak != ' ') *roff_p++ = cbak; 
1893 #endif
1894                         while (*r) *roff_p++ = *r++;
1895                 }
1896
1897                 /* Save the char */
1898                 if ((roff_p > roff_buf) || (ch != ' '))
1899                 {
1900 #ifdef JP
1901                   if( !k_flag ){
1902                         if (ch == ' ' || ch == '(' ) roff_s = roff_p;
1903                   }
1904                   else{
1905                     if( iskanji2 && 
1906                         strncmp(str, "¡£", 2) != 0 && 
1907                         strncmp(str, "¡¢", 2) != 0 &&
1908                         strncmp(str, "¥£", 2) != 0 &&
1909                         strncmp(str, "¡¼", 2) != 0) roff_s = roff_p;
1910                   }
1911 #else
1912                         if (ch == ' ') roff_s = roff_p;
1913 #endif
1914
1915                         *roff_p++ = ch;
1916                 }
1917         }
1918 }
1919
1920
1921
1922 /*
1923  *  Hook function used in spoil_mon_info()
1924  */
1925 static void roff_func(byte attr, cptr str)
1926 {
1927         spoil_out(str);
1928 }
1929
1930
1931 /*
1932  * Create a spoiler file for monsters (-SHAWN-)
1933  */
1934 static void spoil_mon_info(cptr fname)
1935 {
1936         char buf[1024];
1937         int msex, i, l, n=0;
1938         bool breath, magic;
1939         u32b flags1, flags2, flags3, flags4, flags5, flags6, flags7;
1940
1941         u16b why = 2;
1942         s16b *who;
1943
1944         /* Build the filename */
1945         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
1946
1947         /* File type is "TEXT" */
1948         FILE_TYPE(FILE_TYPE_TEXT);
1949
1950         /* Open the file */
1951         fff = my_fopen(buf, "w");
1952
1953         /* Oops */
1954         if (!fff)
1955         {
1956                 msg_print("Cannot create spoiler file.");
1957                 return;
1958         }
1959
1960
1961         /* Dump the header */
1962         sprintf(buf, "Monster Spoilers for Hengband Version %d.%d.%d\n",
1963              FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1964
1965         spoil_out(buf);
1966         spoil_out("------------------------------------------\n\n");
1967
1968         /* Allocate the "who" array */
1969         C_MAKE(who, max_r_idx, s16b);
1970
1971         /* Scan the monsters */
1972         for (i = 1; i < max_r_idx; i++)
1973         {
1974                 monster_race *r_ptr = &r_info[i];
1975
1976                 /* Use that monster */
1977                 if (r_ptr->name) who[n++] = i;
1978         }
1979
1980         /* Select the sort method */
1981         ang_sort_comp = ang_sort_comp_hook;
1982         ang_sort_swap = ang_sort_swap_hook;
1983
1984         /* Sort the array by dungeon depth of monsters */
1985         ang_sort(who, &why, n);
1986
1987
1988         /*
1989          * List all monsters in order
1990          */
1991         for (l = 0; l < n; l++)
1992         {
1993                 monster_race *r_ptr = &r_info[who[l]];
1994
1995                 /* Extract the flags */
1996                 flags1 = r_ptr->flags1;
1997                 flags2 = r_ptr->flags2;
1998                 flags3 = r_ptr->flags3;
1999                 flags4 = r_ptr->flags4;
2000                 flags5 = r_ptr->flags5;
2001                 flags6 = r_ptr->flags6;
2002                 flags7 = r_ptr->flags7;
2003                 breath = FALSE;
2004                 magic = FALSE;
2005
2006                 /* Extract a gender (if applicable) */
2007                 if (flags1 & (RF1_FEMALE)) msex = 2;
2008                 else if (flags1 & (RF1_MALE)) msex = 1;
2009                 else msex = 0;
2010
2011
2012                 /* Prefix */
2013                 if (flags1 & (RF1_QUESTOR))
2014                 {
2015                         spoil_out("[Q] ");
2016                 }
2017                 else if (flags1 & (RF1_UNIQUE))
2018                 {
2019                         spoil_out("[U] ");
2020                 }
2021                 else
2022                 {
2023 #ifndef JP
2024                         spoil_out("The ");
2025 #endif
2026                 }
2027
2028                 /* Name */
2029 #ifdef JP
2030                 sprintf(buf, "%s/%s  (", (r_name + r_ptr->name),(r_name+r_ptr->E_name));  /* ---)--- */
2031 #else
2032                 sprintf(buf, "%s  (", (r_name + r_ptr->name));  /* ---)--- */
2033 #endif
2034
2035                 spoil_out(buf);
2036
2037                 /* Color */
2038                 spoil_out(attr_to_text(r_ptr->d_attr));
2039
2040                 /* Symbol --(-- */
2041                 sprintf(buf, " '%c')\n", r_ptr->d_char);
2042                 spoil_out(buf);
2043
2044
2045                 /* Indent */
2046                 sprintf(buf, "=== ");
2047                 spoil_out(buf);
2048
2049                 /* Number */
2050                 sprintf(buf, "Num:%d  ", who[l]);
2051                 spoil_out(buf);
2052
2053                 /* Level */
2054                 sprintf(buf, "Lev:%d  ", r_ptr->level);
2055                 spoil_out(buf);
2056
2057                 /* Rarity */
2058                 sprintf(buf, "Rar:%d  ", r_ptr->rarity);
2059                 spoil_out(buf);
2060
2061                 /* Speed */
2062                 if (r_ptr->speed >= 110)
2063                 {
2064                         sprintf(buf, "Spd:+%d  ", (r_ptr->speed - 110));
2065                 }
2066                 else
2067                 {
2068                         sprintf(buf, "Spd:-%d  ", (110 - r_ptr->speed));
2069                 }
2070                 spoil_out(buf);
2071
2072                 /* Hitpoints */
2073                 if ((flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1))
2074                 {
2075                         sprintf(buf, "Hp:%d  ", r_ptr->hdice * r_ptr->hside);
2076                 }
2077                 else
2078                 {
2079                         sprintf(buf, "Hp:%dd%d  ", r_ptr->hdice, r_ptr->hside);
2080                 }
2081                 spoil_out(buf);
2082
2083                 /* Armor Class */
2084                 sprintf(buf, "Ac:%d  ", r_ptr->ac);
2085                 spoil_out(buf);
2086
2087                 /* Experience */
2088                 sprintf(buf, "Exp:%ld\n", (long)(r_ptr->mexp));
2089                 spoil_out(buf);
2090
2091                 /* Reuse the code of monster recall. */
2092                 output_monster_spoiler(who[l], roff_func);
2093
2094                 spoil_out(NULL);
2095         }
2096
2097         /* Free the "who" array */
2098         C_KILL(who, max_r_idx, s16b);
2099
2100         /* Check for errors */
2101         if (ferror(fff) || my_fclose(fff))
2102         {
2103                 msg_print("Cannot close spoiler file.");
2104                 return;
2105         }
2106
2107         msg_print("Successfully created a spoiler file.");
2108 }
2109
2110
2111
2112 /*
2113  * Forward declare
2114  */
2115 extern void do_cmd_spoilers(void);
2116
2117 /*
2118  * Create Spoiler files -BEN-
2119  */
2120 void do_cmd_spoilers(void)
2121 {
2122         int i;
2123
2124
2125         /* Save the screen */
2126         screen_save();
2127
2128
2129         /* Drop priv's */
2130         safe_setuid_drop();
2131
2132
2133         /* Interact */
2134         while (1)
2135         {
2136                 /* Clear screen */
2137                 Term_clear();
2138
2139                 /* Info */
2140                 prt("Create a spoiler file.", 2, 0);
2141
2142                 /* Prompt for a file */
2143                 prt("(1) Brief Object Info (obj-desc.spo)", 5, 5);
2144                 prt("(2) Brief Artifact Info (artifact.spo)", 6, 5);
2145                 prt("(3) Brief Monster Info (mon-desc.spo)", 7, 5);
2146                 prt("(4) Full Monster Info (mon-info.spo)", 8, 5);
2147
2148                 /* Prompt */
2149 #ifdef JP
2150 prt("¥³¥Þ¥ó¥É:", 18, 0);
2151 #else
2152                 prt("Command: ", 12, 0);
2153 #endif
2154
2155
2156                 /* Get a choice */
2157                 i = inkey();
2158
2159                 /* Escape */
2160                 if (i == ESCAPE)
2161                 {
2162                         break;
2163                 }
2164
2165                 /* Option (1) */
2166                 else if (i == '1')
2167                 {
2168                         spoil_obj_desc("obj-desc.spo");
2169                 }
2170
2171                 /* Option (2) */
2172                 else if (i == '2')
2173                 {
2174                         spoil_artifact("artifact.spo");
2175                 }
2176
2177                 /* Option (3) */
2178                 else if (i == '3')
2179                 {
2180                         spoil_mon_desc("mon-desc.spo");
2181                 }
2182
2183                 /* Option (4) */
2184                 else if (i == '4')
2185                 {
2186                         spoil_mon_info("mon-info.spo");
2187                 }
2188
2189                 /* Oops */
2190                 else
2191                 {
2192                         bell();
2193                 }
2194
2195                 /* Flush messages */
2196                 msg_print(NULL);
2197         }
2198
2199
2200         /* Grab priv's */
2201         safe_setuid_grab();
2202
2203
2204         /* Restore the screen */
2205         screen_load();
2206 }
2207
2208 /*
2209  * Fill in an object description structure for a given object
2210  */
2211 static void random_artifact_analyze(object_type *o_ptr, obj_desc_list *desc_ptr)
2212 {
2213         analyze_general(o_ptr, desc_ptr->description);
2214         analyze_pval(o_ptr, &desc_ptr->pval_info);
2215         analyze_brand(o_ptr, desc_ptr->brands);
2216         analyze_slay(o_ptr, desc_ptr->slays);
2217         analyze_immune(o_ptr, desc_ptr->immunities);
2218         analyze_resist(o_ptr, desc_ptr->resistances);
2219         analyze_sustains(o_ptr, desc_ptr->sustains);
2220         analyze_misc_magic(o_ptr, desc_ptr->misc_magic);
2221         desc_ptr->activation = item_activation(o_ptr);
2222 #ifdef JP
2223         sprintf(desc_ptr->misc_desc, "½Å¤µ %d.%d kg",
2224                 lbtokg1(o_ptr->weight), lbtokg2(o_ptr->weight));
2225 #else
2226         sprintf(desc_ptr->misc_desc, "Weight %d.%d lbs",
2227                 o_ptr->weight / 10, o_ptr->weight % 10);
2228 #endif
2229 }
2230
2231 /* Create a spoiler file entry for an artifact */
2232
2233 static void spoiler_print_randart(object_type *o_ptr, obj_desc_list *art_ptr)
2234 {
2235         pval_info_type *pval_ptr = &art_ptr->pval_info;
2236
2237         char buf[80];
2238
2239         /* Don't indent the first line */
2240         fprintf(fff, "%s\n", art_ptr->description);
2241         
2242         /* unidentified */
2243         if (!(o_ptr->ident & (IDENT_MENTAL)))
2244         {
2245 #ifdef JP
2246                 fprintf(fff, "%sÉÔÌÀ\n",INDENT1);
2247 #else
2248                 fprintf(fff, "%sUnknown\n",INDENT1);
2249 #endif
2250         }
2251         else {
2252                 /* An "empty" pval description indicates that the pval affects nothing */
2253                 if (pval_ptr->pval_desc[0])
2254                 {
2255                         /* Mention the effects of pval */
2256 #ifdef JP
2257                         sprintf(buf, "%s¤Î½¤Àµ:", pval_ptr->pval_desc);
2258 #else
2259                         sprintf(buf, "%s to", pval_ptr->pval_desc);
2260 #endif
2261                         spoiler_outlist(buf, pval_ptr->pval_affects, ITEM_SEP);
2262                 }
2263           
2264                 /* Now deal with the description lists */
2265
2266 #ifdef JP
2267                 spoiler_outlist("ÂÐ:", art_ptr->slays, ITEM_SEP);
2268                 spoiler_outlist("Éð´ï°À­:", art_ptr->brands, LIST_SEP);
2269                 spoiler_outlist("ÌȱÖ:", art_ptr->immunities, ITEM_SEP);
2270                 spoiler_outlist("ÂÑÀ­:", art_ptr->resistances, ITEM_SEP);
2271                 spoiler_outlist("°Ý»ý:", art_ptr->sustains, ITEM_SEP);
2272 #else
2273                 spoiler_outlist("Slay", art_ptr->slays, ITEM_SEP);
2274                 spoiler_outlist("", art_ptr->brands, LIST_SEP);
2275                 spoiler_outlist("Immunity to", art_ptr->immunities, ITEM_SEP);
2276                 spoiler_outlist("Resist", art_ptr->resistances, ITEM_SEP);
2277                 spoiler_outlist("Sustain", art_ptr->sustains, ITEM_SEP);
2278 #endif
2279                 spoiler_outlist("", art_ptr->misc_magic, LIST_SEP);
2280
2281                 /* Write out the possible activation at the primary indention level */
2282                 if (art_ptr->activation)
2283                 {
2284 #ifdef JP
2285                         fprintf(fff, "%sȯư: %s\n", INDENT1, art_ptr->activation);
2286 #else
2287                         fprintf(fff, "%sActivates for %s\n", INDENT1, art_ptr->activation);
2288 #endif
2289                 }
2290         }
2291         /* End with the miscellaneous facts */
2292         fprintf(fff, "%s%s\n\n", INDENT1, art_ptr->misc_desc);
2293 }
2294
2295 /* Create a part of file for random artifacts */
2296
2297 static void spoil_random_artifact_aux(object_type *o_ptr, int i)
2298 {
2299         obj_desc_list artifact;
2300
2301         if (!object_known_p(o_ptr) || !o_ptr->art_name
2302                 || o_ptr->tval != group_artifact[i].tval)
2303                 return;
2304
2305         /* Analyze the artifact */
2306         random_artifact_analyze(o_ptr, &artifact);
2307
2308         /* Write out the artifact description to the spoiler file */
2309         spoiler_print_randart(o_ptr, &artifact);
2310 }
2311
2312 /*
2313  * Create a list file for random artifacts
2314  */
2315 void spoil_random_artifact(cptr fname)
2316 {
2317         int i,j;
2318
2319         store_type  *st_ptr;
2320         object_type *q_ptr;
2321
2322         char buf[1024];
2323
2324
2325         /* Drop priv's */
2326         safe_setuid_drop();
2327
2328         /* Build the filename */
2329         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2330
2331         /* File type is "TEXT" */
2332         FILE_TYPE(FILE_TYPE_TEXT);
2333
2334         /* Open the file */
2335         fff = my_fopen(buf, "w");
2336
2337         /* Oops */
2338         if (!fff)
2339         {
2340                 msg_print("Cannot create list file.");
2341                 return;
2342         }
2343
2344         /* Dump the header */
2345         sprintf(buf, "Random artifacts list.\r");
2346         spoiler_underline(buf);
2347
2348         /* List the artifacts by tval */
2349         for (j = 0; group_artifact[j].tval; j++)
2350         {
2351                 /* random artifacts wielding */
2352                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2353                 {
2354                         q_ptr = &inventory[i];
2355                         spoil_random_artifact_aux(q_ptr, j);
2356                 }
2357
2358                 /* random artifacts in inventory */
2359                 for (i = 0; i < INVEN_PACK; i++)
2360                 {
2361                         q_ptr = &inventory[i];
2362                         spoil_random_artifact_aux(q_ptr, j);
2363                 }
2364
2365                 /* random artifacts in home */
2366                 st_ptr = &town[1].store[STORE_HOME];
2367                 for (i = 0; i < st_ptr->stock_num; i++)
2368                 {
2369                         q_ptr = &st_ptr->stock[i];
2370                         spoil_random_artifact_aux(q_ptr, j);
2371                 }
2372
2373                 /* random artifacts in museum */
2374                 st_ptr = &town[1].store[STORE_MUSEUM];
2375                 for (i = 0; i < st_ptr->stock_num; i++)
2376                 {
2377                         q_ptr = &st_ptr->stock[i];
2378                         spoil_random_artifact_aux(q_ptr, j);
2379                 }
2380         }
2381
2382         /* Check for errors */
2383         if (ferror(fff) || my_fclose(fff))
2384         {
2385                 msg_print("Cannot close list file.");
2386                 return;
2387         }
2388
2389         /* Grab priv's */
2390         safe_setuid_grab();
2391
2392         /* Message */
2393         msg_print("Successfully created a list file.");
2394 }
2395
2396 #else
2397
2398 #ifdef MACINTOSH
2399 static int i = 0;
2400 #endif /* MACINTOSH */
2401
2402 #endif