OSDN Git Service

オプションで'D', 'H', 'M'を使うと "コマンド:" 行が2重に表示されるバグ
[hengband/hengband.git] / src / cmd4.c
1 /* File: cmd4.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
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: Interface commands */
12
13 #include "angband.h"
14
15
16
17 /*
18  * A set of functions to maintain automatic dumps of various kinds.
19  * -Mogami-
20  *
21  * remove_auto_dump(orig_file, mark)
22  *     Remove the old automatic dump of type "mark".
23  * auto_dump_printf(fmt, ...)
24  *     Dump a formatted string using fprintf().
25  * open_auto_dump(buf, mark)
26  *     Open a file, remove old dump, and add new header.
27  * close_auto_dump(void)
28  *     Add a footer, and close the file.
29  *
30  *    The dump commands of original Angband simply add new lines to
31  * existing files; these files will become bigger and bigger unless
32  * an user deletes some or all of these files by hand at some
33  * point.
34  *
35  *     These three functions automatically delete old dumped lines 
36  * before adding new ones.  Since there are various kinds of automatic 
37  * dumps in a single file, we add a header and a footer with a type 
38  * name for every automatic dump, and kill old lines only when the 
39  * lines have the correct type of header and footer.
40  *
41  *     We need to be quite paranoid about correctness; the user might 
42  * (mistakenly) edit the file by hand, and see all their work come
43  * to nothing on the next auto dump otherwise.  The current code only 
44  * detects changes by noting inconsistencies between the actual number 
45  * of lines and the number written in the footer.  Note that this will 
46  * not catch single-line edits.
47  */
48
49 /*
50  *  Mark strings for auto dump
51  */
52 static char auto_dump_header[] = "# vvvvvvv== %s ==vvvvvvv";
53 static char auto_dump_footer[] = "# ^^^^^^^== %s ==^^^^^^^";
54
55 /*
56  * Variables for auto dump
57  */
58 static FILE *auto_dump_stream;
59 static cptr auto_dump_mark;
60 static int auto_dump_line_num;
61
62 /*
63  * Remove old lines automatically generated before.
64  */
65 static void remove_auto_dump(cptr orig_file)
66 {
67         FILE *tmp_fff, *orig_fff;
68
69         char tmp_file[1024];
70         char buf[1024];
71         bool between_mark = FALSE;
72         bool changed = FALSE;
73         int line_num = 0;
74         long header_location = 0;
75         char header_mark_str[80];
76         char footer_mark_str[80];
77         size_t mark_len;
78
79         /* Prepare a header/footer mark string */
80         sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
81         sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
82
83         mark_len = strlen(footer_mark_str);
84
85         /* Open an old dump file in read-only mode */
86         orig_fff = my_fopen(orig_file, "r");
87
88         /* If original file does not exist, nothing to do */
89         if (!orig_fff) return;
90
91         /* Open a new (temporary) file */
92         tmp_fff = my_fopen_temp(tmp_file, 1024);
93
94         if (!tmp_fff)
95         {
96 #ifdef JP
97             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
98 #else
99             msg_format("Failed to create temporary file %s.", tmp_file);
100 #endif
101             msg_print(NULL);
102             return;
103         }
104
105         /* Loop for every line */
106         while (TRUE)
107         {
108                 /* Read a line */
109                 if (my_fgets(orig_fff, buf, sizeof(buf)))
110                 {
111                         /* Read error: Assume End of File */
112
113                         /*
114                          * Was looking for the footer, but not found.
115                          *
116                          * Since automatic dump might be edited by hand,
117                          * it's dangerous to kill these lines.
118                          * Seek back to the next line of the (pseudo) header,
119                          * and read again.
120                          */
121                         if (between_mark)
122                         {
123                                 fseek(orig_fff, header_location, SEEK_SET);
124                                 between_mark = FALSE;
125                                 continue;
126                         }
127
128                         /* Success -- End the loop */
129                         else
130                         {
131                                 break;
132                         }
133                 }
134
135                 /* We are looking for the header mark of automatic dump */
136                 if (!between_mark)
137                 {
138                         /* Is this line a header? */
139                         if (!strcmp(buf, header_mark_str))
140                         {
141                                 /* Memorise seek point of this line */
142                                 header_location = ftell(orig_fff);
143
144                                 /* Initialize counter for number of lines */
145                                 line_num = 0;
146
147                                 /* Look for the footer from now */
148                                 between_mark = TRUE;
149
150                                 /* There are some changes */
151                                 changed = TRUE;
152                         }
153
154                         /* Not a header */
155                         else
156                         {
157                                 /* Copy orginally lines */
158                                 fprintf(tmp_fff, "%s\n", buf);
159                         }
160                 }
161
162                 /* We are looking for the footer mark of automatic dump */
163                 else
164                 {
165                         /* Is this line a footer? */
166                         if (!strncmp(buf, footer_mark_str, mark_len))
167                         {
168                                 int tmp;
169
170                                 /*
171                                  * Compare the number of lines
172                                  *
173                                  * If there is an inconsistency between
174                                  * actual number of lines and the
175                                  * number here, the automatic dump
176                                  * might be edited by hand.  So it's
177                                  * dangerous to kill these lines.
178                                  * Seek back to the next line of the
179                                  * (pseudo) header, and read again.
180                                  */
181                                 if (!sscanf(buf + mark_len, " (%d)", &tmp)
182                                     || tmp != line_num)
183                                 {
184                                         fseek(orig_fff, header_location, SEEK_SET);
185                                 }
186
187                                 /* Look for another header */
188                                 between_mark = FALSE;
189                         }
190
191                         /* Not a footer */
192                         else
193                         {
194                                 /* Ignore old line, and count number of lines */
195                                 line_num++;
196                         }
197                 }
198         }
199
200         /* Close files */
201         my_fclose(orig_fff);
202         my_fclose(tmp_fff);
203
204         /* If there are some changes, overwrite the original file with new one */
205         if (changed)
206         {
207                 /* Copy contents of temporary file */
208
209                 tmp_fff = my_fopen(tmp_file, "r");
210                 orig_fff = my_fopen(orig_file, "w");
211
212                 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
213                         fprintf(orig_fff, "%s\n", buf);
214
215                 my_fclose(orig_fff);
216                 my_fclose(tmp_fff);
217         }
218
219         /* Kill the temporary file */
220         fd_kill(tmp_file);
221
222         return;
223 }
224
225
226 /*
227  * Dump a formatted line, using "vstrnfmt()".
228  */
229 static void auto_dump_printf(cptr fmt, ...)
230 {
231         cptr p;
232         va_list vp;
233
234         char buf[1024];
235
236         /* Begin the Varargs Stuff */
237         va_start(vp, fmt);
238
239         /* Format the args, save the length */
240         (void)vstrnfmt(buf, sizeof(buf), fmt, vp);
241
242         /* End the Varargs Stuff */
243         va_end(vp);
244
245         /* Count number of lines */
246         for (p = buf; *p; p++)
247         {
248                 if (*p == '\n') auto_dump_line_num++;
249         }
250
251         /* Dump it */
252         fprintf(auto_dump_stream, "%s", buf);
253 }
254
255
256 /*
257  *  Open file to append auto dump.
258  */
259 static bool open_auto_dump(cptr buf, cptr mark)
260 {
261
262         char header_mark_str[80];
263
264         /* Save the mark string */
265         auto_dump_mark = mark;
266
267         /* Prepare a header mark string */
268         sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
269
270         /* Remove old macro dumps */
271         remove_auto_dump(buf);
272
273         /* Append to the file */
274         auto_dump_stream = my_fopen(buf, "a");
275
276         /* Failure */
277         if (!auto_dump_stream) {
278 #ifdef JP
279                 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
280 #else
281                 msg_format("Failed to open %s.", buf);
282 #endif
283                 msg_print(NULL);
284
285                 /* Failed */
286                 return FALSE;
287         }
288
289         /* Start dumping */
290         fprintf(auto_dump_stream, "%s\n", header_mark_str);
291
292         /* Initialize counter */
293         auto_dump_line_num = 0;
294
295 #ifdef JP
296         auto_dump_printf("# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°À¸À®¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£\n");
297         auto_dump_printf("# *·Ù¹ð!!* ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤ë¤Î¤ÇÊÔ½¸¤·¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£\n");
298 #else
299         auto_dump_printf("# *Warning!*  The lines below are an automatic dump.\n");
300         auto_dump_printf("# Don't edit them; changes will be deleted and replaced automatically.\n");
301 #endif
302
303         /* Success */
304         return TRUE;
305 }
306
307 /*
308  *  Append foot part and close auto dump.
309  */
310 static void close_auto_dump(void)
311 {
312         char footer_mark_str[80];
313
314         /* Prepare a footer mark string */
315         sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
316
317 #ifdef JP
318         auto_dump_printf("# *·Ù¹ð!!* °Ê¾å¤Î¹Ô¤Ï¼«Æ°À¸À®¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£\n");
319         auto_dump_printf("# *·Ù¹ð!!* ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤ë¤Î¤ÇÊÔ½¸¤·¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£\n");
320 #else
321         auto_dump_printf("# *Warning!*  The lines above are an automatic dump.\n");
322         auto_dump_printf("# Don't edit them; changes will be deleted and replaced automatically.\n");
323 #endif
324
325         /* End of dump */
326         fprintf(auto_dump_stream, "%s (%d)\n", footer_mark_str, auto_dump_line_num);
327
328         /* Close */
329         my_fclose(auto_dump_stream);
330
331         return;
332 }
333
334
335 #ifndef JP
336 /*
337  * Return suffix of ordinal number
338  */
339 cptr get_ordinal_number_suffix(int num)
340 {
341         num = ABS(num) % 100;
342         switch (num % 10)
343         {
344         case 1:
345                 return (num == 11) ? "th" : "st";
346         case 2:
347                 return (num == 12) ? "th" : "nd";
348         case 3:
349                 return (num == 13) ? "th" : "rd";
350         default:
351                 return "th";
352         }
353 }
354 #endif
355
356
357 /*
358  *   Take note to the diary.
359  */
360 errr do_cmd_write_nikki(int type, int num, cptr note)
361 {
362         int day, hour, min;
363         FILE *fff = NULL;
364         char file_name[80];
365         char buf[1024];
366         cptr note_level = "";
367         bool do_level = TRUE;
368         char note_level_buf[40];
369         int q_idx;
370
371         static bool disable_nikki = FALSE;
372
373         extract_day_hour_min(&day, &hour, &min);
374
375         if (disable_nikki) return(-1);
376
377         if (type == NIKKI_FIX_QUEST_C ||
378             type == NIKKI_FIX_QUEST_F ||
379             type == NIKKI_RAND_QUEST_C ||
380             type == NIKKI_RAND_QUEST_F ||
381             type == NIKKI_TO_QUEST)
382         {
383                 int old_quest;
384
385                 old_quest = p_ptr->inside_quest;
386                 p_ptr->inside_quest = (quest[num].type == QUEST_TYPE_RANDOM) ? 0 : num;
387
388                 /* Get the quest text */
389                 init_flags = INIT_ASSIGN;
390
391                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
392
393                 /* Reset the old quest number */
394                 p_ptr->inside_quest = old_quest;
395         }
396
397 #ifdef JP
398         sprintf(file_name,"playrecord-%s.txt",savefile_base);
399 #else
400         /* different filne name to avoid mixing */
401         sprintf(file_name,"playrec-%s.txt",savefile_base);
402 #endif
403
404         /* Build the filename */
405         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
406
407         /* File type is "TEXT" */
408         FILE_TYPE(FILE_TYPE_TEXT);
409
410         fff = my_fopen(buf, "a");
411
412         /* Failure */
413         if (!fff)
414         {
415 #ifdef JP
416                 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£¥×¥ì¥¤µ­Ï¿¤ò°ì»þÄä»ß¤·¤Þ¤¹¡£", buf);
417 #else
418                 msg_format("Failed to open %s. Play-Record is disabled temporally.", buf);
419 #endif
420                 msg_format(NULL);
421                 disable_nikki=TRUE;
422                 return (-1);
423         }
424
425         q_idx = quest_number(dun_level);
426
427         if (write_level)
428         {
429                 if (p_ptr->inside_arena)
430 #ifdef JP
431                         note_level = "¥¢¥ê¡¼¥Ê:";
432 #else
433                         note_level = "Arane:";
434 #endif
435                 else if (!dun_level)
436 #ifdef JP
437                         note_level = "ÃϾå:";
438 #else
439                         note_level = "Surface:";
440 #endif
441                 else if (q_idx && (is_fixed_quest_idx(q_idx)
442                          && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
443 #ifdef JP
444                         note_level = "¥¯¥¨¥¹¥È:";
445 #else
446                         note_level = "Quest:";
447 #endif
448                 else
449                 {
450 #ifdef JP
451                         sprintf(note_level_buf, "%d³¬(%s):", dun_level, d_name+d_info[dungeon_type].name);
452 #else
453                         sprintf(note_level_buf, "%s L%d:", d_name+d_info[dungeon_type].name, dun_level);
454 #endif
455                         note_level = note_level_buf;
456                 }
457         }
458
459         switch(type)
460         {
461                 case NIKKI_HIGAWARI:
462                 {
463 #ifdef JP
464                         fprintf(fff, "%dÆüÌÜ\n",day);
465 #else
466                         fprintf(fff, "Day %d\n",day);
467 #endif
468                         do_level = FALSE;
469                         break;
470                 }
471                 case NIKKI_BUNSHOU:
472                 {
473                         if (num)
474                         {
475                                 fprintf(fff, "%s\n",note);
476                                 do_level = FALSE;
477                         }
478                         else
479                                 fprintf(fff, " %2d:%02d %20s %s\n",hour, min, note_level, note);
480                         break;
481                 }
482                 case NIKKI_ART:
483                 {
484 #ifdef JP
485                         fprintf(fff, " %2d:%02d %20s %s¤òȯ¸«¤·¤¿¡£\n", hour, min, note_level, note);
486 #else
487                         fprintf(fff, " %2d:%02d %20s discovered %s.\n", hour, min, note_level, note);
488 #endif
489                         break;
490                 }
491                 case NIKKI_UNIQUE:
492                 {
493 #ifdef JP
494                         fprintf(fff, " %2d:%02d %20s %s¤òÅݤ·¤¿¡£\n", hour, min, note_level, note);
495 #else
496                         fprintf(fff, " %2d:%02d %20s defeated %s.\n", hour, min, note_level, note);
497 #endif
498                         break;
499                 }
500                 case NIKKI_FIX_QUEST_C:
501                 {
502                         if (quest[num].flags & QUEST_FLAG_SILENT) break;
503 #ifdef JP
504                         fprintf(fff, " %2d:%02d %20s ¥¯¥¨¥¹¥È¡Ö%s¡×¤òãÀ®¤·¤¿¡£\n", hour, min, note_level, quest[num].name);
505 #else
506                         fprintf(fff, " %2d:%02d %20s completed quest '%s'.\n", hour, min, note_level, quest[num].name);
507 #endif
508                         break;
509                 }
510                 case NIKKI_FIX_QUEST_F:
511                 {
512                         if (quest[num].flags & QUEST_FLAG_SILENT) break;
513 #ifdef JP
514                         fprintf(fff, " %2d:%02d %20s ¥¯¥¨¥¹¥È¡Ö%s¡×¤«¤éÌ¿¤«¤é¤¬¤éƨ¤²µ¢¤Ã¤¿¡£\n", hour, min, note_level, quest[num].name);
515 #else
516                         fprintf(fff, " %2d:%02d %20s run away from quest '%s'.\n", hour, min, note_level, quest[num].name);
517 #endif
518                         break;
519                 }
520                 case NIKKI_RAND_QUEST_C:
521                 {
522                         char name[80];
523                         strcpy(name, r_name+r_info[quest[num].r_idx].name);
524 #ifdef JP
525                         fprintf(fff, " %2d:%02d %20s ¥é¥ó¥À¥à¥¯¥¨¥¹¥È(%s)¤òãÀ®¤·¤¿¡£\n", hour, min, note_level, name);
526 #else
527                         fprintf(fff, " %2d:%02d %20s completed randome quest '%s'\n", hour, min, note_level, name);
528 #endif
529                         break;
530                 }
531                 case NIKKI_RAND_QUEST_F:
532                 {
533                         char name[80];
534                         strcpy(name, r_name+r_info[quest[num].r_idx].name);
535 #ifdef JP
536                         fprintf(fff, " %2d:%02d %20s ¥é¥ó¥À¥à¥¯¥¨¥¹¥È(%s)¤«¤éƨ¤²½Ð¤·¤¿¡£\n", hour, min, note_level, name);
537 #else
538                         fprintf(fff, " %2d:%02d %20s ran away from quest '%s'.\n", hour, min, note_level, name);
539 #endif
540                         break;
541                 }
542                 case NIKKI_MAXDEAPTH:
543                 {
544 #ifdef JP
545                         fprintf(fff, " %2d:%02d %20s %s¤ÎºÇ¿¼³¬%d³¬¤ËÅþ㤷¤¿¡£\n", hour, min, note_level, d_name+d_info[dungeon_type].name, num);
546 #else
547                         fprintf(fff, " %2d:%02d %20s reached level %d of %s for the first time.\n", hour, min, note_level, num, d_name+d_info[dungeon_type].name);
548 #endif
549                         break;
550                 }
551                 case NIKKI_TRUMP:
552                 {
553 #ifdef JP
554                         fprintf(fff, " %2d:%02d %20s %s%s¤ÎºÇ¿¼³¬¤ò%d³¬¤Ë¥»¥Ã¥È¤·¤¿¡£\n", hour, min, note_level, note, d_name + d_info[num].name, max_dlv[num]);
555 #else
556                         fprintf(fff, " %2d:%02d %20s reset recall level of %s to %d %s.\n", hour, min, note_level, d_name + d_info[num].name, max_dlv[num], note);
557 #endif
558                         break;
559                 }
560                 case NIKKI_STAIR:
561                 {
562                         cptr to;
563                         if (q_idx && (is_fixed_quest_idx(q_idx)
564                              && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
565                         {
566 #ifdef JP
567                                 to = "ÃϾå";
568 #else
569                                 to = "the surface";
570 #endif
571                         }
572                         else
573                         {
574 #ifdef JP
575                                 if (!(dun_level+num)) to = "ÃϾå";
576                                 else to = format("%d³¬", dun_level+num);
577 #else
578                                 if (!(dun_level+num)) to = "the surface";
579                                 else to = format("level %d", dun_level+num);
580 #endif
581                         }
582
583 #ifdef JP 
584                         fprintf(fff, " %2d:%02d %20s %s¤Ø%s¡£\n", hour, min, note_level, to, note);
585 #else
586                         fprintf(fff, " %2d:%02d %20s %s %s.\n", hour, min, note_level, note, to);
587 #endif
588                         break;
589                 }
590                 case NIKKI_RECALL:
591                 {
592                         if (!num)
593 #ifdef JP
594                                 fprintf(fff, " %2d:%02d %20s µ¢´Ô¤ò»È¤Ã¤Æ%s¤Î%d³¬¤Ø²¼¤ê¤¿¡£\n", hour, min, note_level, d_name+d_info[dungeon_type].name, max_dlv[dungeon_type]);
595 #else
596                                 fprintf(fff, " %2d:%02d %20s recalled to dungeon level %d of %s.\n", hour, min, note_level, max_dlv[dungeon_type], d_name+d_info[dungeon_type].name);
597 #endif
598                         else
599 #ifdef JP
600                                 fprintf(fff, " %2d:%02d %20s µ¢´Ô¤ò»È¤Ã¤ÆÃϾå¤Ø¤ÈÌá¤Ã¤¿¡£\n", hour, min, note_level);
601 #else
602                                 fprintf(fff, " %2d:%02d %20s recalled from dungeon to surface.\n", hour, min, note_level);
603 #endif
604                         break;
605                 }
606                 case NIKKI_TO_QUEST:
607                 {
608                         if (quest[num].flags & QUEST_FLAG_SILENT) break;
609 #ifdef JP
610                         fprintf(fff, " %2d:%02d %20s ¥¯¥¨¥¹¥È¡Ö%s¡×¤Ø¤ÈÆÍÆþ¤·¤¿¡£\n", hour, min, note_level, quest[num].name);
611 #else
612                         fprintf(fff, " %2d:%02d %20s entered the quest '%s'.\n", hour, min, note_level, quest[num].name);
613 #endif
614                         break;
615                 }
616                 case NIKKI_TELE_LEV:
617                 {
618 #ifdef JP
619                         fprintf(fff, " %2d:%02d %20s ¥ì¥Ù¥ë¡¦¥Æ¥ì¥Ý¡¼¥È¤Çæ½Ð¤·¤¿¡£\n", hour, min, note_level);
620 #else
621                         fprintf(fff, " %2d:%02d %20s Got out using teleport level.\n", hour, min, note_level);
622 #endif
623                         break;
624                 }
625                 case NIKKI_BUY:
626                 {
627 #ifdef JP
628                         fprintf(fff, " %2d:%02d %20s %s¤ò¹ØÆþ¤·¤¿¡£\n", hour, min, note_level, note);
629 #else
630                         fprintf(fff, " %2d:%02d %20s bought %s.\n", hour, min, note_level, note);
631 #endif
632                         break;
633                 }
634                 case NIKKI_SELL:
635                 {
636 #ifdef JP
637                         fprintf(fff, " %2d:%02d %20s %s¤òÇäµÑ¤·¤¿¡£\n", hour, min, note_level, note);
638 #else
639                         fprintf(fff, " %2d:%02d %20s sold %s.\n", hour, min, note_level, note);
640 #endif
641                         break;
642                 }
643                 case NIKKI_ARENA:
644                 {
645                         if (num < 0)
646                         {
647 #ifdef JP
648                                 fprintf(fff, " %2d:%02d %20s Æ®µ»¾ì¤Î%d²óÀï¤Ç¡¢%s¤ÎÁ°¤ËÇÔ¤ìµî¤Ã¤¿¡£\n", hour, min, note_level, -num, note);
649 #else
650                                 int n = -num;
651                                 fprintf(fff, " %2d:%02d %20s beaten by %s in the %d%s fight.\n", hour, min, note_level, note, n, get_ordinal_number_suffix(n));
652 #endif
653                                 break;
654                         }
655 #ifdef JP
656                         fprintf(fff, " %2d:%02d %20s Æ®µ»¾ì¤Î%d²óÀï(%s)¤Ë¾¡Íø¤·¤¿¡£\n", hour, min, note_level, num, note);
657 #else
658                         fprintf(fff, " %2d:%02d %20s won the %d%s fight (%s).\n", hour, min, note_level, num, get_ordinal_number_suffix(num), note);
659 #endif
660                         if (num == MAX_ARENA_MONS)
661                         {
662 #ifdef JP
663                                 fprintf(fff, "                 Æ®µ»¾ì¤Î¤¹¤Ù¤Æ¤ÎŨ¤Ë¾¡Íø¤·¡¢¥Á¥ã¥ó¥Ô¥ª¥ó¤È¤Ê¤Ã¤¿¡£\n");
664 #else
665                                 fprintf(fff, "                 won all fight to become a Chanpion.\n");
666 #endif
667                                 do_level = FALSE;
668                         }
669                         break;
670                 }
671                 case NIKKI_HANMEI:
672                 {
673 #ifdef JP
674                         fprintf(fff, " %2d:%02d %20s %s¤ò¼±Ê̤·¤¿¡£\n", hour, min, note_level, note);
675 #else
676                         fprintf(fff, " %2d:%02d %20s identified %s.\n", hour, min, note_level, note);
677 #endif
678                         break;
679                 }
680                 case NIKKI_WIZ_TELE:
681                 {
682                         cptr to;
683                         if (!dun_level)
684 #ifdef JP
685                                 to = "ÃϾå";
686 #else
687                                 to = "the surface";
688 #endif
689                         else
690 #ifdef JP
691                                 to = format("%d³¬(%s)", dun_level, d_name+d_info[dungeon_type].name);
692 #else
693                                 to = format("level %d of %s", dun_level, d_name+d_info[dungeon_type].name);
694 #endif
695
696 #ifdef JP
697                         fprintf(fff, " %2d:%02d %20s %s¤Ø¤È¥¦¥£¥¶¡¼¥É¡¦¥Æ¥ì¥Ý¡¼¥È¤Ç°ÜÆ°¤·¤¿¡£\n", hour, min, note_level, to);
698 #else
699                         fprintf(fff, " %2d:%02d %20s wizard-teleport to %s.\n", hour, min, note_level, to);
700 #endif
701                         break;
702                 }
703                 case NIKKI_PAT_TELE:
704                 {
705                         cptr to;
706                         if (!dun_level)
707 #ifdef JP
708                                 to = "ÃϾå";
709 #else
710                                 to = "the surface";
711 #endif
712                         else
713 #ifdef JP
714                                 to = format("%d³¬(%s)", dun_level, d_name+d_info[dungeon_type].name);
715 #else
716                                 to = format("level %d of %s", dun_level, d_name+d_info[dungeon_type].name);
717 #endif
718
719 #ifdef JP
720                         fprintf(fff, " %2d:%02d %20s %s¤Ø¤È¥Ñ¥¿¡¼¥ó¤ÎÎϤǰÜÆ°¤·¤¿¡£\n", hour, min, note_level, to);
721 #else
722                         fprintf(fff, " %2d:%02d %20s used Pattern to teleport to %s.\n", hour, min, note_level, to);
723 #endif
724                         break;
725                 }
726                 case NIKKI_LEVELUP:
727                 {
728 #ifdef JP
729                         fprintf(fff, " %2d:%02d %20s ¥ì¥Ù¥ë¤¬%d¤Ë¾å¤¬¤Ã¤¿¡£\n", hour, min, note_level, num);
730 #else
731                         fprintf(fff, " %2d:%02d %20s reached player level %d.\n", hour, min, note_level, num);
732 #endif
733                         break;
734                 }
735                 case NIKKI_GAMESTART:
736                 {
737                         time_t ct = time((time_t*)0);
738                         do_level = FALSE;
739                         if (num)
740                         {
741                                 fprintf(fff, "%s %s",note, ctime(&ct));
742                         }
743                         else
744                                 fprintf(fff, " %2d:%02d %20s %s %s",hour, min, note_level, note, ctime(&ct));
745                         break;
746                 }
747                 case NIKKI_NAMED_PET:
748                 {
749                         fprintf(fff, " %2d:%02d %20s ", hour, min, note_level);
750                         switch (num)
751                         {
752                                 case 0:
753 #ifdef JP
754                                         fprintf(fff, "%s¤òι¤Îͧ¤Ë¤¹¤ë¤³¤È¤Ë·è¤á¤¿¡£\n", note);
755 #else
756                                         fprintf(fff, "decided to travel together with %s.\n", note);
757 #endif
758                                         break;
759                                 case 1:
760 #ifdef JP
761                                         fprintf(fff, "%s¤Î̾Á°¤ò¾Ã¤·¤¿¡£\n", note);
762 #else
763                                         fprintf(fff, "unnamed %s.\n", note);
764 #endif
765                                         break;
766                                 case 2:
767 #ifdef JP
768                                         fprintf(fff, "%s¤ò²òÊü¤·¤¿¡£\n", note);
769 #else
770                                         fprintf(fff, "dismissed %s.\n", note);
771 #endif
772                                         break;
773                                 case 3:
774 #ifdef JP
775                                         fprintf(fff, "%s¤¬»à¤ó¤Ç¤·¤Þ¤Ã¤¿¡£\n", note);
776 #else
777                                         fprintf(fff, "%s died.\n", note);
778 #endif
779                                         break;
780                                 case 4:
781 #ifdef JP
782                                         fprintf(fff, "%s¤ò¤ª¤¤¤ÆÊ̤ΥޥåפذÜÆ°¤·¤¿¡£\n", note);
783 #else
784                                         fprintf(fff, "moved to another map leaving %s behind.\n", note);
785 #endif
786                                         break;
787                                 case 5:
788 #ifdef JP
789                                         fprintf(fff, "%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£\n", note);
790 #else
791                                         fprintf(fff, "lost sight of %s.\n", note);
792 #endif
793                                         break;
794                                 case 6:
795 #ifdef JP
796                                         fprintf(fff, "%s¤¬*Ç˲õ*¤Ë¤è¤Ã¤Æ¾Ã¤¨µî¤Ã¤¿¡£\n", note);
797 #else
798                                         fprintf(fff, "%s was made disappeared by *destruction*.\n", note);
799 #endif
800                                         break;
801                                 case 7:
802 #ifdef JP
803                                         fprintf(fff, "%s¤¬´äÀФ˲¡¤·ÄÙ¤µ¤ì¤¿¡£\n", note);
804 #else
805                                         fprintf(fff, "%s was crushed by falling rocks.\n", note);
806 #endif
807                                         break;
808                                 default:
809                                         fprintf(fff, "\n");
810                                         break;
811                         }
812                         break;
813                 }
814                 default:
815                         break;
816         }
817
818         my_fclose(fff);
819
820         if (do_level) write_level = FALSE;
821
822         return (0);
823 }
824
825
826 #define MAX_SUBTITLE (sizeof(subtitle)/sizeof(subtitle[0]))
827
828 static void do_cmd_disp_nikki(void)
829 {
830         char nikki_title[256];
831         char file_name[80];
832         char buf[1024];
833         char tmp[80];
834 #ifdef JP
835         static const char subtitle[][30] = {"ºÇ¶¯¤ÎÆùÂΤòµá¤á¤Æ",
836                                            "¿ÍÀ¸¤½¤ì¤Ï¤Ï¤«¤Ê¤¤",
837                                            "ÌÀÆü¤Ë¸þ¤«¤Ã¤Æ",
838                                            "꤫¤é¤Ü¤¿¤â¤Á",
839                                            "¤¢¤È¤Îº×¤ê",
840                                            "¤½¤ì¤Ï¤¤¤¤¹Í¤¨¤À",
841                                            "²¿¤È¤Ç¤â¸À¤¨",
842                                            "ÅƤˤâ³Ñ¤Ë¤â",
843                                            "¥¦¥½¤À¤±¤É",
844                                            "¤â¤Ï¤ä¤³¤ì¤Þ¤Ç",
845                                            "¤Ê¤ó¤Ç¤³¤¦¤Ê¤ë¤Î",
846                                            "¤½¤ì¤Ï̵Íý¤À",
847                                            "Åݤ¹¤Ù¤­Å¨¤Ï¥²¡û¥Ä",
848                                            "¤ó¡Á¡©Ê¹¤³¤¨¤ó¤Ê¤¡",
849                                            "¥ª¥ì¤Î̾¤ò¸À¤Ã¤Æ¤ß¤í",
850                                            "Ƭ¤¬ÊѤˤʤäÁ¤ã¤Ã¤¿",
851                                            "¸ß´¹¤·¤Þ¤»¤ó",
852                                            "¤»¤Ã¤«¤¯¤À¤«¤é",
853                                            "¤Þ¤À¤Þ¤À´Å¤¤¤Í",
854                                            "¤à¤´¤¤¤à¤´¤¹¤®¤ë",
855                                            "¤³¤ó¤Ê¤â¤ó¤¸¤ã¤Ê¤¤",
856                                            "¤À¤á¤À¤³¤ê¤ã",
857                                            "¼¡¤¤¤Ã¤Æ¤ß¤è¤¦",
858                                            "¤Á¤ç¤Ã¤È¤À¤±¤è",
859                                            "°¥¤·¤­ËÁ¸±¼Ô",
860                                            "Ìî˾¤Î²Ì¤Æ",
861                                            "̵¸ÂÃϹö",
862                                            "¿À¤Ë·ö²Þ¤òÇä¤ë¼Ô",
863                                            "̤ÃΤÎÀ¤³¦¤Ø",
864                                            "ºÇ¹â¤ÎƬǾ¤òµá¤á¤Æ"};
865 #else
866         static const char subtitle[][51] ={"Quest of The World's Toughest Body",
867                                            "Attack is the best form of defence.",
868                                            "Might is right.",
869                                            "An unexpected windfall",
870                                            "A drowning man will catch at a straw",
871                                            "Don't count your chickens before they are hatched.",
872                                            "It is no use crying over spilt milk.",
873                                            "Seeing is believing.",
874                                            "Strike the iron while it is hot.",
875                                            "I don't care what follows.",
876                                            "To dig a well to put out a house on fire.",
877                                            "Tomorrow is another day.",
878                                            "Easy come, easy go.",
879                                            "The more haste, the less speed.",
880                                            "Where there is life, there is hope.",
881                                            "There is no royal road to *WINNER*.",
882                                            "Danger past, God forgotten.",
883                                            "The best thing to do now is to run away.",
884                                            "Life is but an empty dream.",
885                                            "Dead men tell no tales.",
886                                            "A book that remains shut is but a block.",
887                                            "Misfortunes never come singly.",
888                                            "A little knowledge is a dangerous thing.",
889                                            "History repeats itself.",
890                                            "*WINNER* was not built in a day.",
891                                            "Ignorance is bliss.",
892                                            "To lose is to win?",
893                                            "No medicine can cure folly.",
894                                            "All good things come to an end.",
895                                            "M$ Empire strikes back.",
896                                            "To see is to believe",
897                                            "Time is money.",
898                                            "Quest of The World's Greatest Brain"};
899 #endif
900 #ifdef JP
901         sprintf(file_name,"playrecord-%s.txt",savefile_base);
902 #else
903         sprintf(file_name,"playrec-%s.txt",savefile_base);
904 #endif
905
906         /* Build the filename */
907         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
908
909         if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_MONK || p_ptr->pclass == CLASS_SAMURAI || p_ptr->pclass == CLASS_BERSERKER)
910                 strcpy(tmp,subtitle[randint0(MAX_SUBTITLE-1)]);
911         else if (p_ptr->pclass == CLASS_MAGE || p_ptr->pclass == CLASS_HIGH_MAGE || p_ptr->pclass == CLASS_SORCERER)
912                 strcpy(tmp,subtitle[randint0(MAX_SUBTITLE-1)+1]);
913         else strcpy(tmp,subtitle[randint0(MAX_SUBTITLE-2)+1]);
914
915 #ifdef JP
916         sprintf(nikki_title, "¡Ö%s%s%s¤ÎÅÁÀâ -%s-¡×",
917                 ap_ptr->title, ap_ptr->no ? "¤Î" : "", player_name, tmp);
918 #else
919         sprintf(nikki_title, "Legend of %s %s '%s'",
920                 ap_ptr->title, player_name, tmp);
921 #endif
922
923         /* Display the file contents */
924         show_file(FALSE, buf, nikki_title, -1, 0);
925 }
926
927 static void do_cmd_bunshou(void)
928 {
929         char tmp[80] = "\0";
930         char bunshou[80] = "\0";
931
932 #ifdef JP
933         if (get_string("ÆâÍÆ: ", tmp, 79))
934 #else
935         if (get_string("diary note: ", tmp, 79))
936 #endif
937         {
938                 strcpy(bunshou, tmp);
939
940                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, bunshou);
941         }
942 }
943
944 static void do_cmd_last_get(void)
945 {
946         char buf[256];
947         s32b turn_tmp;
948
949         if (record_o_name[0] == '\0') return;
950
951 #ifdef JP
952         sprintf(buf,"%s¤ÎÆþ¼ê¤òµ­Ï¿¤·¤Þ¤¹¡£",record_o_name);
953 #else
954         sprintf(buf,"Do you really want to record getting %s? ",record_o_name);
955 #endif
956         if (!get_check(buf)) return;
957
958         turn_tmp = turn;
959         turn = record_turn;
960 #ifdef JP
961         sprintf(buf,"%s¤ò¼ê¤ËÆþ¤ì¤¿¡£", record_o_name);
962 #else
963         sprintf(buf,"descover %s.", record_o_name);
964 #endif
965         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, buf);
966         turn = turn_tmp;
967 }
968
969 static void do_cmd_erase_nikki(void)
970 {
971         char file_name[80];
972         char buf[256];
973         FILE *fff = NULL;
974
975 #ifdef JP
976         if (!get_check("ËÜÅö¤Ëµ­Ï¿¤ò¾Ãµî¤·¤Þ¤¹¤«¡©")) return;
977 #else
978         if (!get_check("Do you really want to delete all your record? ")) return;
979 #endif
980
981 #ifdef JP
982         sprintf(file_name,"playrecord-%s.txt",savefile_base);
983 #else
984         sprintf(file_name,"playrec-%s.txt",savefile_base);
985 #endif
986
987         /* Build the filename */
988         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
989
990         /* Remove the file */
991         fd_kill(buf);
992
993         fff = my_fopen(buf, "w");
994         if(fff){
995                 my_fclose(fff);
996 #ifdef JP
997                 msg_format("µ­Ï¿¤ò¾Ãµî¤·¤Þ¤·¤¿¡£");
998 #else
999                 msg_format("deleted record.");
1000 #endif
1001         }else{
1002 #ifdef JP
1003                 msg_format("%s ¤Î¾Ãµî¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£", buf);
1004 #else
1005                 msg_format("failed to delete %s.", buf);
1006 #endif
1007         }
1008         msg_print(NULL);
1009 }
1010
1011
1012 void do_cmd_nikki(void)
1013 {
1014         int i;
1015
1016         /* File type is "TEXT" */
1017         FILE_TYPE(FILE_TYPE_TEXT);
1018
1019         /* Save the screen */
1020         screen_save();
1021
1022         /* Interact until done */
1023         while (1)
1024         {
1025                 /* Clear screen */
1026                 Term_clear();
1027
1028                 /* Ask for a choice */
1029 #ifdef JP
1030                 prt("[ µ­Ï¿¤ÎÀßÄê ]", 2, 0);
1031 #else
1032                 prt("[ Play Record ]", 2, 0);
1033 #endif
1034
1035
1036                 /* Give some choices */
1037 #ifdef JP
1038                 prt("(1) µ­Ï¿¤ò¸«¤ë", 4, 5);
1039                 prt("(2) Ê¸¾Ï¤òµ­Ï¿¤¹¤ë", 5, 5);
1040                 prt("(3) Ä¾Á°¤ËÆþ¼êËô¤Ï´ÕÄꤷ¤¿¤â¤Î¤òµ­Ï¿¤¹¤ë", 6, 5);
1041                 prt("(4) µ­Ï¿¤ò¾Ãµî¤¹¤ë", 7, 5);
1042 #else
1043                 prt("(1) Display your record", 4, 5);
1044                 prt("(2) Add record", 5, 5);
1045                 prt("(3) Record item you last get/identify", 6, 5);
1046                 prt("(4) Delete your record", 7, 5);
1047 #endif
1048
1049
1050                 /* Prompt */
1051 #ifdef JP
1052                 prt("¥³¥Þ¥ó¥É:", 18, 0);
1053 #else
1054                 prt("Command: ", 18, 0);
1055 #endif
1056
1057
1058                 /* Prompt */
1059                 i = inkey();
1060
1061                 /* Done */
1062                 if (i == ESCAPE) break;
1063
1064                 switch (i)
1065                 {
1066                 case '1':
1067                         do_cmd_disp_nikki();
1068                         break;
1069                 case '2':
1070                         do_cmd_bunshou();
1071                         break;
1072                 case '3':
1073                         do_cmd_last_get();
1074                         break;
1075                 case '4':
1076                         do_cmd_erase_nikki();
1077                         break;
1078                 default: /* Unknown option */
1079                         bell();
1080                 }
1081
1082                 /* Flush messages */
1083                 msg_print(NULL);
1084         }
1085
1086         /* Restore the screen */
1087         screen_load();
1088 }
1089
1090 /*
1091  * Hack -- redraw the screen
1092  *
1093  * This command performs various low level updates, clears all the "extra"
1094  * windows, does a total redraw of the main window, and requests all of the
1095  * interesting updates and redraws that I can think of.
1096  *
1097  * This command is also used to "instantiate" the results of the user
1098  * selecting various things, such as graphics mode, so it must call
1099  * the "TERM_XTRA_REACT" hook before redrawing the windows.
1100  */
1101 void do_cmd_redraw(void)
1102 {
1103         int j;
1104
1105         term *old = Term;
1106
1107
1108         /* Hack -- react to changes */
1109         Term_xtra(TERM_XTRA_REACT, 0);
1110
1111
1112         /* Combine and Reorder the pack (later) */
1113         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1114
1115
1116         /* Update torch */
1117         p_ptr->update |= (PU_TORCH);
1118
1119         /* Update stuff */
1120         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
1121
1122         /* Forget lite/view */
1123         p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
1124
1125         /* Update lite/view */
1126         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
1127
1128         /* Update monsters */
1129         p_ptr->update |= (PU_MONSTERS);
1130
1131         /* Redraw everything */
1132         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1133
1134         /* Window stuff */
1135         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1136
1137         /* Window stuff */
1138         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
1139
1140         update_playtime();
1141
1142         /* Hack -- update */
1143         handle_stuff();
1144
1145         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
1146
1147
1148         /* Redraw every window */
1149         for (j = 0; j < 8; j++)
1150         {
1151                 /* Dead window */
1152                 if (!angband_term[j]) continue;
1153
1154                 /* Activate */
1155                 Term_activate(angband_term[j]);
1156
1157                 /* Redraw */
1158                 Term_redraw();
1159
1160                 /* Refresh */
1161                 Term_fresh();
1162
1163                 /* Restore */
1164                 Term_activate(old);
1165         }
1166 }
1167
1168
1169 /*
1170  * Hack -- change name
1171  */
1172 void do_cmd_change_name(void)
1173 {
1174         char    c;
1175
1176         int             mode = 0;
1177
1178         char    tmp[160];
1179
1180
1181         /* Save the screen */
1182         screen_save();
1183
1184         /* Forever */
1185         while (1)
1186         {
1187                 update_playtime();
1188
1189                 /* Display the player */
1190                 display_player(mode);
1191
1192                 if (mode == 4)
1193                 {
1194                         mode = 0;
1195                         display_player(mode);
1196                 }
1197
1198                 /* Prompt */
1199 #ifdef JP
1200                 Term_putstr(2, 23, -1, TERM_WHITE,
1201                             "['c'¤Ç̾Á°Êѹ¹, 'f'¤Ç¥Õ¥¡¥¤¥ë¤Ø½ñ½Ð, 'h'¤Ç¥â¡¼¥ÉÊѹ¹, ESC¤Ç½ªÎ»]");
1202 #else
1203                 Term_putstr(2, 23, -1, TERM_WHITE,
1204                         "['c' to change name, 'f' to file, 'h' to change mode, or ESC]");
1205 #endif
1206
1207
1208                 /* Query */
1209                 c = inkey();
1210
1211                 /* Exit */
1212                 if (c == ESCAPE) break;
1213
1214                 /* Change name */
1215                 if (c == 'c')
1216                 {
1217                         get_name();
1218
1219                         /* Process the player name */
1220                         process_player_name(FALSE);
1221                 }
1222
1223                 /* File dump */
1224                 else if (c == 'f')
1225                 {
1226                         sprintf(tmp, "%s.txt", player_base);
1227 #ifdef JP
1228                         if (get_string("¥Õ¥¡¥¤¥ë̾: ", tmp, 80))
1229 #else
1230                         if (get_string("File name: ", tmp, 80))
1231 #endif
1232
1233                         {
1234                                 if (tmp[0] && (tmp[0] != ' '))
1235                                 {
1236                                         file_character(tmp);
1237                                 }
1238                         }
1239                 }
1240
1241                 /* Toggle mode */
1242                 else if (c == 'h')
1243                 {
1244                         mode++;
1245                 }
1246
1247                 /* Oops */
1248                 else
1249                 {
1250                         bell();
1251                 }
1252
1253                 /* Flush messages */
1254                 msg_print(NULL);
1255         }
1256
1257         /* Restore the screen */
1258         screen_load();
1259
1260         /* Redraw everything */
1261         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
1262
1263         handle_stuff();
1264 }
1265
1266
1267 /*
1268  * Recall the most recent message
1269  */
1270 void do_cmd_message_one(void)
1271 {
1272         /* Recall one message XXX XXX XXX */
1273         prt(format("> %s", message_str(0)), 0, 0);
1274 }
1275
1276
1277 /*
1278  * Show previous messages to the user   -BEN-
1279  *
1280  * The screen format uses line 0 and 23 for headers and prompts,
1281  * skips line 1 and 22, and uses line 2 thru 21 for old messages.
1282  *
1283  * This command shows you which commands you are viewing, and allows
1284  * you to "search" for strings in the recall.
1285  *
1286  * Note that messages may be longer than 80 characters, but they are
1287  * displayed using "infinite" length, with a special sub-command to
1288  * "slide" the virtual display to the left or right.
1289  *
1290  * Attempt to only hilite the matching portions of the string.
1291  */
1292 void do_cmd_messages(int num_now)
1293 {
1294         int i, j, k, n;
1295         uint q;
1296
1297         char shower[80];
1298         char finder[80];
1299         int wid, hgt;
1300
1301
1302         /* Get size */
1303         Term_get_size(&wid, &hgt);
1304
1305         /* Wipe finder */
1306         strcpy(finder, "");
1307
1308         /* Wipe shower */
1309         strcpy(shower, "");
1310
1311
1312         /* Total messages */
1313         n = message_num();
1314
1315         /* Start on first message */
1316         i = 0;
1317
1318         /* Start at leftmost edge */
1319         q = 0;
1320
1321         /* Save the screen */
1322         screen_save();
1323
1324         /* Process requests until done */
1325         while (1)
1326         {
1327                 /* Clear screen */
1328                 Term_clear();
1329
1330                 /* Dump up to 20 lines of messages */
1331                 for (j = 0; (j < hgt - 4) && (i + j < n); j++)
1332                 {
1333                         cptr msg = message_str(i+j);
1334
1335                         /* Apply horizontal scroll */
1336                         msg = (strlen(msg) >= q) ? (msg + q) : "";
1337
1338                         /* Dump the messages, bottom to top */
1339                         Term_putstr(0, hgt-j-3, -1, (bool)(i+j < num_now ? TERM_WHITE : TERM_SLATE), msg);
1340
1341                         /* Hilite "shower" */
1342                         if (shower[0])
1343                         {
1344                                 cptr str = msg;
1345
1346                                 /* Display matches */
1347                                 while ((str = strstr(str, shower)) != NULL)
1348                                 {
1349                                         int len = strlen(shower);
1350
1351                                         /* Display the match */
1352                                         Term_putstr(str-msg, hgt-j-3, len, TERM_YELLOW, shower);
1353
1354                                         /* Advance */
1355                                         str += len;
1356                                 }
1357                         }
1358                 }
1359
1360                 /* Display header XXX XXX XXX */
1361 #ifdef JP
1362                 /* translation */
1363                 prt(format("°ÊÁ°¤Î¥á¥Ã¥»¡¼¥¸ %d-%d Á´Éô¤Ç(%d) ¥ª¥Õ¥»¥Ã¥È(%d)",
1364                            i, i+j-1, n, q), 0, 0);
1365 #else
1366                 prt(format("Message Recall (%d-%d of %d), Offset %d",
1367                     i, i+j-1, n, q), 0, 0);
1368 #endif
1369
1370
1371                 /* Display prompt (not very informative) */
1372 #ifdef JP
1373                 prt("[ 'p' ¤Ç¹¹¤Ë¸Å¤¤¤â¤Î, 'n' ¤Ç¹¹¤Ë¿·¤·¤¤¤â¤Î, '/' ¤Ç¸¡º÷, ESC ¤ÇÃæÃÇ ]", hgt - 1, 0);
1374 #else
1375                 prt("[Press 'p' for older, 'n' for newer, ..., or ESCAPE]", hgt - 1, 0);
1376 #endif
1377
1378
1379                 /* Get a command */
1380                 k = inkey();
1381
1382                 /* Exit on Escape */
1383                 if (k == ESCAPE) break;
1384
1385                 /* Hack -- Save the old index */
1386                 j = i;
1387
1388                 /* Horizontal scroll */
1389                 if (k == '4')
1390                 {
1391                         /* Scroll left */
1392                         q = (q >= 40) ? (q - 40) : 0;
1393
1394                         /* Success */
1395                         continue;
1396                 }
1397
1398                 /* Horizontal scroll */
1399                 if (k == '6')
1400                 {
1401                         /* Scroll right */
1402                         q = q + 40;
1403
1404                         /* Success */
1405                         continue;
1406                 }
1407
1408                 /* Hack -- handle show */
1409                 if (k == '=')
1410                 {
1411                         /* Prompt */
1412 #ifdef JP
1413                         prt("¶¯Ä´: ", hgt - 1, 0);
1414 #else
1415                         prt("Show: ", hgt - 1, 0);
1416 #endif
1417
1418
1419                         /* Get a "shower" string, or continue */
1420                         if (!askfor_aux(shower, 80)) continue;
1421
1422                         /* Okay */
1423                         continue;
1424                 }
1425
1426                 /* Hack -- handle find */
1427                 if (k == '/')
1428                 {
1429                         int z;
1430
1431                         /* Prompt */
1432 #ifdef JP
1433                         prt("¸¡º÷: ", hgt - 1, 0);
1434 #else
1435                         prt("Find: ", hgt - 1, 0);
1436 #endif
1437
1438
1439                         /* Get a "finder" string, or continue */
1440                         if (!askfor_aux(finder, 80)) continue;
1441
1442                         /* Show it */
1443                         strcpy(shower, finder);
1444
1445                         /* Scan messages */
1446                         for (z = i + 1; z < n; z++)
1447                         {
1448                                 cptr msg = message_str(z);
1449
1450                                 /* Search for it */
1451                                 if (strstr(msg, finder))
1452                                 {
1453                                         /* New location */
1454                                         i = z;
1455
1456                                         /* Done */
1457                                         break;
1458                                 }
1459                         }
1460                 }
1461
1462                 /* Recall 1 older message */
1463                 if ((k == '8') || (k == '\n') || (k == '\r'))
1464                 {
1465                         /* Go newer if legal */
1466                         if (i + 1 < n) i += 1;
1467                 }
1468
1469                 /* Recall 10 older messages */
1470                 if (k == '+')
1471                 {
1472                         /* Go older if legal */
1473                         if (i + 10 < n) i += 10;
1474                 }
1475
1476                 /* Recall 20 older messages */
1477                 if ((k == 'p') || (k == KTRL('P')) || (k == ' '))
1478                 {
1479                         /* Go older if legal */
1480                         if (i + 20 < n) i += 20;
1481                 }
1482
1483                 /* Recall 20 newer messages */
1484                 if ((k == 'n') || (k == KTRL('N')))
1485                 {
1486                         /* Go newer (if able) */
1487                         i = (i >= 20) ? (i - 20) : 0;
1488                 }
1489
1490                 /* Recall 10 newer messages */
1491                 if (k == '-')
1492                 {
1493                         /* Go newer (if able) */
1494                         i = (i >= 20) ? (i - 20) : 0;
1495                 }
1496
1497                 /* Recall 1 newer messages */
1498                 if (k == '2')
1499                 {
1500                         /* Go newer (if able) */
1501                         i = (i >= 1) ? (i - 1) : 0;
1502                 }
1503
1504                 /* Hack -- Error of some kind */
1505                 if (i == j) bell();
1506         }
1507
1508         /* Restore the screen */
1509         screen_load();
1510 }
1511
1512
1513
1514 /*
1515  * Number of cheating options
1516  */
1517 #define CHEAT_MAX 7
1518
1519 /*
1520  * Cheating options
1521  */
1522 static option_type cheat_info[CHEAT_MAX] =
1523 {
1524         { &cheat_peek,          FALSE,  255,    0x01, 0x00,
1525 #ifdef JP
1526         "cheat_peek",           "¥¢¥¤¥Æ¥à¤ÎÀ¸À®¤ò¤Î¤¾¤­¸«¤ë"
1527 #else
1528         "cheat_peek",           "Peek into object creation"
1529 #endif
1530         },
1531
1532         { &cheat_hear,          FALSE,  255,    0x02, 0x00,
1533 #ifdef JP
1534         "cheat_hear",           "¥â¥ó¥¹¥¿¡¼¤ÎÀ¸À®¤ò¤Î¤¾¤­¸«¤ë"
1535 #else
1536         "cheat_hear",           "Peek into monster creation"
1537 #endif
1538         },
1539
1540         { &cheat_room,          FALSE,  255,    0x04, 0x00,
1541 #ifdef JP
1542         "cheat_room",           "¥À¥ó¥¸¥ç¥ó¤ÎÀ¸À®¤ò¤Î¤¾¤­¸«¤ë"
1543 #else
1544         "cheat_room",           "Peek into dungeon creation"
1545 #endif
1546         },
1547
1548         { &cheat_xtra,          FALSE,  255,    0x08, 0x00,
1549 #ifdef JP
1550         "cheat_xtra",           "¤½¤Î¾¤Î»ö¤ò¤Î¤¾¤­¸«¤ë"
1551 #else
1552         "cheat_xtra",           "Peek into something else"
1553 #endif
1554         },
1555
1556         { &cheat_know,          FALSE,  255,    0x10, 0x00,
1557 #ifdef JP
1558         "cheat_know",           "´°Á´¤Ê¥â¥ó¥¹¥¿¡¼¤Î»×¤¤½Ð¤òÃΤë"
1559 #else
1560         "cheat_know",           "Know complete monster info"
1561 #endif
1562         },
1563
1564         { &cheat_live,          FALSE,  255,    0x20, 0x00,
1565 #ifdef JP
1566         "cheat_live",           "»à¤ò²óÈò¤¹¤ë¤³¤È¤ò²Äǽ¤Ë¤¹¤ë"
1567 #else
1568         "cheat_live",           "Allow player to avoid death"
1569 #endif
1570         },
1571
1572         { &cheat_save,          FALSE,  255,    0x40, 0x00,
1573 #ifdef JP
1574         "cheat_save",           "»à¤ó¤À»þ¥»¡¼¥Ö¤¹¤ë¤«³Îǧ¤¹¤ë"
1575 #else
1576         "cheat_save",           "Ask for saving death"
1577 #endif
1578         }
1579 };
1580
1581 /*
1582  * Interact with some options for cheating
1583  */
1584 static void do_cmd_options_cheat(cptr info)
1585 {
1586         char    ch;
1587
1588         int             i, k = 0, n = CHEAT_MAX;
1589
1590         char    buf[80];
1591
1592
1593         /* Clear screen */
1594         Term_clear();
1595
1596         /* Interact with the player */
1597         while (TRUE)
1598         {
1599                 int dir;
1600
1601                 /* Prompt XXX XXX XXX */
1602 #ifdef JP
1603                 sprintf(buf, "%s ( ¥ê¥¿¡¼¥ó¤Ç¼¡¤Ø, y/n ¤Ç¥»¥Ã¥È, ESC ¤Ç·èÄê )", info);
1604 #else
1605                 sprintf(buf, "%s (RET to advance, y/n to set, ESC to accept) ", info);
1606 #endif
1607
1608                 prt(buf, 0, 0);
1609
1610 #ifdef JP
1611                 /* º¾µ½¥ª¥×¥·¥ç¥ó¤ò¤¦¤Ã¤«¤ê¤¤¤¸¤Ã¤Æ¤·¤Þ¤¦¿Í¤¬¤¤¤ë¤è¤¦¤Ê¤Î¤ÇÃí°Õ */
1612                 prt("                                 <<  Ãí°Õ  >>", 11, 0);
1613                 prt("      º¾µ½¥ª¥×¥·¥ç¥ó¤ò°ìÅ٤ǤâÀßÄꤹ¤ë¤È¡¢¥¹¥³¥¢µ­Ï¿¤¬»Ä¤é¤Ê¤¯¤Ê¤ê¤Þ¤¹¡ª", 12, 0);
1614                 prt("      ¸å¤Ë²ò½ü¤·¤Æ¤â¥À¥á¤Ç¤¹¤Î¤Ç¡¢¾¡Íø¼Ô¤òÌܻؤ¹Êý¤Ï¤³¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï¤¤", 13, 0);
1615                 prt("      ¤¸¤é¤Ê¤¤¤è¤¦¤Ë¤·¤Æ²¼¤µ¤¤¡£", 14, 0);
1616 #endif
1617                 /* Display the options */
1618                 for (i = 0; i < n; i++)
1619                 {
1620                         byte a = TERM_WHITE;
1621
1622                         /* Color current option */
1623                         if (i == k) a = TERM_L_BLUE;
1624
1625                         /* Display the option text */
1626                         sprintf(buf, "%-48s: %s (%s)",
1627                             cheat_info[i].o_desc,
1628 #ifdef JP
1629                             (*cheat_info[i].o_var ? "¤Ï¤¤  " : "¤¤¤¤¤¨"),
1630 #else
1631                             (*cheat_info[i].o_var ? "yes" : "no "),
1632 #endif
1633
1634                             cheat_info[i].o_text);
1635                         c_prt(a, buf, i + 2, 0);
1636                 }
1637
1638                 /* Hilite current option */
1639                 move_cursor(k + 2, 50);
1640
1641                 /* Get a key */
1642                 ch = inkey();
1643
1644                 /*
1645                  * HACK - Try to translate the key into a direction
1646                  * to allow using the roguelike keys for navigation.
1647                  */
1648                 dir = get_keymap_dir(ch);
1649                 if ((dir == 2) || (dir == 4) || (dir == 6) || (dir == 8))
1650                         ch = I2D(dir);
1651
1652                 /* Analyze */
1653                 switch (ch)
1654                 {
1655                         case ESCAPE:
1656                         {
1657                                 return;
1658                         }
1659
1660                         case '-':
1661                         case '8':
1662                         {
1663                                 k = (n + k - 1) % n;
1664                                 break;
1665                         }
1666
1667                         case ' ':
1668                         case '\n':
1669                         case '\r':
1670                         case '2':
1671                         {
1672                                 k = (k + 1) % n;
1673                                 break;
1674                         }
1675
1676                         case 'y':
1677                         case 'Y':
1678                         case '6':
1679                         {
1680                                 if(!p_ptr->noscore)
1681 #ifdef JP
1682                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "º¾µ½¥ª¥×¥·¥ç¥ó¤òON¤Ë¤·¤Æ¡¢¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
1683 #else
1684                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up sending score to use cheating options.");
1685 #endif
1686                                 p_ptr->noscore |= (cheat_info[k].o_set * 256 + cheat_info[k].o_bit);
1687                                 (*cheat_info[k].o_var) = TRUE;
1688                                 k = (k + 1) % n;
1689                                 break;
1690                         }
1691
1692                         case 'n':
1693                         case 'N':
1694                         case '4':
1695                         {
1696                                 (*cheat_info[k].o_var) = FALSE;
1697                                 k = (k + 1) % n;
1698                                 break;
1699                         }
1700
1701                         case '?':
1702                         {
1703 #ifdef JP
1704                                 strnfmt(buf, sizeof(buf), "joption.txt#%s", cheat_info[k].o_text);
1705 #else
1706                                 strnfmt(buf, sizeof(buf), "option.txt#%s", cheat_info[k].o_text);
1707 #endif
1708                                 /* Peruse the help file */
1709                                 (void)show_file(TRUE, buf, NULL, 0, 0);
1710
1711                                 Term_clear(); 
1712                                 break;
1713                         }
1714
1715                         default:
1716                         {
1717                                 bell();
1718                                 break;
1719                         }
1720                 }
1721         }
1722 }
1723
1724
1725 static option_type autosave_info[2] =
1726 {
1727         { &autosave_l,      FALSE, 255, 0x01, 0x00,
1728 #ifdef JP
1729             "autosave_l",    "¿·¤·¤¤³¬¤ËÆþ¤ëÅ٤˼«Æ°¥»¡¼¥Ö¤¹¤ë" },
1730 #else
1731             "autosave_l",    "Autosave when entering new levels" },
1732 #endif
1733
1734
1735         { &autosave_t,      FALSE, 255, 0x02, 0x00,
1736 #ifdef JP
1737             "autosave_t",   "°ìÄ꥿¡¼¥óËè¤Ë¼«Æ°¥»¡¼¥Ö¤¹¤ë" },
1738 #else
1739             "autosave_t",   "Timed autosave" },
1740 #endif
1741
1742 };
1743
1744
1745 static s16b toggle_frequency(s16b current)
1746 {
1747         switch (current)
1748         {
1749         case 0: return 50;
1750         case 50: return 100;
1751         case 100: return 250;
1752         case 250: return 500;
1753         case 500: return 1000;
1754         case 1000: return 2500;
1755         case 2500: return 5000;
1756         case 5000: return 10000;
1757         case 10000: return 25000;
1758         default: return 0;
1759         }
1760 }
1761
1762
1763 /*
1764  * Interact with some options for cheating
1765  */
1766 static void do_cmd_options_autosave(cptr info)
1767 {
1768         char    ch;
1769
1770         int     i, k = 0, n = 2;
1771
1772         char    buf[80];
1773
1774
1775         /* Clear screen */
1776         Term_clear();
1777
1778         /* Interact with the player */
1779         while (TRUE)
1780         {
1781                 /* Prompt XXX XXX XXX */
1782 #ifdef JP
1783                 sprintf(buf, "%s ( ¥ê¥¿¡¼¥ó¤Ç¼¡¤Ø, y/n ¤Ç¥»¥Ã¥È, F ¤ÇÉÑÅÙ¤òÆþÎÏ, ESC ¤Ç·èÄê ) ", info);
1784 #else
1785                 sprintf(buf, "%s (RET to advance, y/n to set, 'F' for frequency, ESC to accept) ", info);
1786 #endif
1787
1788                 prt(buf, 0, 0);
1789
1790                 /* Display the options */
1791                 for (i = 0; i < n; i++)
1792                 {
1793                         byte a = TERM_WHITE;
1794
1795                         /* Color current option */
1796                         if (i == k) a = TERM_L_BLUE;
1797
1798                         /* Display the option text */
1799                         sprintf(buf, "%-48s: %s (%s)",
1800                             autosave_info[i].o_desc,
1801 #ifdef JP
1802                             (*autosave_info[i].o_var ? "¤Ï¤¤  " : "¤¤¤¤¤¨"),
1803 #else
1804                             (*autosave_info[i].o_var ? "yes" : "no "),
1805 #endif
1806
1807                             autosave_info[i].o_text);
1808                         c_prt(a, buf, i + 2, 0);
1809                 }
1810
1811 #ifdef JP
1812                 prt(format("¼«Æ°¥»¡¼¥Ö¤ÎÉÑÅÙ¡§ %d ¥¿¡¼¥óËè",  autosave_freq), 5, 0);
1813 #else
1814                 prt(format("Timed autosave frequency: every %d turns",  autosave_freq), 5, 0);
1815 #endif
1816
1817
1818
1819                 /* Hilite current option */
1820                 move_cursor(k + 2, 50);
1821
1822                 /* Get a key */
1823                 ch = inkey();
1824
1825                 /* Analyze */
1826                 switch (ch)
1827                 {
1828                         case ESCAPE:
1829                         {
1830                                 return;
1831                         }
1832
1833                         case '-':
1834                         case '8':
1835                         {
1836                                 k = (n + k - 1) % n;
1837                                 break;
1838                         }
1839
1840                         case ' ':
1841                         case '\n':
1842                         case '\r':
1843                         case '2':
1844                         {
1845                                 k = (k + 1) % n;
1846                                 break;
1847                         }
1848
1849                         case 'y':
1850                         case 'Y':
1851                         case '6':
1852                         {
1853
1854                                 (*autosave_info[k].o_var) = TRUE;
1855                                 k = (k + 1) % n;
1856                                 break;
1857                         }
1858
1859                         case 'n':
1860                         case 'N':
1861                         case '4':
1862                         {
1863                                 (*autosave_info[k].o_var) = FALSE;
1864                                 k = (k + 1) % n;
1865                                 break;
1866                         }
1867
1868                         case 'f':
1869                         case 'F':
1870                         {
1871                                 autosave_freq = toggle_frequency(autosave_freq);
1872 #ifdef JP
1873                                 prt(format("¼«Æ°¥»¡¼¥Ö¤ÎÉÑÅÙ¡§ %d ¥¿¡¼¥óËè", 
1874                                            autosave_freq), 5, 0);
1875 #else
1876                                 prt(format("Timed autosave frequency: every %d turns",
1877                                            autosave_freq), 5, 0);
1878 #endif
1879                                 break;
1880                         }
1881
1882                         case '?':
1883                         {
1884 #ifdef JP
1885                                 (void)show_file(TRUE, "joption.txt#Autosave", NULL, 0, 0);
1886 #else
1887                                 (void)show_file(TRUE, "option.txt#Autosave", NULL, 0, 0);
1888 #endif
1889
1890
1891                                 Term_clear(); 
1892                                 break;
1893                         }
1894
1895                         default:
1896                         {
1897                                 bell();
1898                                 break;
1899                         }
1900                 }
1901         }
1902 }
1903
1904
1905 #define PAGE_BIRTH       6
1906 #define PAGE_AUTODESTROY 7
1907
1908 /*
1909  * Interact with some options
1910  */
1911 void do_cmd_options_aux(int page, cptr info)
1912 {
1913         char    ch;
1914         int     i, k = 0, n = 0, l;
1915         int     opt[24];
1916         char    buf[80];
1917         bool    browse_only = (page == PAGE_BIRTH) && character_generated &&
1918                               (!p_ptr->wizard || !allow_debug_opts);
1919
1920
1921         /* Lookup the options */
1922         for (i = 0; i < 24; i++) opt[i] = 0;
1923
1924         /* Scan the options */
1925         for (i = 0; option_info[i].o_desc; i++)
1926         {
1927                 /* Notice options on this "page" */
1928                 if (option_info[i].o_page == page) opt[n++] = i;
1929         }
1930
1931
1932         /* Clear screen */
1933         Term_clear();
1934
1935         /* Interact with the player */
1936         while (TRUE)
1937         {
1938                 int dir;
1939
1940                 /* Prompt XXX XXX XXX */
1941 #ifdef JP
1942                 sprintf(buf, "%s (¥ê¥¿¡¼¥ó:¼¡, %sESC:½ªÎ», ?:¥Ø¥ë¥×) ", info, browse_only ? "" : "y/n:Êѹ¹, ");
1943 #else
1944                 sprintf(buf, "%s (RET:next, %s, ?:help) ", info, browse_only ? "ESC:exit" : "y/n:change, ESC:accept");
1945 #endif
1946
1947                 prt(buf, 0, 0);
1948
1949
1950                 /* HACK -- description for easy-auto-destroy options */
1951 #ifdef JP
1952                 if (page == PAGE_AUTODESTROY) c_prt(TERM_YELLOW, "°Ê²¼¤Î¥ª¥×¥·¥ç¥ó¤Ï¡¢´Ê°×¼«Æ°Ç˲õ¤ò»ÈÍѤ¹¤ë¤È¤­¤Î¤ßÍ­¸ú", 6, 6);
1953 #else
1954                 if (page == PAGE_AUTODESTROY) c_prt(TERM_YELLOW, "Following options will protect items from easy auto-destroyer.", 6, 3);
1955 #endif
1956
1957                 /* Display the options */
1958                 for (i = 0; i < n; i++)
1959                 {
1960                         byte a = TERM_WHITE;
1961
1962                         /* Color current option */
1963                         if (i == k) a = TERM_L_BLUE;
1964
1965                         /* Display the option text */
1966                         sprintf(buf, "%-48s: %s (%.19s)",
1967                                 option_info[opt[i]].o_desc,
1968 #ifdef JP
1969                                 (*option_info[opt[i]].o_var ? "¤Ï¤¤  " : "¤¤¤¤¤¨"),
1970 #else
1971                                 (*option_info[opt[i]].o_var ? "yes" : "no "),
1972 #endif
1973
1974                                 option_info[opt[i]].o_text);
1975                         if ((page == PAGE_AUTODESTROY) && i > 2) c_prt(a, buf, i + 5, 0);
1976                         else c_prt(a, buf, i + 2, 0);
1977                 }
1978
1979                 if ((page == PAGE_AUTODESTROY) && (k > 2)) l = 3;
1980                 else l = 0;
1981
1982                 /* Hilite current option */
1983                 move_cursor(k + 2 + l, 50);
1984
1985                 /* Get a key */
1986                 ch = inkey();
1987
1988                 /*
1989                  * HACK - Try to translate the key into a direction
1990                  * to allow using the roguelike keys for navigation.
1991                  */
1992                 dir = get_keymap_dir(ch);
1993                 if ((dir == 2) || (dir == 4) || (dir == 6) || (dir == 8))
1994                         ch = I2D(dir);
1995
1996                 /* Analyze */
1997                 switch (ch)
1998                 {
1999                         case ESCAPE:
2000                         {
2001                                 return;
2002                         }
2003
2004                         case '-':
2005                         case '8':
2006                         {
2007                                 k = (n + k - 1) % n;
2008                                 break;
2009                         }
2010
2011                         case ' ':
2012                         case '\n':
2013                         case '\r':
2014                         case '2':
2015                         {
2016                                 k = (k + 1) % n;
2017                                 break;
2018                         }
2019
2020                         case 'y':
2021                         case 'Y':
2022                         case '6':
2023                         {
2024                                 if (browse_only) break;
2025                                 (*option_info[opt[k]].o_var) = TRUE;
2026                                 k = (k + 1) % n;
2027                                 break;
2028                         }
2029
2030                         case 'n':
2031                         case 'N':
2032                         case '4':
2033                         {
2034                                 if (browse_only) break;
2035                                 (*option_info[opt[k]].o_var) = FALSE;
2036                                 k = (k + 1) % n;
2037                                 break;
2038                         }
2039
2040                         case 't':
2041                         case 'T':
2042                         {
2043                                 if (!browse_only) (*option_info[opt[k]].o_var) = !(*option_info[opt[k]].o_var);
2044                                 break;
2045                         }
2046
2047                         case '?':
2048                         {
2049 #ifdef JP
2050                                 strnfmt(buf, sizeof(buf), "joption.txt#%s", option_info[opt[k]].o_text);
2051 #else
2052                                 strnfmt(buf, sizeof(buf), "option.txt#%s", option_info[opt[k]].o_text);
2053 #endif
2054                                 /* Peruse the help file */
2055                                 (void)show_file(TRUE, buf, NULL, 0, 0);
2056
2057                                 Term_clear();
2058                                 break;
2059                         }
2060
2061                         default:
2062                         {
2063                                 bell();
2064                                 break;
2065                         }
2066                 }
2067         }
2068 }
2069
2070
2071 /*
2072  * Modify the "window" options
2073  */
2074 static void do_cmd_options_win(void)
2075 {
2076         int i, j, d;
2077
2078         int y = 0;
2079         int x = 0;
2080
2081         char ch;
2082
2083         bool go = TRUE;
2084
2085         u32b old_flag[8];
2086
2087
2088         /* Memorize old flags */
2089         for (j = 0; j < 8; j++)
2090         {
2091                 /* Acquire current flags */
2092                 old_flag[j] = window_flag[j];
2093         }
2094
2095
2096         /* Clear screen */
2097         Term_clear();
2098
2099         /* Interact */
2100         while (go)
2101         {
2102                 /* Prompt XXX XXX XXX */
2103 #ifdef JP
2104                 prt("¥¦¥£¥ó¥É¥¦¡¦¥Õ¥é¥° (<Êý¸þ>¤Ç°ÜÆ°, t¤Ç¥Á¥§¥ó¥¸, y/n ¤Ç¥»¥Ã¥È, ESC)", 0, 0);
2105 #else
2106                 prt("Window Flags (<dir>, t, y, n, ESC) ", 0, 0);
2107 #endif
2108
2109
2110                 /* Display the windows */
2111                 for (j = 0; j < 8; j++)
2112                 {
2113                         byte a = TERM_WHITE;
2114
2115                         cptr s = angband_term_name[j];
2116
2117                         /* Use color */
2118                         if (j == x) a = TERM_L_BLUE;
2119
2120                         /* Window name, staggered, centered */
2121                         Term_putstr(35 + j * 5 - strlen(s) / 2, 2 + j % 2, -1, a, s);
2122                 }
2123
2124                 /* Display the options */
2125                 for (i = 0; i < 16; i++)
2126                 {
2127                         byte a = TERM_WHITE;
2128
2129                         cptr str = window_flag_desc[i];
2130
2131                         /* Use color */
2132                         if (i == y) a = TERM_L_BLUE;
2133
2134                         /* Unused option */
2135 #ifdef JP
2136                         if (!str) str = "(̤»ÈÍÑ)";
2137 #else
2138                         if (!str) str = "(Unused option)";
2139 #endif
2140
2141
2142                         /* Flag name */
2143                         Term_putstr(0, i + 5, -1, a, str);
2144
2145                         /* Display the windows */
2146                         for (j = 0; j < 8; j++)
2147                         {
2148                                 byte a = TERM_WHITE;
2149
2150                                 char c = '.';
2151
2152                                 /* Use color */
2153                                 if ((i == y) && (j == x)) a = TERM_L_BLUE;
2154
2155                                 /* Active flag */
2156                                 if (window_flag[j] & (1L << i)) c = 'X';
2157
2158                                 /* Flag value */
2159                                 Term_putch(35 + j * 5, i + 5, a, c);
2160                         }
2161                 }
2162
2163                 /* Place Cursor */
2164                 Term_gotoxy(35 + x * 5, y + 5);
2165
2166                 /* Get key */
2167                 ch = inkey();
2168
2169                 /* Analyze */
2170                 switch (ch)
2171                 {
2172                         case ESCAPE:
2173                         {
2174                                 go = FALSE;
2175                                 break;
2176                         }
2177
2178                         case 'T':
2179                         case 't':
2180                         {
2181                                 /* Clear windows */
2182                                 for (j = 0; j < 8; j++)
2183                                 {
2184                                         window_flag[j] &= ~(1L << y);
2185                                 }
2186
2187                                 /* Clear flags */
2188                                 for (i = 0; i < 16; i++)
2189                                 {
2190                                         window_flag[x] &= ~(1L << i);
2191                                 }
2192
2193                                 /* Fall through */
2194                         }
2195
2196                         case 'y':
2197                         case 'Y':
2198                         {
2199                                 /* Ignore screen */
2200                                 if (x == 0) break;
2201
2202                                 /* Set flag */
2203                                 window_flag[x] |= (1L << y);
2204                                 break;
2205                         }
2206
2207                         case 'n':
2208                         case 'N':
2209                         {
2210                                 /* Clear flag */
2211                                 window_flag[x] &= ~(1L << y);
2212                                 break;
2213                         }
2214
2215                         case '?':
2216                         {
2217 #ifdef JP
2218                                 (void)show_file(TRUE, "joption.txt#Window", NULL, 0, 0);
2219 #else
2220                                 (void)show_file(TRUE, "option.txt#Window", NULL, 0, 0);
2221 #endif
2222
2223
2224                                 Term_clear(); 
2225                                 break;
2226                         }
2227
2228                         default:
2229                         {
2230                                 d = get_keymap_dir(ch);
2231
2232                                 x = (x + ddx[d] + 8) % 8;
2233                                 y = (y + ddy[d] + 16) % 16;
2234
2235                                 if (!d) bell();
2236                         }
2237                 }
2238         }
2239
2240         /* Notice changes */
2241         for (j = 0; j < 8; j++)
2242         {
2243                 term *old = Term;
2244
2245                 /* Dead window */
2246                 if (!angband_term[j]) continue;
2247
2248                 /* Ignore non-changes */
2249                 if (window_flag[j] == old_flag[j]) continue;
2250
2251                 /* Activate */
2252                 Term_activate(angband_term[j]);
2253
2254                 /* Erase */
2255                 Term_clear();
2256
2257                 /* Refresh */
2258                 Term_fresh();
2259
2260                 /* Restore */
2261                 Term_activate(old);
2262         }
2263 }
2264
2265
2266
2267
2268 /*
2269  * Set or unset various options.
2270  *
2271  * The user must use the "Ctrl-R" command to "adapt" to changes
2272  * in any options which control "visual" aspects of the game.
2273  */
2274 void do_cmd_options(void)
2275 {
2276         int k;
2277
2278
2279         /* Save the screen */
2280         screen_save();
2281
2282         /* Interact */
2283         while (1)
2284         {
2285                 /* Clear screen */
2286                 Term_clear();
2287
2288                 /* Why are we here */
2289 #ifdef JP
2290                 prt("[ ¥ª¥×¥·¥ç¥ó¤ÎÀßÄê ]", 2, 0);
2291 #else
2292                 prt("Options", 2, 0);
2293 #endif
2294
2295
2296                 /* Give some choices */
2297 #ifdef JP
2298                 prt("(1)     ¥­¡¼ÆþÎÏ          ¥ª¥×¥·¥ç¥ó", 3, 5);
2299                 prt("(2)     ²èÌ̽ÐÎÏ          ¥ª¥×¥·¥ç¥ó", 4, 5);
2300                 prt("(3)   ¥²¡¼¥à¥×¥ì¥¤        ¥ª¥×¥·¥ç¥ó", 5, 5);
2301                 prt("(4)   ¹ÔÆ°Ãæ»ß´Ø·¸        ¥ª¥×¥·¥ç¥ó", 6, 5);
2302                 prt("(5)      ¸úΨ²½           ¥ª¥×¥·¥ç¥ó", 7, 5);
2303                 prt("(6) ´Ê°×¥¢¥¤¥Æ¥à¼«Æ°Ç˲õ  ¥ª¥×¥·¥ç¥ó", 8, 5);
2304                 prt("(R)    ¥×¥ì¥¤µ­Ï¿         ¥ª¥×¥·¥ç¥ó", 9, 5);
2305                 /* Special choices */
2306                 prt("(D)  ´ðËÜ¥¦¥§¥¤¥ÈÎÌ", 11, 5);
2307                 prt("(H) Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð", 12, 5);
2308                 prt("(M)   ÄãËâÎÏ¿§ïçÃÍ", 13, 5);
2309                 prt("(A)    ¼«Æ°¥»¡¼¥Ö         ¥ª¥×¥·¥ç¥ó", 14, 5);
2310                 /* Window flags */
2311                 prt("(W) ¥¦¥¤¥ó¥É¥¦¥Õ¥é¥°", 15, 5);
2312 #else
2313                 prt("(1) Input Options", 3, 5);
2314                 prt("(2) Output Options", 4, 5);
2315                 prt("(3) Game-Play Options", 5, 5);
2316                 prt("(4) Disturbance Options", 6, 5);
2317                 prt("(5) Efficiency Options", 7, 5);
2318                 prt("(6) Easy Auto-Destroyer Options", 8, 5);
2319                 prt("(R) Play-record Options", 9, 5);
2320                 /* Special choices */
2321                 prt("(D) Base Delay Factor", 11, 5);
2322                 prt("(H) Hitpoint Warning", 12, 5);
2323                 prt("(M) Mana Color Threshold", 13, 5);
2324                 prt("(A) Autosave Options", 14, 5);
2325                 /* Window flags */
2326                 prt("(W) Window Flags", 15, 5);
2327 #endif
2328
2329                 if (!p_ptr->wizard || !allow_debug_opts)
2330                 {
2331                         /* Birth */
2332 #ifdef JP
2333                         prt("(B)       ½é´ü            ¥ª¥×¥·¥ç¥ó (»²¾È¤Î¤ß)", 16, 5);
2334 #else
2335                         prt("(B) Birth Options (Browse Only)", 16, 5);
2336 #endif
2337                 }
2338                 else
2339                 {
2340                         /* Birth */
2341 #ifdef JP
2342                         prt("(B)       ½é´ü            ¥ª¥×¥·¥ç¥ó", 16, 5);
2343 #else
2344                         prt("(B) Birth Options", 16, 5);
2345 #endif
2346                 }
2347
2348
2349                 if (p_ptr->noscore || allow_debug_opts)
2350                 {
2351                         /* Cheating */
2352 #ifdef JP
2353                         prt("(C)       º¾µ½            ¥ª¥×¥·¥ç¥ó", 17, 5);
2354 #else
2355                         prt("(C) Cheating Options", 17, 5);
2356 #endif
2357                 }
2358
2359
2360                 /* Prompt */
2361 #ifdef JP
2362                 prt("¥³¥Þ¥ó¥É:", 19, 0);
2363 #else
2364                 prt("Command: ", 19, 0);
2365 #endif
2366
2367
2368                 /* Get command */
2369                 k = inkey();
2370
2371                 /* Exit */
2372                 if (k == ESCAPE) break;
2373
2374                 /* Analyze */
2375                 switch (k)
2376                 {
2377                         /* General Options */
2378                         case '1':
2379                         {
2380                                 /* Process the general options */
2381 #ifdef JP
2382                                 do_cmd_options_aux(1, "¥­¡¼ÆþÎÏ¥ª¥×¥·¥ç¥ó");
2383 #else
2384                                 do_cmd_options_aux(1, "Input Options");
2385 #endif
2386
2387                                 break;
2388                         }
2389
2390                         /* General Options */
2391                         case '2':
2392                         {
2393                                 /* Process the general options */
2394 #ifdef JP
2395                                 do_cmd_options_aux(2, "²èÌ̽ÐÎÏ¥ª¥×¥·¥ç¥ó");
2396 #else
2397                                 do_cmd_options_aux(2, "Output Options");
2398 #endif
2399
2400                                 break;
2401                         }
2402
2403                         /* Inventory Options */
2404                         case '3':
2405                         {
2406                                 /* Spawn */
2407 #ifdef JP
2408                                 do_cmd_options_aux(3, "¥²¡¼¥à¥×¥ì¥¤¡¦¥ª¥×¥·¥ç¥ó");
2409 #else
2410                                 do_cmd_options_aux(3, "Game-Play Options");
2411 #endif
2412
2413                                 break;
2414                         }
2415
2416                         /* Disturbance Options */
2417                         case '4':
2418                         {
2419                                 /* Spawn */
2420 #ifdef JP
2421                                 do_cmd_options_aux(4, "¹ÔÆ°Ãæ»ß´Ø·¸¤Î¥ª¥×¥·¥ç¥ó");
2422 #else
2423                                 do_cmd_options_aux(4, "Disturbance Options");
2424 #endif
2425
2426                                 break;
2427                         }
2428
2429                         /* Efficiency Options */
2430                         case '5':
2431                         {
2432                                 /* Spawn */
2433 #ifdef JP
2434                                 do_cmd_options_aux(5, "¸úΨ²½¥ª¥×¥·¥ç¥ó");
2435 #else
2436                                 do_cmd_options_aux(5, "Efficiency Options");
2437 #endif
2438
2439                                 break;
2440                         }
2441
2442                         /* Object auto-destruction Options */
2443                         case '6':
2444                         {
2445                                 /* Spawn */
2446 #ifdef JP
2447                                 do_cmd_options_aux(7, "´Ê°×¥¢¥¤¥Æ¥à¼«Æ°Ç˲õ¥ª¥×¥·¥ç¥ó");
2448 #else
2449                                 do_cmd_options_aux(7, "Easy Auto-Destroyer Options");
2450 #endif
2451                                 break;
2452                         }
2453
2454                         /* Play-record Options */
2455                         case 'R':
2456                         case 'r':
2457                         {
2458                                 /* Spawn */
2459 #ifdef JP
2460                                 do_cmd_options_aux(10, "¥×¥ì¥¤µ­Ï¿¥ª¥×¥·¥ç¥ó");
2461 #else
2462                                 do_cmd_options_aux(10, "Play-record Options");
2463 #endif
2464                                 break;
2465                         }
2466
2467                         /* Birth Options */
2468                         case 'B':
2469                         case 'b':
2470                         {
2471                                 /* Spawn */
2472 #ifdef JP
2473                                 do_cmd_options_aux(6, (!p_ptr->wizard || !allow_debug_opts) ? "½é´ü¥ª¥×¥·¥ç¥ó(»²¾È¤Î¤ß)" : "½é´ü¥ª¥×¥·¥ç¥ó((*)¤Ï¥¹¥³¥¢¤Ë±Æ¶Á)");
2474 #else
2475                                 do_cmd_options_aux(6, (!p_ptr->wizard || !allow_debug_opts) ? "Birth Options(browse only)" : "Birth Options((*)s effect score)");
2476 #endif
2477
2478                                 break;
2479                         }
2480
2481                         /* Cheating Options */
2482                         case 'C':
2483                         {
2484                                 if (!p_ptr->noscore && !allow_debug_opts)
2485                                 {
2486                                         /* Cheat options are not permitted */
2487                                         bell();
2488                                         break;
2489                                 }
2490
2491                                 /* Spawn */
2492 #ifdef JP
2493                                 do_cmd_options_cheat("º¾µ½»Õ¤Ï·è¤·¤Æ¾¡Íø¤Ç¤­¤Ê¤¤¡ª");
2494 #else
2495                                 do_cmd_options_cheat("Cheaters never win");
2496 #endif
2497
2498                                 break;
2499                         }
2500
2501                         case 'a':
2502                         case 'A':
2503                         {
2504 #ifdef JP
2505                                 do_cmd_options_autosave("¼«Æ°¥»¡¼¥Ö");
2506 #else
2507                                 do_cmd_options_autosave("Autosave");
2508 #endif
2509
2510                                 break;
2511                         }
2512
2513                         /* Window flags */
2514                         case 'W':
2515                         case 'w':
2516                         {
2517                                 /* Spawn */
2518                                 do_cmd_options_win();
2519                                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL |
2520                                                   PW_PLAYER | PW_MESSAGE | PW_OVERHEAD |
2521                                                   PW_MONSTER | PW_OBJECT | PW_SNAPSHOT |
2522                                                   PW_BORG_1 | PW_BORG_2 | PW_DUNGEON);
2523                                 break;
2524                         }
2525
2526                         /* Hack -- Delay Speed */
2527                         case 'D':
2528                         case 'd':
2529                         {
2530                                 /* Prompt */
2531 #ifdef JP
2532                                 prt("¥³¥Þ¥ó¥É: ´ðËÜ¥¦¥§¥¤¥ÈÎÌ", 19, 0);
2533 #else
2534                                 prt("Command: Base Delay Factor", 19, 0);
2535 #endif
2536
2537
2538                                 /* Get a new value */
2539                                 while (1)
2540                                 {
2541                                         int msec = delay_factor * delay_factor * delay_factor;
2542 #ifdef JP
2543                                         prt(format("¸½ºß¤Î¥¦¥§¥¤¥È: %d (%d¥ß¥êÉÃ)",
2544                                                    delay_factor, msec), 22, 0);
2545 #else
2546                                         prt(format("Current base delay factor: %d (%d msec)",
2547                                                    delay_factor, msec), 22, 0);
2548 #endif
2549
2550 #ifdef JP
2551                                         prt("¥¦¥§¥¤¥È (0-9) ESC¤Ç·èÄê: ", 20, 0);
2552 #else
2553                                         prt("Delay Factor (0-9 or ESC to accept): ", 20, 0);
2554 #endif
2555
2556                                         k = inkey();
2557                                         if (k == ESCAPE) break;
2558                                         else if (k == '?')
2559                                         {
2560 #ifdef JP
2561                                                 (void)show_file(TRUE, "joption.txt#BaseDelay", NULL, 0, 0);
2562 #else
2563                                                 (void)show_file(TRUE, "option.txt#BaseDelay", NULL, 0, 0);
2564 #endif
2565                                                 Term_clear(); 
2566                                         }
2567                                         else if (isdigit(k)) delay_factor = D2I(k);
2568                                         else bell();
2569                                 }
2570
2571                                 break;
2572                         }
2573
2574                         /* Hack -- hitpoint warning factor */
2575                         case 'H':
2576                         case 'h':
2577                         {
2578                                 /* Prompt */
2579 #ifdef JP
2580                                 prt("¥³¥Þ¥ó¥É: Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð", 19, 0);
2581 #else
2582                                 prt("Command: Hitpoint Warning", 19, 0);
2583 #endif
2584
2585
2586                                 /* Get a new value */
2587                                 while (1)
2588                                 {
2589 #ifdef JP
2590                                         prt(format("¸½ºß¤ÎÄã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð: %d0%%",
2591                                                    hitpoint_warn), 22, 0);
2592 #else
2593                                         prt(format("Current hitpoint warning: %d0%%",
2594                                                    hitpoint_warn), 22, 0);
2595 #endif
2596
2597 #ifdef JP
2598                                         prt("Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð (0-9) ESC¤Ç·èÄê: ", 20, 0);
2599 #else
2600                                         prt("Hitpoint Warning (0-9 or ESC to accept): ", 20, 0);
2601 #endif
2602
2603                                         k = inkey();
2604                                         if (k == ESCAPE) break;
2605                                         else if (k == '?')
2606                                         {
2607 #ifdef JP
2608                                                 (void)show_file(TRUE, "joption.txt#Hitpoint", NULL, 0, 0);
2609 #else
2610                                                 (void)show_file(TRUE, "option.txt#Hitpoint", NULL, 0, 0);
2611 #endif
2612                                                 Term_clear(); 
2613                                         }
2614                                         else if (isdigit(k)) hitpoint_warn = D2I(k);
2615                                         else bell();
2616                                 }
2617
2618                                 break;
2619                         }
2620
2621                         /* Hack -- mana color factor */
2622                         case 'M':
2623                         case 'm':
2624                         {
2625                                 /* Prompt */
2626 #ifdef JP
2627                                 prt("¥³¥Þ¥ó¥É: ÄãËâÎÏ¿§ïçÃÍ", 19, 0);
2628 #else
2629                                 prt("Command: Mana Color Threshold", 19, 0);
2630 #endif
2631
2632
2633                                 /* Get a new value */
2634                                 while (1)
2635                                 {
2636 #ifdef JP
2637                                         prt(format("¸½ºß¤ÎÄãËâÎÏ¿§ïçÃÍ: %d0%%",
2638                                                    mana_warn), 22, 0);
2639 #else
2640                                         prt(format("Current mana color threshold: %d0%%",
2641                                                    mana_warn), 22, 0);
2642 #endif
2643
2644 #ifdef JP
2645                                         prt("ÄãËâÎÏïçÃÍ (0-9) ESC¤Ç·èÄê: ", 20, 0);
2646 #else
2647                                         prt("Mana color Threshold (0-9 or ESC to accept): ", 20, 0);
2648 #endif
2649
2650                                         k = inkey();
2651                                         if (k == ESCAPE) break;
2652                                         else if (k == '?')
2653                                         {
2654 #ifdef JP
2655                                                 (void)show_file(TRUE, "joption.txt#Manapoint", NULL, 0, 0);
2656 #else
2657                                                 (void)show_file(TRUE, "option.txt#Manapoint", NULL, 0, 0);
2658 #endif
2659                                                 Term_clear(); 
2660                                         }
2661                                         else if (isdigit(k)) mana_warn = D2I(k);
2662                                         else bell();
2663                                 }
2664
2665                                 break;
2666                         }
2667
2668                         case '?':
2669 #ifdef JP
2670                                 (void)show_file(TRUE, "joption.txt", NULL, 0, 0);
2671 #else
2672                                 (void)show_file(TRUE, "option.txt", NULL, 0, 0);
2673 #endif
2674                                 Term_clear(); 
2675                                 break;
2676
2677                         /* Unknown option */
2678                         default:
2679                         {
2680                                 /* Oops */
2681                                 bell();
2682                                 break;
2683                         }
2684                 }
2685
2686                 /* Flush messages */
2687                 msg_print(NULL);
2688         }
2689
2690
2691         /* Restore the screen */
2692         screen_load();
2693
2694         /* Hack - Redraw equippy chars */
2695         p_ptr->redraw |= (PR_EQUIPPY);
2696 }
2697
2698
2699
2700 /*
2701  * Ask for a "user pref line" and process it
2702  *
2703  * XXX XXX XXX Allow absolute file names?
2704  */
2705 void do_cmd_pref(void)
2706 {
2707         char buf[80];
2708
2709         /* Default */
2710         strcpy(buf, "");
2711
2712         /* Ask for a "user pref command" */
2713 #ifdef JP
2714         if (!get_string("ÀßÄêÊѹ¹¥³¥Þ¥ó¥É: ", buf, 80)) return;
2715 #else
2716         if (!get_string("Pref: ", buf, 80)) return;
2717 #endif
2718
2719
2720         /* Process that pref command */
2721         (void)process_pref_file_command(buf);
2722 }
2723
2724 void do_cmd_pickpref(void)
2725 {
2726         char buf[80];
2727         errr err;
2728
2729 #ifdef JP
2730         if(!get_check("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤·¤Þ¤¹¤«? ")) return;
2731 #else
2732         if(!get_check("Reload auto-pick preference file? ")) return;
2733 #endif
2734
2735         /* Free old entries */
2736         init_autopicker();
2737
2738         /* ¥­¥ã¥éËè¤ÎÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß */
2739 #ifdef JP
2740         sprintf(buf, "picktype-%s.prf", player_name);
2741 #else
2742         sprintf(buf, "pickpref-%s.prf", player_name);
2743 #endif
2744         err = process_pickpref_file(buf);
2745
2746         if(err == 0)
2747         {
2748 #ifdef JP
2749                 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
2750 #else
2751                 msg_format("loaded '%s'.", buf);
2752 #endif
2753         }
2754
2755         /* ¶¦Ä̤ÎÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß */
2756
2757         /* Process 'pick????.prf' if 'pick????-<name>.prf' doesn't exist */
2758         if (0 > err)
2759         {
2760 #ifdef JP
2761                 err = process_pickpref_file("picktype.prf");
2762 #else
2763                 err = process_pickpref_file("pickpref.prf");
2764 #endif
2765
2766                 if(err == 0)
2767                 {
2768 #ifdef JP
2769                         msg_print("picktype.prf¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£");
2770 #else
2771                         msg_print("loaded 'pickpref.prf'.");
2772 #endif
2773                 }
2774         }
2775
2776
2777 #ifdef JP
2778         if(err) msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
2779 #else
2780         if(err) msg_print("Failed to reload autopick preference.");
2781 #endif
2782 }
2783
2784 #ifdef ALLOW_MACROS
2785
2786 /*
2787  * Hack -- append all current macros to the given file
2788  */
2789 static errr macro_dump(cptr fname)
2790 {
2791         static cptr mark = "Macro Dump";
2792
2793         int i;
2794
2795         char buf[1024];
2796
2797         /* Build the filename */
2798         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2799
2800         /* File type is "TEXT" */
2801         FILE_TYPE(FILE_TYPE_TEXT);
2802
2803         /* Append to the file */
2804         if (!open_auto_dump(buf, mark)) return (-1);
2805
2806         /* Start dumping */
2807 #ifdef JP
2808         auto_dump_printf("\n# ¼«Æ°¥Þ¥¯¥í¥»¡¼¥Ö\n\n");
2809 #else
2810         auto_dump_printf("\n# Automatic macro dump\n\n");
2811 #endif
2812
2813         /* Dump them */
2814         for (i = 0; i < macro__num; i++)
2815         {
2816                 /* Extract the action */
2817                 ascii_to_text(buf, macro__act[i]);
2818
2819                 /* Dump the macro */
2820                 auto_dump_printf("A:%s\n", buf);
2821
2822                 /* Extract the action */
2823                 ascii_to_text(buf, macro__pat[i]);
2824
2825                 /* Dump normal macros */
2826                 auto_dump_printf("P:%s\n", buf);
2827
2828                 /* End the macro */
2829                 auto_dump_printf("\n");
2830         }
2831
2832         /* Close */
2833         close_auto_dump();
2834
2835         /* Success */
2836         return (0);
2837 }
2838
2839
2840 /*
2841  * Hack -- ask for a "trigger" (see below)
2842  *
2843  * Note the complex use of the "inkey()" function from "util.c".
2844  *
2845  * Note that both "flush()" calls are extremely important.
2846  */
2847 static void do_cmd_macro_aux(char *buf)
2848 {
2849         int i, n = 0;
2850
2851         char tmp[1024];
2852
2853
2854         /* Flush */
2855         flush();
2856
2857         /* Do not process macros */
2858         inkey_base = TRUE;
2859
2860         /* First key */
2861         i = inkey();
2862
2863         /* Read the pattern */
2864         while (i)
2865         {
2866                 /* Save the key */
2867                 buf[n++] = i;
2868
2869                 /* Do not process macros */
2870                 inkey_base = TRUE;
2871
2872                 /* Do not wait for keys */
2873                 inkey_scan = TRUE;
2874
2875                 /* Attempt to read a key */
2876                 i = inkey();
2877         }
2878
2879         /* Terminate */
2880         buf[n] = '\0';
2881
2882         /* Flush */
2883         flush();
2884
2885
2886         /* Convert the trigger */
2887         ascii_to_text(tmp, buf);
2888
2889         /* Hack -- display the trigger */
2890         Term_addstr(-1, TERM_WHITE, tmp);
2891 }
2892
2893 #endif
2894
2895
2896 /*
2897  * Hack -- ask for a keymap "trigger" (see below)
2898  *
2899  * Note that both "flush()" calls are extremely important.  This may
2900  * no longer be true, since "util.c" is much simpler now.  XXX XXX XXX
2901  */
2902 static void do_cmd_macro_aux_keymap(char *buf)
2903 {
2904         char tmp[1024];
2905
2906
2907         /* Flush */
2908         flush();
2909
2910
2911         /* Get a key */
2912         buf[0] = inkey();
2913         buf[1] = '\0';
2914
2915
2916         /* Convert to ascii */
2917         ascii_to_text(tmp, buf);
2918
2919         /* Hack -- display the trigger */
2920         Term_addstr(-1, TERM_WHITE, tmp);
2921
2922
2923         /* Flush */
2924         flush();
2925 }
2926
2927
2928 /*
2929  * Hack -- append all keymaps to the given file
2930  */
2931 static errr keymap_dump(cptr fname)
2932 {
2933         static cptr mark = "Keymap Dump";
2934         int i;
2935
2936         char key[1024];
2937         char buf[1024];
2938
2939         int mode;
2940
2941         /* Roguelike */
2942         if (rogue_like_commands)
2943         {
2944                 mode = KEYMAP_MODE_ROGUE;
2945         }
2946
2947         /* Original */
2948         else
2949         {
2950                 mode = KEYMAP_MODE_ORIG;
2951         }
2952
2953
2954         /* Build the filename */
2955         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2956
2957         /* File type is "TEXT" */
2958         FILE_TYPE(FILE_TYPE_TEXT);
2959
2960         /* Append to the file */
2961         if (!open_auto_dump(buf, mark)) return -1;
2962
2963         /* Start dumping */
2964 #ifdef JP
2965         auto_dump_printf("\n# ¼«Æ°¥­¡¼ÇÛÃÖ¥»¡¼¥Ö\n\n");
2966 #else
2967         auto_dump_printf("\n# Automatic keymap dump\n\n");
2968 #endif
2969
2970         /* Dump them */
2971         for (i = 0; i < 256; i++)
2972         {
2973                 cptr act;
2974
2975                 /* Loop up the keymap */
2976                 act = keymap_act[mode][i];
2977
2978                 /* Skip empty keymaps */
2979                 if (!act) continue;
2980
2981                 /* Encode the key */
2982                 buf[0] = i;
2983                 buf[1] = '\0';
2984                 ascii_to_text(key, buf);
2985
2986                 /* Encode the action */
2987                 ascii_to_text(buf, act);
2988
2989                 /* Dump the macro */
2990                 auto_dump_printf("A:%s\n", buf);
2991                 auto_dump_printf("C:%d:%s\n", mode, key);
2992         }
2993
2994         /* Close */
2995         close_auto_dump();
2996
2997         /* Success */
2998         return (0);
2999 }
3000
3001
3002
3003 /*
3004  * Interact with "macros"
3005  *
3006  * Note that the macro "action" must be defined before the trigger.
3007  *
3008  * Could use some helpful instructions on this page.  XXX XXX XXX
3009  */
3010 void do_cmd_macros(void)
3011 {
3012         int i;
3013
3014         char tmp[1024];
3015
3016         char buf[1024];
3017
3018         int mode;
3019
3020
3021         /* Roguelike */
3022         if (rogue_like_commands)
3023         {
3024                 mode = KEYMAP_MODE_ROGUE;
3025         }
3026
3027         /* Original */
3028         else
3029         {
3030                 mode = KEYMAP_MODE_ORIG;
3031         }
3032
3033         /* File type is "TEXT" */
3034         FILE_TYPE(FILE_TYPE_TEXT);
3035
3036
3037         /* Save screen */
3038         screen_save();
3039
3040
3041         /* Process requests until done */
3042         while (1)
3043         {
3044                 /* Clear screen */
3045                 Term_clear();
3046
3047                 /* Describe */
3048 #ifdef JP
3049                 prt("[ ¥Þ¥¯¥í¤ÎÀßÄê ]", 2, 0);
3050 #else
3051                 prt("Interact with Macros", 2, 0);
3052 #endif
3053
3054
3055
3056                 /* Describe that action */
3057 #ifdef JP
3058                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3059 #else
3060                 prt("Current action (if any) shown below:", 20, 0);
3061 #endif
3062
3063
3064                 /* Analyze the current action */
3065                 ascii_to_text(buf, macro__buf);
3066
3067                 /* Display the current action */
3068                 prt(buf, 22, 0);
3069
3070
3071                 /* Selections */
3072 #ifdef JP
3073                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3074 #else
3075                 prt("(1) Load a user pref file", 4, 5);
3076 #endif
3077
3078 #ifdef ALLOW_MACROS
3079 #ifdef JP
3080                 prt("(2) ¥Õ¥¡¥¤¥ë¤Ë¥Þ¥¯¥í¤òÄɲÃ", 5, 5);
3081                 prt("(3) ¥Þ¥¯¥í¤Î³Îǧ", 6, 5);
3082                 prt("(4) ¥Þ¥¯¥í¤ÎºîÀ®", 7, 5);
3083                 prt("(5) ¥Þ¥¯¥í¤Îºï½ü", 8, 5);
3084                 prt("(6) ¥Õ¥¡¥¤¥ë¤Ë¥­¡¼ÇÛÃÖ¤òÄɲÃ", 9, 5);
3085                 prt("(7) ¥­¡¼ÇÛÃ֤γÎǧ", 10, 5);
3086                 prt("(8) ¥­¡¼ÇÛÃ֤κîÀ®", 11, 5);
3087                 prt("(9) ¥­¡¼ÇÛÃ֤κï½ü", 12, 5);
3088                 prt("(0) ¥Þ¥¯¥í¹ÔÆ°¤ÎÆþÎÏ", 13, 5);
3089 #else
3090                 prt("(2) Append macros to a file", 5, 5);
3091                 prt("(3) Query a macro", 6, 5);
3092                 prt("(4) Create a macro", 7, 5);
3093                 prt("(5) Remove a macro", 8, 5);
3094                 prt("(6) Append keymaps to a file", 9, 5);
3095                 prt("(7) Query a keymap", 10, 5);
3096                 prt("(8) Create a keymap", 11, 5);
3097                 prt("(9) Remove a keymap", 12, 5);
3098                 prt("(0) Enter a new action", 13, 5);
3099 #endif
3100
3101 #endif /* ALLOW_MACROS */
3102
3103                 /* Prompt */
3104 #ifdef JP
3105                 prt("¥³¥Þ¥ó¥É: ", 16, 0);
3106 #else
3107                 prt("Command: ", 16, 0);
3108 #endif
3109
3110
3111                 /* Get a command */
3112                 i = inkey();
3113
3114                 /* Leave */
3115                 if (i == ESCAPE) break;
3116
3117                 /* Load a 'macro' file */
3118                 else if (i == '1')
3119                 {
3120                         errr err;
3121
3122                         /* Prompt */
3123 #ifdef JP
3124                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 16, 0);
3125 #else
3126                         prt("Command: Load a user pref file", 16, 0);
3127 #endif
3128
3129
3130                         /* Prompt */
3131 #ifdef JP
3132                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3133 #else
3134                         prt("File: ", 18, 0);
3135 #endif
3136
3137
3138                         /* Default filename */
3139                         sprintf(tmp, "%s.prf", player_name);
3140
3141                         /* Ask for a file */
3142                         if (!askfor_aux(tmp, 80)) continue;
3143
3144                         /* Process the given filename */
3145                         err = process_pref_file(tmp);
3146                         if (-2 == err)
3147                         {
3148 #ifdef JP
3149                                 msg_format("ɸ½à¤ÎÀßÄê¥Õ¥¡¥¤¥ë'%s'¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", tmp);
3150 #else
3151                                 msg_format("Loaded default '%s'.", tmp);
3152 #endif
3153                         }
3154                         else if (err)
3155                         {
3156                                 /* Prompt */
3157 #ifdef JP
3158                                 msg_format("'%s'¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡ª", tmp);
3159 #else
3160                                 msg_format("Failed to load '%s'!");
3161 #endif
3162                         }
3163                         else
3164                         {
3165 #ifdef JP
3166                                 msg_format("'%s'¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", tmp);
3167 #else
3168                                 msg_format("Loaded '%s'.", tmp);
3169 #endif
3170                         }
3171                 }
3172
3173 #ifdef ALLOW_MACROS
3174
3175                 /* Save macros */
3176                 else if (i == '2')
3177                 {
3178                         /* Prompt */
3179 #ifdef JP
3180                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤ò¥Õ¥¡¥¤¥ë¤ËÄɲ乤ë", 16, 0);
3181 #else
3182                         prt("Command: Append macros to a file", 16, 0);
3183 #endif
3184
3185
3186                         /* Prompt */
3187 #ifdef JP
3188                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3189 #else
3190                         prt("File: ", 18, 0);
3191 #endif
3192
3193
3194                         /* Default filename */
3195                         sprintf(tmp, "%s.prf", player_name);
3196
3197                         /* Ask for a file */
3198                         if (!askfor_aux(tmp, 80)) continue;
3199
3200                         /* Dump the macros */
3201                         (void)macro_dump(tmp);
3202
3203                         /* Prompt */
3204 #ifdef JP
3205                         msg_print("¥Þ¥¯¥í¤òÄɲä·¤Þ¤·¤¿¡£");
3206 #else
3207                         msg_print("Appended macros.");
3208 #endif
3209
3210                 }
3211
3212                 /* Query a macro */
3213                 else if (i == '3')
3214                 {
3215                         int k;
3216
3217                         /* Prompt */
3218 #ifdef JP
3219                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤Î³Îǧ", 16, 0);
3220 #else
3221                         prt("Command: Query a macro", 16, 0);
3222 #endif
3223
3224
3225                         /* Prompt */
3226 #ifdef JP
3227                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3228 #else
3229                         prt("Trigger: ", 18, 0);
3230 #endif
3231
3232
3233                         /* Get a macro trigger */
3234                         do_cmd_macro_aux(buf);
3235
3236                         /* Acquire action */
3237                         k = macro_find_exact(buf);
3238
3239                         /* Nothing found */
3240                         if (k < 0)
3241                         {
3242                                 /* Prompt */
3243 #ifdef JP
3244                                 msg_print("¤½¤Î¥­¡¼¤Ë¤Ï¥Þ¥¯¥í¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
3245 #else
3246                                 msg_print("Found no macro.");
3247 #endif
3248
3249                         }
3250
3251                         /* Found one */
3252                         else
3253                         {
3254                                 /* Obtain the action */
3255                                 strcpy(macro__buf, macro__act[k]);
3256
3257                                 /* Analyze the current action */
3258                                 ascii_to_text(buf, macro__buf);
3259
3260                                 /* Display the current action */
3261                                 prt(buf, 22, 0);
3262
3263                                 /* Prompt */
3264 #ifdef JP
3265                                 msg_print("¥Þ¥¯¥í¤ò³Îǧ¤·¤Þ¤·¤¿¡£");
3266 #else
3267                                 msg_print("Found a macro.");
3268 #endif
3269
3270                         }
3271                 }
3272
3273                 /* Create a macro */
3274                 else if (i == '4')
3275                 {
3276                         /* Prompt */
3277 #ifdef JP
3278                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤ÎºîÀ®", 16, 0);
3279 #else
3280                         prt("Command: Create a macro", 16, 0);
3281 #endif
3282
3283
3284                         /* Prompt */
3285 #ifdef JP
3286                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3287 #else
3288                         prt("Trigger: ", 18, 0);
3289 #endif
3290
3291
3292                         /* Get a macro trigger */
3293                         do_cmd_macro_aux(buf);
3294
3295                         /* Clear */
3296                         clear_from(20);
3297
3298                         /* Prompt */
3299 #ifdef JP
3300                         prt("¥Þ¥¯¥í¹ÔÆ°: ", 20, 0);
3301 #else
3302                         prt("Action: ", 20, 0);
3303 #endif
3304
3305
3306                         /* Convert to text */
3307                         ascii_to_text(tmp, macro__buf);
3308
3309                         /* Get an encoded action */
3310                         if (askfor_aux(tmp, 80))
3311                         {
3312                                 /* Convert to ascii */
3313                                 text_to_ascii(macro__buf, tmp);
3314
3315                                 /* Link the macro */
3316                                 macro_add(buf, macro__buf);
3317
3318                                 /* Prompt */
3319 #ifdef JP
3320                                 msg_print("¥Þ¥¯¥í¤òÄɲä·¤Þ¤·¤¿¡£");
3321 #else
3322                                 msg_print("Added a macro.");
3323 #endif
3324
3325                         }
3326                 }
3327
3328                 /* Remove a macro */
3329                 else if (i == '5')
3330                 {
3331                         /* Prompt */
3332 #ifdef JP
3333                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤Îºï½ü", 16, 0);
3334 #else
3335                         prt("Command: Remove a macro", 16, 0);
3336 #endif
3337
3338
3339                         /* Prompt */
3340 #ifdef JP
3341                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3342 #else
3343                         prt("Trigger: ", 18, 0);
3344 #endif
3345
3346
3347                         /* Get a macro trigger */
3348                         do_cmd_macro_aux(buf);
3349
3350                         /* Link the macro */
3351                         macro_add(buf, buf);
3352
3353                         /* Prompt */
3354 #ifdef JP
3355                         msg_print("¥Þ¥¯¥í¤òºï½ü¤·¤Þ¤·¤¿¡£");
3356 #else
3357                         msg_print("Removed a macro.");
3358 #endif
3359
3360                 }
3361
3362                 /* Save keymaps */
3363                 else if (i == '6')
3364                 {
3365                         /* Prompt */
3366 #ifdef JP
3367                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃÖ¤ò¥Õ¥¡¥¤¥ë¤ËÄɲ乤ë", 16, 0);
3368 #else
3369                         prt("Command: Append keymaps to a file", 16, 0);
3370 #endif
3371
3372
3373                         /* Prompt */
3374 #ifdef JP
3375                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3376 #else
3377                         prt("File: ", 18, 0);
3378 #endif
3379
3380
3381                         /* Default filename */
3382                         sprintf(tmp, "%s.prf", player_name);
3383
3384                         /* Ask for a file */
3385                         if (!askfor_aux(tmp, 80)) continue;
3386
3387                         /* Dump the macros */
3388                         (void)keymap_dump(tmp);
3389
3390                         /* Prompt */
3391 #ifdef JP
3392                         msg_print("¥­¡¼ÇÛÃÖ¤òÄɲä·¤Þ¤·¤¿¡£");
3393 #else
3394                         msg_print("Appended keymaps.");
3395 #endif
3396
3397                 }
3398
3399                 /* Query a keymap */
3400                 else if (i == '7')
3401                 {
3402                         cptr act;
3403
3404                         /* Prompt */
3405 #ifdef JP
3406                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤γÎǧ", 16, 0);
3407 #else
3408                         prt("Command: Query a keymap", 16, 0);
3409 #endif
3410
3411
3412                         /* Prompt */
3413 #ifdef JP
3414                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3415 #else
3416                         prt("Keypress: ", 18, 0);
3417 #endif
3418
3419
3420                         /* Get a keymap trigger */
3421                         do_cmd_macro_aux_keymap(buf);
3422
3423                         /* Look up the keymap */
3424                         act = keymap_act[mode][(byte)(buf[0])];
3425
3426                         /* Nothing found */
3427                         if (!act)
3428                         {
3429                                 /* Prompt */
3430 #ifdef JP
3431                                 msg_print("¥­¡¼ÇÛÃÖ¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
3432 #else
3433                                 msg_print("Found no keymap.");
3434 #endif
3435
3436                         }
3437
3438                         /* Found one */
3439                         else
3440                         {
3441                                 /* Obtain the action */
3442                                 strcpy(macro__buf, act);
3443
3444                                 /* Analyze the current action */
3445                                 ascii_to_text(buf, macro__buf);
3446
3447                                 /* Display the current action */
3448                                 prt(buf, 22, 0);
3449
3450                                 /* Prompt */
3451 #ifdef JP
3452                                 msg_print("¥­¡¼ÇÛÃÖ¤ò³Îǧ¤·¤Þ¤·¤¿¡£");
3453 #else
3454                                 msg_print("Found a keymap.");
3455 #endif
3456
3457                         }
3458                 }
3459
3460                 /* Create a keymap */
3461                 else if (i == '8')
3462                 {
3463                         /* Prompt */
3464 #ifdef JP
3465                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤κîÀ®", 16, 0);
3466 #else
3467                         prt("Command: Create a keymap", 16, 0);
3468 #endif
3469
3470
3471                         /* Prompt */
3472 #ifdef JP
3473                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3474 #else
3475                         prt("Keypress: ", 18, 0);
3476 #endif
3477
3478
3479                         /* Get a keymap trigger */
3480                         do_cmd_macro_aux_keymap(buf);
3481
3482                         /* Clear */
3483                         clear_from(20);
3484
3485                         /* Prompt */
3486 #ifdef JP
3487                         prt("¹ÔÆ°: ", 20, 0);
3488 #else
3489                         prt("Action: ", 20, 0);
3490 #endif
3491
3492
3493                         /* Convert to text */
3494                         ascii_to_text(tmp, macro__buf);
3495
3496                         /* Get an encoded action */
3497                         if (askfor_aux(tmp, 80))
3498                         {
3499                                 /* Convert to ascii */
3500                                 text_to_ascii(macro__buf, tmp);
3501
3502                                 /* Free old keymap */
3503                                 string_free(keymap_act[mode][(byte)(buf[0])]);
3504
3505                                 /* Make new keymap */
3506                                 keymap_act[mode][(byte)(buf[0])] = string_make(macro__buf);
3507
3508                                 /* Prompt */
3509 #ifdef JP
3510                                 msg_print("¥­¡¼ÇÛÃÖ¤òÄɲä·¤Þ¤·¤¿¡£");
3511 #else
3512                                 msg_print("Added a keymap.");
3513 #endif
3514
3515                         }
3516                 }
3517
3518                 /* Remove a keymap */
3519                 else if (i == '9')
3520                 {
3521                         /* Prompt */
3522 #ifdef JP
3523                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤κï½ü", 16, 0);
3524 #else
3525                         prt("Command: Remove a keymap", 16, 0);
3526 #endif
3527
3528
3529                         /* Prompt */
3530 #ifdef JP
3531                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3532 #else
3533                         prt("Keypress: ", 18, 0);
3534 #endif
3535
3536
3537                         /* Get a keymap trigger */
3538                         do_cmd_macro_aux_keymap(buf);
3539
3540                         /* Free old keymap */
3541                         string_free(keymap_act[mode][(byte)(buf[0])]);
3542
3543                         /* Make new keymap */
3544                         keymap_act[mode][(byte)(buf[0])] = NULL;
3545
3546                         /* Prompt */
3547 #ifdef JP
3548                         msg_print("¥­¡¼ÇÛÃÖ¤òºï½ü¤·¤Þ¤·¤¿¡£");
3549 #else
3550                         msg_print("Removed a keymap.");
3551 #endif
3552
3553                 }
3554
3555                 /* Enter a new action */
3556                 else if (i == '0')
3557                 {
3558                         /* Prompt */
3559 #ifdef JP
3560                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¹ÔÆ°¤ÎÆþÎÏ", 16, 0);
3561 #else
3562                         prt("Command: Enter a new action", 16, 0);
3563 #endif
3564
3565
3566                         /* Go to the correct location */
3567                         Term_gotoxy(0, 22);
3568
3569                         /* Hack -- limit the value */
3570                         tmp[80] = '\0';
3571
3572                         /* Get an encoded action */
3573                         if (!askfor_aux(buf, 80)) continue;
3574
3575                         /* Extract an action */
3576                         text_to_ascii(macro__buf, buf);
3577                 }
3578
3579 #endif /* ALLOW_MACROS */
3580
3581                 /* Oops */
3582                 else
3583                 {
3584                         /* Oops */
3585                         bell();
3586                 }
3587
3588                 /* Flush messages */
3589                 msg_print(NULL);
3590         }
3591
3592         /* Load screen */
3593         screen_load();
3594 }
3595
3596
3597 static void cmd_visuals_aux(int i, int *num, int max)
3598 {
3599         if (iscntrl(i))
3600         {
3601                 char str[10] = "";
3602                 int tmp;
3603
3604                 sprintf(str, "%d", *num);
3605
3606                 if (!get_string(format("Input new number(0-%d): ", max-1), str, 4))
3607                         return;
3608
3609                 tmp = strtol(str, NULL, 0);
3610                 if (tmp >= 0 && tmp < max)
3611                         *num = tmp;
3612                 return;
3613         }
3614         else if (isupper(i))
3615                 *num = (*num + max - 1) % max;
3616         else
3617                 *num = (*num + 1) % max;
3618
3619         return;
3620 }
3621
3622 /*
3623  * Interact with "visuals"
3624  */
3625 void do_cmd_visuals(void)
3626 {
3627         int i;
3628
3629         char tmp[160];
3630
3631         char buf[1024];
3632
3633         const char *empty_symbol = "<< ? >>";
3634
3635         if (use_bigtile) empty_symbol = "<< ?? >>";
3636
3637         /* File type is "TEXT" */
3638         FILE_TYPE(FILE_TYPE_TEXT);
3639
3640
3641         /* Save the screen */
3642         screen_save();
3643
3644
3645         /* Interact until done */
3646         while (1)
3647         {
3648                 /* Clear screen */
3649                 Term_clear();
3650
3651                 /* Ask for a choice */
3652 #ifdef JP
3653                 prt("²èÌÌɽ¼¨¤ÎÀßÄê", 2, 0);
3654 #else
3655                 prt("Interact with Visuals", 2, 0);
3656 #endif
3657
3658
3659                 /* Give some choices */
3660 #ifdef JP
3661                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3662 #else
3663                 prt("(1) Load a user pref file", 4, 5);
3664 #endif
3665
3666 #ifdef ALLOW_VISUALS
3667 #ifdef JP
3668                 prt("(2) ¥â¥ó¥¹¥¿¡¼¤Î ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 5, 5);
3669                 prt("(3) ¥¢¥¤¥Æ¥à¤Î   ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 6, 5);
3670                 prt("(4) ÃÏ·Á¤Î       ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 7, 5);
3671                 prt("(5) (̤»ÈÍÑ)", 8, 5);
3672                 prt("(6) ¥â¥ó¥¹¥¿¡¼¤Î ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 9, 5);
3673                 prt("(7) ¥¢¥¤¥Æ¥à¤Î   ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 10, 5);
3674                 prt("(8) ÃÏ·Á¤Î       ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 11, 5);
3675                 prt("(9) (̤»ÈÍÑ)", 12, 5);
3676 #else
3677                 prt("(2) Dump monster attr/chars", 5, 5);
3678                 prt("(3) Dump object attr/chars", 6, 5);
3679                 prt("(4) Dump feature attr/chars", 7, 5);
3680                 prt("(5) (unused)", 8, 5);
3681                 prt("(6) Change monster attr/chars", 9, 5);
3682                 prt("(7) Change object attr/chars", 10, 5);
3683                 prt("(8) Change feature attr/chars", 11, 5);
3684                 prt("(9) (unused)", 12, 5);
3685 #endif
3686
3687 #endif
3688 #ifdef JP
3689                 prt("(0) ²èÌÌɽ¼¨ÊýË¡¤Î½é´ü²½", 13, 5);
3690 #else
3691                 prt("(0) Reset visuals", 13, 5);
3692 #endif
3693
3694
3695                 /* Prompt */
3696 #ifdef JP
3697                 prt("¥³¥Þ¥ó¥É:", 18, 0);
3698 #else
3699                 prt("Command: ", 15, 0);
3700 #endif
3701
3702
3703                 /* Prompt */
3704                 i = inkey();
3705
3706                 /* Done */
3707                 if (i == ESCAPE) break;
3708
3709                 /* Load a 'pref' file */
3710                 else if (i == '1')
3711                 {
3712                         /* Prompt */
3713 #ifdef JP
3714                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 15, 0);
3715 #else
3716                         prt("Command: Load a user pref file", 15, 0);
3717 #endif
3718
3719
3720                         /* Prompt */
3721 #ifdef JP
3722                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3723 #else
3724                         prt("File: ", 17, 0);
3725 #endif
3726
3727
3728                         /* Default filename */
3729                         sprintf(tmp, "%s.prf", player_name);
3730
3731                         /* Query */
3732                         if (!askfor_aux(tmp, 70)) continue;
3733
3734                         /* Process the given filename */
3735                         (void)process_pref_file(tmp);
3736                 }
3737
3738 #ifdef ALLOW_VISUALS
3739
3740                 /* Dump monster attr/chars */
3741                 else if (i == '2')
3742                 {
3743                         static cptr mark = "Monster attr/chars";
3744
3745                         /* Prompt */
3746 #ifdef JP
3747                         prt("¥³¥Þ¥ó¥É: ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3748 #else
3749                         prt("Command: Dump monster attr/chars", 15, 0);
3750 #endif
3751
3752
3753                         /* Prompt */
3754 #ifdef JP
3755                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3756 #else
3757                         prt("File: ", 17, 0);
3758 #endif
3759
3760
3761                         /* Default filename */
3762                         sprintf(tmp, "%s.prf", player_name);
3763                         
3764                         /* Get a filename */
3765                         if (!askfor_aux(tmp, 70)) continue;
3766
3767                         /* Build the filename */
3768                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3769
3770                         /* Append to the file */
3771                         if (!open_auto_dump(buf, mark)) continue;
3772
3773                         /* Start dumping */
3774 #ifdef JP
3775                         auto_dump_printf("\n# ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3776 #else
3777                         auto_dump_printf("\n# Monster attr/char definitions\n\n");
3778 #endif
3779
3780                         /* Dump monsters */
3781                         for (i = 1; i < max_r_idx; i++)
3782                         {
3783                                 monster_race *r_ptr = &r_info[i];
3784
3785                                 /* Skip non-entries */
3786                                 if (!r_ptr->name) continue;
3787
3788                                 /* Dump a comment */
3789                                 auto_dump_printf("# %s\n", (r_name + r_ptr->name));
3790
3791                                 /* Dump the monster attr/char info */
3792                                 auto_dump_printf("R:%d:0x%02X/0x%02X\n\n", i,
3793                                         (byte)(r_ptr->x_attr), (byte)(r_ptr->x_char));
3794                         }
3795
3796                         /* Close */
3797                         close_auto_dump();
3798
3799                         /* Message */
3800 #ifdef JP
3801                         msg_print("¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3802 #else
3803                         msg_print("Dumped monster attr/chars.");
3804 #endif
3805
3806                 }
3807
3808                 /* Dump object attr/chars */
3809                 else if (i == '3')
3810                 {
3811                         static cptr mark = "Object attr/chars";
3812
3813                         /* Prompt */
3814 #ifdef JP
3815                         prt("¥³¥Þ¥ó¥É: ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3816 #else
3817                         prt("Command: Dump object attr/chars", 15, 0);
3818 #endif
3819
3820
3821                         /* Prompt */
3822 #ifdef JP
3823                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3824 #else
3825                         prt("File: ", 17, 0);
3826 #endif
3827
3828
3829                         /* Default filename */
3830                         sprintf(tmp, "%s.prf", player_name);
3831
3832                         /* Get a filename */
3833                         if (!askfor_aux(tmp, 70)) continue;
3834
3835                         /* Build the filename */
3836                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3837
3838                         /* Append to the file */
3839                         if (!open_auto_dump(buf, mark)) continue;
3840
3841                         /* Start dumping */
3842 #ifdef JP
3843                         auto_dump_printf("\n# ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3844 #else
3845                         auto_dump_printf("\n# Object attr/char definitions\n\n");
3846 #endif
3847
3848                         /* Dump objects */
3849                         for (i = 1; i < max_k_idx; i++)
3850                         {
3851                                 char o_name[80];
3852                                 object_kind *k_ptr = &k_info[i];
3853
3854                                 /* Skip non-entries */
3855                                 if (!k_ptr->name) continue;
3856
3857                                 /* Skip entries with flavor */
3858                                 if (k_ptr->flavor) continue;
3859
3860                                 /* Tidy name */
3861                                 strip_name(o_name, i);
3862
3863                                 /* Dump a comment */
3864                                 auto_dump_printf("# %s\n", o_name);
3865
3866                                 /* Dump the object attr/char info */
3867                                 auto_dump_printf("K:%d:0x%02X/0x%02X\n\n", i,
3868                                         (byte)(k_ptr->x_attr), (byte)(k_ptr->x_char));
3869                         }
3870
3871                         /* Close */
3872                         close_auto_dump();
3873
3874                         /* Message */
3875 #ifdef JP
3876                         msg_print("¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3877 #else
3878                         msg_print("Dumped object attr/chars.");
3879 #endif
3880
3881                 }
3882
3883                 /* Dump feature attr/chars */
3884                 else if (i == '4')
3885                 {
3886                         static cptr mark = "Feature attr/chars";
3887
3888                         /* Prompt */
3889 #ifdef JP
3890                         prt("¥³¥Þ¥ó¥É: ÃÏ·Á¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3891 #else
3892                         prt("Command: Dump feature attr/chars", 15, 0);
3893 #endif
3894
3895
3896                         /* Prompt */
3897 #ifdef JP
3898                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3899 #else
3900                         prt("File: ", 17, 0);
3901 #endif
3902
3903
3904                         /* Default filename */
3905                         sprintf(tmp, "%s.prf", player_name);
3906
3907                         /* Get a filename */
3908                         if (!askfor_aux(tmp, 70)) continue;
3909
3910                         /* Build the filename */
3911                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3912
3913                         /* Append to the file */
3914                         if (!open_auto_dump(buf, mark)) continue;
3915
3916                         /* Start dumping */
3917 #ifdef JP
3918                         auto_dump_printf("\n# ÃÏ·Á¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3919 #else
3920                         auto_dump_printf("\n# Feature attr/char definitions\n\n");
3921 #endif
3922
3923                         /* Dump features */
3924                         for (i = 1; i < max_f_idx; i++)
3925                         {
3926                                 feature_type *f_ptr = &f_info[i];
3927
3928                                 /* Skip non-entries */
3929                                 if (!f_ptr->name) continue;
3930
3931                                 /* Skip mimiccing features */
3932                                 if (f_ptr->mimic != i) continue;
3933
3934                                 /* Dump a comment */
3935                                 auto_dump_printf("# %s\n", (f_name + f_ptr->name));
3936
3937                                 /* Dump the feature attr/char info */
3938                                 auto_dump_printf("F:%d:0x%02X/0x%02X\n\n", i,
3939                                         (byte)(f_ptr->x_attr), (byte)(f_ptr->x_char));
3940                         }
3941
3942                         /* Close */
3943                         close_auto_dump();
3944
3945                         /* Message */
3946 #ifdef JP
3947                         msg_print("ÃÏ·Á¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3948 #else
3949                         msg_print("Dumped feature attr/chars.");
3950 #endif
3951
3952                 }
3953
3954                 /* Modify monster attr/chars */
3955                 else if (i == '6')
3956                 {
3957                         static int r = 0;
3958
3959                         /* Prompt */
3960 #ifdef JP
3961                         prt("¥³¥Þ¥ó¥É: ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
3962 #else
3963                         prt("Command: Change monster attr/chars", 15, 0);
3964 #endif
3965
3966
3967                         /* Hack -- query until done */
3968                         while (1)
3969                         {
3970                                 monster_race *r_ptr = &r_info[r];
3971                                 byte a, a2;
3972                                 char c, c2;
3973                                 int t;
3974
3975                                 byte da = (r_ptr->d_attr);
3976                                 byte dc = (r_ptr->d_char);
3977                                 byte ca = (r_ptr->x_attr);
3978                                 byte cc = (r_ptr->x_char);
3979
3980                                 /* Label the object */
3981 #ifdef JP
3982                                 Term_putstr(5, 17, -1, TERM_WHITE,
3983                                             format("¥â¥ó¥¹¥¿¡¼ = %d, Ì¾Á° = %-40.40s",
3984                                                    r, (r_name + r_ptr->name)));
3985 #else
3986                                 Term_putstr(5, 17, -1, TERM_WHITE,
3987                                             format("Monster = %d, Name = %-40.40s",
3988                                                    r, (r_name + r_ptr->name)));
3989 #endif
3990
3991
3992                                 /* Label the Default values */
3993 #ifdef JP
3994                                 Term_putstr(10, 19, -1, TERM_WHITE,
3995                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3u / %3u", da, dc));
3996 #else
3997                                 Term_putstr(10, 19, -1, TERM_WHITE,
3998                                             format("Default attr/char = %3u / %3u", da, dc));
3999 #endif
4000
4001                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4002
4003                                 a = da;
4004                                 c = dc;
4005                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4006
4007                                 Term_putch(43, 19, a, c);
4008                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4009
4010                                 /* Label the Current values */
4011 #ifdef JP
4012                                 Term_putstr(10, 20, -1, TERM_WHITE,
4013                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3u / %3u", ca, cc));
4014 #else
4015                                 Term_putstr(10, 20, -1, TERM_WHITE,
4016                                             format("Current attr/char = %3u / %3u", ca, cc));
4017 #endif
4018
4019                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4020
4021                                 a = ca;
4022                                 c = cc;
4023                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4024
4025                                 Term_putch(43, 20, a, c);
4026                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4027
4028
4029                                 /* Prompt */
4030 #ifdef JP
4031                                 Term_putstr(0, 22, -1, TERM_WHITE,
4032                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4033 #else
4034                                 Term_putstr(0, 22, -1, TERM_WHITE,
4035                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4036 #endif
4037
4038                                 /* Get a command */
4039                                 i = inkey();
4040
4041                                 /* All done */
4042                                 if (i == ESCAPE) break;
4043
4044                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4045                                 else if (isupper(i)) c = 'a' + i - 'A';
4046                                 else c = i;
4047
4048                                 switch (c)
4049                                 {
4050                                 case 'n':
4051                                         cmd_visuals_aux(i, &r, max_r_idx);
4052                                         break;
4053                                 case 'a':
4054                                         t = (int)r_ptr->x_attr;
4055                                         cmd_visuals_aux(i, &t, 256);
4056                                         r_ptr->x_attr = (byte)t;
4057                                         break;
4058                                 case 'c':
4059                                         t = (int)r_ptr->x_char;
4060                                         cmd_visuals_aux(i, &t, 256);
4061                                         r_ptr->x_char = (byte)t;
4062                                         break;
4063                                 }
4064                         }
4065                 }
4066
4067                 /* Modify object attr/chars */
4068                 else if (i == '7')
4069                 {
4070                         static int k = 0;
4071
4072                         /* Prompt */
4073 #ifdef JP
4074                         prt("¥³¥Þ¥ó¥É: ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
4075 #else
4076                         prt("Command: Change object attr/chars", 15, 0);
4077 #endif
4078
4079
4080                         /* Hack -- query until done */
4081                         while (1)
4082                         {
4083                                 object_kind *k_ptr = &k_info[k];
4084                                 byte a, a2;
4085                                 char c, c2;
4086                                 int t;
4087
4088                                 byte da = (byte)k_ptr->d_attr;
4089                                 byte dc = (byte)k_ptr->d_char;
4090                                 byte ca = (byte)k_ptr->x_attr;
4091                                 byte cc = (byte)k_ptr->x_char;
4092
4093                                 /* Label the object */
4094 #ifdef JP
4095                                 Term_putstr(5, 17, -1, TERM_WHITE,
4096                                             format("¥¢¥¤¥Æ¥à = %d, Ì¾Á° = %-40.40s",
4097                                                    k, (k_name + k_ptr->name)));
4098 #else
4099                                 Term_putstr(5, 17, -1, TERM_WHITE,
4100                                             format("Object = %d, Name = %-40.40s",
4101                                                    k, (k_name + k_ptr->name)));
4102 #endif
4103
4104
4105                                 /* Label the Default values */
4106 #ifdef JP
4107                                 Term_putstr(10, 19, -1, TERM_WHITE,
4108                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3d / %3d", da, dc));
4109 #else
4110                                 Term_putstr(10, 19, -1, TERM_WHITE,
4111                                             format("Default attr/char = %3d / %3d", da, dc));
4112 #endif
4113
4114                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4115                                 a = da;
4116                                 c = dc;
4117                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4118
4119                                 Term_putch(43, 19, a, c);
4120                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4121
4122
4123                                 /* Label the Current values */
4124 #ifdef JP
4125                                 Term_putstr(10, 20, -1, TERM_WHITE,
4126                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3d / %3d", ca, cc));
4127 #else
4128                                 Term_putstr(10, 20, -1, TERM_WHITE,
4129                                             format("Current attr/char = %3d / %3d", ca, cc));
4130 #endif
4131
4132                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4133                                 a = ca;
4134                                 c = cc;
4135                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4136
4137                                 Term_putch(43, 20, a, c);
4138                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4139
4140
4141                                 /* Prompt */
4142 #ifdef JP
4143                                 Term_putstr(0, 22, -1, TERM_WHITE,
4144                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4145 #else
4146                                 Term_putstr(0, 22, -1, TERM_WHITE,
4147                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4148 #endif
4149
4150                                 /* Get a command */
4151                                 i = inkey();
4152
4153                                 /* All done */
4154                                 if (i == ESCAPE) break;
4155
4156                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4157                                 else if (isupper(i)) c = 'a' + i - 'A';
4158                                 else c = i;
4159
4160                                 switch (c)
4161                                 {
4162                                 case 'n':
4163                                         cmd_visuals_aux(i, &k, max_k_idx);
4164                                         break;
4165                                 case 'a':
4166                                         t = (int)k_info[k].x_attr;
4167                                         cmd_visuals_aux(i, &t, 256);
4168                                         k_info[k].x_attr = (byte)t;
4169                                         break;
4170                                 case 'c':
4171                                         t = (int)k_info[k].x_char;
4172                                         cmd_visuals_aux(i, &t, 256);
4173                                         k_info[k].x_char = (byte)t;
4174                                         break;
4175                                 }
4176                         }
4177                 }
4178
4179                 /* Modify feature attr/chars */
4180                 else if (i == '8')
4181                 {
4182                         static int f = 0;
4183
4184                         /* Prompt */
4185 #ifdef JP
4186                         prt("¥³¥Þ¥ó¥É: ÃÏ·Á¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
4187 #else
4188                         prt("Command: Change feature attr/chars", 15, 0);
4189 #endif
4190
4191
4192                         /* Hack -- query until done */
4193                         while (1)
4194                         {
4195                                 feature_type *f_ptr = &f_info[f];
4196                                 byte a, a2;
4197                                 char c, c2;
4198                                 int t;
4199
4200                                 byte da = (byte)f_ptr->d_attr;
4201                                 byte dc = (byte)f_ptr->d_char;
4202                                 byte ca = (byte)f_ptr->x_attr;
4203                                 byte cc = (byte)f_ptr->x_char;
4204
4205                                 /* Label the object */
4206 #ifdef JP
4207                                 Term_putstr(5, 17, -1, TERM_WHITE,
4208                                             format("ÃÏ·Á = %d, Ì¾Á° = %-40.40s",
4209                                                    f, (f_name + f_ptr->name)));
4210 #else
4211                                 Term_putstr(5, 17, -1, TERM_WHITE,
4212                                             format("Terrain = %d, Name = %-40.40s",
4213                                                    f, (f_name + f_ptr->name)));
4214 #endif
4215
4216
4217                                 /* Label the Default values */
4218 #ifdef JP
4219                                 Term_putstr(10, 19, -1, TERM_WHITE,
4220                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3d / %3d", da, dc));
4221 #else
4222                                 Term_putstr(10, 19, -1, TERM_WHITE,
4223                                             format("Default attr/char = %3d / %3d", da, dc));
4224 #endif
4225
4226                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4227                                 a = da;
4228                                 c = dc;
4229                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4230
4231                                 Term_putch(43, 19, a, c);
4232                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4233
4234
4235                                 /* Label the Current values */
4236 #ifdef JP
4237                                 Term_putstr(10, 20, -1, TERM_WHITE,
4238                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3d / %3d", ca, cc));
4239 #else
4240                                 Term_putstr(10, 20, -1, TERM_WHITE,
4241                                             format("Current attr/char = %3d / %3d", ca, cc));
4242 #endif
4243
4244                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4245                                 a = ca;
4246                                 c = cc;
4247                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4248
4249                                 Term_putch(43, 20, a, c);
4250                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4251
4252
4253                                 /* Prompt */
4254 #ifdef JP
4255                                 Term_putstr(0, 22, -1, TERM_WHITE,
4256                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4257 #else
4258                                 Term_putstr(0, 22, -1, TERM_WHITE,
4259                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4260 #endif
4261
4262                                 /* Get a command */
4263                                 i = inkey();
4264
4265                                 /* All done */
4266                                 if (i == ESCAPE) break;
4267
4268                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4269                                 else if (isupper(i)) c = 'a' + i - 'A';
4270                                 else c = i;
4271
4272                                 switch (c)
4273                                 {
4274                                 case 'n':
4275                                         cmd_visuals_aux(i, &f, max_f_idx);
4276                                         break;
4277                                 case 'a':
4278                                         t = (int)f_info[f].x_attr;
4279                                         cmd_visuals_aux(i, &t, 256);
4280                                         f_info[f].x_attr = (byte)t;
4281                                         break;
4282                                 case 'c':
4283                                         t = (int)f_info[f].x_char;
4284                                         cmd_visuals_aux(i, &t, 256);
4285                                         f_info[f].x_char = (byte)t;
4286                                         break;
4287                                 }
4288                         }
4289                 }
4290
4291 #endif
4292
4293                 /* Reset visuals */
4294                 else if (i == '0')
4295                 {
4296                         /* Reset */
4297                         reset_visuals();
4298
4299                         /* Message */
4300 #ifdef JP
4301                         msg_print("²èÌ̾å¤Î[¿§/ʸ»ú]¤ò½é´üÃͤ˥ꥻ¥Ã¥È¤·¤Þ¤·¤¿¡£");
4302 #else
4303                         msg_print("Visual attr/char tables reset.");
4304 #endif
4305
4306                 }
4307
4308                 /* Unknown option */
4309                 else
4310                 {
4311                         bell();
4312                 }
4313
4314                 /* Flush messages */
4315                 msg_print(NULL);
4316         }
4317
4318
4319         /* Restore the screen */
4320         screen_load();
4321 }
4322
4323
4324 /*
4325  * Interact with "colors"
4326  */
4327 void do_cmd_colors(void)
4328 {
4329         int i;
4330
4331         char tmp[160];
4332
4333         char buf[1024];
4334
4335
4336         /* File type is "TEXT" */
4337         FILE_TYPE(FILE_TYPE_TEXT);
4338
4339
4340         /* Save the screen */
4341         screen_save();
4342
4343
4344         /* Interact until done */
4345         while (1)
4346         {
4347                 /* Clear screen */
4348                 Term_clear();
4349
4350                 /* Ask for a choice */
4351 #ifdef JP
4352                 prt("[ ¥«¥é¡¼¤ÎÀßÄê ]", 2, 0);
4353 #else
4354                 prt("Interact with Colors", 2, 0);
4355 #endif
4356
4357
4358                 /* Give some choices */
4359 #ifdef JP
4360                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
4361 #else
4362                 prt("(1) Load a user pref file", 4, 5);
4363 #endif
4364
4365 #ifdef ALLOW_COLORS
4366 #ifdef JP
4367                 prt("(2) ¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 5, 5);
4368                 prt("(3) ¥«¥é¡¼¤ÎÀßÄê¤òÊѹ¹¤¹¤ë", 6, 5);
4369 #else
4370                 prt("(2) Dump colors", 5, 5);
4371                 prt("(3) Modify colors", 6, 5);
4372 #endif
4373
4374 #endif
4375
4376                 /* Prompt */
4377 #ifdef JP
4378                 prt("¥³¥Þ¥ó¥É: ", 8, 0);
4379 #else
4380                 prt("Command: ", 8, 0);
4381 #endif
4382
4383
4384                 /* Prompt */
4385                 i = inkey();
4386
4387                 /* Done */
4388                 if (i == ESCAPE) break;
4389
4390                 /* Load a 'pref' file */
4391                 if (i == '1')
4392                 {
4393                         /* Prompt */
4394 #ifdef JP
4395                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤·¤Þ¤¹", 8, 0);
4396 #else
4397                         prt("Command: Load a user pref file", 8, 0);
4398 #endif
4399
4400
4401                         /* Prompt */
4402 #ifdef JP
4403                         prt("¥Õ¥¡¥¤¥ë: ", 10, 0);
4404 #else
4405                         prt("File: ", 10, 0);
4406 #endif
4407
4408
4409                         /* Default file */
4410                         sprintf(tmp, "%s.prf", player_name);
4411
4412                         /* Query */
4413                         if (!askfor_aux(tmp, 70)) continue;
4414
4415                         /* Process the given filename */
4416                         (void)process_pref_file(tmp);
4417
4418                         /* Mega-Hack -- react to changes */
4419                         Term_xtra(TERM_XTRA_REACT, 0);
4420
4421                         /* Mega-Hack -- redraw */
4422                         Term_redraw();
4423                 }
4424
4425 #ifdef ALLOW_COLORS
4426
4427                 /* Dump colors */
4428                 else if (i == '2')
4429                 {
4430                         static cptr mark = "Colors";
4431
4432                         /* Prompt */
4433 #ifdef JP
4434                         prt("¥³¥Þ¥ó¥É: ¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 8, 0);
4435 #else
4436                         prt("Command: Dump colors", 8, 0);
4437 #endif
4438
4439
4440                         /* Prompt */
4441 #ifdef JP
4442                         prt("¥Õ¥¡¥¤¥ë: ", 10, 0);
4443 #else
4444                         prt("File: ", 10, 0);
4445 #endif
4446
4447
4448                         /* Default filename */
4449                         sprintf(tmp, "%s.prf", player_name);
4450
4451                         /* Get a filename */
4452                         if (!askfor_aux(tmp, 70)) continue;
4453
4454                         /* Build the filename */
4455                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
4456
4457                         /* Append to the file */
4458                         if (!open_auto_dump(buf, mark)) continue;
4459
4460                         /* Start dumping */
4461 #ifdef JP
4462                         auto_dump_printf("\n# ¥«¥é¡¼¤ÎÀßÄê\n\n");
4463 #else
4464                         auto_dump_printf("\n# Color redefinitions\n\n");
4465 #endif
4466
4467                         /* Dump colors */
4468                         for (i = 0; i < 256; i++)
4469                         {
4470                                 int kv = angband_color_table[i][0];
4471                                 int rv = angband_color_table[i][1];
4472                                 int gv = angband_color_table[i][2];
4473                                 int bv = angband_color_table[i][3];
4474
4475 #ifdef JP
4476                                 cptr name = "̤ÃÎ";
4477 #else
4478                                 cptr name = "unknown";
4479 #endif
4480
4481
4482                                 /* Skip non-entries */
4483                                 if (!kv && !rv && !gv && !bv) continue;
4484
4485                                 /* Extract the color name */
4486                                 if (i < 16) name = color_names[i];
4487
4488                                 /* Dump a comment */
4489 #ifdef JP
4490                                 auto_dump_printf("# ¥«¥é¡¼ '%s'\n", name);
4491 #else
4492                                 auto_dump_printf("# Color '%s'\n", name);
4493 #endif
4494
4495                                 /* Dump the monster attr/char info */
4496                                 auto_dump_printf("V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n",
4497                                         i, kv, rv, gv, bv);
4498                         }
4499
4500                         /* Close */
4501                         close_auto_dump();
4502
4503                         /* Message */
4504 #ifdef JP
4505                         msg_print("¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
4506 #else
4507                         msg_print("Dumped color redefinitions.");
4508 #endif
4509
4510                 }
4511
4512                 /* Edit colors */
4513                 else if (i == '3')
4514                 {
4515                         static byte a = 0;
4516
4517                         /* Prompt */
4518 #ifdef JP
4519                         prt("¥³¥Þ¥ó¥É: ¥«¥é¡¼¤ÎÀßÄê¤òÊѹ¹¤·¤Þ¤¹", 8, 0);
4520 #else
4521                         prt("Command: Modify colors", 8, 0);
4522 #endif
4523
4524
4525                         /* Hack -- query until done */
4526                         while (1)
4527                         {
4528                                 cptr name;
4529                                 byte j;
4530
4531                                 /* Clear */
4532                                 clear_from(10);
4533
4534                                 /* Exhibit the normal colors */
4535                                 for (j = 0; j < 16; j++)
4536                                 {
4537                                         /* Exhibit this color */
4538                                         Term_putstr(j*4, 20, -1, a, "###");
4539
4540                                         /* Exhibit all colors */
4541                                         Term_putstr(j*4, 22, -1, j, format("%3d", j));
4542                                 }
4543
4544                                 /* Describe the color */
4545 #ifdef JP
4546                                 name = ((a < 16) ? color_names[a] : "̤ÄêµÁ");
4547 #else
4548                                 name = ((a < 16) ? color_names[a] : "undefined");
4549 #endif
4550
4551
4552                                 /* Describe the color */
4553 #ifdef JP
4554                                 Term_putstr(5, 10, -1, TERM_WHITE,
4555                                             format("¥«¥é¡¼ = %d, Ì¾Á° = %s", a, name));
4556 #else
4557                                 Term_putstr(5, 10, -1, TERM_WHITE,
4558                                             format("Color = %d, Name = %s", a, name));
4559 #endif
4560
4561
4562                                 /* Label the Current values */
4563                                 Term_putstr(5, 12, -1, TERM_WHITE,
4564                                             format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x",
4565                                                    angband_color_table[a][0],
4566                                                    angband_color_table[a][1],
4567                                                    angband_color_table[a][2],
4568                                                    angband_color_table[a][3]));
4569
4570                                 /* Prompt */
4571 #ifdef JP
4572                                 Term_putstr(0, 14, -1, TERM_WHITE,
4573                                             "¥³¥Þ¥ó¥É (n/N/k/K/r/R/g/G/b/B): ");
4574 #else
4575                                 Term_putstr(0, 14, -1, TERM_WHITE,
4576                                             "Command (n/N/k/K/r/R/g/G/b/B): ");
4577 #endif
4578
4579
4580                                 /* Get a command */
4581                                 i = inkey();
4582
4583                                 /* All done */
4584                                 if (i == ESCAPE) break;
4585
4586                                 /* Analyze */
4587                                 if (i == 'n') a = (byte)(a + 1);
4588                                 if (i == 'N') a = (byte)(a - 1);
4589                                 if (i == 'k') angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
4590                                 if (i == 'K') angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
4591                                 if (i == 'r') angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
4592                                 if (i == 'R') angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
4593                                 if (i == 'g') angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
4594                                 if (i == 'G') angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
4595                                 if (i == 'b') angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
4596                                 if (i == 'B') angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
4597
4598                                 /* Hack -- react to changes */
4599                                 Term_xtra(TERM_XTRA_REACT, 0);
4600
4601                                 /* Hack -- redraw */
4602                                 Term_redraw();
4603                         }
4604                 }
4605
4606 #endif
4607
4608                 /* Unknown option */
4609                 else
4610                 {
4611                         bell();
4612                 }
4613
4614                 /* Flush messages */
4615                 msg_print(NULL);
4616         }
4617
4618
4619         /* Restore the screen */
4620         screen_load();
4621 }
4622
4623
4624 /*
4625  * Note something in the message recall
4626  */
4627 void do_cmd_note(void)
4628 {
4629         char buf[80];
4630
4631         /* Default */
4632         strcpy(buf, "");
4633
4634         /* Input */
4635 #ifdef JP
4636         if (!get_string("¥á¥â: ", buf, 60)) return;
4637 #else
4638         if (!get_string("Note: ", buf, 60)) return;
4639 #endif
4640
4641
4642         /* Ignore empty notes */
4643         if (!buf[0] || (buf[0] == ' ')) return;
4644
4645         /* Add the note to the message recall */
4646 #ifdef JP
4647         msg_format("¥á¥â: %s", buf);
4648 #else
4649         msg_format("Note: %s", buf);
4650 #endif
4651
4652 }
4653
4654
4655 /*
4656  * Mention the current version
4657  */
4658 void do_cmd_version(void)
4659 {
4660
4661         /* Silly message */
4662 #ifdef JP
4663         msg_format("ÊѶòÈÚÅÜ(Hengband) %d.%d.%d",
4664                     FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4665 #else
4666         msg_format("You are playing Hengband %d.%d.%d.",
4667                     FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4668 #endif
4669 }
4670
4671
4672
4673 /*
4674  * Array of feeling strings
4675  */
4676 static cptr do_cmd_feeling_text[11] =
4677 {
4678 #ifdef JP
4679         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4680 #else
4681         "Looks like any other level.",
4682 #endif
4683
4684 #ifdef JP
4685         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4686 #else
4687         "You feel there is something special about this level.",
4688 #endif
4689
4690 #ifdef JP
4691         "¶²¤í¤·¤¤»à¤Î¸¸¤¬ÌܤËÉ⤫¤Ó¡¢µ¤À䤷¤½¤¦¤Ë¤Ê¤Ã¤¿¡ª",
4692 #else
4693         "You nearly faint as horrible visions of death fill your mind!",
4694 #endif
4695
4696 #ifdef JP
4697         "¤³¤Î³¬¤Ï¤È¤Æ¤â´í¸±¤Ê¤è¤¦¤À¡£",
4698 #else
4699         "This level looks very dangerous.",
4700 #endif
4701
4702 #ifdef JP
4703         "¤È¤Æ¤â°­¤¤Í½´¶¤¬¤¹¤ë...",
4704 #else
4705         "You have a very bad feeling...",
4706 #endif
4707
4708 #ifdef JP
4709         "°­¤¤Í½´¶¤¬¤¹¤ë...",
4710 #else
4711         "You have a bad feeling...",
4712 #endif
4713
4714 #ifdef JP
4715         "²¿¤«¶ÛÄ¥¤¹¤ë¡£",
4716 #else
4717         "You feel nervous.",
4718 #endif
4719
4720 #ifdef JP
4721         "¾¯¤·ÉÔ±¿¤Êµ¤¤¬¤¹¤ë...",
4722 #else
4723         "You feel your luck is turning...",
4724 #endif
4725
4726 #ifdef JP
4727         "¤³¤Î¾ì½ê¤Ï¹¥¤­¤Ë¤Ê¤ì¤Ê¤¤¡£",
4728 #else
4729         "You don't like the look of this place.",
4730 #endif
4731
4732 #ifdef JP
4733         "¤³¤Î³¬¤Ï¤½¤ì¤Ê¤ê¤Ë°ÂÁ´¤Ê¤è¤¦¤À¡£",
4734 #else
4735         "This level looks reasonably safe.",
4736 #endif
4737
4738 #ifdef JP
4739         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4740 #else
4741         "What a boring place..."
4742 #endif
4743
4744 };
4745
4746 static cptr do_cmd_feeling_text_combat[11] =
4747 {
4748 #ifdef JP
4749         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4750 #else
4751         "Looks like any other level.",
4752 #endif
4753
4754 #ifdef JP
4755         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4756 #else
4757         "You feel there is something special about this level.",
4758 #endif
4759
4760 #ifdef JP
4761         "º£Ìë¤â¤Þ¤¿¡¢Ã¯¤«¤¬Ì¿¤òÍî¤È¤¹...",
4762 #else
4763         "You nearly faint as horrible visions of death fill your mind!",
4764 #endif
4765
4766 #ifdef JP
4767         "¤³¤Î³¬¤Ï¤È¤Æ¤â´í¸±¤Ê¤è¤¦¤À¡£",
4768 #else
4769         "This level looks very dangerous.",
4770 #endif
4771
4772 #ifdef JP
4773         "¤È¤Æ¤â°­¤¤Í½´¶¤¬¤¹¤ë...",
4774 #else
4775         "You have a very bad feeling...",
4776 #endif
4777
4778 #ifdef JP
4779         "°­¤¤Í½´¶¤¬¤¹¤ë...",
4780 #else
4781         "You have a bad feeling...",
4782 #endif
4783
4784 #ifdef JP
4785         "²¿¤«¶ÛÄ¥¤¹¤ë¡£",
4786 #else
4787         "You feel nervous.",
4788 #endif
4789
4790 #ifdef JP
4791         "¾¯¤·ÉÔ±¿¤Êµ¤¤¬¤¹¤ë...",
4792 #else
4793         "You feel your luck is turning...",
4794 #endif
4795
4796 #ifdef JP
4797         "¤³¤Î¾ì½ê¤Ï¹¥¤­¤Ë¤Ê¤ì¤Ê¤¤¡£",
4798 #else
4799         "You don't like the look of this place.",
4800 #endif
4801
4802 #ifdef JP
4803         "¤³¤Î³¬¤Ï¤½¤ì¤Ê¤ê¤Ë°ÂÁ´¤Ê¤è¤¦¤À¡£",
4804 #else
4805         "This level looks reasonably safe.",
4806 #endif
4807
4808 #ifdef JP
4809         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4810 #else
4811         "What a boring place..."
4812 #endif
4813
4814 };
4815
4816 static cptr do_cmd_feeling_text_lucky[11] =
4817 {
4818 #ifdef JP
4819         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4820         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4821         "¤³¤Î³¬¤Ï¤³¤Î¾å¤Ê¤¯ÁÇÀ²¤é¤·¤¤´¶¤¸¤¬¤¹¤ë¡£",
4822         "ÁÇÀ²¤é¤·¤¤´¶¤¸¤¬¤¹¤ë...",
4823         "¤È¤Æ¤âÎɤ¤´¶¤¸¤¬¤¹¤ë...",
4824         "Îɤ¤´¶¤¸¤¬¤¹¤ë...",
4825         "¤Á¤ç¤Ã¤È¹¬±¿¤Ê´¶¤¸¤¬¤¹¤ë...",
4826         "¿¾¯¤Ï±¿¤¬¸þ¤¤¤Æ¤­¤¿¤«...",
4827         "¸«¤¿´¶¤¸°­¤¯¤Ï¤Ê¤¤...",
4828         "Á´Á³ÂÌÌܤȤ¤¤¦¤³¤È¤Ï¤Ê¤¤¤¬...",
4829         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4830 #else
4831         "Looks like any other level.",
4832         "You feel there is something special about this level.",
4833         "You have a superb feeling about this level.",
4834         "You have an excellent feeling...",
4835         "You have a very good feeling...",
4836         "You have a good feeling...",
4837         "You feel strangely lucky...",
4838         "You feel your luck is turning...",
4839         "You like the look of this place...",
4840         "This level can't be all bad...",
4841         "What a boring place..."
4842 #endif
4843 };
4844
4845
4846 /*
4847  * Note that "feeling" is set to zero unless some time has passed.
4848  * Note that this is done when the level is GENERATED, not entered.
4849  */
4850 void do_cmd_feeling(void)
4851 {
4852         /* Verify the feeling */
4853         if (feeling > 10) feeling = 10;
4854
4855         /* No useful feeling in quests */
4856         if (p_ptr->inside_quest && !random_quest_number(dun_level))
4857         {
4858 #ifdef JP
4859                 msg_print("ŵ·¿Åª¤Ê¥¯¥¨¥¹¥È¤Î¥À¥ó¥¸¥ç¥ó¤Î¤è¤¦¤À¡£");
4860 #else
4861                 msg_print("Looks like a typical quest level.");
4862 #endif
4863
4864                 return;
4865         }
4866
4867         /* No useful feeling in town */
4868         else if (p_ptr->town_num && !dun_level)
4869         {
4870 #ifdef JP
4871                 if (!strcmp(town[p_ptr->town_num].name, "¹ÓÌî"))
4872 #else
4873                 if (!strcmp(town[p_ptr->town_num].name, "wilderness"))
4874 #endif
4875                 {
4876 #ifdef JP
4877                         msg_print("²¿¤«¤¢¤ê¤½¤¦¤Ê¹ÓÌî¤Î¤è¤¦¤À¡£");
4878 #else
4879                         msg_print("Looks like a strange wilderness.");
4880 #endif
4881
4882                         return;
4883                 }
4884                 else
4885                 {
4886 #ifdef JP
4887                         msg_print("ŵ·¿Åª¤ÊÄ®¤Î¤è¤¦¤À¡£");
4888 #else
4889                         msg_print("Looks like a typical town.");
4890 #endif
4891
4892                         return;
4893                 }
4894         }
4895
4896         /* No useful feeling in the wilderness */
4897         else if (!dun_level)
4898         {
4899 #ifdef JP
4900                 msg_print("ŵ·¿Åª¤Ê¹ÓÌî¤Î¤è¤¦¤À¡£");
4901 #else
4902                 msg_print("Looks like a typical wilderness.");
4903 #endif
4904
4905                 return;
4906         }
4907
4908         /* Display the feeling */
4909         if (turn - old_turn >= (150 - dun_level)*TURNS_PER_TICK || cheat_xtra)
4910         {
4911                 if (p_ptr->muta3 & MUT3_GOOD_LUCK) msg_print(do_cmd_feeling_text_lucky[feeling]);
4912                 else {
4913                                         if((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON)){
4914                                                 msg_print(do_cmd_feeling_text_combat[feeling]);
4915                                         }else
4916                                                 msg_print(do_cmd_feeling_text[feeling]);
4917                                 }
4918         }
4919         else
4920         {
4921                 msg_print(do_cmd_feeling_text[0]);
4922         }
4923 }
4924
4925
4926
4927 /*
4928  * Description of each monster group.
4929  */
4930 static cptr monster_group_text[] = 
4931 {
4932 #ifdef JP
4933         "¥æ¥Ë¡¼¥¯",     /* "Uniques" */
4934         "¥¢¥ê",
4935         "¥³¥¦¥â¥ê",
4936         "¥à¥«¥Ç",
4937         "¥É¥é¥´¥ó",
4938         "ÌܶÌ",
4939         "¥Í¥³",
4940         "¥´¡¼¥ì¥à",
4941         "ɸ½à¿Í´Ö·¿À¸Êª",
4942         "¥Ù¥È¥Ù¥È",
4943         "¥¼¥ê¡¼",
4944         "¥³¥Ü¥ë¥É",
4945         "¿åÀ³À¸Êª",
4946         "¥â¥ë¥É",
4947         "¥Ê¡¼¥¬",
4948         "¥ª¡¼¥¯",
4949         "¿Í´Ö",
4950         "»Í­½Ã",
4951         "¥Í¥º¥ß",
4952         "¥¹¥±¥ë¥È¥ó",
4953         "¥Ç¡¼¥â¥ó",
4954         "¥Ü¥ë¥Æ¥Ã¥¯¥¹",
4955         "¥¤¥â¥à¥·/Âç·²",
4956         /* "unused", */
4957         "¥¤¡¼¥¯",
4958         "¥¾¥ó¥Ó/¥ß¥¤¥é",
4959         "Å·»È",
4960         "Ļ",
4961         "¸¤",
4962         /* "¸ÅÂå¥É¥é¥´¥ó/¥ï¥¤¥¢¡¼¥à", */
4963         "¥¨¥ì¥á¥ó¥¿¥ë",
4964         "¥È¥ó¥Ü",
4965         "¥´¡¼¥¹¥È",
4966         "»¨¼ï",
4967         "º«Ãî",
4968         "¥Ø¥Ó",
4969         "¥­¥é¡¼¡¦¥Ó¡¼¥È¥ë",
4970         "¥ê¥Ã¥Á",
4971         "¿¼ó¤Îà¨ÃîÎà",
4972         "Ææ¤ÎÀ¸Êª",
4973         "¥ª¡¼¥¬",
4974         "µðÂç¿Í´Ö·¿À¸Êª",
4975         "¥¯¥¤¥ë¥¹¥ë¥°",
4976         "à¨ÃîÎà/ξÀ¸Îà",
4977         "ÃØéá/¥µ¥½¥ê/¥À¥Ë",
4978         "¥È¥í¥ë",
4979         /* "¾åµé¥Ç¡¼¥â¥ó", */
4980         "¥Ð¥ó¥Ñ¥¤¥¢",
4981         "¥ï¥¤¥È/¥ì¥¤¥¹/Åù",
4982         "¥¾¡¼¥ó/¥¶¥ì¥ó/Åù",
4983         "¥¤¥¨¥Æ¥£",
4984         "¥Ï¥¦¥ó¥É",
4985         "¥ß¥ß¥Ã¥¯",
4986         "ÊÉ/¿¢Êª/µ¤ÂÎ",
4987         "¤ª¤Ð¤±¥­¥Î¥³",
4988         "µåÂÎ",
4989 #else
4990         "Uniques",
4991         "Ant",
4992         "Bat",
4993         "Centipede",
4994         "Dragon",
4995         "Floating Eye",
4996         "Feline",
4997         "Golem",
4998         "Hobbit/Elf/Dwarf",
4999         "Icky Thing",
5000         "Jelly",
5001         "Kobold",
5002         "Aquatic monster",
5003         "Mold",
5004         "Naga",
5005         "Orc",
5006         "Person/Human",
5007         "Quadruped",
5008         "Rodent",
5009         "Skeleton",
5010         "Demon",
5011         "Vortex",
5012         "Worm/Worm-Mass",
5013         /* "unused", */
5014         "Yeek",
5015         "Zombie/Mummy",
5016         "Angel",
5017         "Bird",
5018         "Canine",
5019         /* "Ancient Dragon/Wyrm", */
5020         "Elemental",
5021         "Dragon Fly",
5022         "Ghost",
5023         "Hybrid",
5024         "Insect",
5025         "Snake",
5026         "Killer Beetle",
5027         "Lich",
5028         "Multi-Headed Reptile",
5029         "Mystery Living",
5030         "Ogre",
5031         "Giant Humanoid",
5032         "Quylthulg",
5033         "Reptile/Amphibian",
5034         "Spider/Scorpion/Tick",
5035         "Troll",
5036         /* "Major Demon", */
5037         "Vampire",
5038         "Wight/Wraith/etc",
5039         "Xorn/Xaren/etc",
5040         "Yeti",
5041         "Zephyr Hound",
5042         "Mimic",
5043         "Wall/Plant/Gas",
5044         "Mushroom patch",
5045         "Ball",
5046 #endif
5047         NULL
5048 };
5049
5050
5051 /*
5052  * Symbols of monsters in each group. Note the "Uniques" group
5053  * is handled differently.
5054  */
5055 static cptr monster_group_char[] = 
5056 {
5057         (char *) -1L,
5058         "a",
5059         "b",
5060         "c",
5061         "dD",
5062         "e",
5063         "f",
5064         "g",
5065         "h",
5066         "i",
5067         "j",
5068         "k",
5069         "l",
5070         "m",
5071         "n",
5072         "o",
5073         "pt",
5074         "q",
5075         "r",
5076         "s",
5077         "uU",
5078         "v",
5079         "w",
5080         /* "x", */
5081         "y",
5082         "z",
5083         "A",
5084         "B",
5085         "C",
5086         /* "D", */
5087         "E",
5088         "F",
5089         "G",
5090         "H",
5091         "I",
5092         "J",
5093         "K",
5094         "L",
5095         "M",
5096         "N",
5097         "O",
5098         "P",
5099         "Q",
5100         "R",
5101         "S",
5102         "T",
5103         /* "U", */
5104         "V",
5105         "W",
5106         "X",
5107         "Y",
5108         "Z",
5109         "$!?=&`.|/\\~[]()>",
5110         "#",
5111         ",",
5112         "*",
5113         NULL
5114 };
5115
5116
5117 /*
5118  * hook function to sort monsters by level
5119  */
5120 static bool ang_sort_comp_monster_level(vptr u, vptr v, int a, int b)
5121 {
5122         u16b *who = (u16b*)(u);
5123
5124         int w1 = who[a];
5125         int w2 = who[b];
5126
5127         monster_race *r_ptr1 = &r_info[w1];
5128         monster_race *r_ptr2 = &r_info[w2];
5129
5130         /* Unused */
5131         (void)v;
5132
5133         if (r_ptr2->level > r_ptr1->level) return TRUE;
5134         if (r_ptr1->level > r_ptr2->level) return FALSE;
5135
5136         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return TRUE;
5137         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return FALSE;
5138         return w1 <= w2;
5139 }
5140
5141 /*
5142  * Build a list of monster indexes in the given group. Return the number
5143  * of monsters in the group.
5144  *
5145  * mode & 0x01 : check for non-empty group
5146  * mode & 0x02 : cheat?
5147  */
5148 static int collect_monsters(int grp_cur, s16b mon_idx[], byte mode)
5149 {
5150         int i, mon_cnt = 0;
5151         int dummy_why;
5152
5153         /* Get a list of x_char in this group */
5154         cptr group_char = monster_group_char[grp_cur];
5155
5156         /* XXX Hack -- Check if this is the "Uniques" group */
5157         bool grp_unique = (monster_group_char[grp_cur] == (char *) -1L);
5158
5159         /* Check every race */
5160         for (i = 0; i < max_r_idx; i++)
5161         {
5162                 /* Access the race */
5163                 monster_race *r_ptr = &r_info[i];
5164
5165                 /* Skip empty race */
5166                 if (!r_ptr->name) continue ;
5167
5168                 /* Require known monsters */
5169                 if (!(mode & 0x02) && !cheat_know && !r_ptr->r_sights ) continue;
5170
5171                 if (grp_unique && !(r_ptr->flags1 & RF1_UNIQUE)) continue;
5172
5173                 /* Check for race in the group */
5174                 if (grp_unique || strchr(group_char, r_ptr->d_char))
5175                 {
5176                         /* Add the race */
5177                         mon_idx[mon_cnt++] = i;
5178
5179                         /* XXX Hack -- Just checking for non-empty group */
5180                         if (mode & 0x01) break;
5181                 }
5182         }
5183
5184         /* Terminate the list */
5185         mon_idx[mon_cnt] = 0;
5186
5187         /* Select the sort method */
5188         ang_sort_comp = ang_sort_comp_monster_level;
5189         ang_sort_swap = ang_sort_swap_hook;
5190
5191         /* Sort by monster level */
5192         ang_sort(mon_idx, &dummy_why, mon_cnt);
5193
5194         /* Return the number of races */
5195         return mon_cnt;
5196 }
5197
5198
5199 /*
5200  * Description of each monster group.
5201  */
5202 static cptr object_group_text[] = 
5203 {
5204 #ifdef JP
5205         "¥­¥Î¥³",       /* "Mushrooms" */
5206         "Ìô",           /* "Potions" */
5207         "Ìý¤Ä¤Ü",       /* "Flasks" */
5208         "´¬Êª",         /* "Scrolls" */
5209         "»ØÎØ",         /* "Rings" */
5210         "¥¢¥ß¥å¥ì¥Ã¥È", /* "Amulets" */
5211         "ū",           /* "Whistle" */
5212         "¸÷¸»",         /* "Lanterns" */
5213         "ËâË¡ËÀ",       /* "Wands" */
5214         "¾ó",           /* "Staffs" */
5215         "¥í¥Ã¥É",       /* "Rods" */
5216         "¥«¡¼¥É",       /* "Cards" */
5217         "¥­¥ã¥×¥Á¥ã¡¼¡¦¥Ü¡¼¥ë",
5218         "ÍÓÈé»æ",       
5219         "¤¯¤µ¤Ó",
5220         "Ȣ",
5221         "¿Í·Á",
5222         "Áü",
5223         "¥´¥ß",
5224         "¶õ¤Î¥Ó¥ó",
5225         "¹ü",
5226         "Åá·õÎà",       /* "Swords" */
5227         "Æß´ï",         /* "Blunt Weapons" */
5228         "ĹÊÁÉð´ï",     /* "Polearms" */
5229         "ºÎ·¡Æ»¶ñ",     /* "Diggers" */
5230         "Èô¤ÓÆ»¶ñ",     /* "Bows" */
5231         "ÃÆ",
5232         "Ìð",
5233         "¥Ü¥ë¥È",
5234         "·ÚÁõ³»",       /* "Soft Armor" */
5235         "½ÅÁõ³»",       /* "Hard Armor" */
5236         "¥É¥é¥´¥ó³»",   /* "Dragon Armor" */
5237         "½â",   /* "Shields" */
5238         "¥¯¥í¡¼¥¯",     /* "Cloaks" */
5239         "äƼê", /* "Gloves" */
5240         "¥Ø¥ë¥á¥Ã¥È",   /* "Helms" */
5241         "´§",   /* "Crowns" */
5242         "¥Ö¡¼¥Ä",       /* "Boots" */
5243         "ËâË¡½ñ",
5244 #else
5245         "Mushrooms",
5246         "Potions",
5247         "Flasks",
5248         "Scrolls",
5249         "Rings",
5250         "Amulets",
5251         "Whistle",
5252         "Lanterns",
5253         "Wands",
5254         "Staves",
5255         "Rods",
5256         "Cards",
5257         "Capture Balls",
5258         "Parchments",
5259         "Spikes",
5260         "Boxs",
5261         "Figurines",
5262         "Statues",
5263         "Junks",
5264         "Bottles",
5265         "Skeletons",
5266         "Swords",
5267         "Blunt Weapons",
5268         "Polearms",
5269         "Diggers",
5270         "Bows",
5271         "Shots",
5272         "Arrows",
5273         "Bolts",
5274         "Soft Armor",
5275         "Hard Armor",
5276         "Dragon Armor",
5277         "Shields",
5278         "Cloaks",
5279         "Gloves",
5280         "Helms",
5281         "Crowns",
5282         "Boots",
5283         "Spellbooks",
5284 #endif
5285         NULL
5286 };
5287
5288
5289 /*
5290  * TVALs of items in each group
5291  */
5292 static byte object_group_tval[] = 
5293 {
5294         TV_FOOD,
5295         TV_POTION,
5296         TV_FLASK,
5297         TV_SCROLL,
5298         TV_RING,
5299         TV_AMULET,
5300         TV_WHISTLE,
5301         TV_LITE,
5302         TV_WAND,
5303         TV_STAFF,
5304         TV_ROD,
5305         TV_CARD,
5306         TV_CAPTURE,
5307         TV_PARCHMENT,
5308         TV_SPIKE,
5309         TV_CHEST,
5310         TV_FIGURINE,
5311         TV_STATUE,
5312         TV_JUNK,
5313         TV_BOTTLE,
5314         TV_SKELETON,
5315         TV_SWORD,
5316         TV_HAFTED,
5317         TV_POLEARM,
5318         TV_DIGGING,
5319         TV_BOW,
5320         TV_SHOT,
5321         TV_ARROW,
5322         TV_BOLT,
5323         TV_SOFT_ARMOR,
5324         TV_HARD_ARMOR,
5325         TV_DRAG_ARMOR,
5326         TV_SHIELD,
5327         TV_CLOAK,
5328         TV_GLOVES,
5329         TV_HELM,
5330         TV_CROWN,
5331         TV_BOOTS,
5332         TV_LIFE_BOOK, /* Hack -- all spellbooks */
5333         0
5334 };
5335
5336
5337 /*
5338  * Build a list of monster indexes in the given group. Return the number
5339  * of monsters in the group.
5340  */
5341 static int collect_objects(int grp_cur, int object_idx[])
5342 {
5343         int i, j, k, object_cnt = 0;
5344
5345         /* Get a list of x_char in this group */
5346         byte group_tval = object_group_tval[grp_cur];
5347
5348         /* Check every object */
5349         for (i = 0; i < max_k_idx; i++)
5350         {
5351                 /* Access the race */
5352                 object_kind *k_ptr = &k_info[i];
5353
5354                 /* Skip empty objects */
5355                 if (!k_ptr->name) continue;
5356
5357                 /* Skip non-flavoured objects */
5358                 if (!k_ptr->flavor && !p_ptr->wizard) continue;
5359
5360                 /* Skip items with no distribution (special artifacts) */
5361                 for (j = 0, k = 0; j < 4; j++) k += k_ptr->chance[j];
5362                 if (!(k))  continue; 
5363
5364                 /* Require objects ever seen*/
5365                 if (!k_ptr->aware && !p_ptr->wizard) continue;
5366
5367                 /* Check for race in the group */
5368                 if (TV_LIFE_BOOK == group_tval)
5369                 {
5370                         /* Hack -- All spell books */
5371                         if (TV_LIFE_BOOK <= k_ptr->tval && k_ptr->tval <= TV_HISSATSU_BOOK)
5372                         {
5373                                 /* Add the race */
5374                                 object_idx[object_cnt++] = i;
5375                         }
5376                 }
5377                 else if (k_ptr->tval == group_tval)
5378                 {
5379                         /* Add the race */
5380                         object_idx[object_cnt++] = i;
5381                 }
5382         }
5383
5384         /* Terminate the list */
5385         object_idx[object_cnt] = 0;
5386
5387         /* Return the number of races */
5388         return object_cnt;
5389 }
5390
5391
5392 /*
5393  * Description of each feature group.
5394  */
5395 static cptr feature_group_text[] = 
5396 {
5397         "terrains",
5398         NULL
5399 };
5400
5401
5402 /*
5403  * Build a list of feature indexes in the given group. Return the number
5404  * of features in the group.
5405  */
5406 static int collect_features(int grp_cur, int *feat_idx)
5407 {
5408         int i, feat_cnt = 0;
5409
5410         /* Unused;  There is a single group. */
5411         (void)grp_cur;
5412
5413         /* Check every feature */
5414         for (i = 1; i < max_f_idx; i++)
5415         {
5416                 /* Access the index */
5417                 feature_type *f_ptr = &f_info[i];
5418
5419                 /* Skip empty index */
5420                 if (!f_ptr->name) continue;
5421
5422                 /* Skip mimiccing features */
5423                 if (f_ptr->mimic != i) continue;
5424
5425                 /* Add the index */
5426                 feat_idx[feat_cnt++] = i;
5427         }
5428
5429         /* Terminate the list */
5430         feat_idx[feat_cnt] = 0;
5431
5432         /* Return the number of races */
5433         return feat_cnt;
5434 }
5435
5436
5437 #if 0
5438 /*
5439  * Build a list of monster indexes in the given group. Return the number
5440  * of monsters in the group.
5441  */
5442 static int collect_artifacts(int grp_cur, int object_idx[])
5443 {
5444         int i, object_cnt = 0;
5445
5446         /* Get a list of x_char in this group */
5447         byte group_tval = object_group_tval[grp_cur];
5448
5449         /* Check every object */
5450         for (i = 0; i < max_a_idx; i++)
5451         {
5452                 /* Access the artifact */
5453                 artifact_type *a_ptr = &a_info[i];
5454
5455                 /* Skip empty artifacts */
5456                 if (!a_ptr->name) continue;
5457
5458                 /* Skip "uncreated" artifacts */
5459                 if (!a_ptr->cur_num) continue;
5460
5461                 /* Check for race in the group */
5462                 if (a_ptr->tval == group_tval)
5463                 {
5464                         /* Add the race */
5465                         object_idx[object_cnt++] = i;
5466                 }
5467         }
5468
5469         /* Terminate the list */
5470         object_idx[object_cnt] = 0;
5471
5472         /* Return the number of races */
5473         return object_cnt;
5474 }
5475 #endif /* 0 */
5476
5477
5478 /*
5479  * Encode the screen colors
5480  */
5481 static char hack[17] = "dwsorgbuDWvyRGBU";
5482
5483
5484 static errr photo_fgets(FILE *fff, char *buf, huge n)
5485 {
5486         huge i = 0;
5487
5488         char *s;
5489
5490         char tmp[1024];
5491
5492         /* Read a line */
5493         if (fgets(tmp, 1024, fff))
5494         {
5495                 /* Convert weirdness */
5496                 for (s = tmp; *s; s++)
5497                 {
5498                         /* Handle newline */
5499                         if (*s == '\n')
5500                         {
5501                                 /* Terminate */
5502                                 buf[i] = '\0';
5503
5504                                 /* Success */
5505                                 return (0);
5506                         }
5507
5508                         /* Handle tabs */
5509                         else if (*s == '\t')
5510                         {
5511                                 /* Hack -- require room */
5512                                 if (i + 8 >= n) break;
5513
5514                                 /* Append a space */
5515                                 buf[i++] = ' ';
5516
5517                                 /* Append some more spaces */
5518                                 while (!(i % 8)) buf[i++] = ' ';
5519                         }
5520
5521 #ifdef JP
5522                         else if (iskanji(*s))
5523                         {
5524                                 if (!s[1]) break;
5525                                 buf[i++] = *s++;
5526                                 buf[i++] = *s;
5527                         }
5528 # ifndef EUC
5529         /* È¾³Ñ¤«¤Ê¤ËÂбþ */
5530                         else if ((((int)*s & 0xff) > 0xa1) && (((int)*s & 0xff ) < 0xdf))
5531                         {
5532                                 buf[i++] = *s;
5533                                 if (i >= n) break;
5534                         }
5535 # endif
5536 #endif
5537                         /* Handle printables */
5538                         else
5539                         {
5540                                 /* Copy */
5541                                 buf[i++] = *s;
5542
5543                                 /* Check length */
5544                                 if (i >= n) break;
5545                         }
5546                 }
5547         }
5548
5549         /* Nothing */
5550         buf[0] = '\0';
5551
5552         /* Failure */
5553         return (1);
5554 }
5555
5556
5557 /*
5558  * Hack -- load a screen dump from a file
5559  */
5560 void do_cmd_load_screen(void)
5561 {
5562         int i, y, x;
5563
5564         byte a = 0;
5565         char c = ' ';
5566
5567         bool okay = TRUE;
5568
5569         FILE *fff;
5570
5571         char buf[1024];
5572
5573         int wid, hgt;
5574
5575         Term_get_size(&wid, &hgt);
5576
5577         /* Build the filename */
5578         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
5579
5580         /* Append to the file */
5581         fff = my_fopen(buf, "r");
5582
5583         /* Oops */
5584         if (!fff) {
5585 #ifdef JP
5586                 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
5587 #else
5588                 msg_format("Failed to open %s.", buf);
5589 #endif
5590                 msg_print(NULL);
5591                 return;
5592         }
5593
5594
5595         /* Save the screen */
5596         screen_save();
5597
5598         /* Clear the screen */
5599         Term_clear();
5600
5601
5602         /* Load the screen */
5603         for (y = 0; okay && (y < hgt); y++)
5604         {
5605                 /* Get a line of data */
5606                 if (photo_fgets(fff, buf, 1024)) okay = FALSE;
5607
5608                 /* Show each row */
5609                 for (x = 0; x < wid - 1; x++)
5610                 {
5611                         /* Put the attr/char */
5612                         Term_draw(x, y, TERM_WHITE, buf[x]);
5613                 }
5614         }
5615
5616         /* Get the blank line */
5617         if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
5618
5619
5620         /* Dump the screen */
5621         for (y = 0; okay && (y < hgt); y++)
5622         {
5623                 /* Get a line of data */
5624                 if (photo_fgets(fff, buf, 1024)) okay = FALSE;
5625
5626                 /* Dump each row */
5627                 for (x = 0; x < wid - 1; x++)
5628                 {
5629                         /* Get the attr/char */
5630                         (void)(Term_what(x, y, &a, &c));
5631
5632                         /* Look up the attr */
5633                         for (i = 0; i < 16; i++)
5634                         {
5635                                 /* Use attr matches */
5636                                 if (hack[i] == buf[x]) a = i;
5637                         }
5638
5639                         /* Put the attr/char */
5640                         Term_draw(x, y, a, c);
5641                 }
5642         }
5643
5644
5645         /* Get the blank line */
5646         if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
5647
5648
5649         /* Close it */
5650         my_fclose(fff);
5651
5652
5653         /* Message */
5654 #ifdef JP
5655         prt("¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤µ¤ì¤¿²èÌÌ(µ­Ç°»£±Æ)¤ò¥í¡¼¥É¤·¤Þ¤·¤¿¡£", 0, 0);
5656 #else
5657         msg_print("Screen dump loaded.");
5658 #endif
5659
5660         flush();
5661         inkey();
5662
5663
5664         /* Restore the screen */
5665         screen_load();
5666 }
5667
5668
5669
5670
5671 cptr inven_res_label = 
5672 #ifdef JP
5673  "                               »ÀÅŲÐÎäÆǸ÷°ÇÇ˹ì¹ö°øÆÙÎô ÌÕÉÝÍðáãÆ©Ì¿´¶¾ÃÉüÉâ";
5674 #else
5675  "                               AcElFiCoPoLiDkShSoNtNxCaDi BlFeCfFaSeHlEpSdRgLv";
5676 #endif
5677
5678 /* XTRA HACK RESLIST */
5679 static void do_cmd_knowledge_inven_aux(FILE *fff, object_type *o_ptr, 
5680                                        int *j, byte tval, char *where)
5681 {
5682   char o_name[MAX_NLEN];
5683   u32b flgs[TR_FLAG_SIZE];
5684
5685   if (!o_ptr->k_idx)return;
5686   if (o_ptr->tval != tval)return;
5687
5688        /* 
5689         * HACK:Ring of Lordly protection and Dragon shield/helm
5690         * have random resistances.
5691         */
5692   if ( ((o_ptr->tval >= TV_BOW && o_ptr->tval<= TV_DRAG_ARMOR && o_ptr->name2)
5693        || (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_LORDLY) 
5694        || (o_ptr->tval == TV_SHIELD && o_ptr->sval == SV_DRAGON_SHIELD) 
5695        || (o_ptr->tval == TV_HELM && o_ptr->sval == SV_DRAGON_HELM) 
5696        || (o_ptr->tval == TV_GLOVES && o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) 
5697        || (o_ptr->tval == TV_BOOTS && o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) 
5698        || o_ptr->art_name || o_ptr->name1) && object_known_p(o_ptr))
5699     {
5700       int i = 0;
5701       object_desc(o_name, o_ptr, TRUE, 0);
5702
5703       while ( o_name[i] && i < 26 ){
5704 #ifdef JP
5705         if (iskanji(o_name[i])) i++;
5706 #endif
5707         i++;
5708       }
5709       if(i<28) while(i<28){o_name[i]=' ';i++;}
5710       o_name[i]=0;
5711       
5712       fprintf(fff,"%s %s", where, o_name);
5713
5714       if (!(o_ptr->ident & (IDENT_MENTAL))) 
5715         {
5716 #ifdef JP
5717           fprintf(fff, "-------ÉÔÌÀ--------------- -------ÉÔÌÀ---------\n");
5718 #else
5719           fprintf(fff, "-------unknown------------ -------unknown------\n");
5720 #endif
5721         }
5722       else {
5723         object_flags_known(o_ptr, flgs);
5724       
5725 #ifdef JP
5726         if (have_flag(flgs, TR_IM_ACID)) fprintf(fff,"¡ö");
5727         else if (have_flag(flgs, TR_RES_ACID)) fprintf(fff,"¡Ü");
5728         else fprintf(fff,"¡¦");
5729
5730         if (have_flag(flgs, TR_IM_ELEC)) fprintf(fff,"¡ö");
5731         else if (have_flag(flgs, TR_RES_ELEC)) fprintf(fff,"¡Ü");
5732         else fprintf(fff,"¡¦");
5733
5734         if (have_flag(flgs, TR_IM_FIRE)) fprintf(fff,"¡ö");
5735         else if (have_flag(flgs, TR_RES_FIRE)) fprintf(fff,"¡Ü");
5736         else fprintf(fff,"¡¦");
5737
5738         if (have_flag(flgs, TR_IM_COLD)) fprintf(fff,"¡ö");
5739         else if (have_flag(flgs, TR_RES_COLD)) fprintf(fff,"¡Ü");
5740         else fprintf(fff,"¡¦");
5741         
5742         if (have_flag(flgs, TR_RES_POIS)) fprintf(fff,"¡Ü");
5743         else fprintf(fff,"¡¦");
5744         
5745         if (have_flag(flgs, TR_RES_LITE)) fprintf(fff,"¡Ü");
5746         else fprintf(fff,"¡¦");
5747         
5748         if (have_flag(flgs, TR_RES_DARK)) fprintf(fff,"¡Ü");
5749         else fprintf(fff,"¡¦");
5750         
5751         if (have_flag(flgs, TR_RES_SHARDS)) fprintf(fff,"¡Ü");
5752         else fprintf(fff,"¡¦");
5753         
5754         if (have_flag(flgs, TR_RES_SOUND)) fprintf(fff,"¡Ü");
5755         else fprintf(fff,"¡¦");
5756         
5757         if (have_flag(flgs, TR_RES_NETHER)) fprintf(fff,"¡Ü");
5758         else fprintf(fff,"¡¦");
5759         
5760         if (have_flag(flgs, TR_RES_NEXUS)) fprintf(fff,"¡Ü");
5761         else fprintf(fff,"¡¦");
5762         
5763         if (have_flag(flgs, TR_RES_CHAOS)) fprintf(fff,"¡Ü");
5764         else fprintf(fff,"¡¦");
5765         
5766         if (have_flag(flgs, TR_RES_DISEN)) fprintf(fff,"¡Ü");
5767         else fprintf(fff,"¡¦");
5768         
5769         fprintf(fff," ");
5770         
5771         if (have_flag(flgs, TR_RES_BLIND)) fprintf(fff,"¡Ü");
5772         else fprintf(fff,"¡¦");
5773         
5774         if (have_flag(flgs, TR_RES_FEAR)) fprintf(fff,"¡Ü");
5775         else fprintf(fff,"¡¦");
5776         
5777         if (have_flag(flgs, TR_RES_CONF)) fprintf(fff,"¡Ü");
5778         else fprintf(fff,"¡¦");
5779         
5780         if (have_flag(flgs, TR_FREE_ACT)) fprintf(fff,"¡Ü");
5781         else fprintf(fff,"¡¦");
5782         
5783         if (have_flag(flgs, TR_SEE_INVIS)) fprintf(fff,"¡Ü");
5784         else fprintf(fff,"¡¦");
5785         
5786         if (have_flag(flgs, TR_HOLD_LIFE)) fprintf(fff,"¡Ü");
5787         else fprintf(fff,"¡¦");
5788
5789         if (have_flag(flgs, TR_TELEPATHY)) fprintf(fff,"¡Ü");
5790         else fprintf(fff,"¡¦");
5791
5792         if (have_flag(flgs, TR_SLOW_DIGEST)) fprintf(fff,"¡Ü");
5793         else fprintf(fff,"¡¦");
5794
5795
5796         if (have_flag(flgs, TR_REGEN)) fprintf(fff,"¡Ü");
5797         else fprintf(fff,"¡¦");
5798
5799         if (have_flag(flgs, TR_FEATHER)) fprintf(fff,"¡Ü");
5800         else fprintf(fff,"¡¦");
5801 #else
5802         if (have_flag(flgs, TR_IM_ACID)) fprintf(fff,"* ");
5803         else if (have_flag(flgs, TR_RES_ACID)) fprintf(fff,"+ ");
5804         else fprintf(fff,". ");
5805
5806         if (have_flag(flgs, TR_IM_ELEC)) fprintf(fff,"* ");
5807         else if (have_flag(flgs, TR_RES_ELEC)) fprintf(fff,"+ ");
5808         else fprintf(fff,". ");
5809
5810         if (have_flag(flgs, TR_IM_FIRE)) fprintf(fff,"* ");
5811         else if (have_flag(flgs, TR_RES_FIRE)) fprintf(fff,"+ ");
5812         else fprintf(fff,". ");
5813
5814         if (have_flag(flgs, TR_IM_COLD)) fprintf(fff,"* ");
5815         else if (have_flag(flgs, TR_RES_COLD)) fprintf(fff,"+ ");
5816         else fprintf(fff,". ");
5817         
5818         if (have_flag(flgs, TR_RES_POIS)) fprintf(fff,"+ ");
5819         else fprintf(fff,". ");
5820         
5821         if (have_flag(flgs, TR_RES_LITE)) fprintf(fff,"+ ");
5822         else fprintf(fff,". ");
5823         
5824         if (have_flag(flgs, TR_RES_DARK)) fprintf(fff,"+ ");
5825         else fprintf(fff,". ");
5826         
5827         if (have_flag(flgs, TR_RES_SHARDS)) fprintf(fff,"+ ");
5828         else fprintf(fff,". ");
5829         
5830         if (have_flag(flgs, TR_RES_SOUND)) fprintf(fff,"+ ");
5831         else fprintf(fff,". ");
5832         
5833         if (have_flag(flgs, TR_RES_NETHER)) fprintf(fff,"+ ");
5834         else fprintf(fff,". ");
5835         
5836         if (have_flag(flgs, TR_RES_NEXUS)) fprintf(fff,"+ ");
5837         else fprintf(fff,". ");
5838         
5839         if (have_flag(flgs, TR_RES_CHAOS)) fprintf(fff,"+ ");
5840         else fprintf(fff,". ");
5841         
5842         if (have_flag(flgs, TR_RES_DISEN)) fprintf(fff,"+ ");
5843         else fprintf(fff,". ");
5844         
5845         fprintf(fff," ");
5846         
5847         if (have_flag(flgs, TR_RES_BLIND)) fprintf(fff,"+ ");
5848         else fprintf(fff,". ");
5849         
5850         if (have_flag(flgs, TR_RES_FEAR)) fprintf(fff,"+ ");
5851         else fprintf(fff,". ");
5852         
5853         if (have_flag(flgs, TR_RES_CONF)) fprintf(fff,"+ ");
5854         else fprintf(fff,". ");
5855         
5856         if (have_flag(flgs, TR_FREE_ACT)) fprintf(fff,"+ ");
5857         else fprintf(fff,". ");
5858         
5859         if (have_flag(flgs, TR_SEE_INVIS)) fprintf(fff,"+ ");
5860         else fprintf(fff,". ");
5861         
5862         if (have_flag(flgs, TR_HOLD_LIFE)) fprintf(fff,"+ ");
5863         else fprintf(fff,". ");
5864
5865         if (have_flag(flgs, TR_TELEPATHY)) fprintf(fff,"+ ");
5866         else fprintf(fff,". ");
5867
5868         if (have_flag(flgs, TR_SLOW_DIGEST)) fprintf(fff,"+ ");
5869         else fprintf(fff,". ");
5870
5871
5872         if (have_flag(flgs, TR_REGEN)) fprintf(fff,"+ ");
5873         else fprintf(fff,". ");
5874
5875         if (have_flag(flgs, TR_FEATHER)) fprintf(fff,"+ ");
5876         else fprintf(fff,". ");
5877 #endif  
5878         fprintf(fff,"\n");
5879       }
5880       (*j)++;
5881       if(*j==9)
5882         { 
5883           *j=0;
5884           fprintf(fff,"%s\n", inven_res_label);
5885         }
5886     }
5887 }
5888
5889 /*
5890  * Display *ID* ed weapons/armors's resistances
5891  */
5892 static void do_cmd_knowledge_inven(void)
5893 {
5894
5895         FILE *fff;
5896
5897         char file_name[1024];
5898  
5899         store_type  *st_ptr;
5900         object_type *o_ptr;
5901
5902         byte tval;
5903         int i=0;
5904         int j=0;
5905
5906         char  where[32];
5907
5908         /* Open a new file */
5909         fff = my_fopen_temp(file_name, 1024);
5910         if (!fff) {
5911 #ifdef JP
5912             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
5913 #else
5914             msg_format("Failed to create temporary file %s.", file_name);
5915 #endif
5916             msg_print(NULL);
5917             return;
5918         }
5919         fprintf(fff,"%s\n",inven_res_label);
5920
5921         for (tval=TV_BOW; tval <= TV_RING; tval++){
5922
5923           if (j!=0) {
5924               for (;j<9;j++) fprintf(fff, "\n");
5925               j=0;
5926               fprintf(fff,"%s\n",inven_res_label);              
5927           }
5928           
5929 #ifdef JP
5930           strcpy(where, "Áõ");
5931 #else
5932           strcpy(where, "E ");
5933 #endif
5934           for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
5935             {
5936               o_ptr = &inventory[i];
5937               do_cmd_knowledge_inven_aux(fff, o_ptr, &j, tval, where);
5938             }
5939           
5940 #ifdef JP
5941           strcpy(where, "»ý");
5942 #else
5943           strcpy(where, "I ");
5944 #endif
5945           for (i = 0; i < INVEN_PACK; i++)
5946             {
5947               o_ptr = &inventory[i];
5948               do_cmd_knowledge_inven_aux(fff, o_ptr, &j, tval, where);
5949             }
5950           
5951           
5952           /* Print all homes in the different towns */
5953           st_ptr = &town[1].store[STORE_HOME];
5954 #ifdef JP
5955           strcpy(where, "²È");
5956 #else
5957           strcpy(where, "H ");
5958 #endif
5959               
5960           /* Dump all available items */
5961           for (i = 0; i < st_ptr->stock_num; i++)
5962             {
5963               o_ptr = &st_ptr->stock[i];
5964               do_cmd_knowledge_inven_aux(fff, o_ptr, &j, tval, where);
5965             }
5966         }
5967           
5968         /* Close the file */
5969         my_fclose(fff);
5970
5971         /* Display the file contents */
5972 #ifdef JP
5973         show_file(TRUE, file_name, "*´ÕÄê*ºÑ¤ßÉð´ï/Ëɶñ¤ÎÂÑÀ­¥ê¥¹¥È", 0, 0);
5974 #else
5975         show_file(TRUE, file_name, "Resistances of *identified* equipment", 0, 0);
5976 #endif
5977
5978         /* Remove the file */
5979         fd_kill(file_name);
5980 }
5981
5982
5983 void do_cmd_save_screen_html_aux(char *filename, int message)
5984 {
5985         int y, x, i;
5986
5987         byte a = 0, old_a = 0;
5988         char c = ' ';
5989
5990         FILE *fff, *tmpfff;
5991         char buf[2048];
5992
5993         int yomikomu = 0;
5994         cptr tags[4] = {
5995                 "HEADER_START:",
5996                 "HEADER_END:",
5997                 "FOOTER_START:",
5998                 "FOOTER_END:",
5999         };
6000
6001         cptr html_head[] = {
6002                 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
6003                 "<pre>",
6004                 0,
6005         };
6006         cptr html_foot[] = {
6007                 "</pre>\n",
6008                 "</body>\n</html>\n",
6009                 0,
6010         };
6011
6012         int wid, hgt;
6013
6014         Term_get_size(&wid, &hgt);
6015
6016         /* File type is "TEXT" */
6017         FILE_TYPE(FILE_TYPE_TEXT);
6018
6019         /* Append to the file */
6020         fff = my_fopen(filename, "w");
6021
6022         /* Oops */
6023         if (!fff) {
6024                 if (message) {
6025 #ifdef JP
6026                     msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", filename);
6027 #else
6028                     msg_format("Failed to open file %s.", filename);
6029 #endif
6030                     msg_print(NULL);
6031                 }
6032                 
6033                 return;
6034         }
6035
6036         /* Save the screen */
6037         if (message)
6038                 screen_save();
6039
6040         /* Build the filename */
6041         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "htmldump.prf");
6042         tmpfff = my_fopen(buf, "r");
6043         if (!tmpfff) {
6044                 for (i = 0; html_head[i]; i++)
6045                         fprintf(fff, html_head[i]);
6046         }
6047         else {
6048                 yomikomu = 0;
6049                 while (!my_fgets(tmpfff, buf, sizeof(buf))) {
6050                         if (!yomikomu) {
6051                                 if (strncmp(buf, tags[0], strlen(tags[0])) == 0)
6052                                         yomikomu = 1;
6053                         }
6054                         else {
6055                                 if (strncmp(buf, tags[1], strlen(tags[1])) == 0)
6056                                         break;
6057                                 fprintf(fff, "%s\n", buf);
6058                         }
6059                 }
6060         }
6061
6062         /* Dump the screen */
6063         for (y = 0; y < hgt; y++)
6064         {
6065                 /* Start the row */
6066                 if (y != 0)
6067                         fprintf(fff, "\n");
6068
6069                 /* Dump each row */
6070                 for (x = 0; x < wid - 1; x++)
6071                 {
6072                         int rv, gv, bv;
6073                         cptr cc = NULL;
6074                         /* Get the attr/char */
6075                         (void)(Term_what(x, y, &a, &c));
6076
6077                         switch (c)
6078                         {
6079                         case '&': cc = "&amp;"; break;
6080                         case '<': cc = "&lt;"; break;
6081                         case '>': cc = "&gt;"; break;
6082 #ifdef WINDOWS
6083                         case 0x1f: c = '.'; break;
6084                         case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
6085 #endif
6086                         }
6087
6088                         a = a & 0x0F;
6089                         if ((y == 0 && x == 0) || a != old_a) {
6090                                 rv = angband_color_table[a][1];
6091                                 gv = angband_color_table[a][2];
6092                                 bv = angband_color_table[a][3];
6093                                 fprintf(fff, "%s<font color=\"#%02x%02x%02x\">", 
6094                                         ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
6095                                 old_a = a;
6096                         }
6097                         if (cc)
6098                                 fprintf(fff, "%s", cc);
6099                         else
6100                                 fprintf(fff, "%c", c);
6101                 }
6102         }
6103         fprintf(fff, "</font>");
6104
6105         if (!tmpfff) {
6106                 for (i = 0; html_foot[i]; i++)
6107                         fprintf(fff, html_foot[i]);
6108         }
6109         else {
6110                 rewind(tmpfff);
6111                 yomikomu = 0;
6112                 while (!my_fgets(tmpfff, buf, sizeof(buf))) {
6113                         if (!yomikomu) {
6114                                 if (strncmp(buf, tags[2], strlen(tags[2])) == 0)
6115                                         yomikomu = 1;
6116                         }
6117                         else {
6118                                 if (strncmp(buf, tags[3], strlen(tags[3])) == 0)
6119                                         break;
6120                                 fprintf(fff, "%s\n", buf);
6121                         }
6122                 }
6123                 my_fclose(tmpfff);
6124         }
6125
6126         /* Skip a line */
6127         fprintf(fff, "\n");
6128
6129         /* Close it */
6130         my_fclose(fff);
6131
6132         /* Message */
6133         if (message) {
6134 #ifdef JP
6135         msg_print("²èÌÌ(µ­Ç°»£±Æ)¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
6136 #else
6137                 msg_print("Screen dump saved.");
6138 #endif
6139                 msg_print(NULL);
6140         }
6141
6142         /* Restore the screen */
6143         if (message)
6144                 screen_load();
6145 }
6146
6147 /*
6148  * Hack -- save a screen dump to a file
6149  */
6150 static void do_cmd_save_screen_html(void)
6151 {
6152         char buf[1024], tmp[256] = "screen.html";
6153
6154 #ifdef JP
6155         if (!get_string("¥Õ¥¡¥¤¥ë̾: ", tmp, 80))
6156 #else
6157         if (!get_string("File name: ", tmp, 80))
6158 #endif
6159                 return;
6160
6161         /* Build the filename */
6162         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
6163
6164         msg_print(NULL);
6165
6166         do_cmd_save_screen_html_aux(buf, 1);
6167 }
6168
6169
6170 /*
6171  * Redefinable "save_screen" action
6172  */
6173 void (*screendump_aux)(void) = NULL;
6174
6175
6176 /*
6177  * Hack -- save a screen dump to a file
6178  */
6179 void do_cmd_save_screen(void)
6180 {
6181         bool old_use_graphics = use_graphics;
6182         bool html_dump = FALSE;
6183
6184         int wid, hgt;
6185
6186 #ifdef JP
6187         prt("µ­Ç°»£±Æ¤·¤Þ¤¹¤«¡© [(y)es/(h)tml/(n)o] ", 0, 0);
6188 #else
6189         prt("Save screen dump? [(y)es/(h)tml/(n)o] ", 0, 0);
6190 #endif
6191         while(TRUE)
6192         {
6193                 char c = inkey();
6194                 if (c == 'Y' || c == 'y')
6195                         break;
6196                 else if (c == 'H' || c == 'h')
6197                 {
6198                         html_dump = TRUE;
6199                         break;
6200                 }
6201                 else
6202                 {
6203                         prt("", 0, 0);
6204                         return;
6205                 }
6206         }
6207
6208         Term_get_size(&wid, &hgt);
6209
6210         if (old_use_graphics)
6211         {
6212                 use_graphics = FALSE;
6213                 reset_visuals();
6214
6215                 /* Redraw everything */
6216                 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
6217
6218                 /* Hack -- update */
6219                 handle_stuff();
6220         }
6221
6222         if (html_dump)
6223         {
6224                 do_cmd_save_screen_html();
6225                 do_cmd_redraw();
6226         }
6227
6228         /* Do we use a special screendump function ? */
6229         else if (screendump_aux)
6230         {
6231                 /* Dump the screen to a graphics file */
6232                 (*screendump_aux)();
6233         }
6234         else /* Dump the screen as text */
6235         {
6236                 int y, x;
6237
6238                 byte a = 0;
6239                 char c = ' ';
6240
6241                 FILE *fff;
6242
6243                 char buf[1024];
6244
6245                 /* Build the filename */
6246                 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
6247
6248                 /* File type is "TEXT" */
6249                 FILE_TYPE(FILE_TYPE_TEXT);
6250
6251                 /* Append to the file */
6252                 fff = my_fopen(buf, "w");
6253
6254                 /* Oops */
6255                 if (!fff)
6256                 {
6257 #ifdef JP
6258                         msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
6259 #else
6260                         msg_format("Failed to open file %s.", buf);
6261 #endif
6262                         msg_print(NULL);
6263                         return;
6264                 }
6265
6266
6267                 /* Save the screen */
6268                 screen_save();
6269
6270
6271                 /* Dump the screen */
6272                 for (y = 0; y < hgt; y++)
6273                 {
6274                         /* Dump each row */
6275                         for (x = 0; x < wid - 1; x++)
6276                         {
6277                                 /* Get the attr/char */
6278                                 (void)(Term_what(x, y, &a, &c));
6279
6280                                 /* Dump it */
6281                                 buf[x] = c;
6282                         }
6283
6284                         /* Terminate */
6285                         buf[x] = '\0';
6286
6287                         /* End the row */
6288                         fprintf(fff, "%s\n", buf);
6289                 }
6290
6291                 /* Skip a line */
6292                 fprintf(fff, "\n");
6293
6294
6295                 /* Dump the screen */
6296                 for (y = 0; y < hgt; y++)
6297                 {
6298                         /* Dump each row */
6299                         for (x = 0; x < wid - 1; x++)
6300                         {
6301                                 /* Get the attr/char */
6302                                 (void)(Term_what(x, y, &a, &c));
6303
6304                                 /* Dump it */
6305                                 buf[x] = hack[a&0x0F];
6306                         }
6307
6308                         /* Terminate */
6309                         buf[x] = '\0';
6310
6311                         /* End the row */
6312                         fprintf(fff, "%s\n", buf);
6313                 }
6314
6315                 /* Skip a line */
6316                 fprintf(fff, "\n");
6317
6318
6319                 /* Close it */
6320                 my_fclose(fff);
6321
6322                 /* Message */
6323 #ifdef JP
6324         msg_print("²èÌÌ(µ­Ç°»£±Æ)¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
6325 #else
6326                 msg_print("Screen dump saved.");
6327 #endif
6328
6329                 msg_print(NULL);
6330
6331
6332                 /* Restore the screen */
6333                 screen_load();
6334         }
6335
6336         if (old_use_graphics)
6337         {
6338                 use_graphics = TRUE;
6339                 reset_visuals();
6340
6341                 /* Redraw everything */
6342                 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
6343
6344                 /* Hack -- update */
6345                 handle_stuff();
6346         }
6347 }
6348
6349
6350 /*
6351  * Sorting hook -- Comp function -- see below
6352  *
6353  * We use "u" to point to array of monster indexes,
6354  * and "v" to select the type of sorting to perform on "u".
6355  */
6356 static bool ang_sort_art_comp(vptr u, vptr v, int a, int b)
6357 {
6358         u16b *who = (u16b*)(u);
6359
6360         u16b *why = (u16b*)(v);
6361
6362         int w1 = who[a];
6363         int w2 = who[b];
6364
6365         int z1, z2;
6366
6367         /* Sort by total kills */
6368         if (*why >= 3)
6369         {
6370                 /* Extract total kills */
6371                 z1 = a_info[w1].tval;
6372                 z2 = a_info[w2].tval;
6373
6374                 /* Compare total kills */
6375                 if (z1 < z2) return (TRUE);
6376                 if (z1 > z2) return (FALSE);
6377         }
6378
6379
6380         /* Sort by monster level */
6381         if (*why >= 2)
6382         {
6383                 /* Extract levels */
6384                 z1 = a_info[w1].sval;
6385                 z2 = a_info[w2].sval;
6386
6387                 /* Compare levels */
6388                 if (z1 < z2) return (TRUE);
6389                 if (z1 > z2) return (FALSE);
6390         }
6391
6392
6393         /* Sort by monster experience */
6394         if (*why >= 1)
6395         {
6396                 /* Extract experience */
6397                 z1 = a_info[w1].level;
6398                 z2 = a_info[w2].level;
6399
6400                 /* Compare experience */
6401                 if (z1 < z2) return (TRUE);
6402                 if (z1 > z2) return (FALSE);
6403         }
6404
6405
6406         /* Compare indexes */
6407         return (w1 <= w2);
6408 }
6409
6410
6411 /*
6412  * Sorting hook -- Swap function -- see below
6413  *
6414  * We use "u" to point to array of monster indexes,
6415  * and "v" to select the type of sorting to perform.
6416  */
6417 static void ang_sort_art_swap(vptr u, vptr v, int a, int b)
6418 {
6419         u16b *who = (u16b*)(u);
6420
6421         u16b holder;
6422
6423         /* Unused */
6424         (void)v;
6425
6426         /* Swap */
6427         holder = who[a];
6428         who[a] = who[b];
6429         who[b] = holder;
6430 }
6431
6432
6433 /*
6434  * Check the status of "artifacts"
6435  */
6436 static void do_cmd_knowledge_artifacts(void)
6437 {
6438         int i, k, z, x, y, n = 0;
6439         u16b why = 3;
6440         s16b *who;
6441
6442         FILE *fff;
6443
6444         char file_name[1024];
6445
6446         char base_name[MAX_NLEN];
6447
6448         bool *okay;
6449
6450         /* Open a new file */
6451         fff = my_fopen_temp(file_name, 1024);
6452
6453         if (!fff) {
6454 #ifdef JP
6455             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6456 #else
6457             msg_format("Failed to create temporary file %s.", file_name);
6458 #endif
6459             msg_print(NULL);
6460             return;
6461         }
6462
6463         /* Allocate the "who" array */
6464         C_MAKE(who, max_a_idx, s16b);
6465
6466         /* Allocate the "okay" array */
6467         C_MAKE(okay, max_a_idx, bool);
6468
6469         /* Scan the artifacts */
6470         for (k = 0; k < max_a_idx; k++)
6471         {
6472                 artifact_type *a_ptr = &a_info[k];
6473
6474                 /* Default */
6475                 okay[k] = FALSE;
6476
6477                 /* Skip "empty" artifacts */
6478                 if (!a_ptr->name) continue;
6479
6480                 /* Skip "uncreated" artifacts */
6481                 if (!a_ptr->cur_num) continue;
6482
6483                 /* Assume okay */
6484                 okay[k] = TRUE;
6485         }
6486
6487         /* Check the dungeon */
6488         for (y = 0; y < cur_hgt; y++)
6489         {
6490                 for (x = 0; x < cur_wid; x++)
6491                 {
6492                         cave_type *c_ptr = &cave[y][x];
6493
6494                         s16b this_o_idx, next_o_idx = 0;
6495
6496                         /* Scan all objects in the grid */
6497                         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
6498                         {
6499                                 object_type *o_ptr;
6500
6501                                 /* Acquire object */
6502                                 o_ptr = &o_list[this_o_idx];
6503
6504                                 /* Acquire next object */
6505                                 next_o_idx = o_ptr->next_o_idx;
6506
6507                                 /* Ignore non-artifacts */
6508                                 if (!artifact_p(o_ptr)) continue;
6509
6510                                 /* Ignore known items */
6511                                 if (object_known_p(o_ptr)) continue;
6512
6513                                 /* Note the artifact */
6514                                 okay[o_ptr->name1] = FALSE;
6515                         }
6516                 }
6517         }
6518
6519         /* Check the inventory and equipment */
6520         for (i = 0; i < INVEN_TOTAL; i++)
6521         {
6522                 object_type *o_ptr = &inventory[i];
6523
6524                 /* Ignore non-objects */
6525                 if (!o_ptr->k_idx) continue;
6526
6527                 /* Ignore non-artifacts */
6528                 if (!artifact_p(o_ptr)) continue;
6529
6530                 /* Ignore known items */
6531                 if (object_known_p(o_ptr)) continue;
6532
6533                 /* Note the artifact */
6534                 okay[o_ptr->name1] = FALSE;
6535         }
6536
6537         for (k = 0; k < max_a_idx; k++)
6538         {
6539                 if (okay[k]) who[n++] = k;
6540         }
6541
6542         /* Select the sort method */
6543         ang_sort_comp = ang_sort_art_comp;
6544         ang_sort_swap = ang_sort_art_swap;
6545
6546         /* Sort the array by dungeon depth of monsters */
6547         ang_sort(who, &why, n);
6548
6549         /* Scan the artifacts */
6550         for (k = 0; k < n; k++)
6551         {
6552                 artifact_type *a_ptr = &a_info[who[k]];
6553
6554                 /* Paranoia */
6555 #ifdef JP
6556                 strcpy(base_name, "̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à");
6557 #else
6558                 strcpy(base_name, "Unknown Artifact");
6559 #endif
6560
6561
6562                 /* Obtain the base object type */
6563                 z = lookup_kind(a_ptr->tval, a_ptr->sval);
6564
6565                 /* Real object */
6566                 if (z)
6567                 {
6568                         object_type forge;
6569                         object_type *q_ptr;
6570
6571                         /* Get local object */
6572                         q_ptr = &forge;
6573
6574                         /* Create fake object */
6575                         object_prep(q_ptr, z);
6576
6577                         /* Make it an artifact */
6578                         q_ptr->name1 = (byte)who[k];
6579
6580                         /* Describe the artifact */
6581                         object_desc_store(base_name, q_ptr, FALSE, 0);
6582                 }
6583
6584                 /* Hack -- Build the artifact name */
6585 #ifdef JP
6586                 fprintf(fff, "     %s\n", base_name);
6587 #else
6588                 fprintf(fff, "     The %s\n", base_name);
6589 #endif
6590
6591         }
6592
6593         /* Free the "who" array */
6594         C_KILL(who, max_a_idx, s16b);
6595
6596         /* Free the "okay" array */
6597         C_KILL(okay, max_a_idx, bool);
6598
6599         /* Close the file */
6600         my_fclose(fff);
6601
6602         /* Display the file contents */
6603 #ifdef JP
6604         show_file(TRUE, file_name, "´ûÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à", 0, 0);
6605 #else
6606         show_file(TRUE, file_name, "Artifacts Seen", 0, 0);
6607 #endif
6608
6609
6610         /* Remove the file */
6611         fd_kill(file_name);
6612 }
6613
6614
6615 /*
6616  * Display known uniques
6617  */
6618 static void do_cmd_knowledge_uniques(void)
6619 {
6620         int i, k, n = 0;
6621         u16b why = 2;
6622         s16b *who;
6623
6624         FILE *fff;
6625
6626         char file_name[1024];
6627
6628         /* Open a new file */
6629         fff = my_fopen_temp(file_name, 1024);
6630
6631         if (!fff) {
6632 #ifdef JP
6633             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6634 #else
6635             msg_format("Failed to create temporary file %s.", file_name);
6636 #endif
6637             msg_print(NULL);
6638             return;
6639         }
6640
6641         /* Allocate the "who" array */
6642         C_MAKE(who, max_r_idx, s16b);
6643
6644         /* Scan the monsters */
6645         for (i = 1; i < max_r_idx; i++)
6646         {
6647                 monster_race *r_ptr = &r_info[i];
6648
6649                 /* Use that monster */
6650                 if (r_ptr->name) who[n++] = i;
6651         }
6652
6653         /* Select the sort method */
6654         ang_sort_comp = ang_sort_comp_hook;
6655         ang_sort_swap = ang_sort_swap_hook;
6656
6657         /* Sort the array by dungeon depth of monsters */
6658         ang_sort(who, &why, n);
6659
6660         /* Scan the monster races */
6661         for (k = 0; k < n; k++)
6662         {
6663                 monster_race *r_ptr = &r_info[who[k]];
6664
6665                 /* Only print Uniques */
6666                 if (r_ptr->flags1 & (RF1_UNIQUE))
6667                 {
6668                         bool dead = (r_ptr->max_num == 0);
6669
6670                         if (dead) continue;
6671
6672                         /* Only display "known" uniques */
6673                         if (dead || cheat_know || r_ptr->r_sights)
6674                         {
6675                                 /* Print a message */
6676 #ifdef JP
6677                                 fprintf(fff, "     %s¤Ï¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë¡£\n",
6678                                         (r_name + r_ptr->name));
6679 #else
6680                                 fprintf(fff, "     %s is alive\n",
6681                                         (r_name + r_ptr->name));
6682 #endif
6683
6684                         }
6685                 }
6686         }
6687
6688         /* Free the "who" array */
6689         C_KILL(who, max_r_idx, s16b);
6690
6691         /* Close the file */
6692         my_fclose(fff);
6693
6694         /* Display the file contents */
6695 #ifdef JP
6696         show_file(TRUE, file_name, "¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼", 0, 0);
6697 #else
6698         show_file(TRUE, file_name, "Alive Uniques", 0, 0);
6699 #endif
6700
6701
6702         /* Remove the file */
6703         fd_kill(file_name);
6704 }
6705
6706
6707 /*
6708  * Display weapon-exp
6709  */
6710 static void do_cmd_knowledge_weapon_exp(void)
6711 {
6712         int i, j, num, weapon_exp;
6713
6714         FILE *fff;
6715
6716         char file_name[1024];
6717         char tmp[30];
6718
6719         /* Open a new file */
6720         fff = my_fopen_temp(file_name, 1024);
6721         if (!fff) {
6722 #ifdef JP
6723             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6724 #else
6725             msg_format("Failed to create temporary file %s.", file_name);
6726 #endif
6727             msg_print(NULL);
6728             return;
6729         }
6730
6731         for (i = 0; i < 5; i++)
6732         {
6733                 for (num = 0; num < 64; num++)
6734                 {
6735                         for (j = 0; j < max_k_idx; j++)
6736                         {
6737                                 object_kind *k_ptr = &k_info[j];
6738
6739                                 if ((k_ptr->tval == TV_SWORD - i) && (k_ptr->sval == num))
6740                                 {
6741                                         if ((k_ptr->tval == TV_BOW) && (k_ptr->sval == SV_CRIMSON)) continue;
6742
6743                                         weapon_exp = p_ptr->weapon_exp[4 - i][num];
6744                                         strip_name(tmp, j);
6745                                         fprintf(fff, "%-25s ", tmp);
6746                                         if (weapon_exp >= s_info[p_ptr->pclass].w_max[4 - i][num]) fprintf(fff, "!");
6747                                         else fprintf(fff, " ");
6748                                         fprintf(fff, "%s", exp_level_str[weapon_exp_level(weapon_exp)]);
6749                                         if (cheat_xtra) fprintf(fff, " %d", weapon_exp);
6750                                         fprintf(fff, "\n");
6751                                         break;
6752                                 }
6753                         }
6754                 }
6755         }
6756
6757         /* Close the file */
6758         my_fclose(fff);
6759
6760         /* Display the file contents */
6761 #ifdef JP
6762         show_file(TRUE, file_name, "Éð´ï¤Î·Ð¸³ÃÍ", 0, 0);
6763 #else
6764         show_file(TRUE, file_name, "Weapon Proficiency", 0, 0);
6765 #endif
6766
6767
6768         /* Remove the file */
6769         fd_kill(file_name);
6770 }
6771
6772
6773 /*
6774  * Display spell-exp
6775  */
6776 static void do_cmd_knowledge_spell_exp(void)
6777 {
6778         int i = 0, spell_exp, exp_level;
6779
6780         FILE *fff;
6781         magic_type *s_ptr;
6782
6783         char file_name[1024];
6784
6785         /* Open a new file */
6786         fff = my_fopen_temp(file_name, 1024);
6787         if (!fff) {
6788 #ifdef JP
6789             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6790 #else
6791             msg_format("Failed to create temporary file %s.", file_name);
6792 #endif
6793             msg_print(NULL);
6794             return;
6795         }
6796
6797         if (p_ptr->realm1 != REALM_NONE)
6798         {
6799 #ifdef JP
6800                 fprintf(fff, "%s¤ÎËâË¡½ñ\n", realm_names[p_ptr->realm1]);
6801 #else
6802                 fprintf(fff, "%s Spellbook\n", realm_names[p_ptr->realm1]);
6803 #endif
6804                 for (i = 0; i < 32; i++)
6805                 {
6806                         if (!is_magic(p_ptr->realm1))
6807                         {
6808                                 s_ptr = &technic_info[p_ptr->realm1 - MIN_TECHNIC][i];
6809                         }
6810                         else
6811                         {
6812                                 s_ptr = &mp_ptr->info[p_ptr->realm1 - 1][i];
6813                         }
6814                         if (s_ptr->slevel >= 99) continue;
6815                         spell_exp = p_ptr->spell_exp[i];
6816                         exp_level = spell_exp_level(spell_exp);
6817                         fprintf(fff, "%-25s ", spell_names[technic2magic(p_ptr->realm1) - 1][i]);
6818                         if (p_ptr->realm1 == REALM_HISSATSU)
6819                                 fprintf(fff, "[--]");
6820                         else
6821                         {
6822                                 if (exp_level >= EXP_LEVEL_MASTER) fprintf(fff, "!");
6823                                 else fprintf(fff, " ");
6824                                 fprintf(fff, "%s", exp_level_str[exp_level]);
6825                         }
6826                         if (cheat_xtra) fprintf(fff, " %d", spell_exp);
6827                         fprintf(fff, "\n");
6828                 }
6829         }
6830
6831         if (p_ptr->realm2 != REALM_NONE)
6832         {
6833 #ifdef JP
6834                 fprintf(fff, "%s¤ÎËâË¡½ñ\n", realm_names[p_ptr->realm2]);
6835 #else
6836                 fprintf(fff, "\n%s Spellbook\n", realm_names[p_ptr->realm2]);
6837 #endif
6838                 for (i = 0; i < 32; i++)
6839                 {
6840                         if (!is_magic(p_ptr->realm1))
6841                         {
6842                                 s_ptr = &technic_info[p_ptr->realm2 - MIN_TECHNIC][i];
6843                         }
6844                         else
6845                         {
6846                                 s_ptr = &mp_ptr->info[p_ptr->realm2 - 1][i];
6847                         }
6848                         if (s_ptr->slevel >= 99) continue;
6849
6850                         spell_exp = p_ptr->spell_exp[i + 32];
6851                         exp_level = spell_exp_level(spell_exp);
6852                         fprintf(fff, "%-25s ", spell_names[technic2magic(p_ptr->realm2) - 1][i]);
6853                         if (exp_level >= EXP_LEVEL_EXPERT) fprintf(fff, "!");
6854                         else fprintf(fff, " ");
6855                         fprintf(fff, "%s", exp_level_str[exp_level]);
6856                         if (cheat_xtra) fprintf(fff, " %d", spell_exp);
6857                         fprintf(fff, "\n");
6858                 }
6859         }
6860
6861         /* Close the file */
6862         my_fclose(fff);
6863
6864         /* Display the file contents */
6865 #ifdef JP
6866         show_file(TRUE, file_name, "ËâË¡¤Î·Ð¸³ÃÍ", 0, 0);
6867 #else
6868         show_file(TRUE, file_name, "Spell Proficiency", 0, 0);
6869 #endif
6870
6871
6872         /* Remove the file */
6873         fd_kill(file_name);
6874 }
6875
6876
6877 /*
6878  * Display skill-exp
6879  */
6880 static void do_cmd_knowledge_skill_exp(void)
6881 {
6882         int i = 0, skill_exp;
6883
6884         FILE *fff;
6885
6886         char file_name[1024];
6887 #ifdef JP
6888         char skill_name[3][17]={"¥Þ¡¼¥·¥ã¥ë¥¢¡¼¥Ä", "ÆóÅáή          ", "¾èÇÏ            "};
6889 #else
6890         char skill_name[3][20]={"Martial Arts    ", "Dual Wielding   ", "Riding          "};
6891 #endif
6892
6893         /* Open a new file */
6894         fff = my_fopen_temp(file_name, 1024);
6895         if (!fff) {
6896 #ifdef JP
6897             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6898 #else
6899             msg_format("Failed to create temporary file %s.", file_name);
6900 #endif
6901             msg_print(NULL);
6902             return;
6903         }
6904
6905         for (i = 0; i < 3; i++)
6906         {
6907                 skill_exp = p_ptr->skill_exp[i];
6908                 fprintf(fff, "%-20s ", skill_name[i]);
6909                 if (skill_exp >= s_info[p_ptr->pclass].s_max[i]) fprintf(fff, "!");
6910                 else fprintf(fff, " ");
6911                 fprintf(fff, "%s", exp_level_str[(i == GINOU_RIDING) ? riding_exp_level(skill_exp) : weapon_exp_level(skill_exp)]);
6912                 if (cheat_xtra) fprintf(fff, " %d", skill_exp);
6913                 fprintf(fff, "\n");
6914         }
6915
6916         /* Close the file */
6917         my_fclose(fff);
6918
6919         /* Display the file contents */
6920 #ifdef JP
6921         show_file(TRUE, file_name, "µ»Ç½¤Î·Ð¸³ÃÍ", 0, 0);
6922 #else
6923         show_file(TRUE, file_name, "Miscellaneous Proficiency", 0, 0);
6924 #endif
6925
6926
6927         /* Remove the file */
6928         fd_kill(file_name);
6929 }
6930
6931
6932 /*
6933  * Pluralize a monster name
6934  */
6935 void plural_aux(char *Name)
6936 {
6937         int NameLen = strlen(Name);
6938
6939         if (strstr(Name, "Disembodied hand"))
6940         {
6941                 strcpy(Name, "Disembodied hands that strangled people");
6942         }
6943         else if (strstr(Name, "Colour out of space"))
6944         {
6945                 strcpy(Name, "Colours out of space");
6946         }
6947         else if (strstr(Name, "stairway to hell"))
6948         {
6949                 strcpy(Name, "stairways to hell");
6950         }
6951         else if (strstr(Name, "Dweller on the threshold"))
6952         {
6953                 strcpy(Name, "Dwellers on the threshold");
6954         }
6955         else if (strstr(Name, " of "))
6956         {
6957                 cptr aider = strstr(Name, " of ");
6958                 char dummy[80];
6959                 int i = 0;
6960                 cptr ctr = Name;
6961
6962                 while (ctr < aider)
6963                 {
6964                         dummy[i] = *ctr;
6965                         ctr++; i++;
6966                 }
6967
6968                 if (dummy[i-1] == 's')
6969                 {
6970                         strcpy(&(dummy[i]), "es");
6971                         i++;
6972                 }
6973                 else
6974                 {
6975                         strcpy(&(dummy[i]), "s");
6976                 }
6977
6978                 strcpy(&(dummy[i+1]), aider);
6979                 strcpy(Name, dummy);
6980         }
6981         else if (strstr(Name, "coins"))
6982         {
6983                 char dummy[80];
6984                 strcpy(dummy, "piles of ");
6985                 strcat(dummy, Name);
6986                 strcpy(Name, dummy);
6987                 return;
6988         }
6989         else if (strstr(Name, "Manes"))
6990         {
6991                 return;
6992         }
6993         else if (streq(&(Name[NameLen - 2]), "ey"))
6994         {
6995                 strcpy(&(Name[NameLen - 2]), "eys");
6996         }
6997         else if (Name[NameLen - 1] == 'y')
6998         {
6999                 strcpy(&(Name[NameLen - 1]), "ies");
7000         }
7001         else if (streq(&(Name[NameLen - 4]), "ouse"))
7002         {
7003                 strcpy(&(Name[NameLen - 4]), "ice");
7004         }
7005         else if (streq(&(Name[NameLen - 2]), "us"))
7006         {
7007                 strcpy(&(Name[NameLen - 2]), "i");
7008         }
7009         else if (streq(&(Name[NameLen - 6]), "kelman"))
7010         {
7011                 strcpy(&(Name[NameLen - 6]), "kelmen");
7012         }
7013         else if (streq(&(Name[NameLen - 8]), "wordsman"))
7014         {
7015                 strcpy(&(Name[NameLen - 8]), "wordsmen");
7016         }
7017         else if (streq(&(Name[NameLen - 7]), "oodsman"))
7018         {
7019                 strcpy(&(Name[NameLen - 7]), "oodsmen");
7020         }
7021         else if (streq(&(Name[NameLen - 7]), "eastman"))
7022         {
7023                 strcpy(&(Name[NameLen - 7]), "eastmen");
7024         }
7025         else if (streq(&(Name[NameLen - 8]), "izardman"))
7026         {
7027                 strcpy(&(Name[NameLen - 8]), "izardmen");
7028         }
7029         else if (streq(&(Name[NameLen - 5]), "geist"))
7030         {
7031                 strcpy(&(Name[NameLen - 5]), "geister");
7032         }
7033         else if (streq(&(Name[NameLen - 2]), "ex"))
7034         {
7035                 strcpy(&(Name[NameLen - 2]), "ices");
7036         }
7037         else if (streq(&(Name[NameLen - 2]), "lf"))
7038         {
7039                 strcpy(&(Name[NameLen - 2]), "lves");
7040         }
7041         else if (suffix(Name, "ch") ||
7042                  suffix(Name, "sh") ||
7043                          suffix(Name, "nx") ||
7044                          suffix(Name, "s") ||
7045                          suffix(Name, "o"))
7046         {
7047                 strcpy(&(Name[NameLen]), "es");
7048         }
7049         else
7050         {
7051                 strcpy(&(Name[NameLen]), "s");
7052         }
7053 }
7054
7055 /*
7056  * Display current pets
7057  */
7058 static void do_cmd_knowledge_pets(void)
7059 {
7060         int             i;
7061         FILE            *fff;
7062         monster_type    *m_ptr;
7063         char            pet_name[80];
7064         int             t_friends = 0;
7065         int             show_upkeep = 0;
7066         char            file_name[1024];
7067
7068
7069         /* Open a new file */
7070         fff = my_fopen_temp(file_name, 1024);
7071         if (!fff) {
7072 #ifdef JP
7073             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
7074 #else
7075             msg_format("Failed to create temporary file %s.", file_name);
7076 #endif
7077             msg_print(NULL);
7078             return;
7079         }
7080
7081         /* Process the monsters (backwards) */
7082         for (i = m_max - 1; i >= 1; i--)
7083         {
7084                 /* Access the monster */
7085                 m_ptr = &m_list[i];
7086
7087                 /* Ignore "dead" monsters */
7088                 if (!m_ptr->r_idx) continue;
7089
7090                 /* Calculate "upkeep" for pets */
7091                 if (is_pet(m_ptr))
7092                 {
7093                         t_friends++;
7094                         monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
7095                         fprintf(fff, "%s (%s)\n", pet_name, look_mon_desc(m_ptr, 0x00));
7096                 }
7097         }
7098
7099         /* Process the waiting pets (backwards) */
7100         for (i = MAX_PARTY_MON - 1; i >= 0; i--)
7101         {
7102                 /* Access the monster */
7103                 m_ptr = &party_mon[i];
7104
7105                 /* Ignore "dead" monsters */
7106                 if (!m_ptr->r_idx) continue;
7107
7108                 t_friends++;
7109
7110                 /* List waiting pets */
7111                 monster_desc(pet_name, m_ptr, MD_ASSUME_OUTSIDE | MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
7112                 fprintf(fff, "%s (%s)\n", pet_name, look_mon_desc(m_ptr, 0x00));
7113         }
7114
7115         show_upkeep = calculate_upkeep();
7116
7117         fprintf(fff, "----------------------------------------------\n");
7118 #ifdef JP
7119         fprintf(fff, "    ¹ç·×: %d É¤¤Î¥Ú¥Ã¥È\n", t_friends);
7120         fprintf(fff, " °Ý»ý¥³¥¹¥È: %d%% MP\n", show_upkeep);
7121 #else
7122         fprintf(fff, "   Total: %d pet%s.\n",
7123                 t_friends, (t_friends == 1 ? "" : "s"));
7124         fprintf(fff, "   Upkeep: %d%% mana.\n", show_upkeep);
7125 #endif
7126
7127
7128
7129         /* Close the file */
7130         my_fclose(fff);
7131
7132         /* Display the file contents */
7133 #ifdef JP
7134         show_file(TRUE, file_name, "¸½ºß¤Î¥Ú¥Ã¥È", 0, 0);
7135 #else
7136         show_file(TRUE, file_name, "Current Pets", 0, 0);
7137 #endif
7138
7139
7140         /* Remove the file */
7141         fd_kill(file_name);
7142 }
7143
7144
7145 /*
7146  * Total kill count
7147  *
7148  * Note that the player ghosts are ignored.  XXX XXX XXX
7149  */
7150 static void do_cmd_knowledge_kill_count(void)
7151 {
7152         int i, k, n = 0;
7153         u16b why = 2;
7154         s16b *who;
7155
7156         FILE *fff;
7157
7158         char file_name[1024];
7159
7160         s32b Total = 0;
7161
7162
7163         /* Open a new file */
7164         fff = my_fopen_temp(file_name, 1024);
7165
7166         if (!fff) {
7167 #ifdef JP
7168             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
7169 #else
7170             msg_format("Failed to create temporary file %s.", file_name);
7171 #endif
7172             msg_print(NULL);
7173             return;
7174         }
7175
7176         /* Allocate the "who" array */
7177         C_MAKE(who, max_r_idx, s16b);
7178
7179         {
7180                 /* Monsters slain */
7181                 int kk;
7182
7183                 for (kk = 1; kk < max_r_idx; kk++)
7184                 {
7185                         monster_race *r_ptr = &r_info[kk];
7186
7187                         if (r_ptr->flags1 & (RF1_UNIQUE))
7188                         {
7189                                 bool dead = (r_ptr->max_num == 0);
7190
7191                                 if (dead)
7192                                 {
7193                                         Total++;
7194                                 }
7195                         }
7196                         else
7197                         {
7198                                 s16b This = r_ptr->r_pkills;
7199
7200                                 if (This > 0)
7201                                 {
7202                                         Total += This;
7203                                 }
7204                         }
7205                 }
7206
7207                 if (Total < 1)
7208 #ifdef JP
7209                         fprintf(fff,"¤¢¤Ê¤¿¤Ï¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Ê¤¤¡£\n\n");
7210 #else
7211                         fprintf(fff,"You have defeated no enemies yet.\n\n");
7212 #endif
7213
7214                 else if (Total == 1)
7215 #ifdef JP
7216                         fprintf(fff,"¤¢¤Ê¤¿¤Ï°ìɤ¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n");
7217 #else
7218                         fprintf(fff,"You have defeated one enemy.\n\n");
7219 #endif
7220
7221                 else
7222 #ifdef JP
7223                         fprintf(fff,"¤¢¤Ê¤¿¤Ï %lu É¤¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n", Total);
7224 #else
7225                         fprintf(fff,"You have defeated %lu enemies.\n\n", Total);
7226 #endif
7227
7228         }
7229
7230         Total = 0;
7231
7232         /* Scan the monsters */
7233         for (i = 1; i < max_r_idx; i++)
7234         {
7235                 monster_race *r_ptr = &r_info[i];
7236
7237                 /* Use that monster */
7238                 if (r_ptr->name) who[n++] = i;
7239         }
7240
7241         /* Select the sort method */
7242         ang_sort_comp = ang_sort_comp_hook;
7243         ang_sort_swap = ang_sort_swap_hook;
7244
7245         /* Sort the array by dungeon depth of monsters */
7246         ang_sort(who, &why, n);
7247
7248         /* Scan the monster races */
7249         for (k = 0; k < n; k++)
7250         {
7251                 monster_race *r_ptr = &r_info[who[k]];
7252
7253                 if (r_ptr->flags1 & (RF1_UNIQUE))
7254                 {
7255                         bool dead = (r_ptr->max_num == 0);
7256
7257                         if (dead)
7258                         {
7259                                 /* Print a message */
7260                                 fprintf(fff, "     %s\n",
7261                                     (r_name + r_ptr->name));
7262                                 Total++;
7263                         }
7264                 }
7265                 else
7266                 {
7267                         s16b This = r_ptr->r_pkills;
7268
7269                         if (This > 0)
7270                         {
7271 #ifdef JP
7272                                 /* p,t¤Ï¿Í¤È¿ô¤¨¤ë by ita*/
7273                                 if(strchr("pt",r_ptr->d_char))
7274                                         fprintf(fff, "     %3d ¿Í¤Î %s\n", This, r_name + r_ptr->name);
7275                                 else
7276                                         fprintf(fff, "     %3d É¤¤Î %s\n", This, r_name + r_ptr->name);
7277 #else
7278                                 if (This < 2)
7279                                 {
7280                                         if (strstr(r_name + r_ptr->name, "coins"))
7281                                         {
7282                                                 fprintf(fff, "     1 pile of %s\n", (r_name + r_ptr->name));
7283                                         }
7284                                         else
7285                                         {
7286                                                 fprintf(fff, "     1 %s\n", (r_name + r_ptr->name));
7287                                         }
7288                                 }
7289                                 else
7290                                 {
7291                                         char ToPlural[80];
7292                                         strcpy(ToPlural, (r_name + r_ptr->name));
7293                                         plural_aux(ToPlural);
7294                                         fprintf(fff, "     %d %s\n", This, ToPlural);
7295                                 }
7296 #endif
7297
7298
7299                                 Total += This;
7300                         }
7301                 }
7302         }
7303
7304         fprintf(fff,"----------------------------------------------\n");
7305 #ifdef JP
7306         fprintf(fff,"    ¹ç·×: %lu É¤¤òÅݤ·¤¿¡£\n", Total);
7307 #else
7308         fprintf(fff,"   Total: %lu creature%s killed.\n",
7309                 Total, (Total == 1 ? "" : "s"));
7310 #endif
7311
7312
7313         /* Free the "who" array */
7314         C_KILL(who, max_r_idx, s16b);
7315
7316         /* Close the file */
7317         my_fclose(fff);
7318
7319         /* Display the file contents */
7320 #ifdef JP
7321         show_file(TRUE, file_name, "Åݤ·¤¿Å¨¤Î¿ô", 0, 0);
7322 #else
7323         show_file(TRUE, file_name, "Kill Count", 0, 0);
7324 #endif
7325
7326
7327         /* Remove the file */
7328         fd_kill(file_name);
7329 }
7330
7331
7332 /*
7333  * Display the object groups.
7334  */
7335 static void display_group_list(int col, int row, int wid, int per_page,
7336         int grp_idx[], cptr group_text[], int grp_cur, int grp_top)
7337 {
7338         int i;
7339
7340         /* Display lines until done */
7341         for (i = 0; i < per_page && (grp_idx[i] >= 0); i++)
7342         {
7343                 /* Get the group index */
7344                 int grp = grp_idx[grp_top + i];
7345
7346                 /* Choose a color */
7347                 byte attr = (grp_top + i == grp_cur) ? TERM_L_BLUE : TERM_WHITE;
7348
7349                 /* Erase the entire line */
7350                 Term_erase(col, row + i, wid);
7351
7352                 /* Display the group label */
7353                 c_put_str(attr, group_text[grp], row + i, col);
7354         }
7355 }
7356
7357
7358 /* 
7359  * Move the cursor in a browser window 
7360  */
7361 static void browser_cursor(char ch, int *column, int *grp_cur, int grp_cnt, 
7362                                                    int *list_cur, int list_cnt)
7363 {
7364         int d;
7365         int col = *column;
7366         int grp = *grp_cur;
7367         int list = *list_cur;
7368
7369         /* Extract direction */
7370         if (ch == ' ')
7371         {
7372                 /* Hack -- scroll up full screen */
7373                 d = 3;
7374         }
7375         else if (ch == '-')
7376         {
7377                 /* Hack -- scroll down full screen */
7378                 d = 9;
7379         }
7380         else
7381         {
7382                 d = get_keymap_dir(ch);
7383         }
7384
7385         if (!d) return;
7386
7387         /* Diagonals - hack */
7388         if ((ddx[d] > 0) && ddy[d])
7389         {
7390                 int browser_rows;
7391                 int wid, hgt;
7392
7393                 /* Get size */
7394                 Term_get_size(&wid, &hgt);
7395
7396                 browser_rows = hgt - 8;
7397
7398                 /* Browse group list */
7399                 if (!col)
7400                 {
7401                         int old_grp = grp;
7402
7403                         /* Move up or down */
7404                         grp += ddy[d] * (browser_rows - 1);
7405
7406                         /* Verify */
7407                         if (grp >= grp_cnt)     grp = grp_cnt - 1;
7408                         if (grp < 0) grp = 0;
7409                         if (grp != old_grp)     list = 0;
7410                 }
7411
7412                 /* Browse sub-list list */
7413                 else
7414                 {
7415                         /* Move up or down */
7416                         list += ddy[d] * browser_rows;
7417
7418                         /* Verify */
7419                         if (list >= list_cnt) list = list_cnt - 1;
7420                         if (list < 0) list = 0;
7421                 }
7422
7423                 (*grp_cur) = grp;
7424                 (*list_cur) = list;
7425
7426                 return;
7427         }
7428
7429         if (ddx[d])
7430         {
7431                 col += ddx[d];
7432                 if (col < 0) col = 0;
7433                 if (col > 1) col = 1;
7434
7435                 (*column) = col;
7436
7437                 return;
7438         }
7439
7440         /* Browse group list */
7441         if (!col)
7442         {
7443                 int old_grp = grp;
7444
7445                 /* Move up or down */
7446                 grp += ddy[d];
7447
7448                 /* Verify */
7449                 if (grp >= grp_cnt)     grp = grp_cnt - 1;
7450                 if (grp < 0) grp = 0;
7451                 if (grp != old_grp)     list = 0;
7452         }
7453
7454         /* Browse sub-list list */
7455         else
7456         {
7457                 /* Move up or down */
7458                 list += ddy[d];
7459
7460                 /* Verify */
7461                 if (list >= list_cnt) list = list_cnt - 1;
7462                 if (list < 0) list = 0;
7463         }
7464
7465         (*grp_cur) = grp;
7466         (*list_cur) = list;
7467 }
7468
7469
7470 /*
7471  * Display visuals.
7472  */
7473 static void display_visual_list(int col, int row, int height, int width, byte attr_top, byte char_left)
7474 {
7475         int i, j;
7476
7477         /* Clear the display lines */
7478         for (i = 0; i < height; i++)
7479         {
7480                 Term_erase(col, row + i, width);
7481         }
7482
7483         /* Bigtile mode uses double width */
7484         if (use_bigtile) width /= 2;
7485
7486         /* Display lines until done */
7487         for (i = 0; i < height; i++)
7488         {
7489                 /* Display columns until done */
7490                 for (j = 0; j < width; j++)
7491                 {
7492                         byte a, a2;
7493                         char c, c2;
7494                         int x = col + j;
7495                         int y = row + i;
7496                         int ia, ic;
7497
7498                         /* Bigtile mode uses double width */
7499                         if (use_bigtile) x += j;
7500
7501                         ia = attr_top + i;
7502                         ic = char_left + j;
7503
7504                         /* Ignore illegal characters */
7505                         if (ia > 0x7f || ic > 0xff || ic < ' ' ||
7506                             (!use_graphics && ic > 0x7f))
7507                                 continue;
7508
7509                         a = (byte)ia;
7510                         c = (char)ic;
7511
7512                         /* Force correct code for both ASCII character and tile */
7513                         if (c & 0x80) a |= 0x80;
7514
7515                         if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
7516
7517                         /* Display symbol */
7518                         Term_putch(x, y, a, c);
7519
7520                         /* Second byte */
7521                         if (use_bigtile) Term_putch(x + 1, y, a2, c2);
7522                 }
7523         }
7524 }
7525
7526
7527 /*
7528  * Place the cursor at the collect position for visual mode
7529  */
7530 static void place_visual_list_cursor(int col, int row, byte a, byte c, byte attr_top, byte char_left)
7531 {
7532         int i = (a & 0x7f) - attr_top;
7533         int j = c - char_left;
7534
7535         int x = col + j;
7536         int y = row + i;
7537
7538         /* Bigtile mode uses double width */
7539         if (use_bigtile) x += j;
7540
7541         /* Place the cursor */
7542         Term_gotoxy(x, y);
7543 }
7544
7545
7546 /*
7547  *  Clipboard variables for copy&paste in visual mode
7548  */
7549 static byte attr_idx = 0;
7550 static byte char_idx = 0;
7551
7552 /*
7553  *  Do visual mode command -- Change symbols
7554  */
7555 static bool visual_mode_command(char ch, bool *visual_list_ptr, 
7556                                 int height, int width, 
7557                                 byte *attr_top_ptr, byte *char_left_ptr, 
7558                                 byte *cur_attr_ptr, byte *cur_char_ptr)
7559 {
7560         static byte attr_old = 0, char_old = 0;
7561
7562         switch (ch)
7563         {
7564         case ESCAPE:
7565                 if (*visual_list_ptr)
7566                 {
7567                         /* Cancel change */
7568                         *cur_attr_ptr = attr_old;
7569                         *cur_char_ptr = char_old;
7570                         *visual_list_ptr = FALSE;
7571
7572                         return TRUE;
7573                 }
7574
7575                 break;
7576
7577         case '\n':
7578         case '\r':
7579                 if (*visual_list_ptr)
7580                 {
7581                         /* Accept change */
7582                         *visual_list_ptr = FALSE;
7583
7584                         return TRUE;
7585                 }
7586                 break;
7587
7588         case 'V':
7589         case 'v':
7590                 if (!*visual_list_ptr)
7591                 {
7592                         *visual_list_ptr = TRUE;
7593
7594                         *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
7595                         *char_left_ptr = MAX(0, *cur_char_ptr - 10);
7596
7597                         attr_old = *cur_attr_ptr;
7598                         char_old = *cur_char_ptr;
7599
7600                         return TRUE;
7601                 }
7602                 break;
7603
7604         case 'C':
7605         case 'c':
7606                 /* Set the visual */
7607                 attr_idx = *cur_attr_ptr;
7608                 char_idx = *cur_char_ptr;
7609
7610                 return TRUE;
7611
7612         case 'P':
7613         case 'p':
7614                 if (attr_idx)
7615                 {
7616                         /* Set the char */
7617                         *cur_attr_ptr = attr_idx;
7618                         *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
7619                 }
7620
7621                 if (char_idx)
7622                 {
7623                         /* Set the char */
7624                         *cur_char_ptr = char_idx;
7625                         *char_left_ptr = MAX(0, *cur_char_ptr - 10);
7626                 }
7627
7628                 return TRUE;
7629
7630         default:
7631                 if (*visual_list_ptr)
7632                 {
7633                         int eff_width;
7634                         int d = get_keymap_dir(ch);
7635                         byte a = (*cur_attr_ptr & 0x7f);
7636                         byte c = *cur_char_ptr;
7637
7638                         if (use_bigtile) eff_width = width / 2;
7639                         else eff_width = width;
7640                                         
7641                         /* Restrict direction */
7642                         if ((a == 0) && (ddy[d] < 0)) d = 0;
7643                         if ((c == 0) && (ddx[d] < 0)) d = 0;
7644                         if ((a == 0x7f) && (ddy[d] > 0)) d = 0;
7645                         if ((c == 0xff) && (ddx[d] > 0)) d = 0;
7646
7647                         a += ddy[d];
7648                         c += ddx[d];
7649
7650                         /* Force correct code for both ASCII character and tile */
7651                         if (c & 0x80) a |= 0x80;
7652
7653                         /* Set the visual */
7654                         *cur_attr_ptr = a;
7655                         *cur_char_ptr = c;
7656
7657
7658                         /* Move the frame */
7659                         if ((ddx[d] < 0) && *char_left_ptr > MAX(0, (int)c - 10)) (*char_left_ptr)--;
7660                         if ((ddx[d] > 0) && *char_left_ptr + eff_width < MIN(0xff, (int)c + 10)) (*char_left_ptr)++;
7661                         if ((ddy[d] < 0) && *attr_top_ptr > MAX(0, (int)(a & 0x7f) - 4)) (*attr_top_ptr)--;
7662                         if ((ddy[d] > 0) && *attr_top_ptr + height < MIN(0x7f, (a & 0x7f) + 4)) (*attr_top_ptr)++;
7663                         return TRUE;
7664                 }
7665                                 
7666                 break;
7667         }
7668
7669         /* Visual mode command is not used */
7670         return FALSE;
7671 }
7672
7673
7674 /*
7675  * Display the monsters in a group.
7676  */
7677 static void display_monster_list(int col, int row, int per_page, s16b mon_idx[],
7678         int mon_cur, int mon_top)
7679 {
7680         int i;
7681
7682         /* Display lines until done */
7683         for (i = 0; i < per_page && mon_idx[mon_top + i]; i++)
7684         {
7685                 byte attr;
7686                 byte a, a2;
7687                 char c, c2;
7688
7689                 /* Get the race index */
7690                 int r_idx = mon_idx[mon_top + i] ;
7691
7692                 /* Access the race */
7693                 monster_race *r_ptr = &r_info[r_idx];
7694
7695
7696                 /* Choose a color */
7697                 attr = ((i + mon_top == mon_cur) ? TERM_L_BLUE : TERM_WHITE);
7698
7699                 /* Display the name */
7700                 c_prt(attr, (r_name + r_ptr->name), row + i, col);
7701
7702                 /* Hack -- visual_list mode */
7703                 if (per_page == 1)
7704                 {
7705                         c_prt(attr, format("%02x/%02x", r_ptr->x_attr, r_ptr->x_char), row + i, 60);
7706                 }
7707                 else if (p_ptr->wizard) 
7708                 {
7709                         c_prt(attr, format("%d", r_idx), row + i, 60);
7710                 }
7711
7712                 a = r_ptr->x_attr;
7713                 c = r_ptr->x_char;
7714                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
7715
7716                 /* Display symbol */
7717                 Term_putch(70, row + i, a, c);
7718
7719                 /* Second byte */
7720                 if (use_bigtile) Term_putch(70 + 1, row + i, a2, c2);
7721
7722                 /* Display kills */
7723                 if (!(r_ptr->flags1 & RF1_UNIQUE)) put_str(format("%5d", r_ptr->r_pkills), row + i, 73);
7724 #ifdef JP
7725                 else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "»àË´" : "À¸Â¸"), row + i, 73);
7726 #else
7727                 else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "dead" : "alive"), row + i, 73);
7728 #endif
7729         
7730         }
7731
7732         /* Clear remaining lines */
7733         for (; i < per_page; i++)
7734         {
7735                 Term_erase(col, row + i, 255);
7736         }
7737 }
7738
7739
7740 /*
7741  * Display known monsters.
7742  */
7743 static void do_cmd_knowledge_monsters(void)
7744 {
7745         int i, len, max;
7746         int grp_cur, grp_top, old_grp_cur;
7747         int mon_cur, mon_top;
7748         int grp_cnt, grp_idx[100];
7749         int mon_cnt;
7750         s16b *mon_idx;
7751         
7752         int column = 0;
7753         bool flag;
7754         bool redraw;
7755
7756         bool visual_list = FALSE;
7757         byte attr_top = 0, char_left = 0;
7758
7759         int browser_rows;
7760         int wid, hgt;
7761
7762         /* Get size */
7763         Term_get_size(&wid, &hgt);
7764
7765         browser_rows = hgt - 8;
7766
7767         /* Allocate the "mon_idx" array */
7768         C_MAKE(mon_idx, max_r_idx, s16b);
7769
7770         max = 0;
7771         grp_cnt = 0;
7772
7773         /* Check every group */
7774         for (i = 0; monster_group_text[i] != NULL; i++)
7775         {
7776                 /* Measure the label */
7777                 len = strlen(monster_group_text[i]);
7778
7779                 /* Save the maximum length */
7780                 if (len > max) max = len;
7781
7782                 /* See if any monsters are known */
7783                 if ((monster_group_char[i] == ((char *) -1L)) || collect_monsters(i, mon_idx, 0x01))
7784                 {
7785                         /* Build a list of groups with known monsters */
7786                         grp_idx[grp_cnt++] = i;
7787                 }
7788         }
7789
7790         /* Terminate the list */
7791         grp_idx[grp_cnt] = -1;
7792
7793         old_grp_cur = -1;
7794         grp_cur = grp_top = 0;
7795         mon_cur = mon_top = 0;
7796         mon_cnt = 0;
7797
7798         flag = FALSE;
7799         redraw = TRUE;
7800
7801         while (!flag)
7802         {
7803                 char ch;
7804                 monster_race *r_ptr;
7805
7806                 if (redraw)
7807                 {
7808                         clear_from(0);
7809                 
7810 #ifdef JP
7811                         prt("Ãμ± - ¥â¥ó¥¹¥¿¡¼", 2, 0);
7812                         prt("¥°¥ë¡¼¥×", 4, 0);
7813                         prt("̾Á°", 4, max + 3);
7814                         if (p_ptr->wizard) prt("Idx", 4, 60);
7815                         prt("ʸ»ú »¦³²¿ô", 4, 67);
7816 #else
7817                         prt("Knowledge - Monsters", 2, 0);
7818                         prt("Group", 4, 0);
7819                         prt("Name", 4, max + 3);
7820                         if (p_ptr->wizard) prt("Idx", 4, 60);
7821                         prt("Sym   Kills", 4, 67);
7822 #endif
7823
7824                         for (i = 0; i < 78; i++)
7825                         {
7826                                 Term_putch(i, 5, TERM_WHITE, '=');
7827                         }
7828
7829                         for (i = 0; i < browser_rows; i++)
7830                         {
7831                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
7832                         }
7833
7834                         redraw = FALSE;
7835                 }
7836
7837                 /* Scroll group list */
7838                 if (grp_cur < grp_top) grp_top = grp_cur;
7839                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
7840
7841                 /* Display a list of monster groups */
7842                 display_group_list(0, 6, max, browser_rows, grp_idx, monster_group_text, grp_cur, grp_top);
7843
7844                 if (old_grp_cur != grp_cur)
7845                 {
7846                         old_grp_cur = grp_cur;
7847
7848                         /* Get a list of monsters in the current group */
7849                         mon_cnt = collect_monsters(grp_idx[grp_cur], mon_idx, 0x00);
7850                 }
7851
7852                 /* Scroll monster list */
7853                 while (mon_cur < mon_top)
7854                         mon_top = MAX(0, mon_top - browser_rows/2);
7855                 while (mon_cur >= mon_top + browser_rows)
7856                         mon_top = MIN(mon_cnt - browser_rows, mon_top + browser_rows/2);
7857
7858                 if (!visual_list)
7859                 {
7860                         /* Display a list of monsters in the current group */
7861                         display_monster_list(max + 3, 6, browser_rows, mon_idx, mon_cur, mon_top);
7862                 }
7863                 else
7864                 {
7865                         mon_top = mon_cur;
7866
7867                         /* Display a monster name */
7868                         display_monster_list(max + 3, 6, 1, mon_idx, mon_cur, mon_top);
7869
7870                         /* Display visual list below first monster */
7871                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
7872                 }
7873
7874                 /* Prompt */
7875 #ifdef JP
7876                 prt(format("<Êý¸þ>, 'r'¤Ç»×¤¤½Ð¤ò¸«¤ë%s%s, ESC", visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
7877 #else
7878                 prt(format("<dir>, 'r' to recall%s%s, ESC", visual_list ? ", ENTER to accept" : ", 'v' for visuals", (attr_idx||char_idx) ? ", 'c', 'p' to paste" : ", 'c' to copy"), hgt - 1, 0);
7879 #endif
7880
7881                 /* Get the current monster */
7882                 r_ptr = &r_info[mon_idx[mon_cur]];
7883
7884                 /* Mega Hack -- track this monster race */
7885                 if (mon_cnt) monster_race_track(mon_idx[mon_cur]);
7886
7887                 /* Hack -- handle stuff */
7888                 handle_stuff();
7889
7890                 if (visual_list)
7891                 {
7892                         place_visual_list_cursor(max + 3, 7, r_ptr->x_attr, r_ptr->x_char, attr_top, char_left);
7893                 }
7894                 else if (!column)
7895                 {
7896                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
7897                 }
7898                 else
7899                 {
7900                         Term_gotoxy(max + 3, 6 + (mon_cur - mon_top));
7901                 }
7902         
7903                 ch = inkey();
7904
7905                 /* Do visual mode command if needed */
7906                 if (visual_mode_command(ch, &visual_list, browser_rows-1, wid - (max + 3), &attr_top, &char_left, &r_ptr->x_attr, &r_ptr->x_char)) continue;
7907
7908                 switch (ch)
7909                 {
7910                         case ESCAPE:
7911                         {
7912                                 flag = TRUE;
7913                                 break;
7914                         }
7915
7916                         case 'R':
7917                         case 'r':
7918                         {
7919                                 /* Recall on screen */
7920                                 if (mon_idx[mon_cur])
7921                                 {
7922                                         screen_roff(mon_idx[mon_cur], 0);
7923
7924                                         (void)inkey();
7925         
7926                                         redraw = TRUE;
7927                                 }
7928                                 break;
7929                         }
7930
7931                         default:
7932                         {
7933                                 /* Move the cursor */
7934                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &mon_cur, mon_cnt);
7935
7936                                 break;
7937                         }
7938                 }
7939         }
7940
7941         /* Free the "mon_idx" array */
7942         C_KILL(mon_idx, max_r_idx, s16b);
7943 }
7944
7945
7946 /*
7947  * Display the objects in a group.
7948  */
7949 static void display_object_list(int col, int row, int per_page, int object_idx[],
7950         int object_cur, int object_top)
7951 {
7952         int i;
7953
7954         /* Display lines until done */
7955         for (i = 0; i < per_page && object_idx[object_top + i]; i++)
7956         {
7957                 char o_name[80];
7958                 byte a, a2;
7959                 char c, c2;
7960
7961                 /* Get the object index */
7962                 int k_idx = object_idx[object_top + i];
7963
7964                 /* Access the object */
7965                 object_kind *k_ptr = &k_info[k_idx];
7966
7967                 /* Choose a color */
7968                 byte attr = (k_ptr->aware ? TERM_WHITE : TERM_SLATE);
7969                 byte cursor = (k_ptr->aware ? TERM_L_BLUE : TERM_BLUE);
7970
7971                 attr = ((i + object_top == object_cur) ? cursor : attr);
7972                 
7973                 /* Tidy name */
7974                 strip_name(o_name, k_idx);
7975
7976                 /* Display the name */
7977                 c_prt(attr, o_name, row + i, col);
7978
7979                 /* Hack -- visual_list mode */
7980                 if (per_page == 1)
7981                 {
7982                         c_prt(attr, format("%02x/%02x", k_ptr->x_attr, k_ptr->x_char), row + i, 60);
7983                 }
7984                 else if (p_ptr->wizard)
7985                 {
7986                         c_prt(attr, format ("%d", k_idx), row + i, 70);
7987                 }
7988
7989                 a = k_ptr->flavor ? misc_to_attr[k_ptr->flavor] : k_ptr->x_attr;
7990                 c = k_ptr->flavor ? misc_to_char[k_ptr->flavor] : k_ptr->x_char;
7991
7992                 /* Symbol is unknown */ 
7993                 if (!k_ptr->aware && !p_ptr->wizard)
7994                 {
7995                         c = ' ';
7996                         a = TERM_DARK;
7997                 }
7998
7999                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
8000
8001                 /* Display symbol */
8002                 Term_putch(76, row + i, a, c);
8003
8004                 /* Second byte */
8005                 if (use_bigtile) Term_putch(76 + 1, row + i, a2, c2);
8006         }
8007
8008         /* Clear remaining lines */
8009         for (; i < per_page; i++)
8010         {
8011                 Term_erase(col, row + i, 255);
8012         }
8013 }
8014
8015 /*
8016  * Describe fake object
8017  */
8018 static void desc_obj_fake(int k_idx)
8019 {
8020         object_type *o_ptr;
8021         object_type object_type_body;
8022
8023         /* Get local object */
8024         o_ptr = &object_type_body;
8025
8026         /* Wipe the object */
8027         object_wipe(o_ptr);
8028
8029         /* Create the artifact */
8030         object_prep(o_ptr, k_idx);
8031
8032         /* It's fully know */
8033         o_ptr->ident |= IDENT_KNOWN;
8034
8035         /* Track the object */
8036         /* object_actual_track(o_ptr); */
8037
8038         /* Hack - mark as fake */
8039         /* term_obj_real = FALSE; */
8040
8041         /* Hack -- Handle stuff */
8042         handle_stuff();
8043
8044         if (!screen_object(o_ptr, FALSE))
8045         {
8046 #ifdef JP
8047                 msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
8048 #else
8049                 msg_print("You see nothing special.");
8050 #endif
8051                 msg_print(NULL);
8052         }
8053 }
8054
8055
8056
8057 /*
8058  * Display known objects
8059  */
8060 static void do_cmd_knowledge_objects(void)
8061 {
8062         int i, len, max;
8063         int grp_cur, grp_top, old_grp_cur;
8064         int object_old, object_cur, object_top;
8065         int grp_cnt, grp_idx[100];
8066         int object_cnt;
8067         int *object_idx;
8068
8069         int column = 0;
8070         bool flag;
8071         bool redraw;
8072
8073         bool visual_list = FALSE;
8074         byte attr_top = 0, char_left = 0;
8075
8076         int browser_rows;
8077         int wid, hgt;
8078
8079         /* Get size */
8080         Term_get_size(&wid, &hgt);
8081
8082         browser_rows = hgt - 8;
8083
8084         /* Allocate the "object_idx" array */
8085         C_MAKE(object_idx, max_k_idx, int);
8086
8087         max = 0;
8088         grp_cnt = 0;
8089
8090         /* Check every group */
8091         for (i = 0; object_group_text[i] != NULL; i++)
8092         {
8093                 /* Measure the label */
8094                 len = strlen(object_group_text[i]);
8095
8096                 /* Save the maximum length */
8097                 if (len > max) max = len;
8098
8099                 /* See if any monsters are known */
8100                 if (collect_objects(i, object_idx))
8101                 {
8102                         /* Build a list of groups with known monsters */
8103                         grp_idx[grp_cnt++] = i;
8104                 }
8105         }
8106
8107         /* Terminate the list */
8108         grp_idx[grp_cnt] = -1;
8109
8110         old_grp_cur = -1;
8111         grp_cur = grp_top = 0;
8112         object_cur = object_top = 0;
8113         object_old = -1;
8114         object_cnt = 0;
8115
8116         flag = FALSE;
8117         redraw = TRUE;
8118
8119         while (!flag)
8120         {
8121                 char ch;
8122                 object_kind *k_ptr;
8123
8124                 if (redraw)
8125                 {
8126                         clear_from(0);
8127                 
8128 #ifdef JP
8129                         prt("Ãμ± - ¥¢¥¤¥Æ¥à", 2, 0);
8130                         prt("¥°¥ë¡¼¥×", 4, 0);
8131                         prt("̾Á°", 4, max + 3);
8132                         if (p_ptr->wizard) prt("Idx", 4, 70);
8133                         prt("ʸ»ú", 4, 75);
8134 #else
8135                         prt("Knowledge - objects", 2, 0);
8136                         prt("Group", 4, 0);
8137                         prt("Name", 4, max + 3);
8138                         if (p_ptr->wizard) prt("Idx", 4, 70);
8139                         prt("Sym", 4, 75);
8140 #endif
8141
8142                         for (i = 0; i < 78; i++)
8143                         {
8144                                 Term_putch(i, 5, TERM_WHITE, '=');
8145                         }
8146
8147                         for (i = 0; i < browser_rows; i++)
8148                         {
8149                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
8150                         }
8151
8152                         redraw = FALSE;
8153                 }
8154
8155                 /* Scroll group list */
8156                 if (grp_cur < grp_top) grp_top = grp_cur;
8157                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
8158
8159                 /* Display a list of object groups */
8160                 display_group_list(0, 6, max, browser_rows, grp_idx, object_group_text, grp_cur, grp_top);
8161
8162                 if (old_grp_cur != grp_cur)
8163                 {
8164                         old_grp_cur = grp_cur;
8165
8166                         /* Get a list of objects in the current group */
8167                         object_cnt = collect_objects(grp_idx[grp_cur], object_idx);
8168                 }
8169
8170                 /* Scroll object list */
8171                 while (object_cur < object_top)
8172                         object_top = MAX(0, object_top - browser_rows/2);
8173                 while (object_cur >= object_top + browser_rows)
8174                         object_top = MIN(object_cnt - browser_rows, object_top + browser_rows/2);
8175
8176                 if (!visual_list)
8177                 {
8178                         /* Display a list of objects in the current group */
8179                         display_object_list(max + 3, 6, browser_rows, object_idx, object_cur, object_top);
8180                 }
8181                 else
8182                 {
8183                         object_top = object_cur;
8184
8185                         /* Display a list of objects in the current group */
8186                         display_object_list(max + 3, 6, 1, object_idx, object_cur, object_top);
8187
8188                         /* Display visual list below first object */
8189                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
8190                 }
8191
8192                 /* Get the current object */
8193                 k_ptr = &k_info[object_idx[object_cur]];
8194
8195                 /* Mega Hack -- track this object */
8196                 if (object_cnt) object_kind_track(object_idx[object_cur]);
8197
8198                 /* Prompt */
8199 #ifdef JP
8200                 prt(format("<Êý¸þ>, 'r'¤Ç»×¤¤½Ð¤ò¸«¤ë%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
8201 #else
8202                 prt(format("<dir>, 'r' to recall%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER to accept" : ", 'v' for visuals", (attr_idx||char_idx) ? ", 'c', 'p' to paste" : ", 'c' to copy"), hgt - 1, 0);
8203 #endif
8204
8205                 /* The "current" object changed */
8206                 if (object_old != object_idx[object_cur])
8207                 {
8208                         /* Hack -- handle stuff */
8209                         handle_stuff();
8210
8211                         /* Remember the "current" object */
8212                         object_old = object_idx[object_cur];
8213                 }
8214
8215                 if (visual_list)
8216                 {
8217                         place_visual_list_cursor(max + 3, 7, k_ptr->x_attr, k_ptr->x_char, attr_top, char_left);
8218                 }
8219                 else if (!column)
8220                 {
8221                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
8222                 }
8223                 else
8224                 {
8225                         Term_gotoxy(max + 3, 6 + (object_cur - object_top));
8226                 }
8227         
8228                 ch = inkey();
8229
8230                 /* Do visual mode command if needed */
8231                 /* Symbol of objects with flavor cannot be changed */
8232                 if (!k_ptr->flavor && visual_mode_command(ch, &visual_list, browser_rows-1, wid - (max + 3), &attr_top, &char_left, &k_ptr->x_attr, &k_ptr->x_char)) continue;
8233
8234                 switch (ch)
8235                 {
8236                         case ESCAPE:
8237                         {
8238                                 flag = TRUE;
8239                                 break;
8240                         }
8241
8242                         case 'R':
8243                         case 'r':
8244                         {
8245                                 /* Recall on screen */
8246                                 if (grp_cnt > 0)
8247                                         desc_obj_fake(object_idx[object_cur]);
8248
8249                                 redraw = TRUE;
8250                                 break;
8251                         }
8252
8253                         default:
8254                         {
8255                                 /* Move the cursor */
8256                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &object_cur, object_cnt);
8257                                 break;
8258                         }
8259                 }
8260         }
8261
8262         /* Free the "object_idx" array */
8263         C_KILL(object_idx, max_k_idx, int);
8264 }
8265
8266
8267
8268 /*
8269  * Display the features in a group.
8270  */
8271 static void display_feature_list(int col, int row, int per_page, int *feat_idx,
8272         int feat_cur, int feat_top)
8273 {
8274         int i;
8275
8276         /* Display lines until done */
8277         for (i = 0; i < per_page && feat_idx[feat_top + i]; i++)
8278         {
8279                 byte a, a2;
8280                 char c, c2;
8281                 byte attr;
8282
8283                 /* Get the index */
8284                 int f_idx = feat_idx[feat_top + i];
8285
8286                 /* Access the index */
8287                 feature_type *f_ptr = &f_info[f_idx];
8288
8289                 /* Choose a color */
8290                 attr = ((i + feat_top == feat_cur) ? TERM_L_BLUE : TERM_WHITE);
8291
8292                 /* Display the name */
8293                 c_prt(attr, f_name + f_ptr->name, row + i, col);
8294
8295                 /* Hack -- visual_list mode */
8296                 if (per_page == 1)
8297                 {
8298                         c_prt(attr, format("%02x/%02x", f_ptr->x_attr, f_ptr->x_char), row + i, 60);
8299                 }
8300
8301                 a = f_ptr->x_attr;
8302                 c = f_ptr->x_char;
8303
8304                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
8305
8306                 /* Display symbol */
8307                 Term_putch(68, row + i, a, c);
8308
8309                 /* Second byte */
8310                 if (use_bigtile) Term_putch(68 + 1, row + i, a2, c2);
8311         }
8312
8313         /* Clear remaining lines */
8314         for (; i < per_page; i++)
8315         {
8316                 Term_erase(col, row + i, 255);
8317         }
8318 }
8319
8320
8321 /*
8322  * Interact with feature visuals.
8323  */
8324 static void do_cmd_knowledge_features(void)
8325 {
8326         int i, len, max;
8327         int grp_cur, grp_top, old_grp_cur;
8328         int feat_cur, feat_top;
8329         int grp_cnt, grp_idx[100];
8330         int feat_cnt;
8331         int *feat_idx;
8332         
8333         int column = 0;
8334         bool flag;
8335         bool redraw;
8336
8337         bool visual_list = FALSE;
8338         byte attr_top = 0, char_left = 0;
8339
8340         int browser_rows;
8341         int wid, hgt;
8342
8343         /* Get size */
8344         Term_get_size(&wid, &hgt);
8345
8346         browser_rows = hgt - 8;
8347
8348         /* Allocate the "feat_idx" array */
8349         C_MAKE(feat_idx, max_f_idx, int);
8350
8351         max = 0;
8352         grp_cnt = 0;
8353
8354         /* Check every group */
8355         for (i = 0; feature_group_text[i] != NULL; i++)
8356         {
8357                 /* Measure the label */
8358                 len = strlen(feature_group_text[i]);
8359
8360                 /* Save the maximum length */
8361                 if (len > max) max = len;
8362
8363                 /* See if any features are known */
8364                 if (collect_features(i, feat_idx))
8365                 {
8366                         /* Build a list of groups with known features */
8367                         grp_idx[grp_cnt++] = i;
8368                 }
8369         }
8370
8371         /* Terminate the list */
8372         grp_idx[grp_cnt] = -1;
8373
8374         old_grp_cur = -1;
8375         grp_cur = grp_top = 0;
8376         feat_cur = feat_top = 0;
8377         feat_cnt = 0;
8378
8379         flag = FALSE;
8380         redraw = TRUE;
8381
8382         while ((!flag) && (grp_cnt))
8383         {
8384                 char ch;
8385                 feature_type *f_ptr;
8386
8387                 if (redraw)
8388                 {
8389                         clear_from(0);
8390                 
8391                         prt("Visuals - features", 2, 0);
8392                         prt("Group", 4, 0);
8393                         prt("Name", 4, max + 3);
8394                         prt("Sym", 4, 67);
8395
8396                         for (i = 0; i < 78; i++)
8397                         {
8398                                 Term_putch(i, 5, TERM_WHITE, '=');
8399                         }
8400
8401                         for (i = 0; i < browser_rows; i++)
8402                         {
8403                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
8404                         }
8405
8406                         redraw = FALSE;
8407                 }
8408
8409                 /* Scroll group list */
8410                 if (grp_cur < grp_top) grp_top = grp_cur;
8411                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
8412
8413                 /* Display a list of feature groups */
8414                 display_group_list(0, 6, max, browser_rows, grp_idx, feature_group_text, grp_cur, grp_top);
8415
8416                 if (old_grp_cur != grp_cur)
8417                 {
8418                         old_grp_cur = grp_cur;
8419
8420                         /* Get a list of features in the current group */
8421                         feat_cnt = collect_features(grp_idx[grp_cur], feat_idx);
8422                 }
8423
8424                 /* Scroll feature list */
8425                 while (feat_cur < feat_top)
8426                         feat_top = MAX(0, feat_top - browser_rows/2);
8427                 while (feat_cur >= feat_top + browser_rows)
8428                         feat_top = MIN(feat_cnt - browser_rows, feat_top + browser_rows/2);
8429
8430                 if (!visual_list)
8431                 {
8432                         /* Display a list of features in the current group */
8433                         display_feature_list(max + 3, 6, browser_rows, feat_idx, feat_cur, feat_top);
8434                 }
8435                 else
8436                 {
8437                         feat_top = feat_cur;
8438
8439                         /* Display a list of features in the current group */
8440                         display_feature_list(max + 3, 6, 1, feat_idx, feat_cur, feat_top);
8441
8442                         /* Display visual list below first object */
8443                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
8444                 }
8445
8446                 /* Prompt */
8447 #ifdef JP
8448                 prt(format("<Êý¸þ>%s%s, ESC", visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
8449 #else
8450                 prt(format("<dir>%s%s, ESC", visual_list ? ", ENTER to accept" : ", 'v' for visuals", (attr_idx||char_idx) ? ", 'c', 'p' to paste" : ", 'c' to copy"), hgt - 1, 0);
8451 #endif
8452
8453                 /* Get the current feature */
8454                 f_ptr = &f_info[feat_idx[feat_cur]];
8455
8456                 if (visual_list)
8457                 {
8458                         place_visual_list_cursor(max + 3, 7, f_ptr->x_attr, f_ptr->x_char, attr_top, char_left);
8459                 }
8460                 else if (!column)
8461                 {
8462                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
8463                 }
8464                 else
8465                 {
8466                         Term_gotoxy(max + 3, 6 + (feat_cur - feat_top));
8467                 }
8468         
8469                 ch = inkey();
8470
8471                 /* Do visual mode command if needed */
8472                 if (visual_mode_command(ch, &visual_list, browser_rows-1, wid - (max + 3), &attr_top, &char_left, &f_ptr->x_attr, &f_ptr->x_char)) continue;
8473
8474                 switch (ch)
8475                 {
8476                         case ESCAPE:
8477                         {
8478                                 flag = TRUE;
8479                                 break;
8480                         }
8481
8482                         default:
8483                         {
8484                                 /* Move the cursor */
8485                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &feat_cur, feat_cnt);
8486                                 break;
8487                         }
8488                 }
8489         }
8490
8491         /* Prompt */
8492         if (!grp_cnt) msg_print("No features known.");
8493
8494         /* Free the "feat_idx" array */
8495         C_KILL(feat_idx, max_f_idx, int);
8496 }
8497
8498
8499 /*
8500  * List wanted monsters
8501  */
8502 static void do_cmd_knowledge_kubi(void)
8503 {
8504         int i;
8505         FILE *fff;
8506         
8507         char file_name[1024];
8508         
8509         
8510         /* Open a new file */
8511         fff = my_fopen_temp(file_name, 1024);
8512         if (!fff) {
8513 #ifdef JP
8514             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8515 #else
8516             msg_format("Failed to create temporary file %s.", file_name);
8517 #endif
8518             msg_print(NULL);
8519             return;
8520         }
8521         
8522         if (fff)
8523         {
8524                 bool listed = FALSE;
8525
8526 #ifdef JP
8527                 fprintf(fff, "º£Æü¤Î¥¿¡¼¥²¥Ã¥È : %s\n", (p_ptr->today_mon ? r_name + r_info[p_ptr->today_mon].name : "ÉÔÌÀ"));
8528                 fprintf(fff, "\n");
8529                 fprintf(fff, "¾Þ¶â¼ó¥ê¥¹¥È\n");
8530 #else
8531                 fprintf(fff, "Today target : %s\n", (p_ptr->today_mon ? r_name + r_info[p_ptr->today_mon].name : "unknown"));
8532                 fprintf(fff, "\n");
8533                 fprintf(fff, "List of wanted monsters\n");
8534 #endif
8535                 fprintf(fff, "----------------------------------------------\n");
8536
8537                 for (i = 0; i < MAX_KUBI; i++)
8538                 {
8539                         if (kubi_r_idx[i] <= 10000)
8540                         {
8541                                 fprintf(fff,"%s\n", r_name + r_info[kubi_r_idx[i]].name);
8542
8543                                 listed = TRUE;
8544                         }
8545                 }
8546
8547                 if (!listed)
8548                 {
8549 #ifdef JP
8550                         fprintf(fff,"\n%s\n", "¾Þ¶â¼ó¤Ï¤â¤¦»Ä¤Ã¤Æ¤¤¤Þ¤»¤ó¡£");
8551 #else
8552                         fprintf(fff,"\n%s\n", "There is no more wanted monster.");
8553 #endif
8554                 }
8555         }
8556         
8557         /* Close the file */
8558         my_fclose(fff);
8559         
8560         /* Display the file contents */
8561 #ifdef JP
8562         show_file(TRUE, file_name, "¾Þ¶â¼ó¤Î°ìÍ÷", 0, 0);
8563 #else
8564         show_file(TRUE, file_name, "Wanted monsters", 0, 0);
8565 #endif
8566
8567         
8568         /* Remove the file */
8569         fd_kill(file_name);
8570 }
8571
8572 /*
8573  * List virtues & status
8574  */
8575 static void do_cmd_knowledge_virtues(void)
8576 {
8577         FILE *fff;
8578         
8579         char file_name[1024];
8580         
8581         
8582         /* Open a new file */
8583         fff = my_fopen_temp(file_name, 1024);
8584         if (!fff) {
8585 #ifdef JP
8586             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8587 #else
8588             msg_format("Failed to create temporary file %s.", file_name);
8589 #endif
8590             msg_print(NULL);
8591             return;
8592         }
8593         
8594         if (fff)
8595         {
8596 #ifdef JP
8597                 fprintf(fff, "¸½ºß¤Î°À­ : %s\n\n", your_alignment());
8598 #else
8599                 fprintf(fff, "Your alighnment : %s\n\n", your_alignment());
8600 #endif
8601                 dump_virtues(fff);
8602         }
8603         
8604         /* Close the file */
8605         my_fclose(fff);
8606         
8607         /* Display the file contents */
8608 #ifdef JP
8609         show_file(TRUE, file_name, "Ȭ¤Ä¤ÎÆÁ", 0, 0);
8610 #else
8611         show_file(TRUE, file_name, "Virtues", 0, 0);
8612 #endif
8613
8614         
8615         /* Remove the file */
8616         fd_kill(file_name);
8617 }
8618
8619 /*
8620 * Dungeon
8621 *
8622 */
8623 static void do_cmd_knowledge_dungeon(void)
8624 {
8625         FILE *fff;
8626         
8627         char file_name[1024];
8628         int i;
8629         
8630         
8631         /* Open a new file */
8632         fff = my_fopen_temp(file_name, 1024);
8633         if (!fff) {
8634 #ifdef JP
8635             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8636 #else
8637             msg_format("Failed to create temporary file %s.", file_name);
8638 #endif
8639             msg_print(NULL);
8640             return;
8641         }
8642         
8643         if (fff)
8644         {
8645                 for (i = 1; i < max_d_idx; i++)
8646                 {
8647                         bool seiha = FALSE;
8648
8649                         if (!d_info[i].maxdepth) continue;
8650                         if (!max_dlv[i]) continue;
8651                         if (d_info[i].final_guardian)
8652                         {
8653                                 if (!r_info[d_info[i].final_guardian].max_num) seiha = TRUE;
8654                         }
8655                         else if (max_dlv[i] == d_info[i].maxdepth) seiha = TRUE;
8656 #ifdef JP
8657                         fprintf(fff,"%c%-12s :  %3d ³¬\n", seiha ? '!' : ' ', d_name + d_info[i].name, max_dlv[i]);
8658 #else
8659                         fprintf(fff,"%c%-16s :  level %3d\n", seiha ? '!' : ' ', d_name + d_info[i].name, max_dlv[i]);
8660 #endif
8661                 }
8662         }
8663         
8664         /* Close the file */
8665         my_fclose(fff);
8666         
8667         /* Display the file contents */
8668 #ifdef JP
8669         show_file(TRUE, file_name, "º£¤Þ¤Ç¤ËÆþ¤Ã¤¿¥À¥ó¥¸¥ç¥ó", 0, 0);
8670 #else
8671         show_file(TRUE, file_name, "Dungeon", 0, 0);
8672 #endif
8673
8674         
8675         /* Remove the file */
8676         fd_kill(file_name);
8677 }
8678
8679 /*
8680 * List virtues & status
8681 *
8682 */
8683 static void do_cmd_knowledge_stat(void)
8684 {
8685         FILE *fff;
8686         
8687         char file_name[1024];
8688         int percent, v_nr;
8689         
8690         /* Open a new file */
8691         fff = my_fopen_temp(file_name, 1024);
8692         if (!fff) {
8693 #ifdef JP
8694             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8695 #else
8696             msg_format("Failed to create temporary file %s.", file_name);
8697 #endif
8698             msg_print(NULL);
8699             return;
8700         }
8701         
8702         if (fff)
8703         {
8704                 percent = (int)(((long)p_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
8705                         (2 * p_ptr->hitdie +
8706                         ((PY_MAX_LEVEL - 1+3) * (p_ptr->hitdie + 1))));
8707
8708 #ifdef JP
8709                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "¸½ºß¤ÎÂÎÎÏ¥é¥ó¥¯ : %d/100\n\n", percent);
8710                 else fprintf(fff, "¸½ºß¤ÎÂÎÎÏ¥é¥ó¥¯ : ???\n\n");
8711                 fprintf(fff, "ǽÎϤκÇÂçÃÍ\n\n");
8712 #else
8713                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "Your current Life Rating is %d/100.\n\n", percent);
8714                 else fprintf(fff, "Your current Life Rating is ???.\n\n");
8715                 fprintf(fff, "Limits of maximum stats\n\n");
8716 #endif
8717                 for (v_nr = 0; v_nr < 6; v_nr++)
8718                 {
8719                         if ((p_ptr->knowledge & KNOW_STAT) || p_ptr->stat_max[v_nr] == p_ptr->stat_max_max[v_nr]) fprintf(fff, "%s 18/%d\n", stat_names[v_nr], p_ptr->stat_max_max[v_nr]-18);
8720                         else fprintf(fff, "%s ???\n", stat_names[v_nr]);
8721                 }
8722         }
8723
8724         dump_yourself(fff);
8725
8726         /* Close the file */
8727         my_fclose(fff);
8728         
8729         /* Display the file contents */
8730 #ifdef JP
8731         show_file(TRUE, file_name, "¼«Ê¬¤Ë´Ø¤¹¤ë¾ðÊó", 0, 0);
8732 #else
8733         show_file(TRUE, file_name, "HP-rate & Max stat", 0, 0);
8734 #endif
8735
8736         
8737         /* Remove the file */
8738         fd_kill(file_name);
8739 }
8740
8741
8742 /*
8743  * Print all active quests
8744  */
8745 static void do_cmd_knowledge_quests_current(FILE *fff)
8746 {
8747         char tmp_str[120];
8748         char rand_tmp_str[120] = "\0";
8749         char name[80];
8750         monster_race *r_ptr;
8751         int i;
8752         int rand_level = 100;
8753         int total = 0;
8754
8755 #ifdef JP
8756         fprintf(fff, "¡Ô¿ë¹ÔÃæ¤Î¥¯¥¨¥¹¥È¡Õ\n");
8757 #else
8758         fprintf(fff, "< Current Quest >\n");
8759 #endif
8760
8761         for (i = 1; i < max_quests; i++)
8762         {
8763                 if ((quest[i].status == QUEST_STATUS_TAKEN) || (quest[i].status == QUEST_STATUS_COMPLETED))
8764                 {
8765                         /* Set the quest number temporary */
8766                         int old_quest = p_ptr->inside_quest;
8767                         int j;
8768
8769                         /* Clear the text */
8770                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
8771                         quest_text_line = 0;
8772
8773                         p_ptr->inside_quest = i;
8774
8775                         /* Get the quest text */
8776                         init_flags = INIT_SHOW_TEXT;
8777
8778                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
8779
8780                         /* Reset the old quest number */
8781                         p_ptr->inside_quest = old_quest;
8782
8783                         /* No info from "silent" quests */
8784                         if (quest[i].flags & QUEST_FLAG_SILENT) continue;
8785
8786                         total++;
8787
8788                         if (quest[i].type != QUEST_TYPE_RANDOM)
8789                         {
8790                                 char note[80] = "\0";
8791
8792                                 if (quest[i].status == QUEST_STATUS_TAKEN)
8793                                 {
8794                                         switch (quest[i].type)
8795                                         {
8796                                         case QUEST_TYPE_KILL_LEVEL:
8797                                         case QUEST_TYPE_KILL_ANY_LEVEL:
8798                                                 r_ptr = &r_info[quest[i].r_idx];
8799                                                 strcpy(name, r_name + r_ptr->name);
8800                                                 if (quest[i].max_num > 1)
8801                                                 {
8802 #ifdef JP
8803                                                         sprintf(note," - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
8804                                                                 quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
8805 #else
8806                                                         plural_aux(name);
8807                                                         sprintf(note," - kill %d %s, have killed %d.",
8808                                                                 quest[i].max_num, name, quest[i].cur_num);
8809 #endif
8810                                                 }
8811                                                 else
8812 #ifdef JP
8813                                                         sprintf(note," - %s¤òÅݤ¹¡£",name);
8814 #else
8815                                                         sprintf(note," - kill %s.",name);
8816 #endif
8817                                                 break;
8818
8819                                         case QUEST_TYPE_FIND_ARTIFACT:
8820                                                 strcpy(name, a_name + a_info[quest[i].k_idx].name);
8821 #ifdef JP
8822                                                 sprintf(note," - %s¤ò¸«¤Ä¤±½Ð¤¹¡£", name);
8823 #else
8824                                                 sprintf(note," - Find out %s.", name);
8825 #endif
8826                                                 break;
8827
8828                                         case QUEST_TYPE_FIND_EXIT:
8829 #ifdef JP
8830                                                 sprintf(note," - Ãµº÷¤¹¤ë¡£");
8831 #else
8832                                                 sprintf(note," - Search.");
8833 #endif
8834                                                 break;
8835
8836                                         case QUEST_TYPE_KILL_NUMBER:
8837 #ifdef JP
8838                                                 sprintf(note," - %d ÂΤΥâ¥ó¥¹¥¿¡¼¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
8839                                                         quest[i].max_num, quest[i].max_num - quest[i].cur_num);
8840 #else
8841                                                 sprintf(note," - Kill %d monsters, have killed %d.",
8842                                                         quest[i].max_num, quest[i].cur_num);
8843 #endif
8844                                                 break;
8845
8846                                         case QUEST_TYPE_KILL_ALL:
8847 #ifdef JP
8848                                                 sprintf(note," - Á´¤Æ¤Î¥â¥ó¥¹¥¿¡¼¤òÅݤ¹¡£");
8849 #else
8850                                                 sprintf(note," - Kill all monsters.");
8851 #endif
8852                                                 break;
8853                                         }
8854                                 }
8855
8856                                 /* Print the quest info */
8857 #ifdef JP
8858                                 sprintf(tmp_str, "  %s (´í¸±ÅÙ:%d³¬ÁêÅö)%s\n",
8859                                         quest[i].name, quest[i].level, note);
8860 #else
8861                                 sprintf(tmp_str, "  %s (Danger level: %d)%s\n",
8862                                         quest[i].name, quest[i].level, note);
8863 #endif
8864
8865                                 fprintf(fff, tmp_str);
8866
8867                                 if (quest[i].status == QUEST_STATUS_COMPLETED)
8868                                 {
8869 #ifdef JP
8870                                         sprintf(tmp_str, "    ¥¯¥¨¥¹¥ÈãÀ® - ¤Þ¤ÀÊó½·¤ò¼õ¤±¤È¤Ã¤Æ¤Ê¤¤¡£\n");
8871 #else
8872                                         sprintf(tmp_str, "    Quest Completed - Unrewarded\n");
8873 #endif
8874                                         fprintf(fff, tmp_str);
8875                                 }
8876                                 else
8877                                 {
8878                                         j = 0;
8879
8880                                         while (quest_text[j][0] && j < 10)
8881                                         {
8882                                                 fprintf(fff, "    %s\n", quest_text[j]);
8883                                                 j++;
8884                                         }
8885                                 }
8886                         }
8887                         else if (quest[i].level < rand_level) /* QUEST_TYPE_RANDOM */
8888                         {
8889                                 /* New random */
8890                                 rand_level = quest[i].level;
8891
8892                                 if (max_dlv[DUNGEON_ANGBAND] >= rand_level)
8893                                 {
8894                                         /* Print the quest info */
8895                                         r_ptr = &r_info[quest[i].r_idx];
8896                                         strcpy(name, r_name + r_ptr->name);
8897
8898                                         if (quest[i].max_num > 1)
8899                                         {
8900 #ifdef JP
8901                                                 sprintf(rand_tmp_str,"  %s (%d ³¬) - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)\n",
8902                                                         quest[i].name, quest[i].level,
8903                                                         quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
8904 #else
8905                                                 plural_aux(name);
8906
8907                                                 sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %d %s, have killed %d.\n",
8908                                                         quest[i].name, quest[i].level,
8909                                                         quest[i].max_num, name, quest[i].cur_num);
8910 #endif
8911                                         }
8912                                         else
8913                                         {
8914 #ifdef JP
8915                                                 sprintf(rand_tmp_str,"  %s (%d ³¬) - %s¤òÅݤ¹¡£\n",
8916                                                         quest[i].name, quest[i].level, name);
8917 #else
8918                                                 sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %s.\n",
8919                                                         quest[i].name, quest[i].level, name);
8920 #endif
8921                                         }
8922                                 }
8923                         }
8924                 }
8925         }
8926
8927         /* Print the current random quest  */
8928         if (rand_tmp_str[0]) fprintf(fff, rand_tmp_str);
8929
8930 #ifdef JP
8931         if (!total) fprintf(fff, "  ¤Ê¤·\n");
8932 #else
8933         if (!total) fprintf(fff, "  Nothing.\n");
8934 #endif
8935 }
8936
8937
8938 /*
8939  * Print all finished quests
8940  */
8941 void do_cmd_knowledge_quests_completed(FILE *fff, int quest_num[])
8942 {
8943         char tmp_str[120];
8944         int i;
8945         int total = 0;
8946
8947 #ifdef JP
8948         fprintf(fff, "¡ÔãÀ®¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
8949 #else
8950         fprintf(fff, "< Completed Quest >\n");
8951 #endif
8952         for (i = 1; i < max_quests; i++)
8953         {
8954                 int q_idx = quest_num[i];
8955
8956                 if (quest[q_idx].status == QUEST_STATUS_FINISHED)
8957                 {
8958                         if (is_fixed_quest_idx(q_idx))
8959                         {
8960                                 /* Set the quest number temporary */
8961                                 int old_quest = p_ptr->inside_quest;
8962
8963                                 p_ptr->inside_quest = q_idx;
8964
8965                                 /* Get the quest */
8966                                 init_flags = INIT_ASSIGN;
8967
8968                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
8969
8970                                 /* Reset the old quest number */
8971                                 p_ptr->inside_quest = old_quest;
8972
8973                                 /* No info from "silent" quests */
8974                                 if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
8975                         }
8976
8977                         total++;
8978
8979                         if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
8980                         {
8981                                 /* Print the quest info */
8982
8983                                 if (quest[q_idx].complev == 0)
8984                                 {
8985                                         sprintf(tmp_str,
8986 #ifdef JP
8987                                                 "  %-40s (%3d³¬)            -   ÉÔÀᄀ\n",
8988 #else
8989                                                 "  %-40s (Dungeon level: %3d) - (Cancelled)\n",
8990 #endif
8991                                                 r_name+r_info[quest[q_idx].r_idx].name,
8992                                                 quest[q_idx].level);
8993                                 }
8994                                 else
8995                                 {
8996                                         sprintf(tmp_str,
8997 #ifdef JP
8998                                                 "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
8999 #else
9000                                                 "  %-40s (Dungeon level: %3d) - level %2d\n",
9001 #endif
9002                                                 r_name+r_info[quest[q_idx].r_idx].name,
9003                                                 quest[q_idx].level,
9004                                                 quest[q_idx].complev);
9005                                 }
9006                         }
9007                         else
9008                         {
9009                                 /* Print the quest info */
9010 #ifdef JP
9011                                 sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
9012                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9013 #else
9014                                 sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
9015                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9016 #endif
9017                         }
9018
9019                         fprintf(fff, tmp_str);
9020                 }
9021         }
9022 #ifdef JP
9023         if (!total) fprintf(fff, "  ¤Ê¤·\n");
9024 #else
9025         if (!total) fprintf(fff, "  Nothing.\n");
9026 #endif
9027 }
9028
9029
9030 /*
9031  * Print all failed quests
9032  */
9033 void do_cmd_knowledge_quests_failed(FILE *fff, int quest_num[])
9034 {
9035         char tmp_str[120];
9036         int i;
9037         int total = 0;
9038
9039 #ifdef JP
9040         fprintf(fff, "¡Ô¼ºÇÔ¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
9041 #else
9042         fprintf(fff, "< Failed Quest >\n");
9043 #endif
9044         for (i = 1; i < max_quests; i++)
9045         {
9046                 int q_idx = quest_num[i];
9047
9048                 if ((quest[q_idx].status == QUEST_STATUS_FAILED_DONE) || (quest[q_idx].status == QUEST_STATUS_FAILED))
9049                 {
9050                         if (is_fixed_quest_idx(q_idx))
9051                         {
9052                                 /* Set the quest number temporary */
9053                                 int old_quest = p_ptr->inside_quest;
9054
9055                                 p_ptr->inside_quest = q_idx;
9056
9057                                 /* Get the quest text */
9058                                 init_flags = INIT_ASSIGN;
9059
9060                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
9061
9062                                 /* Reset the old quest number */
9063                                 p_ptr->inside_quest = old_quest;
9064
9065                                 /* No info from "silent" quests */
9066                                 if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
9067                         }
9068
9069                         total++;
9070
9071                         if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
9072                         {
9073                                 /* Print the quest info */
9074 #ifdef JP
9075                                 sprintf(tmp_str, "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
9076                                         r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
9077 #else
9078                                 sprintf(tmp_str, "  %-40s (Dungeon level: %3d) - level %2d\n",
9079                                         r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
9080 #endif
9081                         }
9082                         else
9083                         {
9084                                 /* Print the quest info */
9085 #ifdef JP
9086                                 sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
9087                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9088 #else
9089                                 sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
9090                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9091 #endif
9092                         }
9093                         fprintf(fff, tmp_str);
9094                 }
9095         }
9096 #ifdef JP
9097         if (!total) fprintf(fff, "  ¤Ê¤·\n");
9098 #else
9099         if (!total) fprintf(fff, "  Nothing.\n");
9100 #endif
9101 }
9102
9103
9104 /*
9105  * Print all random quests
9106  */
9107 static void do_cmd_knowledge_quests_wiz_random(FILE *fff)
9108 {
9109         char tmp_str[120];
9110         int i;
9111         int total = 0;
9112
9113 #ifdef JP
9114         fprintf(fff, "¡Ô»Ä¤ê¤Î¥é¥ó¥À¥à¥¯¥¨¥¹¥È¡Õ\n");
9115 #else
9116         fprintf(fff, "< Remaining Random Quest >\n");
9117 #endif
9118         for (i = 1; i < max_quests; i++)
9119         {
9120                 /* No info from "silent" quests */
9121                 if (quest[i].flags & QUEST_FLAG_SILENT) continue;
9122
9123                 if ((quest[i].type == QUEST_TYPE_RANDOM) && (quest[i].status == QUEST_STATUS_TAKEN))
9124                 {
9125                         total++;
9126
9127                         /* Print the quest info */
9128 #ifdef JP
9129                         sprintf(tmp_str, "  %s (%d³¬, %s)\n",
9130                                 quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
9131 #else
9132                         sprintf(tmp_str, "  %s (%d, %s)\n",
9133                                 quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
9134 #endif
9135                         fprintf(fff, tmp_str);
9136                 }
9137         }
9138 #ifdef JP
9139         if (!total) fprintf(fff, "  ¤Ê¤·\n");
9140 #else
9141         if (!total) fprintf(fff, "  Nothing.\n");
9142 #endif
9143 }
9144
9145
9146 bool ang_sort_comp_quest_num(vptr u, vptr v, int a, int b)
9147 {
9148         int *q_num = (int *)u;
9149         quest_type *qa = &quest[q_num[a]];
9150         quest_type *qb = &quest[q_num[b]];
9151
9152         /* Unused */
9153         (void)v;
9154
9155         if (qa->complev < qb->complev) return TRUE;
9156         if (qa->complev > qb->complev) return FALSE;
9157         if (qa->level <= qb->level) return TRUE;
9158         return FALSE;
9159 }
9160
9161 void ang_sort_swap_quest_num(vptr u, vptr v, int a, int b)
9162 {
9163         int *q_num = (int *)u;
9164         int tmp;
9165
9166         /* Unused */
9167         (void)v;
9168
9169         tmp = q_num[a];
9170         q_num[a] = q_num[b];
9171         q_num[b] = tmp;
9172 }
9173
9174
9175 /*
9176  * Print quest status of all active quests
9177  */
9178 static void do_cmd_knowledge_quests(void)
9179 {
9180         FILE *fff;
9181         char file_name[1024];
9182         int *quest_num, dummy, i;
9183
9184         /* Open a new file */
9185         fff = my_fopen_temp(file_name, 1024);
9186         if (!fff)
9187         {
9188 #ifdef JP
9189             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9190 #else
9191             msg_format("Failed to create temporary file %s.", file_name);
9192 #endif
9193             msg_print(NULL);
9194             return;
9195         }
9196
9197         /* Allocate Memory */
9198         C_MAKE(quest_num, max_quests, int);
9199
9200         /* Sort by compete level */
9201         for (i = 1; i < max_quests; i++) quest_num[i] = i;
9202         ang_sort_comp = ang_sort_comp_quest_num;
9203         ang_sort_swap = ang_sort_swap_quest_num;
9204         ang_sort(quest_num, &dummy, max_quests);
9205
9206         /* Dump Quest Information */
9207         do_cmd_knowledge_quests_current(fff);
9208         fputc('\n', fff);
9209         do_cmd_knowledge_quests_completed(fff, quest_num);
9210         fputc('\n', fff);
9211         do_cmd_knowledge_quests_failed(fff, quest_num);
9212         if (p_ptr->wizard)
9213         {
9214                 fputc('\n', fff);
9215                 do_cmd_knowledge_quests_wiz_random(fff);
9216         }
9217
9218         /* Close the file */
9219         my_fclose(fff);
9220
9221         /* Display the file contents */
9222 #ifdef JP
9223         show_file(TRUE, file_name, "¥¯¥¨¥¹¥ÈãÀ®¾õ¶·", 0, 0);
9224 #else
9225         show_file(TRUE, file_name, "Quest status", 0, 0);
9226 #endif
9227
9228         /* Remove the file */
9229         fd_kill(file_name);
9230
9231         /* Free Memory */
9232         C_KILL(quest_num, max_quests, int);
9233 }
9234
9235
9236 /*
9237  * List my home
9238  */
9239 static void do_cmd_knowledge_home(void)
9240 {
9241         FILE *fff;
9242
9243         int i;
9244         char file_name[1024];
9245         store_type  *st_ptr;
9246         char o_name[MAX_NLEN];
9247         cptr            paren = ")";
9248
9249         process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
9250
9251         /* Open a new file */
9252         fff = my_fopen_temp(file_name, 1024);
9253         if (!fff) {
9254 #ifdef JP
9255                 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9256 #else
9257                 msg_format("Failed to create temporary file %s.", file_name);
9258 #endif
9259                 msg_print(NULL);
9260                 return;
9261         }
9262
9263         if (fff)
9264         {
9265                 /* Print all homes in the different towns */
9266                 st_ptr = &town[1].store[STORE_HOME];
9267
9268                 /* Home -- if anything there */
9269                 if (st_ptr->stock_num)
9270                 {
9271 #ifdef JP
9272                         int x = 1;
9273 #endif
9274                         /* Header with name of the town */
9275 #ifdef JP
9276                         fprintf(fff, "  [ ²æ¤¬²È¤Î¥¢¥¤¥Æ¥à ]\n");
9277 #else
9278                         fprintf(fff, "  [Home Inventory]\n");
9279 #endif
9280
9281                         /* Dump all available items */
9282                         for (i = 0; i < st_ptr->stock_num; i++)
9283                         {
9284 #ifdef JP
9285                                 if ((i % 12) == 0) fprintf(fff, "\n ( %d ¥Ú¡¼¥¸ )\n", x++);
9286                                 object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
9287                                 if (strlen(o_name) <= 80-3)
9288                                 {
9289                                         fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
9290                                 }
9291                                 else
9292                                 {
9293                                         int n;
9294                                         char *t;
9295                                         for (n = 0, t = o_name; n < 80-3; n++, t++)
9296                                                 if(iskanji(*t)) {t++; n++;}
9297                                         if (n == 81-3) n = 79-3; /* ºÇ¸å¤¬´Á»úȾʬ */
9298
9299                                         fprintf(fff, "%c%s %.*s\n", I2A(i%12), paren, n, o_name);
9300                                         fprintf(fff, "   %.77s\n", o_name+n);
9301                                 }
9302 #else
9303                                 object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
9304                                 fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
9305 #endif
9306
9307                         }
9308
9309                         /* Add an empty line */
9310                         fprintf(fff, "\n\n");
9311                 }
9312         }
9313
9314         /* Close the file */
9315         my_fclose(fff);
9316
9317         /* Display the file contents */
9318 #ifdef JP
9319         show_file(TRUE, file_name, "²æ¤¬²È¤Î¥¢¥¤¥Æ¥à", 0, 0);
9320 #else
9321         show_file(TRUE, file_name, "Home Inventory", 0, 0);
9322 #endif
9323
9324
9325         /* Remove the file */
9326         fd_kill(file_name);
9327 }
9328
9329
9330 /*
9331  * Check the status of "autopick"
9332  */
9333 static void do_cmd_knowledge_autopick(void)
9334 {
9335         int k;
9336         FILE *fff;
9337         char file_name[1024];
9338
9339         /* Open a new file */
9340         fff = my_fopen_temp(file_name, 1024);
9341
9342         if (!fff)
9343         {
9344 #ifdef JP
9345             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9346 #else
9347             msg_format("Failed to create temporary file %s.", file_name);
9348 #endif
9349             msg_print(NULL);
9350             return;
9351         }
9352
9353         if (!max_autopick)
9354         {
9355 #ifdef JP
9356             fprintf(fff, "¼«Æ°Ç˲õ/½¦¤¤¤Ë¤Ï²¿¤âÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
9357 #else
9358             fprintf(fff, "No preference for auto picker/destroyer.");
9359 #endif
9360         }
9361         else
9362         {
9363 #ifdef JP
9364             fprintf(fff, "   ¼«Æ°½¦¤¤/Ç˲õ¤Ë¤Ï¸½ºß %d¹ÔÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤¹¡£\n\n", max_autopick);
9365 #else
9366             fprintf(fff, "   There are %d registered lines for auto picker/destroyer.\n\n", max_autopick);
9367 #endif
9368         }
9369
9370         for (k = 0; k < max_autopick; k++)
9371         {
9372                 cptr tmp;
9373                 byte act = autopick_list[k].action;
9374                 if (act & DONT_AUTOPICK)
9375                 {
9376 #ifdef JP
9377                         tmp = "ÊüÃÖ";
9378 #else
9379                         tmp = "Leave";
9380 #endif
9381                 }
9382                 else if (act & DO_AUTODESTROY)
9383                 {
9384 #ifdef JP
9385                         tmp = "Ç˲õ";
9386 #else
9387                         tmp = "Destroy";
9388 #endif
9389                 }
9390                 else if (act & DO_AUTOPICK)
9391                 {
9392 #ifdef JP
9393                         tmp = "½¦¤¦";
9394 #else
9395                         tmp = "Pickup";
9396 #endif
9397                 }
9398                 else /* if (act & DO_QUERY_AUTOPICK) */ /* Obvious */
9399                 {
9400 #ifdef JP
9401                         tmp = "³Îǧ";
9402 #else
9403                         tmp = "Query";
9404 #endif
9405                 }
9406
9407                 if (act & DO_DISPLAY)
9408                         fprintf(fff, "%11s", format("[%s]", tmp));
9409                 else
9410                         fprintf(fff, "%11s", format("(%s)", tmp));
9411
9412                 tmp = autopick_line_from_entry(&autopick_list[k]);
9413                 fprintf(fff, " %s", tmp);
9414                 string_free(tmp);
9415                 fprintf(fff, "\n");
9416         }
9417         /* Close the file */
9418         my_fclose(fff);
9419         /* Display the file contents */
9420 #ifdef JP
9421         show_file(TRUE, file_name, "¼«Æ°½¦¤¤/Ç˲õ ÀßÄê¥ê¥¹¥È", 0, 0);
9422 #else
9423         show_file(TRUE, file_name, "Auto-picker/Destroyer", 0, 0);
9424 #endif
9425
9426         /* Remove the file */
9427         fd_kill(file_name);
9428 }
9429
9430
9431 /*
9432  * Interact with "knowledge"
9433  */
9434 void do_cmd_knowledge(void)
9435 {
9436         int i,p=0;
9437         /* File type is "TEXT" */
9438         FILE_TYPE(FILE_TYPE_TEXT);
9439         /* Save the screen */
9440         screen_save();
9441         /* Interact until done */
9442         while (1)
9443         {
9444                 /* Clear screen */
9445                 Term_clear();
9446                 /* Ask for a choice */
9447 #ifdef JP
9448                 prt(format("%d/2 ¥Ú¡¼¥¸", (p+1)), 2, 65);
9449                 prt("¸½ºß¤ÎÃ챤ò³Îǧ¤¹¤ë", 3, 0);
9450 #else
9451                 prt(format("page %d/2", (p+1)), 2, 65);
9452                 prt("Display current knowledge", 3, 0);
9453 #endif
9454
9455                 /* Give some choices */
9456 #ifdef JP
9457                 if (p == 0) {
9458                         prt("(1) ´ûÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à                 ¤Î°ìÍ÷", 6, 5);
9459                         prt("(2) ´ûÃΤΥ¢¥¤¥Æ¥à                       ¤Î°ìÍ÷", 7, 5);
9460                         prt("(3) ´ûÃΤÎÀ¸¤­¤Æ¤¤¤ë¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ ¤Î°ìÍ÷", 8, 5);
9461                         prt("(4) ´ûÃΤΥâ¥ó¥¹¥¿¡¼                     ¤Î°ìÍ÷", 9, 5);
9462                         prt("(5) Åݤ·¤¿Å¨¤Î¿ô                         ¤Î°ìÍ÷", 10, 5);
9463                         if (!vanilla_town) prt("(6) ¾Þ¶â¼ó                               ¤Î°ìÍ÷", 11, 5);
9464                         prt("(7) ¸½ºß¤Î¥Ú¥Ã¥È                         ¤Î°ìÍ÷", 12, 5);
9465                         prt("(8) ²æ¤¬²È¤Î¥¢¥¤¥Æ¥à                     ¤Î°ìÍ÷", 13, 5);
9466                         prt("(9) *´ÕÄê*ºÑ¤ßÁõÈ÷¤ÎÂÑÀ­                 ¤Î°ìÍ÷", 14, 5);
9467                         prt("(0) ÃÏ·Á¤Îɽ¼¨Ê¸»ú/¥¿¥¤¥ë                ¤Î°ìÍ÷", 15, 5);
9468                 } else {
9469                         prt("(a) ¼«Ê¬¤Ë´Ø¤¹¤ë¾ðÊó                     ¤Î°ìÍ÷", 6, 5);
9470                         prt("(b) ÆÍÁ³ÊÑ°Û                             ¤Î°ìÍ÷", 7, 5);
9471                         prt("(c) Éð´ï¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 8, 5);
9472                         prt("(d) ËâË¡¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 9, 5);
9473                         prt("(e) µ»Ç½¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 10, 5);
9474                         prt("(f) ¥×¥ì¥¤¥ä¡¼¤ÎÆÁ                       ¤Î°ìÍ÷", 11, 5);
9475                         prt("(g) Æþ¤Ã¤¿¥À¥ó¥¸¥ç¥ó                     ¤Î°ìÍ÷", 12, 5);
9476                         prt("(h) ¼Â¹ÔÃæ¤Î¥¯¥¨¥¹¥È                     ¤Î°ìÍ÷", 13, 5);
9477                         prt("(i) ¸½ºß¤Î¼«Æ°½¦¤¤/Ç˲õÀßÄê              ¤Î°ìÍ÷", 14, 5);
9478                 }
9479 #else
9480                 if (p == 0) {
9481                         prt("(1) Display known artifacts", 6, 5);
9482                         prt("(2) Display known objects", 7, 5);
9483                         prt("(3) Display remaining uniques", 8, 5);
9484                         prt("(4) Display known monster", 9, 5);
9485                         prt("(5) Display kill count", 10, 5);
9486                         if (!vanilla_town) prt("(6) Display wanted monsters", 11, 5);
9487                         prt("(7) Display current pets", 12, 5);
9488                         prt("(8) Display home inventory", 13, 5);
9489                         prt("(9) Display *identified* equip.", 14, 5);
9490                         prt("(0) Display terrain symbols.", 15, 5);
9491                 } else {
9492                         prt("(a) Display about yourself", 6, 5);
9493                         prt("(b) Display mutations", 7, 5);
9494                         prt("(c) Display weapon proficiency", 8, 5);
9495                         prt("(d) Display spell proficiency", 9, 5);
9496                         prt("(e) Display misc. proficiency", 10, 5);
9497                         prt("(f) Display virtues", 11, 5);
9498                         prt("(g) Display dungeons", 12, 5);
9499                         prt("(h) Display current quests", 13, 5);
9500                         prt("(i) Display auto pick/destroy", 14, 5);
9501                 }
9502 #endif
9503                 /* Prompt */
9504 #ifdef JP
9505                 prt("-³¤¯-", 17, 8);
9506                 prt("ESC) È´¤±¤ë", 21, 1);
9507                 prt("SPACE) ¼¡¥Ú¡¼¥¸", 21, 30);
9508                 /*prt("-) Á°¥Ú¡¼¥¸", 21, 60);*/
9509                 prt("¥³¥Þ¥ó¥É:", 20, 0);
9510 #else
9511                 prt("-more-", 17, 8);
9512                 prt("ESC) Exit menu", 21, 1);
9513                 prt("SPACE) Next page", 21, 30);
9514                 /*prt("-) Previous page", 21, 60);*/
9515                 prt("Command: ", 20, 0);
9516 #endif
9517
9518                 /* Prompt */
9519                 i = inkey();
9520                 /* Done */
9521                 if (i == ESCAPE) break;
9522                 switch (i)
9523                 {
9524                 case ' ': /* Page change */
9525                 case '-':
9526                         p = 1 - p;
9527                         break;
9528                 case '1': /* Artifacts */
9529                         do_cmd_knowledge_artifacts();
9530                         break;
9531                 case '2': /* Objects */
9532                         do_cmd_knowledge_objects();
9533                         break;
9534                 case '3': /* Uniques */
9535                         do_cmd_knowledge_uniques();
9536                         break;
9537                 case '4': /* Monsters */
9538                         do_cmd_knowledge_monsters();
9539                         break;
9540                 case '5': /* Kill count  */
9541                         do_cmd_knowledge_kill_count();
9542                         break;
9543                 case '6': /* wanted */
9544                         if (!vanilla_town) do_cmd_knowledge_kubi();
9545                         break;
9546                 case '7': /* Pets */
9547                         do_cmd_knowledge_pets();
9548                         break;
9549                 case '8': /* Home */
9550                         do_cmd_knowledge_home();
9551                         break;
9552                 case '9': /* Resist list */
9553                         do_cmd_knowledge_inven();
9554                         break;
9555                 case '0': /* Feature list */
9556                         do_cmd_knowledge_features();
9557                         break;
9558                 /* Next page */
9559                 case 'a': /* Max stat */
9560                         do_cmd_knowledge_stat();
9561                         break;
9562                 case 'b': /* Mutations */
9563                         do_cmd_knowledge_mutations();
9564                         break;
9565                 case 'c': /* weapon-exp */
9566                         do_cmd_knowledge_weapon_exp();
9567                         break;
9568                 case 'd': /* spell-exp */
9569                         do_cmd_knowledge_spell_exp();
9570                         break;
9571                 case 'e': /* skill-exp */
9572                         do_cmd_knowledge_skill_exp();
9573                         break;
9574                 case 'f': /* Virtues */
9575                         do_cmd_knowledge_virtues();
9576                         break;
9577                 case 'g': /* Dungeon */
9578                         do_cmd_knowledge_dungeon();
9579                         break;
9580                 case 'h': /* Quests */
9581                         do_cmd_knowledge_quests();
9582                         break;
9583                 case 'i': /* Autopick */
9584                         do_cmd_knowledge_autopick();
9585                         break;
9586                 default: /* Unknown option */
9587                         bell();
9588                 }
9589                 /* Flush messages */
9590                 msg_print(NULL);
9591         }
9592         /* Restore the screen */
9593         screen_load();
9594 }
9595
9596
9597 /*
9598  * Check on the status of an active quest
9599  */
9600 void do_cmd_checkquest(void)
9601 {
9602         /* File type is "TEXT" */
9603         FILE_TYPE(FILE_TYPE_TEXT);
9604
9605         /* Save the screen */
9606         screen_save();
9607
9608         /* Quest info */
9609         do_cmd_knowledge_quests();
9610
9611         /* Restore the screen */
9612         screen_load();
9613 }
9614
9615
9616 /*
9617  * Display the time and date
9618  */
9619 void do_cmd_time(void)
9620 {
9621         int day, hour, min, full, start, end, num;
9622         char desc[1024];
9623
9624         char buf[1024];
9625
9626         FILE *fff;
9627
9628         extract_day_hour_min(&day, &hour, &min);
9629
9630         full = hour * 100 + min;
9631
9632         start = 9999;
9633         end = -9999;
9634
9635         num = 0;
9636
9637 #ifdef JP
9638         strcpy(desc, "ÊѤʻþ¹ï¤À¡£");
9639 #else
9640         strcpy(desc, "It is a strange time.");
9641 #endif
9642
9643
9644         /* Message */
9645 #ifdef JP
9646         msg_format("%d ÆüÌÜ,»þ¹ï¤Ï%d:%02d %s¤Ç¤¹¡£",
9647                    day, (hour % 12 == 0) ? 12 : (hour % 12),
9648                    min, (hour < 12) ? "AM" : "PM");
9649 #else
9650         msg_format("This is day %d. The time is %d:%02d %s.",
9651                    day, (hour % 12 == 0) ? 12 : (hour % 12),
9652                    min, (hour < 12) ? "AM" : "PM");
9653 #endif
9654
9655
9656         /* Find the path */
9657         if (!randint0(10) || p_ptr->image)
9658         {
9659 #ifdef JP
9660                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun_j.txt");
9661 #else
9662                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun.txt");
9663 #endif
9664
9665         }
9666         else
9667         {
9668 #ifdef JP
9669                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm_j.txt");
9670 #else
9671                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm.txt");
9672 #endif
9673
9674         }
9675
9676         /* Open this file */
9677         fff = my_fopen(buf, "rt");
9678
9679         /* Oops */
9680         if (!fff) return;
9681
9682         /* Find this time */
9683         while (!my_fgets(fff, buf, sizeof(buf)))
9684         {
9685                 /* Ignore comments */
9686                 if (!buf[0] || (buf[0] == '#')) continue;
9687
9688                 /* Ignore invalid lines */
9689                 if (buf[1] != ':') continue;
9690
9691                 /* Process 'Start' */
9692                 if (buf[0] == 'S')
9693                 {
9694                         /* Extract the starting time */
9695                         start = atoi(buf + 2);
9696
9697                         /* Assume valid for an hour */
9698                         end = start + 59;
9699
9700                         /* Next... */
9701                         continue;
9702                 }
9703
9704                 /* Process 'End' */
9705                 if (buf[0] == 'E')
9706                 {
9707                         /* Extract the ending time */
9708                         end = atoi(buf + 2);
9709
9710                         /* Next... */
9711                         continue;
9712                 }
9713
9714                 /* Ignore incorrect range */
9715                 if ((start > full) || (full > end)) continue;
9716
9717                 /* Process 'Description' */
9718                 if (buf[0] == 'D')
9719                 {
9720                         num++;
9721
9722                         /* Apply the randomizer */
9723                         if (!randint0(num)) strcpy(desc, buf + 2);
9724
9725                         /* Next... */
9726                         continue;
9727                 }
9728         }
9729
9730         /* Message */
9731         msg_print(desc);
9732
9733         /* Close the file */
9734         my_fclose(fff);
9735 }