OSDN Git Service

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