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