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