OSDN Git Service

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