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