OSDN Git Service

知識コマンド内で「乗馬可能なモンスター」をリスト表示。
[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("[ ¥ª¥×¥·¥ç¥ó¤ÎÀßÄê ]", 1, 0);
2291 #else
2292                 prt("Options", 1, 0);
2293 #endif
2294
2295
2296                 /* Give some choices */
2297 #ifdef JP
2298                 prt("(1)     ¥­¡¼ÆþÎÏ          ¥ª¥×¥·¥ç¥ó", 2, 5);
2299                 prt("(2)     ²èÌ̽ÐÎÏ          ¥ª¥×¥·¥ç¥ó", 3, 5);
2300                 prt("(3)   ¥²¡¼¥à¥×¥ì¥¤        ¥ª¥×¥·¥ç¥ó", 4, 5);
2301                 prt("(4)   ¹ÔÆ°Ãæ»ß´Ø·¸        ¥ª¥×¥·¥ç¥ó", 5, 5);
2302                 prt("(5)      ¸úΨ²½           ¥ª¥×¥·¥ç¥ó", 6, 5);
2303                 prt("(6) ´Ê°×¥¢¥¤¥Æ¥à¼«Æ°Ç˲õ  ¥ª¥×¥·¥ç¥ó", 7, 5);
2304                 prt("(R)    ¥×¥ì¥¤µ­Ï¿         ¥ª¥×¥·¥ç¥ó", 8, 5);
2305
2306                 /* Special choices */
2307                 prt("(P) ¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿", 10, 5);
2308                 prt("(D)  ´ðËÜ¥¦¥§¥¤¥ÈÎÌ", 11, 5);
2309                 prt("(H) Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð", 12, 5);
2310                 prt("(M)   ÄãËâÎÏ¿§ïçÃÍ", 13, 5);
2311                 prt("(A)    ¼«Æ°¥»¡¼¥Ö         ¥ª¥×¥·¥ç¥ó", 14, 5);
2312                 /* Window flags */
2313                 prt("(W) ¥¦¥¤¥ó¥É¥¦¥Õ¥é¥°", 15, 5);
2314 #else
2315                 prt("(1) Input Options", 2, 5);
2316                 prt("(2) Output Options", 3, 5);
2317                 prt("(3) Game-Play Options", 4, 5);
2318                 prt("(4) Disturbance Options", 5, 5);
2319                 prt("(5) Efficiency Options", 6, 5);
2320                 prt("(6) Easy Auto-Destroyer Options", 7, 5);
2321                 prt("(R) Play-record Options", 8, 5);
2322                 /* Special choices */
2323                 prt("(P) Auto-picker/destroyer editor", 10, 5);
2324                 prt("(D) Base Delay Factor", 11, 5);
2325                 prt("(H) Hitpoint Warning", 12, 5);
2326                 prt("(M) Mana Color Threshold", 13, 5);
2327                 prt("(A) Autosave Options", 14, 5);
2328                 /* Window flags */
2329                 prt("(W) Window Flags", 15, 5);
2330 #endif
2331
2332                 if (!p_ptr->wizard || !allow_debug_opts)
2333                 {
2334                         /* Birth */
2335 #ifdef JP
2336                         prt("(B)      ½é´ü            ¥ª¥×¥·¥ç¥ó (»²¾È¤Î¤ß)", 16, 5);
2337 #else
2338                         prt("(B) Birth Options (Browse Only)", 16, 5);
2339 #endif
2340                 }
2341                 else
2342                 {
2343                         /* Birth */
2344 #ifdef JP
2345                         prt("(B)      ½é´ü            ¥ª¥×¥·¥ç¥ó", 16, 5);
2346 #else
2347                         prt("(B) Birth Options", 16, 5);
2348 #endif
2349                 }
2350
2351
2352                 if (p_ptr->noscore || allow_debug_opts)
2353                 {
2354                         /* Cheating */
2355 #ifdef JP
2356                         prt("(C)      º¾µ½            ¥ª¥×¥·¥ç¥ó", 17, 5);
2357 #else
2358                         prt("(C) Cheating Options", 17, 5);
2359 #endif
2360                 }
2361
2362
2363                 /* Prompt */
2364 #ifdef JP
2365                 prt("¥³¥Þ¥ó¥É:", 19, 0);
2366 #else
2367                 prt("Command: ", 19, 0);
2368 #endif
2369
2370
2371                 /* Get command */
2372                 k = inkey();
2373
2374                 /* Exit */
2375                 if (k == ESCAPE) break;
2376
2377                 /* Analyze */
2378                 switch (k)
2379                 {
2380                         /* General Options */
2381                         case '1':
2382                         {
2383                                 /* Process the general options */
2384 #ifdef JP
2385                                 do_cmd_options_aux(1, "¥­¡¼ÆþÎÏ¥ª¥×¥·¥ç¥ó");
2386 #else
2387                                 do_cmd_options_aux(1, "Input Options");
2388 #endif
2389
2390                                 break;
2391                         }
2392
2393                         /* General Options */
2394                         case '2':
2395                         {
2396                                 /* Process the general options */
2397 #ifdef JP
2398                                 do_cmd_options_aux(2, "²èÌ̽ÐÎÏ¥ª¥×¥·¥ç¥ó");
2399 #else
2400                                 do_cmd_options_aux(2, "Output Options");
2401 #endif
2402
2403                                 break;
2404                         }
2405
2406                         /* Inventory Options */
2407                         case '3':
2408                         {
2409                                 /* Spawn */
2410 #ifdef JP
2411                                 do_cmd_options_aux(3, "¥²¡¼¥à¥×¥ì¥¤¡¦¥ª¥×¥·¥ç¥ó");
2412 #else
2413                                 do_cmd_options_aux(3, "Game-Play Options");
2414 #endif
2415
2416                                 break;
2417                         }
2418
2419                         /* Disturbance Options */
2420                         case '4':
2421                         {
2422                                 /* Spawn */
2423 #ifdef JP
2424                                 do_cmd_options_aux(4, "¹ÔÆ°Ãæ»ß´Ø·¸¤Î¥ª¥×¥·¥ç¥ó");
2425 #else
2426                                 do_cmd_options_aux(4, "Disturbance Options");
2427 #endif
2428
2429                                 break;
2430                         }
2431
2432                         /* Efficiency Options */
2433                         case '5':
2434                         {
2435                                 /* Spawn */
2436 #ifdef JP
2437                                 do_cmd_options_aux(5, "¸úΨ²½¥ª¥×¥·¥ç¥ó");
2438 #else
2439                                 do_cmd_options_aux(5, "Efficiency Options");
2440 #endif
2441
2442                                 break;
2443                         }
2444
2445                         /* Object auto-destruction Options */
2446                         case '6':
2447                         {
2448                                 /* Spawn */
2449 #ifdef JP
2450                                 do_cmd_options_aux(7, "´Ê°×¥¢¥¤¥Æ¥à¼«Æ°Ç˲õ¥ª¥×¥·¥ç¥ó");
2451 #else
2452                                 do_cmd_options_aux(7, "Easy Auto-Destroyer Options");
2453 #endif
2454                                 break;
2455                         }
2456
2457                         /* Play-record Options */
2458                         case 'R':
2459                         case 'r':
2460                         {
2461                                 /* Spawn */
2462 #ifdef JP
2463                                 do_cmd_options_aux(10, "¥×¥ì¥¤µ­Ï¿¥ª¥×¥·¥ç¥ó");
2464 #else
2465                                 do_cmd_options_aux(10, "Play-record Options");
2466 #endif
2467                                 break;
2468                         }
2469
2470                         /* Birth Options */
2471                         case 'B':
2472                         case 'b':
2473                         {
2474                                 /* Spawn */
2475 #ifdef JP
2476                                 do_cmd_options_aux(6, (!p_ptr->wizard || !allow_debug_opts) ? "½é´ü¥ª¥×¥·¥ç¥ó(»²¾È¤Î¤ß)" : "½é´ü¥ª¥×¥·¥ç¥ó((*)¤Ï¥¹¥³¥¢¤Ë±Æ¶Á)");
2477 #else
2478                                 do_cmd_options_aux(6, (!p_ptr->wizard || !allow_debug_opts) ? "Birth Options(browse only)" : "Birth Options((*)s effect score)");
2479 #endif
2480
2481                                 break;
2482                         }
2483
2484                         /* Cheating Options */
2485                         case 'C':
2486                         {
2487                                 if (!p_ptr->noscore && !allow_debug_opts)
2488                                 {
2489                                         /* Cheat options are not permitted */
2490                                         bell();
2491                                         break;
2492                                 }
2493
2494                                 /* Spawn */
2495 #ifdef JP
2496                                 do_cmd_options_cheat("º¾µ½»Õ¤Ï·è¤·¤Æ¾¡Íø¤Ç¤­¤Ê¤¤¡ª");
2497 #else
2498                                 do_cmd_options_cheat("Cheaters never win");
2499 #endif
2500
2501                                 break;
2502                         }
2503
2504                         case 'a':
2505                         case 'A':
2506                         {
2507 #ifdef JP
2508                                 do_cmd_options_autosave("¼«Æ°¥»¡¼¥Ö");
2509 #else
2510                                 do_cmd_options_autosave("Autosave");
2511 #endif
2512
2513                                 break;
2514                         }
2515
2516                         /* Window flags */
2517                         case 'W':
2518                         case 'w':
2519                         {
2520                                 /* Spawn */
2521                                 do_cmd_options_win();
2522                                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL |
2523                                                   PW_PLAYER | PW_MESSAGE | PW_OVERHEAD |
2524                                                   PW_MONSTER | PW_OBJECT | PW_SNAPSHOT |
2525                                                   PW_BORG_1 | PW_BORG_2 | PW_DUNGEON);
2526                                 break;
2527                         }
2528
2529                         /* Auto-picker/destroyer editor */
2530                         case 'P':
2531                         case 'p':
2532                         {
2533                                 do_cmd_edit_autopick();
2534                                 break;
2535                         }
2536
2537                         /* Hack -- Delay Speed */
2538                         case 'D':
2539                         case 'd':
2540                         {
2541                                 /* Prompt */
2542 #ifdef JP
2543                                 prt("¥³¥Þ¥ó¥É: ´ðËÜ¥¦¥§¥¤¥ÈÎÌ", 19, 0);
2544 #else
2545                                 prt("Command: Base Delay Factor", 19, 0);
2546 #endif
2547
2548
2549                                 /* Get a new value */
2550                                 while (1)
2551                                 {
2552                                         int msec = delay_factor * delay_factor * delay_factor;
2553 #ifdef JP
2554                                         prt(format("¸½ºß¤Î¥¦¥§¥¤¥È: %d (%d¥ß¥êÉÃ)",
2555                                                    delay_factor, msec), 22, 0);
2556 #else
2557                                         prt(format("Current base delay factor: %d (%d msec)",
2558                                                    delay_factor, msec), 22, 0);
2559 #endif
2560
2561 #ifdef JP
2562                                         prt("¥¦¥§¥¤¥È (0-9) ESC¤Ç·èÄê: ", 20, 0);
2563 #else
2564                                         prt("Delay Factor (0-9 or ESC to accept): ", 20, 0);
2565 #endif
2566
2567                                         k = inkey();
2568                                         if (k == ESCAPE) break;
2569                                         else if (k == '?')
2570                                         {
2571 #ifdef JP
2572                                                 (void)show_file(TRUE, "joption.txt#BaseDelay", NULL, 0, 0);
2573 #else
2574                                                 (void)show_file(TRUE, "option.txt#BaseDelay", NULL, 0, 0);
2575 #endif
2576                                                 Term_clear(); 
2577                                         }
2578                                         else if (isdigit(k)) delay_factor = D2I(k);
2579                                         else bell();
2580                                 }
2581
2582                                 break;
2583                         }
2584
2585                         /* Hack -- hitpoint warning factor */
2586                         case 'H':
2587                         case 'h':
2588                         {
2589                                 /* Prompt */
2590 #ifdef JP
2591                                 prt("¥³¥Þ¥ó¥É: Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð", 19, 0);
2592 #else
2593                                 prt("Command: Hitpoint Warning", 19, 0);
2594 #endif
2595
2596
2597                                 /* Get a new value */
2598                                 while (1)
2599                                 {
2600 #ifdef JP
2601                                         prt(format("¸½ºß¤ÎÄã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð: %d0%%",
2602                                                    hitpoint_warn), 22, 0);
2603 #else
2604                                         prt(format("Current hitpoint warning: %d0%%",
2605                                                    hitpoint_warn), 22, 0);
2606 #endif
2607
2608 #ifdef JP
2609                                         prt("Äã¥Ò¥Ã¥È¥Ý¥¤¥ó¥È·Ù¹ð (0-9) ESC¤Ç·èÄê: ", 20, 0);
2610 #else
2611                                         prt("Hitpoint Warning (0-9 or ESC to accept): ", 20, 0);
2612 #endif
2613
2614                                         k = inkey();
2615                                         if (k == ESCAPE) break;
2616                                         else if (k == '?')
2617                                         {
2618 #ifdef JP
2619                                                 (void)show_file(TRUE, "joption.txt#Hitpoint", NULL, 0, 0);
2620 #else
2621                                                 (void)show_file(TRUE, "option.txt#Hitpoint", NULL, 0, 0);
2622 #endif
2623                                                 Term_clear(); 
2624                                         }
2625                                         else if (isdigit(k)) hitpoint_warn = D2I(k);
2626                                         else bell();
2627                                 }
2628
2629                                 break;
2630                         }
2631
2632                         /* Hack -- mana color factor */
2633                         case 'M':
2634                         case 'm':
2635                         {
2636                                 /* Prompt */
2637 #ifdef JP
2638                                 prt("¥³¥Þ¥ó¥É: ÄãËâÎÏ¿§ïçÃÍ", 19, 0);
2639 #else
2640                                 prt("Command: Mana Color Threshold", 19, 0);
2641 #endif
2642
2643
2644                                 /* Get a new value */
2645                                 while (1)
2646                                 {
2647 #ifdef JP
2648                                         prt(format("¸½ºß¤ÎÄãËâÎÏ¿§ïçÃÍ: %d0%%",
2649                                                    mana_warn), 22, 0);
2650 #else
2651                                         prt(format("Current mana color threshold: %d0%%",
2652                                                    mana_warn), 22, 0);
2653 #endif
2654
2655 #ifdef JP
2656                                         prt("ÄãËâÎÏïçÃÍ (0-9) ESC¤Ç·èÄê: ", 20, 0);
2657 #else
2658                                         prt("Mana color Threshold (0-9 or ESC to accept): ", 20, 0);
2659 #endif
2660
2661                                         k = inkey();
2662                                         if (k == ESCAPE) break;
2663                                         else if (k == '?')
2664                                         {
2665 #ifdef JP
2666                                                 (void)show_file(TRUE, "joption.txt#Manapoint", NULL, 0, 0);
2667 #else
2668                                                 (void)show_file(TRUE, "option.txt#Manapoint", NULL, 0, 0);
2669 #endif
2670                                                 Term_clear(); 
2671                                         }
2672                                         else if (isdigit(k)) mana_warn = D2I(k);
2673                                         else bell();
2674                                 }
2675
2676                                 break;
2677                         }
2678
2679                         case '?':
2680 #ifdef JP
2681                                 (void)show_file(TRUE, "joption.txt", NULL, 0, 0);
2682 #else
2683                                 (void)show_file(TRUE, "option.txt", NULL, 0, 0);
2684 #endif
2685                                 Term_clear(); 
2686                                 break;
2687
2688                         /* Unknown option */
2689                         default:
2690                         {
2691                                 /* Oops */
2692                                 bell();
2693                                 break;
2694                         }
2695                 }
2696
2697                 /* Flush messages */
2698                 msg_print(NULL);
2699         }
2700
2701
2702         /* Restore the screen */
2703         screen_load();
2704
2705         /* Hack - Redraw equippy chars */
2706         p_ptr->redraw |= (PR_EQUIPPY);
2707 }
2708
2709
2710
2711 /*
2712  * Ask for a "user pref line" and process it
2713  *
2714  * XXX XXX XXX Allow absolute file names?
2715  */
2716 void do_cmd_pref(void)
2717 {
2718         char buf[80];
2719
2720         /* Default */
2721         strcpy(buf, "");
2722
2723         /* Ask for a "user pref command" */
2724 #ifdef JP
2725         if (!get_string("ÀßÄêÊѹ¹¥³¥Þ¥ó¥É: ", buf, 80)) return;
2726 #else
2727         if (!get_string("Pref: ", buf, 80)) return;
2728 #endif
2729
2730
2731         /* Process that pref command */
2732         (void)process_pref_file_command(buf);
2733 }
2734
2735 void do_cmd_pickpref(void)
2736 {
2737         char buf[80];
2738         errr err;
2739
2740 #ifdef JP
2741         if(!get_check("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤·¤Þ¤¹¤«? ")) return;
2742 #else
2743         if(!get_check("Reload auto-pick preference file? ")) return;
2744 #endif
2745
2746         /* Free old entries */
2747         init_autopicker();
2748
2749         /* ¥­¥ã¥éËè¤ÎÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß */
2750 #ifdef JP
2751         sprintf(buf, "picktype-%s.prf", player_name);
2752 #else
2753         sprintf(buf, "pickpref-%s.prf", player_name);
2754 #endif
2755         err = process_pickpref_file(buf);
2756
2757         if(err == 0)
2758         {
2759 #ifdef JP
2760                 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
2761 #else
2762                 msg_format("loaded '%s'.", buf);
2763 #endif
2764         }
2765
2766         /* ¶¦Ä̤ÎÀßÄê¥Õ¥¡¥¤¥ëÆɤ߹þ¤ß */
2767
2768         /* Process 'pick????.prf' if 'pick????-<name>.prf' doesn't exist */
2769         if (0 > err)
2770         {
2771 #ifdef JP
2772                 err = process_pickpref_file("picktype.prf");
2773 #else
2774                 err = process_pickpref_file("pickpref.prf");
2775 #endif
2776
2777                 if(err == 0)
2778                 {
2779 #ifdef JP
2780                         msg_print("picktype.prf¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£");
2781 #else
2782                         msg_print("loaded 'pickpref.prf'.");
2783 #endif
2784                 }
2785         }
2786
2787
2788 #ifdef JP
2789         if(err) msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
2790 #else
2791         if(err) msg_print("Failed to reload autopick preference.");
2792 #endif
2793 }
2794
2795 #ifdef ALLOW_MACROS
2796
2797 /*
2798  * Hack -- append all current macros to the given file
2799  */
2800 static errr macro_dump(cptr fname)
2801 {
2802         static cptr mark = "Macro Dump";
2803
2804         int i;
2805
2806         char buf[1024];
2807
2808         /* Build the filename */
2809         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2810
2811         /* File type is "TEXT" */
2812         FILE_TYPE(FILE_TYPE_TEXT);
2813
2814         /* Append to the file */
2815         if (!open_auto_dump(buf, mark)) return (-1);
2816
2817         /* Start dumping */
2818 #ifdef JP
2819         auto_dump_printf("\n# ¼«Æ°¥Þ¥¯¥í¥»¡¼¥Ö\n\n");
2820 #else
2821         auto_dump_printf("\n# Automatic macro dump\n\n");
2822 #endif
2823
2824         /* Dump them */
2825         for (i = 0; i < macro__num; i++)
2826         {
2827                 /* Extract the action */
2828                 ascii_to_text(buf, macro__act[i]);
2829
2830                 /* Dump the macro */
2831                 auto_dump_printf("A:%s\n", buf);
2832
2833                 /* Extract the action */
2834                 ascii_to_text(buf, macro__pat[i]);
2835
2836                 /* Dump normal macros */
2837                 auto_dump_printf("P:%s\n", buf);
2838
2839                 /* End the macro */
2840                 auto_dump_printf("\n");
2841         }
2842
2843         /* Close */
2844         close_auto_dump();
2845
2846         /* Success */
2847         return (0);
2848 }
2849
2850
2851 /*
2852  * Hack -- ask for a "trigger" (see below)
2853  *
2854  * Note the complex use of the "inkey()" function from "util.c".
2855  *
2856  * Note that both "flush()" calls are extremely important.
2857  */
2858 static void do_cmd_macro_aux(char *buf)
2859 {
2860         int i, n = 0;
2861
2862         char tmp[1024];
2863
2864
2865         /* Flush */
2866         flush();
2867
2868         /* Do not process macros */
2869         inkey_base = TRUE;
2870
2871         /* First key */
2872         i = inkey();
2873
2874         /* Read the pattern */
2875         while (i)
2876         {
2877                 /* Save the key */
2878                 buf[n++] = i;
2879
2880                 /* Do not process macros */
2881                 inkey_base = TRUE;
2882
2883                 /* Do not wait for keys */
2884                 inkey_scan = TRUE;
2885
2886                 /* Attempt to read a key */
2887                 i = inkey();
2888         }
2889
2890         /* Terminate */
2891         buf[n] = '\0';
2892
2893         /* Flush */
2894         flush();
2895
2896
2897         /* Convert the trigger */
2898         ascii_to_text(tmp, buf);
2899
2900         /* Hack -- display the trigger */
2901         Term_addstr(-1, TERM_WHITE, tmp);
2902 }
2903
2904 #endif
2905
2906
2907 /*
2908  * Hack -- ask for a keymap "trigger" (see below)
2909  *
2910  * Note that both "flush()" calls are extremely important.  This may
2911  * no longer be true, since "util.c" is much simpler now.  XXX XXX XXX
2912  */
2913 static void do_cmd_macro_aux_keymap(char *buf)
2914 {
2915         char tmp[1024];
2916
2917
2918         /* Flush */
2919         flush();
2920
2921
2922         /* Get a key */
2923         buf[0] = inkey();
2924         buf[1] = '\0';
2925
2926
2927         /* Convert to ascii */
2928         ascii_to_text(tmp, buf);
2929
2930         /* Hack -- display the trigger */
2931         Term_addstr(-1, TERM_WHITE, tmp);
2932
2933
2934         /* Flush */
2935         flush();
2936 }
2937
2938
2939 /*
2940  * Hack -- append all keymaps to the given file
2941  */
2942 static errr keymap_dump(cptr fname)
2943 {
2944         static cptr mark = "Keymap Dump";
2945         int i;
2946
2947         char key[1024];
2948         char buf[1024];
2949
2950         int mode;
2951
2952         /* Roguelike */
2953         if (rogue_like_commands)
2954         {
2955                 mode = KEYMAP_MODE_ROGUE;
2956         }
2957
2958         /* Original */
2959         else
2960         {
2961                 mode = KEYMAP_MODE_ORIG;
2962         }
2963
2964
2965         /* Build the filename */
2966         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
2967
2968         /* File type is "TEXT" */
2969         FILE_TYPE(FILE_TYPE_TEXT);
2970
2971         /* Append to the file */
2972         if (!open_auto_dump(buf, mark)) return -1;
2973
2974         /* Start dumping */
2975 #ifdef JP
2976         auto_dump_printf("\n# ¼«Æ°¥­¡¼ÇÛÃÖ¥»¡¼¥Ö\n\n");
2977 #else
2978         auto_dump_printf("\n# Automatic keymap dump\n\n");
2979 #endif
2980
2981         /* Dump them */
2982         for (i = 0; i < 256; i++)
2983         {
2984                 cptr act;
2985
2986                 /* Loop up the keymap */
2987                 act = keymap_act[mode][i];
2988
2989                 /* Skip empty keymaps */
2990                 if (!act) continue;
2991
2992                 /* Encode the key */
2993                 buf[0] = i;
2994                 buf[1] = '\0';
2995                 ascii_to_text(key, buf);
2996
2997                 /* Encode the action */
2998                 ascii_to_text(buf, act);
2999
3000                 /* Dump the macro */
3001                 auto_dump_printf("A:%s\n", buf);
3002                 auto_dump_printf("C:%d:%s\n", mode, key);
3003         }
3004
3005         /* Close */
3006         close_auto_dump();
3007
3008         /* Success */
3009         return (0);
3010 }
3011
3012
3013
3014 /*
3015  * Interact with "macros"
3016  *
3017  * Note that the macro "action" must be defined before the trigger.
3018  *
3019  * Could use some helpful instructions on this page.  XXX XXX XXX
3020  */
3021 void do_cmd_macros(void)
3022 {
3023         int i;
3024
3025         char tmp[1024];
3026
3027         char buf[1024];
3028
3029         int mode;
3030
3031
3032         /* Roguelike */
3033         if (rogue_like_commands)
3034         {
3035                 mode = KEYMAP_MODE_ROGUE;
3036         }
3037
3038         /* Original */
3039         else
3040         {
3041                 mode = KEYMAP_MODE_ORIG;
3042         }
3043
3044         /* File type is "TEXT" */
3045         FILE_TYPE(FILE_TYPE_TEXT);
3046
3047
3048         /* Save screen */
3049         screen_save();
3050
3051
3052         /* Process requests until done */
3053         while (1)
3054         {
3055                 /* Clear screen */
3056                 Term_clear();
3057
3058                 /* Describe */
3059 #ifdef JP
3060                 prt("[ ¥Þ¥¯¥í¤ÎÀßÄê ]", 2, 0);
3061 #else
3062                 prt("Interact with Macros", 2, 0);
3063 #endif
3064
3065
3066
3067                 /* Describe that action */
3068 #ifdef JP
3069                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3070 #else
3071                 prt("Current action (if any) shown below:", 20, 0);
3072 #endif
3073
3074
3075                 /* Analyze the current action */
3076                 ascii_to_text(buf, macro__buf);
3077
3078                 /* Display the current action */
3079                 prt(buf, 22, 0);
3080
3081
3082                 /* Selections */
3083 #ifdef JP
3084                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3085 #else
3086                 prt("(1) Load a user pref file", 4, 5);
3087 #endif
3088
3089 #ifdef ALLOW_MACROS
3090 #ifdef JP
3091                 prt("(2) ¥Õ¥¡¥¤¥ë¤Ë¥Þ¥¯¥í¤òÄɲÃ", 5, 5);
3092                 prt("(3) ¥Þ¥¯¥í¤Î³Îǧ", 6, 5);
3093                 prt("(4) ¥Þ¥¯¥í¤ÎºîÀ®", 7, 5);
3094                 prt("(5) ¥Þ¥¯¥í¤Îºï½ü", 8, 5);
3095                 prt("(6) ¥Õ¥¡¥¤¥ë¤Ë¥­¡¼ÇÛÃÖ¤òÄɲÃ", 9, 5);
3096                 prt("(7) ¥­¡¼ÇÛÃ֤γÎǧ", 10, 5);
3097                 prt("(8) ¥­¡¼ÇÛÃ֤κîÀ®", 11, 5);
3098                 prt("(9) ¥­¡¼ÇÛÃ֤κï½ü", 12, 5);
3099                 prt("(0) ¥Þ¥¯¥í¹ÔÆ°¤ÎÆþÎÏ", 13, 5);
3100 #else
3101                 prt("(2) Append macros to a file", 5, 5);
3102                 prt("(3) Query a macro", 6, 5);
3103                 prt("(4) Create a macro", 7, 5);
3104                 prt("(5) Remove a macro", 8, 5);
3105                 prt("(6) Append keymaps to a file", 9, 5);
3106                 prt("(7) Query a keymap", 10, 5);
3107                 prt("(8) Create a keymap", 11, 5);
3108                 prt("(9) Remove a keymap", 12, 5);
3109                 prt("(0) Enter a new action", 13, 5);
3110 #endif
3111
3112 #endif /* ALLOW_MACROS */
3113
3114                 /* Prompt */
3115 #ifdef JP
3116                 prt("¥³¥Þ¥ó¥É: ", 16, 0);
3117 #else
3118                 prt("Command: ", 16, 0);
3119 #endif
3120
3121
3122                 /* Get a command */
3123                 i = inkey();
3124
3125                 /* Leave */
3126                 if (i == ESCAPE) break;
3127
3128                 /* Load a 'macro' file */
3129                 else if (i == '1')
3130                 {
3131                         errr err;
3132
3133                         /* Prompt */
3134 #ifdef JP
3135                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 16, 0);
3136 #else
3137                         prt("Command: Load a user pref file", 16, 0);
3138 #endif
3139
3140
3141                         /* Prompt */
3142 #ifdef JP
3143                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3144 #else
3145                         prt("File: ", 18, 0);
3146 #endif
3147
3148
3149                         /* Default filename */
3150                         sprintf(tmp, "%s.prf", player_name);
3151
3152                         /* Ask for a file */
3153                         if (!askfor_aux(tmp, 80)) continue;
3154
3155                         /* Process the given filename */
3156                         err = process_pref_file(tmp);
3157                         if (-2 == err)
3158                         {
3159 #ifdef JP
3160                                 msg_format("ɸ½à¤ÎÀßÄê¥Õ¥¡¥¤¥ë'%s'¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", tmp);
3161 #else
3162                                 msg_format("Loaded default '%s'.", tmp);
3163 #endif
3164                         }
3165                         else if (err)
3166                         {
3167                                 /* Prompt */
3168 #ifdef JP
3169                                 msg_format("'%s'¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡ª", tmp);
3170 #else
3171                                 msg_format("Failed to load '%s'!");
3172 #endif
3173                         }
3174                         else
3175                         {
3176 #ifdef JP
3177                                 msg_format("'%s'¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", tmp);
3178 #else
3179                                 msg_format("Loaded '%s'.", tmp);
3180 #endif
3181                         }
3182                 }
3183
3184 #ifdef ALLOW_MACROS
3185
3186                 /* Save macros */
3187                 else if (i == '2')
3188                 {
3189                         /* Prompt */
3190 #ifdef JP
3191                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤ò¥Õ¥¡¥¤¥ë¤ËÄɲ乤ë", 16, 0);
3192 #else
3193                         prt("Command: Append macros to a file", 16, 0);
3194 #endif
3195
3196
3197                         /* Prompt */
3198 #ifdef JP
3199                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3200 #else
3201                         prt("File: ", 18, 0);
3202 #endif
3203
3204
3205                         /* Default filename */
3206                         sprintf(tmp, "%s.prf", player_name);
3207
3208                         /* Ask for a file */
3209                         if (!askfor_aux(tmp, 80)) continue;
3210
3211                         /* Dump the macros */
3212                         (void)macro_dump(tmp);
3213
3214                         /* Prompt */
3215 #ifdef JP
3216                         msg_print("¥Þ¥¯¥í¤òÄɲä·¤Þ¤·¤¿¡£");
3217 #else
3218                         msg_print("Appended macros.");
3219 #endif
3220
3221                 }
3222
3223                 /* Query a macro */
3224                 else if (i == '3')
3225                 {
3226                         int k;
3227
3228                         /* Prompt */
3229 #ifdef JP
3230                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤Î³Îǧ", 16, 0);
3231 #else
3232                         prt("Command: Query a macro", 16, 0);
3233 #endif
3234
3235
3236                         /* Prompt */
3237 #ifdef JP
3238                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3239 #else
3240                         prt("Trigger: ", 18, 0);
3241 #endif
3242
3243
3244                         /* Get a macro trigger */
3245                         do_cmd_macro_aux(buf);
3246
3247                         /* Acquire action */
3248                         k = macro_find_exact(buf);
3249
3250                         /* Nothing found */
3251                         if (k < 0)
3252                         {
3253                                 /* Prompt */
3254 #ifdef JP
3255                                 msg_print("¤½¤Î¥­¡¼¤Ë¤Ï¥Þ¥¯¥í¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
3256 #else
3257                                 msg_print("Found no macro.");
3258 #endif
3259
3260                         }
3261
3262                         /* Found one */
3263                         else
3264                         {
3265                                 /* Obtain the action */
3266                                 strcpy(macro__buf, macro__act[k]);
3267
3268                                 /* Analyze the current action */
3269                                 ascii_to_text(buf, macro__buf);
3270
3271                                 /* Display the current action */
3272                                 prt(buf, 22, 0);
3273
3274                                 /* Prompt */
3275 #ifdef JP
3276                                 msg_print("¥Þ¥¯¥í¤ò³Îǧ¤·¤Þ¤·¤¿¡£");
3277 #else
3278                                 msg_print("Found a macro.");
3279 #endif
3280
3281                         }
3282                 }
3283
3284                 /* Create a macro */
3285                 else if (i == '4')
3286                 {
3287                         /* Prompt */
3288 #ifdef JP
3289                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤ÎºîÀ®", 16, 0);
3290 #else
3291                         prt("Command: Create a macro", 16, 0);
3292 #endif
3293
3294
3295                         /* Prompt */
3296 #ifdef JP
3297                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3298 #else
3299                         prt("Trigger: ", 18, 0);
3300 #endif
3301
3302
3303                         /* Get a macro trigger */
3304                         do_cmd_macro_aux(buf);
3305
3306                         /* Clear */
3307                         clear_from(20);
3308
3309                         /* Prompt */
3310 #ifdef JP
3311                         prt("¥Þ¥¯¥í¹ÔÆ°: ", 20, 0);
3312 #else
3313                         prt("Action: ", 20, 0);
3314 #endif
3315
3316
3317                         /* Convert to text */
3318                         ascii_to_text(tmp, macro__buf);
3319
3320                         /* Get an encoded action */
3321                         if (askfor_aux(tmp, 80))
3322                         {
3323                                 /* Convert to ascii */
3324                                 text_to_ascii(macro__buf, tmp);
3325
3326                                 /* Link the macro */
3327                                 macro_add(buf, macro__buf);
3328
3329                                 /* Prompt */
3330 #ifdef JP
3331                                 msg_print("¥Þ¥¯¥í¤òÄɲä·¤Þ¤·¤¿¡£");
3332 #else
3333                                 msg_print("Added a macro.");
3334 #endif
3335
3336                         }
3337                 }
3338
3339                 /* Remove a macro */
3340                 else if (i == '5')
3341                 {
3342                         /* Prompt */
3343 #ifdef JP
3344                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¤Îºï½ü", 16, 0);
3345 #else
3346                         prt("Command: Remove a macro", 16, 0);
3347 #endif
3348
3349
3350                         /* Prompt */
3351 #ifdef JP
3352                         prt("¥È¥ê¥¬¡¼¥­¡¼: ", 18, 0);
3353 #else
3354                         prt("Trigger: ", 18, 0);
3355 #endif
3356
3357
3358                         /* Get a macro trigger */
3359                         do_cmd_macro_aux(buf);
3360
3361                         /* Link the macro */
3362                         macro_add(buf, buf);
3363
3364                         /* Prompt */
3365 #ifdef JP
3366                         msg_print("¥Þ¥¯¥í¤òºï½ü¤·¤Þ¤·¤¿¡£");
3367 #else
3368                         msg_print("Removed a macro.");
3369 #endif
3370
3371                 }
3372
3373                 /* Save keymaps */
3374                 else if (i == '6')
3375                 {
3376                         /* Prompt */
3377 #ifdef JP
3378                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃÖ¤ò¥Õ¥¡¥¤¥ë¤ËÄɲ乤ë", 16, 0);
3379 #else
3380                         prt("Command: Append keymaps to a file", 16, 0);
3381 #endif
3382
3383
3384                         /* Prompt */
3385 #ifdef JP
3386                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3387 #else
3388                         prt("File: ", 18, 0);
3389 #endif
3390
3391
3392                         /* Default filename */
3393                         sprintf(tmp, "%s.prf", player_name);
3394
3395                         /* Ask for a file */
3396                         if (!askfor_aux(tmp, 80)) continue;
3397
3398                         /* Dump the macros */
3399                         (void)keymap_dump(tmp);
3400
3401                         /* Prompt */
3402 #ifdef JP
3403                         msg_print("¥­¡¼ÇÛÃÖ¤òÄɲä·¤Þ¤·¤¿¡£");
3404 #else
3405                         msg_print("Appended keymaps.");
3406 #endif
3407
3408                 }
3409
3410                 /* Query a keymap */
3411                 else if (i == '7')
3412                 {
3413                         cptr act;
3414
3415                         /* Prompt */
3416 #ifdef JP
3417                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤γÎǧ", 16, 0);
3418 #else
3419                         prt("Command: Query a keymap", 16, 0);
3420 #endif
3421
3422
3423                         /* Prompt */
3424 #ifdef JP
3425                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3426 #else
3427                         prt("Keypress: ", 18, 0);
3428 #endif
3429
3430
3431                         /* Get a keymap trigger */
3432                         do_cmd_macro_aux_keymap(buf);
3433
3434                         /* Look up the keymap */
3435                         act = keymap_act[mode][(byte)(buf[0])];
3436
3437                         /* Nothing found */
3438                         if (!act)
3439                         {
3440                                 /* Prompt */
3441 #ifdef JP
3442                                 msg_print("¥­¡¼ÇÛÃÖ¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
3443 #else
3444                                 msg_print("Found no keymap.");
3445 #endif
3446
3447                         }
3448
3449                         /* Found one */
3450                         else
3451                         {
3452                                 /* Obtain the action */
3453                                 strcpy(macro__buf, act);
3454
3455                                 /* Analyze the current action */
3456                                 ascii_to_text(buf, macro__buf);
3457
3458                                 /* Display the current action */
3459                                 prt(buf, 22, 0);
3460
3461                                 /* Prompt */
3462 #ifdef JP
3463                                 msg_print("¥­¡¼ÇÛÃÖ¤ò³Îǧ¤·¤Þ¤·¤¿¡£");
3464 #else
3465                                 msg_print("Found a keymap.");
3466 #endif
3467
3468                         }
3469                 }
3470
3471                 /* Create a keymap */
3472                 else if (i == '8')
3473                 {
3474                         /* Prompt */
3475 #ifdef JP
3476                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤κîÀ®", 16, 0);
3477 #else
3478                         prt("Command: Create a keymap", 16, 0);
3479 #endif
3480
3481
3482                         /* Prompt */
3483 #ifdef JP
3484                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3485 #else
3486                         prt("Keypress: ", 18, 0);
3487 #endif
3488
3489
3490                         /* Get a keymap trigger */
3491                         do_cmd_macro_aux_keymap(buf);
3492
3493                         /* Clear */
3494                         clear_from(20);
3495
3496                         /* Prompt */
3497 #ifdef JP
3498                         prt("¹ÔÆ°: ", 20, 0);
3499 #else
3500                         prt("Action: ", 20, 0);
3501 #endif
3502
3503
3504                         /* Convert to text */
3505                         ascii_to_text(tmp, macro__buf);
3506
3507                         /* Get an encoded action */
3508                         if (askfor_aux(tmp, 80))
3509                         {
3510                                 /* Convert to ascii */
3511                                 text_to_ascii(macro__buf, tmp);
3512
3513                                 /* Free old keymap */
3514                                 string_free(keymap_act[mode][(byte)(buf[0])]);
3515
3516                                 /* Make new keymap */
3517                                 keymap_act[mode][(byte)(buf[0])] = string_make(macro__buf);
3518
3519                                 /* Prompt */
3520 #ifdef JP
3521                                 msg_print("¥­¡¼ÇÛÃÖ¤òÄɲä·¤Þ¤·¤¿¡£");
3522 #else
3523                                 msg_print("Added a keymap.");
3524 #endif
3525
3526                         }
3527                 }
3528
3529                 /* Remove a keymap */
3530                 else if (i == '9')
3531                 {
3532                         /* Prompt */
3533 #ifdef JP
3534                         prt("¥³¥Þ¥ó¥É: ¥­¡¼ÇÛÃ֤κï½ü", 16, 0);
3535 #else
3536                         prt("Command: Remove a keymap", 16, 0);
3537 #endif
3538
3539
3540                         /* Prompt */
3541 #ifdef JP
3542                         prt("²¡¤¹¥­¡¼: ", 18, 0);
3543 #else
3544                         prt("Keypress: ", 18, 0);
3545 #endif
3546
3547
3548                         /* Get a keymap trigger */
3549                         do_cmd_macro_aux_keymap(buf);
3550
3551                         /* Free old keymap */
3552                         string_free(keymap_act[mode][(byte)(buf[0])]);
3553
3554                         /* Make new keymap */
3555                         keymap_act[mode][(byte)(buf[0])] = NULL;
3556
3557                         /* Prompt */
3558 #ifdef JP
3559                         msg_print("¥­¡¼ÇÛÃÖ¤òºï½ü¤·¤Þ¤·¤¿¡£");
3560 #else
3561                         msg_print("Removed a keymap.");
3562 #endif
3563
3564                 }
3565
3566                 /* Enter a new action */
3567                 else if (i == '0')
3568                 {
3569                         /* Prompt */
3570 #ifdef JP
3571                         prt("¥³¥Þ¥ó¥É: ¥Þ¥¯¥í¹ÔÆ°¤ÎÆþÎÏ", 16, 0);
3572 #else
3573                         prt("Command: Enter a new action", 16, 0);
3574 #endif
3575
3576
3577                         /* Go to the correct location */
3578                         Term_gotoxy(0, 22);
3579
3580                         /* Hack -- limit the value */
3581                         tmp[80] = '\0';
3582
3583                         /* Get an encoded action */
3584                         if (!askfor_aux(buf, 80)) continue;
3585
3586                         /* Extract an action */
3587                         text_to_ascii(macro__buf, buf);
3588                 }
3589
3590 #endif /* ALLOW_MACROS */
3591
3592                 /* Oops */
3593                 else
3594                 {
3595                         /* Oops */
3596                         bell();
3597                 }
3598
3599                 /* Flush messages */
3600                 msg_print(NULL);
3601         }
3602
3603         /* Load screen */
3604         screen_load();
3605 }
3606
3607
3608 static void cmd_visuals_aux(int i, int *num, int max)
3609 {
3610         if (iscntrl(i))
3611         {
3612                 char str[10] = "";
3613                 int tmp;
3614
3615                 sprintf(str, "%d", *num);
3616
3617                 if (!get_string(format("Input new number(0-%d): ", max-1), str, 4))
3618                         return;
3619
3620                 tmp = strtol(str, NULL, 0);
3621                 if (tmp >= 0 && tmp < max)
3622                         *num = tmp;
3623                 return;
3624         }
3625         else if (isupper(i))
3626                 *num = (*num + max - 1) % max;
3627         else
3628                 *num = (*num + 1) % max;
3629
3630         return;
3631 }
3632
3633 /*
3634  * Interact with "visuals"
3635  */
3636 void do_cmd_visuals(void)
3637 {
3638         int i;
3639
3640         char tmp[160];
3641
3642         char buf[1024];
3643
3644         const char *empty_symbol = "<< ? >>";
3645
3646         if (use_bigtile) empty_symbol = "<< ?? >>";
3647
3648         /* File type is "TEXT" */
3649         FILE_TYPE(FILE_TYPE_TEXT);
3650
3651
3652         /* Save the screen */
3653         screen_save();
3654
3655
3656         /* Interact until done */
3657         while (1)
3658         {
3659                 /* Clear screen */
3660                 Term_clear();
3661
3662                 /* Ask for a choice */
3663 #ifdef JP
3664                 prt("²èÌÌɽ¼¨¤ÎÀßÄê", 2, 0);
3665 #else
3666                 prt("Interact with Visuals", 2, 0);
3667 #endif
3668
3669
3670                 /* Give some choices */
3671 #ifdef JP
3672                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
3673 #else
3674                 prt("(1) Load a user pref file", 4, 5);
3675 #endif
3676
3677 #ifdef ALLOW_VISUALS
3678 #ifdef JP
3679                 prt("(2) ¥â¥ó¥¹¥¿¡¼¤Î ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 5, 5);
3680                 prt("(3) ¥¢¥¤¥Æ¥à¤Î   ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 6, 5);
3681                 prt("(4) ÃÏ·Á¤Î       ¿§/ʸ»ú ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 7, 5);
3682                 prt("(5) (̤»ÈÍÑ)", 8, 5);
3683                 prt("(6) ¥â¥ó¥¹¥¿¡¼¤Î ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 9, 5);
3684                 prt("(7) ¥¢¥¤¥Æ¥à¤Î   ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 10, 5);
3685                 prt("(8) ÃÏ·Á¤Î       ¿§/ʸ»ú ¤òÊѹ¹¤¹¤ë", 11, 5);
3686                 prt("(9) (̤»ÈÍÑ)", 12, 5);
3687 #else
3688                 prt("(2) Dump monster attr/chars", 5, 5);
3689                 prt("(3) Dump object attr/chars", 6, 5);
3690                 prt("(4) Dump feature attr/chars", 7, 5);
3691                 prt("(5) (unused)", 8, 5);
3692                 prt("(6) Change monster attr/chars", 9, 5);
3693                 prt("(7) Change object attr/chars", 10, 5);
3694                 prt("(8) Change feature attr/chars", 11, 5);
3695                 prt("(9) (unused)", 12, 5);
3696 #endif
3697
3698 #endif
3699 #ifdef JP
3700                 prt("(0) ²èÌÌɽ¼¨ÊýË¡¤Î½é´ü²½", 13, 5);
3701 #else
3702                 prt("(0) Reset visuals", 13, 5);
3703 #endif
3704
3705
3706                 /* Prompt */
3707 #ifdef JP
3708                 prt("¥³¥Þ¥ó¥É:", 18, 0);
3709 #else
3710                 prt("Command: ", 15, 0);
3711 #endif
3712
3713
3714                 /* Prompt */
3715                 i = inkey();
3716
3717                 /* Done */
3718                 if (i == ESCAPE) break;
3719
3720                 /* Load a 'pref' file */
3721                 else if (i == '1')
3722                 {
3723                         /* Prompt */
3724 #ifdef JP
3725                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 15, 0);
3726 #else
3727                         prt("Command: Load a user pref file", 15, 0);
3728 #endif
3729
3730
3731                         /* Prompt */
3732 #ifdef JP
3733                         prt("¥Õ¥¡¥¤¥ë: ", 18, 0);
3734 #else
3735                         prt("File: ", 17, 0);
3736 #endif
3737
3738
3739                         /* Default filename */
3740                         sprintf(tmp, "%s.prf", player_name);
3741
3742                         /* Query */
3743                         if (!askfor_aux(tmp, 70)) continue;
3744
3745                         /* Process the given filename */
3746                         (void)process_pref_file(tmp);
3747                 }
3748
3749 #ifdef ALLOW_VISUALS
3750
3751                 /* Dump monster attr/chars */
3752                 else if (i == '2')
3753                 {
3754                         static cptr mark = "Monster attr/chars";
3755
3756                         /* Prompt */
3757 #ifdef JP
3758                         prt("¥³¥Þ¥ó¥É: ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3759 #else
3760                         prt("Command: Dump monster attr/chars", 15, 0);
3761 #endif
3762
3763
3764                         /* Prompt */
3765 #ifdef JP
3766                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3767 #else
3768                         prt("File: ", 17, 0);
3769 #endif
3770
3771
3772                         /* Default filename */
3773                         sprintf(tmp, "%s.prf", player_name);
3774                         
3775                         /* Get a filename */
3776                         if (!askfor_aux(tmp, 70)) continue;
3777
3778                         /* Build the filename */
3779                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3780
3781                         /* Append to the file */
3782                         if (!open_auto_dump(buf, mark)) continue;
3783
3784                         /* Start dumping */
3785 #ifdef JP
3786                         auto_dump_printf("\n# ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3787 #else
3788                         auto_dump_printf("\n# Monster attr/char definitions\n\n");
3789 #endif
3790
3791                         /* Dump monsters */
3792                         for (i = 1; i < max_r_idx; i++)
3793                         {
3794                                 monster_race *r_ptr = &r_info[i];
3795
3796                                 /* Skip non-entries */
3797                                 if (!r_ptr->name) continue;
3798
3799                                 /* Dump a comment */
3800                                 auto_dump_printf("# %s\n", (r_name + r_ptr->name));
3801
3802                                 /* Dump the monster attr/char info */
3803                                 auto_dump_printf("R:%d:0x%02X/0x%02X\n\n", i,
3804                                         (byte)(r_ptr->x_attr), (byte)(r_ptr->x_char));
3805                         }
3806
3807                         /* Close */
3808                         close_auto_dump();
3809
3810                         /* Message */
3811 #ifdef JP
3812                         msg_print("¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3813 #else
3814                         msg_print("Dumped monster attr/chars.");
3815 #endif
3816
3817                 }
3818
3819                 /* Dump object attr/chars */
3820                 else if (i == '3')
3821                 {
3822                         static cptr mark = "Object attr/chars";
3823
3824                         /* Prompt */
3825 #ifdef JP
3826                         prt("¥³¥Þ¥ó¥É: ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3827 #else
3828                         prt("Command: Dump object attr/chars", 15, 0);
3829 #endif
3830
3831
3832                         /* Prompt */
3833 #ifdef JP
3834                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3835 #else
3836                         prt("File: ", 17, 0);
3837 #endif
3838
3839
3840                         /* Default filename */
3841                         sprintf(tmp, "%s.prf", player_name);
3842
3843                         /* Get a filename */
3844                         if (!askfor_aux(tmp, 70)) continue;
3845
3846                         /* Build the filename */
3847                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3848
3849                         /* Append to the file */
3850                         if (!open_auto_dump(buf, mark)) continue;
3851
3852                         /* Start dumping */
3853 #ifdef JP
3854                         auto_dump_printf("\n# ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3855 #else
3856                         auto_dump_printf("\n# Object attr/char definitions\n\n");
3857 #endif
3858
3859                         /* Dump objects */
3860                         for (i = 1; i < max_k_idx; i++)
3861                         {
3862                                 char o_name[80];
3863                                 object_kind *k_ptr = &k_info[i];
3864
3865                                 /* Skip non-entries */
3866                                 if (!k_ptr->name) continue;
3867
3868                                 /* Skip entries with flavor */
3869                                 if (k_ptr->flavor) continue;
3870
3871                                 /* Tidy name */
3872                                 strip_name(o_name, i);
3873
3874                                 /* Dump a comment */
3875                                 auto_dump_printf("# %s\n", o_name);
3876
3877                                 /* Dump the object attr/char info */
3878                                 auto_dump_printf("K:%d:0x%02X/0x%02X\n\n", i,
3879                                         (byte)(k_ptr->x_attr), (byte)(k_ptr->x_char));
3880                         }
3881
3882                         /* Close */
3883                         close_auto_dump();
3884
3885                         /* Message */
3886 #ifdef JP
3887                         msg_print("¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3888 #else
3889                         msg_print("Dumped object attr/chars.");
3890 #endif
3891
3892                 }
3893
3894                 /* Dump feature attr/chars */
3895                 else if (i == '4')
3896                 {
3897                         static cptr mark = "Feature attr/chars";
3898
3899                         /* Prompt */
3900 #ifdef JP
3901                         prt("¥³¥Þ¥ó¥É: ÃÏ·Á¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 15, 0);
3902 #else
3903                         prt("Command: Dump feature attr/chars", 15, 0);
3904 #endif
3905
3906
3907                         /* Prompt */
3908 #ifdef JP
3909                         prt("¥Õ¥¡¥¤¥ë: ", 17, 0);
3910 #else
3911                         prt("File: ", 17, 0);
3912 #endif
3913
3914
3915                         /* Default filename */
3916                         sprintf(tmp, "%s.prf", player_name);
3917
3918                         /* Get a filename */
3919                         if (!askfor_aux(tmp, 70)) continue;
3920
3921                         /* Build the filename */
3922                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
3923
3924                         /* Append to the file */
3925                         if (!open_auto_dump(buf, mark)) continue;
3926
3927                         /* Start dumping */
3928 #ifdef JP
3929                         auto_dump_printf("\n# ÃÏ·Á¤Î[¿§/ʸ»ú]¤ÎÀßÄê\n\n");
3930 #else
3931                         auto_dump_printf("\n# Feature attr/char definitions\n\n");
3932 #endif
3933
3934                         /* Dump features */
3935                         for (i = 1; i < max_f_idx; i++)
3936                         {
3937                                 feature_type *f_ptr = &f_info[i];
3938
3939                                 /* Skip non-entries */
3940                                 if (!f_ptr->name) continue;
3941
3942                                 /* Skip mimiccing features */
3943                                 if (f_ptr->mimic != i) continue;
3944
3945                                 /* Dump a comment */
3946                                 auto_dump_printf("# %s\n", (f_name + f_ptr->name));
3947
3948                                 /* Dump the feature attr/char info */
3949                                 auto_dump_printf("F:%d:0x%02X/0x%02X\n\n", i,
3950                                         (byte)(f_ptr->x_attr), (byte)(f_ptr->x_char));
3951                         }
3952
3953                         /* Close */
3954                         close_auto_dump();
3955
3956                         /* Message */
3957 #ifdef JP
3958                         msg_print("ÃÏ·Á¤Î[¿§/ʸ»ú]¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
3959 #else
3960                         msg_print("Dumped feature attr/chars.");
3961 #endif
3962
3963                 }
3964
3965                 /* Modify monster attr/chars */
3966                 else if (i == '6')
3967                 {
3968                         static int r = 0;
3969
3970                         /* Prompt */
3971 #ifdef JP
3972                         prt("¥³¥Þ¥ó¥É: ¥â¥ó¥¹¥¿¡¼¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
3973 #else
3974                         prt("Command: Change monster attr/chars", 15, 0);
3975 #endif
3976
3977
3978                         /* Hack -- query until done */
3979                         while (1)
3980                         {
3981                                 monster_race *r_ptr = &r_info[r];
3982                                 byte a, a2;
3983                                 char c, c2;
3984                                 int t;
3985
3986                                 byte da = (r_ptr->d_attr);
3987                                 byte dc = (r_ptr->d_char);
3988                                 byte ca = (r_ptr->x_attr);
3989                                 byte cc = (r_ptr->x_char);
3990
3991                                 /* Label the object */
3992 #ifdef JP
3993                                 Term_putstr(5, 17, -1, TERM_WHITE,
3994                                             format("¥â¥ó¥¹¥¿¡¼ = %d, Ì¾Á° = %-40.40s",
3995                                                    r, (r_name + r_ptr->name)));
3996 #else
3997                                 Term_putstr(5, 17, -1, TERM_WHITE,
3998                                             format("Monster = %d, Name = %-40.40s",
3999                                                    r, (r_name + r_ptr->name)));
4000 #endif
4001
4002
4003                                 /* Label the Default values */
4004 #ifdef JP
4005                                 Term_putstr(10, 19, -1, TERM_WHITE,
4006                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3u / %3u", da, dc));
4007 #else
4008                                 Term_putstr(10, 19, -1, TERM_WHITE,
4009                                             format("Default attr/char = %3u / %3u", da, dc));
4010 #endif
4011
4012                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4013
4014                                 a = da;
4015                                 c = dc;
4016                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4017
4018                                 Term_putch(43, 19, a, c);
4019                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4020
4021                                 /* Label the Current values */
4022 #ifdef JP
4023                                 Term_putstr(10, 20, -1, TERM_WHITE,
4024                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3u / %3u", ca, cc));
4025 #else
4026                                 Term_putstr(10, 20, -1, TERM_WHITE,
4027                                             format("Current attr/char = %3u / %3u", ca, cc));
4028 #endif
4029
4030                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4031
4032                                 a = ca;
4033                                 c = cc;
4034                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4035
4036                                 Term_putch(43, 20, a, c);
4037                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4038
4039
4040                                 /* Prompt */
4041 #ifdef JP
4042                                 Term_putstr(0, 22, -1, TERM_WHITE,
4043                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4044 #else
4045                                 Term_putstr(0, 22, -1, TERM_WHITE,
4046                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4047 #endif
4048
4049                                 /* Get a command */
4050                                 i = inkey();
4051
4052                                 /* All done */
4053                                 if (i == ESCAPE) break;
4054
4055                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4056                                 else if (isupper(i)) c = 'a' + i - 'A';
4057                                 else c = i;
4058
4059                                 switch (c)
4060                                 {
4061                                 case 'n':
4062                                         cmd_visuals_aux(i, &r, max_r_idx);
4063                                         break;
4064                                 case 'a':
4065                                         t = (int)r_ptr->x_attr;
4066                                         cmd_visuals_aux(i, &t, 256);
4067                                         r_ptr->x_attr = (byte)t;
4068                                         break;
4069                                 case 'c':
4070                                         t = (int)r_ptr->x_char;
4071                                         cmd_visuals_aux(i, &t, 256);
4072                                         r_ptr->x_char = (byte)t;
4073                                         break;
4074                                 }
4075                         }
4076                 }
4077
4078                 /* Modify object attr/chars */
4079                 else if (i == '7')
4080                 {
4081                         static int k = 0;
4082
4083                         /* Prompt */
4084 #ifdef JP
4085                         prt("¥³¥Þ¥ó¥É: ¥¢¥¤¥Æ¥à¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
4086 #else
4087                         prt("Command: Change object attr/chars", 15, 0);
4088 #endif
4089
4090
4091                         /* Hack -- query until done */
4092                         while (1)
4093                         {
4094                                 object_kind *k_ptr = &k_info[k];
4095                                 byte a, a2;
4096                                 char c, c2;
4097                                 int t;
4098
4099                                 byte da = (byte)k_ptr->d_attr;
4100                                 byte dc = (byte)k_ptr->d_char;
4101                                 byte ca = (byte)k_ptr->x_attr;
4102                                 byte cc = (byte)k_ptr->x_char;
4103
4104                                 /* Label the object */
4105 #ifdef JP
4106                                 Term_putstr(5, 17, -1, TERM_WHITE,
4107                                             format("¥¢¥¤¥Æ¥à = %d, Ì¾Á° = %-40.40s",
4108                                                    k, (k_name + k_ptr->name)));
4109 #else
4110                                 Term_putstr(5, 17, -1, TERM_WHITE,
4111                                             format("Object = %d, Name = %-40.40s",
4112                                                    k, (k_name + k_ptr->name)));
4113 #endif
4114
4115
4116                                 /* Label the Default values */
4117 #ifdef JP
4118                                 Term_putstr(10, 19, -1, TERM_WHITE,
4119                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3d / %3d", da, dc));
4120 #else
4121                                 Term_putstr(10, 19, -1, TERM_WHITE,
4122                                             format("Default attr/char = %3d / %3d", da, dc));
4123 #endif
4124
4125                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4126                                 a = da;
4127                                 c = dc;
4128                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4129
4130                                 Term_putch(43, 19, a, c);
4131                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4132
4133
4134                                 /* Label the Current values */
4135 #ifdef JP
4136                                 Term_putstr(10, 20, -1, TERM_WHITE,
4137                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3d / %3d", ca, cc));
4138 #else
4139                                 Term_putstr(10, 20, -1, TERM_WHITE,
4140                                             format("Current attr/char = %3d / %3d", ca, cc));
4141 #endif
4142
4143                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4144                                 a = ca;
4145                                 c = cc;
4146                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4147
4148                                 Term_putch(43, 20, a, c);
4149                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4150
4151
4152                                 /* Prompt */
4153 #ifdef JP
4154                                 Term_putstr(0, 22, -1, TERM_WHITE,
4155                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4156 #else
4157                                 Term_putstr(0, 22, -1, TERM_WHITE,
4158                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4159 #endif
4160
4161                                 /* Get a command */
4162                                 i = inkey();
4163
4164                                 /* All done */
4165                                 if (i == ESCAPE) break;
4166
4167                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4168                                 else if (isupper(i)) c = 'a' + i - 'A';
4169                                 else c = i;
4170
4171                                 switch (c)
4172                                 {
4173                                 case 'n':
4174                                         cmd_visuals_aux(i, &k, max_k_idx);
4175                                         break;
4176                                 case 'a':
4177                                         t = (int)k_info[k].x_attr;
4178                                         cmd_visuals_aux(i, &t, 256);
4179                                         k_info[k].x_attr = (byte)t;
4180                                         break;
4181                                 case 'c':
4182                                         t = (int)k_info[k].x_char;
4183                                         cmd_visuals_aux(i, &t, 256);
4184                                         k_info[k].x_char = (byte)t;
4185                                         break;
4186                                 }
4187                         }
4188                 }
4189
4190                 /* Modify feature attr/chars */
4191                 else if (i == '8')
4192                 {
4193                         static int f = 0;
4194
4195                         /* Prompt */
4196 #ifdef JP
4197                         prt("¥³¥Þ¥ó¥É: ÃÏ·Á¤Î[¿§/ʸ»ú]¤òÊѹ¹¤·¤Þ¤¹", 15, 0);
4198 #else
4199                         prt("Command: Change feature attr/chars", 15, 0);
4200 #endif
4201
4202
4203                         /* Hack -- query until done */
4204                         while (1)
4205                         {
4206                                 feature_type *f_ptr = &f_info[f];
4207                                 byte a, a2;
4208                                 char c, c2;
4209                                 int t;
4210
4211                                 byte da = (byte)f_ptr->d_attr;
4212                                 byte dc = (byte)f_ptr->d_char;
4213                                 byte ca = (byte)f_ptr->x_attr;
4214                                 byte cc = (byte)f_ptr->x_char;
4215
4216                                 /* Label the object */
4217 #ifdef JP
4218                                 Term_putstr(5, 17, -1, TERM_WHITE,
4219                                             format("ÃÏ·Á = %d, Ì¾Á° = %-40.40s",
4220                                                    f, (f_name + f_ptr->name)));
4221 #else
4222                                 Term_putstr(5, 17, -1, TERM_WHITE,
4223                                             format("Terrain = %d, Name = %-40.40s",
4224                                                    f, (f_name + f_ptr->name)));
4225 #endif
4226
4227
4228                                 /* Label the Default values */
4229 #ifdef JP
4230                                 Term_putstr(10, 19, -1, TERM_WHITE,
4231                                             format("½é´üÃÍ  ¿§ / Ê¸»ú = %3d / %3d", da, dc));
4232 #else
4233                                 Term_putstr(10, 19, -1, TERM_WHITE,
4234                                             format("Default attr/char = %3d / %3d", da, dc));
4235 #endif
4236
4237                                 Term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
4238                                 a = da;
4239                                 c = dc;
4240                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4241
4242                                 Term_putch(43, 19, a, c);
4243                                 if (use_bigtile) Term_putch(43 + 1, 19, a2, c2);
4244
4245
4246                                 /* Label the Current values */
4247 #ifdef JP
4248                                 Term_putstr(10, 20, -1, TERM_WHITE,
4249                                             format("¸½ºßÃÍ  ¿§ / Ê¸»ú = %3d / %3d", ca, cc));
4250 #else
4251                                 Term_putstr(10, 20, -1, TERM_WHITE,
4252                                             format("Current attr/char = %3d / %3d", ca, cc));
4253 #endif
4254
4255                                 Term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
4256                                 a = ca;
4257                                 c = cc;
4258                                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
4259
4260                                 Term_putch(43, 20, a, c);
4261                                 if (use_bigtile) Term_putch(43 + 1, 20, a2, c2);
4262
4263
4264                                 /* Prompt */
4265 #ifdef JP
4266                                 Term_putstr(0, 22, -1, TERM_WHITE,
4267                                             "¥³¥Þ¥ó¥É (n/N/^N/a/A/^A/c/C/^C): ");
4268 #else
4269                                 Term_putstr(0, 22, -1, TERM_WHITE,
4270                                             "Command (n/N/^N/a/A/^A/c/C/^C): ");
4271 #endif
4272
4273                                 /* Get a command */
4274                                 i = inkey();
4275
4276                                 /* All done */
4277                                 if (i == ESCAPE) break;
4278
4279                                 if (iscntrl(i)) c = 'a' + i - KTRL('A');
4280                                 else if (isupper(i)) c = 'a' + i - 'A';
4281                                 else c = i;
4282
4283                                 switch (c)
4284                                 {
4285                                 case 'n':
4286                                         cmd_visuals_aux(i, &f, max_f_idx);
4287                                         break;
4288                                 case 'a':
4289                                         t = (int)f_info[f].x_attr;
4290                                         cmd_visuals_aux(i, &t, 256);
4291                                         f_info[f].x_attr = (byte)t;
4292                                         break;
4293                                 case 'c':
4294                                         t = (int)f_info[f].x_char;
4295                                         cmd_visuals_aux(i, &t, 256);
4296                                         f_info[f].x_char = (byte)t;
4297                                         break;
4298                                 }
4299                         }
4300                 }
4301
4302 #endif
4303
4304                 /* Reset visuals */
4305                 else if (i == '0')
4306                 {
4307                         /* Reset */
4308                         reset_visuals();
4309
4310                         /* Message */
4311 #ifdef JP
4312                         msg_print("²èÌ̾å¤Î[¿§/ʸ»ú]¤ò½é´üÃͤ˥ꥻ¥Ã¥È¤·¤Þ¤·¤¿¡£");
4313 #else
4314                         msg_print("Visual attr/char tables reset.");
4315 #endif
4316
4317                 }
4318
4319                 /* Unknown option */
4320                 else
4321                 {
4322                         bell();
4323                 }
4324
4325                 /* Flush messages */
4326                 msg_print(NULL);
4327         }
4328
4329
4330         /* Restore the screen */
4331         screen_load();
4332 }
4333
4334
4335 /*
4336  * Interact with "colors"
4337  */
4338 void do_cmd_colors(void)
4339 {
4340         int i;
4341
4342         char tmp[160];
4343
4344         char buf[1024];
4345
4346
4347         /* File type is "TEXT" */
4348         FILE_TYPE(FILE_TYPE_TEXT);
4349
4350
4351         /* Save the screen */
4352         screen_save();
4353
4354
4355         /* Interact until done */
4356         while (1)
4357         {
4358                 /* Clear screen */
4359                 Term_clear();
4360
4361                 /* Ask for a choice */
4362 #ifdef JP
4363                 prt("[ ¥«¥é¡¼¤ÎÀßÄê ]", 2, 0);
4364 #else
4365                 prt("Interact with Colors", 2, 0);
4366 #endif
4367
4368
4369                 /* Give some choices */
4370 #ifdef JP
4371                 prt("(1) ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤Î¥í¡¼¥É", 4, 5);
4372 #else
4373                 prt("(1) Load a user pref file", 4, 5);
4374 #endif
4375
4376 #ifdef ALLOW_COLORS
4377 #ifdef JP
4378                 prt("(2) ¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤¹", 5, 5);
4379                 prt("(3) ¥«¥é¡¼¤ÎÀßÄê¤òÊѹ¹¤¹¤ë", 6, 5);
4380 #else
4381                 prt("(2) Dump colors", 5, 5);
4382                 prt("(3) Modify colors", 6, 5);
4383 #endif
4384
4385 #endif
4386
4387                 /* Prompt */
4388 #ifdef JP
4389                 prt("¥³¥Þ¥ó¥É: ", 8, 0);
4390 #else
4391                 prt("Command: ", 8, 0);
4392 #endif
4393
4394
4395                 /* Prompt */
4396                 i = inkey();
4397
4398                 /* Done */
4399                 if (i == ESCAPE) break;
4400
4401                 /* Load a 'pref' file */
4402                 if (i == '1')
4403                 {
4404                         /* Prompt */
4405 #ifdef JP
4406                         prt("¥³¥Þ¥ó¥É: ¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤·¤Þ¤¹", 8, 0);
4407 #else
4408                         prt("Command: Load a user pref file", 8, 0);
4409 #endif
4410
4411
4412                         /* Prompt */
4413 #ifdef JP
4414                         prt("¥Õ¥¡¥¤¥ë: ", 10, 0);
4415 #else
4416                         prt("File: ", 10, 0);
4417 #endif
4418
4419
4420                         /* Default file */
4421                         sprintf(tmp, "%s.prf", player_name);
4422
4423                         /* Query */
4424                         if (!askfor_aux(tmp, 70)) continue;
4425
4426                         /* Process the given filename */
4427                         (void)process_pref_file(tmp);
4428
4429                         /* Mega-Hack -- react to changes */
4430                         Term_xtra(TERM_XTRA_REACT, 0);
4431
4432                         /* Mega-Hack -- redraw */
4433                         Term_redraw();
4434                 }
4435
4436 #ifdef ALLOW_COLORS
4437
4438                 /* Dump colors */
4439                 else if (i == '2')
4440                 {
4441                         static cptr mark = "Colors";
4442
4443                         /* Prompt */
4444 #ifdef JP
4445                         prt("¥³¥Þ¥ó¥É: ¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤¹", 8, 0);
4446 #else
4447                         prt("Command: Dump colors", 8, 0);
4448 #endif
4449
4450
4451                         /* Prompt */
4452 #ifdef JP
4453                         prt("¥Õ¥¡¥¤¥ë: ", 10, 0);
4454 #else
4455                         prt("File: ", 10, 0);
4456 #endif
4457
4458
4459                         /* Default filename */
4460                         sprintf(tmp, "%s.prf", player_name);
4461
4462                         /* Get a filename */
4463                         if (!askfor_aux(tmp, 70)) continue;
4464
4465                         /* Build the filename */
4466                         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
4467
4468                         /* Append to the file */
4469                         if (!open_auto_dump(buf, mark)) continue;
4470
4471                         /* Start dumping */
4472 #ifdef JP
4473                         auto_dump_printf("\n# ¥«¥é¡¼¤ÎÀßÄê\n\n");
4474 #else
4475                         auto_dump_printf("\n# Color redefinitions\n\n");
4476 #endif
4477
4478                         /* Dump colors */
4479                         for (i = 0; i < 256; i++)
4480                         {
4481                                 int kv = angband_color_table[i][0];
4482                                 int rv = angband_color_table[i][1];
4483                                 int gv = angband_color_table[i][2];
4484                                 int bv = angband_color_table[i][3];
4485
4486 #ifdef JP
4487                                 cptr name = "̤ÃÎ";
4488 #else
4489                                 cptr name = "unknown";
4490 #endif
4491
4492
4493                                 /* Skip non-entries */
4494                                 if (!kv && !rv && !gv && !bv) continue;
4495
4496                                 /* Extract the color name */
4497                                 if (i < 16) name = color_names[i];
4498
4499                                 /* Dump a comment */
4500 #ifdef JP
4501                                 auto_dump_printf("# ¥«¥é¡¼ '%s'\n", name);
4502 #else
4503                                 auto_dump_printf("# Color '%s'\n", name);
4504 #endif
4505
4506                                 /* Dump the monster attr/char info */
4507                                 auto_dump_printf("V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n",
4508                                         i, kv, rv, gv, bv);
4509                         }
4510
4511                         /* Close */
4512                         close_auto_dump();
4513
4514                         /* Message */
4515 #ifdef JP
4516                         msg_print("¥«¥é¡¼¤ÎÀßÄê¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
4517 #else
4518                         msg_print("Dumped color redefinitions.");
4519 #endif
4520
4521                 }
4522
4523                 /* Edit colors */
4524                 else if (i == '3')
4525                 {
4526                         static byte a = 0;
4527
4528                         /* Prompt */
4529 #ifdef JP
4530                         prt("¥³¥Þ¥ó¥É: ¥«¥é¡¼¤ÎÀßÄê¤òÊѹ¹¤·¤Þ¤¹", 8, 0);
4531 #else
4532                         prt("Command: Modify colors", 8, 0);
4533 #endif
4534
4535
4536                         /* Hack -- query until done */
4537                         while (1)
4538                         {
4539                                 cptr name;
4540                                 byte j;
4541
4542                                 /* Clear */
4543                                 clear_from(10);
4544
4545                                 /* Exhibit the normal colors */
4546                                 for (j = 0; j < 16; j++)
4547                                 {
4548                                         /* Exhibit this color */
4549                                         Term_putstr(j*4, 20, -1, a, "###");
4550
4551                                         /* Exhibit all colors */
4552                                         Term_putstr(j*4, 22, -1, j, format("%3d", j));
4553                                 }
4554
4555                                 /* Describe the color */
4556 #ifdef JP
4557                                 name = ((a < 16) ? color_names[a] : "̤ÄêµÁ");
4558 #else
4559                                 name = ((a < 16) ? color_names[a] : "undefined");
4560 #endif
4561
4562
4563                                 /* Describe the color */
4564 #ifdef JP
4565                                 Term_putstr(5, 10, -1, TERM_WHITE,
4566                                             format("¥«¥é¡¼ = %d, Ì¾Á° = %s", a, name));
4567 #else
4568                                 Term_putstr(5, 10, -1, TERM_WHITE,
4569                                             format("Color = %d, Name = %s", a, name));
4570 #endif
4571
4572
4573                                 /* Label the Current values */
4574                                 Term_putstr(5, 12, -1, TERM_WHITE,
4575                                             format("K = 0x%02x / R,G,B = 0x%02x,0x%02x,0x%02x",
4576                                                    angband_color_table[a][0],
4577                                                    angband_color_table[a][1],
4578                                                    angband_color_table[a][2],
4579                                                    angband_color_table[a][3]));
4580
4581                                 /* Prompt */
4582 #ifdef JP
4583                                 Term_putstr(0, 14, -1, TERM_WHITE,
4584                                             "¥³¥Þ¥ó¥É (n/N/k/K/r/R/g/G/b/B): ");
4585 #else
4586                                 Term_putstr(0, 14, -1, TERM_WHITE,
4587                                             "Command (n/N/k/K/r/R/g/G/b/B): ");
4588 #endif
4589
4590
4591                                 /* Get a command */
4592                                 i = inkey();
4593
4594                                 /* All done */
4595                                 if (i == ESCAPE) break;
4596
4597                                 /* Analyze */
4598                                 if (i == 'n') a = (byte)(a + 1);
4599                                 if (i == 'N') a = (byte)(a - 1);
4600                                 if (i == 'k') angband_color_table[a][0] = (byte)(angband_color_table[a][0] + 1);
4601                                 if (i == 'K') angband_color_table[a][0] = (byte)(angband_color_table[a][0] - 1);
4602                                 if (i == 'r') angband_color_table[a][1] = (byte)(angband_color_table[a][1] + 1);
4603                                 if (i == 'R') angband_color_table[a][1] = (byte)(angband_color_table[a][1] - 1);
4604                                 if (i == 'g') angband_color_table[a][2] = (byte)(angband_color_table[a][2] + 1);
4605                                 if (i == 'G') angband_color_table[a][2] = (byte)(angband_color_table[a][2] - 1);
4606                                 if (i == 'b') angband_color_table[a][3] = (byte)(angband_color_table[a][3] + 1);
4607                                 if (i == 'B') angband_color_table[a][3] = (byte)(angband_color_table[a][3] - 1);
4608
4609                                 /* Hack -- react to changes */
4610                                 Term_xtra(TERM_XTRA_REACT, 0);
4611
4612                                 /* Hack -- redraw */
4613                                 Term_redraw();
4614                         }
4615                 }
4616
4617 #endif
4618
4619                 /* Unknown option */
4620                 else
4621                 {
4622                         bell();
4623                 }
4624
4625                 /* Flush messages */
4626                 msg_print(NULL);
4627         }
4628
4629
4630         /* Restore the screen */
4631         screen_load();
4632 }
4633
4634
4635 /*
4636  * Note something in the message recall
4637  */
4638 void do_cmd_note(void)
4639 {
4640         char buf[80];
4641
4642         /* Default */
4643         strcpy(buf, "");
4644
4645         /* Input */
4646 #ifdef JP
4647         if (!get_string("¥á¥â: ", buf, 60)) return;
4648 #else
4649         if (!get_string("Note: ", buf, 60)) return;
4650 #endif
4651
4652
4653         /* Ignore empty notes */
4654         if (!buf[0] || (buf[0] == ' ')) return;
4655
4656         /* Add the note to the message recall */
4657 #ifdef JP
4658         msg_format("¥á¥â: %s", buf);
4659 #else
4660         msg_format("Note: %s", buf);
4661 #endif
4662
4663 }
4664
4665
4666 /*
4667  * Mention the current version
4668  */
4669 void do_cmd_version(void)
4670 {
4671
4672         /* Silly message */
4673 #ifdef JP
4674         msg_format("ÊѶòÈÚÅÜ(Hengband) %d.%d.%d",
4675                     FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4676 #else
4677         msg_format("You are playing Hengband %d.%d.%d.",
4678                     FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4679 #endif
4680 }
4681
4682
4683
4684 /*
4685  * Array of feeling strings
4686  */
4687 static cptr do_cmd_feeling_text[11] =
4688 {
4689 #ifdef JP
4690         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4691 #else
4692         "Looks like any other level.",
4693 #endif
4694
4695 #ifdef JP
4696         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4697 #else
4698         "You feel there is something special about this level.",
4699 #endif
4700
4701 #ifdef JP
4702         "¶²¤í¤·¤¤»à¤Î¸¸¤¬ÌܤËÉ⤫¤Ó¡¢µ¤À䤷¤½¤¦¤Ë¤Ê¤Ã¤¿¡ª",
4703 #else
4704         "You nearly faint as horrible visions of death fill your mind!",
4705 #endif
4706
4707 #ifdef JP
4708         "¤³¤Î³¬¤Ï¤È¤Æ¤â´í¸±¤Ê¤è¤¦¤À¡£",
4709 #else
4710         "This level looks very dangerous.",
4711 #endif
4712
4713 #ifdef JP
4714         "¤È¤Æ¤â°­¤¤Í½´¶¤¬¤¹¤ë...",
4715 #else
4716         "You have a very bad feeling...",
4717 #endif
4718
4719 #ifdef JP
4720         "°­¤¤Í½´¶¤¬¤¹¤ë...",
4721 #else
4722         "You have a bad feeling...",
4723 #endif
4724
4725 #ifdef JP
4726         "²¿¤«¶ÛÄ¥¤¹¤ë¡£",
4727 #else
4728         "You feel nervous.",
4729 #endif
4730
4731 #ifdef JP
4732         "¾¯¤·ÉÔ±¿¤Êµ¤¤¬¤¹¤ë...",
4733 #else
4734         "You feel your luck is turning...",
4735 #endif
4736
4737 #ifdef JP
4738         "¤³¤Î¾ì½ê¤Ï¹¥¤­¤Ë¤Ê¤ì¤Ê¤¤¡£",
4739 #else
4740         "You don't like the look of this place.",
4741 #endif
4742
4743 #ifdef JP
4744         "¤³¤Î³¬¤Ï¤½¤ì¤Ê¤ê¤Ë°ÂÁ´¤Ê¤è¤¦¤À¡£",
4745 #else
4746         "This level looks reasonably safe.",
4747 #endif
4748
4749 #ifdef JP
4750         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4751 #else
4752         "What a boring place..."
4753 #endif
4754
4755 };
4756
4757 static cptr do_cmd_feeling_text_combat[11] =
4758 {
4759 #ifdef JP
4760         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4761 #else
4762         "Looks like any other level.",
4763 #endif
4764
4765 #ifdef JP
4766         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4767 #else
4768         "You feel there is something special about this level.",
4769 #endif
4770
4771 #ifdef JP
4772         "º£Ìë¤â¤Þ¤¿¡¢Ã¯¤«¤¬Ì¿¤òÍî¤È¤¹...",
4773 #else
4774         "You nearly faint as horrible visions of death fill your mind!",
4775 #endif
4776
4777 #ifdef JP
4778         "¤³¤Î³¬¤Ï¤È¤Æ¤â´í¸±¤Ê¤è¤¦¤À¡£",
4779 #else
4780         "This level looks very dangerous.",
4781 #endif
4782
4783 #ifdef JP
4784         "¤È¤Æ¤â°­¤¤Í½´¶¤¬¤¹¤ë...",
4785 #else
4786         "You have a very bad feeling...",
4787 #endif
4788
4789 #ifdef JP
4790         "°­¤¤Í½´¶¤¬¤¹¤ë...",
4791 #else
4792         "You have a bad feeling...",
4793 #endif
4794
4795 #ifdef JP
4796         "²¿¤«¶ÛÄ¥¤¹¤ë¡£",
4797 #else
4798         "You feel nervous.",
4799 #endif
4800
4801 #ifdef JP
4802         "¾¯¤·ÉÔ±¿¤Êµ¤¤¬¤¹¤ë...",
4803 #else
4804         "You feel your luck is turning...",
4805 #endif
4806
4807 #ifdef JP
4808         "¤³¤Î¾ì½ê¤Ï¹¥¤­¤Ë¤Ê¤ì¤Ê¤¤¡£",
4809 #else
4810         "You don't like the look of this place.",
4811 #endif
4812
4813 #ifdef JP
4814         "¤³¤Î³¬¤Ï¤½¤ì¤Ê¤ê¤Ë°ÂÁ´¤Ê¤è¤¦¤À¡£",
4815 #else
4816         "This level looks reasonably safe.",
4817 #endif
4818
4819 #ifdef JP
4820         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4821 #else
4822         "What a boring place..."
4823 #endif
4824
4825 };
4826
4827 static cptr do_cmd_feeling_text_lucky[11] =
4828 {
4829 #ifdef JP
4830         "¤³¤Î³¬¤ÎÊ·°Ïµ¤¤ò´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿...",
4831         "¤³¤Î³¬¤Ë¤Ï²¿¤«ÆÃÊ̤ʤâ¤Î¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£",
4832         "¤³¤Î³¬¤Ï¤³¤Î¾å¤Ê¤¯ÁÇÀ²¤é¤·¤¤´¶¤¸¤¬¤¹¤ë¡£",
4833         "ÁÇÀ²¤é¤·¤¤´¶¤¸¤¬¤¹¤ë...",
4834         "¤È¤Æ¤âÎɤ¤´¶¤¸¤¬¤¹¤ë...",
4835         "Îɤ¤´¶¤¸¤¬¤¹¤ë...",
4836         "¤Á¤ç¤Ã¤È¹¬±¿¤Ê´¶¤¸¤¬¤¹¤ë...",
4837         "¿¾¯¤Ï±¿¤¬¸þ¤¤¤Æ¤­¤¿¤«...",
4838         "¸«¤¿´¶¤¸°­¤¯¤Ï¤Ê¤¤...",
4839         "Á´Á³ÂÌÌܤȤ¤¤¦¤³¤È¤Ï¤Ê¤¤¤¬...",
4840         "¤Ê¤ó¤ÆÂà¶þ¤Ê¤È¤³¤í¤À..."
4841 #else
4842         "Looks like any other level.",
4843         "You feel there is something special about this level.",
4844         "You have a superb feeling about this level.",
4845         "You have an excellent feeling...",
4846         "You have a very good feeling...",
4847         "You have a good feeling...",
4848         "You feel strangely lucky...",
4849         "You feel your luck is turning...",
4850         "You like the look of this place...",
4851         "This level can't be all bad...",
4852         "What a boring place..."
4853 #endif
4854 };
4855
4856
4857 /*
4858  * Note that "feeling" is set to zero unless some time has passed.
4859  * Note that this is done when the level is GENERATED, not entered.
4860  */
4861 void do_cmd_feeling(void)
4862 {
4863         /* Verify the feeling */
4864         if (feeling > 10) feeling = 10;
4865
4866         /* No useful feeling in quests */
4867         if (p_ptr->inside_quest && !random_quest_number(dun_level))
4868         {
4869 #ifdef JP
4870                 msg_print("ŵ·¿Åª¤Ê¥¯¥¨¥¹¥È¤Î¥À¥ó¥¸¥ç¥ó¤Î¤è¤¦¤À¡£");
4871 #else
4872                 msg_print("Looks like a typical quest level.");
4873 #endif
4874
4875                 return;
4876         }
4877
4878         /* No useful feeling in town */
4879         else if (p_ptr->town_num && !dun_level)
4880         {
4881 #ifdef JP
4882                 if (!strcmp(town[p_ptr->town_num].name, "¹ÓÌî"))
4883 #else
4884                 if (!strcmp(town[p_ptr->town_num].name, "wilderness"))
4885 #endif
4886                 {
4887 #ifdef JP
4888                         msg_print("²¿¤«¤¢¤ê¤½¤¦¤Ê¹ÓÌî¤Î¤è¤¦¤À¡£");
4889 #else
4890                         msg_print("Looks like a strange wilderness.");
4891 #endif
4892
4893                         return;
4894                 }
4895                 else
4896                 {
4897 #ifdef JP
4898                         msg_print("ŵ·¿Åª¤ÊÄ®¤Î¤è¤¦¤À¡£");
4899 #else
4900                         msg_print("Looks like a typical town.");
4901 #endif
4902
4903                         return;
4904                 }
4905         }
4906
4907         /* No useful feeling in the wilderness */
4908         else if (!dun_level)
4909         {
4910 #ifdef JP
4911                 msg_print("ŵ·¿Åª¤Ê¹ÓÌî¤Î¤è¤¦¤À¡£");
4912 #else
4913                 msg_print("Looks like a typical wilderness.");
4914 #endif
4915
4916                 return;
4917         }
4918
4919         /* Display the feeling */
4920         if (turn - old_turn >= (150 - dun_level)*TURNS_PER_TICK || cheat_xtra)
4921         {
4922                 if (p_ptr->muta3 & MUT3_GOOD_LUCK) msg_print(do_cmd_feeling_text_lucky[feeling]);
4923                 else {
4924                                         if((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON)){
4925                                                 msg_print(do_cmd_feeling_text_combat[feeling]);
4926                                         }else
4927                                                 msg_print(do_cmd_feeling_text[feeling]);
4928                                 }
4929         }
4930         else
4931         {
4932                 msg_print(do_cmd_feeling_text[0]);
4933         }
4934 }
4935
4936
4937
4938 /*
4939  * Description of each monster group.
4940  */
4941 static cptr monster_group_text[] = 
4942 {
4943 #ifdef JP
4944         "¥æ¥Ë¡¼¥¯",     /* "Uniques" */
4945         "¾èÇϲÄǽ¤Ê¥â¥ó¥¹¥¿¡¼", /* "Riding" */
4946         "¥¢¥ê",
4947         "¥³¥¦¥â¥ê",
4948         "¥à¥«¥Ç",
4949         "¥É¥é¥´¥ó",
4950         "ÌܶÌ",
4951         "¥Í¥³",
4952         "¥´¡¼¥ì¥à",
4953         "ɸ½à¿Í´Ö·¿À¸Êª",
4954         "¥Ù¥È¥Ù¥È",
4955         "¥¼¥ê¡¼",
4956         "¥³¥Ü¥ë¥É",
4957         "¿åÀ³À¸Êª",
4958         "¥â¥ë¥É",
4959         "¥Ê¡¼¥¬",
4960         "¥ª¡¼¥¯",
4961         "¿Í´Ö",
4962         "»Í­½Ã",
4963         "¥Í¥º¥ß",
4964         "¥¹¥±¥ë¥È¥ó",
4965         "¥Ç¡¼¥â¥ó",
4966         "¥Ü¥ë¥Æ¥Ã¥¯¥¹",
4967         "¥¤¥â¥à¥·/Âç·²",
4968         /* "unused", */
4969         "¥¤¡¼¥¯",
4970         "¥¾¥ó¥Ó/¥ß¥¤¥é",
4971         "Å·»È",
4972         "Ļ",
4973         "¸¤",
4974         /* "¸ÅÂå¥É¥é¥´¥ó/¥ï¥¤¥¢¡¼¥à", */
4975         "¥¨¥ì¥á¥ó¥¿¥ë",
4976         "¥È¥ó¥Ü",
4977         "¥´¡¼¥¹¥È",
4978         "»¨¼ï",
4979         "º«Ãî",
4980         "¥Ø¥Ó",
4981         "¥­¥é¡¼¡¦¥Ó¡¼¥È¥ë",
4982         "¥ê¥Ã¥Á",
4983         "¿¼ó¤Îà¨ÃîÎà",
4984         "Ææ¤ÎÀ¸Êª",
4985         "¥ª¡¼¥¬",
4986         "µðÂç¿Í´Ö·¿À¸Êª",
4987         "¥¯¥¤¥ë¥¹¥ë¥°",
4988         "à¨ÃîÎà/ξÀ¸Îà",
4989         "ÃØéá/¥µ¥½¥ê/¥À¥Ë",
4990         "¥È¥í¥ë",
4991         /* "¾åµé¥Ç¡¼¥â¥ó", */
4992         "¥Ð¥ó¥Ñ¥¤¥¢",
4993         "¥ï¥¤¥È/¥ì¥¤¥¹/Åù",
4994         "¥¾¡¼¥ó/¥¶¥ì¥ó/Åù",
4995         "¥¤¥¨¥Æ¥£",
4996         "¥Ï¥¦¥ó¥É",
4997         "¥ß¥ß¥Ã¥¯",
4998         "ÊÉ/¿¢Êª/µ¤ÂÎ",
4999         "¤ª¤Ð¤±¥­¥Î¥³",
5000         "µåÂÎ",
5001 #else
5002         "Uniques",
5003         "Ridable monsters",
5004         "Ant",
5005         "Bat",
5006         "Centipede",
5007         "Dragon",
5008         "Floating Eye",
5009         "Feline",
5010         "Golem",
5011         "Hobbit/Elf/Dwarf",
5012         "Icky Thing",
5013         "Jelly",
5014         "Kobold",
5015         "Aquatic monster",
5016         "Mold",
5017         "Naga",
5018         "Orc",
5019         "Person/Human",
5020         "Quadruped",
5021         "Rodent",
5022         "Skeleton",
5023         "Demon",
5024         "Vortex",
5025         "Worm/Worm-Mass",
5026         /* "unused", */
5027         "Yeek",
5028         "Zombie/Mummy",
5029         "Angel",
5030         "Bird",
5031         "Canine",
5032         /* "Ancient Dragon/Wyrm", */
5033         "Elemental",
5034         "Dragon Fly",
5035         "Ghost",
5036         "Hybrid",
5037         "Insect",
5038         "Snake",
5039         "Killer Beetle",
5040         "Lich",
5041         "Multi-Headed Reptile",
5042         "Mystery Living",
5043         "Ogre",
5044         "Giant Humanoid",
5045         "Quylthulg",
5046         "Reptile/Amphibian",
5047         "Spider/Scorpion/Tick",
5048         "Troll",
5049         /* "Major Demon", */
5050         "Vampire",
5051         "Wight/Wraith/etc",
5052         "Xorn/Xaren/etc",
5053         "Yeti",
5054         "Zephyr Hound",
5055         "Mimic",
5056         "Wall/Plant/Gas",
5057         "Mushroom patch",
5058         "Ball",
5059 #endif
5060         NULL
5061 };
5062
5063
5064 /*
5065  * Symbols of monsters in each group. Note the "Uniques" group
5066  * is handled differently.
5067  */
5068 static cptr monster_group_char[] = 
5069 {
5070         (char *) -1L,
5071         (char *) -2L,
5072         "a",
5073         "b",
5074         "c",
5075         "dD",
5076         "e",
5077         "f",
5078         "g",
5079         "h",
5080         "i",
5081         "j",
5082         "k",
5083         "l",
5084         "m",
5085         "n",
5086         "o",
5087         "pt",
5088         "q",
5089         "r",
5090         "s",
5091         "uU",
5092         "v",
5093         "w",
5094         /* "x", */
5095         "y",
5096         "z",
5097         "A",
5098         "B",
5099         "C",
5100         /* "D", */
5101         "E",
5102         "F",
5103         "G",
5104         "H",
5105         "I",
5106         "J",
5107         "K",
5108         "L",
5109         "M",
5110         "N",
5111         "O",
5112         "P",
5113         "Q",
5114         "R",
5115         "S",
5116         "T",
5117         /* "U", */
5118         "V",
5119         "W",
5120         "X",
5121         "Y",
5122         "Z",
5123         "$!?=&`.|/\\~[]()>",
5124         "#",
5125         ",",
5126         "*",
5127         NULL
5128 };
5129
5130
5131 /*
5132  * hook function to sort monsters by level
5133  */
5134 static bool ang_sort_comp_monster_level(vptr u, vptr v, int a, int b)
5135 {
5136         u16b *who = (u16b*)(u);
5137
5138         int w1 = who[a];
5139         int w2 = who[b];
5140
5141         monster_race *r_ptr1 = &r_info[w1];
5142         monster_race *r_ptr2 = &r_info[w2];
5143
5144         /* Unused */
5145         (void)v;
5146
5147         if (r_ptr2->level > r_ptr1->level) return TRUE;
5148         if (r_ptr1->level > r_ptr2->level) return FALSE;
5149
5150         if ((r_ptr2->flags1 & RF1_UNIQUE) && !(r_ptr1->flags1 & RF1_UNIQUE)) return TRUE;
5151         if ((r_ptr1->flags1 & RF1_UNIQUE) && !(r_ptr2->flags1 & RF1_UNIQUE)) return FALSE;
5152         return w1 <= w2;
5153 }
5154
5155 /*
5156  * Build a list of monster indexes in the given group. Return the number
5157  * of monsters in the group.
5158  *
5159  * mode & 0x01 : check for non-empty group
5160  * mode & 0x02 : cheat?
5161  */
5162 static int collect_monsters(int grp_cur, s16b mon_idx[], byte mode)
5163 {
5164         int i, mon_cnt = 0;
5165         int dummy_why;
5166
5167         /* Get a list of x_char in this group */
5168         cptr group_char = monster_group_char[grp_cur];
5169
5170         /* XXX Hack -- Check if this is the "Uniques" group */
5171         bool grp_unique = (monster_group_char[grp_cur] == (char *) -1L);
5172
5173         /* XXX Hack -- Check if this is the "Riding" group */
5174         bool grp_riding = (monster_group_char[grp_cur] == (char *) -2L);
5175
5176         /* Check every race */
5177         for (i = 0; i < max_r_idx; i++)
5178         {
5179                 /* Access the race */
5180                 monster_race *r_ptr = &r_info[i];
5181
5182                 /* Skip empty race */
5183                 if (!r_ptr->name) continue ;
5184
5185                 /* Require known monsters */
5186                 if (!(mode & 0x02) && !cheat_know && !r_ptr->r_sights ) continue;
5187
5188                 if (grp_unique)
5189                 {
5190                         if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
5191                 }
5192
5193                 else if (grp_riding)
5194                 {
5195                         if (!(r_ptr->flags7 & RF7_RIDING)) continue;
5196                 }
5197
5198                 else
5199                 {
5200                         /* Check for race in the group */
5201                         if (!strchr(group_char, r_ptr->d_char)) continue;
5202                 }
5203
5204                 /* Add the race */
5205                 mon_idx[mon_cnt++] = i;
5206
5207                 /* XXX Hack -- Just checking for non-empty group */
5208                 if (mode & 0x01) break;
5209         }
5210
5211         /* Terminate the list */
5212         mon_idx[mon_cnt] = 0;
5213
5214         /* Select the sort method */
5215         ang_sort_comp = ang_sort_comp_monster_level;
5216         ang_sort_swap = ang_sort_swap_hook;
5217
5218         /* Sort by monster level */
5219         ang_sort(mon_idx, &dummy_why, mon_cnt);
5220
5221         /* Return the number of races */
5222         return mon_cnt;
5223 }
5224
5225
5226 /*
5227  * Description of each monster group.
5228  */
5229 static cptr object_group_text[] = 
5230 {
5231 #ifdef JP
5232         "¥­¥Î¥³",       /* "Mushrooms" */
5233         "Ìô",           /* "Potions" */
5234         "Ìý¤Ä¤Ü",       /* "Flasks" */
5235         "´¬Êª",         /* "Scrolls" */
5236         "»ØÎØ",         /* "Rings" */
5237         "¥¢¥ß¥å¥ì¥Ã¥È", /* "Amulets" */
5238         "ū",           /* "Whistle" */
5239         "¸÷¸»",         /* "Lanterns" */
5240         "ËâË¡ËÀ",       /* "Wands" */
5241         "¾ó",           /* "Staffs" */
5242         "¥í¥Ã¥É",       /* "Rods" */
5243         "¥«¡¼¥É",       /* "Cards" */
5244         "¥­¥ã¥×¥Á¥ã¡¼¡¦¥Ü¡¼¥ë",
5245         "ÍÓÈé»æ",       
5246         "¤¯¤µ¤Ó",
5247         "Ȣ",
5248         "¿Í·Á",
5249         "Áü",
5250         "¥´¥ß",
5251         "¶õ¤Î¥Ó¥ó",
5252         "¹ü",
5253         "Åá·õÎà",       /* "Swords" */
5254         "Æß´ï",         /* "Blunt Weapons" */
5255         "ĹÊÁÉð´ï",     /* "Polearms" */
5256         "ºÎ·¡Æ»¶ñ",     /* "Diggers" */
5257         "Èô¤ÓÆ»¶ñ",     /* "Bows" */
5258         "ÃÆ",
5259         "Ìð",
5260         "¥Ü¥ë¥È",
5261         "·ÚÁõ³»",       /* "Soft Armor" */
5262         "½ÅÁõ³»",       /* "Hard Armor" */
5263         "¥É¥é¥´¥ó³»",   /* "Dragon Armor" */
5264         "½â",   /* "Shields" */
5265         "¥¯¥í¡¼¥¯",     /* "Cloaks" */
5266         "äƼê", /* "Gloves" */
5267         "¥Ø¥ë¥á¥Ã¥È",   /* "Helms" */
5268         "´§",   /* "Crowns" */
5269         "¥Ö¡¼¥Ä",       /* "Boots" */
5270         "ËâË¡½ñ",
5271 #else
5272         "Mushrooms",
5273         "Potions",
5274         "Flasks",
5275         "Scrolls",
5276         "Rings",
5277         "Amulets",
5278         "Whistle",
5279         "Lanterns",
5280         "Wands",
5281         "Staves",
5282         "Rods",
5283         "Cards",
5284         "Capture Balls",
5285         "Parchments",
5286         "Spikes",
5287         "Boxs",
5288         "Figurines",
5289         "Statues",
5290         "Junks",
5291         "Bottles",
5292         "Skeletons",
5293         "Swords",
5294         "Blunt Weapons",
5295         "Polearms",
5296         "Diggers",
5297         "Bows",
5298         "Shots",
5299         "Arrows",
5300         "Bolts",
5301         "Soft Armor",
5302         "Hard Armor",
5303         "Dragon Armor",
5304         "Shields",
5305         "Cloaks",
5306         "Gloves",
5307         "Helms",
5308         "Crowns",
5309         "Boots",
5310         "Spellbooks",
5311 #endif
5312         NULL
5313 };
5314
5315
5316 /*
5317  * TVALs of items in each group
5318  */
5319 static byte object_group_tval[] = 
5320 {
5321         TV_FOOD,
5322         TV_POTION,
5323         TV_FLASK,
5324         TV_SCROLL,
5325         TV_RING,
5326         TV_AMULET,
5327         TV_WHISTLE,
5328         TV_LITE,
5329         TV_WAND,
5330         TV_STAFF,
5331         TV_ROD,
5332         TV_CARD,
5333         TV_CAPTURE,
5334         TV_PARCHMENT,
5335         TV_SPIKE,
5336         TV_CHEST,
5337         TV_FIGURINE,
5338         TV_STATUE,
5339         TV_JUNK,
5340         TV_BOTTLE,
5341         TV_SKELETON,
5342         TV_SWORD,
5343         TV_HAFTED,
5344         TV_POLEARM,
5345         TV_DIGGING,
5346         TV_BOW,
5347         TV_SHOT,
5348         TV_ARROW,
5349         TV_BOLT,
5350         TV_SOFT_ARMOR,
5351         TV_HARD_ARMOR,
5352         TV_DRAG_ARMOR,
5353         TV_SHIELD,
5354         TV_CLOAK,
5355         TV_GLOVES,
5356         TV_HELM,
5357         TV_CROWN,
5358         TV_BOOTS,
5359         TV_LIFE_BOOK, /* Hack -- all spellbooks */
5360         0
5361 };
5362
5363
5364 /*
5365  * Build a list of monster indexes in the given group. Return the number
5366  * of monsters in the group.
5367  */
5368 static int collect_objects(int grp_cur, int object_idx[])
5369 {
5370         int i, j, k, object_cnt = 0;
5371
5372         /* Get a list of x_char in this group */
5373         byte group_tval = object_group_tval[grp_cur];
5374
5375         /* Check every object */
5376         for (i = 0; i < max_k_idx; i++)
5377         {
5378                 /* Access the race */
5379                 object_kind *k_ptr = &k_info[i];
5380
5381                 /* Skip empty objects */
5382                 if (!k_ptr->name) continue;
5383
5384                 /* Skip non-flavoured objects */
5385                 if (!k_ptr->flavor && !p_ptr->wizard) continue;
5386
5387                 /* Skip items with no distribution (special artifacts) */
5388                 for (j = 0, k = 0; j < 4; j++) k += k_ptr->chance[j];
5389                 if (!(k))  continue; 
5390
5391                 /* Require objects ever seen*/
5392                 if (!k_ptr->aware && !p_ptr->wizard) continue;
5393
5394                 /* Check for race in the group */
5395                 if (TV_LIFE_BOOK == group_tval)
5396                 {
5397                         /* Hack -- All spell books */
5398                         if (TV_LIFE_BOOK <= k_ptr->tval && k_ptr->tval <= TV_HISSATSU_BOOK)
5399                         {
5400                                 /* Add the race */
5401                                 object_idx[object_cnt++] = i;
5402                         }
5403                 }
5404                 else if (k_ptr->tval == group_tval)
5405                 {
5406                         /* Add the race */
5407                         object_idx[object_cnt++] = i;
5408                 }
5409         }
5410
5411         /* Terminate the list */
5412         object_idx[object_cnt] = 0;
5413
5414         /* Return the number of races */
5415         return object_cnt;
5416 }
5417
5418
5419 /*
5420  * Description of each feature group.
5421  */
5422 static cptr feature_group_text[] = 
5423 {
5424         "terrains",
5425         NULL
5426 };
5427
5428
5429 /*
5430  * Build a list of feature indexes in the given group. Return the number
5431  * of features in the group.
5432  */
5433 static int collect_features(int grp_cur, int *feat_idx)
5434 {
5435         int i, feat_cnt = 0;
5436
5437         /* Unused;  There is a single group. */
5438         (void)grp_cur;
5439
5440         /* Check every feature */
5441         for (i = 1; i < max_f_idx; i++)
5442         {
5443                 /* Access the index */
5444                 feature_type *f_ptr = &f_info[i];
5445
5446                 /* Skip empty index */
5447                 if (!f_ptr->name) continue;
5448
5449                 /* Skip mimiccing features */
5450                 if (f_ptr->mimic != i) continue;
5451
5452                 /* Add the index */
5453                 feat_idx[feat_cnt++] = i;
5454         }
5455
5456         /* Terminate the list */
5457         feat_idx[feat_cnt] = 0;
5458
5459         /* Return the number of races */
5460         return feat_cnt;
5461 }
5462
5463
5464 #if 0
5465 /*
5466  * Build a list of monster indexes in the given group. Return the number
5467  * of monsters in the group.
5468  */
5469 static int collect_artifacts(int grp_cur, int object_idx[])
5470 {
5471         int i, object_cnt = 0;
5472
5473         /* Get a list of x_char in this group */
5474         byte group_tval = object_group_tval[grp_cur];
5475
5476         /* Check every object */
5477         for (i = 0; i < max_a_idx; i++)
5478         {
5479                 /* Access the artifact */
5480                 artifact_type *a_ptr = &a_info[i];
5481
5482                 /* Skip empty artifacts */
5483                 if (!a_ptr->name) continue;
5484
5485                 /* Skip "uncreated" artifacts */
5486                 if (!a_ptr->cur_num) continue;
5487
5488                 /* Check for race in the group */
5489                 if (a_ptr->tval == group_tval)
5490                 {
5491                         /* Add the race */
5492                         object_idx[object_cnt++] = i;
5493                 }
5494         }
5495
5496         /* Terminate the list */
5497         object_idx[object_cnt] = 0;
5498
5499         /* Return the number of races */
5500         return object_cnt;
5501 }
5502 #endif /* 0 */
5503
5504
5505 /*
5506  * Encode the screen colors
5507  */
5508 static char hack[17] = "dwsorgbuDWvyRGBU";
5509
5510
5511 static errr photo_fgets(FILE *fff, char *buf, huge n)
5512 {
5513         huge i = 0;
5514
5515         char *s;
5516
5517         char tmp[1024];
5518
5519         /* Read a line */
5520         if (fgets(tmp, 1024, fff))
5521         {
5522                 /* Convert weirdness */
5523                 for (s = tmp; *s; s++)
5524                 {
5525                         /* Handle newline */
5526                         if (*s == '\n')
5527                         {
5528                                 /* Terminate */
5529                                 buf[i] = '\0';
5530
5531                                 /* Success */
5532                                 return (0);
5533                         }
5534
5535                         /* Handle tabs */
5536                         else if (*s == '\t')
5537                         {
5538                                 /* Hack -- require room */
5539                                 if (i + 8 >= n) break;
5540
5541                                 /* Append a space */
5542                                 buf[i++] = ' ';
5543
5544                                 /* Append some more spaces */
5545                                 while (!(i % 8)) buf[i++] = ' ';
5546                         }
5547
5548 #ifdef JP
5549                         else if (iskanji(*s))
5550                         {
5551                                 if (!s[1]) break;
5552                                 buf[i++] = *s++;
5553                                 buf[i++] = *s;
5554                         }
5555 # ifndef EUC
5556         /* È¾³Ñ¤«¤Ê¤ËÂбþ */
5557                         else if ((((int)*s & 0xff) > 0xa1) && (((int)*s & 0xff ) < 0xdf))
5558                         {
5559                                 buf[i++] = *s;
5560                                 if (i >= n) break;
5561                         }
5562 # endif
5563 #endif
5564                         /* Handle printables */
5565                         else
5566                         {
5567                                 /* Copy */
5568                                 buf[i++] = *s;
5569
5570                                 /* Check length */
5571                                 if (i >= n) break;
5572                         }
5573                 }
5574         }
5575
5576         /* Nothing */
5577         buf[0] = '\0';
5578
5579         /* Failure */
5580         return (1);
5581 }
5582
5583
5584 /*
5585  * Hack -- load a screen dump from a file
5586  */
5587 void do_cmd_load_screen(void)
5588 {
5589         int i, y, x;
5590
5591         byte a = 0;
5592         char c = ' ';
5593
5594         bool okay = TRUE;
5595
5596         FILE *fff;
5597
5598         char buf[1024];
5599
5600         int wid, hgt;
5601
5602         Term_get_size(&wid, &hgt);
5603
5604         /* Build the filename */
5605         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
5606
5607         /* Append to the file */
5608         fff = my_fopen(buf, "r");
5609
5610         /* Oops */
5611         if (!fff) {
5612 #ifdef JP
5613                 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
5614 #else
5615                 msg_format("Failed to open %s.", buf);
5616 #endif
5617                 msg_print(NULL);
5618                 return;
5619         }
5620
5621
5622         /* Save the screen */
5623         screen_save();
5624
5625         /* Clear the screen */
5626         Term_clear();
5627
5628
5629         /* Load the screen */
5630         for (y = 0; okay && (y < hgt); y++)
5631         {
5632                 /* Get a line of data */
5633                 if (photo_fgets(fff, buf, 1024)) okay = FALSE;
5634
5635                 /* Show each row */
5636                 for (x = 0; x < wid - 1; x++)
5637                 {
5638                         /* Put the attr/char */
5639                         Term_draw(x, y, TERM_WHITE, buf[x]);
5640                 }
5641         }
5642
5643         /* Get the blank line */
5644         if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
5645
5646
5647         /* Dump the screen */
5648         for (y = 0; okay && (y < hgt); y++)
5649         {
5650                 /* Get a line of data */
5651                 if (photo_fgets(fff, buf, 1024)) okay = FALSE;
5652
5653                 /* Dump each row */
5654                 for (x = 0; x < wid - 1; x++)
5655                 {
5656                         /* Get the attr/char */
5657                         (void)(Term_what(x, y, &a, &c));
5658
5659                         /* Look up the attr */
5660                         for (i = 0; i < 16; i++)
5661                         {
5662                                 /* Use attr matches */
5663                                 if (hack[i] == buf[x]) a = i;
5664                         }
5665
5666                         /* Put the attr/char */
5667                         Term_draw(x, y, a, c);
5668                 }
5669         }
5670
5671
5672         /* Get the blank line */
5673         if (my_fgets(fff, buf, sizeof(buf))) okay = FALSE;
5674
5675
5676         /* Close it */
5677         my_fclose(fff);
5678
5679
5680         /* Message */
5681 #ifdef JP
5682         prt("¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤µ¤ì¤¿²èÌÌ(µ­Ç°»£±Æ)¤ò¥í¡¼¥É¤·¤Þ¤·¤¿¡£", 0, 0);
5683 #else
5684         msg_print("Screen dump loaded.");
5685 #endif
5686
5687         flush();
5688         inkey();
5689
5690
5691         /* Restore the screen */
5692         screen_load();
5693 }
5694
5695
5696
5697
5698 cptr inven_res_label = 
5699 #ifdef JP
5700  "                               »ÀÅŲÐÎäÆǸ÷°ÇÇ˹ì¹ö°øÆÙÎô ÌÕÉÝÍðáãÆ©Ì¿´¶¾ÃÉüÉâ";
5701 #else
5702  "                               AcElFiCoPoLiDkShSoNtNxCaDi BlFeCfFaSeHlEpSdRgLv";
5703 #endif
5704
5705
5706 #ifdef JP
5707 #define IM_FLAG_STR  "¡ö"
5708 #define HAS_FLAG_STR "¡Ü"
5709 #define NO_FLAG_STR  "¡¦"
5710 #else
5711 #define IM_FLAG_STR  "* "
5712 #define HAS_FLAG_STR "+ "
5713 #define NO_FLAG_STR  ". "
5714 #endif
5715
5716 #define print_im_or_res_flag(IM, RES) \
5717 { \
5718         fputs(have_flag(flgs, (IM)) ? IM_FLAG_STR : \
5719               (have_flag(flgs, (RES)) ? HAS_FLAG_STR : NO_FLAG_STR), fff); \
5720 }
5721
5722 #define print_flag(TR) \
5723 { \
5724         fputs(have_flag(flgs, (TR)) ? HAS_FLAG_STR : NO_FLAG_STR, fff); \
5725 }
5726
5727
5728 /* XTRA HACK RESLIST */
5729 static void do_cmd_knowledge_inven_aux(FILE *fff, object_type *o_ptr, int *j, byte tval, char *where)
5730 {
5731         char o_name[MAX_NLEN];
5732         u32b flgs[TR_FLAG_SIZE];
5733
5734         if (!o_ptr->k_idx) return;
5735         if (o_ptr->tval != tval) return;
5736
5737         /* Identified items only */
5738         if (!object_known_p(o_ptr)) return;
5739
5740         /*
5741          * HACK:Ring of Lordly protection and Dragon equipment
5742          * have random resistances.
5743          */
5744         if (((o_ptr->tval >= TV_BOW) && (o_ptr->tval<= TV_DRAG_ARMOR) && o_ptr->name2)
5745             || ((o_ptr->tval == TV_AMULET) && (o_ptr->sval == SV_AMULET_RESISTANCE))
5746             || ((o_ptr->tval == TV_RING) && (o_ptr->sval == SV_RING_LORDLY))
5747             || ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD))
5748             || ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM))
5749             || ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES))
5750             || ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE))
5751             || o_ptr->art_name || o_ptr->name1)
5752         {
5753                 int i = 0;
5754                 object_desc(o_name, o_ptr, TRUE, 0);
5755
5756                 while (o_name[i] && (i < 26))
5757                 {
5758 #ifdef JP
5759                         if (iskanji(o_name[i])) i++;
5760 #endif
5761                         i++;
5762                 }
5763
5764                 if (i < 28)
5765                 {
5766                         while (i < 28)
5767                         {
5768                                 o_name[i] = ' '; i++;
5769                         }
5770                 }
5771                 o_name[i] = '\0';
5772
5773                 fprintf(fff, "%s %s", where, o_name);
5774
5775                 if (!(o_ptr->ident & (IDENT_MENTAL)))
5776                 {
5777 #ifdef JP
5778                         fputs("-------ÉÔÌÀ--------------- -------ÉÔÌÀ---------\n", fff);
5779 #else
5780                         fputs("-------unknown------------ -------unknown------\n", fff);
5781 #endif
5782                 }
5783                 else
5784                 {
5785                         object_flags_known(o_ptr, flgs);
5786
5787                         print_im_or_res_flag(TR_IM_ACID, TR_RES_ACID);
5788                         print_im_or_res_flag(TR_IM_ELEC, TR_RES_ELEC);
5789                         print_im_or_res_flag(TR_IM_FIRE, TR_RES_FIRE);
5790                         print_im_or_res_flag(TR_IM_COLD, TR_RES_COLD);
5791                         print_flag(TR_RES_POIS);
5792                         print_flag(TR_RES_LITE);
5793                         print_flag(TR_RES_DARK);
5794                         print_flag(TR_RES_SHARDS);
5795                         print_flag(TR_RES_SOUND);
5796                         print_flag(TR_RES_NETHER);
5797                         print_flag(TR_RES_NEXUS);
5798                         print_flag(TR_RES_CHAOS);
5799                         print_flag(TR_RES_DISEN);
5800
5801                         fputs(" ", fff);
5802
5803                         print_flag(TR_RES_BLIND);
5804                         print_flag(TR_RES_FEAR);
5805                         print_flag(TR_RES_CONF);
5806                         print_flag(TR_FREE_ACT);
5807                         print_flag(TR_SEE_INVIS);
5808                         print_flag(TR_HOLD_LIFE);
5809                         print_flag(TR_TELEPATHY);
5810                         print_flag(TR_SLOW_DIGEST);
5811                         print_flag(TR_REGEN);
5812                         print_flag(TR_FEATHER);
5813
5814                         fputc('\n', fff);
5815                 }
5816                 (*j)++;
5817                 if (*j == 9)
5818                 {
5819                         *j = 0;
5820                         fprintf(fff, "%s\n", inven_res_label);
5821                 }
5822         }
5823 }
5824
5825 /*
5826  * Display *ID* ed weapons/armors's resistances
5827  */
5828 static void do_cmd_knowledge_inven(void)
5829 {
5830         FILE *fff;
5831
5832         char file_name[1024];
5833
5834         store_type  *st_ptr;
5835
5836         byte tval;
5837         int i = 0;
5838         int j = 0;
5839
5840         char  where[32];
5841
5842         /* Open a new file */
5843         fff = my_fopen_temp(file_name, 1024);
5844         if (!fff)
5845         {
5846 #ifdef JP
5847             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
5848 #else
5849             msg_format("Failed to create temporary file %s.", file_name);
5850 #endif
5851             msg_print(NULL);
5852             return;
5853         }
5854         fprintf(fff, "%s\n", inven_res_label);
5855
5856         for (tval = TV_BOW; tval <= TV_RING; tval++)
5857         {
5858                 if (j != 0)
5859                 {
5860                         for (; j < 9; j++) fputc('\n', fff);
5861                         j = 0;
5862                         fprintf(fff, "%s\n", inven_res_label);
5863                 }
5864
5865 #ifdef JP
5866                 strcpy(where, "Áõ");
5867 #else
5868                 strcpy(where, "E ");
5869 #endif
5870                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
5871                 {
5872                         do_cmd_knowledge_inven_aux(fff, &inventory[i], &j, tval, where);
5873                 }
5874
5875 #ifdef JP
5876                 strcpy(where, "»ý");
5877 #else
5878                 strcpy(where, "I ");
5879 #endif
5880                 for (i = 0; i < INVEN_PACK; i++)
5881                 {
5882                         do_cmd_knowledge_inven_aux(fff, &inventory[i], &j, tval, where);
5883                 }
5884
5885                 st_ptr = &town[1].store[STORE_HOME];
5886 #ifdef JP
5887                 strcpy(where, "²È");
5888 #else
5889                 strcpy(where, "H ");
5890 #endif
5891
5892                 for (i = 0; i < st_ptr->stock_num; i++)
5893                 {
5894                         do_cmd_knowledge_inven_aux(fff, &st_ptr->stock[i], &j, tval, where);
5895                 }
5896         }
5897
5898         /* Close the file */
5899         my_fclose(fff);
5900
5901         /* Display the file contents */
5902 #ifdef JP
5903         show_file(TRUE, file_name, "*´ÕÄê*ºÑ¤ßÉð´ï/Ëɶñ¤ÎÂÑÀ­¥ê¥¹¥È", 0, 0);
5904 #else
5905         show_file(TRUE, file_name, "Resistances of *identified* equipment", 0, 0);
5906 #endif
5907
5908         /* Remove the file */
5909         fd_kill(file_name);
5910 }
5911
5912
5913 void do_cmd_save_screen_html_aux(char *filename, int message)
5914 {
5915         int y, x, i;
5916
5917         byte a = 0, old_a = 0;
5918         char c = ' ';
5919
5920         FILE *fff, *tmpfff;
5921         char buf[2048];
5922
5923         int yomikomu = 0;
5924         cptr tags[4] = {
5925                 "HEADER_START:",
5926                 "HEADER_END:",
5927                 "FOOTER_START:",
5928                 "FOOTER_END:",
5929         };
5930
5931         cptr html_head[] = {
5932                 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
5933                 "<pre>",
5934                 0,
5935         };
5936         cptr html_foot[] = {
5937                 "</pre>\n",
5938                 "</body>\n</html>\n",
5939                 0,
5940         };
5941
5942         int wid, hgt;
5943
5944         Term_get_size(&wid, &hgt);
5945
5946         /* File type is "TEXT" */
5947         FILE_TYPE(FILE_TYPE_TEXT);
5948
5949         /* Append to the file */
5950         fff = my_fopen(filename, "w");
5951
5952         /* Oops */
5953         if (!fff) {
5954                 if (message) {
5955 #ifdef JP
5956                     msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", filename);
5957 #else
5958                     msg_format("Failed to open file %s.", filename);
5959 #endif
5960                     msg_print(NULL);
5961                 }
5962                 
5963                 return;
5964         }
5965
5966         /* Save the screen */
5967         if (message)
5968                 screen_save();
5969
5970         /* Build the filename */
5971         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "htmldump.prf");
5972         tmpfff = my_fopen(buf, "r");
5973         if (!tmpfff) {
5974                 for (i = 0; html_head[i]; i++)
5975                         fprintf(fff, html_head[i]);
5976         }
5977         else {
5978                 yomikomu = 0;
5979                 while (!my_fgets(tmpfff, buf, sizeof(buf))) {
5980                         if (!yomikomu) {
5981                                 if (strncmp(buf, tags[0], strlen(tags[0])) == 0)
5982                                         yomikomu = 1;
5983                         }
5984                         else {
5985                                 if (strncmp(buf, tags[1], strlen(tags[1])) == 0)
5986                                         break;
5987                                 fprintf(fff, "%s\n", buf);
5988                         }
5989                 }
5990         }
5991
5992         /* Dump the screen */
5993         for (y = 0; y < hgt; y++)
5994         {
5995                 /* Start the row */
5996                 if (y != 0)
5997                         fprintf(fff, "\n");
5998
5999                 /* Dump each row */
6000                 for (x = 0; x < wid - 1; x++)
6001                 {
6002                         int rv, gv, bv;
6003                         cptr cc = NULL;
6004                         /* Get the attr/char */
6005                         (void)(Term_what(x, y, &a, &c));
6006
6007                         switch (c)
6008                         {
6009                         case '&': cc = "&amp;"; break;
6010                         case '<': cc = "&lt;"; break;
6011                         case '>': cc = "&gt;"; break;
6012 #ifdef WINDOWS
6013                         case 0x1f: c = '.'; break;
6014                         case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
6015 #endif
6016                         }
6017
6018                         a = a & 0x0F;
6019                         if ((y == 0 && x == 0) || a != old_a) {
6020                                 rv = angband_color_table[a][1];
6021                                 gv = angband_color_table[a][2];
6022                                 bv = angband_color_table[a][3];
6023                                 fprintf(fff, "%s<font color=\"#%02x%02x%02x\">", 
6024                                         ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
6025                                 old_a = a;
6026                         }
6027                         if (cc)
6028                                 fprintf(fff, "%s", cc);
6029                         else
6030                                 fprintf(fff, "%c", c);
6031                 }
6032         }
6033         fprintf(fff, "</font>");
6034
6035         if (!tmpfff) {
6036                 for (i = 0; html_foot[i]; i++)
6037                         fprintf(fff, html_foot[i]);
6038         }
6039         else {
6040                 rewind(tmpfff);
6041                 yomikomu = 0;
6042                 while (!my_fgets(tmpfff, buf, sizeof(buf))) {
6043                         if (!yomikomu) {
6044                                 if (strncmp(buf, tags[2], strlen(tags[2])) == 0)
6045                                         yomikomu = 1;
6046                         }
6047                         else {
6048                                 if (strncmp(buf, tags[3], strlen(tags[3])) == 0)
6049                                         break;
6050                                 fprintf(fff, "%s\n", buf);
6051                         }
6052                 }
6053                 my_fclose(tmpfff);
6054         }
6055
6056         /* Skip a line */
6057         fprintf(fff, "\n");
6058
6059         /* Close it */
6060         my_fclose(fff);
6061
6062         /* Message */
6063         if (message) {
6064 #ifdef JP
6065         msg_print("²èÌÌ(µ­Ç°»£±Æ)¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
6066 #else
6067                 msg_print("Screen dump saved.");
6068 #endif
6069                 msg_print(NULL);
6070         }
6071
6072         /* Restore the screen */
6073         if (message)
6074                 screen_load();
6075 }
6076
6077 /*
6078  * Hack -- save a screen dump to a file
6079  */
6080 static void do_cmd_save_screen_html(void)
6081 {
6082         char buf[1024], tmp[256] = "screen.html";
6083
6084 #ifdef JP
6085         if (!get_string("¥Õ¥¡¥¤¥ë̾: ", tmp, 80))
6086 #else
6087         if (!get_string("File name: ", tmp, 80))
6088 #endif
6089                 return;
6090
6091         /* Build the filename */
6092         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, tmp);
6093
6094         msg_print(NULL);
6095
6096         do_cmd_save_screen_html_aux(buf, 1);
6097 }
6098
6099
6100 /*
6101  * Redefinable "save_screen" action
6102  */
6103 void (*screendump_aux)(void) = NULL;
6104
6105
6106 /*
6107  * Hack -- save a screen dump to a file
6108  */
6109 void do_cmd_save_screen(void)
6110 {
6111         bool old_use_graphics = use_graphics;
6112         bool html_dump = FALSE;
6113
6114         int wid, hgt;
6115
6116 #ifdef JP
6117         prt("µ­Ç°»£±Æ¤·¤Þ¤¹¤«¡© [(y)es/(h)tml/(n)o] ", 0, 0);
6118 #else
6119         prt("Save screen dump? [(y)es/(h)tml/(n)o] ", 0, 0);
6120 #endif
6121         while(TRUE)
6122         {
6123                 char c = inkey();
6124                 if (c == 'Y' || c == 'y')
6125                         break;
6126                 else if (c == 'H' || c == 'h')
6127                 {
6128                         html_dump = TRUE;
6129                         break;
6130                 }
6131                 else
6132                 {
6133                         prt("", 0, 0);
6134                         return;
6135                 }
6136         }
6137
6138         Term_get_size(&wid, &hgt);
6139
6140         if (old_use_graphics)
6141         {
6142                 use_graphics = FALSE;
6143                 reset_visuals();
6144
6145                 /* Redraw everything */
6146                 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
6147
6148                 /* Hack -- update */
6149                 handle_stuff();
6150         }
6151
6152         if (html_dump)
6153         {
6154                 do_cmd_save_screen_html();
6155                 do_cmd_redraw();
6156         }
6157
6158         /* Do we use a special screendump function ? */
6159         else if (screendump_aux)
6160         {
6161                 /* Dump the screen to a graphics file */
6162                 (*screendump_aux)();
6163         }
6164         else /* Dump the screen as text */
6165         {
6166                 int y, x;
6167
6168                 byte a = 0;
6169                 char c = ' ';
6170
6171                 FILE *fff;
6172
6173                 char buf[1024];
6174
6175                 /* Build the filename */
6176                 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, "dump.txt");
6177
6178                 /* File type is "TEXT" */
6179                 FILE_TYPE(FILE_TYPE_TEXT);
6180
6181                 /* Append to the file */
6182                 fff = my_fopen(buf, "w");
6183
6184                 /* Oops */
6185                 if (!fff)
6186                 {
6187 #ifdef JP
6188                         msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
6189 #else
6190                         msg_format("Failed to open file %s.", buf);
6191 #endif
6192                         msg_print(NULL);
6193                         return;
6194                 }
6195
6196
6197                 /* Save the screen */
6198                 screen_save();
6199
6200
6201                 /* Dump the screen */
6202                 for (y = 0; y < hgt; y++)
6203                 {
6204                         /* Dump each row */
6205                         for (x = 0; x < wid - 1; x++)
6206                         {
6207                                 /* Get the attr/char */
6208                                 (void)(Term_what(x, y, &a, &c));
6209
6210                                 /* Dump it */
6211                                 buf[x] = c;
6212                         }
6213
6214                         /* Terminate */
6215                         buf[x] = '\0';
6216
6217                         /* End the row */
6218                         fprintf(fff, "%s\n", buf);
6219                 }
6220
6221                 /* Skip a line */
6222                 fprintf(fff, "\n");
6223
6224
6225                 /* Dump the screen */
6226                 for (y = 0; y < hgt; y++)
6227                 {
6228                         /* Dump each row */
6229                         for (x = 0; x < wid - 1; x++)
6230                         {
6231                                 /* Get the attr/char */
6232                                 (void)(Term_what(x, y, &a, &c));
6233
6234                                 /* Dump it */
6235                                 buf[x] = hack[a&0x0F];
6236                         }
6237
6238                         /* Terminate */
6239                         buf[x] = '\0';
6240
6241                         /* End the row */
6242                         fprintf(fff, "%s\n", buf);
6243                 }
6244
6245                 /* Skip a line */
6246                 fprintf(fff, "\n");
6247
6248
6249                 /* Close it */
6250                 my_fclose(fff);
6251
6252                 /* Message */
6253 #ifdef JP
6254         msg_print("²èÌÌ(µ­Ç°»£±Æ)¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£");
6255 #else
6256                 msg_print("Screen dump saved.");
6257 #endif
6258
6259                 msg_print(NULL);
6260
6261
6262                 /* Restore the screen */
6263                 screen_load();
6264         }
6265
6266         if (old_use_graphics)
6267         {
6268                 use_graphics = TRUE;
6269                 reset_visuals();
6270
6271                 /* Redraw everything */
6272                 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
6273
6274                 /* Hack -- update */
6275                 handle_stuff();
6276         }
6277 }
6278
6279
6280 /*
6281  * Sorting hook -- Comp function -- see below
6282  *
6283  * We use "u" to point to array of monster indexes,
6284  * and "v" to select the type of sorting to perform on "u".
6285  */
6286 static bool ang_sort_art_comp(vptr u, vptr v, int a, int b)
6287 {
6288         u16b *who = (u16b*)(u);
6289
6290         u16b *why = (u16b*)(v);
6291
6292         int w1 = who[a];
6293         int w2 = who[b];
6294
6295         int z1, z2;
6296
6297         /* Sort by total kills */
6298         if (*why >= 3)
6299         {
6300                 /* Extract total kills */
6301                 z1 = a_info[w1].tval;
6302                 z2 = a_info[w2].tval;
6303
6304                 /* Compare total kills */
6305                 if (z1 < z2) return (TRUE);
6306                 if (z1 > z2) return (FALSE);
6307         }
6308
6309
6310         /* Sort by monster level */
6311         if (*why >= 2)
6312         {
6313                 /* Extract levels */
6314                 z1 = a_info[w1].sval;
6315                 z2 = a_info[w2].sval;
6316
6317                 /* Compare levels */
6318                 if (z1 < z2) return (TRUE);
6319                 if (z1 > z2) return (FALSE);
6320         }
6321
6322
6323         /* Sort by monster experience */
6324         if (*why >= 1)
6325         {
6326                 /* Extract experience */
6327                 z1 = a_info[w1].level;
6328                 z2 = a_info[w2].level;
6329
6330                 /* Compare experience */
6331                 if (z1 < z2) return (TRUE);
6332                 if (z1 > z2) return (FALSE);
6333         }
6334
6335
6336         /* Compare indexes */
6337         return (w1 <= w2);
6338 }
6339
6340
6341 /*
6342  * Sorting hook -- Swap function -- see below
6343  *
6344  * We use "u" to point to array of monster indexes,
6345  * and "v" to select the type of sorting to perform.
6346  */
6347 static void ang_sort_art_swap(vptr u, vptr v, int a, int b)
6348 {
6349         u16b *who = (u16b*)(u);
6350
6351         u16b holder;
6352
6353         /* Unused */
6354         (void)v;
6355
6356         /* Swap */
6357         holder = who[a];
6358         who[a] = who[b];
6359         who[b] = holder;
6360 }
6361
6362
6363 /*
6364  * Check the status of "artifacts"
6365  */
6366 static void do_cmd_knowledge_artifacts(void)
6367 {
6368         int i, k, z, x, y, n = 0;
6369         u16b why = 3;
6370         s16b *who;
6371
6372         FILE *fff;
6373
6374         char file_name[1024];
6375
6376         char base_name[MAX_NLEN];
6377
6378         bool *okay;
6379
6380         /* Open a new file */
6381         fff = my_fopen_temp(file_name, 1024);
6382
6383         if (!fff) {
6384 #ifdef JP
6385             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6386 #else
6387             msg_format("Failed to create temporary file %s.", file_name);
6388 #endif
6389             msg_print(NULL);
6390             return;
6391         }
6392
6393         /* Allocate the "who" array */
6394         C_MAKE(who, max_a_idx, s16b);
6395
6396         /* Allocate the "okay" array */
6397         C_MAKE(okay, max_a_idx, bool);
6398
6399         /* Scan the artifacts */
6400         for (k = 0; k < max_a_idx; k++)
6401         {
6402                 artifact_type *a_ptr = &a_info[k];
6403
6404                 /* Default */
6405                 okay[k] = FALSE;
6406
6407                 /* Skip "empty" artifacts */
6408                 if (!a_ptr->name) continue;
6409
6410                 /* Skip "uncreated" artifacts */
6411                 if (!a_ptr->cur_num) continue;
6412
6413                 /* Assume okay */
6414                 okay[k] = TRUE;
6415         }
6416
6417         /* Check the dungeon */
6418         for (y = 0; y < cur_hgt; y++)
6419         {
6420                 for (x = 0; x < cur_wid; x++)
6421                 {
6422                         cave_type *c_ptr = &cave[y][x];
6423
6424                         s16b this_o_idx, next_o_idx = 0;
6425
6426                         /* Scan all objects in the grid */
6427                         for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
6428                         {
6429                                 object_type *o_ptr;
6430
6431                                 /* Acquire object */
6432                                 o_ptr = &o_list[this_o_idx];
6433
6434                                 /* Acquire next object */
6435                                 next_o_idx = o_ptr->next_o_idx;
6436
6437                                 /* Ignore non-artifacts */
6438                                 if (!artifact_p(o_ptr)) continue;
6439
6440                                 /* Ignore known items */
6441                                 if (object_known_p(o_ptr)) continue;
6442
6443                                 /* Note the artifact */
6444                                 okay[o_ptr->name1] = FALSE;
6445                         }
6446                 }
6447         }
6448
6449         /* Check the inventory and equipment */
6450         for (i = 0; i < INVEN_TOTAL; i++)
6451         {
6452                 object_type *o_ptr = &inventory[i];
6453
6454                 /* Ignore non-objects */
6455                 if (!o_ptr->k_idx) continue;
6456
6457                 /* Ignore non-artifacts */
6458                 if (!artifact_p(o_ptr)) continue;
6459
6460                 /* Ignore known items */
6461                 if (object_known_p(o_ptr)) continue;
6462
6463                 /* Note the artifact */
6464                 okay[o_ptr->name1] = FALSE;
6465         }
6466
6467         for (k = 0; k < max_a_idx; k++)
6468         {
6469                 if (okay[k]) who[n++] = k;
6470         }
6471
6472         /* Select the sort method */
6473         ang_sort_comp = ang_sort_art_comp;
6474         ang_sort_swap = ang_sort_art_swap;
6475
6476         /* Sort the array by dungeon depth of monsters */
6477         ang_sort(who, &why, n);
6478
6479         /* Scan the artifacts */
6480         for (k = 0; k < n; k++)
6481         {
6482                 artifact_type *a_ptr = &a_info[who[k]];
6483
6484                 /* Paranoia */
6485 #ifdef JP
6486                 strcpy(base_name, "̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à");
6487 #else
6488                 strcpy(base_name, "Unknown Artifact");
6489 #endif
6490
6491
6492                 /* Obtain the base object type */
6493                 z = lookup_kind(a_ptr->tval, a_ptr->sval);
6494
6495                 /* Real object */
6496                 if (z)
6497                 {
6498                         object_type forge;
6499                         object_type *q_ptr;
6500
6501                         /* Get local object */
6502                         q_ptr = &forge;
6503
6504                         /* Create fake object */
6505                         object_prep(q_ptr, z);
6506
6507                         /* Make it an artifact */
6508                         q_ptr->name1 = (byte)who[k];
6509
6510                         /* Describe the artifact */
6511                         object_desc_store(base_name, q_ptr, FALSE, 0);
6512                 }
6513
6514                 /* Hack -- Build the artifact name */
6515 #ifdef JP
6516                 fprintf(fff, "     %s\n", base_name);
6517 #else
6518                 fprintf(fff, "     The %s\n", base_name);
6519 #endif
6520
6521         }
6522
6523         /* Free the "who" array */
6524         C_KILL(who, max_a_idx, s16b);
6525
6526         /* Free the "okay" array */
6527         C_KILL(okay, max_a_idx, bool);
6528
6529         /* Close the file */
6530         my_fclose(fff);
6531
6532         /* Display the file contents */
6533 #ifdef JP
6534         show_file(TRUE, file_name, "´ûÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à", 0, 0);
6535 #else
6536         show_file(TRUE, file_name, "Artifacts Seen", 0, 0);
6537 #endif
6538
6539
6540         /* Remove the file */
6541         fd_kill(file_name);
6542 }
6543
6544
6545 /*
6546  * Display known uniques
6547  */
6548 static void do_cmd_knowledge_uniques(void)
6549 {
6550         int i, k, n = 0;
6551         u16b why = 2;
6552         s16b *who;
6553
6554         FILE *fff;
6555
6556         char file_name[1024];
6557
6558         /* Open a new file */
6559         fff = my_fopen_temp(file_name, 1024);
6560
6561         if (!fff) {
6562 #ifdef JP
6563             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6564 #else
6565             msg_format("Failed to create temporary file %s.", file_name);
6566 #endif
6567             msg_print(NULL);
6568             return;
6569         }
6570
6571         /* Allocate the "who" array */
6572         C_MAKE(who, max_r_idx, s16b);
6573
6574         /* Scan the monsters */
6575         for (i = 1; i < max_r_idx; i++)
6576         {
6577                 monster_race *r_ptr = &r_info[i];
6578
6579                 /* Use that monster */
6580                 if (r_ptr->name) who[n++] = i;
6581         }
6582
6583         /* Select the sort method */
6584         ang_sort_comp = ang_sort_comp_hook;
6585         ang_sort_swap = ang_sort_swap_hook;
6586
6587         /* Sort the array by dungeon depth of monsters */
6588         ang_sort(who, &why, n);
6589
6590         /* Scan the monster races */
6591         for (k = 0; k < n; k++)
6592         {
6593                 monster_race *r_ptr = &r_info[who[k]];
6594
6595                 /* Only print Uniques */
6596                 if (r_ptr->flags1 & (RF1_UNIQUE))
6597                 {
6598                         bool dead = (r_ptr->max_num == 0);
6599
6600                         if (dead) continue;
6601
6602                         /* Only display "known" uniques */
6603                         if (dead || cheat_know || r_ptr->r_sights)
6604                         {
6605                                 /* Print a message */
6606 #ifdef JP
6607                                 fprintf(fff, "     %s¤Ï¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë¡£\n",
6608                                         (r_name + r_ptr->name));
6609 #else
6610                                 fprintf(fff, "     %s is alive\n",
6611                                         (r_name + r_ptr->name));
6612 #endif
6613
6614                         }
6615                 }
6616         }
6617
6618         /* Free the "who" array */
6619         C_KILL(who, max_r_idx, s16b);
6620
6621         /* Close the file */
6622         my_fclose(fff);
6623
6624         /* Display the file contents */
6625 #ifdef JP
6626         show_file(TRUE, file_name, "¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼", 0, 0);
6627 #else
6628         show_file(TRUE, file_name, "Alive Uniques", 0, 0);
6629 #endif
6630
6631
6632         /* Remove the file */
6633         fd_kill(file_name);
6634 }
6635
6636
6637 /*
6638  * Display weapon-exp
6639  */
6640 static void do_cmd_knowledge_weapon_exp(void)
6641 {
6642         int i, j, num, weapon_exp;
6643
6644         FILE *fff;
6645
6646         char file_name[1024];
6647         char tmp[30];
6648
6649         /* Open a new file */
6650         fff = my_fopen_temp(file_name, 1024);
6651         if (!fff) {
6652 #ifdef JP
6653             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6654 #else
6655             msg_format("Failed to create temporary file %s.", file_name);
6656 #endif
6657             msg_print(NULL);
6658             return;
6659         }
6660
6661         for (i = 0; i < 5; i++)
6662         {
6663                 for (num = 0; num < 64; num++)
6664                 {
6665                         for (j = 0; j < max_k_idx; j++)
6666                         {
6667                                 object_kind *k_ptr = &k_info[j];
6668
6669                                 if ((k_ptr->tval == TV_SWORD - i) && (k_ptr->sval == num))
6670                                 {
6671                                         if ((k_ptr->tval == TV_BOW) && (k_ptr->sval == SV_CRIMSON)) continue;
6672
6673                                         weapon_exp = p_ptr->weapon_exp[4 - i][num];
6674                                         strip_name(tmp, j);
6675                                         fprintf(fff, "%-25s ", tmp);
6676                                         if (weapon_exp >= s_info[p_ptr->pclass].w_max[4 - i][num]) fprintf(fff, "!");
6677                                         else fprintf(fff, " ");
6678                                         fprintf(fff, "%s", exp_level_str[weapon_exp_level(weapon_exp)]);
6679                                         if (cheat_xtra) fprintf(fff, " %d", weapon_exp);
6680                                         fprintf(fff, "\n");
6681                                         break;
6682                                 }
6683                         }
6684                 }
6685         }
6686
6687         /* Close the file */
6688         my_fclose(fff);
6689
6690         /* Display the file contents */
6691 #ifdef JP
6692         show_file(TRUE, file_name, "Éð´ï¤Î·Ð¸³ÃÍ", 0, 0);
6693 #else
6694         show_file(TRUE, file_name, "Weapon Proficiency", 0, 0);
6695 #endif
6696
6697
6698         /* Remove the file */
6699         fd_kill(file_name);
6700 }
6701
6702
6703 /*
6704  * Display spell-exp
6705  */
6706 static void do_cmd_knowledge_spell_exp(void)
6707 {
6708         int i = 0, spell_exp, exp_level;
6709
6710         FILE *fff;
6711         magic_type *s_ptr;
6712
6713         char file_name[1024];
6714
6715         /* Open a new file */
6716         fff = my_fopen_temp(file_name, 1024);
6717         if (!fff) {
6718 #ifdef JP
6719             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6720 #else
6721             msg_format("Failed to create temporary file %s.", file_name);
6722 #endif
6723             msg_print(NULL);
6724             return;
6725         }
6726
6727         if (p_ptr->realm1 != REALM_NONE)
6728         {
6729 #ifdef JP
6730                 fprintf(fff, "%s¤ÎËâË¡½ñ\n", realm_names[p_ptr->realm1]);
6731 #else
6732                 fprintf(fff, "%s Spellbook\n", realm_names[p_ptr->realm1]);
6733 #endif
6734                 for (i = 0; i < 32; i++)
6735                 {
6736                         if (!is_magic(p_ptr->realm1))
6737                         {
6738                                 s_ptr = &technic_info[p_ptr->realm1 - MIN_TECHNIC][i];
6739                         }
6740                         else
6741                         {
6742                                 s_ptr = &mp_ptr->info[p_ptr->realm1 - 1][i];
6743                         }
6744                         if (s_ptr->slevel >= 99) continue;
6745                         spell_exp = p_ptr->spell_exp[i];
6746                         exp_level = spell_exp_level(spell_exp);
6747                         fprintf(fff, "%-25s ", spell_names[technic2magic(p_ptr->realm1) - 1][i]);
6748                         if (p_ptr->realm1 == REALM_HISSATSU)
6749                                 fprintf(fff, "[--]");
6750                         else
6751                         {
6752                                 if (exp_level >= EXP_LEVEL_MASTER) fprintf(fff, "!");
6753                                 else fprintf(fff, " ");
6754                                 fprintf(fff, "%s", exp_level_str[exp_level]);
6755                         }
6756                         if (cheat_xtra) fprintf(fff, " %d", spell_exp);
6757                         fprintf(fff, "\n");
6758                 }
6759         }
6760
6761         if (p_ptr->realm2 != REALM_NONE)
6762         {
6763 #ifdef JP
6764                 fprintf(fff, "%s¤ÎËâË¡½ñ\n", realm_names[p_ptr->realm2]);
6765 #else
6766                 fprintf(fff, "\n%s Spellbook\n", realm_names[p_ptr->realm2]);
6767 #endif
6768                 for (i = 0; i < 32; i++)
6769                 {
6770                         if (!is_magic(p_ptr->realm1))
6771                         {
6772                                 s_ptr = &technic_info[p_ptr->realm2 - MIN_TECHNIC][i];
6773                         }
6774                         else
6775                         {
6776                                 s_ptr = &mp_ptr->info[p_ptr->realm2 - 1][i];
6777                         }
6778                         if (s_ptr->slevel >= 99) continue;
6779
6780                         spell_exp = p_ptr->spell_exp[i + 32];
6781                         exp_level = spell_exp_level(spell_exp);
6782                         fprintf(fff, "%-25s ", spell_names[technic2magic(p_ptr->realm2) - 1][i]);
6783                         if (exp_level >= EXP_LEVEL_EXPERT) fprintf(fff, "!");
6784                         else fprintf(fff, " ");
6785                         fprintf(fff, "%s", exp_level_str[exp_level]);
6786                         if (cheat_xtra) fprintf(fff, " %d", spell_exp);
6787                         fprintf(fff, "\n");
6788                 }
6789         }
6790
6791         /* Close the file */
6792         my_fclose(fff);
6793
6794         /* Display the file contents */
6795 #ifdef JP
6796         show_file(TRUE, file_name, "ËâË¡¤Î·Ð¸³ÃÍ", 0, 0);
6797 #else
6798         show_file(TRUE, file_name, "Spell Proficiency", 0, 0);
6799 #endif
6800
6801
6802         /* Remove the file */
6803         fd_kill(file_name);
6804 }
6805
6806
6807 /*
6808  * Display skill-exp
6809  */
6810 static void do_cmd_knowledge_skill_exp(void)
6811 {
6812         int i = 0, skill_exp;
6813
6814         FILE *fff;
6815
6816         char file_name[1024];
6817 #ifdef JP
6818         char skill_name[3][17]={"¥Þ¡¼¥·¥ã¥ë¥¢¡¼¥Ä", "ÆóÅáή          ", "¾èÇÏ            "};
6819 #else
6820         char skill_name[3][20]={"Martial Arts    ", "Dual Wielding   ", "Riding          "};
6821 #endif
6822
6823         /* Open a new file */
6824         fff = my_fopen_temp(file_name, 1024);
6825         if (!fff) {
6826 #ifdef JP
6827             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
6828 #else
6829             msg_format("Failed to create temporary file %s.", file_name);
6830 #endif
6831             msg_print(NULL);
6832             return;
6833         }
6834
6835         for (i = 0; i < 3; i++)
6836         {
6837                 skill_exp = p_ptr->skill_exp[i];
6838                 fprintf(fff, "%-20s ", skill_name[i]);
6839                 if (skill_exp >= s_info[p_ptr->pclass].s_max[i]) fprintf(fff, "!");
6840                 else fprintf(fff, " ");
6841                 fprintf(fff, "%s", exp_level_str[(i == GINOU_RIDING) ? riding_exp_level(skill_exp) : weapon_exp_level(skill_exp)]);
6842                 if (cheat_xtra) fprintf(fff, " %d", skill_exp);
6843                 fprintf(fff, "\n");
6844         }
6845
6846         /* Close the file */
6847         my_fclose(fff);
6848
6849         /* Display the file contents */
6850 #ifdef JP
6851         show_file(TRUE, file_name, "µ»Ç½¤Î·Ð¸³ÃÍ", 0, 0);
6852 #else
6853         show_file(TRUE, file_name, "Miscellaneous Proficiency", 0, 0);
6854 #endif
6855
6856
6857         /* Remove the file */
6858         fd_kill(file_name);
6859 }
6860
6861
6862 /*
6863  * Pluralize a monster name
6864  */
6865 void plural_aux(char *Name)
6866 {
6867         int NameLen = strlen(Name);
6868
6869         if (strstr(Name, "Disembodied hand"))
6870         {
6871                 strcpy(Name, "Disembodied hands that strangled people");
6872         }
6873         else if (strstr(Name, "Colour out of space"))
6874         {
6875                 strcpy(Name, "Colours out of space");
6876         }
6877         else if (strstr(Name, "stairway to hell"))
6878         {
6879                 strcpy(Name, "stairways to hell");
6880         }
6881         else if (strstr(Name, "Dweller on the threshold"))
6882         {
6883                 strcpy(Name, "Dwellers on the threshold");
6884         }
6885         else if (strstr(Name, " of "))
6886         {
6887                 cptr aider = strstr(Name, " of ");
6888                 char dummy[80];
6889                 int i = 0;
6890                 cptr ctr = Name;
6891
6892                 while (ctr < aider)
6893                 {
6894                         dummy[i] = *ctr;
6895                         ctr++; i++;
6896                 }
6897
6898                 if (dummy[i-1] == 's')
6899                 {
6900                         strcpy(&(dummy[i]), "es");
6901                         i++;
6902                 }
6903                 else
6904                 {
6905                         strcpy(&(dummy[i]), "s");
6906                 }
6907
6908                 strcpy(&(dummy[i+1]), aider);
6909                 strcpy(Name, dummy);
6910         }
6911         else if (strstr(Name, "coins"))
6912         {
6913                 char dummy[80];
6914                 strcpy(dummy, "piles of ");
6915                 strcat(dummy, Name);
6916                 strcpy(Name, dummy);
6917                 return;
6918         }
6919         else if (strstr(Name, "Manes"))
6920         {
6921                 return;
6922         }
6923         else if (streq(&(Name[NameLen - 2]), "ey"))
6924         {
6925                 strcpy(&(Name[NameLen - 2]), "eys");
6926         }
6927         else if (Name[NameLen - 1] == 'y')
6928         {
6929                 strcpy(&(Name[NameLen - 1]), "ies");
6930         }
6931         else if (streq(&(Name[NameLen - 4]), "ouse"))
6932         {
6933                 strcpy(&(Name[NameLen - 4]), "ice");
6934         }
6935         else if (streq(&(Name[NameLen - 2]), "us"))
6936         {
6937                 strcpy(&(Name[NameLen - 2]), "i");
6938         }
6939         else if (streq(&(Name[NameLen - 6]), "kelman"))
6940         {
6941                 strcpy(&(Name[NameLen - 6]), "kelmen");
6942         }
6943         else if (streq(&(Name[NameLen - 8]), "wordsman"))
6944         {
6945                 strcpy(&(Name[NameLen - 8]), "wordsmen");
6946         }
6947         else if (streq(&(Name[NameLen - 7]), "oodsman"))
6948         {
6949                 strcpy(&(Name[NameLen - 7]), "oodsmen");
6950         }
6951         else if (streq(&(Name[NameLen - 7]), "eastman"))
6952         {
6953                 strcpy(&(Name[NameLen - 7]), "eastmen");
6954         }
6955         else if (streq(&(Name[NameLen - 8]), "izardman"))
6956         {
6957                 strcpy(&(Name[NameLen - 8]), "izardmen");
6958         }
6959         else if (streq(&(Name[NameLen - 5]), "geist"))
6960         {
6961                 strcpy(&(Name[NameLen - 5]), "geister");
6962         }
6963         else if (streq(&(Name[NameLen - 2]), "ex"))
6964         {
6965                 strcpy(&(Name[NameLen - 2]), "ices");
6966         }
6967         else if (streq(&(Name[NameLen - 2]), "lf"))
6968         {
6969                 strcpy(&(Name[NameLen - 2]), "lves");
6970         }
6971         else if (suffix(Name, "ch") ||
6972                  suffix(Name, "sh") ||
6973                          suffix(Name, "nx") ||
6974                          suffix(Name, "s") ||
6975                          suffix(Name, "o"))
6976         {
6977                 strcpy(&(Name[NameLen]), "es");
6978         }
6979         else
6980         {
6981                 strcpy(&(Name[NameLen]), "s");
6982         }
6983 }
6984
6985 /*
6986  * Display current pets
6987  */
6988 static void do_cmd_knowledge_pets(void)
6989 {
6990         int             i;
6991         FILE            *fff;
6992         monster_type    *m_ptr;
6993         char            pet_name[80];
6994         int             t_friends = 0;
6995         int             show_upkeep = 0;
6996         char            file_name[1024];
6997
6998
6999         /* Open a new file */
7000         fff = my_fopen_temp(file_name, 1024);
7001         if (!fff) {
7002 #ifdef JP
7003             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
7004 #else
7005             msg_format("Failed to create temporary file %s.", file_name);
7006 #endif
7007             msg_print(NULL);
7008             return;
7009         }
7010
7011         /* Process the monsters (backwards) */
7012         for (i = m_max - 1; i >= 1; i--)
7013         {
7014                 /* Access the monster */
7015                 m_ptr = &m_list[i];
7016
7017                 /* Ignore "dead" monsters */
7018                 if (!m_ptr->r_idx) continue;
7019
7020                 /* Calculate "upkeep" for pets */
7021                 if (is_pet(m_ptr))
7022                 {
7023                         t_friends++;
7024                         monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
7025                         fprintf(fff, "%s (%s)\n", pet_name, look_mon_desc(m_ptr, 0x00));
7026                 }
7027         }
7028
7029         show_upkeep = calculate_upkeep();
7030
7031         fprintf(fff, "----------------------------------------------\n");
7032 #ifdef JP
7033         fprintf(fff, "    ¹ç·×: %d É¤¤Î¥Ú¥Ã¥È\n", t_friends);
7034         fprintf(fff, " °Ý»ý¥³¥¹¥È: %d%% MP\n", show_upkeep);
7035 #else
7036         fprintf(fff, "   Total: %d pet%s.\n",
7037                 t_friends, (t_friends == 1 ? "" : "s"));
7038         fprintf(fff, "   Upkeep: %d%% mana.\n", show_upkeep);
7039 #endif
7040
7041
7042
7043         /* Close the file */
7044         my_fclose(fff);
7045
7046         /* Display the file contents */
7047 #ifdef JP
7048         show_file(TRUE, file_name, "¸½ºß¤Î¥Ú¥Ã¥È", 0, 0);
7049 #else
7050         show_file(TRUE, file_name, "Current Pets", 0, 0);
7051 #endif
7052
7053
7054         /* Remove the file */
7055         fd_kill(file_name);
7056 }
7057
7058
7059 /*
7060  * Total kill count
7061  *
7062  * Note that the player ghosts are ignored.  XXX XXX XXX
7063  */
7064 static void do_cmd_knowledge_kill_count(void)
7065 {
7066         int i, k, n = 0;
7067         u16b why = 2;
7068         s16b *who;
7069
7070         FILE *fff;
7071
7072         char file_name[1024];
7073
7074         s32b Total = 0;
7075
7076
7077         /* Open a new file */
7078         fff = my_fopen_temp(file_name, 1024);
7079
7080         if (!fff) {
7081 #ifdef JP
7082             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
7083 #else
7084             msg_format("Failed to create temporary file %s.", file_name);
7085 #endif
7086             msg_print(NULL);
7087             return;
7088         }
7089
7090         /* Allocate the "who" array */
7091         C_MAKE(who, max_r_idx, s16b);
7092
7093         {
7094                 /* Monsters slain */
7095                 int kk;
7096
7097                 for (kk = 1; kk < max_r_idx; kk++)
7098                 {
7099                         monster_race *r_ptr = &r_info[kk];
7100
7101                         if (r_ptr->flags1 & (RF1_UNIQUE))
7102                         {
7103                                 bool dead = (r_ptr->max_num == 0);
7104
7105                                 if (dead)
7106                                 {
7107                                         Total++;
7108                                 }
7109                         }
7110                         else
7111                         {
7112                                 s16b This = r_ptr->r_pkills;
7113
7114                                 if (This > 0)
7115                                 {
7116                                         Total += This;
7117                                 }
7118                         }
7119                 }
7120
7121                 if (Total < 1)
7122 #ifdef JP
7123                         fprintf(fff,"¤¢¤Ê¤¿¤Ï¤Þ¤ÀŨ¤òÅݤ·¤Æ¤¤¤Ê¤¤¡£\n\n");
7124 #else
7125                         fprintf(fff,"You have defeated no enemies yet.\n\n");
7126 #endif
7127
7128                 else if (Total == 1)
7129 #ifdef JP
7130                         fprintf(fff,"¤¢¤Ê¤¿¤Ï°ìɤ¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n");
7131 #else
7132                         fprintf(fff,"You have defeated one enemy.\n\n");
7133 #endif
7134
7135                 else
7136 #ifdef JP
7137                         fprintf(fff,"¤¢¤Ê¤¿¤Ï %lu É¤¤ÎŨ¤òÅݤ·¤Æ¤¤¤ë¡£\n\n", Total);
7138 #else
7139                         fprintf(fff,"You have defeated %lu enemies.\n\n", Total);
7140 #endif
7141
7142         }
7143
7144         Total = 0;
7145
7146         /* Scan the monsters */
7147         for (i = 1; i < max_r_idx; i++)
7148         {
7149                 monster_race *r_ptr = &r_info[i];
7150
7151                 /* Use that monster */
7152                 if (r_ptr->name) who[n++] = i;
7153         }
7154
7155         /* Select the sort method */
7156         ang_sort_comp = ang_sort_comp_hook;
7157         ang_sort_swap = ang_sort_swap_hook;
7158
7159         /* Sort the array by dungeon depth of monsters */
7160         ang_sort(who, &why, n);
7161
7162         /* Scan the monster races */
7163         for (k = 0; k < n; k++)
7164         {
7165                 monster_race *r_ptr = &r_info[who[k]];
7166
7167                 if (r_ptr->flags1 & (RF1_UNIQUE))
7168                 {
7169                         bool dead = (r_ptr->max_num == 0);
7170
7171                         if (dead)
7172                         {
7173                                 /* Print a message */
7174                                 fprintf(fff, "     %s\n",
7175                                     (r_name + r_ptr->name));
7176                                 Total++;
7177                         }
7178                 }
7179                 else
7180                 {
7181                         s16b This = r_ptr->r_pkills;
7182
7183                         if (This > 0)
7184                         {
7185 #ifdef JP
7186                                 /* p,t¤Ï¿Í¤È¿ô¤¨¤ë by ita*/
7187                                 if(strchr("pt",r_ptr->d_char))
7188                                         fprintf(fff, "     %3d ¿Í¤Î %s\n", This, r_name + r_ptr->name);
7189                                 else
7190                                         fprintf(fff, "     %3d É¤¤Î %s\n", This, r_name + r_ptr->name);
7191 #else
7192                                 if (This < 2)
7193                                 {
7194                                         if (strstr(r_name + r_ptr->name, "coins"))
7195                                         {
7196                                                 fprintf(fff, "     1 pile of %s\n", (r_name + r_ptr->name));
7197                                         }
7198                                         else
7199                                         {
7200                                                 fprintf(fff, "     1 %s\n", (r_name + r_ptr->name));
7201                                         }
7202                                 }
7203                                 else
7204                                 {
7205                                         char ToPlural[80];
7206                                         strcpy(ToPlural, (r_name + r_ptr->name));
7207                                         plural_aux(ToPlural);
7208                                         fprintf(fff, "     %d %s\n", This, ToPlural);
7209                                 }
7210 #endif
7211
7212
7213                                 Total += This;
7214                         }
7215                 }
7216         }
7217
7218         fprintf(fff,"----------------------------------------------\n");
7219 #ifdef JP
7220         fprintf(fff,"    ¹ç·×: %lu É¤¤òÅݤ·¤¿¡£\n", Total);
7221 #else
7222         fprintf(fff,"   Total: %lu creature%s killed.\n",
7223                 Total, (Total == 1 ? "" : "s"));
7224 #endif
7225
7226
7227         /* Free the "who" array */
7228         C_KILL(who, max_r_idx, s16b);
7229
7230         /* Close the file */
7231         my_fclose(fff);
7232
7233         /* Display the file contents */
7234 #ifdef JP
7235         show_file(TRUE, file_name, "Åݤ·¤¿Å¨¤Î¿ô", 0, 0);
7236 #else
7237         show_file(TRUE, file_name, "Kill Count", 0, 0);
7238 #endif
7239
7240
7241         /* Remove the file */
7242         fd_kill(file_name);
7243 }
7244
7245
7246 /*
7247  * Display the object groups.
7248  */
7249 static void display_group_list(int col, int row, int wid, int per_page,
7250         int grp_idx[], cptr group_text[], int grp_cur, int grp_top)
7251 {
7252         int i;
7253
7254         /* Display lines until done */
7255         for (i = 0; i < per_page && (grp_idx[i] >= 0); i++)
7256         {
7257                 /* Get the group index */
7258                 int grp = grp_idx[grp_top + i];
7259
7260                 /* Choose a color */
7261                 byte attr = (grp_top + i == grp_cur) ? TERM_L_BLUE : TERM_WHITE;
7262
7263                 /* Erase the entire line */
7264                 Term_erase(col, row + i, wid);
7265
7266                 /* Display the group label */
7267                 c_put_str(attr, group_text[grp], row + i, col);
7268         }
7269 }
7270
7271
7272 /* 
7273  * Move the cursor in a browser window 
7274  */
7275 static void browser_cursor(char ch, int *column, int *grp_cur, int grp_cnt, 
7276                                                    int *list_cur, int list_cnt)
7277 {
7278         int d;
7279         int col = *column;
7280         int grp = *grp_cur;
7281         int list = *list_cur;
7282
7283         /* Extract direction */
7284         if (ch == ' ')
7285         {
7286                 /* Hack -- scroll up full screen */
7287                 d = 3;
7288         }
7289         else if (ch == '-')
7290         {
7291                 /* Hack -- scroll down full screen */
7292                 d = 9;
7293         }
7294         else
7295         {
7296                 d = get_keymap_dir(ch);
7297         }
7298
7299         if (!d) return;
7300
7301         /* Diagonals - hack */
7302         if ((ddx[d] > 0) && ddy[d])
7303         {
7304                 int browser_rows;
7305                 int wid, hgt;
7306
7307                 /* Get size */
7308                 Term_get_size(&wid, &hgt);
7309
7310                 browser_rows = hgt - 8;
7311
7312                 /* Browse group list */
7313                 if (!col)
7314                 {
7315                         int old_grp = grp;
7316
7317                         /* Move up or down */
7318                         grp += ddy[d] * (browser_rows - 1);
7319
7320                         /* Verify */
7321                         if (grp >= grp_cnt)     grp = grp_cnt - 1;
7322                         if (grp < 0) grp = 0;
7323                         if (grp != old_grp)     list = 0;
7324                 }
7325
7326                 /* Browse sub-list list */
7327                 else
7328                 {
7329                         /* Move up or down */
7330                         list += ddy[d] * browser_rows;
7331
7332                         /* Verify */
7333                         if (list >= list_cnt) list = list_cnt - 1;
7334                         if (list < 0) list = 0;
7335                 }
7336
7337                 (*grp_cur) = grp;
7338                 (*list_cur) = list;
7339
7340                 return;
7341         }
7342
7343         if (ddx[d])
7344         {
7345                 col += ddx[d];
7346                 if (col < 0) col = 0;
7347                 if (col > 1) col = 1;
7348
7349                 (*column) = col;
7350
7351                 return;
7352         }
7353
7354         /* Browse group list */
7355         if (!col)
7356         {
7357                 int old_grp = grp;
7358
7359                 /* Move up or down */
7360                 grp += ddy[d];
7361
7362                 /* Verify */
7363                 if (grp >= grp_cnt)     grp = grp_cnt - 1;
7364                 if (grp < 0) grp = 0;
7365                 if (grp != old_grp)     list = 0;
7366         }
7367
7368         /* Browse sub-list list */
7369         else
7370         {
7371                 /* Move up or down */
7372                 list += ddy[d];
7373
7374                 /* Verify */
7375                 if (list >= list_cnt) list = list_cnt - 1;
7376                 if (list < 0) list = 0;
7377         }
7378
7379         (*grp_cur) = grp;
7380         (*list_cur) = list;
7381 }
7382
7383
7384 /*
7385  * Display visuals.
7386  */
7387 static void display_visual_list(int col, int row, int height, int width, byte attr_top, byte char_left)
7388 {
7389         int i, j;
7390
7391         /* Clear the display lines */
7392         for (i = 0; i < height; i++)
7393         {
7394                 Term_erase(col, row + i, width);
7395         }
7396
7397         /* Bigtile mode uses double width */
7398         if (use_bigtile) width /= 2;
7399
7400         /* Display lines until done */
7401         for (i = 0; i < height; i++)
7402         {
7403                 /* Display columns until done */
7404                 for (j = 0; j < width; j++)
7405                 {
7406                         byte a, a2;
7407                         char c, c2;
7408                         int x = col + j;
7409                         int y = row + i;
7410                         int ia, ic;
7411
7412                         /* Bigtile mode uses double width */
7413                         if (use_bigtile) x += j;
7414
7415                         ia = attr_top + i;
7416                         ic = char_left + j;
7417
7418                         /* Ignore illegal characters */
7419                         if (ia > 0x7f || ic > 0xff || ic < ' ' ||
7420                             (!use_graphics && ic > 0x7f))
7421                                 continue;
7422
7423                         a = (byte)ia;
7424                         c = (char)ic;
7425
7426                         /* Force correct code for both ASCII character and tile */
7427                         if (c & 0x80) a |= 0x80;
7428
7429                         if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
7430
7431                         /* Display symbol */
7432                         Term_putch(x, y, a, c);
7433
7434                         /* Second byte */
7435                         if (use_bigtile) Term_putch(x + 1, y, a2, c2);
7436                 }
7437         }
7438 }
7439
7440
7441 /*
7442  * Place the cursor at the collect position for visual mode
7443  */
7444 static void place_visual_list_cursor(int col, int row, byte a, byte c, byte attr_top, byte char_left)
7445 {
7446         int i = (a & 0x7f) - attr_top;
7447         int j = c - char_left;
7448
7449         int x = col + j;
7450         int y = row + i;
7451
7452         /* Bigtile mode uses double width */
7453         if (use_bigtile) x += j;
7454
7455         /* Place the cursor */
7456         Term_gotoxy(x, y);
7457 }
7458
7459
7460 /*
7461  *  Clipboard variables for copy&paste in visual mode
7462  */
7463 static byte attr_idx = 0;
7464 static byte char_idx = 0;
7465
7466 /*
7467  *  Do visual mode command -- Change symbols
7468  */
7469 static bool visual_mode_command(char ch, bool *visual_list_ptr, 
7470                                 int height, int width, 
7471                                 byte *attr_top_ptr, byte *char_left_ptr, 
7472                                 byte *cur_attr_ptr, byte *cur_char_ptr)
7473 {
7474         static byte attr_old = 0, char_old = 0;
7475
7476         switch (ch)
7477         {
7478         case ESCAPE:
7479                 if (*visual_list_ptr)
7480                 {
7481                         /* Cancel change */
7482                         *cur_attr_ptr = attr_old;
7483                         *cur_char_ptr = char_old;
7484                         *visual_list_ptr = FALSE;
7485
7486                         return TRUE;
7487                 }
7488
7489                 break;
7490
7491         case '\n':
7492         case '\r':
7493                 if (*visual_list_ptr)
7494                 {
7495                         /* Accept change */
7496                         *visual_list_ptr = FALSE;
7497
7498                         return TRUE;
7499                 }
7500                 break;
7501
7502         case 'V':
7503         case 'v':
7504                 if (!*visual_list_ptr)
7505                 {
7506                         *visual_list_ptr = TRUE;
7507
7508                         *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
7509                         *char_left_ptr = MAX(0, *cur_char_ptr - 10);
7510
7511                         attr_old = *cur_attr_ptr;
7512                         char_old = *cur_char_ptr;
7513
7514                         return TRUE;
7515                 }
7516                 break;
7517
7518         case 'C':
7519         case 'c':
7520                 /* Set the visual */
7521                 attr_idx = *cur_attr_ptr;
7522                 char_idx = *cur_char_ptr;
7523
7524                 return TRUE;
7525
7526         case 'P':
7527         case 'p':
7528                 if (attr_idx)
7529                 {
7530                         /* Set the char */
7531                         *cur_attr_ptr = attr_idx;
7532                         *attr_top_ptr = MAX(0, (*cur_attr_ptr & 0x7f) - 5);
7533                 }
7534
7535                 if (char_idx)
7536                 {
7537                         /* Set the char */
7538                         *cur_char_ptr = char_idx;
7539                         *char_left_ptr = MAX(0, *cur_char_ptr - 10);
7540                 }
7541
7542                 return TRUE;
7543
7544         default:
7545                 if (*visual_list_ptr)
7546                 {
7547                         int eff_width;
7548                         int d = get_keymap_dir(ch);
7549                         byte a = (*cur_attr_ptr & 0x7f);
7550                         byte c = *cur_char_ptr;
7551
7552                         if (use_bigtile) eff_width = width / 2;
7553                         else eff_width = width;
7554                                         
7555                         /* Restrict direction */
7556                         if ((a == 0) && (ddy[d] < 0)) d = 0;
7557                         if ((c == 0) && (ddx[d] < 0)) d = 0;
7558                         if ((a == 0x7f) && (ddy[d] > 0)) d = 0;
7559                         if ((c == 0xff) && (ddx[d] > 0)) d = 0;
7560
7561                         a += ddy[d];
7562                         c += ddx[d];
7563
7564                         /* Force correct code for both ASCII character and tile */
7565                         if (c & 0x80) a |= 0x80;
7566
7567                         /* Set the visual */
7568                         *cur_attr_ptr = a;
7569                         *cur_char_ptr = c;
7570
7571
7572                         /* Move the frame */
7573                         if ((ddx[d] < 0) && *char_left_ptr > MAX(0, (int)c - 10)) (*char_left_ptr)--;
7574                         if ((ddx[d] > 0) && *char_left_ptr + eff_width < MIN(0xff, (int)c + 10)) (*char_left_ptr)++;
7575                         if ((ddy[d] < 0) && *attr_top_ptr > MAX(0, (int)(a & 0x7f) - 4)) (*attr_top_ptr)--;
7576                         if ((ddy[d] > 0) && *attr_top_ptr + height < MIN(0x7f, (a & 0x7f) + 4)) (*attr_top_ptr)++;
7577                         return TRUE;
7578                 }
7579                                 
7580                 break;
7581         }
7582
7583         /* Visual mode command is not used */
7584         return FALSE;
7585 }
7586
7587
7588 /*
7589  * Display the monsters in a group.
7590  */
7591 static void display_monster_list(int col, int row, int per_page, s16b mon_idx[],
7592         int mon_cur, int mon_top)
7593 {
7594         int i;
7595
7596         /* Display lines until done */
7597         for (i = 0; i < per_page && mon_idx[mon_top + i]; i++)
7598         {
7599                 byte attr;
7600                 byte a, a2;
7601                 char c, c2;
7602
7603                 /* Get the race index */
7604                 int r_idx = mon_idx[mon_top + i] ;
7605
7606                 /* Access the race */
7607                 monster_race *r_ptr = &r_info[r_idx];
7608
7609
7610                 /* Choose a color */
7611                 attr = ((i + mon_top == mon_cur) ? TERM_L_BLUE : TERM_WHITE);
7612
7613                 /* Display the name */
7614                 c_prt(attr, (r_name + r_ptr->name), row + i, col);
7615
7616                 /* Hack -- visual_list mode */
7617                 if (per_page == 1)
7618                 {
7619                         c_prt(attr, format("%02x/%02x", r_ptr->x_attr, r_ptr->x_char), row + i, 60);
7620                 }
7621                 else if (p_ptr->wizard) 
7622                 {
7623                         c_prt(attr, format("%d", r_idx), row + i, 60);
7624                 }
7625
7626                 a = r_ptr->x_attr;
7627                 c = r_ptr->x_char;
7628                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
7629
7630                 /* Display symbol */
7631                 Term_putch(70, row + i, a, c);
7632
7633                 /* Second byte */
7634                 if (use_bigtile) Term_putch(70 + 1, row + i, a2, c2);
7635
7636                 /* Display kills */
7637                 if (!(r_ptr->flags1 & RF1_UNIQUE)) put_str(format("%5d", r_ptr->r_pkills), row + i, 73);
7638 #ifdef JP
7639                 else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "»àË´" : "À¸Â¸"), row + i, 73);
7640 #else
7641                 else c_put_str((r_ptr->max_num == 0 ? TERM_L_DARK : TERM_WHITE), (r_ptr->max_num == 0 ? "dead" : "alive"), row + i, 73);
7642 #endif
7643         
7644         }
7645
7646         /* Clear remaining lines */
7647         for (; i < per_page; i++)
7648         {
7649                 Term_erase(col, row + i, 255);
7650         }
7651 }
7652
7653
7654 /*
7655  * Display known monsters.
7656  */
7657 static void do_cmd_knowledge_monsters(void)
7658 {
7659         int i, len, max;
7660         int grp_cur, grp_top, old_grp_cur;
7661         int mon_cur, mon_top;
7662         int grp_cnt, grp_idx[100];
7663         int mon_cnt;
7664         s16b *mon_idx;
7665         
7666         int column = 0;
7667         bool flag;
7668         bool redraw;
7669
7670         bool visual_list = FALSE;
7671         byte attr_top = 0, char_left = 0;
7672
7673         int browser_rows;
7674         int wid, hgt;
7675
7676         /* Get size */
7677         Term_get_size(&wid, &hgt);
7678
7679         browser_rows = hgt - 8;
7680
7681         /* Allocate the "mon_idx" array */
7682         C_MAKE(mon_idx, max_r_idx, s16b);
7683
7684         max = 0;
7685         grp_cnt = 0;
7686
7687         /* Check every group */
7688         for (i = 0; monster_group_text[i] != NULL; i++)
7689         {
7690                 /* Measure the label */
7691                 len = strlen(monster_group_text[i]);
7692
7693                 /* Save the maximum length */
7694                 if (len > max) max = len;
7695
7696                 /* See if any monsters are known */
7697                 if ((monster_group_char[i] == ((char *) -1L)) || collect_monsters(i, mon_idx, 0x01))
7698                 {
7699                         /* Build a list of groups with known monsters */
7700                         grp_idx[grp_cnt++] = i;
7701                 }
7702         }
7703
7704         /* Terminate the list */
7705         grp_idx[grp_cnt] = -1;
7706
7707         old_grp_cur = -1;
7708         grp_cur = grp_top = 0;
7709         mon_cur = mon_top = 0;
7710         mon_cnt = 0;
7711
7712         flag = FALSE;
7713         redraw = TRUE;
7714
7715         while (!flag)
7716         {
7717                 char ch;
7718                 monster_race *r_ptr;
7719
7720                 if (redraw)
7721                 {
7722                         clear_from(0);
7723                 
7724 #ifdef JP
7725                         prt("Ãμ± - ¥â¥ó¥¹¥¿¡¼", 2, 0);
7726                         prt("¥°¥ë¡¼¥×", 4, 0);
7727                         prt("̾Á°", 4, max + 3);
7728                         if (p_ptr->wizard) prt("Idx", 4, 60);
7729                         prt("ʸ»ú »¦³²¿ô", 4, 67);
7730 #else
7731                         prt("Knowledge - Monsters", 2, 0);
7732                         prt("Group", 4, 0);
7733                         prt("Name", 4, max + 3);
7734                         if (p_ptr->wizard) prt("Idx", 4, 60);
7735                         prt("Sym   Kills", 4, 67);
7736 #endif
7737
7738                         for (i = 0; i < 78; i++)
7739                         {
7740                                 Term_putch(i, 5, TERM_WHITE, '=');
7741                         }
7742
7743                         for (i = 0; i < browser_rows; i++)
7744                         {
7745                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
7746                         }
7747
7748                         redraw = FALSE;
7749                 }
7750
7751                 /* Scroll group list */
7752                 if (grp_cur < grp_top) grp_top = grp_cur;
7753                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
7754
7755                 /* Display a list of monster groups */
7756                 display_group_list(0, 6, max, browser_rows, grp_idx, monster_group_text, grp_cur, grp_top);
7757
7758                 if (old_grp_cur != grp_cur)
7759                 {
7760                         old_grp_cur = grp_cur;
7761
7762                         /* Get a list of monsters in the current group */
7763                         mon_cnt = collect_monsters(grp_idx[grp_cur], mon_idx, 0x00);
7764                 }
7765
7766                 /* Scroll monster list */
7767                 while (mon_cur < mon_top)
7768                         mon_top = MAX(0, mon_top - browser_rows/2);
7769                 while (mon_cur >= mon_top + browser_rows)
7770                         mon_top = MIN(mon_cnt - browser_rows, mon_top + browser_rows/2);
7771
7772                 if (!visual_list)
7773                 {
7774                         /* Display a list of monsters in the current group */
7775                         display_monster_list(max + 3, 6, browser_rows, mon_idx, mon_cur, mon_top);
7776                 }
7777                 else
7778                 {
7779                         mon_top = mon_cur;
7780
7781                         /* Display a monster name */
7782                         display_monster_list(max + 3, 6, 1, mon_idx, mon_cur, mon_top);
7783
7784                         /* Display visual list below first monster */
7785                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
7786                 }
7787
7788                 /* Prompt */
7789 #ifdef JP
7790                 prt(format("<Êý¸þ>, 'r'¤Ç»×¤¤½Ð¤ò¸«¤ë%s%s, ESC", visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
7791 #else
7792                 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);
7793 #endif
7794
7795                 /* Get the current monster */
7796                 r_ptr = &r_info[mon_idx[mon_cur]];
7797
7798                 /* Mega Hack -- track this monster race */
7799                 if (mon_cnt) monster_race_track(mon_idx[mon_cur]);
7800
7801                 /* Hack -- handle stuff */
7802                 handle_stuff();
7803
7804                 if (visual_list)
7805                 {
7806                         place_visual_list_cursor(max + 3, 7, r_ptr->x_attr, r_ptr->x_char, attr_top, char_left);
7807                 }
7808                 else if (!column)
7809                 {
7810                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
7811                 }
7812                 else
7813                 {
7814                         Term_gotoxy(max + 3, 6 + (mon_cur - mon_top));
7815                 }
7816         
7817                 ch = inkey();
7818
7819                 /* Do visual mode command if needed */
7820                 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;
7821
7822                 switch (ch)
7823                 {
7824                         case ESCAPE:
7825                         {
7826                                 flag = TRUE;
7827                                 break;
7828                         }
7829
7830                         case 'R':
7831                         case 'r':
7832                         {
7833                                 /* Recall on screen */
7834                                 if (mon_idx[mon_cur])
7835                                 {
7836                                         screen_roff(mon_idx[mon_cur], 0);
7837
7838                                         (void)inkey();
7839         
7840                                         redraw = TRUE;
7841                                 }
7842                                 break;
7843                         }
7844
7845                         default:
7846                         {
7847                                 /* Move the cursor */
7848                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &mon_cur, mon_cnt);
7849
7850                                 break;
7851                         }
7852                 }
7853         }
7854
7855         /* Free the "mon_idx" array */
7856         C_KILL(mon_idx, max_r_idx, s16b);
7857 }
7858
7859
7860 /*
7861  * Display the objects in a group.
7862  */
7863 static void display_object_list(int col, int row, int per_page, int object_idx[],
7864         int object_cur, int object_top)
7865 {
7866         int i;
7867
7868         /* Display lines until done */
7869         for (i = 0; i < per_page && object_idx[object_top + i]; i++)
7870         {
7871                 char o_name[80];
7872                 byte a, a2;
7873                 char c, c2;
7874
7875                 /* Get the object index */
7876                 int k_idx = object_idx[object_top + i];
7877
7878                 /* Access the object */
7879                 object_kind *k_ptr = &k_info[k_idx];
7880
7881                 /* Choose a color */
7882                 byte attr = (k_ptr->aware ? TERM_WHITE : TERM_SLATE);
7883                 byte cursor = (k_ptr->aware ? TERM_L_BLUE : TERM_BLUE);
7884
7885                 attr = ((i + object_top == object_cur) ? cursor : attr);
7886                 
7887                 /* Tidy name */
7888                 strip_name(o_name, k_idx);
7889
7890                 /* Display the name */
7891                 c_prt(attr, o_name, row + i, col);
7892
7893                 /* Hack -- visual_list mode */
7894                 if (per_page == 1)
7895                 {
7896                         c_prt(attr, format("%02x/%02x", k_ptr->x_attr, k_ptr->x_char), row + i, 60);
7897                 }
7898                 else if (p_ptr->wizard)
7899                 {
7900                         c_prt(attr, format ("%d", k_idx), row + i, 70);
7901                 }
7902
7903                 a = k_ptr->flavor ? misc_to_attr[k_ptr->flavor] : k_ptr->x_attr;
7904                 c = k_ptr->flavor ? misc_to_char[k_ptr->flavor] : k_ptr->x_char;
7905
7906                 /* Symbol is unknown */ 
7907                 if (!k_ptr->aware && !p_ptr->wizard)
7908                 {
7909                         c = ' ';
7910                         a = TERM_DARK;
7911                 }
7912
7913                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
7914
7915                 /* Display symbol */
7916                 Term_putch(76, row + i, a, c);
7917
7918                 /* Second byte */
7919                 if (use_bigtile) Term_putch(76 + 1, row + i, a2, c2);
7920         }
7921
7922         /* Clear remaining lines */
7923         for (; i < per_page; i++)
7924         {
7925                 Term_erase(col, row + i, 255);
7926         }
7927 }
7928
7929 /*
7930  * Describe fake object
7931  */
7932 static void desc_obj_fake(int k_idx)
7933 {
7934         object_type *o_ptr;
7935         object_type object_type_body;
7936
7937         /* Get local object */
7938         o_ptr = &object_type_body;
7939
7940         /* Wipe the object */
7941         object_wipe(o_ptr);
7942
7943         /* Create the artifact */
7944         object_prep(o_ptr, k_idx);
7945
7946         /* It's fully know */
7947         o_ptr->ident |= IDENT_KNOWN;
7948
7949         /* Track the object */
7950         /* object_actual_track(o_ptr); */
7951
7952         /* Hack - mark as fake */
7953         /* term_obj_real = FALSE; */
7954
7955         /* Hack -- Handle stuff */
7956         handle_stuff();
7957
7958         if (!screen_object(o_ptr, FALSE))
7959         {
7960 #ifdef JP
7961                 msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
7962 #else
7963                 msg_print("You see nothing special.");
7964 #endif
7965                 msg_print(NULL);
7966         }
7967 }
7968
7969
7970
7971 /*
7972  * Display known objects
7973  */
7974 static void do_cmd_knowledge_objects(void)
7975 {
7976         int i, len, max;
7977         int grp_cur, grp_top, old_grp_cur;
7978         int object_old, object_cur, object_top;
7979         int grp_cnt, grp_idx[100];
7980         int object_cnt;
7981         int *object_idx;
7982
7983         int column = 0;
7984         bool flag;
7985         bool redraw;
7986
7987         bool visual_list = FALSE;
7988         byte attr_top = 0, char_left = 0;
7989
7990         int browser_rows;
7991         int wid, hgt;
7992
7993         /* Get size */
7994         Term_get_size(&wid, &hgt);
7995
7996         browser_rows = hgt - 8;
7997
7998         /* Allocate the "object_idx" array */
7999         C_MAKE(object_idx, max_k_idx, int);
8000
8001         max = 0;
8002         grp_cnt = 0;
8003
8004         /* Check every group */
8005         for (i = 0; object_group_text[i] != NULL; i++)
8006         {
8007                 /* Measure the label */
8008                 len = strlen(object_group_text[i]);
8009
8010                 /* Save the maximum length */
8011                 if (len > max) max = len;
8012
8013                 /* See if any monsters are known */
8014                 if (collect_objects(i, object_idx))
8015                 {
8016                         /* Build a list of groups with known monsters */
8017                         grp_idx[grp_cnt++] = i;
8018                 }
8019         }
8020
8021         /* Terminate the list */
8022         grp_idx[grp_cnt] = -1;
8023
8024         old_grp_cur = -1;
8025         grp_cur = grp_top = 0;
8026         object_cur = object_top = 0;
8027         object_old = -1;
8028         object_cnt = 0;
8029
8030         flag = FALSE;
8031         redraw = TRUE;
8032
8033         while (!flag)
8034         {
8035                 char ch;
8036                 object_kind *k_ptr;
8037
8038                 if (redraw)
8039                 {
8040                         clear_from(0);
8041                 
8042 #ifdef JP
8043                         prt("Ãμ± - ¥¢¥¤¥Æ¥à", 2, 0);
8044                         prt("¥°¥ë¡¼¥×", 4, 0);
8045                         prt("̾Á°", 4, max + 3);
8046                         if (p_ptr->wizard) prt("Idx", 4, 70);
8047                         prt("ʸ»ú", 4, 75);
8048 #else
8049                         prt("Knowledge - objects", 2, 0);
8050                         prt("Group", 4, 0);
8051                         prt("Name", 4, max + 3);
8052                         if (p_ptr->wizard) prt("Idx", 4, 70);
8053                         prt("Sym", 4, 75);
8054 #endif
8055
8056                         for (i = 0; i < 78; i++)
8057                         {
8058                                 Term_putch(i, 5, TERM_WHITE, '=');
8059                         }
8060
8061                         for (i = 0; i < browser_rows; i++)
8062                         {
8063                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
8064                         }
8065
8066                         redraw = FALSE;
8067                 }
8068
8069                 /* Scroll group list */
8070                 if (grp_cur < grp_top) grp_top = grp_cur;
8071                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
8072
8073                 /* Display a list of object groups */
8074                 display_group_list(0, 6, max, browser_rows, grp_idx, object_group_text, grp_cur, grp_top);
8075
8076                 if (old_grp_cur != grp_cur)
8077                 {
8078                         old_grp_cur = grp_cur;
8079
8080                         /* Get a list of objects in the current group */
8081                         object_cnt = collect_objects(grp_idx[grp_cur], object_idx);
8082                 }
8083
8084                 /* Scroll object list */
8085                 while (object_cur < object_top)
8086                         object_top = MAX(0, object_top - browser_rows/2);
8087                 while (object_cur >= object_top + browser_rows)
8088                         object_top = MIN(object_cnt - browser_rows, object_top + browser_rows/2);
8089
8090                 if (!visual_list)
8091                 {
8092                         /* Display a list of objects in the current group */
8093                         display_object_list(max + 3, 6, browser_rows, object_idx, object_cur, object_top);
8094                 }
8095                 else
8096                 {
8097                         object_top = object_cur;
8098
8099                         /* Display a list of objects in the current group */
8100                         display_object_list(max + 3, 6, 1, object_idx, object_cur, object_top);
8101
8102                         /* Display visual list below first object */
8103                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
8104                 }
8105
8106                 /* Get the current object */
8107                 k_ptr = &k_info[object_idx[object_cur]];
8108
8109                 /* Mega Hack -- track this object */
8110                 if (object_cnt) object_kind_track(object_idx[object_cur]);
8111
8112                 /* Prompt */
8113 #ifdef JP
8114                 prt(format("<Êý¸þ>, 'r'¤Ç»×¤¤½Ð¤ò¸«¤ë%s%s, ESC", k_ptr->flavor ? "" : visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
8115 #else
8116                 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);
8117 #endif
8118
8119                 /* The "current" object changed */
8120                 if (object_old != object_idx[object_cur])
8121                 {
8122                         /* Hack -- handle stuff */
8123                         handle_stuff();
8124
8125                         /* Remember the "current" object */
8126                         object_old = object_idx[object_cur];
8127                 }
8128
8129                 if (visual_list)
8130                 {
8131                         place_visual_list_cursor(max + 3, 7, k_ptr->x_attr, k_ptr->x_char, attr_top, char_left);
8132                 }
8133                 else if (!column)
8134                 {
8135                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
8136                 }
8137                 else
8138                 {
8139                         Term_gotoxy(max + 3, 6 + (object_cur - object_top));
8140                 }
8141         
8142                 ch = inkey();
8143
8144                 /* Do visual mode command if needed */
8145                 /* Symbol of objects with flavor cannot be changed */
8146                 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;
8147
8148                 switch (ch)
8149                 {
8150                         case ESCAPE:
8151                         {
8152                                 flag = TRUE;
8153                                 break;
8154                         }
8155
8156                         case 'R':
8157                         case 'r':
8158                         {
8159                                 /* Recall on screen */
8160                                 if (grp_cnt > 0)
8161                                         desc_obj_fake(object_idx[object_cur]);
8162
8163                                 redraw = TRUE;
8164                                 break;
8165                         }
8166
8167                         default:
8168                         {
8169                                 /* Move the cursor */
8170                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &object_cur, object_cnt);
8171                                 break;
8172                         }
8173                 }
8174         }
8175
8176         /* Free the "object_idx" array */
8177         C_KILL(object_idx, max_k_idx, int);
8178 }
8179
8180
8181
8182 /*
8183  * Display the features in a group.
8184  */
8185 static void display_feature_list(int col, int row, int per_page, int *feat_idx,
8186         int feat_cur, int feat_top)
8187 {
8188         int i;
8189
8190         /* Display lines until done */
8191         for (i = 0; i < per_page && feat_idx[feat_top + i]; i++)
8192         {
8193                 byte a, a2;
8194                 char c, c2;
8195                 byte attr;
8196
8197                 /* Get the index */
8198                 int f_idx = feat_idx[feat_top + i];
8199
8200                 /* Access the index */
8201                 feature_type *f_ptr = &f_info[f_idx];
8202
8203                 /* Choose a color */
8204                 attr = ((i + feat_top == feat_cur) ? TERM_L_BLUE : TERM_WHITE);
8205
8206                 /* Display the name */
8207                 c_prt(attr, f_name + f_ptr->name, row + i, col);
8208
8209                 /* Hack -- visual_list mode */
8210                 if (per_page == 1)
8211                 {
8212                         c_prt(attr, format("%02x/%02x", f_ptr->x_attr, f_ptr->x_char), row + i, 60);
8213                 }
8214
8215                 a = f_ptr->x_attr;
8216                 c = f_ptr->x_char;
8217
8218                 if (use_bigtile) bigtile_attr(&c, &a, &c2, &a2);
8219
8220                 /* Display symbol */
8221                 Term_putch(68, row + i, a, c);
8222
8223                 /* Second byte */
8224                 if (use_bigtile) Term_putch(68 + 1, row + i, a2, c2);
8225         }
8226
8227         /* Clear remaining lines */
8228         for (; i < per_page; i++)
8229         {
8230                 Term_erase(col, row + i, 255);
8231         }
8232 }
8233
8234
8235 /*
8236  * Interact with feature visuals.
8237  */
8238 static void do_cmd_knowledge_features(void)
8239 {
8240         int i, len, max;
8241         int grp_cur, grp_top, old_grp_cur;
8242         int feat_cur, feat_top;
8243         int grp_cnt, grp_idx[100];
8244         int feat_cnt;
8245         int *feat_idx;
8246         
8247         int column = 0;
8248         bool flag;
8249         bool redraw;
8250
8251         bool visual_list = FALSE;
8252         byte attr_top = 0, char_left = 0;
8253
8254         int browser_rows;
8255         int wid, hgt;
8256
8257         /* Get size */
8258         Term_get_size(&wid, &hgt);
8259
8260         browser_rows = hgt - 8;
8261
8262         /* Allocate the "feat_idx" array */
8263         C_MAKE(feat_idx, max_f_idx, int);
8264
8265         max = 0;
8266         grp_cnt = 0;
8267
8268         /* Check every group */
8269         for (i = 0; feature_group_text[i] != NULL; i++)
8270         {
8271                 /* Measure the label */
8272                 len = strlen(feature_group_text[i]);
8273
8274                 /* Save the maximum length */
8275                 if (len > max) max = len;
8276
8277                 /* See if any features are known */
8278                 if (collect_features(i, feat_idx))
8279                 {
8280                         /* Build a list of groups with known features */
8281                         grp_idx[grp_cnt++] = i;
8282                 }
8283         }
8284
8285         /* Terminate the list */
8286         grp_idx[grp_cnt] = -1;
8287
8288         old_grp_cur = -1;
8289         grp_cur = grp_top = 0;
8290         feat_cur = feat_top = 0;
8291         feat_cnt = 0;
8292
8293         flag = FALSE;
8294         redraw = TRUE;
8295
8296         while ((!flag) && (grp_cnt))
8297         {
8298                 char ch;
8299                 feature_type *f_ptr;
8300
8301                 if (redraw)
8302                 {
8303                         clear_from(0);
8304                 
8305                         prt("Visuals - features", 2, 0);
8306                         prt("Group", 4, 0);
8307                         prt("Name", 4, max + 3);
8308                         prt("Sym", 4, 67);
8309
8310                         for (i = 0; i < 78; i++)
8311                         {
8312                                 Term_putch(i, 5, TERM_WHITE, '=');
8313                         }
8314
8315                         for (i = 0; i < browser_rows; i++)
8316                         {
8317                                 Term_putch(max + 1, 6 + i, TERM_WHITE, '|');
8318                         }
8319
8320                         redraw = FALSE;
8321                 }
8322
8323                 /* Scroll group list */
8324                 if (grp_cur < grp_top) grp_top = grp_cur;
8325                 if (grp_cur >= grp_top + browser_rows) grp_top = grp_cur - browser_rows + 1;
8326
8327                 /* Display a list of feature groups */
8328                 display_group_list(0, 6, max, browser_rows, grp_idx, feature_group_text, grp_cur, grp_top);
8329
8330                 if (old_grp_cur != grp_cur)
8331                 {
8332                         old_grp_cur = grp_cur;
8333
8334                         /* Get a list of features in the current group */
8335                         feat_cnt = collect_features(grp_idx[grp_cur], feat_idx);
8336                 }
8337
8338                 /* Scroll feature list */
8339                 while (feat_cur < feat_top)
8340                         feat_top = MAX(0, feat_top - browser_rows/2);
8341                 while (feat_cur >= feat_top + browser_rows)
8342                         feat_top = MIN(feat_cnt - browser_rows, feat_top + browser_rows/2);
8343
8344                 if (!visual_list)
8345                 {
8346                         /* Display a list of features in the current group */
8347                         display_feature_list(max + 3, 6, browser_rows, feat_idx, feat_cur, feat_top);
8348                 }
8349                 else
8350                 {
8351                         feat_top = feat_cur;
8352
8353                         /* Display a list of features in the current group */
8354                         display_feature_list(max + 3, 6, 1, feat_idx, feat_cur, feat_top);
8355
8356                         /* Display visual list below first object */
8357                         display_visual_list(max + 3, 7, browser_rows-1, wid - (max + 3), attr_top, char_left);
8358                 }
8359
8360                 /* Prompt */
8361 #ifdef JP
8362                 prt(format("<Êý¸þ>%s%s, ESC", visual_list ? ", ENTER¤Ç·èÄê" : ", 'v'¤Ç¥·¥ó¥Ü¥ëÊѹ¹", (attr_idx||char_idx) ? ", 'c', 'p'¤Ç¥Ú¡¼¥¹¥È" : ", 'c'¤Ç¥³¥Ô¡¼"), hgt - 1, 0);
8363 #else
8364                 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);
8365 #endif
8366
8367                 /* Get the current feature */
8368                 f_ptr = &f_info[feat_idx[feat_cur]];
8369
8370                 if (visual_list)
8371                 {
8372                         place_visual_list_cursor(max + 3, 7, f_ptr->x_attr, f_ptr->x_char, attr_top, char_left);
8373                 }
8374                 else if (!column)
8375                 {
8376                         Term_gotoxy(0, 6 + (grp_cur - grp_top));
8377                 }
8378                 else
8379                 {
8380                         Term_gotoxy(max + 3, 6 + (feat_cur - feat_top));
8381                 }
8382         
8383                 ch = inkey();
8384
8385                 /* Do visual mode command if needed */
8386                 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;
8387
8388                 switch (ch)
8389                 {
8390                         case ESCAPE:
8391                         {
8392                                 flag = TRUE;
8393                                 break;
8394                         }
8395
8396                         default:
8397                         {
8398                                 /* Move the cursor */
8399                                 browser_cursor(ch, &column, &grp_cur, grp_cnt, &feat_cur, feat_cnt);
8400                                 break;
8401                         }
8402                 }
8403         }
8404
8405         /* Prompt */
8406         if (!grp_cnt) msg_print("No features known.");
8407
8408         /* Free the "feat_idx" array */
8409         C_KILL(feat_idx, max_f_idx, int);
8410 }
8411
8412
8413 /*
8414  * List wanted monsters
8415  */
8416 static void do_cmd_knowledge_kubi(void)
8417 {
8418         int i;
8419         FILE *fff;
8420         
8421         char file_name[1024];
8422         
8423         
8424         /* Open a new file */
8425         fff = my_fopen_temp(file_name, 1024);
8426         if (!fff) {
8427 #ifdef JP
8428             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8429 #else
8430             msg_format("Failed to create temporary file %s.", file_name);
8431 #endif
8432             msg_print(NULL);
8433             return;
8434         }
8435         
8436         if (fff)
8437         {
8438                 bool listed = FALSE;
8439
8440 #ifdef JP
8441                 fprintf(fff, "º£Æü¤Î¥¿¡¼¥²¥Ã¥È : %s\n", (p_ptr->today_mon ? r_name + r_info[p_ptr->today_mon].name : "ÉÔÌÀ"));
8442                 fprintf(fff, "\n");
8443                 fprintf(fff, "¾Þ¶â¼ó¥ê¥¹¥È\n");
8444 #else
8445                 fprintf(fff, "Today target : %s\n", (p_ptr->today_mon ? r_name + r_info[p_ptr->today_mon].name : "unknown"));
8446                 fprintf(fff, "\n");
8447                 fprintf(fff, "List of wanted monsters\n");
8448 #endif
8449                 fprintf(fff, "----------------------------------------------\n");
8450
8451                 for (i = 0; i < MAX_KUBI; i++)
8452                 {
8453                         if (kubi_r_idx[i] <= 10000)
8454                         {
8455                                 fprintf(fff,"%s\n", r_name + r_info[kubi_r_idx[i]].name);
8456
8457                                 listed = TRUE;
8458                         }
8459                 }
8460
8461                 if (!listed)
8462                 {
8463 #ifdef JP
8464                         fprintf(fff,"\n%s\n", "¾Þ¶â¼ó¤Ï¤â¤¦»Ä¤Ã¤Æ¤¤¤Þ¤»¤ó¡£");
8465 #else
8466                         fprintf(fff,"\n%s\n", "There is no more wanted monster.");
8467 #endif
8468                 }
8469         }
8470         
8471         /* Close the file */
8472         my_fclose(fff);
8473         
8474         /* Display the file contents */
8475 #ifdef JP
8476         show_file(TRUE, file_name, "¾Þ¶â¼ó¤Î°ìÍ÷", 0, 0);
8477 #else
8478         show_file(TRUE, file_name, "Wanted monsters", 0, 0);
8479 #endif
8480
8481         
8482         /* Remove the file */
8483         fd_kill(file_name);
8484 }
8485
8486 /*
8487  * List virtues & status
8488  */
8489 static void do_cmd_knowledge_virtues(void)
8490 {
8491         FILE *fff;
8492         
8493         char file_name[1024];
8494         
8495         
8496         /* Open a new file */
8497         fff = my_fopen_temp(file_name, 1024);
8498         if (!fff) {
8499 #ifdef JP
8500             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8501 #else
8502             msg_format("Failed to create temporary file %s.", file_name);
8503 #endif
8504             msg_print(NULL);
8505             return;
8506         }
8507         
8508         if (fff)
8509         {
8510 #ifdef JP
8511                 fprintf(fff, "¸½ºß¤Î°À­ : %s\n\n", your_alignment());
8512 #else
8513                 fprintf(fff, "Your alighnment : %s\n\n", your_alignment());
8514 #endif
8515                 dump_virtues(fff);
8516         }
8517         
8518         /* Close the file */
8519         my_fclose(fff);
8520         
8521         /* Display the file contents */
8522 #ifdef JP
8523         show_file(TRUE, file_name, "Ȭ¤Ä¤ÎÆÁ", 0, 0);
8524 #else
8525         show_file(TRUE, file_name, "Virtues", 0, 0);
8526 #endif
8527
8528         
8529         /* Remove the file */
8530         fd_kill(file_name);
8531 }
8532
8533 /*
8534 * Dungeon
8535 *
8536 */
8537 static void do_cmd_knowledge_dungeon(void)
8538 {
8539         FILE *fff;
8540         
8541         char file_name[1024];
8542         int i;
8543         
8544         
8545         /* Open a new file */
8546         fff = my_fopen_temp(file_name, 1024);
8547         if (!fff) {
8548 #ifdef JP
8549             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8550 #else
8551             msg_format("Failed to create temporary file %s.", file_name);
8552 #endif
8553             msg_print(NULL);
8554             return;
8555         }
8556         
8557         if (fff)
8558         {
8559                 for (i = 1; i < max_d_idx; i++)
8560                 {
8561                         bool seiha = FALSE;
8562
8563                         if (!d_info[i].maxdepth) continue;
8564                         if (!max_dlv[i]) continue;
8565                         if (d_info[i].final_guardian)
8566                         {
8567                                 if (!r_info[d_info[i].final_guardian].max_num) seiha = TRUE;
8568                         }
8569                         else if (max_dlv[i] == d_info[i].maxdepth) seiha = TRUE;
8570 #ifdef JP
8571                         fprintf(fff,"%c%-12s :  %3d ³¬\n", seiha ? '!' : ' ', d_name + d_info[i].name, max_dlv[i]);
8572 #else
8573                         fprintf(fff,"%c%-16s :  level %3d\n", seiha ? '!' : ' ', d_name + d_info[i].name, max_dlv[i]);
8574 #endif
8575                 }
8576         }
8577         
8578         /* Close the file */
8579         my_fclose(fff);
8580         
8581         /* Display the file contents */
8582 #ifdef JP
8583         show_file(TRUE, file_name, "º£¤Þ¤Ç¤ËÆþ¤Ã¤¿¥À¥ó¥¸¥ç¥ó", 0, 0);
8584 #else
8585         show_file(TRUE, file_name, "Dungeon", 0, 0);
8586 #endif
8587
8588         
8589         /* Remove the file */
8590         fd_kill(file_name);
8591 }
8592
8593 /*
8594 * List virtues & status
8595 *
8596 */
8597 static void do_cmd_knowledge_stat(void)
8598 {
8599         FILE *fff;
8600         
8601         char file_name[1024];
8602         int percent, v_nr;
8603         
8604         /* Open a new file */
8605         fff = my_fopen_temp(file_name, 1024);
8606         if (!fff) {
8607 #ifdef JP
8608             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
8609 #else
8610             msg_format("Failed to create temporary file %s.", file_name);
8611 #endif
8612             msg_print(NULL);
8613             return;
8614         }
8615         
8616         if (fff)
8617         {
8618                 percent = (int)(((long)p_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
8619                         (2 * p_ptr->hitdie +
8620                         ((PY_MAX_LEVEL - 1+3) * (p_ptr->hitdie + 1))));
8621
8622 #ifdef JP
8623                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "¸½ºß¤ÎÂÎÎÏ¥é¥ó¥¯ : %d/100\n\n", percent);
8624                 else fprintf(fff, "¸½ºß¤ÎÂÎÎÏ¥é¥ó¥¯ : ???\n\n");
8625                 fprintf(fff, "ǽÎϤκÇÂçÃÍ\n\n");
8626 #else
8627                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "Your current Life Rating is %d/100.\n\n", percent);
8628                 else fprintf(fff, "Your current Life Rating is ???.\n\n");
8629                 fprintf(fff, "Limits of maximum stats\n\n");
8630 #endif
8631                 for (v_nr = 0; v_nr < 6; v_nr++)
8632                 {
8633                         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);
8634                         else fprintf(fff, "%s ???\n", stat_names[v_nr]);
8635                 }
8636         }
8637
8638         dump_yourself(fff);
8639
8640         /* Close the file */
8641         my_fclose(fff);
8642         
8643         /* Display the file contents */
8644 #ifdef JP
8645         show_file(TRUE, file_name, "¼«Ê¬¤Ë´Ø¤¹¤ë¾ðÊó", 0, 0);
8646 #else
8647         show_file(TRUE, file_name, "HP-rate & Max stat", 0, 0);
8648 #endif
8649
8650         
8651         /* Remove the file */
8652         fd_kill(file_name);
8653 }
8654
8655
8656 /*
8657  * Print all active quests
8658  */
8659 static void do_cmd_knowledge_quests_current(FILE *fff)
8660 {
8661         char tmp_str[120];
8662         char rand_tmp_str[120] = "\0";
8663         char name[80];
8664         monster_race *r_ptr;
8665         int i;
8666         int rand_level = 100;
8667         int total = 0;
8668
8669 #ifdef JP
8670         fprintf(fff, "¡Ô¿ë¹ÔÃæ¤Î¥¯¥¨¥¹¥È¡Õ\n");
8671 #else
8672         fprintf(fff, "< Current Quest >\n");
8673 #endif
8674
8675         for (i = 1; i < max_quests; i++)
8676         {
8677                 if ((quest[i].status == QUEST_STATUS_TAKEN) || (quest[i].status == QUEST_STATUS_COMPLETED))
8678                 {
8679                         /* Set the quest number temporary */
8680                         int old_quest = p_ptr->inside_quest;
8681                         int j;
8682
8683                         /* Clear the text */
8684                         for (j = 0; j < 10; j++) quest_text[j][0] = '\0';
8685                         quest_text_line = 0;
8686
8687                         p_ptr->inside_quest = i;
8688
8689                         /* Get the quest text */
8690                         init_flags = INIT_SHOW_TEXT;
8691
8692                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
8693
8694                         /* Reset the old quest number */
8695                         p_ptr->inside_quest = old_quest;
8696
8697                         /* No info from "silent" quests */
8698                         if (quest[i].flags & QUEST_FLAG_SILENT) continue;
8699
8700                         total++;
8701
8702                         if (quest[i].type != QUEST_TYPE_RANDOM)
8703                         {
8704                                 char note[80] = "\0";
8705
8706                                 if (quest[i].status == QUEST_STATUS_TAKEN)
8707                                 {
8708                                         switch (quest[i].type)
8709                                         {
8710                                         case QUEST_TYPE_KILL_LEVEL:
8711                                         case QUEST_TYPE_KILL_ANY_LEVEL:
8712                                                 r_ptr = &r_info[quest[i].r_idx];
8713                                                 strcpy(name, r_name + r_ptr->name);
8714                                                 if (quest[i].max_num > 1)
8715                                                 {
8716 #ifdef JP
8717                                                         sprintf(note," - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
8718                                                                 quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
8719 #else
8720                                                         plural_aux(name);
8721                                                         sprintf(note," - kill %d %s, have killed %d.",
8722                                                                 quest[i].max_num, name, quest[i].cur_num);
8723 #endif
8724                                                 }
8725                                                 else
8726 #ifdef JP
8727                                                         sprintf(note," - %s¤òÅݤ¹¡£",name);
8728 #else
8729                                                         sprintf(note," - kill %s.",name);
8730 #endif
8731                                                 break;
8732
8733                                         case QUEST_TYPE_FIND_ARTIFACT:
8734                                                 strcpy(name, a_name + a_info[quest[i].k_idx].name);
8735 #ifdef JP
8736                                                 sprintf(note," - %s¤ò¸«¤Ä¤±½Ð¤¹¡£", name);
8737 #else
8738                                                 sprintf(note," - Find out %s.", name);
8739 #endif
8740                                                 break;
8741
8742                                         case QUEST_TYPE_FIND_EXIT:
8743 #ifdef JP
8744                                                 sprintf(note," - Ãµº÷¤¹¤ë¡£");
8745 #else
8746                                                 sprintf(note," - Search.");
8747 #endif
8748                                                 break;
8749
8750                                         case QUEST_TYPE_KILL_NUMBER:
8751 #ifdef JP
8752                                                 sprintf(note," - %d ÂΤΥâ¥ó¥¹¥¿¡¼¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)",
8753                                                         quest[i].max_num, quest[i].max_num - quest[i].cur_num);
8754 #else
8755                                                 sprintf(note," - Kill %d monsters, have killed %d.",
8756                                                         quest[i].max_num, quest[i].cur_num);
8757 #endif
8758                                                 break;
8759
8760                                         case QUEST_TYPE_KILL_ALL:
8761 #ifdef JP
8762                                                 sprintf(note," - Á´¤Æ¤Î¥â¥ó¥¹¥¿¡¼¤òÅݤ¹¡£");
8763 #else
8764                                                 sprintf(note," - Kill all monsters.");
8765 #endif
8766                                                 break;
8767                                         }
8768                                 }
8769
8770                                 /* Print the quest info */
8771 #ifdef JP
8772                                 sprintf(tmp_str, "  %s (´í¸±ÅÙ:%d³¬ÁêÅö)%s\n",
8773                                         quest[i].name, quest[i].level, note);
8774 #else
8775                                 sprintf(tmp_str, "  %s (Danger level: %d)%s\n",
8776                                         quest[i].name, quest[i].level, note);
8777 #endif
8778
8779                                 fprintf(fff, tmp_str);
8780
8781                                 if (quest[i].status == QUEST_STATUS_COMPLETED)
8782                                 {
8783 #ifdef JP
8784                                         sprintf(tmp_str, "    ¥¯¥¨¥¹¥ÈãÀ® - ¤Þ¤ÀÊó½·¤ò¼õ¤±¤È¤Ã¤Æ¤Ê¤¤¡£\n");
8785 #else
8786                                         sprintf(tmp_str, "    Quest Completed - Unrewarded\n");
8787 #endif
8788                                         fprintf(fff, tmp_str);
8789                                 }
8790                                 else
8791                                 {
8792                                         j = 0;
8793
8794                                         while (quest_text[j][0] && j < 10)
8795                                         {
8796                                                 fprintf(fff, "    %s\n", quest_text[j]);
8797                                                 j++;
8798                                         }
8799                                 }
8800                         }
8801                         else if (quest[i].level < rand_level) /* QUEST_TYPE_RANDOM */
8802                         {
8803                                 /* New random */
8804                                 rand_level = quest[i].level;
8805
8806                                 if (max_dlv[DUNGEON_ANGBAND] >= rand_level)
8807                                 {
8808                                         /* Print the quest info */
8809                                         r_ptr = &r_info[quest[i].r_idx];
8810                                         strcpy(name, r_name + r_ptr->name);
8811
8812                                         if (quest[i].max_num > 1)
8813                                         {
8814 #ifdef JP
8815                                                 sprintf(rand_tmp_str,"  %s (%d ³¬) - %d ÂΤÎ%s¤òÅݤ¹¡£(¤¢¤È %d ÂÎ)\n",
8816                                                         quest[i].name, quest[i].level,
8817                                                         quest[i].max_num, name, quest[i].max_num - quest[i].cur_num);
8818 #else
8819                                                 plural_aux(name);
8820
8821                                                 sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %d %s, have killed %d.\n",
8822                                                         quest[i].name, quest[i].level,
8823                                                         quest[i].max_num, name, quest[i].cur_num);
8824 #endif
8825                                         }
8826                                         else
8827                                         {
8828 #ifdef JP
8829                                                 sprintf(rand_tmp_str,"  %s (%d ³¬) - %s¤òÅݤ¹¡£\n",
8830                                                         quest[i].name, quest[i].level, name);
8831 #else
8832                                                 sprintf(rand_tmp_str,"  %s (Dungeon level: %d)\n  Kill %s.\n",
8833                                                         quest[i].name, quest[i].level, name);
8834 #endif
8835                                         }
8836                                 }
8837                         }
8838                 }
8839         }
8840
8841         /* Print the current random quest  */
8842         if (rand_tmp_str[0]) fprintf(fff, rand_tmp_str);
8843
8844 #ifdef JP
8845         if (!total) fprintf(fff, "  ¤Ê¤·\n");
8846 #else
8847         if (!total) fprintf(fff, "  Nothing.\n");
8848 #endif
8849 }
8850
8851
8852 /*
8853  * Print all finished quests
8854  */
8855 void do_cmd_knowledge_quests_completed(FILE *fff, int quest_num[])
8856 {
8857         char tmp_str[120];
8858         int i;
8859         int total = 0;
8860
8861 #ifdef JP
8862         fprintf(fff, "¡ÔãÀ®¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
8863 #else
8864         fprintf(fff, "< Completed Quest >\n");
8865 #endif
8866         for (i = 1; i < max_quests; i++)
8867         {
8868                 int q_idx = quest_num[i];
8869
8870                 if (quest[q_idx].status == QUEST_STATUS_FINISHED)
8871                 {
8872                         if (is_fixed_quest_idx(q_idx))
8873                         {
8874                                 /* Set the quest number temporary */
8875                                 int old_quest = p_ptr->inside_quest;
8876
8877                                 p_ptr->inside_quest = q_idx;
8878
8879                                 /* Get the quest */
8880                                 init_flags = INIT_ASSIGN;
8881
8882                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
8883
8884                                 /* Reset the old quest number */
8885                                 p_ptr->inside_quest = old_quest;
8886
8887                                 /* No info from "silent" quests */
8888                                 if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
8889                         }
8890
8891                         total++;
8892
8893                         if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
8894                         {
8895                                 /* Print the quest info */
8896
8897                                 if (quest[q_idx].complev == 0)
8898                                 {
8899                                         sprintf(tmp_str,
8900 #ifdef JP
8901                                                 "  %-40s (%3d³¬)            -   ÉÔÀᄀ\n",
8902 #else
8903                                                 "  %-40s (Dungeon level: %3d) - (Cancelled)\n",
8904 #endif
8905                                                 r_name+r_info[quest[q_idx].r_idx].name,
8906                                                 quest[q_idx].level);
8907                                 }
8908                                 else
8909                                 {
8910                                         sprintf(tmp_str,
8911 #ifdef JP
8912                                                 "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
8913 #else
8914                                                 "  %-40s (Dungeon level: %3d) - level %2d\n",
8915 #endif
8916                                                 r_name+r_info[quest[q_idx].r_idx].name,
8917                                                 quest[q_idx].level,
8918                                                 quest[q_idx].complev);
8919                                 }
8920                         }
8921                         else
8922                         {
8923                                 /* Print the quest info */
8924 #ifdef JP
8925                                 sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
8926                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
8927 #else
8928                                 sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
8929                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
8930 #endif
8931                         }
8932
8933                         fprintf(fff, tmp_str);
8934                 }
8935         }
8936 #ifdef JP
8937         if (!total) fprintf(fff, "  ¤Ê¤·\n");
8938 #else
8939         if (!total) fprintf(fff, "  Nothing.\n");
8940 #endif
8941 }
8942
8943
8944 /*
8945  * Print all failed quests
8946  */
8947 void do_cmd_knowledge_quests_failed(FILE *fff, int quest_num[])
8948 {
8949         char tmp_str[120];
8950         int i;
8951         int total = 0;
8952
8953 #ifdef JP
8954         fprintf(fff, "¡Ô¼ºÇÔ¤·¤¿¥¯¥¨¥¹¥È¡Õ\n");
8955 #else
8956         fprintf(fff, "< Failed Quest >\n");
8957 #endif
8958         for (i = 1; i < max_quests; i++)
8959         {
8960                 int q_idx = quest_num[i];
8961
8962                 if ((quest[q_idx].status == QUEST_STATUS_FAILED_DONE) || (quest[q_idx].status == QUEST_STATUS_FAILED))
8963                 {
8964                         if (is_fixed_quest_idx(q_idx))
8965                         {
8966                                 /* Set the quest number temporary */
8967                                 int old_quest = p_ptr->inside_quest;
8968
8969                                 p_ptr->inside_quest = q_idx;
8970
8971                                 /* Get the quest text */
8972                                 init_flags = INIT_ASSIGN;
8973
8974                                 process_dungeon_file("q_info.txt", 0, 0, 0, 0);
8975
8976                                 /* Reset the old quest number */
8977                                 p_ptr->inside_quest = old_quest;
8978
8979                                 /* No info from "silent" quests */
8980                                 if (quest[q_idx].flags & QUEST_FLAG_SILENT) continue;
8981                         }
8982
8983                         total++;
8984
8985                         if (!is_fixed_quest_idx(q_idx) && quest[q_idx].r_idx)
8986                         {
8987                                 /* Print the quest info */
8988 #ifdef JP
8989                                 sprintf(tmp_str, "  %-40s (%3d³¬)            - ¥ì¥Ù¥ë%2d\n",
8990                                         r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
8991 #else
8992                                 sprintf(tmp_str, "  %-40s (Dungeon level: %3d) - level %2d\n",
8993                                         r_name+r_info[quest[q_idx].r_idx].name, quest[q_idx].level, quest[q_idx].complev);
8994 #endif
8995                         }
8996                         else
8997                         {
8998                                 /* Print the quest info */
8999 #ifdef JP
9000                                 sprintf(tmp_str, "  %-40s (´í¸±ÅÙ:%3d³¬ÁêÅö) - ¥ì¥Ù¥ë%2d\n",
9001                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9002 #else
9003                                 sprintf(tmp_str, "  %-40s (Danger  level: %3d) - level %2d\n",
9004                                         quest[q_idx].name, quest[q_idx].level, quest[q_idx].complev);
9005 #endif
9006                         }
9007                         fprintf(fff, tmp_str);
9008                 }
9009         }
9010 #ifdef JP
9011         if (!total) fprintf(fff, "  ¤Ê¤·\n");
9012 #else
9013         if (!total) fprintf(fff, "  Nothing.\n");
9014 #endif
9015 }
9016
9017
9018 /*
9019  * Print all random quests
9020  */
9021 static void do_cmd_knowledge_quests_wiz_random(FILE *fff)
9022 {
9023         char tmp_str[120];
9024         int i;
9025         int total = 0;
9026
9027 #ifdef JP
9028         fprintf(fff, "¡Ô»Ä¤ê¤Î¥é¥ó¥À¥à¥¯¥¨¥¹¥È¡Õ\n");
9029 #else
9030         fprintf(fff, "< Remaining Random Quest >\n");
9031 #endif
9032         for (i = 1; i < max_quests; i++)
9033         {
9034                 /* No info from "silent" quests */
9035                 if (quest[i].flags & QUEST_FLAG_SILENT) continue;
9036
9037                 if ((quest[i].type == QUEST_TYPE_RANDOM) && (quest[i].status == QUEST_STATUS_TAKEN))
9038                 {
9039                         total++;
9040
9041                         /* Print the quest info */
9042 #ifdef JP
9043                         sprintf(tmp_str, "  %s (%d³¬, %s)\n",
9044                                 quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
9045 #else
9046                         sprintf(tmp_str, "  %s (%d, %s)\n",
9047                                 quest[i].name, quest[i].level, r_name+r_info[quest[i].r_idx].name);
9048 #endif
9049                         fprintf(fff, tmp_str);
9050                 }
9051         }
9052 #ifdef JP
9053         if (!total) fprintf(fff, "  ¤Ê¤·\n");
9054 #else
9055         if (!total) fprintf(fff, "  Nothing.\n");
9056 #endif
9057 }
9058
9059
9060 bool ang_sort_comp_quest_num(vptr u, vptr v, int a, int b)
9061 {
9062         int *q_num = (int *)u;
9063         quest_type *qa = &quest[q_num[a]];
9064         quest_type *qb = &quest[q_num[b]];
9065
9066         /* Unused */
9067         (void)v;
9068
9069         if (qa->complev < qb->complev) return TRUE;
9070         if (qa->complev > qb->complev) return FALSE;
9071         if (qa->level <= qb->level) return TRUE;
9072         return FALSE;
9073 }
9074
9075 void ang_sort_swap_quest_num(vptr u, vptr v, int a, int b)
9076 {
9077         int *q_num = (int *)u;
9078         int tmp;
9079
9080         /* Unused */
9081         (void)v;
9082
9083         tmp = q_num[a];
9084         q_num[a] = q_num[b];
9085         q_num[b] = tmp;
9086 }
9087
9088
9089 /*
9090  * Print quest status of all active quests
9091  */
9092 static void do_cmd_knowledge_quests(void)
9093 {
9094         FILE *fff;
9095         char file_name[1024];
9096         int *quest_num, dummy, i;
9097
9098         /* Open a new file */
9099         fff = my_fopen_temp(file_name, 1024);
9100         if (!fff)
9101         {
9102 #ifdef JP
9103             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9104 #else
9105             msg_format("Failed to create temporary file %s.", file_name);
9106 #endif
9107             msg_print(NULL);
9108             return;
9109         }
9110
9111         /* Allocate Memory */
9112         C_MAKE(quest_num, max_quests, int);
9113
9114         /* Sort by compete level */
9115         for (i = 1; i < max_quests; i++) quest_num[i] = i;
9116         ang_sort_comp = ang_sort_comp_quest_num;
9117         ang_sort_swap = ang_sort_swap_quest_num;
9118         ang_sort(quest_num, &dummy, max_quests);
9119
9120         /* Dump Quest Information */
9121         do_cmd_knowledge_quests_current(fff);
9122         fputc('\n', fff);
9123         do_cmd_knowledge_quests_completed(fff, quest_num);
9124         fputc('\n', fff);
9125         do_cmd_knowledge_quests_failed(fff, quest_num);
9126         if (p_ptr->wizard)
9127         {
9128                 fputc('\n', fff);
9129                 do_cmd_knowledge_quests_wiz_random(fff);
9130         }
9131
9132         /* Close the file */
9133         my_fclose(fff);
9134
9135         /* Display the file contents */
9136 #ifdef JP
9137         show_file(TRUE, file_name, "¥¯¥¨¥¹¥ÈãÀ®¾õ¶·", 0, 0);
9138 #else
9139         show_file(TRUE, file_name, "Quest status", 0, 0);
9140 #endif
9141
9142         /* Remove the file */
9143         fd_kill(file_name);
9144
9145         /* Free Memory */
9146         C_KILL(quest_num, max_quests, int);
9147 }
9148
9149
9150 /*
9151  * List my home
9152  */
9153 static void do_cmd_knowledge_home(void)
9154 {
9155         FILE *fff;
9156
9157         int i;
9158         char file_name[1024];
9159         store_type  *st_ptr;
9160         char o_name[MAX_NLEN];
9161         cptr            paren = ")";
9162
9163         process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
9164
9165         /* Open a new file */
9166         fff = my_fopen_temp(file_name, 1024);
9167         if (!fff) {
9168 #ifdef JP
9169                 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9170 #else
9171                 msg_format("Failed to create temporary file %s.", file_name);
9172 #endif
9173                 msg_print(NULL);
9174                 return;
9175         }
9176
9177         if (fff)
9178         {
9179                 /* Print all homes in the different towns */
9180                 st_ptr = &town[1].store[STORE_HOME];
9181
9182                 /* Home -- if anything there */
9183                 if (st_ptr->stock_num)
9184                 {
9185 #ifdef JP
9186                         int x = 1;
9187 #endif
9188                         /* Header with name of the town */
9189 #ifdef JP
9190                         fprintf(fff, "  [ ²æ¤¬²È¤Î¥¢¥¤¥Æ¥à ]\n");
9191 #else
9192                         fprintf(fff, "  [Home Inventory]\n");
9193 #endif
9194
9195                         /* Dump all available items */
9196                         for (i = 0; i < st_ptr->stock_num; i++)
9197                         {
9198 #ifdef JP
9199                                 if ((i % 12) == 0) fprintf(fff, "\n ( %d ¥Ú¡¼¥¸ )\n", x++);
9200                                 object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
9201                                 if (strlen(o_name) <= 80-3)
9202                                 {
9203                                         fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
9204                                 }
9205                                 else
9206                                 {
9207                                         int n;
9208                                         char *t;
9209                                         for (n = 0, t = o_name; n < 80-3; n++, t++)
9210                                                 if(iskanji(*t)) {t++; n++;}
9211                                         if (n == 81-3) n = 79-3; /* ºÇ¸å¤¬´Á»úȾʬ */
9212
9213                                         fprintf(fff, "%c%s %.*s\n", I2A(i%12), paren, n, o_name);
9214                                         fprintf(fff, "   %.77s\n", o_name+n);
9215                                 }
9216 #else
9217                                 object_desc(o_name, &st_ptr->stock[i], TRUE, 3);
9218                                 fprintf(fff, "%c%s %s\n", I2A(i%12), paren, o_name);
9219 #endif
9220
9221                         }
9222
9223                         /* Add an empty line */
9224                         fprintf(fff, "\n\n");
9225                 }
9226         }
9227
9228         /* Close the file */
9229         my_fclose(fff);
9230
9231         /* Display the file contents */
9232 #ifdef JP
9233         show_file(TRUE, file_name, "²æ¤¬²È¤Î¥¢¥¤¥Æ¥à", 0, 0);
9234 #else
9235         show_file(TRUE, file_name, "Home Inventory", 0, 0);
9236 #endif
9237
9238
9239         /* Remove the file */
9240         fd_kill(file_name);
9241 }
9242
9243
9244 /*
9245  * Check the status of "autopick"
9246  */
9247 static void do_cmd_knowledge_autopick(void)
9248 {
9249         int k;
9250         FILE *fff;
9251         char file_name[1024];
9252
9253         /* Open a new file */
9254         fff = my_fopen_temp(file_name, 1024);
9255
9256         if (!fff)
9257         {
9258 #ifdef JP
9259             msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
9260 #else
9261             msg_format("Failed to create temporary file %s.", file_name);
9262 #endif
9263             msg_print(NULL);
9264             return;
9265         }
9266
9267         if (!max_autopick)
9268         {
9269 #ifdef JP
9270             fprintf(fff, "¼«Æ°Ç˲õ/½¦¤¤¤Ë¤Ï²¿¤âÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
9271 #else
9272             fprintf(fff, "No preference for auto picker/destroyer.");
9273 #endif
9274         }
9275         else
9276         {
9277 #ifdef JP
9278             fprintf(fff, "   ¼«Æ°½¦¤¤/Ç˲õ¤Ë¤Ï¸½ºß %d¹ÔÅÐÏ¿¤µ¤ì¤Æ¤¤¤Þ¤¹¡£\n\n", max_autopick);
9279 #else
9280             fprintf(fff, "   There are %d registered lines for auto picker/destroyer.\n\n", max_autopick);
9281 #endif
9282         }
9283
9284         for (k = 0; k < max_autopick; k++)
9285         {
9286                 cptr tmp;
9287                 byte act = autopick_list[k].action;
9288                 if (act & DONT_AUTOPICK)
9289                 {
9290 #ifdef JP
9291                         tmp = "ÊüÃÖ";
9292 #else
9293                         tmp = "Leave";
9294 #endif
9295                 }
9296                 else if (act & DO_AUTODESTROY)
9297                 {
9298 #ifdef JP
9299                         tmp = "Ç˲õ";
9300 #else
9301                         tmp = "Destroy";
9302 #endif
9303                 }
9304                 else if (act & DO_AUTOPICK)
9305                 {
9306 #ifdef JP
9307                         tmp = "½¦¤¦";
9308 #else
9309                         tmp = "Pickup";
9310 #endif
9311                 }
9312                 else /* if (act & DO_QUERY_AUTOPICK) */ /* Obvious */
9313                 {
9314 #ifdef JP
9315                         tmp = "³Îǧ";
9316 #else
9317                         tmp = "Query";
9318 #endif
9319                 }
9320
9321                 if (act & DO_DISPLAY)
9322                         fprintf(fff, "%11s", format("[%s]", tmp));
9323                 else
9324                         fprintf(fff, "%11s", format("(%s)", tmp));
9325
9326                 tmp = autopick_line_from_entry(&autopick_list[k]);
9327                 fprintf(fff, " %s", tmp);
9328                 string_free(tmp);
9329                 fprintf(fff, "\n");
9330         }
9331         /* Close the file */
9332         my_fclose(fff);
9333         /* Display the file contents */
9334 #ifdef JP
9335         show_file(TRUE, file_name, "¼«Æ°½¦¤¤/Ç˲õ ÀßÄê¥ê¥¹¥È", 0, 0);
9336 #else
9337         show_file(TRUE, file_name, "Auto-picker/Destroyer", 0, 0);
9338 #endif
9339
9340         /* Remove the file */
9341         fd_kill(file_name);
9342 }
9343
9344
9345 /*
9346  * Interact with "knowledge"
9347  */
9348 void do_cmd_knowledge(void)
9349 {
9350         int i,p=0;
9351         /* File type is "TEXT" */
9352         FILE_TYPE(FILE_TYPE_TEXT);
9353         /* Save the screen */
9354         screen_save();
9355         /* Interact until done */
9356         while (1)
9357         {
9358                 /* Clear screen */
9359                 Term_clear();
9360                 /* Ask for a choice */
9361 #ifdef JP
9362                 prt(format("%d/2 ¥Ú¡¼¥¸", (p+1)), 2, 65);
9363                 prt("¸½ºß¤ÎÃ챤ò³Îǧ¤¹¤ë", 3, 0);
9364 #else
9365                 prt(format("page %d/2", (p+1)), 2, 65);
9366                 prt("Display current knowledge", 3, 0);
9367 #endif
9368
9369                 /* Give some choices */
9370 #ifdef JP
9371                 if (p == 0) {
9372                         prt("(1) ´ûÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à                 ¤Î°ìÍ÷", 6, 5);
9373                         prt("(2) ´ûÃΤΥ¢¥¤¥Æ¥à                       ¤Î°ìÍ÷", 7, 5);
9374                         prt("(3) ´ûÃΤÎÀ¸¤­¤Æ¤¤¤ë¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ ¤Î°ìÍ÷", 8, 5);
9375                         prt("(4) ´ûÃΤΥâ¥ó¥¹¥¿¡¼                     ¤Î°ìÍ÷", 9, 5);
9376                         prt("(5) Åݤ·¤¿Å¨¤Î¿ô                         ¤Î°ìÍ÷", 10, 5);
9377                         if (!vanilla_town) prt("(6) ¾Þ¶â¼ó                               ¤Î°ìÍ÷", 11, 5);
9378                         prt("(7) ¸½ºß¤Î¥Ú¥Ã¥È                         ¤Î°ìÍ÷", 12, 5);
9379                         prt("(8) ²æ¤¬²È¤Î¥¢¥¤¥Æ¥à                     ¤Î°ìÍ÷", 13, 5);
9380                         prt("(9) *´ÕÄê*ºÑ¤ßÁõÈ÷¤ÎÂÑÀ­                 ¤Î°ìÍ÷", 14, 5);
9381                         prt("(0) ÃÏ·Á¤Îɽ¼¨Ê¸»ú/¥¿¥¤¥ë                ¤Î°ìÍ÷", 15, 5);
9382                 } else {
9383                         prt("(a) ¼«Ê¬¤Ë´Ø¤¹¤ë¾ðÊó                     ¤Î°ìÍ÷", 6, 5);
9384                         prt("(b) ÆÍÁ³ÊÑ°Û                             ¤Î°ìÍ÷", 7, 5);
9385                         prt("(c) Éð´ï¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 8, 5);
9386                         prt("(d) ËâË¡¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 9, 5);
9387                         prt("(e) µ»Ç½¤Î·Ð¸³ÃÍ                         ¤Î°ìÍ÷", 10, 5);
9388                         prt("(f) ¥×¥ì¥¤¥ä¡¼¤ÎÆÁ                       ¤Î°ìÍ÷", 11, 5);
9389                         prt("(g) Æþ¤Ã¤¿¥À¥ó¥¸¥ç¥ó                     ¤Î°ìÍ÷", 12, 5);
9390                         prt("(h) ¼Â¹ÔÃæ¤Î¥¯¥¨¥¹¥È                     ¤Î°ìÍ÷", 13, 5);
9391                         prt("(i) ¸½ºß¤Î¼«Æ°½¦¤¤/Ç˲õÀßÄê              ¤Î°ìÍ÷", 14, 5);
9392                 }
9393 #else
9394                 if (p == 0) {
9395                         prt("(1) Display known artifacts", 6, 5);
9396                         prt("(2) Display known objects", 7, 5);
9397                         prt("(3) Display remaining uniques", 8, 5);
9398                         prt("(4) Display known monster", 9, 5);
9399                         prt("(5) Display kill count", 10, 5);
9400                         if (!vanilla_town) prt("(6) Display wanted monsters", 11, 5);
9401                         prt("(7) Display current pets", 12, 5);
9402                         prt("(8) Display home inventory", 13, 5);
9403                         prt("(9) Display *identified* equip.", 14, 5);
9404                         prt("(0) Display terrain symbols.", 15, 5);
9405                 } else {
9406                         prt("(a) Display about yourself", 6, 5);
9407                         prt("(b) Display mutations", 7, 5);
9408                         prt("(c) Display weapon proficiency", 8, 5);
9409                         prt("(d) Display spell proficiency", 9, 5);
9410                         prt("(e) Display misc. proficiency", 10, 5);
9411                         prt("(f) Display virtues", 11, 5);
9412                         prt("(g) Display dungeons", 12, 5);
9413                         prt("(h) Display current quests", 13, 5);
9414                         prt("(i) Display auto pick/destroy", 14, 5);
9415                 }
9416 #endif
9417                 /* Prompt */
9418 #ifdef JP
9419                 prt("-³¤¯-", 17, 8);
9420                 prt("ESC) È´¤±¤ë", 21, 1);
9421                 prt("SPACE) ¼¡¥Ú¡¼¥¸", 21, 30);
9422                 /*prt("-) Á°¥Ú¡¼¥¸", 21, 60);*/
9423                 prt("¥³¥Þ¥ó¥É:", 20, 0);
9424 #else
9425                 prt("-more-", 17, 8);
9426                 prt("ESC) Exit menu", 21, 1);
9427                 prt("SPACE) Next page", 21, 30);
9428                 /*prt("-) Previous page", 21, 60);*/
9429                 prt("Command: ", 20, 0);
9430 #endif
9431
9432                 /* Prompt */
9433                 i = inkey();
9434                 /* Done */
9435                 if (i == ESCAPE) break;
9436                 switch (i)
9437                 {
9438                 case ' ': /* Page change */
9439                 case '-':
9440                         p = 1 - p;
9441                         break;
9442                 case '1': /* Artifacts */
9443                         do_cmd_knowledge_artifacts();
9444                         break;
9445                 case '2': /* Objects */
9446                         do_cmd_knowledge_objects();
9447                         break;
9448                 case '3': /* Uniques */
9449                         do_cmd_knowledge_uniques();
9450                         break;
9451                 case '4': /* Monsters */
9452                         do_cmd_knowledge_monsters();
9453                         break;
9454                 case '5': /* Kill count  */
9455                         do_cmd_knowledge_kill_count();
9456                         break;
9457                 case '6': /* wanted */
9458                         if (!vanilla_town) do_cmd_knowledge_kubi();
9459                         break;
9460                 case '7': /* Pets */
9461                         do_cmd_knowledge_pets();
9462                         break;
9463                 case '8': /* Home */
9464                         do_cmd_knowledge_home();
9465                         break;
9466                 case '9': /* Resist list */
9467                         do_cmd_knowledge_inven();
9468                         break;
9469                 case '0': /* Feature list */
9470                         do_cmd_knowledge_features();
9471                         break;
9472                 /* Next page */
9473                 case 'a': /* Max stat */
9474                         do_cmd_knowledge_stat();
9475                         break;
9476                 case 'b': /* Mutations */
9477                         do_cmd_knowledge_mutations();
9478                         break;
9479                 case 'c': /* weapon-exp */
9480                         do_cmd_knowledge_weapon_exp();
9481                         break;
9482                 case 'd': /* spell-exp */
9483                         do_cmd_knowledge_spell_exp();
9484                         break;
9485                 case 'e': /* skill-exp */
9486                         do_cmd_knowledge_skill_exp();
9487                         break;
9488                 case 'f': /* Virtues */
9489                         do_cmd_knowledge_virtues();
9490                         break;
9491                 case 'g': /* Dungeon */
9492                         do_cmd_knowledge_dungeon();
9493                         break;
9494                 case 'h': /* Quests */
9495                         do_cmd_knowledge_quests();
9496                         break;
9497                 case 'i': /* Autopick */
9498                         do_cmd_knowledge_autopick();
9499                         break;
9500                 default: /* Unknown option */
9501                         bell();
9502                 }
9503                 /* Flush messages */
9504                 msg_print(NULL);
9505         }
9506         /* Restore the screen */
9507         screen_load();
9508 }
9509
9510
9511 /*
9512  * Check on the status of an active quest
9513  */
9514 void do_cmd_checkquest(void)
9515 {
9516         /* File type is "TEXT" */
9517         FILE_TYPE(FILE_TYPE_TEXT);
9518
9519         /* Save the screen */
9520         screen_save();
9521
9522         /* Quest info */
9523         do_cmd_knowledge_quests();
9524
9525         /* Restore the screen */
9526         screen_load();
9527 }
9528
9529
9530 /*
9531  * Display the time and date
9532  */
9533 void do_cmd_time(void)
9534 {
9535         int day, hour, min, full, start, end, num;
9536         char desc[1024];
9537
9538         char buf[1024];
9539
9540         FILE *fff;
9541
9542         extract_day_hour_min(&day, &hour, &min);
9543
9544         full = hour * 100 + min;
9545
9546         start = 9999;
9547         end = -9999;
9548
9549         num = 0;
9550
9551 #ifdef JP
9552         strcpy(desc, "ÊѤʻþ¹ï¤À¡£");
9553 #else
9554         strcpy(desc, "It is a strange time.");
9555 #endif
9556
9557
9558         /* Message */
9559 #ifdef JP
9560         msg_format("%d ÆüÌÜ,»þ¹ï¤Ï%d:%02d %s¤Ç¤¹¡£",
9561                    day, (hour % 12 == 0) ? 12 : (hour % 12),
9562                    min, (hour < 12) ? "AM" : "PM");
9563 #else
9564         msg_format("This is day %d. The time is %d:%02d %s.",
9565                    day, (hour % 12 == 0) ? 12 : (hour % 12),
9566                    min, (hour < 12) ? "AM" : "PM");
9567 #endif
9568
9569
9570         /* Find the path */
9571         if (!randint0(10) || p_ptr->image)
9572         {
9573 #ifdef JP
9574                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun_j.txt");
9575 #else
9576                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timefun.txt");
9577 #endif
9578
9579         }
9580         else
9581         {
9582 #ifdef JP
9583                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm_j.txt");
9584 #else
9585                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "timenorm.txt");
9586 #endif
9587
9588         }
9589
9590         /* Open this file */
9591         fff = my_fopen(buf, "rt");
9592
9593         /* Oops */
9594         if (!fff) return;
9595
9596         /* Find this time */
9597         while (!my_fgets(fff, buf, sizeof(buf)))
9598         {
9599                 /* Ignore comments */
9600                 if (!buf[0] || (buf[0] == '#')) continue;
9601
9602                 /* Ignore invalid lines */
9603                 if (buf[1] != ':') continue;
9604
9605                 /* Process 'Start' */
9606                 if (buf[0] == 'S')
9607                 {
9608                         /* Extract the starting time */
9609                         start = atoi(buf + 2);
9610
9611                         /* Assume valid for an hour */
9612                         end = start + 59;
9613
9614                         /* Next... */
9615                         continue;
9616                 }
9617
9618                 /* Process 'End' */
9619                 if (buf[0] == 'E')
9620                 {
9621                         /* Extract the ending time */
9622                         end = atoi(buf + 2);
9623
9624                         /* Next... */
9625                         continue;
9626                 }
9627
9628                 /* Ignore incorrect range */
9629                 if ((start > full) || (full > end)) continue;
9630
9631                 /* Process 'Description' */
9632                 if (buf[0] == 'D')
9633                 {
9634                         num++;
9635
9636                         /* Apply the randomizer */
9637                         if (!randint0(num)) strcpy(desc, buf + 2);
9638
9639                         /* Next... */
9640                         continue;
9641                 }
9642         }
9643
9644         /* Message */
9645         msg_print(desc);
9646
9647         /* Close the file */
9648         my_fclose(fff);
9649 }